Skip to content

Commit

Permalink
Added new Default Storage path (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Nov 17, 2024
1 parent f2ef29f commit 6ec1d41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 7 additions & 1 deletion InternetTest/InternetTest/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ public static class Global
public static string Version => "8.6.1.2409";
#endif
public static string LastVersionLink => "https://raw.githubusercontent.com/Leo-Corporation/LeoCorp-Docs/master/Liens/Update%20System/InternetTest/7.0/Version.txt";
internal static string SynethiaPath => $@"{FileSys.AppDataPath}\Léo Corporation\InternetTest Pro\NewSynethiaConfig.json";

#if PORTABLE
public static string DefaultStoragePath => $@"{FileSys.CurrentAppDirectory}\InternetTest Pro\";
#else
public static string DefaultStoragePath => $@"{FileSys.AppDataPath}\Léo Corporation\InternetTest Pro\";
#endif
public static string SynethiaPath => $@"{DefaultStoragePath}\NewSynethiaConfig.json";
public static bool IsConfidentialModeEnabled { get; set; } = false;
public static Settings Settings { get; set; } = SettingsManager.Load();
public static SynethiaConfig SynethiaConfig { get; set; } = LoadConfig();
Expand Down
13 changes: 6 additions & 7 deletions InternetTest/InternetTest/Classes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,20 @@ public Settings()

public static class SettingsManager
{
private static string SettingsPath => $@"{FileSys.AppDataPath}\Léo Corporation\InternetTest Pro\Settings.xml";
public static Settings Load()
{
if (!Directory.Exists($@"{FileSys.AppDataPath}\Léo Corporation\InternetTest Pro\"))
if (!Directory.Exists(Global.DefaultStoragePath))
{
Directory.CreateDirectory($@"{FileSys.AppDataPath}\Léo Corporation\InternetTest Pro\");
Directory.CreateDirectory(Global.DefaultStoragePath);
}

if (!File.Exists(SettingsPath))
if (!File.Exists($@"{Global.DefaultStoragePath}\Settings.xml"))
{
Global.Settings = new();

// Serialize to XML
XmlSerializer xmlSerializer = new(typeof(Settings));
StreamWriter streamWriter = new(SettingsPath);
StreamWriter streamWriter = new($@"{Global.DefaultStoragePath}\Settings.xml");
xmlSerializer.Serialize(streamWriter, Global.Settings);
streamWriter.Dispose();
return new();
Expand All @@ -106,7 +105,7 @@ public static Settings Load()
// Deserialize from xml
XmlSerializer xmlDeserializer = new(typeof(Settings));

StreamReader streamReader = new(SettingsPath);
StreamReader streamReader = new($@"{Global.DefaultStoragePath}\Settings.xml");
var settings = (Settings?)xmlDeserializer.Deserialize(streamReader) ?? new();

// Upgrade the settings file if it comes from an older version
Expand All @@ -130,7 +129,7 @@ public static void Save()
{
// Serialize to XML
XmlSerializer xmlSerializer = new(typeof(Settings));
StreamWriter streamWriter = new(SettingsPath);
StreamWriter streamWriter = new($@"{Global.DefaultStoragePath}\Settings.xml");
xmlSerializer.Serialize(streamWriter, Global.Settings);
streamWriter.Dispose();
}
Expand Down

0 comments on commit 6ec1d41

Please sign in to comment.