diff --git a/Common/File/FileUtil.cpp b/Common/File/FileUtil.cpp index d9270f5d2d..19da5f04bb 100644 --- a/Common/File/FileUtil.cpp +++ b/Common/File/FileUtil.cpp @@ -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()) { diff --git a/Common/File/FileUtil.h b/Common/File/FileUtil.h index 225850b26d..2ae3329b75 100644 --- a/Common/File/FileUtil.h +++ b/Common/File/FileUtil.h @@ -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);