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

Commit

Permalink
✨ 引入一些新功能
Browse files Browse the repository at this point in the history
  • Loading branch information
DaiYu-233 committed May 11, 2024
1 parent 82781e8 commit ccd7673
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 22 deletions.
10 changes: 10 additions & 0 deletions YMCL.Main/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Panuon.WPF.UI;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Windows;
Expand Down Expand Up @@ -47,6 +48,15 @@ protected override void OnStartup(StartupEventArgs e)
//Shutdown();
}
base.OnStartup(e);

string resourceName = "YMCL.Main.Public.Text.DateTime.txt";
Assembly _assembly = Assembly.GetExecutingAssembly();
Stream stream = _assembly.GetManifestResourceStream(resourceName);
using (StreamReader reader = new StreamReader(stream))
{
Const.Version = reader.ReadToEnd();
}

StartupArgs = e.Args;
var args = e.Args;

Expand Down
2 changes: 1 addition & 1 deletion YMCL.Main/Public/Const.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Window
}

public static string CurseForgeApiKey { get; } = "$2a$10$ndSPnOpYqH3DRmLTWJTf5Ofm7lz9uYoTGvhSj0OjJWJ8WdO4ZTsr.";
public static string Version { get; } = "2024.05.02.00.05";
public static string Version { get; set; } = null;
public static string UpdaterId { get; } = "97B62D3AD1724EFA9AFC7A8D8971BBB1";
public static string AzureClientId { get; } = "c06d4d68-7751-4a8a-a2ff-d1b46688f428";
public static string VersionSettingFileName { get; } = "YMCL.Setting.DaiYu";
Expand Down
9 changes: 9 additions & 0 deletions YMCL.Main/Public/Lang/MainLang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions YMCL.Main/Public/Lang/MainLang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,7 @@
<data name="ResourceAreMissing" xml:space="preserve">
<value>有资源缺失</value>
</data>
<data name="MinecraftCrash" xml:space="preserve">
<value>Minecraft发生崩溃</value>
</data>
</root>
1 change: 1 addition & 0 deletions YMCL.Main/Public/Text/DateTime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024.05.02.00.05
22 changes: 18 additions & 4 deletions YMCL.Main/Views/Main/Pages/Launch/Launch.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using MinecraftLaunch.Classes.Interfaces;
using MinecraftLaunch.Components.Checker;
using System;
using MinecraftLaunch.Components.Analyzer;

namespace YMCL.Main.Views.Main.Pages.Launch
{
Expand Down Expand Up @@ -833,7 +834,7 @@ public async void LaunchClient(string versionId, string minecraftPath = "", bool
return;
}
var setting = JsonConvert.DeserializeObject<Public.Class.Setting>(File.ReadAllText(Const.SettingDataPath));

if (string.IsNullOrEmpty(mcPath))
{
mcPath = setting.MinecraftFolder;
Expand Down Expand Up @@ -957,6 +958,7 @@ public async void LaunchClient(string versionId, string minecraftPath = "", bool
}
}
}
bool aloneCore = true;
if (!string.IsNullOrEmpty(javaPath))
{
LaunchConfig config = new();
Expand Down Expand Up @@ -995,7 +997,7 @@ public async void LaunchClient(string versionId, string minecraftPath = "", bool
{
maxMem = versionSetting.MaxMem;
}
bool aloneCore = true;

if (versionSetting.AloneCore == SettingItem.VersionSettingAloneCore.Global)
{
aloneCore = setting.AloneCore;
Expand Down Expand Up @@ -1053,15 +1055,27 @@ await Dispatcher.BeginInvoke(async () =>
Toast.Show(message: $"{LangHelper.Current.GetText("Launch_LaunchGame_Click_GameExit")}{args.ExitCode}", position: ToastPosition.Top, window: Const.Window.main);
taskProgress.Hide();
Const.Window.main.Focus();

if (args.ExitCode == 1)
{
var crashAnalyzer = new GameCrashAnalyzer(version, aloneCore);
var reports = crashAnalyzer.AnalysisLogs();
var msg = string.Empty;
foreach (var report in reports)
{
msg += $"\n{report.CrashCauses}";
}
MessageBoxX.Show($"{MainLang.MinecraftCrash}\n{msg}", "Yu Minecraft Launcher");
}
});
};
watcher.OutputLogReceived += async (_, args) =>
{
Debug.WriteLine(args.Text);
Debug.WriteLine(args.Log);
await Dispatcher.BeginInvoke(() =>
{
//task.AppendText(args.Text, false);
taskProgress.InsertProgressText(args.Text, false);
taskProgress.InsertProgressText(args.Original, false);
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ public void Enabled()
WindowState = WindowState.Normal;
Show();
Activate();
Focus();
Topmost = true;
open = true;
}
public void Disabled()
{
WindowState = WindowState.Minimized;
Hide();
open = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<ui:ProgressBar x:Name="TaskProgressBar" Margin="8,0,11,0"/>
</DockPanel>
</Border>
<TextBox x:Name="TaskProgressTextBox" Margin="10,10,10,10" FontFamily="{DynamicResource Font}" IsReadOnly="True"/>
<TextBox x:Name="TaskProgressTextBox" Margin="10,10,10,10" FontFamily="{DynamicResource Font}" IsReadOnly="True" TextWrapping="Wrap"/>
</DockPanel>
</Grid>
</ui:ClippingBorder>
Expand Down
9 changes: 7 additions & 2 deletions YMCL.Main/YMCL.Main.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<DebugType>embedded</DebugType>
</PropertyGroup>

<ItemGroup>
<None Remove="Public\Text\DateTime.txt" />
</ItemGroup>

<ItemGroup>
<Page Remove="Public\Text\CustomHomePageDefault.xaml" />
<Page Update="UI\MusicPlayer\Main\MusicPlayer.xaml">
Expand All @@ -39,6 +43,7 @@
<EmbeddedResource Include="Public\Text\CustomHomePageDefault.xaml">
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
<EmbeddedResource Include="Public\Text\DateTime.txt" />
</ItemGroup>

<ItemGroup>
Expand All @@ -54,8 +59,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.9.27" />
<PackageReference Include="MinecraftLaunch" Version="3.0.7" />
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.9.28" />
<PackageReference Include="MinecraftLaunch" Version="3.1.0-preview02" />
<PackageReference Include="MinecraftLaunch.Skin" Version="1.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Panuon.WPF.UI" Version="1.2.1.2" />
Expand Down
81 changes: 69 additions & 12 deletions YMCL.Test/Program.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,83 @@
using MinecraftLaunch.Components.Fetcher;
using MinecraftLaunch.Components.Analyzer;
using MinecraftLaunch.Components.Fetcher;
using MinecraftLaunch.Components.Installer;
using MinecraftLaunch.Components.Resolver;

public class Program
{
public static async Task Main()
public static List<Tuple<string, List<string>>> ParseCommandLine(string commandLine)
{
using (var client = new HttpClient())
var parameters = new List<Tuple<string, List<string>>>();
var currentMethod = string.Empty;
var currentArgs = new List<string>();
var isInQuotes = false;
var argBuilder = new System.Text.StringBuilder();

foreach (var c in commandLine)
{
try
if (c == '"')
{
isInQuotes = !isInQuotes; // Toggle the quotes state
continue; // Skip the quote character
}

if (char.IsWhiteSpace(c) && !isInQuotes)
{
var response = await client.GetAsync("https://daiyu.fun/page/YmclComments/");
response.EnsureSuccessStatusCode();
string htmlContent = await response.Content.ReadAsStringAsync(); // 读取HTML内容
Console.WriteLine(htmlContent); // 输出HTML内容到控制台
// If we're not in quotes and encounter a whitespace, it might be the end of a method or argument
if (!string.IsNullOrEmpty(currentMethod))
{
// If we have a method name, add the current args list to the parameters
parameters.Add(Tuple.Create(currentMethod, currentArgs));
// Reset for the next method/argument
currentMethod = string.Empty;
currentArgs = new List<string>();
}
else if (argBuilder.Length > 0)
{
// If we don't have a method name but have built an argument, add it to the current args list
currentArgs.Add(argBuilder.ToString());
argBuilder.Clear();
}
// Otherwise, do nothing (it's just whitespace)
}
catch (HttpRequestException e)
else
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
// If we're here, we're either building a method name or an argument
if (string.IsNullOrEmpty(currentMethod) && !char.IsWhiteSpace(c))
{
// Start of a new method name
currentMethod = c.ToString();
}
else
{
// Building an argument or continuing a method name
argBuilder.Append(c);
}
}
}

Console.ReadKey();
// Add the last method and its arguments (if any)
if (!string.IsNullOrEmpty(currentMethod))
{
parameters.Add(Tuple.Create(currentMethod, currentArgs));
}
else if (argBuilder.Length > 0)
{
// If there's a leftover argument without a method name, it's an error or the input is malformed
// You can decide how to handle this case
throw new ArgumentException("Malformed command line: argument without a method name.");
}

return parameters;
}
public static async Task Main()
{
var commandLine = "--launch '1.20.1-Fabric 0.15.10' --close create 'some value' another_value --ey";
var parsedParameters = ParseCommandLine(commandLine);

foreach (var parameter in parsedParameters)
{
Console.WriteLine($"Method: {parameter.Item1}, Args: {string.Join(", ", parameter.Item2)}");
}
}
}
2 changes: 1 addition & 1 deletion YMCL.Test/YMCL.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MinecraftLaunch" Version="3.0.6" />
<PackageReference Include="MinecraftLaunch" Version="3.1.0-preview02" />
<PackageReference Include="MinecraftLaunch.Skin" Version="1.0.0" />
</ItemGroup>

Expand Down

0 comments on commit ccd7673

Please sign in to comment.