private void Application_Startup(object sender, StartupEventArgs e) { #region 检查环境 if ((System.Environment.Version.Major == 4) && (System.Environment.Version.Minor == 0)) { if ((!SystemTools.IsSetupFrameworkUpdate("KB2468871v2")) && (!SystemTools.IsSetupFrameworkUpdate("KB2468871"))) { var result = MessageBox.Show(GetResourceString("String.Message.NoFrameworkUpdate2"), GetResourceString("String.Message.NoFrameworkUpdate"), MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { System.Diagnostics.Process.Start("https://github.com/Nsiso/NsisoLauncher/wiki/%E5%90%AF%E5%8A%A8%E5%99%A8%E6%8A%A5%E9%94%99%EF%BC%9A%E5%BD%93%E5%89%8D%E7%94%B5%E8%84%91%E7%8E%AF%E5%A2%83%E7%BC%BA%E5%B0%91KB2468871v2%E8%A1%A5%E4%B8%81"); System.Environment.Exit(0); } } } #endregion #region DEBUG初始化 //debug logHandler = new LogHandler(true); AggregateExceptionCatched += (a, b) => logHandler.AppendFatal(b.AggregateException); if (e.Args.Contains("-debug")) { Windows.DebugWindow debugWindow = new Windows.DebugWindow(); debugWindow.Show(); logHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log); } #endregion config = new ConfigHandler(); #region DEBUG初始化(基于配置文件) if (config.MainConfig.Launcher.Debug && !e.Args.Contains("-debug")) { Windows.DebugWindow debugWindow = new Windows.DebugWindow(); debugWindow.Show(); logHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log); } #endregion #region 数据初始化 Config.Environment env = config.MainConfig.Environment; javaList = Java.GetJavaList(); //设置版本路径 string gameroot = null; switch (env.GamePathType) { case GameDirEnum.ROOT: gameroot = Path.GetFullPath(".minecraft"); break; case GameDirEnum.APPDATA: gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\.minecraft"; break; case GameDirEnum.PROGRAMFILES: gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\.minecraft"; break; case GameDirEnum.CUSTOM: gameroot = env.GamePath + "\\.minecraft"; break; default: throw new ArgumentException("判断游戏目录类型时出现异常,请检查配置文件中GamePathType节点"); } logHandler.AppendInfo("核心初始化->游戏根目录(默认则为空):" + gameroot); //设置JAVA Java java = null; if (env.AutoJava) { java = Java.GetSuitableJava(javaList); } else { java = javaList.Find(x => x.Path == env.JavaPath); if (java == null) { java = Java.GetJavaInfo(env.JavaPath); } } if (java != null) { env.JavaPath = java.Path; logHandler.AppendInfo("核心初始化->Java路径:" + java.Path); logHandler.AppendInfo("核心初始化->Java版本:" + java.Version); logHandler.AppendInfo("核心初始化->Java位数:" + java.Arch); } else { logHandler.AppendWarn("核心初始化失败,当前电脑未匹配到JAVA"); } //设置版本独立 bool verIso = config.MainConfig.Environment.VersionIsolation; #endregion #region 启动核心初始化 handler = new LaunchHandler(gameroot, java, verIso); handler.GameLog += (s, log) => logHandler.AppendLog(s, new Log() { LogLevel = LogLevel.GAME, Message = log }); #endregion #region 载核心初始化 ServicePointManager.DefaultConnectionLimit = 10; Download downloadCfg = config.MainConfig.Download; downloader = new MultiThreadDownloader(); if (!string.IsNullOrWhiteSpace(downloadCfg.DownloadProxyAddress)) { WebProxy proxy = new WebProxy(downloadCfg.DownloadProxyAddress, downloadCfg.DownloadProxyPort); if (!string.IsNullOrWhiteSpace(downloadCfg.ProxyUserName)) { NetworkCredential credential = new NetworkCredential(downloadCfg.ProxyUserName, downloadCfg.ProxyUserPassword); proxy.Credentials = credential; } downloader.Proxy = proxy; } downloader.ProcessorSize = App.config.MainConfig.Download.DownloadThreadsSize; downloader.DownloadLog += (s, log) => logHandler?.AppendLog(s, log); #endregion #region NIDE8核心初始化 if (!string.IsNullOrWhiteSpace(config.MainConfig.User.Nide8ServerID)) { nide8Handler = new Core.Net.Nide8API.APIHandler(config.MainConfig.User.Nide8ServerID); nide8Handler.UpdateBaseURL(); } #endregion #region 自定义主题初始化 var custom = config.MainConfig.Customize; if (!string.IsNullOrWhiteSpace(custom.AccentColor) && !string.IsNullOrWhiteSpace(custom.AppThme)) { logHandler.AppendInfo("自定义->更改主题颜色:" + custom.AccentColor); logHandler.AppendInfo("自定义->更改主题:" + custom.AppThme); ThemeManager.ChangeAppStyle(Current, ThemeManager.GetAccent(custom.AccentColor), ThemeManager.GetAppTheme(custom.AppThme)); } #endregion }
private void Application_Startup(object sender, StartupEventArgs e) { #region DEBUG初始化 //debug logHandler = new LogHandler(true); AggregateExceptionCatched += (a, b) => logHandler.AppendFatal(b.AggregateException); if (e.Args.Contains("-debug")) { Windows.DebugWindow debugWindow = new Windows.DebugWindow(); debugWindow.Show(); logHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log); } #endregion config = new ConfigHandler(); #region DEBUG初始化(基于配置文件) if (config.MainConfig.Launcher.Debug && !e.Args.Contains("-debug")) { Windows.DebugWindow debugWindow = new Windows.DebugWindow(); debugWindow.Show(); logHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log); } #endregion #region MineRealms反馈API初始化 #if DEBUG MineRealmsAPIHandler = new MineRealmsLauncherCore.Net.PhalAPI.APIHandler(true); #else MineRealmsAPIHandler = new MineRealmsLauncherCore.Net.PhalAPI.APIHandler(config.MainConfig.Launcher.NoTracking); #endif #endregion #region 数据初始化 Config.Environment env = config.MainConfig.Environment; javaList = Java.GetJavaList(); //设置版本路径 string gameroot = null; switch (env.GamePathType) { case GameDirEnum.ROOT: gameroot = Path.GetFullPath(".minecraft"); break; case GameDirEnum.APPDATA: gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\.minecraft"; break; case GameDirEnum.PROGRAMFILES: gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\.minecraft"; break; case GameDirEnum.CUSTOM: gameroot = env.GamePath + "\\.minecraft"; break; default: throw new ArgumentException("判断游戏目录类型时出现异常,请检查配置文件中GamePathType节点"); } logHandler.AppendInfo("核心初始化->游戏根目录(默认则为空):" + gameroot); //设置JAVA Java java = null; if (env.AutoJava) { java = Java.GetSuitableJava(javaList); } else { java = javaList.Find(x => x.Path == env.JavaPath); if (java == null) { java = Java.GetJavaInfo(env.JavaPath); } } if (java != null) { env.JavaPath = java.Path; logHandler.AppendInfo("核心初始化->Java路径:" + java.Path); logHandler.AppendInfo("核心初始化->Java版本:" + java.Version); logHandler.AppendInfo("核心初始化->Java位数:" + java.Arch); } else { logHandler.AppendWarn("核心初始化失败,当前电脑未匹配到JAVA"); } //设置版本独立 bool verIso = config.MainConfig.Environment.VersionIsolation; #endregion #region 启动核心初始化 handler = new LaunchHandler(gameroot, java, verIso); handler.GameLog += (s, log) => logHandler.AppendLog(s, new Log() { LogLevel = LogLevel.GAME, Message = log }); handler.LaunchLog += (s, log) => logHandler.AppendLog(s, log); #endregion #region 载核心初始化 ServicePointManager.DefaultConnectionLimit = 10; Download downloadCfg = config.MainConfig.Download; downloader = new MultiThreadDownloader(); if (!string.IsNullOrWhiteSpace(downloadCfg.DownloadProxyAddress)) { WebProxy proxy = new WebProxy(downloadCfg.DownloadProxyAddress, downloadCfg.DownloadProxyPort); if (!string.IsNullOrWhiteSpace(downloadCfg.ProxyUserName)) { NetworkCredential credential = new NetworkCredential(downloadCfg.ProxyUserName, downloadCfg.ProxyUserPassword); proxy.Credentials = credential; } downloader.Proxy = proxy; } downloader.ProcessorSize = App.config.MainConfig.Download.DownloadThreadsSize; downloader.CheckFileHash = App.config.MainConfig.Download.CheckDownloadFileHash; downloader.DownloadLog += (s, log) => logHandler?.AppendLog(s, log); #endregion #region 自定义主题初始化 var custom = config.MainConfig.Customize; if (!string.IsNullOrWhiteSpace(custom.AccentColor) && !string.IsNullOrWhiteSpace(custom.AppThme)) { logHandler.AppendInfo("自定义->更改主题颜色:" + custom.AccentColor); logHandler.AppendInfo("自定义->更改主题:" + custom.AppThme); ThemeManager.ChangeAppStyle(Current, ThemeManager.GetAccent(custom.AccentColor), ThemeManager.GetAppTheme(custom.AppThme)); } #endregion }
private void Application_Startup(object sender, StartupEventArgs e) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11; Process[] myProcesses = Process.GetProcessesByName("NsisoLauncher");//获取指定的进程名 bool self = false; foreach (var item in myProcesses) { if (item.MainModule.FileName == AppDomain.CurrentDomain.BaseDirectory + AppDomain.CurrentDomain.FriendlyName) { if (self == false) { self = true; } else { SetForegroundWindow(item.MainWindowHandle); Shutdown(); } } } LogHandler = new LogHandler(true); Config = new ConfigHandler(); EnvironmentObj env = Config.MainConfig.Environment; JavaList = Java.GetJavaList(); AggregateExceptionCatched += (a, b) => LogHandler.AppendFatal(b.AggregateException); if (Config.MainConfig.Launcher.Debug || e.Args.Contains("-debug")) { DebugWindow debugWindow = new DebugWindow(); debugWindow.Show(); LogHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log); } nsisoAPIHandler = new APIHandler(Config.MainConfig.Launcher.NoTracking); //设置版本路径 string gameroot = null; switch (env.GamePathType) { case GameDirEnum.ROOT: gameroot = Path.GetFullPath(".minecraft"); break; case GameDirEnum.APPDATA: gameroot = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\.minecraft"; break; case GameDirEnum.PROGRAMFILES: gameroot = System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\.minecraft"; break; case GameDirEnum.CUSTOM: gameroot = env.GamePath + "\\.minecraft"; break; default: throw new ArgumentException("判断游戏目录类型时出现异常,请检查配置文件中GamePathType节点"); } LogHandler.AppendInfo("核心初始化->游戏根目录(默认则为空):" + gameroot); //设置JAVA Java java; if (env.AutoJava) { java = Java.GetSuitableJava(JavaList); } else { java = JavaList.Find(x => x.Path == env.JavaPath); if (java == null) { java = Java.GetJavaInfo(env.JavaPath); } } if (java != null) { env.JavaPath = java.Path; LogHandler.AppendInfo("核心初始化->Java路径:" + java.Path); LogHandler.AppendInfo("核心初始化->Java版本:" + java.Version); LogHandler.AppendInfo("核心初始化->Java位数:" + java.Arch); } else { LogHandler.AppendWarn("核心初始化失败,当前电脑未匹配到JAVA"); } bool verIso = Config.MainConfig.Environment.VersionIsolation; Handler = new LaunchHandler(gameroot, java, verIso); Handler.GameLog += (s, log) => LogHandler.AppendLog(s, new Log() { LogLevel = LogLevel.GAME, Message = log }); Handler.LaunchLog += (s, log) => LogHandler.AppendLog(s, log); ServicePointManager.DefaultConnectionLimit = 10; Downloader = new MultiThreadDownloader(); ProxyRe(); Downloader.ProcessorSize = Config.MainConfig.Download.DownloadThreadsSize; Downloader.CheckFileHash = Config.MainConfig.Download.CheckDownloadFileHash; Downloader.DownloadLog += (s, log) => LogHandler?.AppendLog(s, log); var custom = Config.MainConfig.Customize; if (!string.IsNullOrWhiteSpace(custom.AppThme)) { LogHandler.AppendInfo("自定义->更改主题:" + custom.AppThme); ThemeManager.Current.ChangeTheme(Current, custom.AppThme); } Lauguage(); }
private void Application_Startup(object sender, StartupEventArgs e) { #region DEBUG初始化 //debug LogHandler = new LogHandler(true); AggregateExceptionCatched += (a, b) => LogHandler.AppendFatal(b.AggregateException); if (e.Args.Contains("-debug")) { DebugWindow debugWindow = new DebugWindow(); debugWindow.Show(); LogHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log); } #endregion #region 从旧版本跳转 String[] args = System.Environment.GetCommandLineArgs(); if (args.Length == 2) { //关闭并删除旧版本 Task.Run(() => { Process oldLauncher = Process.GetProcessById(Convert.ToInt32(args[1])); string oldLauncherPath = oldLauncher.MainModule.FileName; oldLauncher.Kill(); oldLauncher.WaitForExit(); File.Delete(oldLauncherPath); }); } #endregion Config = new ConfigHandler(); #region DEBUG初始化(基于配置文件) if (Config.MainConfig.Launcher.Debug && !e.Args.Contains("-debug")) { DebugWindow debugWindow = new DebugWindow(); debugWindow.Show(); LogHandler.OnLog += (s, log) => debugWindow?.AppendLog(s, log); } #endregion #region Nsiso反馈API初始化 #if DEBUG NsisoAPIHandler = new NsisoLauncherCore.Net.PhalAPI.APIHandler(true); #else NsisoAPIHandler = new NsisoLauncherCore.Net.PhalAPI.APIHandler(Config.MainConfig.Launcher.NoTracking); #endif #endregion #region 数据初始化 Config.Environment env = Config.MainConfig.Environment; JavaList = Java.GetJavaList(); //设置版本路径 string gameroot = null; switch (env.GamePathType) { case GameDirEnum.ROOT: gameroot = Path.GetFullPath(".minecraft"); break; case GameDirEnum.APPDATA: gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\.minecraft"; break; case GameDirEnum.PROGRAMFILES: gameroot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\.minecraft"; break; case GameDirEnum.CUSTOM: gameroot = env.GamePath + "\\.minecraft"; break; default: throw new ArgumentException("判断游戏目录类型时出现异常,请检查配置文件中GamePathType节点"); } LogHandler.AppendInfo("核心初始化->游戏根目录(默认则为空):" + gameroot); //设置JAVA Java java = null; if (env.AutoJava) { java = Java.GetSuitableJava(JavaList); } else { java = JavaList.Find(x => x.Path == env.JavaPath); if (java == null) { java = Java.GetJavaInfo(env.JavaPath); } } if (java != null) { env.JavaPath = java.Path; LogHandler.AppendInfo("核心初始化->Java路径:" + java.Path); LogHandler.AppendInfo("核心初始化->Java版本:" + java.Version); LogHandler.AppendInfo("核心初始化->Java位数:" + java.Arch); } else { LogHandler.AppendWarn("核心初始化失败,当前电脑未匹配到JAVA"); } //设置版本独立 bool verIso = Config.MainConfig.Environment.VersionIsolation; #endregion #region 启动核心初始化 Handler = new LaunchHandler(gameroot, java, verIso); Handler.GameLog += (s, log) => LogHandler.AppendLog(s, new Log() { LogLevel = LogLevel.GAME, Message = log }); Handler.LaunchLog += (s, log) => LogHandler.AppendLog(s, log); #endregion #region 载核心初始化 ServicePointManager.DefaultConnectionLimit = 10; Download downloadCfg = Config.MainConfig.Download; Downloader = new MultiThreadDownloader(); if (!string.IsNullOrWhiteSpace(downloadCfg.DownloadProxyAddress)) { WebProxy proxy = new WebProxy(downloadCfg.DownloadProxyAddress, downloadCfg.DownloadProxyPort); if (!string.IsNullOrWhiteSpace(downloadCfg.ProxyUserName)) { NetworkCredential credential = new NetworkCredential(downloadCfg.ProxyUserName, downloadCfg.ProxyUserPassword); proxy.Credentials = credential; } Downloader.Proxy = proxy; } Downloader.ProcessorSize = App.Config.MainConfig.Download.DownloadThreadsSize; Downloader.CheckFileHash = App.Config.MainConfig.Download.CheckDownloadFileHash; Downloader.DownloadLog += (s, log) => LogHandler?.AppendLog(s, log); #endregion #region 自定义主题初始化 var custom = Config.MainConfig.Customize; if (!string.IsNullOrWhiteSpace(custom.AccentColor) && !string.IsNullOrWhiteSpace(custom.AppThme)) { LogHandler.AppendInfo("自定义->更改主题颜色:" + custom.AccentColor); LogHandler.AppendInfo("自定义->更改主题:" + custom.AppThme); ThemeManager.ChangeAppStyle(Current, ThemeManager.GetAccent(custom.AccentColor), ThemeManager.GetAppTheme(custom.AppThme)); } #endregion #region 读取版本 VersionList = new ObservableCollection <Version>(); RefreshVersionList(); #endregion }
private async void Page_Loaded(object sender, RoutedEventArgs e) { this.Resources.Remove("PrimaryHueMidBrush"); this.Resources.Add("PrimaryHueMidBrush", new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(Settings.PrimaryHueMidBrush))); this.Resources.Remove("PrimaryHueLightBrush"); this.Resources.Add("PrimaryHueLightBrush", new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(Settings.PrimaryHueLightBrush))); this.Resources.Remove("PrimaryHueDarkBrush"); this.Resources.Add("PrimaryHueDarkBrush", new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(Settings.PrimaryHueDarkBrush))); if (IsLoading) { return; } #region Update Label1.Content = "检查更新"; try { await Task.Run(() => { WebClient webClient = new WebClient(); string[] a; if (App.version.Contains("Pre")) { a = Encoding.UTF8.GetString(webClient.DownloadData("http://api.axing6.cn/debug.html")).Split('#'); } else { a = Encoding.UTF8.GetString(webClient.DownloadData("http://api.axing6.cn/api.html")).Split('#'); } if (a[0] != App.version) { this.Dispatcher.BeginInvoke(new Action(() => { this.NavigationService.Navigate(new Page3()); })); } webClient.Dispose(); }); } catch { Label1.Content = "检查更新失败"; } #endregion #region JSON Label1.Content = "检查配置文件"; if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\.XMCL")) { } else { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\.XMCL"); } if (System.IO.File.Exists(System.IO.Directory.GetCurrentDirectory() + "\\XMCL.json")) { } else { FileStream fs1 = new FileStream(System.Environment.CurrentDirectory + "\\XMCL.json", FileMode.Create, FileAccess.ReadWrite); try { fs1.Write(XMCL.Properties.Resources.XMCL, 0, XMCL.Properties.Resources.XMCL.Length); fs1.Flush(); fs1.Close(); } catch (Exception ex) { throw ex; } } if (Settings.JavaPath == null || Settings.JavaPath.Length == 0) { List <string> vs = Java.GetJavaList(); if (vs != null) { Json.Write("Files", "JavaPath", vs[0]); } } if (Json.ReadPaths().Count == 0) { Json.AddPath("官方启动器", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\.minecraft", "Grass_Block", false); } if (Settings.GamePathName.Length == 0) { Json.Write("Files", "GamePathName", Newtonsoft.Json.Linq.JObject.Parse(Json.ReadPaths()[0].ToString())["Name"].ToString()); } Json.ChangePath("官方启动器", "Path", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\.minecraft"); ComboBox C1 = MainWindow.ComboBox; C1.ItemsSource = SomethingUseful.GetVersions(Settings.GamePath); if (Settings.LatestVerison.Contains(" ")) { string[] vs = Settings.LatestVerison.Split(' '); if (vs[0] == Settings.GamePath) { for (int i = 0; i < C1.Items.Count; i++) { if (C1.Items[i].ToString() == vs[1]) { C1.SelectedIndex = i; } } } } #endregion #region Timer Label1.Content = "开启性能检查器"; await Task.Run(() => { MainWindow.performance = new Performance(); MainWindow.timer = new System.Timers.Timer(); MainWindow.timer.Elapsed += MainWindow.Timer_Elapsed; MainWindow.timer.Enabled = true; MainWindow.timer.Interval = 1500; MainWindow.timer.Start(); }); #endregion Label1.Content = "检查账户"; MainWindow.Login(); this.NavigationService.Navigate(null); }