void LoadLegacyScores(const std::string &path) { if (!platform_file_exists(path.c_str())) { return; } bool highscoresDirty = false; try { auto fs = FileStream(path, FILE_MODE_OPEN); if (fs.GetLength() <= 4) { // Initial value of scores for RCT2, just ignore return; } // Load header auto header = fs.ReadValue<rct_scenario_scores_header>(); for (uint32 i = 0; i < header.scenario_count; i++) { // Read legacy entry auto scBasic = fs.ReadValue<rct_scenario_basic>(); // Ignore non-completed scenarios if (scBasic.flags & SCENARIO_FLAGS_COMPLETED) { bool notFound = true; for (size_t i = 0; i < _highscores.size(); i++) { scenario_highscore_entry * highscore = _highscores[i]; if (String::Equals(scBasic.path, highscore->fileName, true)) { notFound = false; // Check if legacy highscore is better if (scBasic.company_value > highscore->company_value) { SafeFree(highscore->name); highscore->name = win1252_to_utf8_alloc(scBasic.completed_by, Util::CountOf(scBasic.completed_by)); highscore->company_value = scBasic.company_value; highscore->timestamp = DATETIME64_MIN; break; } } } if (notFound) { scenario_highscore_entry * highscore = InsertHighscore(); highscore->fileName = String::Duplicate(scBasic.path); highscore->name = win1252_to_utf8_alloc(scBasic.completed_by, Util::CountOf(scBasic.completed_by)); highscore->company_value = scBasic.company_value; highscore->timestamp = DATETIME64_MIN; } } } } catch (Exception ex) { Console::Error::WriteLine("Error reading legacy scenario scores file: '%s'", path.c_str()); } if (highscoresDirty) { SaveHighscores(); } }
~_MappableBuffer() { /* Free the additional page we allocated. See _MappableBuffer::Create */ ::munmap(*this + ((GetLength() + PAGE_SIZE - 1) & PAGE_MASK), PAGE_SIZE); }
UINT CSafeFile::Read(void* lpBuf, UINT nCount) { if (GetPosition() + nCount > GetLength()) AfxThrowFileException(CFileException::endOfFile, 0, GetFileName()); return CFile::Read(lpBuf, nCount); }
void CFX_WideString::Reserve(FX_STRSIZE len) { GetBuffer(len); ReleaseBuffer(GetLength()); }
CStdString CStdString::Left(int iLength) const { if( iLength < 0 ) iLength = 0; if( iLength > GetLength() ) iLength = GetLength(); return CStdString(m_pstr, iLength); }
void CStdString::SetAt(int nIndex, TCHAR ch) { ASSERT(nIndex>=0 && nIndex<GetLength()); m_pstr[nIndex] = ch; }