diff options
| author | hrydgard <hrydgard@gmail.com> | 2008-09-22 19:48:12 +0000 |
|---|---|---|
| committer | hrydgard <hrydgard@gmail.com> | 2008-09-22 19:48:12 +0000 |
| commit | 38f04809f14a924fb2c5925cd6d4f2ec1859087f (patch) | |
| tree | 49c200eff66320ca7bed8eb3e7be08b6b64bda64 /Source/Core/Common/Src/FileUtil.cpp | |
| parent | a0eb4ad055240825f6d3a3dea54512d351d20049 (diff) | |
Reduce the use of string objects slightly. Add Delete ISO feature.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@610 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/Common/Src/FileUtil.cpp')
| -rw-r--r-- | Source/Core/Common/Src/FileUtil.cpp | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 061f51ea5a..406678d6f9 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -19,6 +19,7 @@ #include "FileUtil.h"
#ifdef _WIN32
+#include <windows.h>
#include <shlobj.h> // for SHGetFolderPath
#include <shellapi.h>
#include <commdlg.h> // for GetSaveFileName
@@ -29,23 +30,24 @@ #include <stdlib.h>
#endif
-bool File::Exists(const std::string &filename)
+bool File::Exists(const char *filename)
{
#ifdef _WIN32
- return GetFileAttributes(filename.c_str()) != INVALID_FILE_ATTRIBUTES;
+ return GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES;
#else
struct stat file_info;
- int result = stat(filename.c_str(), &file_info);
+ int result = stat(filename, &file_info);
return result == 0;
#endif
}
-bool File::IsDirectory(const std::string &filename) {
+bool File::IsDirectory(const char *filename)
+{
#ifdef _WIN32
- return (GetFileAttributes(filename.c_str()) & FILE_ATTRIBUTE_DIRECTORY) != 0;
+ return (GetFileAttributes(filename) & FILE_ATTRIBUTE_DIRECTORY) != 0;
#else
struct stat file_info;
- int result = stat(filename.c_str(), &file_info);
+ int result = stat(filename, &file_info);
if (result == 0)
return S_ISDIR(file_info.st_mode);
else
@@ -53,7 +55,22 @@ bool File::IsDirectory(const std::string &filename) { #endif
}
-std::string SanitizePath(const std::string &filename) {
+bool File::Delete(const char *filename)
+{
+ if (!File::Exists(filename))
+ return false;
+ if (File::IsDirectory(filename))
+ return false;
+#ifdef _WIN32
+ DeleteFile(filename);
+#else
+ unlink(filename);
+#endif
+ return true;
+}
+
+std::string SanitizePath(const char *filename)
+{
std::string copy = filename;
for (size_t i = 0; i < copy.size(); i++)
if (copy[i] == '/')
@@ -61,7 +78,7 @@ std::string SanitizePath(const std::string &filename) { return copy;
}
-void File::Launch(const std::string &filename)
+void File::Launch(const char *filename)
{
#ifdef _WIN32
std::string win_filename = SanitizePath(filename);
@@ -76,7 +93,7 @@ void File::Launch(const std::string &filename) #endif
}
-void File::Explore(const std::string &path)
+void File::Explore(const char *path)
{
#ifdef _WIN32
std::string win_path = SanitizePath(path);
@@ -92,27 +109,27 @@ void File::Explore(const std::string &path) }
// Returns true if successful, or path already exists.
-bool File::CreateDir(const std::string &path)
+bool File::CreateDir(const char *path)
{
#ifdef _WIN32
- if (::CreateDirectory(path.c_str(), NULL))
+ if (::CreateDirectory(path, NULL))
return true;
DWORD error = GetLastError();
if (error == ERROR_ALREADY_EXISTS)
{
- PanicAlert("%s already exists", path.c_str());
+ PanicAlert("%s already exists", path);
return true;
}
PanicAlert("Error creating directory: %i", error);
return false;
#else
- if (mkdir(path.c_str(), 0644) == 0)
+ if (mkdir(path, 0644) == 0)
return true;
int err = errno;
if (err == EEXIST) {
- PanicAlert("%s already exists", path.c_str());
+ PanicAlert("%s already exists", path);
return true;
}
@@ -122,7 +139,7 @@ bool File::CreateDir(const std::string &path) #endif
}
-std::string GetUserDirectory() {
+std::string File::GetUserDirectory() {
#ifdef _WIN32
char path[MAX_PATH];
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, path)))
@@ -137,3 +154,12 @@ std::string GetUserDirectory() { return dir;
#endif
}
+
+u64 File::GetSize(const char *filename)
+{
+ FILE *f = fopen(filename, "rb");
+ fseek(f, 0, SEEK_END);
+ u64 pos = ftell(f);
+ fclose(f);
+ return pos;
+}
|
