コード例 #1
0
ファイル: ConfigWindow.xaml.cs プロジェクト: not1ce111/Spedit
 private void NewButton_Clicked(object sender, RoutedEventArgs e)
 {
     Config c = new Config() { Name = "New Config", Standard = false, OptimizeLevel = 2, VerboseLevel = 1 };
     List<Config> configList = new List<Config>(Program.Configs);
     configList.Add(c);
     Program.Configs = configList.ToArray();
     ConfigListBox.Items.Add(new ListBoxItem() { Content = "New Config" });
 }
コード例 #2
0
ファイル: ConfigControl.cs プロジェクト: not1ce111/Spedit
 public static Config[] Load()
 {
     List<Config> configs = new List<Config>();
     if (File.Exists("sourcepawn\\configs\\Configs.xml"))
     {
         try
         {
             XmlDocument document = new XmlDocument();
             document.Load("sourcepawn\\configs\\Configs.xml");
             if (document.ChildNodes.Count < 1)
             {
                 throw new Exception("No main 'Configurations' node.");
             }
             XmlNode mainNode = document.ChildNodes[0];
             if (mainNode.ChildNodes.Count < 1)
             {
                 throw new Exception("No 'config' nodes found.");
             }
             for (int i = 0; i < mainNode.ChildNodes.Count; ++i)
             {
                 XmlNode node = mainNode.ChildNodes[i];
                 string _Name = ReadAttributeStringSafe(ref node, "Name", "UNKOWN CONFIG " + (i + 1).ToString());
                 string _SMDirectoryStr = ReadAttributeStringSafe(ref node, "SMDirectory", "");
                 string[] SMDirectoriesSplitted = _SMDirectoryStr.Split(';');
                 List<string> SMDirs = new List<string>();
                 foreach (string dir in SMDirectoriesSplitted)
                 {
                     string d = dir.Trim();
                     if (Directory.Exists(d))
                     {
                         SMDirs.Add(d);
                     }
                 }
                 string _Standard = ReadAttributeStringSafe(ref node, "Standard", "0");
                 bool IsStandardConfig = false;
                 if (_Standard != "0" && !string.IsNullOrWhiteSpace(_Standard))
                 {
                     IsStandardConfig = true;
                 }
                 string _AutoCopyStr = ReadAttributeStringSafe(ref node, "AutoCopy", "0");
                 bool _AutoCopy = false;
                 if (_AutoCopyStr != "0" && !string.IsNullOrWhiteSpace(_AutoCopyStr))
                 {
                     _AutoCopy = true;
                 }
                 string _CopyDirectory = ReadAttributeStringSafe(ref node, "CopyDirectory", "");
                 string _ServerFile = ReadAttributeStringSafe(ref node, "ServerFile", "");
                 string _ServerArgs = ReadAttributeStringSafe(ref node, "ServerArgs", "");
                 string _PostCmd = ReadAttributeStringSafe(ref node, "PostCmd", "");
                 string _PreCmd = ReadAttributeStringSafe(ref node, "PreCmd", "");
                 int _OptimizationLevel = 2, _VerboseLevel = 1;
                 int subValue;
                 if (int.TryParse(ReadAttributeStringSafe(ref node, "OptimizationLevel", "2"), out subValue))
                 {
                     _OptimizationLevel = subValue;
                 }
                 if (int.TryParse(ReadAttributeStringSafe(ref node, "VerboseLevel", "1"), out subValue))
                 {
                     _VerboseLevel = subValue;
                 }
                 bool _DeleteAfterCopy = false;
                 string DeleteAfterCopyStr = ReadAttributeStringSafe(ref node, "DeleteAfterCopy", "0");
                 if (!(DeleteAfterCopyStr == "0" || string.IsNullOrWhiteSpace(DeleteAfterCopyStr)))
                 {
                     _DeleteAfterCopy = true;
                 }
                 string _FTPHost = ReadAttributeStringSafe(ref node, "FTPHost", "ftp://localhost/");
                 string _FTPUser = ReadAttributeStringSafe(ref node, "FTPUser", "");
                 string encryptedFTPPW = ReadAttributeStringSafe(ref node, "FTPPassword", "");
                 string _FTPPW = ManagedAES.Decrypt(encryptedFTPPW);
                 string _FTPDir = ReadAttributeStringSafe(ref node, "FTPDir", "");
                 string _RConEngineSourceStr = ReadAttributeStringSafe(ref node, "RConSourceEngine", "1");
                 bool _RConEngineTypeSource = false;
                 if (!(_RConEngineSourceStr == "0" || string.IsNullOrWhiteSpace(_RConEngineSourceStr)))
                 {
                     _RConEngineTypeSource = true;
                 }
                 string _RConIP = ReadAttributeStringSafe(ref node, "RConIP", "127.0.0.1");
                 string _RConPortStr = ReadAttributeStringSafe(ref node, "RConPort", "27015");
                 ushort _RConPort = 27015;
                 if (!ushort.TryParse(_RConPortStr, NumberStyles.Any, CultureInfo.InvariantCulture, out _RConPort))
                 {
                     _RConPort = 27015;
                 }
                 string encryptedRConPassword = ReadAttributeStringSafe(ref node, "RConPassword", "");
                 string _RConPassword = ManagedAES.Decrypt(encryptedRConPassword);
                 string _RConCommands = ReadAttributeStringSafe(ref node, "RConCommands", "");
                 Config c = new Config()
                 {
                     Name = _Name,
                     SMDirectories = SMDirs.ToArray(),
                     Standard = IsStandardConfig
                     ,
                     AutoCopy = _AutoCopy,
                     CopyDirectory = _CopyDirectory,
                     ServerFile = _ServerFile,
                     ServerArgs = _ServerArgs
                     ,
                     PostCmd = _PostCmd,
                     PreCmd = _PreCmd,
                     OptimizeLevel = _OptimizationLevel,
                     VerboseLevel = _VerboseLevel,
                     DeleteAfterCopy = _DeleteAfterCopy
                     ,
                     FTPHost = _FTPHost,
                     FTPUser = _FTPUser,
                     FTPPassword = _FTPPW,
                     FTPDir = _FTPDir
                     ,
                     RConUseSourceEngine = _RConEngineTypeSource,
                     RConIP = _RConIP,
                     RConPort = _RConPort,
                     RConPassword = _RConPassword,
                     RConCommands = _RConCommands
                 };
                 if (IsStandardConfig)
                 {
                     c.LoadSMDef();
                 }
                 configs.Add(c);
             }
         }
         catch (Exception e)
         {
             MessageBox.Show("An error appeared while reading the configs. Without them, the editor wont start. Reinstall program!" + Environment.NewLine + "Details: " + e.Message
                 , "Error while reading configs."
                 , MessageBoxButton.OK
                 , MessageBoxImage.Warning);
             Environment.Exit(Environment.ExitCode);
         }
     }
     else
     {
         MessageBox.Show("The Editor could not find the Configs.xml file. Without it, the editor wont start. Reinstall program.", "File not found.", MessageBoxButton.OK, MessageBoxImage.Warning);
         Environment.Exit(Environment.ExitCode);
     }
     return configs.ToArray();
 }