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
This commit is contained in:
parent
bb091ae751
commit
fd1dc5f008
3 changed files with 53 additions and 0 deletions
46
Source/File/DirectoryRemoval.cpp
Normal file
46
Source/File/DirectoryRemoval.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include "File/DirectoryRemoval.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <windows.h>
|
||||
|
||||
// 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 {
|
||||
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);
|
||||
}
|
||||
6
Source/File/DirectoryRemoval.h
Normal file
6
Source/File/DirectoryRemoval.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef RAGNAROK_SOURCE_FILE_DIRECTORYREMOVAL_H
|
||||
#define RAGNAROK_SOURCE_FILE_DIRECTORYREMOVAL_H
|
||||
|
||||
void RemoveDirectoryTree(const char* path);
|
||||
|
||||
#endif
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue