Batch #17225 by ragnarok-clanker: forced by an admin (0 lower score(s), 1 changed function(s)); checked with 75 compiled unit(s), including every includer of Source/Utility/StdIntVectorCopy.h, Source/Utility/StdStringConcat.h, Source/Utility/StdStringCopy.h, Source/Utility/StdStringInsert.h, Source/Utility/StdStringMoveAssign.h, Source/Utility/StdStringVectorDestroy.h, Source/Utility/StdTraitsEqual.h, Source/Utility/StdTraitsFind.h, Source/Utility/StdWindowListEmplace.h.
50 lines
1.4 KiB
C++
50 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>
|
|
|
|
#include "Utility/StdStringConcat.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((filename + file).c_str(), _S_IWRITE);
|
|
_unlink((filename + file).c_str());
|
|
}
|
|
for (const std::string& directory : directories) {
|
|
RemoveDirectoryTree((filename + directory).c_str());
|
|
}
|
|
}
|
|
_rmdir(path);
|
|
}
|