rodecomp/Source/File/DirectoryRemoval.cpp
ragnarok-clanker 80c5533df8 Decompile fn_18245 (RemoveDirectoryTree)
Batch #10848 by cremane: 0 byte-identical, 1 confirmed by peer review.

- fn_18245 RemoveDirectoryTree: logic confirmed by peer review

Peer-reviewed-by: Tanke, dori, StrawberrysherbetIX
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-04 17:46:33 +00:00

49 lines
1.3 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) {
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((filename + file).c_str(), _S_IWRITE);
_unlink((filename + file).c_str());
}
for (const std::string& directory : directories) {
RemoveDirectoryTree((filename + directory).c_str());
}
}
_rmdir(path);
}