コード例 #1
0
        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
        }
コード例 #2
0
        //保存按钮点击后
        private async void saveButton_Click(object sender, RoutedEventArgs e)
        {
            switch (App.Config.MainConfig.Environment.GamePathType)
            {
            case GameDirEnum.ROOT:
                App.Handler.GameRootPath = Path.GetFullPath(".minecraft");
                break;

            case GameDirEnum.APPDATA:
                App.Handler.GameRootPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\.minecraft";
                break;

            case GameDirEnum.PROGRAMFILES:
                App.Handler.GameRootPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\.minecraft";
                break;

            case GameDirEnum.CUSTOM:
                App.Handler.GameRootPath = App.Config.MainConfig.Environment.GamePath + "\\.minecraft";
                break;

            default:
                throw new ArgumentException(App.GetResourceString("String.Settingwindow.Message.GamePathType.Error"));
            }
            App.Handler.VersionIsolation = App.Config.MainConfig.Environment.VersionIsolation;
            App.Downloader.CheckFileHash = App.Config.MainConfig.Download.CheckDownloadFileHash;

            if (_isGameSettingChanged)
            {
                if (App.Config.MainConfig.Environment.VersionIsolation)
                {
                    await GameHelper.SaveOptionsAsync(VersionOption.Type.options,
                                                      versionOptionsGrid.ItemsSource as List <VersionOption>,
                                                      App.Handler,
                                                      VersionsComboBox.SelectedItem as MCVersion);

                    await GameHelper.SaveOptionsAsync(VersionOption.Type.optionsof,
                                                      versionOptionsofGrid.ItemsSource as List <VersionOption>,
                                                      App.Handler,
                                                      VersionsComboBox.SelectedItem as MCVersion);
                }
                else
                {
                    await GameHelper.SaveOptionsAsync(VersionOption.Type.options,
                                                      versionOptionsGrid.ItemsSource as List <VersionOption>,
                                                      App.Handler,
                                                      new() { ID = "null" });

                    await GameHelper.SaveOptionsAsync(VersionOption.Type.optionsof,
                                                      versionOptionsofGrid.ItemsSource as List <VersionOption>,
                                                      App.Handler,
                                                      new() { ID = "null" });
                }
            }

            App.Config.Save();
            App.ProxyRe();

            saveButton.Content = App.GetResourceString("String.Settingwindow.Saving");
            EnvironmentObj env  = App.Config.MainConfig.Environment;
            Java           java = null;

            if (env.AutoJava)
            {
                java = Java.GetSuitableJava(App.JavaList);
            }
            else
            {
                java = App.JavaList.Find(x => x.Path == env.JavaPath);
                if (java == null)
                {
                    java = Java.GetJavaInfo(env.JavaPath);
                }
            }
            if (java != null)
            {
                App.Handler.Java = java;
                Close();
            }
            else
            {
                await this.ShowMessageAsync(App.GetResourceString("String.Settingwindow.SaveError"),
                                            App.GetResourceString("String.Settingwindow.JavaError"));
            }
        }
コード例 #3
0
        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
        }
コード例 #4
0
        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
        }
コード例 #5
0
ファイル: App.xaml.cs プロジェクト: Coloryr/NsisoLauncher
        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();
        }