Skip to content

Commit

Permalink
Fixed config loading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarah Hawthorne committed Sep 3, 2020
1 parent 3e20087 commit 86ac0d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Apex Launcher/Apex Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@
<ApplicationIcon>giratina.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>Properties\LauncherKey.pfx</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down Expand Up @@ -148,7 +149,6 @@
<EmbeddedResource Include="Forms\TextEntryForm.resx">
<DependentUpon>TextEntryForm.cs</DependentUpon>
</EmbeddedResource>
<None Include="Properties\LauncherKey.pfx" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
21 changes: 13 additions & 8 deletions Apex Launcher/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Apex_Launcher {
public static class Config {
private static bool _loaded = false;
private static string Filepath => Path.Combine(Directory.GetCurrentDirectory(), "config.txt");

private static VersionGameFiles _currentVersion;
Expand All @@ -15,7 +16,7 @@ public static VersionGameFiles CurrentVersion {
}
set {
_currentVersion = value;
SaveConfig();
if (_loaded) SaveConfig();
}
}

Expand All @@ -26,7 +27,7 @@ public static VersionAudio CurrentAudioVersion {
}
set {
_currentVersionAudio = value;
SaveConfig();
if (_loaded) SaveConfig();
}
}

Expand All @@ -38,7 +39,7 @@ public static string InstallPath {
}
set {
_installPath = value;
SaveConfig();
if (_loaded) SaveConfig();
}
}

Expand All @@ -49,7 +50,7 @@ public static bool KeepLauncherOpen {
}
set {
_keepLauncherOpen = value;
SaveConfig();
if (_loaded) SaveConfig();
}
}

Expand All @@ -60,7 +61,7 @@ public static bool DisableAudioDownload {
}
set {
_disableAudioDownload = value;
SaveConfig();
if (_loaded) SaveConfig();
}
}

Expand All @@ -73,20 +74,24 @@ public static void LoadConfig() {
string value = split[1].Trim();

foreach (PropertyInfo pi in typeof(Config).GetProperties()) {
if (pi.Name.ToLower() == param) {
if (pi.Name.ToLower() == param.ToLower()) {
try {
object v = null;
if (pi.PropertyType.IsAssignableFrom(typeof(IDownloadable))) {
if (pi.PropertyType.GetInterfaces().Contains(typeof(IDownloadable))) {
if (pi.PropertyType == typeof(VersionGameFiles)) v = VersionGameFiles.FromString(value);
if (pi.PropertyType == typeof(VersionAudio)) v = VersionAudio.FromString(value);
} else pi.SetValue(null, Convert.ChangeType(value, pi.PropertyType));
} else v = Convert.ChangeType(value, pi.PropertyType);

pi.SetValue(null, v);
} catch (Exception) {
pi.SetValue(null, default);
}
break;
}
}
}

_loaded = true;
}

public static void SaveConfig() {
Expand Down

0 comments on commit 86ac0d7

Please sign in to comment.