mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge branch 'wolfreak99-num_of_conflicts' into develop
This commit is contained in:
commit
20b1ce069f
|
@ -15,6 +15,7 @@
|
|||
#pragma endregion
|
||||
|
||||
#include <string>
|
||||
#include "core/Console.hpp"
|
||||
#include "core/Guard.hpp"
|
||||
#include "core/String.hpp"
|
||||
#include "network/network.h"
|
||||
|
@ -82,7 +83,6 @@ namespace OpenRCT2
|
|||
/** If set, will end the OpenRCT2 game loop. Intentially private to this module so that the flag can not be set back to false. */
|
||||
static bool _finished;
|
||||
|
||||
static void SetupEnvironment();
|
||||
static void SetVersionInfoString();
|
||||
static bool ShouldRunVariableFrame();
|
||||
static void RunGameLoop();
|
||||
|
@ -114,47 +114,31 @@ extern "C"
|
|||
Guard::Assert(gHashCTX != nullptr, "EVP_MD_CTX_create failed");
|
||||
#endif // DISABLE_NETWORK
|
||||
|
||||
utf8 userPath[MAX_PATH];
|
||||
platform_resolve_openrct_data_path();
|
||||
platform_resolve_user_data_path();
|
||||
platform_get_user_directory(userPath, NULL, sizeof(userPath));
|
||||
if (!platform_ensure_directory_exists(userPath))
|
||||
crash_init();
|
||||
|
||||
// Sets up the environment OpenRCT2 is running in, e.g. directory paths
|
||||
OpenRCT2::_env = OpenRCT2::SetupEnvironment();
|
||||
if (OpenRCT2::_env == nullptr)
|
||||
{
|
||||
log_fatal("Could not create user directory (do you have write access to your documents folder?)");
|
||||
return false;
|
||||
}
|
||||
|
||||
crash_init();
|
||||
|
||||
if (!rct2_interop_setup_segment())
|
||||
{
|
||||
log_fatal("Unable to load RCT2 data sector");
|
||||
return false;
|
||||
}
|
||||
|
||||
openrct2_set_exe_path();
|
||||
|
||||
config_set_defaults();
|
||||
if (!config_open_default())
|
||||
{
|
||||
if (!config_find_or_browse_install_directory())
|
||||
{
|
||||
gConfigGeneral.last_run_version = String::Duplicate(OPENRCT2_VERSION);
|
||||
config_save_default();
|
||||
utf8 path[MAX_PATH];
|
||||
config_get_default_path(path, sizeof(path));
|
||||
log_fatal("An RCT2 install directory must be specified! Please edit \"game_path\" in %s.", path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
gOpenRCT2ShowChangelog = true;
|
||||
if (gConfigGeneral.last_run_version != NULL && (strcmp(gConfigGeneral.last_run_version, OPENRCT2_VERSION) == 0))
|
||||
if (gConfigGeneral.last_run_version != nullptr && String::Equals(gConfigGeneral.last_run_version, OPENRCT2_VERSION))
|
||||
{
|
||||
gOpenRCT2ShowChangelog = false;
|
||||
}
|
||||
gConfigGeneral.last_run_version = String::Duplicate(OPENRCT2_VERSION);
|
||||
config_save_default();
|
||||
else
|
||||
{
|
||||
gOpenRCT2ShowChangelog = true;
|
||||
gConfigGeneral.last_run_version = String::Duplicate(OPENRCT2_VERSION);
|
||||
config_save_default();
|
||||
}
|
||||
|
||||
// TODO add configuration option to allow multiple instances
|
||||
// if (!gOpenRCT2Headless && !platform_lock_single_instance()) {
|
||||
|
@ -162,17 +146,6 @@ extern "C"
|
|||
// return false;
|
||||
// }
|
||||
|
||||
if (!rct2_init_directories())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!rct2_startup_checks())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sets up the environment OpenRCT2 is running in, e.g. directory paths
|
||||
OpenRCT2::SetupEnvironment();
|
||||
IObjectRepository * objRepo = CreateObjectRepository(OpenRCT2::_env);
|
||||
ITrackDesignRepository * tdRepo = CreateTrackDesignRepository(OpenRCT2::_env);
|
||||
CreateScenarioRepository(OpenRCT2::_env);
|
||||
|
@ -328,8 +301,43 @@ extern "C"
|
|||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
static void SetupEnvironment()
|
||||
IPlatformEnvironment * SetupEnvironment()
|
||||
{
|
||||
utf8 userPath[MAX_PATH];
|
||||
platform_resolve_openrct_data_path();
|
||||
platform_resolve_user_data_path();
|
||||
platform_get_user_directory(userPath, NULL, sizeof(userPath));
|
||||
if (!platform_ensure_directory_exists(userPath))
|
||||
{
|
||||
Console::Error::WriteLine("Could not create user directory (do you have write access to your documents folder?)");
|
||||
return false;
|
||||
}
|
||||
openrct2_set_exe_path();
|
||||
|
||||
config_set_defaults();
|
||||
if (!config_open_default())
|
||||
{
|
||||
if (!config_find_or_browse_install_directory())
|
||||
{
|
||||
gConfigGeneral.last_run_version = String::Duplicate(OPENRCT2_VERSION);
|
||||
config_save_default();
|
||||
utf8 path[MAX_PATH];
|
||||
config_get_default_path(path, sizeof(path));
|
||||
Console::Error::WriteLine("An RCT2 install directory must be specified! Please edit \"game_path\" in %s.", path);
|
||||
return nullptr;
|
||||
}
|
||||
config_save_default();
|
||||
}
|
||||
|
||||
if (!rct2_init_directories())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!rct2_startup_checks())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
utf8 path[260];
|
||||
std::string basePaths[4];
|
||||
basePaths[(size_t)DIRBASE::RCT2] = std::string(gRCT2AddressAppPath);
|
||||
|
@ -337,7 +345,9 @@ namespace OpenRCT2
|
|||
basePaths[(size_t)DIRBASE::OPENRCT2] = std::string(path);
|
||||
platform_get_user_directory(path, nullptr, sizeof(path));
|
||||
basePaths[(size_t)DIRBASE::USER] = std::string(path);
|
||||
OpenRCT2::_env = CreatePlatformEnvironment(basePaths);
|
||||
|
||||
IPlatformEnvironment * env = CreatePlatformEnvironment(basePaths);
|
||||
return env;
|
||||
}
|
||||
|
||||
static void SetVersionInfoString()
|
||||
|
|
|
@ -40,6 +40,17 @@ enum STARTUP_ACTION
|
|||
STARTUP_ACTION_EDIT
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
interface IPlatformEnvironment;
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
IPlatformEnvironment * SetupEnvironment();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
extern "C"
|
||||
{
|
||||
#include "../config.h"
|
||||
#include "../OpenRCT2.h"
|
||||
#include "../platform/crash.h"
|
||||
}
|
||||
|
||||
|
@ -30,6 +29,8 @@ extern "C"
|
|||
#include "../core/Path.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../network/network.h"
|
||||
#include "../object/ObjectRepository.h"
|
||||
#include "../OpenRCT2.h"
|
||||
#include "CommandLine.hpp"
|
||||
|
||||
#ifdef USE_BREAKPAD
|
||||
|
@ -98,6 +99,7 @@ static exitcode_t HandleCommandIntro(CommandLineArgEnumerator * enumerator);
|
|||
static exitcode_t HandleCommandHost(CommandLineArgEnumerator * enumerator);
|
||||
static exitcode_t HandleCommandJoin(CommandLineArgEnumerator * enumerator);
|
||||
static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator * enumerator);
|
||||
static exitcode_t HandleCommandScanObjects(CommandLineArgEnumerator * enumerator);
|
||||
|
||||
#if defined(__WINDOWS__) && !defined(__MINGW32__)
|
||||
|
||||
|
@ -128,6 +130,7 @@ const CommandLineCommand CommandLine::RootCommands[]
|
|||
#endif
|
||||
DefineCommand("set-rct2", "<path>", StandardOptions, HandleCommandSetRCT2),
|
||||
DefineCommand("convert", "<source> <destination>", StandardOptions, CommandLine::HandleCommandConvert),
|
||||
DefineCommand("scan-objects", "<path>", StandardOptions, HandleCommandScanObjects),
|
||||
|
||||
#if defined(__WINDOWS__) && !defined(__MINGW32__)
|
||||
DefineCommand("register-shell", "", RegisterShellOptions, HandleCommandRegisterShell),
|
||||
|
@ -387,6 +390,20 @@ static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator * enumerator)
|
|||
}
|
||||
}
|
||||
|
||||
static exitcode_t HandleCommandScanObjects(CommandLineArgEnumerator * enumerator)
|
||||
{
|
||||
exitcode_t result = CommandLine::HandleCommandDefault();
|
||||
if (result != EXITCODE_CONTINUE)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
IPlatformEnvironment * env = OpenRCT2::SetupEnvironment();
|
||||
IObjectRepository * objectRepository = CreateObjectRepository(env);
|
||||
objectRepository->Construct();
|
||||
return EXITCODE_OK;
|
||||
}
|
||||
|
||||
#if defined(__WINDOWS__) && !defined(__MINGW32__)
|
||||
static exitcode_t HandleCommandRegisterShell(CommandLineArgEnumerator * enumerator)
|
||||
{
|
||||
|
|
|
@ -936,6 +936,9 @@ bool config_find_or_browse_install_directory()
|
|||
gConfigGeneral.game_path = malloc(strlen(path) + 1);
|
||||
safe_strcpy(gConfigGeneral.game_path, path, MAX_PATH);
|
||||
} else {
|
||||
if (gOpenRCT2Headless) {
|
||||
return false;
|
||||
}
|
||||
while (1) {
|
||||
platform_show_messagebox("OpenRCT2 needs files from the original RollerCoaster Tycoon 2 in order to work. Please select the directory where you installed RollerCoaster Tycoon 2.");
|
||||
installPath = platform_open_directory_browser("Please select your RCT2 directory");
|
||||
|
|
|
@ -99,6 +99,7 @@ class ObjectRepository : public IObjectRepository
|
|||
QueryDirectoryResult _queryDirectoryResult = { 0 };
|
||||
ObjectEntryMap _itemMap;
|
||||
uint16 _languageId = 0;
|
||||
int _numConflicts;
|
||||
|
||||
public:
|
||||
ObjectRepository(IPlatformEnvironment * env)
|
||||
|
@ -115,24 +116,25 @@ public:
|
|||
{
|
||||
ClearItems();
|
||||
|
||||
_queryDirectoryResult = { 0 };
|
||||
|
||||
const std::string &rct2Path = _env->GetDirectoryPath(DIRBASE::RCT2, DIRID::OBJECT);
|
||||
const std::string &openrct2Path = _env->GetDirectoryPath(DIRBASE::USER, DIRID::OBJECT);
|
||||
QueryDirectory(&_queryDirectoryResult, rct2Path);
|
||||
QueryDirectory(&_queryDirectoryResult, openrct2Path);
|
||||
|
||||
Query();
|
||||
if (!Load())
|
||||
{
|
||||
_languageId = gCurrentLanguage;
|
||||
|
||||
Construct();
|
||||
Scan();
|
||||
Save();
|
||||
}
|
||||
|
||||
// SortItems();
|
||||
}
|
||||
|
||||
void Construct() override
|
||||
{
|
||||
_languageId = gCurrentLanguage;
|
||||
Query();
|
||||
Scan();
|
||||
Save();
|
||||
}
|
||||
|
||||
size_t GetNumObjects() const override
|
||||
{
|
||||
return _items.size();
|
||||
|
@ -233,6 +235,16 @@ private:
|
|||
_itemMap.clear();
|
||||
}
|
||||
|
||||
void Query()
|
||||
{
|
||||
_queryDirectoryResult = { 0 };
|
||||
|
||||
const std::string &rct2Path = _env->GetDirectoryPath(DIRBASE::RCT2, DIRID::OBJECT);
|
||||
const std::string &openrct2Path = _env->GetDirectoryPath(DIRBASE::USER, DIRID::OBJECT);
|
||||
QueryDirectory(&_queryDirectoryResult, rct2Path);
|
||||
QueryDirectory(&_queryDirectoryResult, openrct2Path);
|
||||
}
|
||||
|
||||
void QueryDirectory(QueryDirectoryResult * result, const std::string &directory)
|
||||
{
|
||||
utf8 pattern[MAX_PATH];
|
||||
|
@ -241,12 +253,10 @@ private:
|
|||
Path::QueryDirectory(result, pattern);
|
||||
}
|
||||
|
||||
void Construct()
|
||||
void Scan()
|
||||
{
|
||||
utf8 objectDirectory[MAX_PATH];
|
||||
Path::GetDirectory(objectDirectory, sizeof(objectDirectory), gRCT2AddressObjectDataPath);
|
||||
|
||||
Console::WriteLine("Scanning %lu objects...", _queryDirectoryResult.TotalFiles);
|
||||
_numConflicts = 0;
|
||||
|
||||
auto stopwatch = Stopwatch();
|
||||
stopwatch.Start();
|
||||
|
@ -258,6 +268,10 @@ private:
|
|||
|
||||
stopwatch.Stop();
|
||||
Console::WriteLine("Scanning complete in %.2f seconds.", stopwatch.GetElapsedMilliseconds() / 1000.0f);
|
||||
if (_numConflicts > 0)
|
||||
{
|
||||
Console::WriteLine("%d object conflicts found.", _numConflicts);
|
||||
}
|
||||
}
|
||||
|
||||
void ScanDirectory(const std::string &directory)
|
||||
|
@ -390,6 +404,7 @@ private:
|
|||
}
|
||||
else
|
||||
{
|
||||
_numConflicts++;
|
||||
Console::Error::WriteLine("Object conflict: '%s'", conflict->Path);
|
||||
Console::Error::WriteLine(" : '%s'", item->Path);
|
||||
return false;
|
||||
|
|
|
@ -64,6 +64,7 @@ interface IObjectRepository
|
|||
virtual ~IObjectRepository() { }
|
||||
|
||||
virtual void LoadOrConstruct() abstract;
|
||||
virtual void Construct() abstract;
|
||||
virtual size_t GetNumObjects() const abstract;
|
||||
virtual const ObjectRepositoryItem * GetObjects() const abstract;
|
||||
virtual const ObjectRepositoryItem * FindObject(const utf8 * name) const abstract;
|
||||
|
|
Loading…
Reference in New Issue