From fd1dc5f008056eca9dfa9feaf068db232baa9418 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Mon, 26 Oct 2026 22:55:40 +0000 Subject: [PATCH] Decompile fn_18245 (RemoveDirectoryTree) Batch #870 by ragnarok-clanker: 0 byte-identical, 1 confirmed by peer review. - fn_18245 RemoveDirectoryTree: logic confirmed by peer review Reviewed-by: ragnarok-clanker Adds to the build: Source/File/DirectoryRemoval.cpp --- Source/File/DirectoryRemoval.cpp | 46 ++++++++++++++++++++++++++++++++ Source/File/DirectoryRemoval.h | 6 +++++ compile.json | 1 + 3 files changed, 53 insertions(+) create mode 100644 Source/File/DirectoryRemoval.cpp create mode 100644 Source/File/DirectoryRemoval.h diff --git a/Source/File/DirectoryRemoval.cpp b/Source/File/DirectoryRemoval.cpp new file mode 100644 index 0000000..206353f --- /dev/null +++ b/Source/File/DirectoryRemoval.cpp @@ -0,0 +1,46 @@ +#include "File/DirectoryRemoval.h" + +#include +#include +#include +#include +#include +#include +#include + +// FUNCTION: fn_18245 +void RemoveDirectoryTree(const char* path) { + std::list files; + std::list directories; + WIN32_FIND_DATAA found{}; + char filename[2048]; + std::strcpy(filename, path); + std::strcat(filename, "\\*.*"); + HANDLE search = FindFirstFileA(filename, &found); + if (search == INVALID_HANDLE_VALUE) { + FindClose(search); + } else { + do { + if (found.cFileName[0] == '.' && (found.cFileName[1] == 0 || (found.cFileName[1] == '.' && found.cFileName[2] == 0))) { + continue; + } + if ((found.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { + directories.push_back(std::string(found.cFileName)); + } else { + files.push_back(std::string(found.cFileName)); + } + } while (FindNextFileA(search, &found)); + FindClose(search); + + std::strcpy(filename, path); + std::strcat(filename, "\\"); + for (const std::string& file : files) { + _chmod((std::string(filename) + file).c_str(), _S_IWRITE); + _unlink((std::string(filename) + file).c_str()); + } + for (const std::string& directory : directories) { + RemoveDirectoryTree((std::string(filename) + directory).c_str()); + } + } + _rmdir(path); +} diff --git a/Source/File/DirectoryRemoval.h b/Source/File/DirectoryRemoval.h new file mode 100644 index 0000000..34fa762 --- /dev/null +++ b/Source/File/DirectoryRemoval.h @@ -0,0 +1,6 @@ +#ifndef RAGNAROK_SOURCE_FILE_DIRECTORYREMOVAL_H +#define RAGNAROK_SOURCE_FILE_DIRECTORYREMOVAL_H + +void RemoveDirectoryTree(const char* path); + +#endif diff --git a/compile.json b/compile.json index f69bb01..f31c94d 100644 --- a/compile.json +++ b/compile.json @@ -387,6 +387,7 @@ "Source/Contents/World/WorldTerrainPicking.cpp": 4, "Source/Contents/World/WorldViewSpatial.cpp": 3, "Source/File/CommonObject.cpp": 1, + "Source/File/DirectoryRemoval.cpp": 1, "Source/File/File.cpp": 1, "Source/File/FileCreation.cpp": 1, "Source/File/FileEnumeration.cpp": 1,