|
14 | 14 | using LMC.Account; |
15 | 15 | using LMC.Pages; |
16 | 16 | using LMC.Utils; |
| 17 | +using System.Reflection.Emit; |
17 | 18 |
|
18 | 19 | namespace LMC |
19 | 20 | { |
@@ -46,26 +47,107 @@ public MainWindow() |
46 | 47 | InitializeComponent(); |
47 | 48 | s_background = BackGround; |
48 | 49 | MainFrame = MainFrm; |
| 50 | + double width; |
| 51 | + if(double.TryParse(Config.ReadGlobal("window", "width"), out width)) |
| 52 | + { |
| 53 | + this.Width = width; |
| 54 | + } |
| 55 | + double height; |
| 56 | + if (double.TryParse(Config.ReadGlobal("window", "height"), out height)) |
| 57 | + { |
| 58 | + this.Height = height; |
| 59 | + } |
49 | 60 | if (File.Exists($"./LMC/update.bat")) |
50 | 61 | { |
51 | 62 | File.Delete($"./LMC/update.bat"); |
52 | | - ShowDialog("确认", $"更新成功,可以关闭CMD命令行窗口,LMC已更新至{App.LauncherVersion}-{App.LauncherVersionType},构建号{App.LauncherBuildVersion}", "提示"); |
| 63 | + ShowDialog("确认", $"更新成功,可以关闭CMD命令行窗口,LMC已更新至{App.LauncherVersion}-{App.LauncherVersionType},构建号{App.LauncherBuildVersion},更新内容:\n{App.LauncherUpdateLog}", "提示"); |
53 | 64 | } |
54 | 65 | Secrets.GetDeviceCode(); |
55 | 66 | var accounts = AccountManager.GetAccounts(false).Result; |
56 | | - foreach ( var account in accounts) |
| 67 | + foreach (var account in accounts) |
57 | 68 | { |
58 | | - if(account.Type == AccountType.MSA) |
| 69 | + if (account.Type == AccountType.MSA) |
59 | 70 | { |
60 | | - AccountManager.GetAvatarAsync(account,64); |
| 71 | + AccountManager.GetAvatarAsync(account, 64); |
61 | 72 | } |
62 | 73 | } |
| 74 | + this.Loaded += MainWindow_Loaded; |
| 75 | + this.SizeChanged += MainWindow_SizeChanged; |
63 | 76 | } |
64 | 77 | catch { |
65 | 78 | Environment.Exit(1); |
66 | 79 | } |
67 | 80 | } |
68 | 81 |
|
| 82 | + private void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e) |
| 83 | + { |
| 84 | + double width = this.ActualWidth; |
| 85 | + double height = this.ActualHeight; |
| 86 | + Config.WriteGlobal("window", "width", width.ToString()); |
| 87 | + Config.WriteGlobal("window", "height", height.ToString()); |
| 88 | + } |
| 89 | + |
| 90 | + private async void MainWindow_Loaded(object sender, RoutedEventArgs e) |
| 91 | + { |
| 92 | + s_logger.Info("正在检查更新"); |
| 93 | + try |
| 94 | + { |
| 95 | + var ver = await UpdateChecker.Check(); |
| 96 | + |
| 97 | + if (ver == null) |
| 98 | + { |
| 99 | + throw new Exception("检查更新失败,版本为空"); |
| 100 | + } |
| 101 | + if (ver.Type == App.LauncherVersionType && ver.Version == App.LauncherVersion && ver.Build == App.LauncherBuildVersion) { |
| 102 | + s_logger.Info("当前是最新版"); |
| 103 | + return; |
| 104 | + } |
| 105 | + if (!ver.SecurityOrEmergency) |
| 106 | + { |
| 107 | + var res = await ShowDialog("取消", $"发现新的非紧急更新版!\n版本号:{ver.Version}\n类型:{ver.Type}\n构建号:{ver.Build}", "更新", ContentDialogButton.Primary, "更新"); |
| 108 | + if (res == ContentDialogResult.Primary) |
| 109 | + { |
| 110 | + try |
| 111 | + { |
| 112 | + await UpdateChecker.Update(ver); |
| 113 | + } |
| 114 | + catch (Exception ex) |
| 115 | + { |
| 116 | + new Logger("MW-UPD").Error($"更新失败:{ex.Message}\n{ex.StackTrace}"); |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + else |
| 121 | + { |
| 122 | + ContentDialog dialog = new ContentDialog(); |
| 123 | + dialog.Title = "更新"; |
| 124 | + dialog.Content = $"发现新的紧急更新版!\n版本号:{ver.Version}\n类型:{ver.Type}\n构建号:{ver.Build}"; |
| 125 | + dialog.PrimaryButtonText = "更新"; |
| 126 | + dialog.DefaultButton = ContentDialogButton.Primary; |
| 127 | + dialog.PrimaryButtonClick += async (s, e) => |
| 128 | + { |
| 129 | + try |
| 130 | + { |
| 131 | + await UpdateChecker.Update(ver); |
| 132 | + } |
| 133 | + catch (Exception ex) |
| 134 | + { |
| 135 | + new Logger("AP-UPD").Error($"更新失败:{ex.Message}\n{ex.StackTrace}"); |
| 136 | + } |
| 137 | + }; |
| 138 | + dialog.ShowAsync(); |
| 139 | + |
| 140 | + } |
| 141 | + } |
| 142 | + catch (Exception ex) |
| 143 | + { |
| 144 | + s_logger.Error("更新检查失败:" + ex.Message + "\n" + ex.StackTrace); |
| 145 | + ShowDialog("确认", $"更新检查失败:{ex.Message}\n{ex.StackTrace}", "错误"); |
| 146 | + } |
| 147 | + |
| 148 | + } |
| 149 | + |
| 150 | + |
69 | 151 | public static void AddAccPage() |
70 | 152 | { |
71 | 153 | MainFrame.Navigate(AddAccountPage); |
|
0 commit comments