From 9d8cecce0a0bbe92b652fddd3a6b2739ee3e14f9 Mon Sep 17 00:00:00 2001 From: nutzboi Date: Thu, 2 Apr 2026 04:41:55 +0200 Subject: [PATCH 1/2] Allow file_manager to detect compiling for Windows. Consistent with 6c23f94. I suspect more like this commit should come. Updating addons using unofficial links should now work on Windows as the proper implementation of removeDirectory is now the one compiled. --- src/io/file_manager.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index df87df5e138..6a64bb324c9 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -60,7 +60,7 @@ namespace irr { } // For mkdir -#if !defined(WIN32) +#if !defined(WIN_BUILD) # include # include # include @@ -1245,7 +1245,7 @@ void FileManager::checkAndCreateGPDir() } // checkAndCreateGPDir // ---------------------------------------------------------------------------- -#if !defined(WIN32) && !defined(__APPLE__) +#if !defined(WIN_BUILD) && !defined(__APPLE__) /** Find a directory to use for remaining unix variants. Use the new standards * for config directory based on XDG_* environment variables, or a @@ -1532,7 +1532,7 @@ bool FileManager::removeFile(const std::string &name) const if(FileUtils::statU8Path(name, &mystat) < 0) return false; if( S_ISREG(mystat.st_mode)) { -#if defined(WIN32) +#if defined(WIN_BUILD) return _wremove(StringUtils::utf8ToWide(name).c_str()) == 0; #else return remove(name.c_str()) == 0; @@ -1584,7 +1584,7 @@ bool FileManager::removeDirectory(const std::string &name) const } } -#if defined(WIN32) +#if defined(WIN_BUILD) return RemoveDirectory(StringUtils::utf8ToWide(name).c_str())==TRUE; #else return remove(name.c_str())==0; @@ -1659,7 +1659,7 @@ bool FileManager::moveDirectoryInto(std::string source, std::string target) if (isDirectory(target)) return false; -#if defined(WIN32) +#if defined(WIN_BUILD) return MoveFileExW(StringUtils::utf8ToWide(source).c_str(), StringUtils::utf8ToWide(target).c_str(), MOVEFILE_WRITE_THROUGH) != 0; From f8ed20e2c3e01657204f66e6d2833bcbfda1848a Mon Sep 17 00:00:00 2001 From: nutzboi Date: Thu, 2 Apr 2026 04:54:43 +0200 Subject: [PATCH 2/2] Fix moveDirectoryInto failing to follow hard links on Windows especially to different disks. This fix is compatible with C++17 and later only. --- src/io/file_manager.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index 6a64bb324c9..336ba7ccfb6 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -1660,9 +1661,15 @@ bool FileManager::moveDirectoryInto(std::string source, std::string target) return false; #if defined(WIN_BUILD) - return MoveFileExW(StringUtils::utf8ToWide(source).c_str(), - StringUtils::utf8ToWide(target).c_str(), - MOVEFILE_WRITE_THROUGH) != 0; + try{ + std::filesystem::copy(source.c_str(), target.c_str(), std::filesystem::copy_options::recursive); + std::filesystem::remove_all(source.c_str()); + return 1; + } + catch(std::filesystem::filesystem_error const& ex){ + Log::error("FileManager", "%s", ex.what()); + return 0; + } #else return rename(source.c_str(), target.c_str()) != -1; #endif