rodecomp/Source/File/DirectoryRemoval.cpp
ragnarok-clanker c29fc396cc Decompile fn_18245 (RemoveDirectoryTree)
Batch #15125 by Yommy: 0 byte-identical, 1 confirmed by peer review.

- fn_18245 RemoveDirectoryTree: logic confirmed by peer review

Peer-reviewed-by: ragnarok-clanker, gordaoprogramas, codeplay
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-09 20:43:09 +00:00

48 lines
1.4 KiB
C++

#include "File/DirectoryRemoval.h"
#include <cstring>
#include <direct.h>
#include <io.h>
#include <list>
#include <string>
#include <sys/stat.h>
#include <windows.h>
// OFFSET: 0x00AF45E0
// FUNCTION: fn_18245
void RemoveDirectoryTree(const char* path) {
std::list<std::string> files;
std::list<std::string> 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 {
std::string dot(".");
std::string dotdot("..");
do {
if (dot != found.cFileName && dotdot != found.cFileName) {
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);
}