added linux support for fileutils

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1225 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee 2008-11-20 13:37:57 +00:00
parent 337ff1f56b
commit 2ad407e477
1 changed files with 44 additions and 12 deletions

View File

@ -25,7 +25,8 @@
#include <commdlg.h> // for GetSaveFileName #include <commdlg.h> // for GetSaveFileName
#include <io.h> #include <io.h>
#else #else
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
@ -128,10 +129,10 @@ bool CreateDir(const char *path)
PanicAlert("%s already exists", path); PanicAlert("%s already exists", path);
return true; return true;
} }
PanicAlert("Error creating directory: %i", error); PanicAlert("Error creating directory %s: %i", path, error);
return false; return false;
#else #else
if (mkdir(path, 0644) == 0) if (mkdir(path, 0755) == 0)
return true; return true;
int err = errno; int err = errno;
@ -142,7 +143,7 @@ bool CreateDir(const char *path)
return true; return true;
} }
PanicAlert("Error creating directory: %s", strerror(err)); PanicAlert("Error creating directory %s: %s", path, strerror(err));
return false; return false;
#endif #endif
@ -150,16 +151,19 @@ bool CreateDir(const char *path)
bool DeleteDir(const char *filename) bool DeleteDir(const char *filename)
{ {
#ifdef _WIN32
if (!File::IsDirectory(filename)) if (!File::IsDirectory(filename))
return false; return false;
#ifdef _WIN32
return ::RemoveDirectory (filename) ? true : false; return ::RemoveDirectory (filename) ? true : false;
#else #else
if (rmdir(filename) == 0)
return true;
PanicAlert("File::DeleteDir() not implemented"); int err = errno;
return false;
PanicAlert("Error removing directory %s",strerror(err));
return false;
#endif #endif
} }
@ -324,10 +328,38 @@ error_jmp:
return Result; return Result;
#else #else
// taken from http://www.dreamincode.net/code/snippet2700.htm
DIR *pdir = NULL;
pdir = opendir (_Directory.c_str());
struct dirent *pent = NULL;
PanicAlert("File::DeleteDirRecursively() not implemented"); if (pdir == NULL) {
return false; return false;
}
char file[256];
int counter = 1;
while ((pent = readdir(pdir))) {
if (counter > 2) {
for (int i = 0; i < 256; i++) file[i] = '\0';
strcat(file, _Directory.c_str());
if (pent == NULL) {
return false;
}
strcat(file, pent->d_name);
if (IsDirectory(file) == true) {
DeleteDir(file);
} else {
remove(file);
}
}
counter++;
}
return DeleteDir(_Directory.c_str());
#endif #endif
} }