mirror of https://github.com/OpenRCT2/OpenRCT2.git
Fix #13445: Make FileScanner::ScanDirectory return a unique_ptr
Also fixes a resource leak in TitleSequence::GetSaves.
This commit is contained in:
parent
efd5d7dfe7
commit
94da3cf422
|
@ -92,6 +92,7 @@ The following people are not part of the development team, but have been contrib
|
|||
* Helio Batimarqui (batimarqui) - Misc.
|
||||
* Keith Stellyes (keithstellyes) - Misc.
|
||||
* Bas Cantrijn (Basssiiie) - Misc.
|
||||
* Adrian Zdanowicz (CookiePLMonster) - Misc.
|
||||
|
||||
## Bug fixes
|
||||
* (halfbro)
|
||||
|
|
|
@ -536,7 +536,7 @@ namespace ThemeManager
|
|||
}
|
||||
|
||||
auto themesPattern = Path::Combine(GetThemePath(), "*.json");
|
||||
auto scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(themesPattern, true));
|
||||
auto scanner = Path::ScanDirectory(themesPattern, true);
|
||||
while (scanner->Next())
|
||||
{
|
||||
auto fileInfo = scanner->GetFileInfo();
|
||||
|
|
|
@ -913,7 +913,7 @@ static void window_loadsave_populate_list(rct_window* w, int32_t includeNewItem,
|
|||
safe_strcat_path(filter, "*", std::size(filter));
|
||||
path_append_extension(filter, extToken, std::size(filter));
|
||||
|
||||
auto scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(filter, false));
|
||||
auto scanner = Path::ScanDirectory(filter, false);
|
||||
while (scanner->Next())
|
||||
{
|
||||
LoadSaveListItem newListItem;
|
||||
|
|
|
@ -1189,7 +1189,6 @@ namespace OpenRCT2
|
|||
}
|
||||
}
|
||||
}
|
||||
delete scanner;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_HTTP
|
||||
|
|
|
@ -678,7 +678,7 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL
|
|||
|
||||
// At first, count how many autosaves there are
|
||||
{
|
||||
auto scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(filter, false));
|
||||
auto scanner = Path::ScanDirectory(filter, false);
|
||||
while (scanner->Next())
|
||||
{
|
||||
autosavesCount++;
|
||||
|
@ -693,7 +693,7 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL
|
|||
|
||||
auto autosaveFiles = std::vector<std::string>(autosavesCount);
|
||||
{
|
||||
auto scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(filter, false));
|
||||
auto scanner = Path::ScanDirectory(filter, false);
|
||||
for (size_t i = 0; i < autosavesCount; i++)
|
||||
{
|
||||
autosaveFiles[i].resize(MAX_PATH, 0);
|
||||
|
|
|
@ -161,7 +161,6 @@ private:
|
|||
|
||||
files.push_back(std::move(path));
|
||||
}
|
||||
delete scanner;
|
||||
}
|
||||
return ScanResult(stats, files);
|
||||
}
|
||||
|
|
|
@ -342,18 +342,18 @@ private:
|
|||
|
||||
#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
|
||||
IFileScanner* Path::ScanDirectory(const std::string& pattern, bool recurse)
|
||||
std::unique_ptr<IFileScanner> Path::ScanDirectory(const std::string& pattern, bool recurse)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return new FileScannerWindows(pattern, recurse);
|
||||
return std::make_unique<FileScannerWindows>(pattern, recurse);
|
||||
#elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
return new FileScannerUnix(pattern, recurse);
|
||||
return std::make_unique<FileScannerUnix>(pattern, recurse);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Path::QueryDirectory(QueryDirectoryResult* result, const std::string& pattern)
|
||||
{
|
||||
IFileScanner* scanner = Path::ScanDirectory(pattern, true);
|
||||
auto scanner = Path::ScanDirectory(pattern, true);
|
||||
while (scanner->Next())
|
||||
{
|
||||
const FileInfo* fileInfo = scanner->GetFileInfo();
|
||||
|
@ -366,12 +366,11 @@ void Path::QueryDirectory(QueryDirectoryResult* result, const std::string& patte
|
|||
result->FileDateModifiedChecksum = ror32(result->FileDateModifiedChecksum, 5);
|
||||
result->PathChecksum += GetPathChecksum(path);
|
||||
}
|
||||
delete scanner;
|
||||
}
|
||||
|
||||
std::vector<std::string> Path::GetDirectories(const std::string& path)
|
||||
{
|
||||
auto scanner = std::unique_ptr<IFileScanner>(ScanDirectory(path, false));
|
||||
auto scanner = ScanDirectory(path, false);
|
||||
auto baseScanner = static_cast<FileScannerBase*>(scanner.get());
|
||||
|
||||
std::vector<DirectoryChild> children;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "../common.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -50,7 +51,7 @@ namespace Path
|
|||
* @param recurse Whether to scan sub directories or not.
|
||||
* @returns A new FileScanner, this must be deleted when no longer needed.
|
||||
*/
|
||||
IFileScanner* ScanDirectory(const std::string& pattern, bool recurse);
|
||||
std::unique_ptr<IFileScanner> ScanDirectory(const std::string& pattern, bool recurse);
|
||||
|
||||
/**
|
||||
* Scans a directory and all sub directories
|
||||
|
|
|
@ -274,7 +274,7 @@ std::string ImageTable::FindLegacyObject(const std::string& name)
|
|||
{
|
||||
// Search recursively for any file with the target name (case insensitive)
|
||||
auto filter = Path::Combine(objectsPath, "*.dat");
|
||||
auto scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(filter, true));
|
||||
auto scanner = Path::ScanDirectory(filter, true);
|
||||
while (scanner->Next())
|
||||
{
|
||||
auto currentName = Path::GetFileName(scanner->GetPathRelative());
|
||||
|
|
|
@ -443,7 +443,7 @@ void ScriptEngine::LoadPlugins()
|
|||
if (Path::DirectoryExists(base))
|
||||
{
|
||||
auto pattern = Path::Combine(base, "*.js");
|
||||
auto scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(pattern, true));
|
||||
auto scanner = Path::ScanDirectory(pattern, true);
|
||||
while (scanner->Next())
|
||||
{
|
||||
auto path = std::string(scanner->GetPath());
|
||||
|
|
|
@ -292,7 +292,7 @@ static std::vector<std::string> GetSaves(const std::string& directory)
|
|||
std::vector<std::string> saves;
|
||||
|
||||
auto pattern = Path::Combine(directory, "*.sc6;*.sv6");
|
||||
IFileScanner* scanner = Path::ScanDirectory(pattern, true);
|
||||
auto scanner = Path::ScanDirectory(pattern, true);
|
||||
while (scanner->Next())
|
||||
{
|
||||
const utf8* path = scanner->GetPathRelative();
|
||||
|
|
|
@ -209,12 +209,11 @@ namespace TitleSequenceManager
|
|||
static void Scan(const std::string& directory)
|
||||
{
|
||||
auto pattern = Path::Combine(directory, "script.txt;*.parkseq");
|
||||
IFileScanner* fileScanner = Path::ScanDirectory(pattern, true);
|
||||
auto fileScanner = Path::ScanDirectory(pattern, true);
|
||||
while (fileScanner->Next())
|
||||
{
|
||||
AddSequence(fileScanner->GetPath());
|
||||
}
|
||||
delete fileScanner;
|
||||
}
|
||||
|
||||
static void AddSequence(const std::string& scanPath)
|
||||
|
|
|
@ -53,7 +53,7 @@ static std::vector<ReplayTestData> GetReplayFiles()
|
|||
std::string replayPathPattern = Path::Combine(replayPath, "*.sv6r");
|
||||
std::vector<std::string> files;
|
||||
|
||||
std::unique_ptr<IFileScanner> scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(replayPathPattern, true));
|
||||
auto scanner = Path::ScanDirectory(replayPathPattern, true);
|
||||
while (scanner->Next())
|
||||
{
|
||||
ReplayTestData test;
|
||||
|
|
Loading…
Reference in New Issue