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

Commit 1456263

Browse files
authored
Merge pull request #128 from Muinez/master
Asynchronous config loading
2 parents 73142fd + cae26e0 commit 1456263

File tree

21 files changed

+2331
-711
lines changed

21 files changed

+2331
-711
lines changed

Program.cs

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -54,83 +54,83 @@ public static void Main(string[] args)
5454
try
5555
{
5656
#endif
57-
var splashScreen = new SplashScreen("Resources/Icons/icon256x.png");
58-
splashScreen.Show(false, true);
59-
Environment.CurrentDirectory =
60-
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ??
61-
throw new NullReferenceException();
57+
var splashScreen = new SplashScreen("Resources/Icons/icon256x.png");
58+
splashScreen.Show(false, true);
59+
Environment.CurrentDirectory =
60+
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ??
61+
throw new NullReferenceException();
6262
#if !DEBUG
6363
ProfileOptimization.SetProfileRoot(Environment.CurrentDirectory);
6464
ProfileOptimization.StartProfile("Startup.Profile");
6565
#endif
66-
UpdateStatus = new UpdateInfo();
67-
OptionsObject = OptionsControl.Load(out var ProgramIsNew);
66+
UpdateStatus = new UpdateInfo();
67+
OptionsObject = OptionsControl.Load(out var ProgramIsNew);
6868

69-
if (!File.Exists(Constants.HotkeysFile))
70-
{
71-
HotkeyControl.CreateDefaultHotkeys();
72-
}
73-
else
74-
{
75-
HotkeyControl.CheckAndBufferHotkeys();
76-
}
77-
78-
// Delete the default Ctrl+D hotkey to assign manually
79-
AvalonEditCommands.DeleteLine.InputGestures.Clear();
69+
if (!File.Exists(Constants.HotkeysFile))
70+
{
71+
HotkeyControl.CreateDefaultHotkeys();
72+
}
73+
else
74+
{
75+
HotkeyControl.CheckAndBufferHotkeys();
76+
}
8077

81-
if (OptionsObject.Program_DiscordPresence)
82-
{
83-
// Init Discord RPC
84-
DiscordClient.Initialize();
78+
// Delete the default Ctrl+D hotkey to assign manually
79+
AvalonEditCommands.DeleteLine.InputGestures.Clear();
8580

86-
// Set default presence
87-
DiscordClient.SetPresence(new RichPresence
81+
if (OptionsObject.Program_DiscordPresence)
8882
{
89-
State = "Idle",
90-
Timestamps = DiscordTime,
91-
Assets = new Assets
92-
{
93-
LargeImageKey = "immagine"
94-
},
95-
Buttons = new Button[]
83+
// Init Discord RPC
84+
DiscordClient.Initialize();
85+
86+
// Set default presence
87+
DiscordClient.SetPresence(new RichPresence
9688
{
97-
new Button() { Label = Constants.GetSPCodeText, Url = Constants.GitHubLatestRelease }
98-
}
99-
});
100-
}
89+
State = "Idle",
90+
Timestamps = DiscordTime,
91+
Assets = new Assets { LargeImageKey = "immagine" },
92+
Buttons = new Button[]
93+
{
94+
new Button()
95+
{
96+
Label = Constants.GetSPCodeText, Url = Constants.GitHubLatestRelease
97+
}
98+
}
99+
});
100+
}
101101

102-
// Set up translations
103-
Translations = new TranslationProvider();
104-
Translations.LoadLanguage(OptionsObject.Language, true);
102+
// Set up translations
103+
Translations = new TranslationProvider();
104+
Translations.LoadLanguage(OptionsObject.Language, true);
105105

106-
// Check startup arguments for -rcck
107-
foreach (var arg in args)
108-
{
109-
if (arg.ToLowerInvariant() == "-rcck") //ReCreateCryptoKey
106+
// Check startup arguments for -rcck
107+
foreach (var arg in args)
110108
{
111-
OptionsObject.ReCreateCryptoKey();
112-
MakeRCCKAlert();
109+
if (arg.ToLowerInvariant() == "-rcck") //ReCreateCryptoKey
110+
{
111+
OptionsObject.ReCreateCryptoKey();
112+
MakeRCCKAlert();
113+
}
113114
}
114-
}
115115

116-
Configs = ConfigLoader.Load();
117-
for (var i = 0; i < Configs.Count; ++i)
118-
{
119-
if (Configs[i].Name == OptionsObject.Program_SelectedConfig)
116+
Configs = ConfigLoader.Load();
117+
for (var i = 0; i < Configs.Count; ++i)
120118
{
121-
SelectedConfig = i;
122-
break;
119+
if (Configs[i].Name == OptionsObject.Program_SelectedConfig)
120+
{
121+
SelectedConfig = i;
122+
break;
123+
}
123124
}
124-
}
125125

126-
if (!OptionsObject.Program_UseHardwareAcceleration)
127-
{
128-
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
129-
}
126+
if (!OptionsObject.Program_UseHardwareAcceleration)
127+
{
128+
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
129+
}
130130
#if !DEBUG
131131
if (ProgramIsNew)
132132
{
133-
if (Translations.AvailableLanguageIDs.Count> 0)
133+
if (Translations.AvailableLanguageIDs.Count > 0)
134134
{
135135
splashScreen.Close(new TimeSpan(0, 0, 1));
136136
var langIds = Translations.AvailableLanguageIDs;
@@ -148,9 +148,9 @@ public static void Main(string[] args)
148148
}
149149
}
150150
#endif
151-
MainWindow = new MainWindow(splashScreen);
152-
var pipeServer = new PipeInteropServer(MainWindow);
153-
pipeServer.Start();
151+
MainWindow = new MainWindow(splashScreen);
152+
var pipeServer = new PipeInteropServer(MainWindow);
153+
pipeServer.Start();
154154
#if !DEBUG
155155
}
156156
catch (Exception e)
@@ -176,9 +176,9 @@ public static void Main(string[] args)
176176
Task.Run(UpdateCheck.Check);
177177
}
178178
#endif
179-
app.Startup += App_Startup;
180-
app.Run(MainWindow);
181-
OptionsControl.Save();
179+
app.Startup += App_Startup;
180+
app.Run(MainWindow);
181+
OptionsControl.Save();
182182
#if !DEBUG
183183
}
184184
catch (Exception e)

SPCodeBenchmarks/CondenserBench.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Configs;
3+
using BenchmarkDotNet.Jobs;
4+
using BenchmarkDotNet.Toolchains.InProcess.NoEmit;
5+
using SourcepawnCondenser;
6+
using static SPCode.Utils.SPSyntaxTidy.SPSyntaxTidy;
7+
8+
namespace SPCodeBenchmarks;
9+
10+
[Config(typeof(Config))]
11+
[MemoryDiagnoser]
12+
public class CondenserBench
13+
{
14+
private class Config : ManualConfig
15+
{
16+
public Config()
17+
{
18+
AddJob(Job.MediumRun
19+
.WithLaunchCount(1)
20+
.WithToolchain(InProcessNoEmitToolchain.Instance)
21+
.WithId("InProcess"));
22+
}
23+
}
24+
25+
[Benchmark]
26+
public void Condense()
27+
{
28+
var text = File.ReadAllText("sourcepawn/nativevotes.inc");
29+
30+
var condenser =
31+
new Condenser(text, "test"); // The biggest thing I found
32+
33+
condenser.Condense();
34+
}
35+
}

SPCodeBenchmarks/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using BenchmarkDotNet.Running;
2+
using SPCodeBenchmarks;
3+
4+
BenchmarkRunner.Run<CondenserBench>();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net48</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<LangVersion>latest</LangVersion>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\SourcepawnCondenser\SourcepawnCondenser\SourcepawnCondenser.csproj" />
13+
<ProjectReference Include="..\SPCode.csproj" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<Content Include="sourcepawn\**">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</Content>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<PackageReference Include="BenchmarkDotNet">
24+
<Version>0.13.2</Version>
25+
</PackageReference>
26+
</ItemGroup>
27+
28+
29+
</Project>

0 commit comments

Comments
 (0)