1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 13:33:02 +01:00

Merge pull request #7163 from IntelOrca/fix/cold-startup

Fix cold startup
This commit is contained in:
Ted John
2018-02-11 22:50:19 +00:00
committed by GitHub
3 changed files with 39 additions and 33 deletions

View File

@@ -572,6 +572,9 @@ namespace Config
{
try
{
auto directory = Path::GetDirectory(path);
Path::CreateDirectory(directory);
auto fs = FileStream(path, FILE_MODE_WRITE);
auto writer = std::unique_ptr<IIniWriter>(CreateIniWriter(&fs));
WriteGeneral(writer.get());

View File

@@ -196,7 +196,6 @@ private:
items.push_back(std::get<1>(item));
}
}
Console::WriteLine();
WriteIndexFile(scanResult.Stats, items);
@@ -210,41 +209,44 @@ private:
{
bool loadedItems = false;
std::vector<TItem> items;
try
if (File::Exists(_indexPath))
{
log_verbose("FileIndex:Loading index: '%s'", _indexPath.c_str());
auto fs = FileStream(_indexPath, FILE_MODE_OPEN);
try
{
log_verbose("FileIndex:Loading index: '%s'", _indexPath.c_str());
auto fs = FileStream(_indexPath, FILE_MODE_OPEN);
// Read header, check if we need to re-scan
auto header = fs.ReadValue<FileIndexHeader>();
if (header.HeaderSize == sizeof(FileIndexHeader) &&
header.MagicNumber == _magicNumber &&
header.VersionA == FILE_INDEX_VERSION &&
header.VersionB == _version &&
header.LanguageId == gCurrentLanguage &&
header.Stats.TotalFiles == stats.TotalFiles &&
header.Stats.TotalFileSize == stats.TotalFileSize &&
header.Stats.FileDateModifiedChecksum == stats.FileDateModifiedChecksum &&
header.Stats.PathChecksum == stats.PathChecksum)
{
// Directory is the same, just read the saved items
for (uint32 i = 0; i < header.NumItems; i++)
// Read header, check if we need to re-scan
auto header = fs.ReadValue<FileIndexHeader>();
if (header.HeaderSize == sizeof(FileIndexHeader) &&
header.MagicNumber == _magicNumber &&
header.VersionA == FILE_INDEX_VERSION &&
header.VersionB == _version &&
header.LanguageId == gCurrentLanguage &&
header.Stats.TotalFiles == stats.TotalFiles &&
header.Stats.TotalFileSize == stats.TotalFileSize &&
header.Stats.FileDateModifiedChecksum == stats.FileDateModifiedChecksum &&
header.Stats.PathChecksum == stats.PathChecksum)
{
auto item = Deserialise(&fs);
items.push_back(item);
// Directory is the same, just read the saved items
for (uint32 i = 0; i < header.NumItems; i++)
{
auto item = Deserialise(&fs);
items.push_back(item);
}
loadedItems = true;
}
else
{
Console::WriteLine("%s out of date", _name.c_str());
}
loadedItems = true;
}
else
catch (const std::exception &e)
{
Console::WriteLine("%s out of date", _name.c_str());
Console::Error::WriteLine("Unable to load index: '%s'.", _indexPath.c_str());
Console::Error::WriteLine("%s", e.what());
}
}
catch (const std::exception &e)
{
Console::Error::WriteLine("Unable to load index: '%s'.", _indexPath.c_str());
Console::Error::WriteLine("%s", e.what());
}
return std::make_tuple(loadedItems, items);
}

View File

@@ -818,6 +818,11 @@ void window_close_top()
*/
void window_close_all()
{
if (gWindowNextSlot == nullptr)
{
return;
}
window_close_by_class(WC_DROPDOWN);
for (rct_window * w = RCT2_LAST_WINDOW; w >= g_window_list; w--)
@@ -2667,11 +2672,7 @@ void window_reset_visibilities()
void window_init_all()
{
if (gWindowNextSlot != nullptr)
{
window_close_all();
}
window_close_all();
gWindowNextSlot = g_window_list;
}