Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
✨ 支持运行"ymcl"打开启动器
Browse files Browse the repository at this point in the history
  • Loading branch information
DaiYu-233 committed May 18, 2024
1 parent 858a837 commit 8eded21
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2024-05-17T12:56:08.6038334Z;True|2024-03-24T01:01:53.7028265+08:00;True|2024-03-24T01:01:12.6152908+08:00;True|2024-03-17T08:22:18.0649252+08:00;True|2024-03-17T07:54:32.3843552+08:00;True|2024-03-16T02:36:45.4285090+08:00;True|2024-03-09T20:53:41.7358912+08:00;True|2024-03-09T02:01:44.9304554+08:00;False|2024-03-09T02:01:22.5812914+08:00;False|2024-03-09T02:00:57.9393924+08:00;True|2024-03-09T01:43:54.2928837+08:00;True|2024-03-08T20:33:31.5214462+08:00;True|2024-02-23T17:59:22.9820098+08:00;True|2024-02-07T15:19:08.8940230+08:00;True|2024-02-04T18:21:14.9769464+08:00;True|2024-02-04T15:14:39.4036707+08:00;True|2024-01-31T16:00:53.7465648+08:00;True|2024-01-31T14:34:24.9551335+08:00;True|2024-01-29T17:50:50.0394231+08:00;True|2024-01-29T17:27:51.6989645+08:00;True|2024-01-29T01:12:53.6424384+08:00;True|2024-01-28T18:34:28.1880865+08:00;True|2024-01-24T01:50:31.0096758+08:00;True|2024-01-24T01:13:03.8341087+08:00;True|2024-01-24T01:02:18.1443995+08:00;True|2024-01-24T00:13:09.4106261+08:00;True|2024-01-23T19:30:44.5307442+08:00;True|2024-01-23T19:26:41.9447509+08:00;True|2024-01-23T17:20:28.4552582+08:00;False|2024-01-23T17:19:54.6032960+08:00;True|2024-01-23T16:09:40.3446859+08:00;True|2024-01-23T16:08:17.1112817+08:00;True|2024-01-23T15:46:15.7646614+08:00;True|2024-01-23T15:40:36.0459058+08:00;True|2024-01-21T00:37:00.8430817+08:00;False|2024-01-21T00:34:51.4589993+08:00;False|2024-01-21T00:31:59.0812525+08:00;False|2024-01-21T00:30:41.6578455+08:00;True|2024-01-21T00:30:17.9156441+08:00;True|2024-01-21T00:30:09.1187126+08:00;True|2024-01-21T00:29:59.5992260+08:00;True|2024-01-21T00:29:54.6225163+08:00;True|2024-01-21T00:29:47.9785106+08:00;True|2024-01-21T00:28:14.3570126+08:00;False|2024-01-21T00:28:05.7388712+08:00;False|2024-01-21T00:26:35.3619180+08:00;False|2024-01-21T00:25:38.1582660+08:00;True|2024-01-21T00:25:31.2101642+08:00;False|2024-01-21T00:25:16.1009723+08:00;False|2024-01-21T00:24:41.3056576+08:00;False|2024-01-21T00:24:22.5887214+08:00;False|2024-01-21T00:24:08.3964843+08:00;True|2024-01-21T00:23:33.9770686+08:00;True|2024-01-21T00:23:25.0545878+08:00;False|2024-01-21T00:17:47.9427506+08:00;True|2024-01-20T00:15:03.5976901+08:00;True|2024-01-20T00:14:36.4913028+08:00;True|2024-01-20T00:13:53.5314050+08:00;</History>
<History>True|2024-05-18T12:44:20.5837330Z;True|2024-05-18T20:43:33.5582720+08:00;True|2024-05-18T20:39:02.6859007+08:00;True|2024-05-18T20:04:06.6094097+08:00;True|2024-05-17T20:56:08.6038334+08:00;True|2024-03-24T01:01:53.7028265+08:00;True|2024-03-24T01:01:12.6152908+08:00;True|2024-03-17T08:22:18.0649252+08:00;True|2024-03-17T07:54:32.3843552+08:00;True|2024-03-16T02:36:45.4285090+08:00;True|2024-03-09T20:53:41.7358912+08:00;True|2024-03-09T02:01:44.9304554+08:00;False|2024-03-09T02:01:22.5812914+08:00;False|2024-03-09T02:00:57.9393924+08:00;True|2024-03-09T01:43:54.2928837+08:00;True|2024-03-08T20:33:31.5214462+08:00;True|2024-02-23T17:59:22.9820098+08:00;True|2024-02-07T15:19:08.8940230+08:00;True|2024-02-04T18:21:14.9769464+08:00;True|2024-02-04T15:14:39.4036707+08:00;True|2024-01-31T16:00:53.7465648+08:00;True|2024-01-31T14:34:24.9551335+08:00;True|2024-01-29T17:50:50.0394231+08:00;True|2024-01-29T17:27:51.6989645+08:00;True|2024-01-29T01:12:53.6424384+08:00;True|2024-01-28T18:34:28.1880865+08:00;True|2024-01-24T01:50:31.0096758+08:00;True|2024-01-24T01:13:03.8341087+08:00;True|2024-01-24T01:02:18.1443995+08:00;True|2024-01-24T00:13:09.4106261+08:00;True|2024-01-23T19:30:44.5307442+08:00;True|2024-01-23T19:26:41.9447509+08:00;True|2024-01-23T17:20:28.4552582+08:00;False|2024-01-23T17:19:54.6032960+08:00;True|2024-01-23T16:09:40.3446859+08:00;True|2024-01-23T16:08:17.1112817+08:00;True|2024-01-23T15:46:15.7646614+08:00;True|2024-01-23T15:40:36.0459058+08:00;True|2024-01-21T00:37:00.8430817+08:00;False|2024-01-21T00:34:51.4589993+08:00;False|2024-01-21T00:31:59.0812525+08:00;False|2024-01-21T00:30:41.6578455+08:00;True|2024-01-21T00:30:17.9156441+08:00;True|2024-01-21T00:30:09.1187126+08:00;True|2024-01-21T00:29:59.5992260+08:00;True|2024-01-21T00:29:54.6225163+08:00;True|2024-01-21T00:29:47.9785106+08:00;True|2024-01-21T00:28:14.3570126+08:00;False|2024-01-21T00:28:05.7388712+08:00;False|2024-01-21T00:26:35.3619180+08:00;False|2024-01-21T00:25:38.1582660+08:00;True|2024-01-21T00:25:31.2101642+08:00;False|2024-01-21T00:25:16.1009723+08:00;False|2024-01-21T00:24:41.3056576+08:00;False|2024-01-21T00:24:22.5887214+08:00;False|2024-01-21T00:24:08.3964843+08:00;True|2024-01-21T00:23:33.9770686+08:00;True|2024-01-21T00:23:25.0545878+08:00;False|2024-01-21T00:17:47.9427506+08:00;True|2024-01-20T00:15:03.5976901+08:00;True|2024-01-20T00:14:36.4913028+08:00;True|2024-01-20T00:13:53.5314050+08:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>
92 changes: 87 additions & 5 deletions YMCL.Main/Views/Initialize/InitializeWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public partial class InitializeWindow : WindowX
MD5="7ECB82C30E2BECFDC442B41368789D5A"
},
new DownloadFile()
{
Name="YMCL.Starter.exe",
Url="https://ymcl.daiyu.fun/Assets/YMCL/YMCL.Starter.exe",
MD5="51B4B0BF4F1C7499B7BD1AF7FD2CCAE4"
},
new DownloadFile()
{
Name="FluentIcons.ttf",
Url="https://ymcl.daiyu.fun/Assets/YMCL/FluentIcons.ttf",
Expand Down Expand Up @@ -86,7 +92,7 @@ public partial class InitializeWindow : WindowX
public InitializeWindow()
{
InitializeComponent();

}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -342,6 +348,7 @@ async void Download()
Timeout = new TimeSpan(0, 0, 40)
};

var down = false;
foreach (var item in files)
{
#region MD5
Expand Down Expand Up @@ -403,10 +410,12 @@ async void Download()
registryKeya.SetValue("", Const.YMCLBat);
RegistryKey registryKeyb = Registry.ClassesRoot.OpenSubKey("YMCL", true).CreateSubKey(@"shell\open\command");
registryKeyb.SetValue("", $"\"{Const.YMCLBat}\" \"%1\"");

File.Copy(Path.Combine(Const.PublicDataRootPath, "YMCL.Starter.exe"), "C:\\Windows\\ymcl.exe", true);
}
catch { }


if (File.Exists(Path.Combine(Const.PublicDataRootPath, item.Name)) && md5 == item.MD5)
{
lines[i].Text = LangHelper.Current.GetText("InitializeWindow_DownloadFinish");
Expand All @@ -415,6 +424,7 @@ async void Download()
}
else
{
down = true;
await Task.Run(async () =>
{
try
Expand Down Expand Up @@ -496,9 +506,25 @@ await Dispatcher.BeginInvoke(() =>

if (!needInstallFont && File.Exists(Path.Combine(Const.PublicDataRootPath, "FontHasBeenInstalled")) && !App.StartupArgs.Contains("InstallFont"))
{
MainWindow main = Const.Window.main;
Hide();
main.Show();
if (!down)
{
MainWindow main = Const.Window.main;
Hide();
main.Show();
}
else
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
UseShellExecute = true,
WorkingDirectory = Environment.CurrentDirectory,
FileName = System.Windows.Forms.Application.ExecutablePath,
Verb = "runas",
Arguments = "InstallFont"
};
Process.Start(startInfo);
Application.Current.Shutdown();
}
}
else
{
Expand Down Expand Up @@ -542,9 +568,65 @@ await Dispatcher.BeginInvoke(() =>
WriteProfileString("fonts", Path.GetFileNameWithoutExtension(fontFilePath1) + "(TrueType)", $"YMCL_{Method.GetTimeStamp()}_" + Path.GetFileName(fontFilePath1));

File.WriteAllText(Path.Combine(Const.PublicDataRootPath, "FontHasBeenInstalled"), "");
File.Copy(Path.Combine(Const.PublicDataRootPath, "YMCL.Starter.exe"), "C:\\Windows\\ymcl.exe", true);
}
Next.IsEnabled = true;
}

if (down)
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
{
var message = MessageBoxX.Show(LangHelper.Current.GetText("InitializeWindow_Download_AdministratorPermissionRequired"), "Yu Minecraft Launcher", MessageBoxButton.OKCancel, MessageBoxIcon.Info);
if (message == MessageBoxResult.OK)
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
UseShellExecute = true,
WorkingDirectory = Environment.CurrentDirectory,
FileName = System.Windows.Forms.Application.ExecutablePath,
Verb = "runas",
Arguments = "InstallFont"
};
Process.Start(startInfo);
Application.Current.Shutdown();
}
else
{
MessageBoxX.Show(LangHelper.Current.GetText("InitializeWindow_FailedToObtainAdministratorPrivileges"), "Yu Minecraft Launcher", MessageBoxIcon.Error);
Application.Current.Shutdown();
}
}
else
{
RegistryKey keyRoot = Registry.ClassesRoot.CreateSubKey("YMCL", true);
keyRoot.SetValue("", "Yu Minecraft Launcher");
keyRoot.SetValue("URL Protocol", Const.YMCLBat);
RegistryKey registryKeya = Registry.ClassesRoot.OpenSubKey("YMCL", true).CreateSubKey("DefaultIcon");
registryKeya.SetValue("", Const.YMCLBat);
RegistryKey registryKeyb = Registry.ClassesRoot.OpenSubKey("YMCL", true).CreateSubKey(@"shell\open\command");
registryKeyb.SetValue("", $"\"{Const.YMCLBat}\" \"%1\"");

File.Copy(Path.Combine(Const.PublicDataRootPath, "YMCL.Starter.exe"), "C:\\Windows\\ymcl.exe", true);

var fontFilePath = "C:\\ProgramData\\DaiYu.YMCL\\MiSans.ttf";
string fontPath = Path.Combine(Environment.GetEnvironmentVariable("WINDIR"), "fonts", $"YMCL_{Method.GetTimeStamp()}_" + Path.GetFileName(fontFilePath));
File.Copy(fontFilePath, fontPath, true); //font是程序目录下放字体的文件夹
AddFontResource(fontPath);
WriteProfileString("fonts", Path.GetFileNameWithoutExtension(fontFilePath) + "(TrueType)", $"YMCL_{Method.GetTimeStamp()}_" + Path.GetFileName(fontFilePath));


var fontFilePath1 = "C:\\ProgramData\\DaiYu.YMCL\\FluentIcons.ttf";
string fontPath1 = Path.Combine(Environment.GetEnvironmentVariable("WINDIR"), "fonts", $"YMCL_{Method.GetTimeStamp()}_" + Path.GetFileName(fontFilePath1));
File.Copy(fontFilePath1, fontPath1, true); //font是程序目录下放字体的文件夹
AddFontResource(fontPath1);
WriteProfileString("fonts", Path.GetFileNameWithoutExtension(fontFilePath1) + "(TrueType)", $"YMCL_{Method.GetTimeStamp()}_" + Path.GetFileName(fontFilePath1));

File.WriteAllText(Path.Combine(Const.PublicDataRootPath, "FontHasBeenInstalled"), "");
}
}
}
private void TimerElapsed(object sender, ElapsedEventArgs e)
{
Expand Down
2 changes: 1 addition & 1 deletion YMCL.Main/Views/Main/Pages/Launch/Launch.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Net;
Expand Down
21 changes: 18 additions & 3 deletions YMCL.Main/Views/Main/Pages/MusicPlayer/MusicPlayer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
xmlns:pu="https://opensource.panuon.com/wpf-ui"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
Title="MusicPlayer"
d:DesignHeight="450"
d:DesignWidth="800"
AllowDrop="True"
Background="{DynamicResource 2x}"
Cursor=""
Drop="Page_Drop"
mc:Ignorable="d">
<Page.Triggers>
Expand Down Expand Up @@ -85,7 +84,6 @@
DockPanel.Dock="Right">
<TextBlock
x:Name="TimeText"
Width="100"
Margin="0,0,15,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Expand All @@ -94,6 +92,23 @@
Foreground="{DynamicResource TextColor}"
Text="00:00/00:00"
TextAlignment="Right" />
<ui:FontIcon
Margin="0,0,6,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Cursor="Hand"
FontSize="24"
Foreground="{DynamicResource TextColor}"
Glyph="&#xE994;" />
<Slider
x:Name="Voiume"
Width="80"
Margin="0,0,15,0"
VerticalAlignment="Center"
LargeChange="1"
Maximum="100"
ValueChanged="Voiume_ValueChanged"
Value="50" />
<ui:FontIcon
x:Name="LyricBtn"
Margin="0,0,15,0"
Expand Down
7 changes: 6 additions & 1 deletion YMCL.Main/Views/Main/Pages/MusicPlayer/MusicPlayer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ await Dispatcher.BeginInvoke(() =>
public async void AddLocalSong(string path)
{
if (_theLastLocalSong == path)
return;
return;
_theLastLocalSong = path;
string[] Array = path.Split(@"\");
player_for_duration.Open(new Uri(path));
Expand Down Expand Up @@ -969,5 +969,10 @@ private void Page_Drop(object sender, System.Windows.DragEventArgs e)
{
Const.Window.main.DropMethod(e);
}

private void Voiume_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
player.Volume = Voiume.Value / 100;
}
}
}
20 changes: 20 additions & 0 deletions YMCL.Starter/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Diagnostics;

namespace YMCL.Starter
{
internal class Program
{
static void Main(string[] args)
{
var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DaiYu.YMCL", "YMCL.ExePath.DaiYu");
var exe = File.ReadAllText(path);
ProcessStartInfo startInfo = new ProcessStartInfo
{
UseShellExecute = true,
WorkingDirectory = Path.GetDirectoryName(exe),
FileName = exe
};
Process.Start(startInfo);
}
}
}
18 changes: 18 additions & 0 deletions YMCL.Starter/Properties/PublishProfiles/FolderProfile.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net8.0\publish\win-x86\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
</Project>
10 changes: 10 additions & 0 deletions YMCL.Starter/Properties/PublishProfiles/FolderProfile.pubxml.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2024-05-18T12:33:31.5767525Z;True|2024-05-18T20:13:27.0548315+08:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>
10 changes: 10 additions & 0 deletions YMCL.Starter/YMCL.Starter.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
8 changes: 7 additions & 1 deletion YMCL.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YMCL.Updater", "YMCL.Update
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YMCL.Notifier", "YMCL.Notifier\YMCL.Notifier.csproj", "{6F580E3D-0E22-4D07-A114-DF87D6C38AB9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YMCL.Starter", "YMCL.Starter\YMCL.Starter.csproj", "{1CDB284E-93BF-4147-BBE2-6D688A768611}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,12 +41,16 @@ Global
{6F580E3D-0E22-4D07-A114-DF87D6C38AB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F580E3D-0E22-4D07-A114-DF87D6C38AB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F580E3D-0E22-4D07-A114-DF87D6C38AB9}.Release|Any CPU.Build.0 = Release|Any CPU
{1CDB284E-93BF-4147-BBE2-6D688A768611}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1CDB284E-93BF-4147-BBE2-6D688A768611}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CDB284E-93BF-4147-BBE2-6D688A768611}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CDB284E-93BF-4147-BBE2-6D688A768611}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AA3DCF72-989A-4AF3-B1D8-E38534D8879A}
RESX_NeutralResourcesLanguage = zh-Hans
SolutionGuid = {AA3DCF72-989A-4AF3-B1D8-E38534D8879A}
EndGlobalSection
EndGlobal

0 comments on commit 8eded21

Please sign in to comment.