Пример #1
0
        public MainWindow()
        {
            try
            {
                _suppressEvents = true;

                // Initialize code -------------------------------------
                EnvironmentHelper.Initialize(_builtinLanguages);

                _mainGameExists = File.Exists(EnvironmentHelper.GameRootDirectory + ExecutableGame);
                _studioExists   = File.Exists(EnvironmentHelper.GameRootDirectory + ExecutableStudio);
                _studioExists   = File.Exists(EnvironmentHelper.GameRootDirectory + ExecutableVR);

                if (_studioExists)
                {
                    SettingManager.Initialize(EnvironmentHelper.GetConfigFilePath(), RegistryKeyGame, RegistryKeyStudio);
                }
                else
                {
                    SettingManager.Initialize(EnvironmentHelper.GetConfigFilePath(), RegistryKeyGame);
                }

                SettingManager.LoadSettings();

                // Initialize interface --------------------------------
                InitializeComponent();

                WindowStartupLocation = WindowStartupLocation.CenterScreen;
                CustomRes.Visibility  = Visibility.Hidden;

                if (string.IsNullOrEmpty((string)labelTranslated.Content))
                {
                    labelTranslated.Visibility       = Visibility.Hidden;
                    labelTranslatedBorder.Visibility = Visibility.Hidden;
                }

                if (!EnvironmentHelper.KKmanExist)
                {
                    gridUpdate.Visibility  = Visibility.Hidden;
                    gridManager.Visibility = Visibility.Hidden;
                }

                // Launcher Customization: Defining Warning, background and character
                if (!string.IsNullOrEmpty(EnvironmentHelper.VersionString))
                {
                    labelDist.Content = EnvironmentHelper.VersionString;
                }

                if (!string.IsNullOrEmpty(EnvironmentHelper.WarningString))
                {
                    warningText.Text = EnvironmentHelper.WarningString;
                }

                if (EnvironmentHelper.CustomCharacterImage != null)
                {
                    PackChara.Source = EnvironmentHelper.CustomCharacterImage;
                }
                if (EnvironmentHelper.CustomBgImage != null)
                {
                    appBG.ImageSource = EnvironmentHelper.CustomBgImage;
                }

                var primaryDisplay = Localizable.PrimaryDisplay;
                var subDisplay     = Localizable.SubDisplay;
                for (var i = 0; i < Screen.AllScreens.Length; i++)
                {
                    // 0 is primary
                    var newItem = i == 0 ? primaryDisplay : $"{subDisplay} : " + i;
                    dropDisplay.Items.Add(newItem);
                }

                KoikatsuStartup();
                PluginToggleManager.CreatePluginToggles(Toggleables);

                _suppressEvents = false;

                UpdateDisplaySettings(SettingManager.CurrentSettings.FullScreen);

                Closed    += (sender, args) => SettingManager.SaveSettings();
                MouseDown += (sender, args) => { if (args.ChangedButton == MouseButton.Left)
                                                 {
                                                     DragMove();
                                                 }
                };
                buttonClose.Click += (sender, args) => Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to start the launcher, please consider reporting this error to the developers.\n\nError that caused the crash: " + e, "Launcher crash", MessageBoxButtons.OK, MessageBoxIcon.Error);
                File.WriteAllText(Path.Combine(EnvironmentHelper.GameRootDirectory, "launcher_crash.log"), e.ToString());
                Close();
            }
        }