diff --git a/src/OpenRCT2.cpp b/src/OpenRCT2.cpp index 0f693a05c0..f870399a0b 100644 --- a/src/OpenRCT2.cpp +++ b/src/OpenRCT2.cpp @@ -190,7 +190,7 @@ extern "C" // TODO Ideally we want to delay this until we show the title so that we can // still open the game window and draw a progress screen for the creation // of the object cache. - objRepo->LoadOrConstruct(); + objRepo->LoadOrConstruct(false); // TODO Like objects, this can take a while if there are a lot of track designs // its also really something really we might want to do in the background diff --git a/src/cmdline/RootCommands.cpp b/src/cmdline/RootCommands.cpp index 2586279392..6990b75134 100644 --- a/src/cmdline/RootCommands.cpp +++ b/src/cmdline/RootCommands.cpp @@ -30,6 +30,7 @@ extern "C" #include "../core/Path.hpp" #include "../core/String.hpp" #include "../network/network.h" +#include "../object/ObjectRepository.h" #include "CommandLine.hpp" #ifdef USE_BREAKPAD @@ -66,6 +67,7 @@ static utf8 * _userDataPath = nullptr; static utf8 * _openrctDataPath = nullptr; static utf8 * _rct2DataPath = nullptr; static bool _silentBreakpad = false; +static bool _forceScan = false; static const CommandLineOptionDefinition StandardOptions[] { @@ -89,6 +91,7 @@ static const CommandLineOptionDefinition StandardOptions[] #ifdef USE_BREAKPAD { CMDLINE_TYPE_SWITCH, &_silentBreakpad, NAC, "silent-breakpad", "make breakpad crash reporting silent" }, #endif // USE_BREAKPAD + { CMDLINE_TYPE_SWITCH, &_forceScan, 'f', "force-scan", "forces scanning of object repository" }, OptionTableEnd }; @@ -194,6 +197,14 @@ exitcode_t CommandLine::HandleCommandDefault() gOpenRCT2Headless = _headless; gOpenRCT2SilentBreakpad = _silentBreakpad || _headless; + if (_forceScan) + { + IObjectRepository * objectRepository = GetObjectRepository(); + objectRepository->LoadOrConstruct(true); + + result = EXITCODE_OK; + } + if (_userDataPath != nullptr) { String::Set(gCustomUserDataPath, sizeof(gCustomUserDataPath), _userDataPath); diff --git a/src/object/ObjectRepository.cpp b/src/object/ObjectRepository.cpp index f81b30a51d..ca83285645 100644 --- a/src/object/ObjectRepository.cpp +++ b/src/object/ObjectRepository.cpp @@ -99,6 +99,7 @@ class ObjectRepository : public IObjectRepository QueryDirectoryResult _queryDirectoryResult = { 0 }; ObjectEntryMap _itemMap; uint16 _languageId = 0; + int _numConflicts; public: ObjectRepository(IPlatformEnvironment * env) @@ -111,7 +112,7 @@ public: ClearItems(); } - void LoadOrConstruct() override + void LoadOrConstruct(bool forceScan) override { ClearItems(); @@ -122,8 +123,12 @@ public: QueryDirectory(&_queryDirectoryResult, rct2Path); QueryDirectory(&_queryDirectoryResult, openrct2Path); - if (!Load()) + if (forceScan || !Load()) { + if (forceScan) + { + Console::WriteLine("Forcing object repository scan."); + } _languageId = gCurrentLanguage; Construct(); @@ -247,6 +252,7 @@ private: Path::GetDirectory(objectDirectory, sizeof(objectDirectory), gRCT2AddressObjectDataPath); Console::WriteLine("Scanning %lu objects...", _queryDirectoryResult.TotalFiles); + _numConflicts = 0; auto stopwatch = Stopwatch(); stopwatch.Start(); @@ -258,6 +264,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 +400,7 @@ private: } else { + _numConflicts++; Console::Error::WriteLine("Object conflict: '%s'", conflict->Path); Console::Error::WriteLine(" : '%s'", item->Path); return false; @@ -659,7 +670,7 @@ extern "C" void object_list_load() { IObjectRepository * objectRepository = GetObjectRepository(); - objectRepository->LoadOrConstruct(); + objectRepository->LoadOrConstruct(false); IObjectManager * objectManager = GetObjectManager(); objectManager->UnloadAll(); diff --git a/src/object/ObjectRepository.h b/src/object/ObjectRepository.h index 11ef872873..e696c7c783 100644 --- a/src/object/ObjectRepository.h +++ b/src/object/ObjectRepository.h @@ -63,7 +63,7 @@ interface IObjectRepository { virtual ~IObjectRepository() { } - virtual void LoadOrConstruct() abstract; + virtual void LoadOrConstruct(bool forceScan) abstract; virtual size_t GetNumObjects() const abstract; virtual const ObjectRepositoryItem * GetObjects() const abstract; virtual const ObjectRepositoryItem * FindObject(const utf8 * name) const abstract;