Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d #8

Merged
merged 2 commits into from
Dec 18, 2023
Merged

d #8

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions ShareLoader.Share/SettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ namespace ShareLoader.Share;

public class SettingsHelper
{
private static bool isLoaded = false;
public static string FilePath { get; set; } = "/shareloader/settings.txt";

public static Dictionary<string, string> Settings { get; set; } = new Dictionary<string, string>();

public static T? GetSetting<T>(string name)
{
if(Settings == null) Load();
if(Settings == null || !Settings.ContainsKey(name)) return (T?)Convert.ChangeType(null, typeof(T?));
if(!isLoaded) Load();
if(!Settings.ContainsKey(name)) return (T?)Convert.ChangeType(null, typeof(T?));
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(Settings[name]);
}

public static string GetSetting(string name)
{
if(Settings == null) Load();
if(Settings == null || !Settings.ContainsKey(name)) return "";
if(!isLoaded) Load();
if(!Settings.ContainsKey(name)) return "";
return Settings[name];
}

Expand Down Expand Up @@ -44,6 +45,7 @@ public static void SetSetting(string name, string value)

public static void Load()
{
isLoaded = true;
if(!Directory.Exists("/shareloader"))
{
Console.WriteLine("/shareloader/ doesnt exist");
Expand Down
Loading