public MainWindow(Mutex mutex, out bool showUsrDiag) { // data router _mutex = mutex; br = new BindingRouter(env); // services if (!ApiVendor.TryPrepareRestApi()) { InlineLogic.ServerUnreachableLogic(); } showUsrDiag = SupportStatic.RemoteInitialize(br.ConfAutoUpdate); SupportStatic.InitializeAll(); pool = new DataPool(x => LoggingManagementService.WriteLine(x, "UplMgmt")); SubprocessManagementService.OnOverrideRequested += br.SaveConfig; LoggingManagementService.OnNewLogLine += br.DummyListener; TransmittingManagementService.OnDataOutput += pool.SinkData; TransmittingManagementService.OnDataOutput += LocalHandler; // user interface InitializeComponent(); InitializeWinformComponent(); CommandBindings.Add(new CommandBinding(BindingRouter.UiSearchLineEnterCommand, OnCommandLineEnter)); this.DataContext = br; #if DEBUG Title = "Milvaneth Prélude"; #endif // subviews ip = new ItemOverviewPage(br); sp = new SettingPage(br); lp = new LogPage(br); ap = new AboutPage(br); // custom message InlineLogic.GlobalMessageLogic(); if (!showUsrDiag) { ShowOverlay(); } // finish initialize if (br.ConfAutoAttach) { SubprocessManagementService.SpawnAll(out _); } if (!br.ConfNotUseHunter) { SubprocessManagementService.SpawnHunter(); } br.UiActiveTab = 3; MainFrame.Navigate(ap); }
public static void InitializeLogic() { try { if (!SupportStatic.FirstRunPrepare()) { MessageBox.Show( "无法找到初始数据文件\n\n请确保文件名近似 milinit_20190101.pack 的数据文件\n已经被下载并被放置于本软件的根目录下\n\n您通常可以在本软件的下载页面找到数据文件的下载链接", "初始化失败"); Environment.Exit(0); } } catch (Exception ex) { MessageBox.Show("软件初始化出现错误:\n" + ex, "初始化失败"); Environment.Exit(0); } try { if (!SupportStatic.CheckFileIntegrity()) { MessageBox.Show("文件完整性校验异常,请重新下载本程序或手动覆盖受损文件\n您可能需要手动删除数据文件夹", "初始化失败"); Environment.Exit(0); } } catch (Exception ex) { MessageBox.Show("软件缺少运行必要的文件,请重新下载安装本程序" + ex, "初始化失败"); Environment.Exit(0); } try { var exeName = "Milvaneth.Cmd.exe"; var proc = Process.GetCurrentProcess(); var path = proc.GetMainModuleFileName() ?? throw new InvalidOperationException("Current process has no main module"); var _exePath = Path.Combine(Path.GetDirectoryName(path), exeName); if (!(FirewallRegister.RegisterToFirewall(_exePath, "Milvaneth Core Component") && FirewallRegister.RegisterToFirewall(proc.GetMainModuleFileName(), "Milvaneth Client"))) { Task.Run(FirewallLogic); } } catch { Task.Run(FirewallLogic); } }
private void DoGracefulExit() { _mutex.ReleaseMutex(); _mutex.Close(); this.Hide(); ov?.Close(); br.SaveConfig(); SystemTrayIcon.Visible = false; SupportStatic.ExitAll(); Environment.Exit(0); }
private void OnStartup(object sender, StartupEventArgs e) { var initWindow = new Initializing(); initWindow.Show(); Logger.Initialize(false, false); InlineLogic.InitializeLogic(); var startMinimized = SupportStatic.RunMinimized(e.Args); var mainWindow = new MainWindow(_mutexwnd, out var hidden); initWindow.Close(); if (!startMinimized && !hidden) { mainWindow.Show(); mainWindow.Topmost = true; mainWindow.Topmost = false; } else { var am = new AccountManagement(); am.Show(); am.Topmost = true; am.Topmost = false; am.Closing += (o, args) => { if (!ApiVendor.HasToken()) { InlineLogic.NotLoggedInLogic(); Environment.Exit(0); } }; Task.Run(() => { while (!ApiVendor.HasToken()) { Thread.Sleep(1000); } if (Dispatcher?.CheckAccess() ?? true) { mainWindow.Show(); mainWindow.ShowOverlay(); mainWindow.Topmost = true; mainWindow.Topmost = false; return; } Dispatcher.Invoke(() => { mainWindow.Show(); mainWindow.ShowOverlay(); mainWindow.Topmost = true; mainWindow.Topmost = false; }); }); } }
public static void UpdateLogic(bool hideNoUpdateMessage = true, bool includeOptional = true) { var up = new UpdateProcedure(); var needUpdate = false; VersionInfo info = null; int ret; try { ret = up.Step1(out needUpdate, out info); } catch (HttpRequestException e) { ret = 02_0000 + (int)e.Data["StatusCode"]; } if (CheckVendor.NotValidResponseCode(ret)) { MessageBox.Show($"客户端检查更新失败:{MessageVendor.FormatError(ret)}", "Milvaneth 客户端更新"); return; } if (!needUpdate) { if (!hideNoUpdateMessage) { MessageBox.Show($"已经是最新版本", "Milvaneth 客户端更新"); } return; } if (!info.ForceUpdate) { if (!includeOptional) { return; } var result = MessageBox.Show( $"有可用新版本 {info.EligibleMilvanethVersion} (D-{info.EligibleDataVersion} / G-{info.EligibleGameVersion})\n" + $"版本说明:{info.DisplayMessage}\n" + "是否现在更新?", "Milvaneth 客户端更新", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) { return; } } else { Task.Run(() => MessageBox.Show( $"有可用新版本 {info.EligibleMilvanethVersion} (D-{info.EligibleDataVersion} / G-{info.EligibleGameVersion})\n" + $"版本说明:{info.DisplayMessage}\n" + "本版本为必要更新,将自动下载并安装更新\n请不要关闭或退出程序,程序将在更新完成后自动重启", "Milvaneth 客户端更新", MessageBoxButton.OK)); } VersionDownload download = null; try { ret = up.Step2(out download); } catch (HttpRequestException e) { ret = 02_0000 + (int)e.Data["StatusCode"]; } if (CheckVendor.NotValidResponseCode(ret)) { MessageBox.Show($"客户端下载更新失败:{MessageVendor.FormatError(ret)}", "Milvaneth 客户端更新"); return; } var patches = UpdateVendor.DownloadPatches(download, null); UpdateVendor.WaitAllFinish(patches); if (!info.ForceUpdate) { MessageBox.Show($"更新即将开始,请不要关闭或退出程序\n程序将在更新完成后自动重启", "Milvaneth 客户端更新"); } SupportStatic.ExitAll(); UpdateVendor.InvokeUpdateAndExitProgram(download, true); }