-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMLSaveSettings.cpp
More file actions
84 lines (65 loc) · 1.84 KB
/
Copy pathMLSaveSettings.cpp
File metadata and controls
84 lines (65 loc) · 1.84 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
82
83
#include "MLSaveSettings.h"
#include <Windows.h>
#include "DXSampleHelper.h"
#include <shlwapi.h>
static const char* gSectionName = "Main";
static void
GetAssetsPathA(_Out_writes_(pathSize) char* path, UINT pathSize)
{
if (path == nullptr) {
throw std::exception();
}
DWORD size = GetModuleFileNameA(nullptr, path, pathSize);
if (size == 0 || size == pathSize) {
// Method failed or path was truncated.
throw std::exception();
}
char* lastSlash = strrchr(path, L'\\');
if (lastSlash) {
*(lastSlash + 1) = L'\0';
}
}
MLSaveSettings::MLSaveSettings(const char *settingsFileName)
{
char path[MAX_PATH];
GetAssetsPathA(path, _countof(path));
mSettingsFileNameA = std::string(path) + settingsFileName;
mIni.SetUnicode();
mIni.LoadFile(mSettingsFileNameA.c_str());
wchar_t nameW[256] = {};
}
MLSaveSettings::~MLSaveSettings(void) {
}
void
MLSaveSettings::WriteToFile(void) {
mIni.SaveFile(mSettingsFileNameA.c_str());
}
void
MLSaveSettings::SaveInt(const char* key, int v) {
mIni.SetLongValue(gSectionName, key, v);
}
int
MLSaveSettings::LoadInt(const char* key, int defaultValue) {
return mIni.GetLongValue(gSectionName, key, defaultValue);
}
void
MLSaveSettings::SaveDouble(const char* key, double v) {
mIni.SetDoubleValue(gSectionName, key, v);
}
double
MLSaveSettings::LoadDouble(const char* key, double defaultValue) {
return mIni.GetDoubleValue(gSectionName, key, defaultValue);
}
void
MLSaveSettings::SaveStringA(const char* key, const char* name) {
mIni.SetValue(gSectionName, key, name);
}
const std::string
MLSaveSettings::LoadStringA(const char* key) {
const char *name_r = mIni.GetValue(gSectionName, key, "");
if (nullptr == name_r || strlen(name_r) == 0) {
return "";
}
// std::string‚ðì‚Á‚Ä–ß‚·B
return name_r;
}