mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-15 10:58:13 +08:00
Add AppConfig
This commit is contained in:
41
src/AppConfig.cs
Normal file
41
src/AppConfig.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace YaeAchievement;
|
||||||
|
|
||||||
|
public class AppConfig {
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "location")]
|
||||||
|
public string? Location { get; set; }
|
||||||
|
|
||||||
|
private static AppConfig? _instance;
|
||||||
|
|
||||||
|
private static readonly string FileName = Path.Combine(GlobalVars.AppPath, "conf.json");
|
||||||
|
|
||||||
|
public static string GamePath => _instance!.Location!;
|
||||||
|
|
||||||
|
internal static void Load() {
|
||||||
|
if (File.Exists(FileName)) {
|
||||||
|
var text = File.ReadAllText(FileName);
|
||||||
|
_instance = JsonConvert.DeserializeObject<AppConfig>(text)!;
|
||||||
|
}
|
||||||
|
if (_instance?.Location == null || !Utils.CheckGamePathValid(_instance.Location)) {
|
||||||
|
var gameInstallPath = Utils.FindGamePathFromRegistry();
|
||||||
|
if (!string.IsNullOrEmpty(gameInstallPath)) {
|
||||||
|
Console.WriteLine($"自动读取到游戏路径: {gameInstallPath}");
|
||||||
|
Console.WriteLine($"如果确认路径无误,请按 Y ;若有误或需要自行选择,请按 N ");
|
||||||
|
var key = Console.ReadKey().Key;
|
||||||
|
gameInstallPath = key == ConsoleKey.Y ? gameInstallPath : Utils.SelectGameExecutable();
|
||||||
|
} else {
|
||||||
|
gameInstallPath = Utils.SelectGameExecutable();
|
||||||
|
}
|
||||||
|
_instance = new AppConfig {
|
||||||
|
Location = gameInstallPath
|
||||||
|
};
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Save() {
|
||||||
|
File.WriteAllText(FileName, JsonConvert.SerializeObject(_instance!, Formatting.Indented));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,6 @@ public static class GlobalVars {
|
|||||||
public static bool DebugProxy = false;
|
public static bool DebugProxy = false;
|
||||||
public static bool CheckGamePath = true;
|
public static bool CheckGamePath = true;
|
||||||
public static bool UnexpectedExit = true;
|
public static bool UnexpectedExit = true;
|
||||||
public static string GamePath = null!;
|
|
||||||
public static Version AppVersion = Assembly.GetEntryAssembly()!.GetName().Version!;
|
public static Version AppVersion = Assembly.GetEntryAssembly()!.GetName().Version!;
|
||||||
public static readonly string AppPath = AppDomain.CurrentDomain.BaseDirectory;
|
public static readonly string AppPath = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
|
|
||||||
@@ -21,6 +20,5 @@ public static class GlobalVars {
|
|||||||
public const string LibName = "YaeLib.dll";
|
public const string LibName = "YaeLib.dll";
|
||||||
public const string PipeName = "YaeAchievementPipe";
|
public const string PipeName = "YaeAchievementPipe";
|
||||||
public const string BucketHost = "https://cn-cd-1259389942.file.myqcloud.com";
|
public const string BucketHost = "https://cn-cd-1259389942.file.myqcloud.com";
|
||||||
public const string ConfigFileName = "YaeAchievement.runtimeconfig.json";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user