コード例 #1
0
        private void MetroWindow_Closed(object sender, EventArgs e)
        {
            if (NeedsSMDefInvalidation)
            {
                for (int i = 0; i < Program.Configs.Length; ++i)
                {
                    Program.Configs[i].InvalidateSMDef();
                }
            }
            Program.MainWindow.FillConfigMenu();
            Program.MainWindow.ChangeConfig(Program.SelectedConfig);
            StringBuilder     outString = new StringBuilder();
            XmlWriterSettings settings  = new XmlWriterSettings()
            {
                Indent = true, IndentChars = "\t", NewLineOnAttributes = false, OmitXmlDeclaration = true
            };

            using (XmlWriter writer = XmlWriter.Create(outString, settings))
            {
                writer.WriteStartElement("Configurations");
                for (int i = 0; i < Program.Configs.Length; ++i)
                {
                    Config c = Program.Configs[i];
                    writer.WriteStartElement("Config");
                    writer.WriteAttributeString("Name", c.Name);
                    StringBuilder SMDirOut = new StringBuilder();
                    foreach (string dir in c.SMDirectories)
                    {
                        SMDirOut.Append(dir.Trim() + ";");
                    }
                    writer.WriteAttributeString("SMDirectory", SMDirOut.ToString());
                    writer.WriteAttributeString("Standard", (c.Standard) ? "1" : "0");
                    writer.WriteAttributeString("CopyDirectory", c.CopyDirectory);
                    writer.WriteAttributeString("AutoCopy", (c.AutoCopy) ? "1" : "0");
                    writer.WriteAttributeString("ServerFile", c.ServerFile);
                    writer.WriteAttributeString("ServerArgs", c.ServerArgs);
                    writer.WriteAttributeString("PostCmd", c.PostCmd);
                    writer.WriteAttributeString("PreCmd", c.PreCmd);
                    writer.WriteAttributeString("OptimizationLevel", c.OptimizeLevel.ToString());
                    writer.WriteAttributeString("VerboseLevel", c.VerboseLevel.ToString());
                    writer.WriteAttributeString("DeleteAfterCopy", (c.DeleteAfterCopy) ? "1" : "0");
                    writer.WriteAttributeString("FTPHost", c.FTPHost);
                    writer.WriteAttributeString("FTPUser", c.FTPUser);
                    writer.WriteAttributeString("FTPPassword", ManagedAES.Encrypt(c.FTPPassword));
                    writer.WriteAttributeString("FTPDir", c.FTPDir);
                    writer.WriteAttributeString("RConSourceEngine", (c.RConUseSourceEngine) ? "1" : "0");
                    writer.WriteAttributeString("RConIP", c.RConIP);
                    writer.WriteAttributeString("RConPort", c.RConPort.ToString());
                    writer.WriteAttributeString("RConPassword", ManagedAES.Encrypt(c.RConPassword));
                    writer.WriteAttributeString("RConCommands", c.RConCommands);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.Flush();
            }
            File.WriteAllText("sourcepawn\\configs\\Configs.xml", outString.ToString());
        }
コード例 #2
0
        private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // TODO: find out what is this for
            if (NeedsSMDefInvalidation)
            {
                foreach (var config in Program.Configs)
                {
                    config.InvalidateSMDef();
                }
            }

            // Fill a list with all configs from the ListBox

            var configsList = new List <string>();

            foreach (ListBoxItem item in ConfigListBox.Items)
            {
                configsList.Add(item.Content.ToString());
            }

            // Check for empty named configs and disallow saving configs

            foreach (var cfg in configsList)
            {
                if (cfg == string.Empty)
                {
                    e.Cancel = true;
                    this.ShowMessageAsync(Program.Translations.GetLanguage("ErrorSavingConfigs"),
                                          Program.Translations.GetLanguage("EmptyConfigNames"), MessageDialogStyle.Affirmative,
                                          MetroDialogOptions);
                    return;
                }
            }

            // Check for duplicate names in the config list and disallow saving configs

            if (configsList.Count != configsList.Distinct().Count())
            {
                e.Cancel = true;
                this.ShowMessageAsync(Program.Translations.GetLanguage("ErrorSavingConfigs"),
                                      Program.Translations.GetLanguage("DuplicateConfigNames"), MessageDialogStyle.Affirmative,
                                      MetroDialogOptions);
                return;
            }

            Program.MainWindow.FillConfigMenu();
            Program.MainWindow.ChangeConfig(Program.SelectedConfig);
            var outString = new StringBuilder();
            var settings  = new XmlWriterSettings
            {
                Indent              = true,
                IndentChars         = "\t",
                NewLineOnAttributes = false,
                OmitXmlDeclaration  = true
            };

            using (var writer = XmlWriter.Create(outString, settings))
            {
                writer.WriteStartElement("Configurations");
                foreach (var c in Program.Configs)
                {
                    writer.WriteStartElement("Config");
                    writer.WriteAttributeString("Name", c.Name);
                    var SMDirOut = new StringBuilder();
                    foreach (var dir in c.SMDirectories)
                    {
                        SMDirOut.Append(dir.Trim() + ";");
                    }

                    writer.WriteAttributeString("SMDirectory", SMDirOut.ToString());
                    writer.WriteAttributeString("Standard", c.Standard ? "1" : "0");
                    writer.WriteAttributeString("CopyDirectory", c.CopyDirectory);
                    writer.WriteAttributeString("AutoCopy", c.AutoCopy ? "1" : "0");
                    writer.WriteAttributeString("AutoUpload", c.AutoUpload ? "1" : "0");
                    writer.WriteAttributeString("AutoRCON", c.AutoRCON ? "1" : "0");
                    writer.WriteAttributeString("ServerFile", c.ServerFile);
                    writer.WriteAttributeString("ServerArgs", c.ServerArgs);
                    writer.WriteAttributeString("PostCmd", c.PostCmd);
                    writer.WriteAttributeString("PreCmd", c.PreCmd);
                    writer.WriteAttributeString("OptimizationLevel", c.OptimizeLevel.ToString());
                    writer.WriteAttributeString("VerboseLevel", c.VerboseLevel.ToString());
                    writer.WriteAttributeString("DeleteAfterCopy", c.DeleteAfterCopy ? "1" : "0");
                    writer.WriteAttributeString("FTPHost", c.FTPHost);
                    writer.WriteAttributeString("FTPUser", c.FTPUser);
                    writer.WriteAttributeString("FTPPassword", ManagedAES.Encrypt(c.FTPPassword));
                    writer.WriteAttributeString("FTPDir", c.FTPDir);
                    writer.WriteAttributeString("RConSourceEngine", c.RConUseSourceEngine ? "1" : "0");
                    writer.WriteAttributeString("RConIP", c.RConIP);
                    writer.WriteAttributeString("RConPort", c.RConPort.ToString());
                    writer.WriteAttributeString("RConPassword", ManagedAES.Encrypt(c.RConPassword));
                    writer.WriteAttributeString("RConCommands", c.RConCommands);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.Flush();
            }

            File.WriteAllText(Paths.GetConfigFilePath(), outString.ToString());
        }