-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_settings.cpp
170 lines (133 loc) · 3.57 KB
/
mod_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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "stdafx.h"
#include "mod_settings.h"
#include "launcher_settings.h"
#include "misc.h"
#include "iniparser/iniparser.h"
#include "iniparser/dictionary.h"
char ModSettings::m_mod_params[1024] = "";
char ModSettings::m_standard_params[1024] = "";
char ModSettings::m_custom_params[1024] = "";
bool ModSettings::load_mod()
{
char ini_name[MAX_PATH];
sprintf(ini_name, "%s\\%s\\%s", LauncherSettings::get_exe_pathonly(), LauncherSettings::get_active_mod(), const_cast<char*>(INI_MOD_DEFAULT));
dictionary *ini = iniparser_load(ini_name);
if (ini == NULL)
return false;
iniparser_dump(ini, stderr);
// read ini variables
// TODO
Int3();
// atomically assign all ini variables
// TODO
Int3();
iniparser_freedict(ini);
return true;
}
bool ModSettings::load_user()
{
if (LauncherSettings::get_exe_type() == EXE_TYPE_CUSTOM)
return load_user_fso();
else
return load_user_retail();
}
bool ModSettings::load_user_fso()
{
char ini_name[MAX_PATH];
sprintf(ini_name, "%s\\%s\\%s", LauncherSettings::get_exe_pathonly(), LauncherSettings::get_active_mod(), const_cast<char*>(INI_MOD_CUSTOM));
dictionary *ini = iniparser_load(ini_name);
if (ini == NULL)
return false;
iniparser_dump(ini, stderr);
// read ini variables
char *standard_params = iniparser_getstr(ini, "settings:flags");
if (standard_params == NULL)
return false;
// atomically assign all ini variables
strcpy(m_standard_params, standard_params);
strcpy(m_custom_params, "");
iniparser_freedict(ini);
return true;
}
bool ModSettings::load_user_retail()
{
FILE *fp = NULL;
char path_buffer[MAX_PATH];
bool exists = check_cfg_file(path_buffer);
if (!exists)
return false;
fp = fopen(path_buffer, "rt");
if (fp == NULL)
return false;
// read cfg variables
char custom_params[MAX_CUSTOM_PARAM_SIZE];
fgets(m_custom_params, sizeof(m_custom_params) - 1, fp);
//if (custom_params == NULL)
// return false;
// atomically assign all cfg variables
strcpy(m_standard_params, "");
strcpy(m_custom_params, custom_params);
fclose(fp);
return true;
}
bool ModSettings::save_user()
{
char path_buffer[MAX_PATH];
char all_params[3000] = { 0 };
FILE *fp;
// build command line (sans exe)
if (*m_mod_params)
{
strcat(all_params, m_mod_params);
strcat(all_params, " ");
}
if (*m_standard_params)
{
strcat(all_params, m_standard_params);
strcat(all_params, " ");
}
if (*m_custom_params)
{
strcat(all_params, m_custom_params);
strcat(all_params, " ");
}
trim(all_params);
// write to config file
check_cfg_file(path_buffer, true);
fp = fopen(path_buffer, "wt");
if (fp)
{
fwrite(all_params, len * sizeof(char), 1, fp);
fclose(fp);
}
// write standard params to ini file
char ini_name[MAX_PATH];
sprintf(ini_name, "%s\\%s\\%s", LauncherSettings::get_exe_pathonly(), LauncherSettings::get_active_mod(), const_cast<char*>(INI_MOD_CUSTOM));
fp = ini_open_for_write(ini_name, false, "These are the user's custom settings; don't distribute them with the mod because he'll want to choose his own");
if (fp == NULL)
return false;
ini_write_type(fp, "[settings]");
ini_write_data(fp, "flags", m_standard_params);
ini_close(fp);
return true;
}
char *ModSettings::get_mod_parameters()
{
return m_mod_params;
}
char *ModSettings::get_standard_parameters()
{
return m_standard_params;
}
char *ModSettings::get_custom_parameters()
{
return m_custom_params;
}
void ModSettings::set_standard_parameters(const char *standard_params)
{
strcpy(m_standard_params, standard_params);
}
void ModSettings::set_custom_parameters(const char *custom_params)
{
strcpy(m_custom_params, custom_params);
}