コード例 #1
0
        public UserSettings GetSettings()
        {
            try
            {
                if (File.Exists(SettingsFilePath))
                {
                    var serializer = new XmlSerializer(typeof(UserSettings));
                    using (var file = File.Open(SettingsFilePath, FileMode.Open))
                    {
                        this.loadedSettings = (UserSettings)serializer.Deserialize(file);
                    }
                }
                else
                {
                    this.loadedSettings = GetInitialSettings();
                }
            }
            catch (InvalidOperationException)
            {
                HandleInvalidConfig();
                this.loadedSettings = GetInitialSettings();
            }

            return this.loadedSettings;
        }
コード例 #2
0
        public void showFormIfNeeded(string currentGameName, UserSettings currentUserSettingObject, bool useDefaultConfig)
        {
            string currentSettingName = "";
            List<string> configNames = null;

            // We receive as parameter the current game name. However it may not be the current config.
            if (!useDefaultConfig) currentSettingName = currentGameName;

            userSettingObject = currentUserSettingObject;

            configNames = userSettingObject.GetAllConfigsGameNameFromCurrentUserSettings();
            configNames.Remove(currentSettingName);

            configNames.Insert(0, Constants.settingNameForFactorySettings);

            // In the list, no game string value is nothing. Replace it with No Game so user understands it
            for (int i = 0; i < configNames.Count; i++)
                if (configNames[i] == "") configNames[i] = Constants.noGameConfigNameToDisplayToUser;

            cbxConfigToPickFrom.DataSource = configNames;

            this.ShowDialog();
        }
コード例 #3
0
        public void PrepareFormAndShowIfNeeded(UserSettings currentUserSettingObject, string settingsPath, string fileName)
        {
            List<string> configNames = null;

            this.settingsPath = settingsPath;
            this.fileName = fileName;

            cbxConfigToDelete.Enabled = true;
            btnDelete.Enabled = true;
            btnDeleteAll.Enabled = true;

            userSettingObject = currentUserSettingObject;

            configNames = userSettingObject.GetAllConfigsGameNameFromCurrentUserSettings();

            if (configNames.Count == 0)
            {
                MessageBox.Show("No configs!", "C# MegaMan Engine", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // Buil list
                // In the list, no game string value is nothing. Replace it with No Game so user understands it
                cbxConfigToDelete.Items.Clear();

                for (int x = 0; x < configNames.Count; x++)
                {
                    if (string.IsNullOrWhiteSpace(configNames[x])) configNames[x] = Constants.noGameConfigNameToDisplayToUser;
                    cbxConfigToDelete.Items.Add(configNames[x]);
                }

                cbxConfigToDelete.SelectedIndex = 0;

                this.ShowDialog();
            }
        }
コード例 #4
0
        public static void SaveToConfigXML(UserSettings userSettings, string settingsPath, string fileName = null)
        {
            if (fileName == null) fileName = Constants.Paths.SettingFile;

            var serializer = new XmlSerializer(typeof(UserSettings));

            XmlTextWriter writer = new XmlTextWriter(settingsPath, null)
            {
                Indentation = 1,
                IndentChar = '\t',
                Formatting = Formatting.Indented
            };

            serializer.Serialize(writer, userSettings);

            writer.Close();
        }