forked from jadaradix/dsgamemaker
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOptionsLib.cs
More file actions
81 lines (73 loc) · 2.67 KB
/
OptionsLib.cs
File metadata and controls
81 lines (73 loc) · 2.67 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
namespace DS_Game_Maker
{
internal static partial class OptionsLib
{
public static List<string> OptionNames = new List<string>();
public static List<string> OptionValues = new List<string>();
public static string OptionPath = string.Empty;
public static void LoadOptions()
{
OptionNames.Clear();
OptionValues.Clear();
foreach (string OL in File.ReadAllLines(OptionPath))
{
string OName = OL.Substring(0, OL.IndexOf(" "));
string OValue = OL.Substring(OL.IndexOf(" ") + 1);
OptionNames.Add(OName);
OptionValues.Add(OValue);
}
}
public static void SaveOptions()
{
string FinalString = string.Empty;
for (ushort I = 0, loopTo = (ushort)(OptionNames.Count - 1); I <= loopTo; I++)
FinalString += OptionNames[I] + " " + OptionValues[I] + Constants.vbCrLf;
File.WriteAllText(OptionPath, FinalString);
}
public static string GetOption(string SettingName)
{
for (byte SettingNo = 0, loopTo = (byte)(OptionNames.Count - 1); SettingNo <= loopTo; SettingNo++)
{
if (OptionNames[SettingNo] == SettingName)
return OptionValues[SettingNo];
}
return string.Empty;
}
public static void SetOption(string OptionName, string OptionValue)
{
var BackupValues = new List<string>();
for (byte SettingNo = 0, loopTo = (byte)(OptionNames.Count - 1); SettingNo <= loopTo; SettingNo++)
{
if (OptionNames[SettingNo] == OptionName)
{
BackupValues.Add(OptionValue);
}
else
{
BackupValues.Add(OptionValues[SettingNo]);
}
}
OptionValues.Clear();
for (ushort I = 0, loopTo1 = (ushort)(BackupValues.Count - 1); I <= loopTo1; I++)
OptionValues.Add(BackupValues[I]);
BackupValues.Clear();
}
public static void PatchOption(string OName, string OValue)
{
bool DoTheAdd = true;
string FS = string.Empty;
foreach (string OL in File.ReadAllLines(OptionPath))
{
if (OL.StartsWith(OName + " "))
DoTheAdd = false;
FS += OL + Constants.vbCrLf;
}
if (DoTheAdd)
{
FS += OName + " " + OValue;
File.WriteAllText(OptionPath, FS);
}
}
}
}