From 8d6cb974bfe0111c0896a46006f819dec0da077e Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 10 Jan 2022 12:52:33 +0100 Subject: [PATCH] Move platform_directory_delete() to Path --- src/openrct2/core/Path.cpp | 5 +++++ src/openrct2/core/Path.hpp | 1 + src/openrct2/platform/Posix.cpp | 5 ----- src/openrct2/platform/Windows.cpp | 20 -------------------- src/openrct2/platform/platform.h | 1 - src/openrct2/title/TitleSequenceManager.cpp | 2 +- 6 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/openrct2/core/Path.cpp b/src/openrct2/core/Path.cpp index 97e293ff1c..0a71bf9b05 100644 --- a/src/openrct2/core/Path.cpp +++ b/src/openrct2/core/Path.cpp @@ -104,4 +104,9 @@ namespace Path { return Platform::ResolveCasing(path, File::Exists(path)); } + + bool DeleteDirectory(std::string_view path) + { + return fs::remove_all(u8path(path)) > 0; + } } // namespace Path diff --git a/src/openrct2/core/Path.hpp b/src/openrct2/core/Path.hpp index b3de9dd13e..5c3be0715e 100644 --- a/src/openrct2/core/Path.hpp +++ b/src/openrct2/core/Path.hpp @@ -26,6 +26,7 @@ namespace Path std::string GetDirectory(std::string_view path); void CreateDirectory(std::string_view path); bool DirectoryExists(std::string_view path); + bool DeleteDirectory(std::string_view path); std::string GetFileName(std::string_view origPath); std::string GetFileNameWithoutExtension(std::string_view path); std::string GetExtension(std::string_view path); diff --git a/src/openrct2/platform/Posix.cpp b/src/openrct2/platform/Posix.cpp index 0c31ce1aac..66e5d18703 100644 --- a/src/openrct2/platform/Posix.cpp +++ b/src/openrct2/platform/Posix.cpp @@ -89,11 +89,6 @@ bool platform_ensure_directory_exists(const utf8* path) return true; } -bool platform_directory_delete(const utf8* path) -{ - return fs::remove_all(u8path(path)) > 0; -} - std::string platform_get_absolute_path(const utf8* relative_path, const utf8* base_path) { std::string result; diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp index ecc291cb16..150139d1b9 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -70,26 +70,6 @@ bool platform_ensure_directory_exists(const utf8* path) return success != FALSE; } -bool platform_directory_delete(const utf8* path) -{ - // Needs to be double-null terminated as pFrom is a null terminated array of strings - auto wPath = String::ToWideChar(path) + L"\0"; - - SHFILEOPSTRUCTW fileop; - fileop.hwnd = nullptr; // no status display - fileop.wFunc = FO_DELETE; // delete operation - fileop.pFrom = wPath.c_str(); // source file name as double null terminated string - fileop.pTo = nullptr; // no destination needed - fileop.fFlags = FOF_NOCONFIRMATION | FOF_SILENT; // do not prompt the user - - fileop.fAnyOperationsAborted = FALSE; - fileop.lpszProgressTitle = nullptr; - fileop.hNameMappings = nullptr; - - int32_t ret = SHFileOperationW(&fileop); - return (ret == 0); -} - bool platform_lock_single_instance() { HANDLE mutex, status; diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index 49a422b092..bdf34c1a32 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -89,7 +89,6 @@ void platform_refresh_video(bool recreate_window); // Platform specific definitions time_t platform_file_get_modified_time(const utf8* path); bool platform_ensure_directory_exists(const utf8* path); -bool platform_directory_delete(const utf8* path); std::string platform_get_absolute_path(const utf8* relative_path, const utf8* base_path); bool platform_lock_single_instance(); diff --git a/src/openrct2/title/TitleSequenceManager.cpp b/src/openrct2/title/TitleSequenceManager.cpp index 62f863c62f..982f3f5608 100644 --- a/src/openrct2/title/TitleSequenceManager.cpp +++ b/src/openrct2/title/TitleSequenceManager.cpp @@ -90,7 +90,7 @@ namespace TitleSequenceManager } else { - platform_directory_delete(path); + Path::DeleteDirectory(path); } _items.erase(_items.begin() + i); }