Exemplo n.º 1
0
        private void ctlMainForm_Load(object sender, EventArgs e)
        {
            Logging.Log.Debug("Loading main window.");

            Rectangle primaryScreenSize = Screen.PrimaryScreen.Bounds;

            Logging.Log.DebugFormat("Primary screen size is {0}x{1}",
                                    primaryScreenSize.Width, primaryScreenSize.Height);

            int maxWidth = Math.Min(primaryScreenSize.Width, DfoLauncher.GetWidthFromHeight(primaryScreenSize.Height));

            ctlWindowSizeSlider.Minimum = DfoLauncher.DefaultGameWindowWidth;
            ctlWindowSizeSlider.Maximum = Math.Max(maxWidth, DfoLauncher.DefaultGameWindowWidth);

            Logging.Log.DebugFormat("Allowable game window width: {0}-{1}",
                                    ctlWindowSizeSlider.Minimum, ctlWindowSizeSlider.Maximum);

            // Initialize window size UI
            ctlWindowSizeSlider_ValueChanged(ctlWindowSizeSlider, EventArgs.Empty);

            // Bind switchable files to checkboxes
            IDictionary <string, CheckBox> switchableFileCheckboxes = GetSwitchableCheckboxes();

            foreach (ISwitchableFile switchableFile in m_parsedArgs.Settings.SwitchableFiles.Values)
            {
                if (switchableFileCheckboxes.ContainsKey(switchableFile.Name))
                {
                    SwitchableFiles.Add(switchableFile.Name,
                                        new CheckboxSwitchableFile(switchableFileCheckboxes[switchableFile.Name],
                                                                   switchableFile));
                }
                else
                {
                    // Hmmm...No UI binding for a switchable file. Add it as a switchable file and let
                    // setting/command-line behavior take effect.
                    SwitchableFiles.Add(switchableFile.Name, new PlainUiSwitchableFile(switchableFile));
                }
            }

            m_savedSettings = SettingsLoader.Load();
            ApplySettingsAndArguments();

            FixSwitchableFilesIfNeeded();

            ctlUsername.Select();
            Logging.Log.Debug("Main window loaded.");
        }
Exemplo n.º 2
0
        private void ctlMainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (m_launcher.State == LaunchState.GameInProgress && m_launcher.Params.FilesToSwitch.Count > 0)
            {
                DisplayError("You cannot close this program while the game is in progress if you chose to switch any files. You must wait until the game finishes so the files can be switched back.",
                             "Sorry, you can't exit yet");
                e.Cancel = true;
                return;
            }

            Logging.Log.Debug("Main window closing.");

            m_launcherThreadCanceledEvent.Set();
            if (m_launcherThread != null)
            {
                Logging.Log.Debug("Waiting for launcher thread to end.");
                m_launcherThread.Join();
                Logging.Log.Debug("Launcher thread joined.");
            }

            SettingsLoader.Save(GetCurrentSettings());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Applies the command-line arguments and saved settings to the form's properties.
        /// Command-line arguments take precedence, following by saved settings, followed by a default.
        /// </summary>
        private void ApplySettingsAndArguments()
        {
            Logging.Log.Debug("Applying settings and arguments.");

            SettingsLoader.ApplySettingStruct(m_parsedArgs.Settings.ClosePopup, m_savedSettings.ClosePopup, null,
                                              "Close popup", ( bool closePopup ) => ClosePopup = closePopup, m_launcher.Params.ClosePopup,
                                              SensitiveData.None);

            SettingsLoader.ApplySettingStruct(m_parsedArgs.Settings.LaunchWindowed, m_savedSettings.LaunchWindowed, null,
                                              "Launch windowed", ( bool windowed ) => LaunchWindowed = windowed, false, SensitiveData.None);

            SettingsLoader.ApplySettingStruct(null, m_savedSettings.RememberUsername, null, "Remember username",
                                              ( bool remember ) => RememberMe = remember, false, SensitiveData.None);

            SettingsLoader.ApplySettingClass(m_parsedArgs.Settings.Username, m_savedSettings.Username, null,
                                             "Username", ( string user ) => Username = user, "", SensitiveData.Usernames);

            SettingsLoader.ApplySettingClass(m_parsedArgs.Settings.Password, m_savedSettings.Password, null,
                                             "Password", ( string pass ) => Password = pass, "", SensitiveData.Passwords);

            Func <int, string> validateWindowSize = ( int size ) =>
            {
                if (size > 0)
                {
                    return(null);
                }
                else
                {
                    return(string.Format("{0} is not a positive integer.", size));
                }
            };

            SettingsLoader.ApplySettingStruct(m_parsedArgs.Settings.GameWindowWidth, m_savedSettings.GameWindowWidth,
                                              validateWindowSize, "Starting game window width", ( int width ) => GameWindowStartingWidth = width,
                                              DfoLauncher.DefaultGameWindowWidth, SensitiveData.None);

            SettingsLoader.ApplySettingStruct(m_parsedArgs.Settings.GameWindowHeight,
                                              m_savedSettings.GameWindowHeight, validateWindowSize, "Starting game window height",
                                              ( int height ) => GameWindowStartingHeight = height,
                                              DfoLauncher.DefaultGameWindowHeight, SensitiveData.None);

            Func <string, string> validatePath = ( string dir ) =>
            {
                if (Utilities.PathIsValid(dir))
                {
                    return(null);
                }
                else
                {
                    return(string.Format("{0} is not a valid path.", dir));
                }
            };

            SettingsLoader.ApplySettingClass(m_parsedArgs.Settings.DfoDir, m_savedSettings.DfoDir, validatePath,
                                             "DFO directory", ( string dfodir ) => { if (dfodir != null)
                                                                                     {
                                                                                         DfoDir = dfodir;
                                                                                     }
                                             }, null,
                                             SensitiveData.None);

            if (DfoDir == null)
            {
                try
                {
                    AutoDetectDfoDir();
                }
                catch (IOException ex)
                {
                    Logging.Log.ErrorFormat("Could not autodetect the DFO directory. {0} Using {1} as a fallback.",
                                            ex.Message, DefaultDfoDir);
                    DfoDir = DefaultDfoDir;
                }
            }

            foreach (string switchableName in m_parsedArgs.Settings.SwitchableFiles.Keys)
            {
                ISwitchableFile switchableFromArgs     = m_parsedArgs.Settings.SwitchableFiles[switchableName];
                bool?           switchFromArgs         = m_parsedArgs.Settings.SwitchFile[switchableName];
                ISwitchableFile switchableFromSettings = m_savedSettings.SwitchableFiles[switchableName];
                bool?           switchFromSettings     = m_savedSettings.SwitchFile[switchableName];

                SwitchableFiles[switchableName].RelativeRoot = DfoDir;

                SettingsLoader.ApplySettingClass(switchableFromArgs.CustomFile, switchableFromSettings.CustomFile,
                                                 validatePath,
                                                 string.Format("Custom file for {0}", switchableFromArgs.NormalFile),
                                                 ( string customFile ) => SwitchableFiles[switchableName].CustomFile = customFile,
                                                 switchableFromArgs.DefaultCustomFile, SensitiveData.None);

                SettingsLoader.ApplySettingClass(switchableFromArgs.TempFile, switchableFromSettings.TempFile,
                                                 validatePath,
                                                 string.Format("Temp file for {0}", switchableFromArgs.NormalFile),
                                                 ( string tempFile ) => SwitchableFiles[switchableName].TempFile = tempFile,
                                                 switchableFromArgs.DefaultTempFile, SensitiveData.None);

                SettingsLoader.ApplySettingStruct(switchFromArgs, switchFromSettings, null,
                                                  string.Format("Switch {0}", switchableFromArgs.NormalFile),
                                                  ( bool switchFile ) => SwitchableFiles[switchableName].SwitchIfFilesOk = switchFile,
                                                  false, SensitiveData.None);
            }

            Logging.Log.Debug("Done applying settings and arguments.");
        }