Skip to content

Commit 19a37eb

Browse files
authored
Merge pull request #1024 from asarium/feature/defaultConfigLoc
Improve logic for determining legacy mode
2 parents 5922824 + 5725562 commit 19a37eb

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

code/osapi/osapi.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
#include "cmdline/cmdline.h"
2020
#include "osapi/osapi.h"
2121

22-
23-
#include <SDL_assert.h>
24-
22+
#include <fstream>
2523
#include <algorithm>
2624

2725
namespace
@@ -304,6 +302,11 @@ void os_sleep(uint ms)
304302
#endif
305303
}
306304

305+
static bool file_exists(const SCP_string& path) {
306+
std::ofstream str(path, std::ios::in);
307+
return str.good();
308+
}
309+
307310
bool os_is_legacy_mode()
308311
{
309312
// Make this check a little faster by caching the result
@@ -318,19 +321,31 @@ bool os_is_legacy_mode()
318321
checkedLegacyMode = true;
319322
}
320323
else {
324+
bool old_config_exists = false;
325+
bool new_config_exists = false;
326+
321327
SCP_stringstream path_stream;
322328
path_stream << getPreferencesPath() << DIR_SEPARATOR_CHAR << Osreg_config_file_name;
323329

324-
// Use the existance of the fs2_open.ini file for determining if the launcher supports the new mode
325-
auto file = fopen(path_stream.str().c_str(), "r");
330+
new_config_exists = file_exists(path_stream.str());
331+
#ifdef SCP_UNIX
332+
path_stream.str("");
333+
path_stream << Cfile_user_dir_legacy << DIR_SEPARATOR_CHAR << Osreg_config_file_name;
326334

327-
if (file == nullptr)
328-
{
335+
old_config_exists = file_exists(path_stream.str());
336+
#else
337+
// At this point we can't determine if the old config exists so just assume that it does
338+
old_config_exists = true;
339+
#endif
340+
341+
if (new_config_exists) {
342+
// If the new config exists then we never use the lagacy mode
343+
legacyMode = false;
344+
} else if (old_config_exists) {
345+
// Old config exists but new doesn't -> use legacy mode
329346
legacyMode = true;
330-
}
331-
else
332-
{
333-
fclose(file);
347+
} else {
348+
// Neither old nor new config exists -> this is a new install
334349
legacyMode = false;
335350
}
336351
}

0 commit comments

Comments
 (0)