/** * Loads the original scores.dat file and replaces any highscores that * are better for matching scenarios. */ void LoadLegacyScores() { std::string rct2Path = _env->GetFilePath(PATHID::SCORES_RCT2); std::string legacyPath = _env->GetFilePath(PATHID::SCORES_LEGACY); LoadLegacyScores(legacyPath); LoadLegacyScores(rct2Path); }
explicit ObjectFileIndex(IObjectRepository& objectRepository, const IPlatformEnvironment& env) : FileIndex( "object index", MAGIC_NUMBER, VERSION, env.GetFilePath(PATHID::CACHE_OBJECTS), std::string(PATTERN), std::vector<std::string>{ env.GetDirectoryPath(DIRBASE::OPENRCT2, DIRID::OBJECT), env.GetDirectoryPath(DIRBASE::USER, DIRID::OBJECT), }) , _objectRepository(objectRepository) { }
explicit TrackDesignFileIndex(const IPlatformEnvironment &env) : FileIndex("track design index", MAGIC_NUMBER, VERSION, env.GetFilePath(PATHID::CACHE_TRACKS), std::string(PATTERN), std::vector<std::string>({ env.GetDirectoryPath(DIRBASE::RCT1, DIRID::TRACK), env.GetDirectoryPath(DIRBASE::RCT2, DIRID::TRACK), env.GetDirectoryPath(DIRBASE::USER, DIRID::TRACK) })) { }
void Scan() override { _scenarios.clear(); // Scan RCT2 directory std::string rct2dir = _env->GetDirectoryPath(DIRBASE::RCT2, DIRID::SCENARIO); std::string openrct2dir = _env->GetDirectoryPath(DIRBASE::USER, DIRID::SCENARIO); Scan(rct2dir); Scan(openrct2dir); Sort(); LoadScores(); LoadLegacyScores(); AttachHighscores(); }
void LoadScores() { std::string path = _env->GetFilePath(PATHID::SCORES); if (!platform_file_exists(path.c_str())) { return; } try { auto fs = FileStream(path, FILE_MODE_OPEN); uint32 fileVersion = fs.ReadValue<uint32>(); if (fileVersion != 1) { Console::Error::WriteLine("Invalid or incompatible highscores file."); return; } ClearHighscores(); uint32 numHighscores = fs.ReadValue<uint32>(); for (uint32 i = 0; i < numHighscores; i++) { scenario_highscore_entry * highscore = InsertHighscore(); highscore->fileName = fs.ReadString(); highscore->name = fs.ReadString(); highscore->company_value = fs.ReadValue<money32>(); highscore->timestamp = fs.ReadValue<datetime64>(); } } catch (Exception ex) { Console::Error::WriteLine("Error reading highscores."); } }
void SaveHighscores() { std::string path = _env->GetFilePath(PATHID::SCORES); try { auto fs = FileStream(path, FILE_MODE_WRITE); fs.WriteValue<uint32>(HighscoreFileVersion); fs.WriteValue<uint32>((uint32)_highscores.size()); for (size_t i = 0; i < _highscores.size(); i++) { const scenario_highscore_entry * highscore = _highscores[i]; fs.WriteString(highscore->fileName); fs.WriteString(highscore->name); fs.WriteValue(highscore->company_value); fs.WriteValue(highscore->timestamp); } } catch (Exception ex) { Console::Error::WriteLine("Unable to save highscores to '%s'", path.c_str()); } }