Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 8a414d3

Browse files
committed
Auto Upload & RCON CheckBox
1 parent 9f19c17 commit 8a414d3

File tree

6 files changed

+304
-319
lines changed

6 files changed

+304
-319
lines changed

App/AssemblyInfo1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@
3333
#if (DEBUG)
3434
[assembly: AssemblyVersion("1.12.*")]
3535
#else
36-
[assembly: AssemblyVersion("1.3.4.7")]
36+
[assembly: AssemblyVersion("1.3.5.0")]
3737
#endif

Interop/ConfigControl.cs

Lines changed: 99 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,116 @@
1-
using SourcepawnCondenser;
2-
using SourcepawnCondenser.SourcemodDefinition;
3-
using Spedit.Utils;
4-
using System;
1+
using System;
52
using System.Collections.Generic;
63
using System.Globalization;
74
using System.IO;
85
using System.Windows;
96
using System.Xml;
7+
using SourcepawnCondenser.SourcemodDefinition;
8+
using Spedit.Utils;
109

1110
namespace Spedit.Interop
1211
{
1312
public static class ConfigLoader
1413
{
1514
public static Config[] Load()
1615
{
17-
List<Config> configs = new List<Config>();
16+
var configs = new List<Config>();
1817
if (File.Exists("sourcepawn\\configs\\Configs.xml"))
1918
{
2019
try
2120
{
22-
XmlDocument document = new XmlDocument();
21+
var document = new XmlDocument();
2322
document.Load("sourcepawn\\configs\\Configs.xml");
24-
if (document.ChildNodes.Count < 1)
23+
if (document.ChildNodes.Count < 1) throw new Exception("No main 'Configurations' node.");
24+
var mainNode = document.ChildNodes[0];
25+
if (mainNode.ChildNodes.Count < 1) throw new Exception("No 'config' nodes found.");
26+
for (var i = 0; i < mainNode.ChildNodes.Count; ++i)
2527
{
26-
throw new Exception("No main 'Configurations' node.");
27-
}
28-
XmlNode mainNode = document.ChildNodes[0];
29-
if (mainNode.ChildNodes.Count < 1)
30-
{
31-
throw new Exception("No 'config' nodes found.");
32-
}
33-
for (int i = 0; i < mainNode.ChildNodes.Count; ++i)
34-
{
35-
XmlNode node = mainNode.ChildNodes[i];
36-
string _Name = ReadAttributeStringSafe(ref node, "Name", "UNKOWN CONFIG " + (i + 1).ToString());
37-
string _SMDirectoryStr = ReadAttributeStringSafe(ref node, "SMDirectory", "");
38-
string[] SMDirectoriesSplitted = _SMDirectoryStr.Split(';');
39-
List<string> SMDirs = new List<string>();
40-
foreach (string dir in SMDirectoriesSplitted)
28+
var node = mainNode.ChildNodes[i];
29+
var _Name = ReadAttributeStringSafe(ref node, "Name", "UNKOWN CONFIG " + (i + 1));
30+
var _SMDirectoryStr = ReadAttributeStringSafe(ref node, "SMDirectory");
31+
var SMDirectoriesSplitted = _SMDirectoryStr.Split(';');
32+
var SMDirs = new List<string>();
33+
foreach (var dir in SMDirectoriesSplitted)
4134
{
42-
string d = dir.Trim();
43-
if (Directory.Exists(d))
44-
{
45-
SMDirs.Add(d);
46-
}
35+
var d = dir.Trim();
36+
if (Directory.Exists(d)) SMDirs.Add(d);
4737
}
48-
string _Standard = ReadAttributeStringSafe(ref node, "Standard", "0");
49-
bool IsStandardConfig = false;
50-
if (_Standard != "0" && !string.IsNullOrWhiteSpace(_Standard))
51-
{
52-
IsStandardConfig = true;
53-
}
54-
string _AutoCopyStr = ReadAttributeStringSafe(ref node, "AutoCopy", "0");
55-
bool _AutoCopy = false;
56-
if (_AutoCopyStr != "0" && !string.IsNullOrWhiteSpace(_AutoCopyStr))
57-
{
58-
_AutoCopy = true;
59-
}
60-
string _CopyDirectory = ReadAttributeStringSafe(ref node, "CopyDirectory", "");
61-
string _ServerFile = ReadAttributeStringSafe(ref node, "ServerFile", "");
62-
string _ServerArgs = ReadAttributeStringSafe(ref node, "ServerArgs", "");
63-
string _PostCmd = ReadAttributeStringSafe(ref node, "PostCmd", "");
64-
string _PreCmd = ReadAttributeStringSafe(ref node, "PreCmd", "");
38+
39+
var _Standard = ReadAttributeStringSafe(ref node, "Standard", "0");
40+
var _AutoCopyStr = ReadAttributeStringSafe(ref node, "AutoCopy", "0");
41+
var _AutoUploadStr = ReadAttributeStringSafe(ref node, "AutoUpload", "0");
42+
var _AutoRCONStr = ReadAttributeStringSafe(ref node, "AutoRCON", "0");
43+
var _CopyDirectory = ReadAttributeStringSafe(ref node, "CopyDirectory");
44+
var _ServerFile = ReadAttributeStringSafe(ref node, "ServerFile");
45+
var _ServerArgs = ReadAttributeStringSafe(ref node, "ServerArgs");
46+
var _PostCmd = ReadAttributeStringSafe(ref node, "PostCmd");
47+
var _PreCmd = ReadAttributeStringSafe(ref node, "PreCmd");
48+
49+
var IsStandardConfig = _Standard != "0" && !string.IsNullOrWhiteSpace(_Standard);
50+
var _AutoCopy = _AutoCopyStr != "0" && !string.IsNullOrWhiteSpace(_AutoCopyStr);
51+
var _AutoUpload = _AutoUploadStr != "0" && !string.IsNullOrWhiteSpace(_AutoUploadStr);
52+
var _AutoRCON = _AutoRCONStr != "0" && !string.IsNullOrWhiteSpace(_AutoRCONStr);
53+
6554
int _OptimizationLevel = 2, _VerboseLevel = 1;
6655
int subValue;
6756
if (int.TryParse(ReadAttributeStringSafe(ref node, "OptimizationLevel", "2"), out subValue))
68-
{
6957
_OptimizationLevel = subValue;
70-
}
7158
if (int.TryParse(ReadAttributeStringSafe(ref node, "VerboseLevel", "1"), out subValue))
72-
{
7359
_VerboseLevel = subValue;
74-
}
75-
bool _DeleteAfterCopy = false;
76-
string DeleteAfterCopyStr = ReadAttributeStringSafe(ref node, "DeleteAfterCopy", "0");
60+
var _DeleteAfterCopy = false;
61+
var DeleteAfterCopyStr = ReadAttributeStringSafe(ref node, "DeleteAfterCopy", "0");
7762
if (!(DeleteAfterCopyStr == "0" || string.IsNullOrWhiteSpace(DeleteAfterCopyStr)))
78-
{
7963
_DeleteAfterCopy = true;
80-
}
81-
string _FTPHost = ReadAttributeStringSafe(ref node, "FTPHost", "ftp://localhost/");
82-
string _FTPUser = ReadAttributeStringSafe(ref node, "FTPUser", "");
83-
string encryptedFTPPW = ReadAttributeStringSafe(ref node, "FTPPassword", "");
84-
string _FTPPW = ManagedAES.Decrypt(encryptedFTPPW);
85-
string _FTPDir = ReadAttributeStringSafe(ref node, "FTPDir", "");
86-
string _RConEngineSourceStr = ReadAttributeStringSafe(ref node, "RConSourceEngine", "1");
87-
bool _RConEngineTypeSource = false;
88-
if (!(_RConEngineSourceStr == "0" || string.IsNullOrWhiteSpace(_RConEngineSourceStr)))
89-
{
90-
_RConEngineTypeSource = true;
91-
}
92-
string _RConIP = ReadAttributeStringSafe(ref node, "RConIP", "127.0.0.1");
93-
string _RConPortStr = ReadAttributeStringSafe(ref node, "RConPort", "27015");
64+
var _FTPHost = ReadAttributeStringSafe(ref node, "FTPHost", "ftp://localhost/");
65+
var _FTPUser = ReadAttributeStringSafe(ref node, "FTPUser");
66+
var encryptedFTPPW = ReadAttributeStringSafe(ref node, "FTPPassword");
67+
var _FTPPW = ManagedAES.Decrypt(encryptedFTPPW);
68+
var _FTPDir = ReadAttributeStringSafe(ref node, "FTPDir");
69+
var _RConEngineSourceStr = ReadAttributeStringSafe(ref node, "RConSourceEngine", "1");
70+
bool _RConEngineTypeSource = !(_RConEngineSourceStr == "0" || string.IsNullOrWhiteSpace(_RConEngineSourceStr));
71+
var _RConIP = ReadAttributeStringSafe(ref node, "RConIP", "127.0.0.1");
72+
var _RConPortStr = ReadAttributeStringSafe(ref node, "RConPort", "27015");
9473
ushort _RConPort = 27015;
95-
if (!ushort.TryParse(_RConPortStr, NumberStyles.Any, CultureInfo.InvariantCulture, out _RConPort))
96-
{
97-
_RConPort = 27015;
98-
}
99-
string encryptedRConPassword = ReadAttributeStringSafe(ref node, "RConPassword", "");
100-
string _RConPassword = ManagedAES.Decrypt(encryptedRConPassword);
101-
string _RConCommands = ReadAttributeStringSafe(ref node, "RConCommands", "");
102-
Config c = new Config()
74+
if (!ushort.TryParse(_RConPortStr, NumberStyles.Any, CultureInfo.InvariantCulture,
75+
out _RConPort)) _RConPort = 27015;
76+
var encryptedRConPassword = ReadAttributeStringSafe(ref node, "RConPassword");
77+
var _RConPassword = ManagedAES.Decrypt(encryptedRConPassword);
78+
var _RConCommands = ReadAttributeStringSafe(ref node, "RConCommands");
79+
var c = new Config
10380
{
10481
Name = _Name,
10582
SMDirectories = SMDirs.ToArray(),
106-
Standard = IsStandardConfig
107-
,
83+
Standard = IsStandardConfig,
10884
AutoCopy = _AutoCopy,
85+
AutoRCON = _AutoRCON,
86+
AutoUpload = _AutoUpload,
10987
CopyDirectory = _CopyDirectory,
11088
ServerFile = _ServerFile,
111-
ServerArgs = _ServerArgs
112-
,
89+
ServerArgs = _ServerArgs,
11390
PostCmd = _PostCmd,
11491
PreCmd = _PreCmd,
11592
OptimizeLevel = _OptimizationLevel,
11693
VerboseLevel = _VerboseLevel,
117-
DeleteAfterCopy = _DeleteAfterCopy
118-
,
94+
DeleteAfterCopy = _DeleteAfterCopy,
11995
FTPHost = _FTPHost,
12096
FTPUser = _FTPUser,
12197
FTPPassword = _FTPPW,
122-
FTPDir = _FTPDir
123-
,
98+
FTPDir = _FTPDir,
12499
RConUseSourceEngine = _RConEngineTypeSource,
125100
RConIP = _RConIP,
126101
RConPort = _RConPort,
127102
RConPassword = _RConPassword,
128103
RConCommands = _RConCommands
129104
};
130-
if (IsStandardConfig)
131-
{
132-
c.LoadSMDef();
133-
}
105+
if (IsStandardConfig) c.LoadSMDef();
134106
configs.Add(c);
135107
}
136108
}
137109
catch (Exception e)
138110
{
139-
MessageBox.Show("An error appeared while reading the configs. Without them, the editor wont start. Reinstall program!" + Environment.NewLine + "Details: " + e.Message
111+
MessageBox.Show(
112+
"An error appeared while reading the configs. Without them, the editor wont start. Reinstall program!" +
113+
Environment.NewLine + "Details: " + e.Message
140114
, "Error while reading configs."
141115
, MessageBoxButton.OK
142116
, MessageBoxImage.Warning);
@@ -145,89 +119,88 @@ public static Config[] Load()
145119
}
146120
else
147121
{
148-
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);
122+
MessageBox.Show(
123+
"The Editor could not find the Configs.xml file. Without it, the editor wont start. Reinstall program.",
124+
"File not found.", MessageBoxButton.OK, MessageBoxImage.Warning);
149125
Environment.Exit(Environment.ExitCode);
150126
}
127+
151128
return configs.ToArray();
152129
}
153130

154131
private static string ReadAttributeStringSafe(ref XmlNode node, string attributeName, string defaultValue = "")
155132
{
156-
for (int i = 0; i < node.Attributes.Count; ++i)
157-
{
133+
for (var i = 0; i < node.Attributes.Count; ++i)
158134
if (node.Attributes[i].Name == attributeName)
159-
{
160135
return node.Attributes[i].Value;
161-
}
162-
}
163136
return defaultValue;
164137
}
165138
}
166139

167140
public class Config
168141
{
169-
public string Name = string.Empty;
170-
171-
public bool Standard = false;
172-
173-
public bool AutoCopy = false;
174-
175-
public string[] SMDirectories = new string[0];
142+
public bool AutoCopy;
143+
public bool AutoUpload;
144+
public bool AutoRCON;
145+
176146
public string CopyDirectory = string.Empty;
177-
public string ServerFile = string.Empty;
178-
public string ServerArgs = string.Empty;
179147

180-
public string PostCmd = string.Empty;
181-
public string PreCmd = string.Empty;
148+
public bool DeleteAfterCopy;
149+
public string FTPDir = string.Empty;
182150

183-
public bool DeleteAfterCopy = false;
151+
public string FTPHost = "ftp://localhost/";
184152

185-
public int OptimizeLevel = 2;
186-
public int VerboseLevel = 1;
153+
public string
154+
FTPPassword =
155+
string.Empty; //securestring? No! Because it's saved in plaintext and if you want to keep it a secret, you shouldn't automaticly uploade it anyways...
187156

188-
public string FTPHost = "ftp://localhost/";
189157
public string FTPUser = string.Empty;
190-
public string FTPPassword = string.Empty; //securestring? No! Because it's saved in plaintext and if you want to keep it a secret, you shouldn't automaticly uploade it anyways...
191-
public string FTPDir = string.Empty;
158+
public string Name = string.Empty;
192159

193-
public bool RConUseSourceEngine = true;
160+
public int OptimizeLevel = 2;
161+
162+
public string PostCmd = string.Empty;
163+
public string PreCmd = string.Empty;
164+
public string RConCommands = string.Empty;
194165
public string RConIP = "127.0.0.1";
195-
public ushort RConPort = 27015;
196166
public string RConPassword = string.Empty;
197-
public string RConCommands = string.Empty;
167+
public ushort RConPort = 27015;
168+
169+
public bool RConUseSourceEngine = true;
170+
public string ServerArgs = string.Empty;
171+
public string ServerFile = string.Empty;
198172

199173
private SMDefinition SMDef;
200174

175+
public string[] SMDirectories = new string[0];
176+
177+
public bool Standard;
178+
public int VerboseLevel = 1;
179+
201180
public SMDefinition GetSMDef()
202181
{
203-
if (SMDef == null)
204-
{
205-
LoadSMDef();
206-
}
182+
if (SMDef == null) LoadSMDef();
207183
return SMDef;
208184
}
209185

210186
public void InvalidateSMDef()
211187
{
212-
this.SMDef = null;
188+
SMDef = null;
213189
}
214190

215191
public void LoadSMDef()
216192
{
217-
if (this.SMDef != null)
218-
{
219-
return;
220-
}
193+
if (SMDef != null) return;
221194
try
222195
{
223-
SMDefinition def = new SMDefinition();
224-
def.AppendFiles(SMDirectories);
225-
SMDef = def;
196+
var def = new SMDefinition();
197+
def.AppendFiles(SMDirectories);
198+
SMDef = def;
226199
}
227200
catch (Exception)
228201
{
229-
this.SMDef = new SMDefinition(); //this could be dangerous...
202+
SMDef = new SMDefinition(); //this could be dangerous...
230203
}
231204
}
232205
}
233-
}
206+
}

Interop/TranslationProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ private void FillToEnglishDefaults()
227227
language.Add("OptimizeLvl", "Optimization level");
228228
language.Add("VerboseLvl", "Verbose level");
229229
language.Add("AutoCopy", "Auto copy after compile");
230+
language.Add("AutoUpload", "Auto upload .smx after Compile");
231+
language.Add("AutoRCON", "Send RCON Commands after Compile");
230232
language.Add("DeleteOldSMX", "Delete old .smx after copy");
231233
language.Add("FTPHost", "FTP host");
232234
language.Add("FTPUser", "FTP user");

UI/MainWindowSPCompiler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ await this.ShowMessageAsync(Program.Translations.GetLanguage("SPCompNotStarted")
195195
progressTask.SetProgress(1.0);
196196
CompileOutput.Text = stringOutput.ToString();
197197
if (c.AutoCopy) Copy_Plugins(true);
198+
if (c.AutoUpload) FTPUpload_Plugins();
199+
if (c.AutoRCON) Server_Query();
198200
if (CompileOutputRow.Height.Value < 11.0) CompileOutputRow.Height = new GridLength(200.0);
199201
}
200202

UI/Windows/ConfigWindow.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
<TextBlock Name="VerboseBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,400,0,0" Text="Verbose Level: " IsHitTestVisible="False" />
4747
<CheckBox Name="C_AutoCopy" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="321,370,0,0" Content="Auto Copy after Compile" Checked="C_AutoCopy_Changed" Unchecked="C_AutoCopy_Changed" />
4848
<CheckBox Name="C_DeleteAfterCopy" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="321,399,0,0" Content="Delete old .smx after copy" Checked="C_DeleteAfterCopy_Changed" Unchecked="C_DeleteAfterCopy_Changed" />
49+
<CheckBox Name="C_AutoUpload" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="500,370,0,0" Content="Upload .smx after Compile" Checked="C_AutoUpload_Changed" Unchecked="C_AutoUpload_Changed" />
50+
<CheckBox Name="C_AutoRCON" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="500,399,0,0" Content="Send RCON Commands after Compile" Checked="C_AutoRCON_Changed" Unchecked="C_AutoRCON_Changed" />
4951
<TextBox Name="C_Name" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="195,0,5,0" TextChanged="C_Name_TextChanged" />
5052
<TextBox Name="C_SMDir" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="195,30,5,0" TextChanged="C_SMDir_TextChanged"
5153
Style="{DynamicResource SearchMetroTextBox}"

0 commit comments

Comments
 (0)