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

Commit 0e5e281

Browse files
committed
Generic IDE Optimizations
1 parent 50c1c7b commit 0e5e281

13 files changed

+572
-653
lines changed

Program.cs

+126-126
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public static class Program
2121
public static OptionsControl OptionsObject;
2222
public static TranslationProvider Translations;
2323
public static Config[] Configs;
24-
public static int SelectedConfig = 0;
24+
public static int SelectedConfig;
2525

2626
public static UpdateInfo UpdateStatus;
2727

28-
public static bool RCCKMade = false;
29-
public static DiscordRpcClient discordClient = new DiscordRpcClient("692110664948514836");
28+
public static bool RCCKMade;
29+
public static readonly DiscordRpcClient discordClient = new DiscordRpcClient("692110664948514836");
3030
public static Timestamps discordTime = Timestamps.Now;
3131

3232
[STAThread]
@@ -46,134 +46,136 @@ public static void Main(string[] args)
4646
}
4747
});
4848
bool mutexReserved;
49-
using (Mutex appMutex = new Mutex(true, "SpeditGlobalMutex", out mutexReserved))
49+
using (new Mutex(true, "SpeditGlobalMutex", out mutexReserved))
5050
{
51-
if (mutexReserved)
52-
{
53-
bool ProgramIsNew = false;
51+
if (mutexReserved)
52+
{
5453
#if !DEBUG
55-
try
56-
{
54+
try
55+
{
5756
#endif
58-
SplashScreen splashScreen = new SplashScreen("Resources/Icon256x.png");
59-
splashScreen.Show(false, true);
60-
Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
57+
SplashScreen splashScreen = new SplashScreen("Resources/Icon256x.png");
58+
splashScreen.Show(false, true);
59+
Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? throw new NullReferenceException();
6160
#if !DEBUG
62-
ProfileOptimization.SetProfileRoot(Environment.CurrentDirectory);
63-
ProfileOptimization.StartProfile("Startup.Profile");
61+
ProfileOptimization.SetProfileRoot(Environment.CurrentDirectory);
62+
ProfileOptimization.StartProfile("Startup.Profile");
6463
#endif
65-
UpdateStatus = new UpdateInfo();
66-
OptionsObject = OptionsControlIOObject.Load(out ProgramIsNew);
67-
Translations = new TranslationProvider();
68-
Translations.LoadLanguage(OptionsObject.Language, true);
69-
for (int i = 0; i < args.Length; ++i)
70-
{
71-
if (args[i].ToLowerInvariant() == "-rcck") //ReCreateCryptoKey
72-
{
73-
OptionsObject.ReCreateCryptoKey();
74-
MakeRCCKAlert();
75-
}
76-
}
77-
Configs = ConfigLoader.Load();
78-
for (int i = 0; i < Configs.Length; ++i)
79-
{
80-
if (Configs[i].Name == OptionsObject.Program_SelectedConfig)
81-
{
82-
Program.SelectedConfig = i;
83-
break;
84-
}
85-
}
86-
if (!OptionsObject.Program_UseHardwareAcceleration)
87-
{
88-
RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
89-
}
64+
UpdateStatus = new UpdateInfo();
65+
OptionsObject = OptionsControlIOObject.Load(out var ProgramIsNew);
66+
Translations = new TranslationProvider();
67+
Translations.LoadLanguage(OptionsObject.Language, true);
68+
for (int i = 0; i < args.Length; ++i)
69+
{
70+
if (args[i].ToLowerInvariant() == "-rcck") //ReCreateCryptoKey
71+
{
72+
OptionsObject.ReCreateCryptoKey();
73+
MakeRCCKAlert();
74+
}
75+
}
76+
Configs = ConfigLoader.Load();
77+
for (int i = 0; i < Configs.Length; ++i)
78+
{
79+
if (Configs[i].Name == OptionsObject.Program_SelectedConfig)
80+
{
81+
Program.SelectedConfig = i;
82+
break;
83+
}
84+
}
85+
if (!OptionsObject.Program_UseHardwareAcceleration)
86+
{
87+
RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
88+
}
9089
#if !DEBUG
91-
if (ProgramIsNew)
92-
{
93-
if (Translations.AvailableLanguageIDs.Length > 0)
94-
{
95-
splashScreen.Close(new TimeSpan(0, 0, 1));
96-
var languageWindow = new UI.Interop.LanguageChooserWindow(Translations.AvailableLanguageIDs, Translations.AvailableLanguages);
97-
languageWindow.ShowDialog();
98-
string potentialSelectedLanguageID = languageWindow.SelectedID;
99-
if (!string.IsNullOrWhiteSpace(potentialSelectedLanguageID))
100-
{
101-
OptionsObject.Language = potentialSelectedLanguageID;
102-
Translations.LoadLanguage(potentialSelectedLanguageID);
103-
}
104-
splashScreen.Show(false, true);
105-
}
106-
}
90+
if (ProgramIsNew)
91+
{
92+
if (Translations.AvailableLanguageIDs.Length > 0)
93+
{
94+
splashScreen.Close(new TimeSpan(0, 0, 1));
95+
var languageWindow = new UI.Interop.LanguageChooserWindow(Translations.AvailableLanguageIDs, Translations.AvailableLanguages);
96+
languageWindow.ShowDialog();
97+
string potentialSelectedLanguageID = languageWindow.SelectedID;
98+
if (!string.IsNullOrWhiteSpace(potentialSelectedLanguageID))
99+
{
100+
OptionsObject.Language = potentialSelectedLanguageID;
101+
Translations.LoadLanguage(potentialSelectedLanguageID);
102+
}
103+
splashScreen.Show(false, true);
104+
}
105+
}
107106
#endif
108-
MainWindow = new MainWindow(splashScreen);
109-
PipeInteropServer pipeServer = new PipeInteropServer(MainWindow);
110-
pipeServer.Start();
107+
MainWindow = new MainWindow(splashScreen);
108+
PipeInteropServer pipeServer = new PipeInteropServer(MainWindow);
109+
pipeServer.Start();
111110
#if !DEBUG
112-
}
113-
catch (Exception e)
114-
{
115-
File.WriteAllText("CRASH_" + Environment.TickCount.ToString() + ".txt", BuildExceptionString(e, "SPEDIT LOADING"));
116-
MessageBox.Show("An error occured while loading." + Environment.NewLine + "A crash report was written in the editor-directory.",
117-
"Error while Loading",
118-
MessageBoxButton.OK,
119-
MessageBoxImage.Error);
120-
Environment.Exit(Environment.ExitCode);
121-
}
111+
}
112+
catch (Exception e)
113+
{
114+
File.WriteAllText("CRASH_" + Environment.TickCount.ToString() + ".txt", BuildExceptionString(e, "SPEDIT LOADING"));
115+
MessageBox.Show("An error occured while loading." + Environment.NewLine + "A crash report was written in the editor-directory.",
116+
"Error while Loading",
117+
MessageBoxButton.OK,
118+
MessageBoxImage.Error);
119+
Environment.Exit(Environment.ExitCode);
120+
}
122121
#endif
123-
Application app = new Application();
122+
Application app = new Application();
124123
#if !DEBUG
125-
try
126-
{
127-
if (OptionsObject.Program_CheckForUpdates)
128-
{
129-
UpdateCheck.Check(true);
130-
}
124+
try
125+
{
126+
if (OptionsObject.Program_CheckForUpdates)
127+
{
128+
UpdateCheck.Check(true);
129+
}
131130
#endif
132-
app.Startup += App_Startup;
133-
app.Run(MainWindow);
134-
OptionsControlIOObject.Save();
131+
app.Startup += App_Startup;
132+
app.Run(MainWindow);
133+
OptionsControlIOObject.Save();
135134
#if !DEBUG
136-
}
137-
catch (Exception e)
138-
{
139-
File.WriteAllText("CRASH_" + Environment.TickCount.ToString() + ".txt", BuildExceptionString(e, "SPEDIT MAIN"));
140-
MessageBox.Show("An error occured." + Environment.NewLine + "A crash report was written in the editor-directory.",
141-
"Error",
142-
MessageBoxButton.OK,
143-
MessageBoxImage.Error);
144-
Environment.Exit(Environment.ExitCode);
145-
}
135+
}
136+
catch (Exception e)
137+
{
138+
File.WriteAllText("CRASH_" + Environment.TickCount.ToString() + ".txt", BuildExceptionString(e, "SPEDIT MAIN"));
139+
MessageBox.Show("An error occured." + Environment.NewLine + "A crash report was written in the editor-directory.",
140+
"Error",
141+
MessageBoxButton.OK,
142+
MessageBoxImage.Error);
143+
Environment.Exit(Environment.ExitCode);
144+
}
146145
#endif
147-
}
148-
else
149-
{
150-
try
151-
{
152-
StringBuilder sBuilder = new StringBuilder();
153-
bool addedFiles = false;
154-
for (int i = 0; i < args.Length; ++i)
155-
{
156-
if (!string.IsNullOrWhiteSpace(args[i]))
157-
{
158-
FileInfo fInfo = new FileInfo(args[i]);
159-
if (fInfo.Exists)
160-
{
161-
string ext = fInfo.Extension.ToLowerInvariant().Trim(new char[] { '.', ' ' });
162-
if (ext == "sp" || ext == "inc" || ext == "txt" || ext == "smx")
163-
{
164-
addedFiles = true;
165-
sBuilder.Append(fInfo.FullName);
166-
if ((i + 1) != args.Length)
167-
{ sBuilder.Append("|"); }
168-
}
169-
}
170-
}
171-
}
172-
if (addedFiles)
173-
{ PipeInteropClient.ConnectToMasterPipeAndSendData(sBuilder.ToString()); }
174-
}
175-
catch (Exception) { } //dont fuck the user up with irrelevant data
176-
}
146+
}
147+
else
148+
{
149+
try
150+
{
151+
StringBuilder sBuilder = new StringBuilder();
152+
bool addedFiles = false;
153+
for (int i = 0; i < args.Length; ++i)
154+
{
155+
if (!string.IsNullOrWhiteSpace(args[i]))
156+
{
157+
FileInfo fInfo = new FileInfo(args[i]);
158+
if (fInfo.Exists)
159+
{
160+
string ext = fInfo.Extension.ToLowerInvariant().Trim(new char[] { '.', ' ' });
161+
if (ext == "sp" || ext == "inc" || ext == "txt" || ext == "smx")
162+
{
163+
addedFiles = true;
164+
sBuilder.Append(fInfo.FullName);
165+
if ((i + 1) != args.Length)
166+
{ sBuilder.Append("|"); }
167+
}
168+
}
169+
}
170+
}
171+
if (addedFiles)
172+
{ PipeInteropClient.ConnectToMasterPipeAndSendData(sBuilder.ToString()); }
173+
}
174+
catch (Exception)
175+
{
176+
// ignored
177+
} //dont fuck the user up with irrelevant data
178+
}
177179
}
178180
}
179181

@@ -203,8 +205,7 @@ public static void ClearUpdateFiles()
203205

204206
private static void App_Startup(object sender, StartupEventArgs e)
205207
{
206-
207-
Tuple<MahApps.Metro.AppTheme, MahApps.Metro.Accent> appStyle = MahApps.Metro.ThemeManager.DetectAppStyle(Application.Current);
208+
MahApps.Metro.ThemeManager.DetectAppStyle(Application.Current);
208209
MahApps.Metro.ThemeManager.ChangeAppStyle(Application.Current,
209210
MahApps.Metro.ThemeManager.GetAccent("Green"),
210211
MahApps.Metro.ThemeManager.GetAppTheme("BaseDark")); // or appStyle.Item1
@@ -220,11 +221,10 @@ private static string BuildExceptionString(Exception e, string SectionName)
220221
outString.AppendLine("64 bit mode: " + ((Environment.Is64BitProcess) ? "TRUE" : "FALSE"));
221222
outString.AppendLine("Dir: " + Environment.CurrentDirectory);
222223
outString.AppendLine("Working Set: " + (Environment.WorkingSet / 1024).ToString() + " kb");
223-
outString.AppendLine("Installed UI Culture: " + System.Globalization.CultureInfo.InstalledUICulture ?? "null");
224-
outString.AppendLine("Current UI Culture: " + System.Globalization.CultureInfo.CurrentUICulture ?? "null");
225-
outString.AppendLine("Current Culture: " + System.Globalization.CultureInfo.CurrentCulture ?? "null");
224+
outString.AppendLine("Installed UI Culture: " + System.Globalization.CultureInfo.InstalledUICulture);
225+
outString.AppendLine("Current UI Culture: " + System.Globalization.CultureInfo.CurrentUICulture);
226+
outString.AppendLine("Current Culture: " + System.Globalization.CultureInfo.CurrentCulture);
226227
outString.AppendLine();
227-
Exception current = e;
228228
int eNumber = 1;
229229
for (; ; )
230230
{
@@ -246,12 +246,12 @@ private static string BuildExceptionString(Exception e, string SectionName)
246246
if (e.TargetSite != null)
247247
{
248248
outString.AppendLine("Targetsite Name:");
249-
outString.AppendLine(e.TargetSite.Name ?? "null");
249+
outString.AppendLine(e.TargetSite.Name);
250250
}
251251
e = e.InnerException;
252252
eNumber++;
253253
}
254-
return (eNumber - 1).ToString() + Environment.NewLine + outString.ToString();
254+
return (eNumber - 1) + Environment.NewLine + outString;
255255
}
256256
}
257257
}

0 commit comments

Comments
 (0)