-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfig.cs
More file actions
61 lines (52 loc) · 1.66 KB
/
Config.cs
File metadata and controls
61 lines (52 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
namespace Pluton.Core
{
using System;
using System.IO;
using UnityEngine;
public class Config : Singleton<Config>, ISingleton
{
IniParser PlutonConfig;
public void Initialize()
{
string ConfigPath = DirectoryConfig.GetInstance().GetConfigPath("Pluton");
if (File.Exists(ConfigPath)) {
PlutonConfig = new IniParser(ConfigPath);
Debug.Log("Config " + ConfigPath + " loaded!");
} else {
Directory.CreateDirectory(Util.GetInstance().GetPublicFolder());
File.Create(ConfigPath).Close();
PlutonConfig = new IniParser(ConfigPath);
Debug.Log("Config " + ConfigPath + " Created!");
Debug.Log("The config will be filled with the default values.");
}
}
static Config()
{
dependencies = new System.Collections.Generic.List<Func<bool>> {
() => SingletonEx.IsInitialized<DirectoryConfig>()
};
}
public string GetValue(string Section, string Setting, string defaultValue = "")
{
if (!PlutonConfig.ContainsSetting(Section, Setting)) {
PlutonConfig.AddSetting(Section, Setting, defaultValue);
PlutonConfig.Save();
}
return PlutonConfig.GetSetting(Section, Setting, defaultValue);
}
public bool GetBoolValue(string Section, string Setting, bool defaultValue = false)
{
if (!PlutonConfig.ContainsSetting(Section, Setting)) {
PlutonConfig.AddSetting(Section, Setting, defaultValue.ToString().ToLower());
PlutonConfig.Save();
}
return PlutonConfig.GetBoolSetting(Section, Setting, defaultValue);
}
public void Reload()
{
string ConfigPath = DirectoryConfig.GetInstance().GetConfigPath("Pluton");
if (File.Exists(ConfigPath))
PlutonConfig = new IniParser(ConfigPath);
}
}
}