-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cs
95 lines (85 loc) · 3.14 KB
/
Config.cs
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace ChusanExplorer
{
public static class Config
{
public static readonly Color[] rarityColors = new Color[]
{
Color.White,
Color.LightGreen,
Color.LightBlue,
Color.HotPink,
Color.Orange,
Color.Gold,
Color.IndianRed,
Color.DarkRed,
};
public static readonly Color[] levelColors = new Color[]
{
Color.Green,
Color.Orange,
Color.IndianRed,
Color.Purple,
};
public const string ALL = "(All)";
public const string NO_DESCRIP = "-";
public static string DirA000 = "C:/Chunithm New Plus/app/data/A000";
public static string DirOptions = "C:/Chunithm New Plus/option";
public static string DirAquaDB = "C:/Chunithm New Plus/aqua-0.0.31-RELEASE/data/db.sqlite";
public static bool MuteErrors = false;
static ReadWriteINIfile ini;
static string iniPath = Path.GetFullPath("config.ini");
const string grpData = "Game Files",
grpDB = "Aqua Files",
grpSettings = "Settings";
const string keyA000 = "path_to_A000",
keyOption = "path_to_option",
keyDB = "path_to_db",
keyMuteError = "mute_errors";
public static void Init()
{
ini = new ReadWriteINIfile(iniPath);
if (File.Exists(iniPath))
{
// read
DirA000 = Path.GetFullPath(ini.ReadINI(grpData, keyA000));
DirOptions = Path.GetFullPath(ini.ReadINI(grpData, keyOption));
DirAquaDB = Path.GetFullPath(ini.ReadINI(grpDB, keyDB));
bool.TryParse(ini.ReadINI(grpSettings, keyMuteError), out MuteErrors);
}
else
{
// write
ini.WriteINI(grpData, keyA000, DirA000);
ini.WriteINI(grpData, keyOption, DirOptions);
ini.WriteINI(grpDB, keyDB, DirAquaDB);
ini.WriteINI(grpSettings, keyMuteError, MuteErrors.ToString());
}
}
}
public class ReadWriteINIfile
{
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string name, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
public string path;
public ReadWriteINIfile(string inipath)
{
path = inipath;
}
public void WriteINI(string name, string key, string value)
{
WritePrivateProfileString(name, key, value, this.path);
}
public string ReadINI(string name, string key)
{
StringBuilder sb = new StringBuilder(255);
GetPrivateProfileString(name, key, "", sb, 255, this.path);
return sb.ToString();
}
}
}