Just move DeleteDir next to DeleteDirRecursive

This commit is contained in:
Henrik Rydgård 2024-01-21 21:49:23 +01:00
parent 3b3373dde6
commit 1935dd3f4c
2 changed files with 38 additions and 38 deletions

View File

@ -613,41 +613,6 @@ bool CreateFullPath(const Path &path) {
return true;
}
// Deletes an empty directory, returns true on success
bool DeleteDir(const Path &path) {
switch (path.Type()) {
case PathType::NATIVE:
break; // OK
case PathType::CONTENT_URI:
return Android_RemoveFile(path.ToString()) == StorageError::SUCCESS;
default:
return false;
}
INFO_LOG(COMMON, "DeleteDir: directory %s", path.c_str());
// check if a directory
if (!File::IsDirectory(path)) {
ERROR_LOG(COMMON, "DeleteDir: Not a directory %s", path.c_str());
return false;
}
#ifdef _WIN32
#if PPSSPP_PLATFORM(UWP)
if (RemoveDirectoryFromAppW(path.ToWString().c_str()))
return true;
#else
if (::RemoveDirectory(path.ToWString().c_str()))
return true;
#endif
#else
if (rmdir(path.c_str()) == 0)
return true;
#endif
ERROR_LOG(COMMON, "DeleteDir: %s: %s", path.c_str(), GetLastErrorMsg().c_str());
return false;
}
// renames file srcFilename to destFilename, returns true on success
bool Rename(const Path &srcFilename, const Path &destFilename) {
if (srcFilename.Type() != destFilename.Type()) {
@ -936,6 +901,41 @@ bool CreateEmptyFile(const Path &filename) {
return true;
}
// Deletes an empty directory, returns true on success
bool DeleteDir(const Path &path) {
switch (path.Type()) {
case PathType::NATIVE:
break; // OK
case PathType::CONTENT_URI:
return Android_RemoveFile(path.ToString()) == StorageError::SUCCESS;
default:
return false;
}
INFO_LOG(COMMON, "DeleteDir: directory %s", path.c_str());
// check if a directory
if (!File::IsDirectory(path)) {
ERROR_LOG(COMMON, "DeleteDir: Not a directory %s", path.c_str());
return false;
}
#ifdef _WIN32
#if PPSSPP_PLATFORM(UWP)
if (RemoveDirectoryFromAppW(path.ToWString().c_str()))
return true;
#else
if (::RemoveDirectory(path.ToWString().c_str()))
return true;
#endif
#else
if (rmdir(path.c_str()) == 0)
return true;
#endif
ERROR_LOG(COMMON, "DeleteDir: %s: %s", path.c_str(), GetLastErrorMsg().c_str());
return false;
}
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const Path &directory) {
switch (directory.Type()) {

View File

@ -86,11 +86,11 @@ bool CreateDir(const Path &filename);
// Creates the full path of fullPath returns true on success
bool CreateFullPath(const Path &fullPath);
// Deletes a given filename, return true on success
// Doesn't supports deleting a directory
// Deletes a given file by name, return true on success
// Doesn't support deleting a directory (although it will work on some platforms - ideally shouldn't)
bool Delete(const Path &filename);
// Deletes a directory filename, returns true on success
// Deletes a directory by name, returns true on success
// Directory must be empty.
bool DeleteDir(const Path &filename);