diff --git a/src/AppConfig.cs b/src/AppConfig.cs index 4d02fc4..afa77bd 100644 --- a/src/AppConfig.cs +++ b/src/AppConfig.cs @@ -7,7 +7,11 @@ public static class AppConfig { public static string GamePath { get; private set; } = null!; - internal static void Load() { + internal static void Load(string argumentPath) { + if (argumentPath == "auto" && File.Exists(argumentPath)) { + GamePath = argumentPath; + return; + } var pathCacheFile = new CacheFile("genshin_impact_game_path"); if (pathCacheFile.Exists()) { var path = pathCacheFile.Read().Content.ToStringUtf8(); diff --git a/src/Export.cs b/src/Export.cs index 8dfc92e..56e41e2 100644 --- a/src/Export.cs +++ b/src/Export.cs @@ -9,14 +9,19 @@ using static AchievementAllDataNotify.Types.Achievement.Types; namespace YaeAchievement; public static class Export { - + + public static uint ExportTo { get; set; } = uint.MaxValue; + public static void Choose(AchievementAllDataNotify data) { - Console.Write(App.ExportChoose); - while (Console.KeyAvailable) { - Console.ReadKey(false); + if (ExportTo == uint.MaxValue) { + Console.Write(App.ExportChoose); + while (Console.KeyAvailable) { + Console.ReadKey(false); + } + if (!uint.TryParse(Console.ReadLine(), out var num)) num = 0; + ExportTo = num; } - if (!int.TryParse(Console.ReadLine(), out var num)) num = 0; - ((Action) (num switch { + ((Action) (ExportTo switch { 1 => ToHuTao, 2 => ToPaimon, 3 => ToSeelie, diff --git a/src/Program.cs b/src/Program.cs index 7d55cc6..1342fb6 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -17,8 +17,10 @@ Console.WriteLine(App.AppBanner, GlobalVars.AppVersionName); Console.WriteLine(@"https://github.com/HolographicHat/YaeAchievement"); Console.WriteLine(@"----------------------------------------------------"); -AppConfig.Load(); -CheckUpdate(); +AppConfig.Load(args.GetOrNull(0) ?? "auto"); +Export.ExportTo = ToUIntOrNull(args.GetOrNull(1)) ?? uint.MaxValue; + +CheckUpdate(ToBooleanOrFalse(args.GetOrNull(2))); AppCenter.Init(); new EventLog("AppInit") { Properties = { diff --git a/src/Utils.cs b/src/Utils.cs index e5c7c51..76758a6 100644 --- a/src/Utils.cs +++ b/src/Utils.cs @@ -56,6 +56,18 @@ public static class Utils { } } + public static T? GetOrNull(this T[] array, uint index) where T : class { + return array.Length > index ? array[index] : null; + } + + public static uint? ToUIntOrNull(string? value) { + return value != null ? uint.TryParse(value, out var result) ? result : null : null; + } + + public static bool ToBooleanOrFalse(string? value) { + return value != null && bool.TryParse(value, out var result) && result; + } + public static void CopyToClipboard(string text) { if (Native.OpenClipboard(IntPtr.Zero)) { Native.EmptyClipboard(); @@ -71,7 +83,7 @@ public static class Utils { } } - public static void CheckUpdate() { + public static void CheckUpdate(bool useLocalLib) { var info = UpdateInfo.Parser.ParseFrom(GetBucketFileAsByteArray("schicksal/version"))!; if (GlobalVars.AppVersionCode != info.VersionCode) { Console.WriteLine(App.UpdateNewVersion, GlobalVars.AppVersionName, info.VersionName); @@ -89,7 +101,9 @@ public static class Utils { Environment.Exit(0); } } - if (info.EnableLibDownload) { + if (useLocalLib) { + File.Copy(GlobalVars.LibPath, Path.Combine(GlobalVars.AppPath, "YaeLib.dll")); + } else if (info.EnableLibDownload) { File.WriteAllBytes(GlobalVars.LibPath, GetBucketFileAsByteArray("schicksal/lib.dll")); } }