-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher_settings.cpp
152 lines (118 loc) · 3.18 KB
/
launcher_settings.cpp
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "stdafx.h"
#include "launcher_settings.h"
#include "misc.h"
#include "iniparser/iniparser.h"
#include "iniparser/dictionary.h"
char LauncherSettings::m_exe_filepath[MAX_PATH] = "";
char LauncherSettings::m_exe_pathonly[MAX_PATH] = "";
char LauncherSettings::m_exe_nameonly[MAX_PATH] = "";
bool LauncherSettings::m_is_exe_path_valid = false;
char LauncherSettings::m_reg_path[MAX_PATH] = "";
int LauncherSettings::m_exe_type = EXE_TYPE_NONE;
char LauncherSettings::m_active_mod[MAX_PATH] = "";
bool LauncherSettings::m_showed_pilot_warning = false;
bool LauncherSettings::m_is_openal_build = false;
bool LauncherSettings::load()
{
dictionary *ini = iniparser_load(const_cast<char*>(INI_MAIN));
if (ini == NULL)
return false;
iniparser_dump(ini, stderr);
// read ini variables
char *exe_filepath = iniparser_getstr(ini, "launcher:exe_filepath");
char *active_mod = iniparser_getstr(ini, "launcher:active_mod");
bool showed_pilot_warning = (iniparser_getboolean(ini, "launcher:showed_pilot_warning", 0) != 0);
if (exe_filepath == NULL || active_mod == NULL)
return false;
// atomically assign all ini variables
set_exe_filepath(exe_filepath);
set_active_mod(active_mod);
m_showed_pilot_warning = showed_pilot_warning;
iniparser_freedict(ini);
return true;
}
bool LauncherSettings::save()
{
FILE *fp = ini_open_for_write(const_cast<char*>(INI_MAIN), false, "DO NOT EDIT THIS FILE");
if (fp == NULL)
return false;
ini_write_type(fp, "[launcher]");
ini_write_data(fp, "exe_filepath", m_exe_filepath);
ini_write_data(fp, "active_mod", m_active_mod);
ini_write_data(fp, "showed_pilot_warning", m_showed_pilot_warning);
ini_close(fp);
return true;
}
char *LauncherSettings::get_exe_pathonly()
{
return m_exe_pathonly;
}
char *LauncherSettings::get_exe_nameonly()
{
return m_exe_nameonly;
}
char *LauncherSettings::get_exe_filepath()
{
return m_exe_filepath;
}
bool LauncherSettings::is_exe_path_valid()
{
return m_is_exe_path_valid;
}
void LauncherSettings::set_exe_filepath(const char *path)
{
if (path == NULL || *path == '\0')
return;
strcpy(m_exe_filepath, path);
strcpy(m_exe_pathonly, path);
char *final_slash = strrchr(m_exe_pathonly, '\\');
if (final_slash != NULL)
{
strcpy(m_exe_nameonly, final_slash+1);
*final_slash = '\0';
m_is_exe_path_valid = true;
}
else
{
*m_exe_pathonly = '\0';
strcpy(m_exe_nameonly, path);
m_is_exe_path_valid = false;
}
}
char *LauncherSettings::get_reg_path()
{
return m_reg_path;
}
int LauncherSettings::get_exe_type()
{
return m_exe_type;
}
void LauncherSettings::set_reg_path(const char *reg_path, int exe_type)
{
strcpy(m_reg_path, reg_path);
m_exe_type = exe_type;
}
char *LauncherSettings::get_active_mod()
{
return m_active_mod;
}
void LauncherSettings::set_active_mod(const char *active_mod)
{
strcpy(m_active_mod, active_mod);
}
bool LauncherSettings::get_showed_pilot_warning()
{
return m_showed_pilot_warning;
}
void LauncherSettings::set_showed_pilot_warning(bool showed_pilot_warning)
{
m_showed_pilot_warning = showed_pilot_warning;
}
bool LauncherSettings::is_openal_build()
{
return m_is_openal_build;
}
void LauncherSettings::set_openal_build(bool flag)
{
m_is_openal_build = flag;
}