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

Commit e934c7f

Browse files
authored
Merge pull request #50 from ratawar/master
Code cleanup Some typography errors corrected Changed preprocessor directives RegEx for highlighting to match all words that begin with a hash # Fixed ctrl+clicking on symbols (partially including methodmap and enum structs symbols) not working for all defined scripting directories Fixed the Definition Window (ctrl+shift+f) not working/crashing for all defined scripting directories You can press Enter now to go to a definition in the Definition Window Fixed IDE crashing when attempting to reformat all editors with none opened Fixed IDE crashing when detaching an editor to a separate window Refactored installation to send all configuration and setting files, templates and temporary files to %appdata%, even if the program gets installed anywhere else. Implemented an IsLocalInstallation detection for compatibility with the portable version - program knows where to fetch the contents of the sourcepawn folder (configuration and setting files, templates and temporary files)
2 parents cc53e84 + 91b92d9 commit e934c7f

File tree

94 files changed

+3139
-3015
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3139
-3015
lines changed

App/AssemblyInfo1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Reflection;
2-
using System.Runtime.InteropServices;
32
using System.Resources;
3+
using System.Runtime.InteropServices;
44

55
// General Information about an assembly is controlled through the following
66
// set of attributes. Change these attribute values to modify the information

Deploy/SPCode.nsi

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ RequestExecutionLevel admin
2828

2929
!insertmacro MUI_LANGUAGE "English"
3030

31-
32-
33-
3431
Section "Program" prog01
3532
SectionIn 1 RO
3633
SetOutPath $INSTDIR
3734

3835
!insertmacro CheckNetFramework 48
3936

40-
4137
File SPCode.exe
4238
File MahApps.Metro.dll
4339
File ICSharpCode.AvalonEdit.dll
@@ -60,21 +56,23 @@ File Microsoft.WindowsAPICodePack.Shell.dll
6056
File lang_0_spcode.xml
6157
File GPLv3.txt
6258

63-
IfFileExists $INSTDIR\options_0.dat OptionsExist OptionsDoesNotExist
64-
OptionsExist:
65-
Delete $INSTDIR\options_0.dat
66-
OptionsDoesNotExist:
59+
CreateDirectory "$APPDATA\spcode\sourcepawn"
60+
CreateDirectory "$APPDATA\spcode\sourcepawn\errorfiles"
61+
CreateDirectory "$APPDATA\spcode\sourcepawn\scripts"
62+
CreateDirectory "$APPDATA\spcode\sourcepawn\temp"
63+
CreateDirectory "$APPDATA\spcode\sourcepawn\templates"
64+
CreateDirectory "$APPDATA\spcode\sourcepawn\configs"
65+
CreateDirectory "$APPDATA\spcode\sourcepawn\configs\sm_1_10_0_6478"
6766

68-
CreateDirectory "$INSTDIR\sourcepawn"
69-
CreateDirectory "$INSTDIR\sourcepawn\errorfiles"
70-
CreateDirectory "$INSTDIR\sourcepawn\scripts"
71-
CreateDirectory "$INSTDIR\sourcepawn\temp"
72-
CreateDirectory "$INSTDIR\sourcepawn\templates"
73-
CreateDirectory "$INSTDIR\sourcepawn\configs"
74-
CreateDirectory "$INSTDIR\sourcepawn\configs\sm_1_10_0_6478"
67+
SetOutPath $APPDATA\spcode
7568
File /r ".\sourcepawn"
7669

77-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\spcode" "DisplayName" "SPCode - A lightweight sourcepawn editor"
70+
IfFileExists $APPDATA\spcode\options_0.dat OptionsExist OptionsDoesNotExist
71+
OptionsExist:
72+
Delete $APPDATA\spcode\options_0.dat
73+
OptionsDoesNotExist:
74+
75+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\spcode" "DisplayName" "SPCode - A lightweight SourcePawn editor"
7876
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\spcode" "UninstallString" "$INSTDIR\uninstall.exe"
7977
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\spcode" "InstallLocation" "$INSTDIR"
8078
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\spcode" "DisplayIcon" "$INSTDIR\SPCode.exe"
@@ -87,7 +85,6 @@ WriteUninstaller $INSTDIR\uninstall.exe
8785
SectionEnd
8886

8987

90-
9188
Section "File Association (.sp)" prog02
9289
SectionIn 1
9390
${registerExtension} "$INSTDIR\SPCode.exe" ".sp" "Sourcepawn Script"
@@ -145,7 +142,7 @@ Delete $INSTDIR\Microsoft.WindowsAPICodePack.Shell.dll
145142
Delete $INSTDIR\lang_0_spcode.xml
146143
Delete $INSTDIR\GPLv3.txt
147144
Delete $INSTDIR\*.dat
148-
RMDir /r $INSTDIR\sourcepawn
145+
RMDir /r $APPDATA\spcode
149146
RMDir $INSTDIR
150147

151148
Delete "$DESKTOP\SPCode.lnk"

Deploy/SpcodeUpdater/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static void Main()
4141

4242
private static void Worker(object arg)
4343
{
44-
var um = (UpdateMarquee) arg;
44+
var um = (UpdateMarquee)arg;
4545
var zipFile = Path.Combine(Environment.CurrentDirectory, "updateZipFile.zip");
4646

4747
var zipFileContent = Resources.Update;
@@ -59,7 +59,7 @@ private static void Worker(object arg)
5959

6060
zipInfo.Delete();
6161

62-
um.Invoke((InvokeDel) (() => { um.SetToReadyState(); }));
62+
um.Invoke((InvokeDel)(() => { um.SetToReadyState(); }));
6363
}
6464
}
6565
}

Interop/ConfigControl.cs

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,31 @@ public static class ConfigLoader
1414
public static Config[] Load()
1515
{
1616
var configs = new List<Config>();
17-
if (File.Exists("sourcepawn\\configs\\Configs.xml"))
17+
if (File.Exists(Paths.GetConfigFilePath()))
1818
{
1919
try
2020
{
21+
// Document gets loaded
2122
var document = new XmlDocument();
22-
document.Load("sourcepawn\\configs\\Configs.xml");
23-
if (document.ChildNodes.Count < 1) throw new Exception("No main 'Configurations' node.");
23+
document.Load(Paths.GetConfigFilePath());
24+
25+
// Document gets checked for proper Configurations tag
26+
if (document.ChildNodes.Count < 1)
27+
{
28+
throw new Exception("No main 'Configurations' node.");
29+
}
30+
31+
// We check for main node and its main child 'Config' node
2432
var mainNode = document.ChildNodes[0];
25-
if (mainNode.ChildNodes.Count < 1) throw new Exception("No 'config' nodes found.");
33+
if (mainNode.ChildNodes.Count < 1)
34+
{
35+
throw new Exception("No 'config' nodes found.");
36+
}
37+
38+
// Start looping through all 'Config' child nodes
2639
for (var i = 0; i < mainNode.ChildNodes.Count; ++i)
2740
{
2841
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)
34-
{
35-
var d = dir.Trim();
36-
if (Directory.Exists(d)) SMDirs.Add(d);
37-
}
3842

3943
var _Standard = ReadAttributeStringSafe(ref node, "Standard", "0");
4044
var _AutoCopyStr = ReadAttributeStringSafe(ref node, "AutoCopy", "0");
@@ -45,22 +49,57 @@ public static Config[] Load()
4549
var _ServerArgs = ReadAttributeStringSafe(ref node, "ServerArgs");
4650
var _PostCmd = ReadAttributeStringSafe(ref node, "PostCmd");
4751
var _PreCmd = ReadAttributeStringSafe(ref node, "PreCmd");
48-
52+
4953
var IsStandardConfig = _Standard != "0" && !string.IsNullOrWhiteSpace(_Standard);
5054
var _AutoCopy = _AutoCopyStr != "0" && !string.IsNullOrWhiteSpace(_AutoCopyStr);
5155
var _AutoUpload = _AutoUploadStr != "0" && !string.IsNullOrWhiteSpace(_AutoUploadStr);
5256
var _AutoRCON = _AutoRCONStr != "0" && !string.IsNullOrWhiteSpace(_AutoRCONStr);
53-
57+
58+
var _Name = ReadAttributeStringSafe(ref node, "Name", "UNKOWN CONFIG " + (i + 1));
59+
var _SMDirectoryStr = ReadAttributeStringSafe(ref node, "SMDirectory");
60+
var SMDirectoriesSplitted = _SMDirectoryStr.Split(';');
61+
var SMDirs = new List<string>();
62+
63+
// If it's the default config the program comes with, add as SMDirectory the default one
64+
// (calculate it based on installation being standalone or portable)
65+
if (IsStandardConfig && string.IsNullOrEmpty(_SMDirectoryStr))
66+
{
67+
SMDirs.Add(Paths.GetConfigsFolderPath());
68+
}
69+
70+
foreach (var dir in SMDirectoriesSplitted)
71+
{
72+
var d = dir.Trim();
73+
if (Directory.Exists(d))
74+
{
75+
SMDirs.Add(d);
76+
}
77+
}
78+
79+
// Extra assurance for the program to always load a proper config
80+
if (IsStandardConfig && SMDirs.Count == 0)
81+
{
82+
SMDirs.Add(Paths.GetConfigsFolderPath());
83+
}
84+
5485
int _OptimizationLevel = 2, _VerboseLevel = 1;
55-
int subValue;
56-
if (int.TryParse(ReadAttributeStringSafe(ref node, "OptimizationLevel", "2"), out subValue))
86+
if (int.TryParse(ReadAttributeStringSafe(ref node, "OptimizationLevel", "2"), out var subValue))
87+
{
5788
_OptimizationLevel = subValue;
89+
}
90+
5891
if (int.TryParse(ReadAttributeStringSafe(ref node, "VerboseLevel", "1"), out subValue))
92+
{
5993
_VerboseLevel = subValue;
94+
}
95+
6096
var _DeleteAfterCopy = false;
6197
var DeleteAfterCopyStr = ReadAttributeStringSafe(ref node, "DeleteAfterCopy", "0");
6298
if (!(DeleteAfterCopyStr == "0" || string.IsNullOrWhiteSpace(DeleteAfterCopyStr)))
99+
{
63100
_DeleteAfterCopy = true;
101+
}
102+
64103
var _FTPHost = ReadAttributeStringSafe(ref node, "FTPHost", "ftp://localhost/");
65104
var _FTPUser = ReadAttributeStringSafe(ref node, "FTPUser");
66105
var encryptedFTPPW = ReadAttributeStringSafe(ref node, "FTPPassword");
@@ -70,12 +109,16 @@ public static Config[] Load()
70109
bool _RConEngineTypeSource = !(_RConEngineSourceStr == "0" || string.IsNullOrWhiteSpace(_RConEngineSourceStr));
71110
var _RConIP = ReadAttributeStringSafe(ref node, "RConIP", "127.0.0.1");
72111
var _RConPortStr = ReadAttributeStringSafe(ref node, "RConPort", "27015");
73-
ushort _RConPort = 27015;
74-
if (!ushort.TryParse(_RConPortStr, NumberStyles.Any, CultureInfo.InvariantCulture,
75-
out _RConPort)) _RConPort = 27015;
112+
113+
if (!ushort.TryParse(_RConPortStr, NumberStyles.Any, CultureInfo.InvariantCulture, out var _RConPort))
114+
{
115+
_RConPort = 27015;
116+
}
117+
76118
var encryptedRConPassword = ReadAttributeStringSafe(ref node, "RConPassword");
77119
var _RConPassword = ManagedAES.Decrypt(encryptedRConPassword);
78120
var _RConCommands = ReadAttributeStringSafe(ref node, "RConCommands");
121+
79122
var c = new Config
80123
{
81124
Name = _Name,
@@ -102,14 +145,17 @@ public static Config[] Load()
102145
RConPassword = _RConPassword,
103146
RConCommands = _RConCommands
104147
};
105-
if (IsStandardConfig) c.LoadSMDef();
148+
if (IsStandardConfig)
149+
{
150+
c.LoadSMDef();
151+
}
106152
configs.Add(c);
107153
}
108154
}
109155
catch (Exception e)
110156
{
111157
MessageBox.Show(
112-
"An error appeared while reading the configs. Without them, the editor wont start. Reinstall program!" +
158+
"An error occured while reading the configs. Without them, the editor will not start. Reinstall your program." +
113159
Environment.NewLine + "Details: " + e.Message
114160
, "Error while reading configs."
115161
, MessageBoxButton.OK
@@ -120,8 +166,8 @@ public static Config[] Load()
120166
else
121167
{
122168
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);
169+
"The Editor could not find the Configs.xml file, neither locally nor in AppData. Without it, the editor will not start. Reinstall your program.",
170+
"Configs file not found.", MessageBoxButton.OK, MessageBoxImage.Warning);
125171
Environment.Exit(Environment.ExitCode);
126172
}
127173

@@ -142,7 +188,7 @@ public class Config
142188
public bool AutoCopy;
143189
public bool AutoUpload;
144190
public bool AutoRCON;
145-
191+
146192
public string CopyDirectory = string.Empty;
147193

148194
public bool DeleteAfterCopy;

Interop/OptionsControl.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.Serialization.Formatters.Binary;
44
using System.Security.Cryptography;
55
using System.Windows.Media;
6+
using SPCode.Utils;
67

78
namespace SPCode //leave this here instead of .Interop because of reasons...
89
{
@@ -196,7 +197,7 @@ public static void Save()
196197
try
197198
{
198199
var formatter = new BinaryFormatter();
199-
using (var fileStream = new FileStream("options_0.dat", FileMode.Create, FileAccess.ReadWrite,
200+
using (var fileStream = new FileStream(Paths.GetOptionsFilePath(), FileMode.Create, FileAccess.ReadWrite,
200201
FileShare.None))
201202
{
202203
formatter.Serialize(fileStream, Program.OptionsObject);
@@ -212,17 +213,17 @@ public static OptionsControl Load(out bool ProgramIsNew)
212213
{
213214
try
214215
{
215-
if (File.Exists("options_0.dat"))
216+
if (File.Exists(Paths.GetOptionsFilePath()))
216217
{
217218
object deserializedOptionsObj;
218219
var formatter = new BinaryFormatter();
219-
using (var fileStream = new FileStream("options_0.dat", FileMode.Open, FileAccess.Read,
220+
using (var fileStream = new FileStream(Paths.GetOptionsFilePath(), FileMode.Open, FileAccess.Read,
220221
FileShare.ReadWrite))
221222
{
222223
deserializedOptionsObj = formatter.Deserialize(fileStream);
223224
}
224225

225-
var oc = (OptionsControl) deserializedOptionsObj;
226+
var oc = (OptionsControl)deserializedOptionsObj;
226227
oc.FillNullToDefaults();
227228
ProgramIsNew = false;
228229
return oc;

Interop/PipeInteropClient.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public static void ConnectToMasterPipeAndSendData(string data)
1818
stream.Write(stringLengthData, 0, stringLengthData.Length);
1919
stream.Write(stringData, 0, stringData.Length);
2020
}
21-
using (NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", "SPCodeNamedPipeServer", PipeDirection.Out, PipeOptions.Asynchronous))
22-
{
23-
pipeClient.Connect(5000);
24-
pipeClient.Write(array, 0, array.Length);
25-
pipeClient.Flush();
26-
}
21+
using (NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", "SPCodeNamedPipeServer", PipeDirection.Out, PipeOptions.Asynchronous))
22+
{
23+
pipeClient.Connect(5000);
24+
pipeClient.Write(array, 0, array.Length);
25+
pipeClient.Flush();
26+
}
2727
}
2828
}
2929
}

Interop/PipeInteropServer.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using SPCode.UI;
2-
using System;
1+
using System;
32
using System.IO.Pipes;
43
using System.Text;
4+
using SPCode.UI;
55

66
namespace SPCode.Interop
77
{
@@ -25,10 +25,10 @@ public void Close()
2525
pipeServer.Close();
2626
}
2727

28-
public void Dispose()
29-
{
30-
pipeServer.Close();
31-
}
28+
public void Dispose()
29+
{
30+
pipeServer.Close();
31+
}
3232

3333
private void StartInteropServer()
3434
{
@@ -51,7 +51,7 @@ private void PipeConnection_MessageIn(IAsyncResult iar)
5151
pipeServer.Read(byteBuffer, 0, length);
5252
string data = Encoding.UTF8.GetString(byteBuffer);
5353
string[] files = data.Split('|');
54-
bool SelectIt = true;
54+
bool SelectIt = true;
5555
for (int i = 0; i < files.Length; ++i)
5656
{
5757
_window.Dispatcher.Invoke(() =>
@@ -61,8 +61,8 @@ private void PipeConnection_MessageIn(IAsyncResult iar)
6161
if (_window.TryLoadSourceFile(files[i], SelectIt) && _window.WindowState == System.Windows.WindowState.Minimized)
6262
{
6363
_window.WindowState = System.Windows.WindowState.Normal;
64-
SelectIt = false;
65-
}
64+
SelectIt = false;
65+
}
6666
}
6767
});
6868
}

0 commit comments

Comments
 (0)