diff --git a/contributors.md b/contributors.md index 0a04899ff0..0a8a3039d1 100644 --- a/contributors.md +++ b/contributors.md @@ -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) diff --git a/src/openrct2-ui/interface/Theme.cpp b/src/openrct2-ui/interface/Theme.cpp index 5af3632d10..192d04d23a 100644 --- a/src/openrct2-ui/interface/Theme.cpp +++ b/src/openrct2-ui/interface/Theme.cpp @@ -536,7 +536,7 @@ namespace ThemeManager } auto themesPattern = Path::Combine(GetThemePath(), "*.json"); - auto scanner = std::unique_ptr(Path::ScanDirectory(themesPattern, true)); + auto scanner = Path::ScanDirectory(themesPattern, true); while (scanner->Next()) { auto fileInfo = scanner->GetFileInfo(); diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 574cd128c4..05c2ead6aa 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -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(Path::ScanDirectory(filter, false)); + auto scanner = Path::ScanDirectory(filter, false); while (scanner->Next()) { LoadSaveListItem newListItem; diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 97caa7c4f9..fe376141b1 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -1189,7 +1189,6 @@ namespace OpenRCT2 } } } - delete scanner; } #ifndef DISABLE_HTTP diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 5dcb15ccf7..50c8afb43f 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -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(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(autosavesCount); { - auto scanner = std::unique_ptr(Path::ScanDirectory(filter, false)); + auto scanner = Path::ScanDirectory(filter, false); for (size_t i = 0; i < autosavesCount; i++) { autosaveFiles[i].resize(MAX_PATH, 0); diff --git a/src/openrct2/core/FileIndex.hpp b/src/openrct2/core/FileIndex.hpp index 033a286b14..0e5d570a47 100644 --- a/src/openrct2/core/FileIndex.hpp +++ b/src/openrct2/core/FileIndex.hpp @@ -161,7 +161,6 @@ private: files.push_back(std::move(path)); } - delete scanner; } return ScanResult(stats, files); } diff --git a/src/openrct2/core/FileScanner.cpp b/src/openrct2/core/FileScanner.cpp index 56a435c986..9c79c500f7 100644 --- a/src/openrct2/core/FileScanner.cpp +++ b/src/openrct2/core/FileScanner.cpp @@ -342,18 +342,18 @@ private: #endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) -IFileScanner* Path::ScanDirectory(const std::string& pattern, bool recurse) +std::unique_ptr Path::ScanDirectory(const std::string& pattern, bool recurse) { #ifdef _WIN32 - return new FileScannerWindows(pattern, recurse); + return std::make_unique(pattern, recurse); #elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) - return new FileScannerUnix(pattern, recurse); + return std::make_unique(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 Path::GetDirectories(const std::string& path) { - auto scanner = std::unique_ptr(ScanDirectory(path, false)); + auto scanner = ScanDirectory(path, false); auto baseScanner = static_cast(scanner.get()); std::vector children; diff --git a/src/openrct2/core/FileScanner.h b/src/openrct2/core/FileScanner.h index f3136e48f4..1e6c63d230 100644 --- a/src/openrct2/core/FileScanner.h +++ b/src/openrct2/core/FileScanner.h @@ -11,6 +11,7 @@ #include "../common.h" +#include #include #include @@ -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 ScanDirectory(const std::string& pattern, bool recurse); /** * Scans a directory and all sub directories diff --git a/src/openrct2/object/ImageTable.cpp b/src/openrct2/object/ImageTable.cpp index 0c70da90cc..15b04d1c70 100644 --- a/src/openrct2/object/ImageTable.cpp +++ b/src/openrct2/object/ImageTable.cpp @@ -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(Path::ScanDirectory(filter, true)); + auto scanner = Path::ScanDirectory(filter, true); while (scanner->Next()) { auto currentName = Path::GetFileName(scanner->GetPathRelative()); diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index d1a1ff3217..db2f1a1801 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -443,7 +443,7 @@ void ScriptEngine::LoadPlugins() if (Path::DirectoryExists(base)) { auto pattern = Path::Combine(base, "*.js"); - auto scanner = std::unique_ptr(Path::ScanDirectory(pattern, true)); + auto scanner = Path::ScanDirectory(pattern, true); while (scanner->Next()) { auto path = std::string(scanner->GetPath()); diff --git a/src/openrct2/title/TitleSequence.cpp b/src/openrct2/title/TitleSequence.cpp index 87d513ae4f..c5e47ca72a 100644 --- a/src/openrct2/title/TitleSequence.cpp +++ b/src/openrct2/title/TitleSequence.cpp @@ -292,7 +292,7 @@ static std::vector GetSaves(const std::string& directory) std::vector 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(); diff --git a/src/openrct2/title/TitleSequenceManager.cpp b/src/openrct2/title/TitleSequenceManager.cpp index 02c8c381f0..553c061596 100644 --- a/src/openrct2/title/TitleSequenceManager.cpp +++ b/src/openrct2/title/TitleSequenceManager.cpp @@ -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) diff --git a/test/tests/ReplayTests.cpp b/test/tests/ReplayTests.cpp index 7377a57110..83b8c8f4b5 100644 --- a/test/tests/ReplayTests.cpp +++ b/test/tests/ReplayTests.cpp @@ -53,7 +53,7 @@ static std::vector GetReplayFiles() std::string replayPathPattern = Path::Combine(replayPath, "*.sv6r"); std::vector files; - std::unique_ptr scanner = std::unique_ptr(Path::ScanDirectory(replayPathPattern, true)); + auto scanner = Path::ScanDirectory(replayPathPattern, true); while (scanner->Next()) { ReplayTestData test;