mirror of https://github.com/OpenRCT2/OpenRCT2.git
Add File::GetSize to get object size in a simpler way
Drastically reduces startup speed because of the optimization applied to ObjectAsset::GetSize - now the file size is obtained without reading the entire file into memory.
This commit is contained in:
parent
dc11021192
commit
95388cfbb1
|
@ -20,6 +20,7 @@
|
||||||
- Fix: [#14587] Confusing message when joining server with mismatched network version.
|
- Fix: [#14587] Confusing message when joining server with mismatched network version.
|
||||||
- Fix: [#14604] American-style Steam Trains are not imported correctly from RCT1 saves.
|
- Fix: [#14604] American-style Steam Trains are not imported correctly from RCT1 saves.
|
||||||
- Fix: [#14638] The “About OpenRCT2” window cannot be themed.
|
- Fix: [#14638] The “About OpenRCT2” window cannot be themed.
|
||||||
|
- Improved: [#14712]: Improve startup times.
|
||||||
|
|
||||||
0.3.3 (2021-03-13)
|
0.3.3 (2021-03-13)
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||||
*
|
*
|
||||||
* For a complete list of all authors, please refer to contributors.md
|
* For a complete list of all authors, please refer to contributors.md
|
||||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
@ -123,6 +123,11 @@ namespace File
|
||||||
{
|
{
|
||||||
return Platform::GetLastModified(path);
|
return Platform::GetLastModified(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t GetSize(std::string_view path)
|
||||||
|
{
|
||||||
|
return Platform::GetFileSize(path);
|
||||||
|
}
|
||||||
} // namespace File
|
} // namespace File
|
||||||
|
|
||||||
bool writeentirefile(const utf8* path, const void* buffer, size_t length)
|
bool writeentirefile(const utf8* path, const void* buffer, size_t length)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||||
*
|
*
|
||||||
* For a complete list of all authors, please refer to contributors.md
|
* For a complete list of all authors, please refer to contributors.md
|
||||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
@ -26,4 +26,5 @@ namespace File
|
||||||
std::vector<std::string> ReadAllLines(std::string_view path);
|
std::vector<std::string> ReadAllLines(std::string_view path);
|
||||||
void WriteAllBytes(const std::string& path, const void* buffer, size_t length);
|
void WriteAllBytes(const std::string& path, const void* buffer, size_t length);
|
||||||
uint64_t GetLastModified(const std::string& path);
|
uint64_t GetLastModified(const std::string& path);
|
||||||
|
uint64_t GetSize(std::string_view path);
|
||||||
} // namespace File
|
} // namespace File
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||||
*
|
*
|
||||||
* For a complete list of all authors, please refer to contributors.md
|
* For a complete list of all authors, please refer to contributors.md
|
||||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
@ -252,18 +252,11 @@ bool ObjectAsset::IsAvailable() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ObjectAsset::GetSize() const
|
uint64_t ObjectAsset::GetSize() const
|
||||||
{
|
{
|
||||||
if (_zipPath.empty())
|
if (_zipPath.empty())
|
||||||
{
|
{
|
||||||
try
|
return File::GetSize(_path);
|
||||||
{
|
|
||||||
return File::ReadAllBytes(_path).size();
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||||
*
|
*
|
||||||
* For a complete list of all authors, please refer to contributors.md
|
* For a complete list of all authors, please refer to contributors.md
|
||||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
@ -223,7 +223,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsAvailable() const;
|
bool IsAvailable() const;
|
||||||
size_t GetSize() const;
|
uint64_t GetSize() const;
|
||||||
std::unique_ptr<OpenRCT2::IStream> GetStream() const;
|
std::unique_ptr<OpenRCT2::IStream> GetStream() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||||
*
|
*
|
||||||
* For a complete list of all authors, please refer to contributors.md
|
* For a complete list of all authors, please refer to contributors.md
|
||||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
@ -177,6 +177,19 @@ namespace Platform
|
||||||
return lastModified;
|
return lastModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t GetFileSize(std::string_view path)
|
||||||
|
{
|
||||||
|
uint64_t size = 0;
|
||||||
|
struct stat statInfo
|
||||||
|
{
|
||||||
|
};
|
||||||
|
if (stat(std::string(path).c_str(), &statInfo) == 0)
|
||||||
|
{
|
||||||
|
size = statInfo.st_size;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
bool ShouldIgnoreCase()
|
bool ShouldIgnoreCase()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||||
*
|
*
|
||||||
* For a complete list of all authors, please refer to contributors.md
|
* For a complete list of all authors, please refer to contributors.md
|
||||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
@ -554,6 +554,21 @@ namespace Platform
|
||||||
return lastModified;
|
return lastModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t GetFileSize(std::string_view path)
|
||||||
|
{
|
||||||
|
uint64_t size = 0;
|
||||||
|
auto pathW = String::ToWideChar(path);
|
||||||
|
WIN32_FILE_ATTRIBUTE_DATA attributes;
|
||||||
|
if (GetFileAttributesExW(pathW.c_str(), GetFileExInfoStandard, &attributes) != FALSE)
|
||||||
|
{
|
||||||
|
ULARGE_INTEGER fileSize;
|
||||||
|
fileSize.LowPart = attributes.nFileSizeLow;
|
||||||
|
fileSize.HighPart = attributes.nFileSizeHigh;
|
||||||
|
size = fileSize.QuadPart;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
bool ShouldIgnoreCase()
|
bool ShouldIgnoreCase()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||||
*
|
*
|
||||||
* For a complete list of all authors, please refer to contributors.md
|
* For a complete list of all authors, please refer to contributors.md
|
||||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
@ -39,6 +39,7 @@ namespace Platform
|
||||||
bool IsPathSeparator(char c);
|
bool IsPathSeparator(char c);
|
||||||
utf8* GetAbsolutePath(utf8* buffer, size_t bufferSize, const utf8* relativePath);
|
utf8* GetAbsolutePath(utf8* buffer, size_t bufferSize, const utf8* relativePath);
|
||||||
uint64_t GetLastModified(const std::string& path);
|
uint64_t GetLastModified(const std::string& path);
|
||||||
|
uint64_t GetFileSize(std::string_view path);
|
||||||
std::string ResolveCasing(const std::string& path, bool fileExists);
|
std::string ResolveCasing(const std::string& path, bool fileExists);
|
||||||
rct2_time GetTimeLocal();
|
rct2_time GetTimeLocal();
|
||||||
rct2_date GetDateLocal();
|
rct2_date GetDateLocal();
|
||||||
|
|
Loading…
Reference in New Issue