1 |
/* Pcsx2 - Pc Ps2 Emulator |
2 |
* Copyright (C) 2002-2003 Pcsx2 Team |
3 |
* |
4 |
* This program is free software; you can redistribute it and/or modify |
5 |
* it under the terms of the GNU General Public License as published by |
6 |
* the Free Software Foundation; either version 2 of the License, or |
7 |
* (at your option) any later version. |
8 |
* |
9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
* GNU General Public License for more details. |
13 |
* |
14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
17 |
*/ |
18 |
|
19 |
#include "Win32.h" |
20 |
|
21 |
#include "Common.h" |
22 |
#include "Paths.h" |
23 |
|
24 |
static const u32 IniVersion = 102; |
25 |
|
26 |
const char* g_CustomConfigFile; |
27 |
//char g_WorkingFolder[g_MaxPath]; // Working folder at application startup |
28 |
|
29 |
// Returns TRUE if the user has invoked the -cfg command line option. |
30 |
static bool hasCustomConfig() |
31 |
{ |
32 |
return (g_CustomConfigFile != NULL) && (g_CustomConfigFile[0] != 0); |
33 |
} |
34 |
|
35 |
// Returns the FULL (absolute) path and filename of the configuration file. |
36 |
static wxString GetConfigFilename() |
37 |
{ |
38 |
// Load a user-specified configuration, or use the ini relative to the application's working directory. |
39 |
// (Our current working directory can change, so we use the one we detected at startup) |
40 |
|
41 |
return Path::Combine( Config.Paths.Working, hasCustomConfig() ? g_CustomConfigFile : (DEFAULT_INIS_DIR "\\pcsx2.ini") ); |
42 |
} |
43 |
|
44 |
////////////////////////////////////////////////////////////////////////////////////////// |
45 |
// InitFileLoader |
46 |
|
47 |
IniFileLoader::~IniFileLoader() {} |
48 |
IniFileLoader::IniFileLoader() : IniFile(), |
49 |
m_workspace( 4096, "IniFileLoader Workspace" ) |
50 |
{ |
51 |
} |
52 |
|
53 |
void IniFileLoader::Entry( const wxString& var, wxString& value, const wxString& defvalue ) |
54 |
{ |
55 |
int retval = GetPrivateProfileString( |
56 |
m_section.c_str(), var.c_str(), defvalue.c_str(), m_workspace.GetPtr(), m_workspace.GetLength(), m_filename.c_str() |
57 |
); |
58 |
|
59 |
if( retval >= m_workspace.GetLength() - 2 ) |
60 |
Console::Notice( "Loadini Warning > Possible truncated value on key '%hs'", params &var ); |
61 |
//Console::WriteLn( "WTF!! %s ", params m_workspace.GetPtr() ); |
62 |
value = m_workspace.GetPtr(); |
63 |
} |
64 |
|
65 |
void IniFileLoader::Entry( const wxString& var, char (&value)[g_MaxPath], const wxString& defvalue ) |
66 |
{ |
67 |
int retval = GetPrivateProfileString( |
68 |
m_section.c_str(), var.c_str(), defvalue.c_str(), value, sizeof( value ), m_filename.c_str() |
69 |
); |
70 |
|
71 |
if( retval >= sizeof(value) - 2 ) |
72 |
Console::Notice( "Loadini Warning > Possible truncated value on key '%hs'", params &var ); |
73 |
} |
74 |
|
75 |
void IniFileLoader::Entry( const wxString& var, int& value, const int defvalue ) |
76 |
{ |
77 |
wxString retval; |
78 |
Entry( var, retval, to_string( defvalue ) ); |
79 |
value = atoi( retval.c_str() ); |
80 |
} |
81 |
|
82 |
void IniFileLoader::Entry( const wxString& var, uint& value, const uint defvalue ) |
83 |
{ |
84 |
wxString retval; |
85 |
Entry( var, retval, to_string( defvalue ) ); |
86 |
value = atoi( retval.c_str() ); |
87 |
} |
88 |
|
89 |
void IniFileLoader::Entry( const wxString& var, bool& value, const bool defvalue ) |
90 |
{ |
91 |
wxString retval; |
92 |
Entry( var, retval, defvalue ? "enabled" : "disabled" ); |
93 |
value = (retval == "enabled"); |
94 |
} |
95 |
|
96 |
void IniFileLoader::EnumEntry( const wxString& var, int& value, const char* const* enumArray, const int defvalue ) |
97 |
{ |
98 |
wxString retval; |
99 |
Entry( var, retval, enumArray[defvalue] ); |
100 |
|
101 |
int i=0; |
102 |
while( enumArray[i] != NULL && ( retval != enumArray[i] ) ) i++; |
103 |
|
104 |
if( enumArray[i] == NULL ) |
105 |
{ |
106 |
Console::Notice( "Loadini Warning > Unrecognized value '%hs' on key '%hs'\n\tUsing the default setting of '%s'.", |
107 |
params &retval, &var, enumArray[defvalue] ); |
108 |
value = defvalue; |
109 |
} |
110 |
else |
111 |
value = i; |
112 |
} |
113 |
|
114 |
////////////////////////////////////////////////////////////////////////////////////////// |
115 |
// InitFileSaver |
116 |
|
117 |
IniFileSaver::~IniFileSaver() {} |
118 |
|
119 |
IniFileSaver::IniFileSaver() : IniFile() |
120 |
{ |
121 |
char versionStr[20]; |
122 |
_itoa( IniVersion, versionStr, 10 ); |
123 |
WritePrivateProfileString( "Misc", "IniVersion", versionStr, m_filename.c_str() ); |
124 |
} |
125 |
|
126 |
void IniFileSaver::Entry( const wxString& var, const wxString& value, const wxString& defvalue ) |
127 |
{ |
128 |
WritePrivateProfileString( m_section.c_str(), var.c_str(), value.c_str(), m_filename.c_str() ); |
129 |
} |
130 |
|
131 |
void IniFileSaver::Entry( const wxString& var, wxString& value, const wxString& defvalue ) |
132 |
{ |
133 |
WritePrivateProfileString( m_section.c_str(), var.c_str(), value.c_str(), m_filename.c_str() ); |
134 |
} |
135 |
|
136 |
void IniFileSaver::Entry( const wxString& var, char (&value)[g_MaxPath], const wxString& defvalue ) |
137 |
{ |
138 |
WritePrivateProfileString( m_section.c_str(), var.c_str(), value, m_filename.c_str() ); |
139 |
} |
140 |
|
141 |
void IniFileSaver::Entry( const wxString& var, int& value, const int defvalue ) |
142 |
{ |
143 |
Entry( var, to_string( value ) ); |
144 |
} |
145 |
|
146 |
void IniFileSaver::Entry( const wxString& var, uint& value, const uint defvalue ) |
147 |
{ |
148 |
Entry( var, to_string( value ) ); |
149 |
} |
150 |
|
151 |
void IniFileSaver::Entry( const wxString& var, bool& value, const bool defvalue ) |
152 |
{ |
153 |
Entry( var, value ? "enabled" : "disabled" ); |
154 |
} |
155 |
|
156 |
void IniFileSaver::EnumEntry( const wxString& var, int& value, const char* const* enumArray, const int defvalue ) |
157 |
{ |
158 |
Entry( var, enumArray[value] ); |
159 |
} |
160 |
|
161 |
////////////////////////////////////////////////////////////////////////////////////////// |
162 |
// InitFile -- Base class implementation. |
163 |
|
164 |
IniFile::~IniFile() {} |
165 |
IniFile::IniFile() : m_filename( GetConfigFilename() ), m_section("Misc") |
166 |
{ |
167 |
} |
168 |
|
169 |
void IniFile::SetCurrentSection( const wxString& newsection ) |
170 |
{ |
171 |
m_section = newsection; |
172 |
} |
173 |
|
174 |
void IniFile::DoConfig( PcsxConfig& Conf ) |
175 |
{ |
176 |
SetCurrentSection( "Misc" ); |
177 |
|
178 |
Entry( "Blockdump", Conf.Blockdump, false ); |
179 |
|
180 |
Entry( "Patching", Conf.Patch, false ); |
181 |
Entry( "GameFixes", Conf.GameFixes); |
182 |
|
183 |
#ifdef PCSX2_DEVBUILD |
184 |
Entry( "DevLogFlags", (uint&)varLog ); |
185 |
#endif |
186 |
|
187 |
//interface |
188 |
SetCurrentSection( "Interface" ); |
189 |
Entry( "Bios", Conf.Bios ); |
190 |
Entry( "Language", Conf.Lang ); |
191 |
wxString plug = DEFAULT_PLUGINS_DIR; |
192 |
Entry( "PluginsDir", Conf.Paths.Plugins, plug ); |
193 |
wxString bios = DEFAULT_BIOS_DIR; |
194 |
Entry( "BiosDir", Conf.Paths.Bios, bios ); |
195 |
Entry( "CloseGsOnEscape", Conf.closeGSonEsc, true ); |
196 |
|
197 |
SetCurrentSection( "Console" ); |
198 |
Entry( "ConsoleWindow", Conf.PsxOut, true ); |
199 |
Entry( "Profiler", Conf.Profiler, false ); |
200 |
Entry( "CdvdVerbose", Conf.cdvdPrint, false ); |
201 |
|
202 |
SetCurrentSection( "Framelimiter" ); |
203 |
Entry( "CustomFps", Conf.CustomFps ); |
204 |
Entry( "FrameskipMode", Conf.CustomFrameSkip ); |
205 |
Entry( "ConsecutiveFramesToRender", Conf.CustomConsecutiveFrames ); |
206 |
Entry( "ConsecutiveFramesToSkip", Conf.CustomConsecutiveSkip ); |
207 |
|
208 |
MemcardSettings( Conf ); |
209 |
|
210 |
SetCurrentSection( "Plugins" ); |
211 |
|
212 |
Entry( "GS", Conf.Plugins.GS ); |
213 |
Entry( "SPU2", Conf.Plugins.SPU2 ); |
214 |
Entry( "CDVD", Conf.Plugins.CDVD ); |
215 |
Entry( "PAD1", Conf.Plugins.PAD1 ); |
216 |
Entry( "PAD2", Conf.Plugins.PAD2 ); |
217 |
Entry( "DEV9", Conf.Plugins.DEV9 ); |
218 |
Entry( "USB", Conf.Plugins.USB ); |
219 |
Entry( "FW", Conf.Plugins.FW ); |
220 |
|
221 |
//cpu |
222 |
SetCurrentSection( "Cpu" ); |
223 |
Entry( "Options", Conf.Options, PCSX2_EEREC|PCSX2_VU0REC|PCSX2_VU1REC|PCSX2_GSMULTITHREAD|PCSX2_FRAMELIMIT_LIMIT ); |
224 |
Entry( "sseMXCSR", Conf.sseMXCSR, DEFAULT_sseMXCSR ); |
225 |
Entry( "sseVUMXCSR", Conf.sseVUMXCSR, DEFAULT_sseVUMXCSR ); |
226 |
Entry( "eeOptions", Conf.eeOptions, DEFAULT_eeOptions ); |
227 |
Entry( "vuOptions", Conf.vuOptions, DEFAULT_vuOptions ); |
228 |
|
229 |
SetCurrentSection("Hacks"); |
230 |
Entry("EECycleRate", Config.Hacks.EECycleRate); |
231 |
if (Config.Hacks.EECycleRate > 2) |
232 |
Config.Hacks.EECycleRate = 2; |
233 |
Entry("IOPCycleDouble", Config.Hacks.IOPCycleDouble); |
234 |
//Entry("WaitCycleExt", Config.Hacks.WaitCycleExt); |
235 |
Entry("INTCSTATSlow", Config.Hacks.INTCSTATSlow); |
236 |
Entry("VUCycleSteal", Config.Hacks.VUCycleSteal); |
237 |
Entry("vuFlagHack", Config.Hacks.vuFlagHack); |
238 |
Entry("vuMinMax", Config.Hacks.vuMinMax); |
239 |
Entry("IdleLoopFF", Config.Hacks.IdleLoopFF); |
240 |
if (Conf.Hacks.VUCycleSteal < 0 || Conf.Hacks.VUCycleSteal > 4) |
241 |
Conf.Hacks.VUCycleSteal = 0; |
242 |
Entry("ESCExits", Config.Hacks.ESCExits); |
243 |
} |
244 |
|
245 |
////////////////////////////////////////////////////////////////////////////////////////// |
246 |
// Public API -- LoadConfig / SaveConfig |
247 |
|
248 |
bool LoadConfig() |
249 |
{ |
250 |
bool status = true; |
251 |
|
252 |
wxString szIniFile( GetConfigFilename() ); |
253 |
|
254 |
if( !Path::Exists( szIniFile ) ) |
255 |
{ |
256 |
if( hasCustomConfig() ) |
257 |
{ |
258 |
// using custom config, so fail outright: |
259 |
throw Exception::FileNotFound( |
260 |
"User-specified configuration file not found:\n\t%s\n\nPCSX2 will now exit." |
261 |
); |
262 |
} |
263 |
|
264 |
// standard mode operation. Create the directory. |
265 |
Path::CreateDirectory( "inis" ); |
266 |
status = false; // inform caller that we're not configured. |
267 |
} |
268 |
else |
269 |
{ |
270 |
// sanity check to make sure the user doesn't have some kind of |
271 |
// crazy ass setup... why not! |
272 |
|
273 |
if( Path::IsDirectory( szIniFile ) ) |
274 |
throw Exception::Stream( |
275 |
"Cannot open or create the Pcsx2 ini file because a directory of\n" |
276 |
"the same name already exists! Please delete it or reinstall Pcsx2\n" |
277 |
"fresh and try again." |
278 |
); |
279 |
|
280 |
// Ini Version check! ----> |
281 |
// If the user's ini is old, give them a friendly warning that says they should |
282 |
// probably delete it. |
283 |
|
284 |
char versionStr[20]; |
285 |
u32 version; |
286 |
|
287 |
GetPrivateProfileString( "Misc", "IniVersion", NULL, versionStr, 20, szIniFile.c_str() ); |
288 |
version = atoi( versionStr ); |
289 |
if( version < IniVersion ) |
290 |
{ |
291 |
// Warn the user of a version mismatch. |
292 |
Msgbox::Alert( |
293 |
"Configuration versions do not match. Pcsx2 may be unstable.\n" |
294 |
"If you experience problems, delete the pcsx2.ini file from the ini dir." |
295 |
); |
296 |
|
297 |
// save the new version -- gets rid of the warning on subsequent startups |
298 |
_itoa( IniVersion, versionStr, 10 ); |
299 |
WritePrivateProfileString( "Misc", "IniVersion", versionStr, szIniFile.c_str() ); |
300 |
} |
301 |
} |
302 |
|
303 |
IniFileLoader().DoConfig( Config ); |
304 |
|
305 |
return status; |
306 |
} |
307 |
|
308 |
void SaveConfig() |
309 |
{ |
310 |
PcsxConfig tmpConf = Config; |
311 |
|
312 |
strcpy( tmpConf.Plugins.GS, winConfig.Plugins.GS ); |
313 |
strcpy( tmpConf.Plugins.SPU2, winConfig.Plugins.SPU2 ); |
314 |
strcpy( tmpConf.Plugins.CDVD, winConfig.Plugins.CDVD ); |
315 |
strcpy( tmpConf.Plugins.PAD1, winConfig.Plugins.PAD1 ); |
316 |
strcpy( tmpConf.Plugins.PAD2, winConfig.Plugins.PAD2 ); |
317 |
strcpy( tmpConf.Plugins.DEV9, winConfig.Plugins.DEV9 ); |
318 |
strcpy( tmpConf.Plugins.USB, winConfig.Plugins.USB ); |
319 |
strcpy( tmpConf.Plugins.FW, winConfig.Plugins.FW ); |
320 |
|
321 |
IniFileSaver().DoConfig( tmpConf ); |
322 |
} |
323 |
|