diff --git a/App.axaml b/App.axaml index d182648..90c5fca 100644 --- a/App.axaml +++ b/App.axaml @@ -2,12 +2,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="toast_mcl.App" xmlns:sty="using:FluentAvalonia.Styling" - RequestedThemeVariant="Dark" - > + RequestedThemeVariant="Dark"> - diff --git a/MainWindow.axaml b/MainWindow.axaml index d32dde7..1f618ee 100644 --- a/MainWindow.axaml +++ b/MainWindow.axaml @@ -8,11 +8,6 @@ Title="toast_mcl"> - - - - - @@ -40,7 +35,6 @@ - diff --git a/Pages/About.axaml b/Pages/About.axaml index b478889..43002a8 100644 --- a/Pages/About.axaml +++ b/Pages/About.axaml @@ -1,5 +1,6 @@ - This is About + + diff --git a/Program.cs b/Program.cs index bca458c..13c8b3d 100644 --- a/Program.cs +++ b/Program.cs @@ -1,23 +1,31 @@ -using Avalonia; +using Avalonia; using System; using System.Runtime.InteropServices; +using toast_mcl; namespace toast_mcl { internal class Program { - // Initialization code. Don't use any Avalonia, third-party APIs or any - // SynchronizationContext-reliant code before AppMain is called: things aren't initialized - // yet and stuff might break. + // 初始化代码。 + // 在调用AppMain之前,请不要使用任何Avalonia、第三方API或任何依赖于SynchronizationContext的代码: + // 因为这些东西尚未初始化,可能会导致错误。 [STAThread] - public static void Main(string[] args) => BuildAvaloniaApp() - .StartWithClassicDesktopLifetime(args); + public static void Main(string[] args) + { + Base.Init(); - // Avalonia configuration, don't remove; also used by visual designer. + BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + } + + // Avalonia配置,请勿删除;也被可视化设计器使用。 public static AppBuilder BuildAvaloniaApp() - => AppBuilder.Configure() + { + return AppBuilder.Configure() .UsePlatformDetect() .WithFont_LXGWWenKai() .LogToTrace(); + } } } diff --git a/Programs/Base.cs b/Programs/Base.cs new file mode 100644 index 0000000..0a46238 --- /dev/null +++ b/Programs/Base.cs @@ -0,0 +1,26 @@ +using System; +using toast_mcl.Programs; + +namespace toast_mcl; + +public static class Base +{ + // 版本号处理 + public enum VersionTypes + { + Alpha, + Beta, + Release + } + public static VersionTypes VersionType = VersionTypes.Alpha; + public static Version Version = new Version(0, 0, 1); + + // 获取程序目录 + public static string AppDirectory = AppDomain.CurrentDomain.BaseDirectory; + + // 初始化 + public static void Init() + { + ConfigUtils.Init(); + } +} \ No newline at end of file diff --git a/Programs/Config/ConfigSettings.cs b/Programs/Config/ConfigSettings.cs new file mode 100644 index 0000000..c60d11f --- /dev/null +++ b/Programs/Config/ConfigSettings.cs @@ -0,0 +1,15 @@ +using System; +using toast_mcl; + +namespace toast_mcl.Config; + +public class ConfigSettings +{ + public AppSettings ?AppSettings { get; set; } +} + +public class AppSettings +{ + public Version Version { get; set; } = Base.Version; + public string VersionType { get; set; } = Base.VersionType.ToString(); +} \ No newline at end of file diff --git a/Programs/Config/ConfigUtils.cs b/Programs/Config/ConfigUtils.cs new file mode 100644 index 0000000..60d3b55 --- /dev/null +++ b/Programs/Config/ConfigUtils.cs @@ -0,0 +1,60 @@ +using System.Linq; +using System.IO; +using Newtonsoft.Json; +using toast_mcl.Config; + +namespace toast_mcl.Programs; +public static class ConfigUtils +{ + public static ConfigSettings ?Settings { get; private set;} + + private static readonly string ConfigFolderPath = Path.Combine(Base.AppDirectory, "toast_mc"); + private static readonly string ConfigFilePath = Path.Combine(ConfigFolderPath, "config.json"); + + public static void Init() + { + if (!Directory.Exists(ConfigFolderPath)) + { + Directory.CreateDirectory(ConfigFolderPath); + } + if (!File.Exists(ConfigFilePath)) + { + CreateDefaultConfig(); + } + } + private static void CreateDefaultConfig() + { + Settings = DefaultConfig.GetDefaultConfig(); + SaveConfig(); + } + public static void LoadConfig() + { + if (File.Exists(ConfigFilePath)) + { + string configJson = File.ReadAllText(ConfigFilePath); + Settings = JsonConvert.DeserializeObject(configJson); + } + else + { + CreateDefaultConfig(); + } + + var ConfigVersion = Settings?.AppSettings?.Version; + if (ConfigVersion != Base.Version) + { + var oldSettings = Settings; + UpdateConfig(); + } + } + + private static void UpdateConfig() + { + + } + + public static void SaveConfig() + { + string configJson = JsonConvert.SerializeObject(Settings, Formatting.Indented); + File.WriteAllText(ConfigFilePath, configJson); + } +} \ No newline at end of file diff --git a/Programs/Config/DefaultConfig.cs b/Programs/Config/DefaultConfig.cs new file mode 100644 index 0000000..f1b51dc --- /dev/null +++ b/Programs/Config/DefaultConfig.cs @@ -0,0 +1,20 @@ +using System; +using toast_mcl; + +namespace toast_mcl.Config; + +public static class DefaultConfig +{ + public static ConfigSettings GetDefaultConfig() + { + + return new ConfigSettings + { + AppSettings = new AppSettings + { + Version = Base.Version, + VersionType = Base.VersionType.ToString() + }, + }; + } +} \ No newline at end of file diff --git a/toast_mcl.csproj b/toast_mcl.csproj index 4448d20..0982111 100644 --- a/toast_mcl.csproj +++ b/toast_mcl.csproj @@ -25,6 +25,8 @@ + +