More conversion from char * to std::string.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7266 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice 2011-03-01 03:06:14 +00:00
parent ba54fac9eb
commit a5b471f490
37 changed files with 338 additions and 444 deletions

View File

@ -57,7 +57,7 @@ namespace AudioCommon
if (ac_Config.m_DumpAudio) if (ac_Config.m_DumpAudio)
{ {
std::string audio_file_name = File::GetUserPath(D_DUMPAUDIO_IDX) + "audiodump.wav"; std::string audio_file_name = File::GetUserPath(D_DUMPAUDIO_IDX) + "audiodump.wav";
File::CreateFullPath(audio_file_name.c_str()); File::CreateFullPath(audio_file_name);
mixer->StartLogAudio(audio_file_name.c_str()); mixer->StartLogAudio(audio_file_name.c_str());
} }

View File

@ -185,11 +185,11 @@ public:
{ {
INFO_LOG(COMMON, "ChunkReader: Loading %s" , _rFilename.c_str()); INFO_LOG(COMMON, "ChunkReader: Loading %s" , _rFilename.c_str());
if (! File::Exists(_rFilename.c_str())) if (!File::Exists(_rFilename))
return false; return false;
// Check file size // Check file size
u64 fileSize = File::GetSize(_rFilename.c_str()); u64 fileSize = File::GetSize(_rFilename);
u64 headerSize = sizeof(SChunkHeader); u64 headerSize = sizeof(SChunkHeader);
if (fileSize < headerSize) { if (fileSize < headerSize) {
ERROR_LOG(COMMON,"ChunkReader: File too small"); ERROR_LOG(COMMON,"ChunkReader: File too small");

View File

@ -49,8 +49,8 @@
#endif #endif
#ifdef BSD4_4 #ifdef BSD4_4
#define stat64 stat // XXX #define stat64 stat
#define fstat64 fstat // XXX #define fstat64 fstat
#endif #endif
// This namespace has various generic functions related to files and paths. // This namespace has various generic functions related to files and paths.
@ -73,7 +73,7 @@ static void StripTailDirSlashes(std::string &fname)
} }
// Returns true if file filename exists // Returns true if file filename exists
bool Exists(const char *filename) bool Exists(const std::string filename)
{ {
struct stat64 file_info; struct stat64 file_info;
@ -86,7 +86,7 @@ bool Exists(const char *filename)
} }
// Returns true if filename is a directory // Returns true if filename is a directory
bool IsDirectory(const char *filename) bool IsDirectory(const std::string filename)
{ {
struct stat64 file_info; struct stat64 file_info;
@ -97,7 +97,7 @@ bool IsDirectory(const char *filename)
if (result < 0) { if (result < 0) {
WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s", WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s",
filename, GetLastErrorMsg()); filename.c_str(), GetLastErrorMsg());
return false; return false;
} }
@ -106,33 +106,36 @@ bool IsDirectory(const char *filename)
// Deletes a given filename, return true on success // Deletes a given filename, return true on success
// Doesn't supports deleting a directory // Doesn't supports deleting a directory
bool Delete(const char *filename) bool Delete(const std::string filename)
{ {
INFO_LOG(COMMON, "Delete: file %s", filename); INFO_LOG(COMMON, "Delete: file %s", filename.c_str());
// Return true because we care about the file no // Return true because we care about the file no
// being there, not the actual delete. // being there, not the actual delete.
if (!Exists(filename)) { if (!Exists(filename))
WARN_LOG(COMMON, "Delete: %s does not exists", filename); {
WARN_LOG(COMMON, "Delete: %s does not exists", filename.c_str());
return true; return true;
} }
// We can't delete a directory // We can't delete a directory
if (IsDirectory(filename)) { if (IsDirectory(filename))
WARN_LOG(COMMON, "Delete: %s is a directory", filename); {
WARN_LOG(COMMON, "Delete: %s is a directory", filename.c_str());
return false; return false;
} }
#ifdef _WIN32 #ifdef _WIN32
if (!DeleteFile(filename)) { if (!DeleteFile(filename.c_str()))
{
WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s", WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s",
filename, GetLastErrorMsg()); filename.c_str(), GetLastErrorMsg());
return false; return false;
} }
#else #else
if (unlink(filename) == -1) { if (unlink(filename.c_str()) == -1) {
WARN_LOG(COMMON, "Delete: unlink failed on %s: %s", WARN_LOG(COMMON, "Delete: unlink failed on %s: %s",
filename, GetLastErrorMsg()); filename.c_str(), GetLastErrorMsg());
return false; return false;
} }
#endif #endif
@ -141,128 +144,122 @@ bool Delete(const char *filename)
} }
// Returns true if successful, or path already exists. // Returns true if successful, or path already exists.
bool CreateDir(const char *path) bool CreateDir(const std::string path)
{ {
INFO_LOG(COMMON, "CreateDir: directory %s", path); INFO_LOG(COMMON, "CreateDir: directory %s", path.c_str());
#ifdef _WIN32 #ifdef _WIN32
if (::CreateDirectory(path, NULL)) if (::CreateDirectory(path.c_str(), NULL))
return true; return true;
DWORD error = GetLastError(); DWORD error = GetLastError();
if (error == ERROR_ALREADY_EXISTS) { if (error == ERROR_ALREADY_EXISTS)
WARN_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: already exists", path); {
WARN_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: already exists", path.c_str());
return true; return true;
} }
ERROR_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: %i", path, error); ERROR_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: %i", path.c_str(), error);
return false; return false;
#else #else
if (mkdir(path, 0755) == 0) if (mkdir(path.c_str(), 0755) == 0)
return true; return true;
int err = errno; int err = errno;
if (err == EEXIST) { if (err == EEXIST)
WARN_LOG(COMMON, "CreateDir: mkdir failed on %s: already exists", path); {
WARN_LOG(COMMON, "CreateDir: mkdir failed on %s: already exists", path.c_str());
return true; return true;
} }
ERROR_LOG(COMMON, "CreateDir: mkdir failed on %s: %s", path, strerror(err)); ERROR_LOG(COMMON, "CreateDir: mkdir failed on %s: %s", path.c_str(), strerror(err));
return false; return false;
#endif #endif
} }
// Creates the full path of fullPath returns true on success // Creates the full path of fullPath returns true on success
bool CreateFullPath(const char *fullPath) bool CreateFullPath(const std::string fullPath)
{ {
int panicCounter = 100; int panicCounter = 100;
INFO_LOG(COMMON, "CreateFullPath: path %s", fullPath); INFO_LOG(COMMON, "CreateFullPath: path %s", fullPath.c_str());
if (File::Exists(fullPath)) { if (File::Exists(fullPath))
INFO_LOG(COMMON, "CreateFullPath: path exists %s", fullPath); {
INFO_LOG(COMMON, "CreateFullPath: path exists %s", fullPath.c_str());
return true; return true;
} }
// safety check to ensure we have good dir seperators size_t position = 0;
std::string strFullPath(fullPath); while (true)
{
const char *position = strFullPath.c_str();
while (true) {
// Find next sub path // Find next sub path
position = strchr(position, DIR_SEP_CHR); position = fullPath.find(DIR_SEP_CHR, position);
// we're done, yay! // we're done, yay!
if (! position) if (position == fullPath.npos)
return true; return true;
position++; std::string subPath = fullPath.substr(0, position);
if (!File::IsDirectory(subPath))
// Create next sub path File::CreateDir(subPath);
int sLen = (int)(position - strFullPath.c_str());
if (sLen > 0) {
char *subPath = strndup(strFullPath.c_str(), sLen);
if (!File::IsDirectory(subPath)) {
File::CreateDir(subPath);
}
free(subPath);
}
// A safety check // A safety check
panicCounter--; panicCounter--;
if (panicCounter <= 0) { if (panicCounter <= 0)
{
ERROR_LOG(COMMON, "CreateFullPath: directory structure too deep"); ERROR_LOG(COMMON, "CreateFullPath: directory structure too deep");
return false; return false;
} }
position++;
} }
} }
// Deletes a directory filename, returns true on success // Deletes a directory filename, returns true on success
bool DeleteDir(const char *filename) bool DeleteDir(const std::string filename)
{ {
INFO_LOG(COMMON, "DeleteDir: directory %s", filename); INFO_LOG(COMMON, "DeleteDir: directory %s", filename.c_str());
// check if a directory // check if a directory
if (!File::IsDirectory(filename)) { if (!File::IsDirectory(filename))
ERROR_LOG(COMMON, "DeleteDir: Not a directory %s", {
filename); ERROR_LOG(COMMON, "DeleteDir: Not a directory %s", filename.c_str());
return false; return false;
} }
#ifdef _WIN32 #ifdef _WIN32
if (::RemoveDirectory(filename)) if (::RemoveDirectory(filename.c_str()))
return true; return true;
#else #else
if (rmdir(filename) == 0) if (rmdir(filename.c_str()) == 0)
return true; return true;
#endif #endif
ERROR_LOG(COMMON, "DeleteDir: %s: %s", ERROR_LOG(COMMON, "DeleteDir: %s: %s", filename.c_str(), GetLastErrorMsg());
filename, GetLastErrorMsg());
return false; return false;
} }
// renames file srcFilename to destFilename, returns true on success // renames file srcFilename to destFilename, returns true on success
bool Rename(const char *srcFilename, const char *destFilename) bool Rename(const std::string srcFilename, const std::string destFilename)
{ {
INFO_LOG(COMMON, "Rename: %s --> %s", INFO_LOG(COMMON, "Rename: %s --> %s",
srcFilename, destFilename); srcFilename.c_str(), destFilename.c_str());
if (rename(srcFilename, destFilename) == 0) if (rename(srcFilename.c_str(), destFilename.c_str()) == 0)
return true; return true;
ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s", ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s",
srcFilename, destFilename, GetLastErrorMsg()); srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
return false; return false;
} }
// copies file srcFilename to destFilename, returns true on success // copies file srcFilename to destFilename, returns true on success
bool Copy(const char *srcFilename, const char *destFilename) bool Copy(const std::string srcFilename, const std::string destFilename)
{ {
INFO_LOG(COMMON, "Copy: %s --> %s", INFO_LOG(COMMON, "Copy: %s --> %s",
srcFilename, destFilename); srcFilename.c_str(), destFilename.c_str());
#ifdef _WIN32 #ifdef _WIN32
if (CopyFile(srcFilename, destFilename, FALSE)) if (CopyFile(srcFilename.c_str(), destFilename.c_str(), FALSE))
return true; return true;
ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s", ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s",
srcFilename, destFilename, GetLastErrorMsg()); srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
return false; return false;
#else #else
@ -272,21 +269,21 @@ bool Copy(const char *srcFilename, const char *destFilename)
char buffer[BSIZE]; char buffer[BSIZE];
// Open input file // Open input file
FILE *input = fopen(srcFilename, "rb"); FILE *input = fopen(srcFilename.c_str(), "rb");
if (!input) if (!input)
{ {
ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s", ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s",
srcFilename, destFilename, GetLastErrorMsg()); srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
return false; return false;
} }
// open output file // open output file
FILE *output = fopen(destFilename, "wb"); FILE *output = fopen(destFilename.c_str(), "wb");
if (!output) if (!output)
{ {
fclose(input); fclose(input);
ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s", ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s",
srcFilename, destFilename, GetLastErrorMsg()); srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
return false; return false;
} }
@ -297,10 +294,11 @@ bool Copy(const char *srcFilename, const char *destFilename)
int rnum = fread(buffer, sizeof(char), BSIZE, input); int rnum = fread(buffer, sizeof(char), BSIZE, input);
if (rnum != BSIZE) if (rnum != BSIZE)
{ {
if (ferror(input) != 0) { if (ferror(input) != 0)
{
ERROR_LOG(COMMON, ERROR_LOG(COMMON,
"Copy: failed reading from source, %s --> %s: %s", "Copy: failed reading from source, %s --> %s: %s",
srcFilename, destFilename, GetLastErrorMsg()); srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
return false; return false;
} }
} }
@ -310,8 +308,8 @@ bool Copy(const char *srcFilename, const char *destFilename)
if (wnum != rnum) if (wnum != rnum)
{ {
ERROR_LOG(COMMON, ERROR_LOG(COMMON,
"Copy: failed writing to output, %s --> %s: %s", "Copy: failed writing to output, %s --> %s: %s",
srcFilename, destFilename, GetLastErrorMsg()); srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
return false; return false;
} }
} }
@ -323,29 +321,29 @@ bool Copy(const char *srcFilename, const char *destFilename)
} }
// Returns the size of filename (64bit) // Returns the size of filename (64bit)
u64 GetSize(const char *filename) u64 GetSize(const std::string filename)
{ {
if (!Exists(filename)) { if (!Exists(filename))
WARN_LOG(COMMON, "GetSize: failed %s: No such file" {
,filename); WARN_LOG(COMMON, "GetSize: failed %s: No such file", filename.c_str());
return 0; return 0;
} }
if (IsDirectory(filename)) { if (IsDirectory(filename))
WARN_LOG(COMMON, "GetSize: failed %s: is a directory" {
,filename); WARN_LOG(COMMON, "GetSize: failed %s: is a directory", filename.c_str());
return 0; return 0;
} }
// on windows it's actually _stat64 defined in commonFuncs
struct stat64 buf; struct stat64 buf;
if (stat64(filename, &buf) == 0) { if (stat64(filename.c_str(), &buf) == 0)
{
DEBUG_LOG(COMMON, "GetSize: %s: %lld", DEBUG_LOG(COMMON, "GetSize: %s: %lld",
filename, (long long)buf.st_size); filename.c_str(), (long long)buf.st_size);
return buf.st_size; return buf.st_size;
} }
ERROR_LOG(COMMON, "GetSize: Stat failed %s: %s", ERROR_LOG(COMMON, "GetSize: Stat failed %s: %s",
filename, GetLastErrorMsg()); filename.c_str(), GetLastErrorMsg());
return 0; return 0;
} }
@ -381,14 +379,14 @@ u64 GetSize(FILE *f)
} }
// creates an empty file filename, returns true on success // creates an empty file filename, returns true on success
bool CreateEmptyFile(const char *filename) bool CreateEmptyFile(const std::string filename)
{ {
INFO_LOG(COMMON, "CreateEmptyFile: %s", filename); INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());
FILE *pFile = fopen(filename, "wb"); FILE *pFile = fopen(filename.c_str(), "wb");
if (!pFile) { if (!pFile) {
ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s", ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s",
filename, GetLastErrorMsg()); filename.c_str(), GetLastErrorMsg());
return false; return false;
} }
fclose(pFile); fclose(pFile);
@ -398,55 +396,57 @@ bool CreateEmptyFile(const char *filename)
// Scans the directory tree gets, starting from _Directory and adds the // Scans the directory tree gets, starting from _Directory and adds the
// results into parentEntry. Returns the number of files+directories found // results into parentEntry. Returns the number of files+directories found
u32 ScanDirectoryTree(const char *directory, FSTEntry& parentEntry) u32 ScanDirectoryTree(const std::string directory, FSTEntry& parentEntry)
{ {
INFO_LOG(COMMON, "ScanDirectoryTree: directory %s", directory); INFO_LOG(COMMON, "ScanDirectoryTree: directory %s", directory.c_str());
// How many files + directories we found // How many files + directories we found
u32 foundEntries = 0; u32 foundEntries = 0;
char *virtualName;
#ifdef _WIN32 #ifdef _WIN32
// Find the first file in the directory. // Find the first file in the directory.
WIN32_FIND_DATA ffd; WIN32_FIND_DATA ffd;
char searchName[MAX_PATH + 3];
strncpy(searchName, directory, MAX_PATH);
strcat(searchName, "\\*");
HANDLE hFind = FindFirstFile(searchName, &ffd); HANDLE hFind = FindFirstFile((directory + "\\*").c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE) { if (hFind == INVALID_HANDLE_VALUE)
{
FindClose(hFind); FindClose(hFind);
return foundEntries; return foundEntries;
} }
// windows loop // windows loop
do { do
{
FSTEntry entry; FSTEntry entry;
virtualName = ffd.cFileName; const std::string virtualName(ffd.cFileName);
#else #else
struct dirent dirent, *result = NULL; struct dirent dirent, *result = NULL;
DIR *dirp = opendir(directory); DIR *dirp = opendir(directory.c_str());
if (!dirp) if (!dirp)
return 0; return 0;
// non windows loop // non windows loop
while (!readdir_r(dirp, &dirent, &result) && result) { while (!readdir_r(dirp, &dirent, &result) && result)
{
FSTEntry entry; FSTEntry entry;
virtualName = result->d_name; const std::string virtualName(result->d_name);
#endif #endif
// check for "." and ".." // check for "." and ".."
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) || if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
((virtualName[0] == '.') && (virtualName[1] == '.') && ((virtualName[0] == '.') && (virtualName[1] == '.') &&
(virtualName[2] == '\0'))) (virtualName[2] == '\0')))
continue; continue;
entry.virtualName = virtualName; entry.virtualName = virtualName;
entry.physicalName = directory; entry.physicalName = directory;
entry.physicalName += DIR_SEP + entry.virtualName; entry.physicalName += DIR_SEP + entry.virtualName;
if (IsDirectory(entry.physicalName.c_str())) { if (IsDirectory(entry.physicalName.c_str()))
{
entry.isDirectory = true; entry.isDirectory = true;
// is a directory, lets go inside // is a directory, lets go inside
entry.size = ScanDirectoryTree(entry.physicalName.c_str(), entry); entry.size = ScanDirectoryTree(entry.physicalName, entry);
foundEntries += (u32)entry.size; foundEntries += (u32)entry.size;
} else { // is a file }
else
{ // is a file
entry.isDirectory = false; entry.isDirectory = false;
entry.size = GetSize(entry.physicalName.c_str()); entry.size = GetSize(entry.physicalName.c_str());
} }
@ -465,38 +465,35 @@ u32 ScanDirectoryTree(const char *directory, FSTEntry& parentEntry)
} }
// deletes the given directory and anything under it. Returns true on // Deletes the given directory and anything under it. Returns true on success.
// success. bool DeleteDirRecursively(const std::string directory)
bool DeleteDirRecursively(const char *directory)
{ {
INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory); INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());
#ifdef _WIN32 #ifdef _WIN32
// Find the first file in the directory. // Find the first file in the directory.
WIN32_FIND_DATA ffd; WIN32_FIND_DATA ffd;
char searchName[MAX_PATH + 3] = {0}; HANDLE hFind = FindFirstFile((directory + "\\*").c_str(), &ffd);
strncpy(searchName, directory, MAX_PATH); if (hFind == INVALID_HANDLE_VALUE)
strcat(searchName, "\\*"); {
HANDLE hFind = FindFirstFile(searchName, &ffd);
if (hFind == INVALID_HANDLE_VALUE) {
FindClose(hFind); FindClose(hFind);
return false; return false;
} }
// windows loop // windows loop
do { do
char *virtualName = ffd.cFileName; {
const std::string virtualName = ffd.cFileName;
#else #else
struct dirent dirent, *result = NULL; struct dirent dirent, *result = NULL;
DIR *dirp = opendir(directory); DIR *dirp = opendir(directory.c_str());
if (!dirp) if (!dirp)
return false; return false;
// non windows loop // non windows loop
while (!readdir_r(dirp, &dirent, &result) && result) { while (!readdir_r(dirp, &dirent, &result) && result)
char *virtualName = result->d_name; {
const std::string virtualName = result->d_name;
#endif #endif
// check for "." and ".." // check for "." and ".."
@ -505,12 +502,14 @@ bool DeleteDirRecursively(const char *directory)
(virtualName[2] == '\0'))) (virtualName[2] == '\0')))
continue; continue;
char newPath[MAX_PATH]; std::string newPath = directory + DIR_SEP_CHR + virtualName;
sprintf(newPath, "%s%c%s", directory, DIR_SEP_CHR, virtualName); if (IsDirectory(newPath))
if (IsDirectory(newPath)) { {
if (!DeleteDirRecursively(newPath)) if (!DeleteDirRecursively(newPath))
return false; return false;
} else { }
else
{
if (!File::Delete(newPath)) if (!File::Delete(newPath))
return false; return false;
} }
@ -527,37 +526,34 @@ bool DeleteDirRecursively(const char *directory)
return true; return true;
} }
//Create directory and copy contents (does not overwrite existing files) // Create directory and copy contents (does not overwrite existing files)
void CopyDir(const char *source_path, const char *dest_path) void CopyDir(const std::string source_path, const std::string dest_path)
{ {
#ifndef _WIN32 #ifndef _WIN32
if (!strcmp(source_path, dest_path)) return; if (source_path == dest_path) return;
if (!File::Exists(source_path)) return; if (!File::Exists(source_path)) return;
if (!File::Exists(dest_path)) File::CreateFullPath(dest_path); if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);
char *virtualName;
struct dirent dirent, *result = NULL; struct dirent dirent, *result = NULL;
DIR *dirp = opendir(source_path); DIR *dirp = opendir(source_path.c_str());
if (!dirp) return; if (!dirp) return;
while (!readdir_r(dirp, &dirent, &result) && result) while (!readdir_r(dirp, &dirent, &result) && result)
{ {
virtualName = result->d_name; const std::string virtualName(result->d_name);
// check for "." and ".." // check for "." and ".."
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) || if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
((virtualName[0] == '.') && (virtualName[1] == '.') && ((virtualName[0] == '.') && (virtualName[1] == '.') &&
(virtualName[2] == '\0'))) (virtualName[2] == '\0')))
continue; continue;
char source[FILENAME_MAX], dest[FILENAME_MAX]; std::string source, dest;
sprintf(source, "%s%s", source_path, virtualName); source = source_path + virtualName;
sprintf(dest, "%s%s", dest_path, virtualName); dest = dest_path + virtualName;
if (IsDirectory(source)) if (IsDirectory(source))
{ {
const unsigned int srclen = strlen(source); source += '/';
const unsigned int destlen = strlen(dest); dest += '/';
source[srclen] = '/'; source[srclen+1] = '\0';
dest[destlen] = '/'; dest[destlen+1] = '\0';
if (!File::Exists(dest)) File::CreateFullPath(dest); if (!File::Exists(dest)) File::CreateFullPath(dest);
CopyDir(source, dest); CopyDir(source, dest);
} }
@ -584,9 +580,9 @@ std::string GetCurrentDir()
} }
// Sets the current directory to the given directory // Sets the current directory to the given directory
bool SetCurrentDir(const char *_rDirectory) bool SetCurrentDir(const std::string directory)
{ {
return __chdir(_rDirectory) == 0; return __chdir(directory.c_str()) == 0;
} }
#if defined(__APPLE__) #if defined(__APPLE__)
@ -622,155 +618,57 @@ std::string GetSysDirectory()
return sysDir; return sysDir;
} }
// Returns a pointer to a string with a Dolphin data dir or file in the user's home // Returns a string with a Dolphin data dir or file in the user's home
// directory. To be used in "multi-user" mode (that is, installed). // directory. To be used in "multi-user" mode (that is, installed).
std::string &GetUserPath(int DirIDX) std::string &GetUserPath(const unsigned int DirIDX)
{ {
static std::string UserDir; static std::string paths[NUM_PATH_INDICES];
static std::string GCUserDir;
static std::string WiiUserDir;
static std::string WiiRootDir;
static std::string ConfigDir;
static std::string GameConfigDir;
static std::string MapsDir;
static std::string CacheDir;
static std::string ShaderCacheDir;
static std::string ShadersDir;
static std::string StateSavesDir;
static std::string ScreenShotsDir;
static std::string OpenCLDir;
static std::string HiresTexturesDir;
static std::string DumpDir;
static std::string DumpFramesDir;
static std::string DumpAudioDir;
static std::string DumpTexturesDir;
static std::string DumpDSPDir;
static std::string LogsDir;
static std::string MailLogsDir;
static std::string WiiSYSCONFDir;
static std::string DolphinConfig;
static std::string DSPConfig;
static std::string DebuggerConfig;
static std::string LoggerConfig;
static std::string MainLog;
static std::string WiiSYSCONF;
static std::string RamDump;
static std::string ARamDump;
static std::string GCSRam;
static std::string Default;
// Set up all paths and files on the first run // Set up all paths and files on the first run
if (UserDir.empty()) if (paths[D_USER_IDX].empty())
{ {
#ifdef _WIN32 #ifdef _WIN32
// Keep the directory setup the way it was on windows paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
UserDir = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
#else #else
if (File::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) if (File::Exists(ROOT_DIR DIR_SEP USERDATA_DIR))
UserDir = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP; paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
else else
UserDir = std::string(getenv("HOME")) + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP; paths[D_USER_IDX] = std::string(getenv("HOME")) + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP;
#endif #endif
INFO_LOG(COMMON, "GetUserPath: Setting user directory to %s:", UserDir.c_str()); INFO_LOG(COMMON, "GetUserPath: Setting user directory to %s:", paths[D_USER_IDX].c_str());
GCUserDir = UserDir + GC_USER_DIR DIR_SEP; paths[D_GCUSER_IDX] = paths[D_USER_IDX] + GC_USER_DIR DIR_SEP;
WiiUserDir = UserDir + WII_USER_DIR DIR_SEP; paths[D_WIIUSER_IDX] = paths[D_USER_IDX] + WII_USER_DIR DIR_SEP;
WiiRootDir = UserDir + WII_USER_DIR; paths[D_WIIROOT_IDX] = paths[D_USER_IDX] + WII_USER_DIR;
ConfigDir = UserDir + CONFIG_DIR DIR_SEP; paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
GameConfigDir = UserDir + GAMECONFIG_DIR DIR_SEP; paths[D_GAMECONFIG_IDX] = paths[D_USER_IDX] + GAMECONFIG_DIR DIR_SEP;
MapsDir = UserDir + MAPS_DIR DIR_SEP; paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP;
CacheDir = UserDir + CACHE_DIR DIR_SEP; paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
ShaderCacheDir = UserDir + SHADERCACHE_DIR DIR_SEP; paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP;
ShadersDir = UserDir + SHADERS_DIR DIR_SEP; paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP;
StateSavesDir = UserDir + STATESAVES_DIR DIR_SEP; paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP;
ScreenShotsDir = UserDir + SCREENSHOTS_DIR DIR_SEP; paths[D_SCREENSHOTS_IDX] = paths[D_USER_IDX] + SCREENSHOTS_DIR DIR_SEP;
OpenCLDir = UserDir + OPENCL_DIR DIR_SEP; paths[D_OPENCL_IDX] = paths[D_USER_IDX] + OPENCL_DIR DIR_SEP;
HiresTexturesDir = UserDir + HIRES_TEXTURES_DIR DIR_SEP; paths[D_HIRESTEXTURES_IDX] = paths[D_USER_IDX] + HIRES_TEXTURES_DIR DIR_SEP;
DumpDir = UserDir + DUMP_DIR DIR_SEP; paths[D_DUMP_IDX] = paths[D_USER_IDX] + DUMP_DIR DIR_SEP;
DumpFramesDir = UserDir + DUMP_FRAMES_DIR DIR_SEP; paths[D_DUMPFRAMES_IDX] = paths[D_USER_IDX] + DUMP_FRAMES_DIR DIR_SEP;
DumpAudioDir = UserDir + DUMP_AUDIO_DIR DIR_SEP; paths[D_DUMPAUDIO_IDX] = paths[D_USER_IDX] + DUMP_AUDIO_DIR DIR_SEP;
DumpTexturesDir = UserDir + DUMP_TEXTURES_DIR DIR_SEP; paths[D_DUMPTEXTURES_IDX] = paths[D_USER_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
DumpDSPDir = UserDir + DUMP_DSP_DIR DIR_SEP; paths[D_DUMPDSP_IDX] = paths[D_USER_IDX] + DUMP_DSP_DIR DIR_SEP;
LogsDir = UserDir + LOGS_DIR DIR_SEP; paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
MailLogsDir = UserDir + MAIL_LOGS_DIR DIR_SEP; paths[D_MAILLOGS_IDX] = paths[D_USER_IDX] + MAIL_LOGS_DIR DIR_SEP;
WiiSYSCONFDir = UserDir + WII_SYSCONF_DIR DIR_SEP; paths[D_WIISYSCONF_IDX] = paths[D_USER_IDX] + WII_SYSCONF_DIR DIR_SEP;
DolphinConfig = ConfigDir + DOLPHIN_CONFIG; paths[F_DOLPHINCONFIG_IDX] = paths[D_CONFIG_IDX] + DOLPHIN_CONFIG;
DSPConfig = ConfigDir + DSP_CONFIG; paths[F_DSPCONFIG_IDX] = paths[D_CONFIG_IDX] + DSP_CONFIG;
DebuggerConfig = ConfigDir + DEBUGGER_CONFIG; paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
LoggerConfig = ConfigDir + LOGGER_CONFIG; paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
MainLog = LogsDir + MAIN_LOG; paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG;
WiiSYSCONF = WiiSYSCONFDir + WII_SYSCONF; paths[F_WIISYSCONF_IDX] = paths[D_WIISYSCONF_IDX] + WII_SYSCONF;
RamDump = DumpDir + RAM_DUMP; paths[F_RAMDUMP_IDX] = paths[D_DUMP_IDX] + RAM_DUMP;
ARamDump = DumpDir + ARAM_DUMP; paths[F_ARAMDUMP_IDX] = paths[D_DUMP_IDX] + ARAM_DUMP;
GCSRam = GCUserDir + GC_SRAM; paths[F_GCSRAM_IDX] = paths[D_GCUSER_IDX] + GC_SRAM;
}
switch (DirIDX)
{
case D_USER_IDX:
return UserDir;
case D_GCUSER_IDX:
return GCUserDir;
case D_WIIUSER_IDX:
return WiiUserDir;
case D_WIIROOT_IDX:
return WiiRootDir;
case D_CONFIG_IDX:
return ConfigDir;
case D_GAMECONFIG_IDX:
return GameConfigDir;
case D_MAPS_IDX:
return MapsDir;
case D_CACHE_IDX:
return CacheDir;
case D_SHADERCACHE_IDX:
return ShaderCacheDir;
case D_SHADERS_IDX:
return ShadersDir;
case D_STATESAVES_IDX:
return StateSavesDir;
case D_SCREENSHOTS_IDX:
return ScreenShotsDir;
case D_OPENCL_IDX:
return OpenCLDir;
case D_HIRESTEXTURES_IDX:
return HiresTexturesDir;
case D_DUMP_IDX:
return DumpDir;
case D_DUMPFRAMES_IDX:
return DumpFramesDir;
case D_DUMPAUDIO_IDX:
return DumpAudioDir;
case D_DUMPTEXTURES_IDX:
return DumpTexturesDir;
case D_DUMPDSP_IDX:
return DumpDSPDir;
case D_LOGS_IDX:
return LogsDir;
case D_MAILLOGS_IDX:
return MailLogsDir;
case D_WIISYSCONF_IDX:
return WiiSYSCONFDir;
case F_DOLPHINCONFIG_IDX:
return DolphinConfig;
case F_DSPCONFIG_IDX:
return DSPConfig;
case F_DEBUGGERCONFIG_IDX:
return DebuggerConfig;
case F_LOGGERCONFIG_IDX:
return LoggerConfig;
case F_MAINLOG_IDX:
return MainLog;
case F_WIISYSCONF_IDX:
return WiiSYSCONF;
case F_RAMDUMP_IDX:
return RamDump;
case F_ARAMDUMP_IDX:
return ARamDump;
case F_GCSRAM_IDX:
return GCSRam;
default:
return Default;
} }
return paths[DirIDX];
} }
bool WriteStringToFile(bool text_file, const std::string &str, const char *filename) bool WriteStringToFile(bool text_file, const std::string &str, const char *filename)

View File

@ -57,6 +57,7 @@ enum {
F_RAMDUMP_IDX, F_RAMDUMP_IDX,
F_ARAMDUMP_IDX, F_ARAMDUMP_IDX,
F_GCSRAM_IDX, F_GCSRAM_IDX,
NUM_PATH_INDICES
}; };
namespace File namespace File
@ -73,13 +74,13 @@ struct FSTEntry
}; };
// Returns true if file filename exists // Returns true if file filename exists
bool Exists(const char *filename); bool Exists(const std::string filename);
// Returns true if filename is a directory // Returns true if filename is a directory
bool IsDirectory(const char *filename); bool IsDirectory(const std::string filename);
// Returns the size of filename (64bit) // Returns the size of filename (64bit)
u64 GetSize(const char *filename); u64 GetSize(const std::string filename);
// Overloaded GetSize, accepts file descriptor // Overloaded GetSize, accepts file descriptor
u64 GetSize(const int fd); u64 GetSize(const int fd);
@ -88,46 +89,46 @@ u64 GetSize(const int fd);
u64 GetSize(FILE *f); u64 GetSize(FILE *f);
// Returns true if successful, or path already exists. // Returns true if successful, or path already exists.
bool CreateDir(const char *filename); bool CreateDir(const std::string filename);
// Creates the full path of fullPath returns true on success // Creates the full path of fullPath returns true on success
bool CreateFullPath(const char *fullPath); bool CreateFullPath(const std::string fullPath);
// Deletes a given filename, return true on success // Deletes a given filename, return true on success
// Doesn't supports deleting a directory // Doesn't supports deleting a directory
bool Delete(const char *filename); bool Delete(const std::string filename);
// Deletes a directory filename, returns true on success // Deletes a directory filename, returns true on success
bool DeleteDir(const char *filename); bool DeleteDir(const std::string filename);
// renames file srcFilename to destFilename, returns true on success // renames file srcFilename to destFilename, returns true on success
bool Rename(const char *srcFilename, const char *destFilename); bool Rename(const std::string srcFilename, const std::string destFilename);
// copies file srcFilename to destFilename, returns true on success // copies file srcFilename to destFilename, returns true on success
bool Copy(const char *srcFilename, const char *destFilename); bool Copy(const std::string srcFilename, const std::string destFilename);
// creates an empty file filename, returns true on success // creates an empty file filename, returns true on success
bool CreateEmptyFile(const char *filename); bool CreateEmptyFile(const std::string filename);
// Scans the directory tree gets, starting from _Directory and adds the // Scans the directory tree gets, starting from _Directory and adds the
// results into parentEntry. Returns the number of files+directories found // results into parentEntry. Returns the number of files+directories found
u32 ScanDirectoryTree(const char *directory, FSTEntry& parentEntry); u32 ScanDirectoryTree(const std::string directory, FSTEntry& parentEntry);
// deletes the given directory and anything under it. Returns true on success. // deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const char *directory); bool DeleteDirRecursively(const std::string directory);
// Returns the current directory // Returns the current directory
std::string GetCurrentDir(); std::string GetCurrentDir();
// Create directory and copy contents (does not overwrite existing files) // Create directory and copy contents (does not overwrite existing files)
void CopyDir(const char *source_path, const char *dest_path); void CopyDir(const std::string source_path, const std::string dest_path);
// Set the current directory to given directory // Set the current directory to given directory
bool SetCurrentDir(const char *directory); bool SetCurrentDir(const std::string directory);
// Returns a pointer to a string with a Dolphin data dir in the user's home // Returns a pointer to a string with a Dolphin data dir in the user's home
// directory. To be used in "multi-user" mode (that is, installed). // directory. To be used in "multi-user" mode (that is, installed).
std::string &GetUserPath(int DirIDX); std::string &GetUserPath(const unsigned int DirIDX);
// Returns the path to where the sys file are // Returns the path to where the sys file are
std::string GetSysDirectory(); std::string GetSysDirectory();

View File

@ -54,7 +54,7 @@ bool CheckTitleTMD(u64 _titleID)
{ {
std::string TitlePath; std::string TitlePath;
TitlePath = CreateTitleContentPath(_titleID) + "/title.tmd"; TitlePath = CreateTitleContentPath(_titleID) + "/title.tmd";
if (File::Exists(TitlePath.c_str())) if (File::Exists(TitlePath))
{ {
FILE* pTMDFile = fopen(TitlePath.c_str(), "rb"); FILE* pTMDFile = fopen(TitlePath.c_str(), "rb");
if(pTMDFile) if(pTMDFile)
@ -74,7 +74,7 @@ bool CheckTitleTMD(u64 _titleID)
bool CheckTitleTIK(u64 _titleID) bool CheckTitleTIK(u64 _titleID)
{ {
std::string TikPath = Common::CreateTicketFileName(_titleID); std::string TikPath = Common::CreateTicketFileName(_titleID);
if (File::Exists(TikPath.c_str())) if (File::Exists(TikPath))
{ {
FILE* pTIKFile = fopen(TikPath.c_str(), "rb"); FILE* pTIKFile = fopen(TikPath.c_str(), "rb");
if(pTIKFile) if(pTIKFile)
@ -112,7 +112,7 @@ void ReadReplacements(replace_v& replacements)
std::string filename(File::GetUserPath(D_WIIROOT_IDX)); std::string filename(File::GetUserPath(D_WIIROOT_IDX));
filename += replace_fname; filename += replace_fname;
if (!File::Exists(filename.c_str())) if (!File::Exists(filename))
CreateReplacementFile(filename); CreateReplacementFile(filename);
std::ifstream f(filename.c_str()); std::ifstream f(filename.c_str());

View File

@ -288,7 +288,7 @@ bool CBoot::BootUp()
// ELF // ELF
case SCoreStartupParameter::BOOT_ELF: case SCoreStartupParameter::BOOT_ELF:
{ {
if(!File::Exists(_StartupPara.m_strFilename.c_str())) if(!File::Exists(_StartupPara.m_strFilename))
{ {
PanicAlertT("The file you specified (%s) does not exist", PanicAlertT("The file you specified (%s) does not exist",
_StartupPara.m_strFilename.c_str()); _StartupPara.m_strFilename.c_str());

View File

@ -499,7 +499,8 @@ static inline std::string GenerateScreenshotName()
std::string gameId = SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID(); std::string gameId = SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID();
tempname = File::GetUserPath(D_SCREENSHOTS_IDX) + gameId + DIR_SEP_CHR; tempname = File::GetUserPath(D_SCREENSHOTS_IDX) + gameId + DIR_SEP_CHR;
if (!File::CreateFullPath(tempname.c_str())) { if (!File::CreateFullPath(tempname))
{
//fallback to old-style screenshots, without folder. //fallback to old-style screenshots, without folder.
tempname = File::GetUserPath(D_SCREENSHOTS_IDX); tempname = File::GetUserPath(D_SCREENSHOTS_IDX);
} }
@ -508,7 +509,7 @@ static inline std::string GenerateScreenshotName()
do do
name = StringFromFormat("%s-%d.png", tempname.c_str(), index++); name = StringFromFormat("%s-%d.png", tempname.c_str(), index++);
while (File::Exists(name.c_str())); while (File::Exists(name));
return name; return name;
} }

View File

@ -114,7 +114,7 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
bool bootDrive = cdio_is_cdrom(m_strFilename); bool bootDrive = cdio_is_cdrom(m_strFilename);
// Check if the file exist, we may have gotten it from a --elf command line // Check if the file exist, we may have gotten it from a --elf command line
// that gave an incorrect file name // that gave an incorrect file name
if (!bootDrive && !File::Exists(m_strFilename.c_str())) if (!bootDrive && !File::Exists(m_strFilename))
{ {
PanicAlertT("The specified file \"%s\" does not exist", m_strFilename.c_str()); PanicAlertT("The specified file \"%s\" does not exist", m_strFilename.c_str());
return false; return false;
@ -304,7 +304,7 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
m_strBootROM = File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + Region + DIR_SEP GC_IPL; m_strBootROM = File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + Region + DIR_SEP GC_IPL;
if (!bHLE_BS2) if (!bHLE_BS2)
{ {
if (!File::Exists(m_strBootROM.c_str())) if (!File::Exists(m_strBootROM))
{ {
WARN_LOG(BOOT, "bootrom file %s not found - using HLE.", m_strBootROM.c_str()); WARN_LOG(BOOT, "bootrom file %s not found - using HLE.", m_strBootROM.c_str());
bHLE_BS2 = true; bHLE_BS2 = true;
@ -340,7 +340,7 @@ void SCoreStartupParameter::CheckMemcardPath(std::string& memcardPath, std::stri
if (!hasregion) if (!hasregion)
{ {
// filename doesn't have region in the extension // filename doesn't have region in the extension
if (File::Exists(filename.c_str())) if (File::Exists(filename))
{ {
// If the old file exists we are polite and ask if we should copy it // If the old file exists we are polite and ask if we should copy it
std::string oldFilename = filename; std::string oldFilename = filename;
@ -352,7 +352,7 @@ void SCoreStartupParameter::CheckMemcardPath(std::string& memcardPath, std::stri
"Would you like to copy the old file to this new location?\n", "Would you like to copy the old file to this new location?\n",
isSlotA ? 'A':'B', isSlotA ? 'A':'B', filename.c_str())) isSlotA ? 'A':'B', isSlotA ? 'A':'B', filename.c_str()))
{ {
if (!File::Copy(oldFilename.c_str(), filename.c_str())) if (!File::Copy(oldFilename, filename))
PanicAlertT("Copy failed"); PanicAlertT("Copy failed");
} }
} }

View File

@ -109,9 +109,9 @@ void DSPLLE::Initialize(void *hWnd, bool bWii, bool bDSPThread)
std::string irom_file = File::GetSysDirectory() + GC_SYS_DIR DIR_SEP DSP_IROM; std::string irom_file = File::GetSysDirectory() + GC_SYS_DIR DIR_SEP DSP_IROM;
std::string coef_file = File::GetSysDirectory() + GC_SYS_DIR DIR_SEP DSP_COEF; std::string coef_file = File::GetSysDirectory() + GC_SYS_DIR DIR_SEP DSP_COEF;
if (!File::Exists(irom_file.c_str())) if (!File::Exists(irom_file))
irom_file = File::GetUserPath(D_GCUSER_IDX) + DIR_SEP DSP_IROM; irom_file = File::GetUserPath(D_GCUSER_IDX) + DIR_SEP DSP_IROM;
if (!File::Exists(coef_file.c_str())) if (!File::Exists(coef_file))
coef_file = File::GetUserPath(D_GCUSER_IDX) + DIR_SEP DSP_COEF; coef_file = File::GetUserPath(D_GCUSER_IDX) + DIR_SEP DSP_COEF;
bCanWork = DSPCore_Init(irom_file.c_str(), coef_file.c_str(), AudioCommon::UseJIT()); bCanWork = DSPCore_Init(irom_file.c_str(), coef_file.c_str(), AudioCommon::UseJIT());

View File

@ -111,8 +111,8 @@ void innerFlush(flushStruct* data)
{ {
std::string dir; std::string dir;
SplitPath(data->filename, &dir, 0, 0); SplitPath(data->filename, &dir, 0, 0);
if(!File::IsDirectory(dir.c_str())) if(!File::IsDirectory(dir))
File::CreateFullPath(dir.c_str()); File::CreateFullPath(dir);
pFile = fopen(data->filename.c_str(), "wb"); pFile = fopen(data->filename.c_str(), "wb");
} }

View File

@ -213,10 +213,10 @@ void CopySettingsFile(std::string& DeviceName)
// Check if the target dir exists, otherwise create it // Check if the target dir exists, otherwise create it
std::string TargetDir = Target.substr(0, Target.find_last_of(DIR_SEP)); std::string TargetDir = Target.substr(0, Target.find_last_of(DIR_SEP));
if (!File::IsDirectory(TargetDir.c_str())) if (!File::IsDirectory(TargetDir))
File::CreateFullPath(Target.c_str()); File::CreateFullPath(Target);
if (File::Copy(Source.c_str(), Target.c_str())) if (File::Copy(Source, Target))
{ {
INFO_LOG(WII_IPC_FILEIO, "FS: Copied %s to %s", Source.c_str(), Target.c_str()); INFO_LOG(WII_IPC_FILEIO, "FS: Copied %s to %s", Source.c_str(), Target.c_str());
} }

View File

@ -108,7 +108,7 @@ bool CWII_IPC_HLE_Device_FileIO::Open(u32 _CommandAddress, u32 _Mode)
// The file must exist before we can open it // The file must exist before we can open it
// It should be created by ISFS_CreateFile, not here // It should be created by ISFS_CreateFile, not here
if(File::Exists(m_Filename.c_str())) if(File::Exists(m_Filename))
{ {
INFO_LOG(WII_IPC_FILEIO, "FileIO: Open %s (%s)", m_Name.c_str(), Modes[_Mode]); INFO_LOG(WII_IPC_FILEIO, "FileIO: Open %s (%s)", m_Name.c_str(), Modes[_Mode]);
switch(_Mode) switch(_Mode)

View File

@ -445,11 +445,11 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress)
std::string TicketFilename = Common::CreateTicketFileName(TitleID); std::string TicketFilename = Common::CreateTicketFileName(TitleID);
u32 ViewCount = 0; u32 ViewCount = 0;
if (File::Exists(TicketFilename.c_str())) if (File::Exists(TicketFilename))
{ {
const u32 SIZE_OF_ONE_TICKET = 676; const u32 SIZE_OF_ONE_TICKET = 676;
u32 FileSize = (u32)(File::GetSize(TicketFilename.c_str())); u32 FileSize = (u32)(File::GetSize(TicketFilename));
_dbg_assert_msg_(WII_IPC_ES, (FileSize % SIZE_OF_ONE_TICKET) == 0, "IOCTL_ES_GETVIEWCNT ticket file size seems to be wrong"); _dbg_assert_msg_(WII_IPC_ES, (FileSize % SIZE_OF_ONE_TICKET) == 0, "IOCTL_ES_GETVIEWCNT ticket file size seems to be wrong");
ViewCount = FileSize / SIZE_OF_ONE_TICKET; ViewCount = FileSize / SIZE_OF_ONE_TICKET;
@ -481,7 +481,7 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress)
u32 maxViews = Memory::Read_U32(Buffer.InBuffer[1].m_Address); u32 maxViews = Memory::Read_U32(Buffer.InBuffer[1].m_Address);
std::string TicketFilename = Common::CreateTicketFileName(TitleID); std::string TicketFilename = Common::CreateTicketFileName(TitleID);
if (File::Exists(TicketFilename.c_str())) if (File::Exists(TicketFilename))
{ {
const u32 SIZE_OF_ONE_TICKET = 676; const u32 SIZE_OF_ONE_TICKET = 676;
FILE* pFile = fopen(TicketFilename.c_str(), "rb"); FILE* pFile = fopen(TicketFilename.c_str(), "rb");
@ -807,9 +807,9 @@ u32 CWII_IPC_HLE_Device_es::ES_DIVerify(u8* _pTMD, u32 _sz)
dataPath = Common::CreateTitleDataPath(tmdTitleID) + DIR_SEP; dataPath = Common::CreateTitleDataPath(tmdTitleID) + DIR_SEP;
tmdPath = contentPath + "/title.tmd"; tmdPath = contentPath + "/title.tmd";
File::CreateFullPath(contentPath.c_str()); File::CreateFullPath(contentPath);
File::CreateFullPath(dataPath.c_str()); File::CreateFullPath(dataPath);
if(!File::Exists(tmdPath.c_str())) if(!File::Exists(tmdPath))
{ {
FILE* _pTMDFile = fopen(tmdPath.c_str(), "wb"); FILE* _pTMDFile = fopen(tmdPath.c_str(), "wb");
if (_pTMDFile) if (_pTMDFile)

View File

@ -47,7 +47,7 @@ bool CWII_IPC_HLE_Device_fs::Open(u32 _CommandAddress, u32 _Mode)
// clear tmp folder // clear tmp folder
{ {
std::string Path = File::GetUserPath(D_WIIUSER_IDX) + "tmp"; std::string Path = File::GetUserPath(D_WIIUSER_IDX) + "tmp";
File::DeleteDirRecursively(Path.c_str()); File::DeleteDirRecursively(Path);
File::CreateDir(Path.c_str()); File::CreateDir(Path.c_str());
} }
@ -125,7 +125,7 @@ bool CWII_IPC_HLE_Device_fs::IOCtlV(u32 _CommandAddress)
INFO_LOG(WII_IPC_FILEIO, "FS: IOCTL_READ_DIR %s", DirName.c_str()); INFO_LOG(WII_IPC_FILEIO, "FS: IOCTL_READ_DIR %s", DirName.c_str());
if (!File::Exists(DirName.c_str())) if (!File::Exists(DirName))
{ {
WARN_LOG(WII_IPC_FILEIO, "FS: Search not found: %s", DirName.c_str()); WARN_LOG(WII_IPC_FILEIO, "FS: Search not found: %s", DirName.c_str());
ReturnValue = FS_DIRFILE_NOT_FOUND; ReturnValue = FS_DIRFILE_NOT_FOUND;
@ -133,7 +133,7 @@ bool CWII_IPC_HLE_Device_fs::IOCtlV(u32 _CommandAddress)
} }
// AyuanX: what if we return "found one successfully" if it is a file? // AyuanX: what if we return "found one successfully" if it is a file?
else if (!File::IsDirectory(DirName.c_str())) else if (!File::IsDirectory(DirName))
{ {
// It's not a directory, so error. // It's not a directory, so error.
// Games don't usually seem to care WHICH error they get, as long as it's <0 // Games don't usually seem to care WHICH error they get, as long as it's <0
@ -214,10 +214,10 @@ bool CWII_IPC_HLE_Device_fs::IOCtlV(u32 _CommandAddress)
u32 iNodes = 0; u32 iNodes = 0;
INFO_LOG(WII_IPC_FILEIO, "IOCTL_GETUSAGE %s", path.c_str()); INFO_LOG(WII_IPC_FILEIO, "IOCTL_GETUSAGE %s", path.c_str());
if (File::IsDirectory(path.c_str())) if (File::IsDirectory(path))
{ {
File::FSTEntry parentDir; File::FSTEntry parentDir;
iNodes = File::ScanDirectoryTree(path.c_str(), parentDir); iNodes = File::ScanDirectoryTree(path, parentDir);
u64 totalSize = ComputeTotalFileSize(parentDir); // "Real" size, to be converted to nand blocks u64 totalSize = ComputeTotalFileSize(parentDir); // "Real" size, to be converted to nand blocks
@ -315,8 +315,8 @@ s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _B
INFO_LOG(WII_IPC_FILEIO, "FS: CREATE_DIR %s, OwnerID %#x, GroupID %#x, Attributes %#x", DirName.c_str(), OwnerID, GroupID, Attribs); INFO_LOG(WII_IPC_FILEIO, "FS: CREATE_DIR %s, OwnerID %#x, GroupID %#x, Attributes %#x", DirName.c_str(), OwnerID, GroupID, Attribs);
DirName += DIR_SEP; DirName += DIR_SEP;
File::CreateFullPath(DirName.c_str()); File::CreateFullPath(DirName);
_dbg_assert_msg_(WII_IPC_FILEIO, File::IsDirectory(DirName.c_str()), "FS: CREATE_DIR %s failed", DirName.c_str()); _dbg_assert_msg_(WII_IPC_FILEIO, File::IsDirectory(DirName), "FS: CREATE_DIR %s failed", DirName.c_str());
return FS_RESULT_OK; return FS_RESULT_OK;
} }
@ -359,13 +359,13 @@ s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _B
u8 GroupPerm = 0x3; // read/write u8 GroupPerm = 0x3; // read/write
u8 OtherPerm = 0x3; // read/write u8 OtherPerm = 0x3; // read/write
u8 Attributes = 0x00; // no attributes u8 Attributes = 0x00; // no attributes
if (File::IsDirectory(Filename.c_str())) if (File::IsDirectory(Filename))
{ {
INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR Directory %s - all permission flags are set", Filename.c_str()); INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR Directory %s - all permission flags are set", Filename.c_str());
} }
else else
{ {
if (File::Exists(Filename.c_str())) if (File::Exists(Filename))
{ {
INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR %s - all permission flags are set", Filename.c_str()); INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR %s - all permission flags are set", Filename.c_str());
} }
@ -401,11 +401,11 @@ s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _B
std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64); std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64);
Offset += 64; Offset += 64;
if (File::Delete(Filename.c_str())) if (File::Delete(Filename))
{ {
INFO_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s", Filename.c_str()); INFO_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s", Filename.c_str());
} }
else if (File::DeleteDir(Filename.c_str())) else if (File::DeleteDir(Filename))
{ {
INFO_LOG(WII_IPC_FILEIO, "FS: DeleteDir %s", Filename.c_str()); INFO_LOG(WII_IPC_FILEIO, "FS: DeleteDir %s", Filename.c_str());
} }
@ -430,16 +430,16 @@ s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _B
Offset += 64; Offset += 64;
// try to make the basis directory // try to make the basis directory
File::CreateFullPath(FilenameRename.c_str()); File::CreateFullPath(FilenameRename);
// if there is already a file, delete it // if there is already a file, delete it
if (File::Exists(FilenameRename.c_str())) if (File::Exists(FilenameRename))
{ {
File::Delete(FilenameRename.c_str()); File::Delete(FilenameRename);
} }
// finally try to rename the file // finally try to rename the file
if (File::Rename(Filename.c_str(), FilenameRename.c_str())) if (File::Rename(Filename, FilenameRename))
{ {
INFO_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s", Filename.c_str(), FilenameRename.c_str()); INFO_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s", Filename.c_str(), FilenameRename.c_str());
} }
@ -475,15 +475,15 @@ s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _B
DEBUG_LOG(WII_IPC_FILEIO, " Attributes: 0x%02x", Attributes); DEBUG_LOG(WII_IPC_FILEIO, " Attributes: 0x%02x", Attributes);
// check if the file already exist // check if the file already exist
if (File::Exists(Filename.c_str())) if (File::Exists(Filename))
{ {
WARN_LOG(WII_IPC_FILEIO, "\tresult = FS_RESULT_EXISTS"); WARN_LOG(WII_IPC_FILEIO, "\tresult = FS_RESULT_EXISTS");
return FS_FILE_EXIST; return FS_FILE_EXIST;
} }
// create the file // create the file
File::CreateFullPath(Filename.c_str()); // just to be sure File::CreateFullPath(Filename); // just to be sure
bool Result = File::CreateEmptyFile(Filename.c_str()); bool Result = File::CreateEmptyFile(Filename);
if (!Result) if (!Result)
{ {
ERROR_LOG(WII_IPC_FILEIO, "CWII_IPC_HLE_Device_fs: couldn't create new file"); ERROR_LOG(WII_IPC_FILEIO, "CWII_IPC_HLE_Device_fs: couldn't create new file");

View File

@ -201,25 +201,21 @@ bool BeginRecordingInput(int controllers)
if(g_playMode != MODE_NONE || controllers == 0 || g_recordfd != NULL) if(g_playMode != MODE_NONE || controllers == 0 || g_recordfd != NULL)
return false; return false;
const char *filename = g_recordFile.c_str(); if(File::Exists(g_recordFile))
File::Delete(g_recordFile);
if(File::Exists(filename))
File::Delete(filename);
if (Core::isRunning()) if (Core::isRunning())
{ {
std::string tmpStateFilename = g_recordFile; const std::string stateFilename = g_recordFile + ".sav";
tmpStateFilename.append(".sav");
const char *stateFilename = tmpStateFilename.c_str();
if(File::Exists(stateFilename)) if(File::Exists(stateFilename))
File::Delete(stateFilename); File::Delete(stateFilename);
State_SaveAs(stateFilename); State_SaveAs(stateFilename.c_str());
g_bRecordingFromSaveState = true; g_bRecordingFromSaveState = true;
} }
g_recordfd = fopen(filename, "wb"); g_recordfd = fopen(g_recordFile.c_str(), "wb");
if(!g_recordfd) { if(!g_recordfd) {
PanicAlertT("Error opening file %s for recording", filename); PanicAlertT("Error opening file %s for recording", g_recordFile.c_str());
return false; return false;
} }
@ -360,8 +356,8 @@ bool PlayInput(const char *filename)
DTMHeader header; DTMHeader header;
File::Delete(g_recordFile.c_str()); File::Delete(g_recordFile);
File::Copy(filename, g_recordFile.c_str()); File::Copy(filename, g_recordFile);
g_recordfd = fopen(g_recordFile.c_str(), "r+b"); g_recordfd = fopen(g_recordFile.c_str(), "r+b");
if(!g_recordfd) if(!g_recordfd)
@ -377,9 +373,8 @@ bool PlayInput(const char *filename)
// Load savestate (and skip to frame data) // Load savestate (and skip to frame data)
if(header.bFromSaveState) if(header.bFromSaveState)
{ {
std::string stateFilename = filename; const std::string stateFilename = std::string(filename) + ".sav";
stateFilename.append(".sav"); if(File::Exists(stateFilename))
if(File::Exists(stateFilename.c_str()))
Core::SetStateFileName(stateFilename); Core::SetStateFileName(stateFilename);
g_bRecordingFromSaveState = true; g_bRecordingFromSaveState = true;
} }
@ -445,8 +440,8 @@ void LoadInput(const char *filename)
if (g_recordfd) if (g_recordfd)
fclose(g_recordfd); fclose(g_recordfd);
File::Delete(g_recordFile.c_str()); File::Delete(g_recordFile);
File::Copy(filename, g_recordFile.c_str()); File::Copy(filename, g_recordFile);
g_recordfd = fopen(g_recordFile.c_str(), "r+b"); g_recordfd = fopen(g_recordFile.c_str(), "r+b");
fseeko(g_recordfd, 0, SEEK_END); fseeko(g_recordfd, 0, SEEK_END);
@ -569,8 +564,8 @@ void EndPlayInput(bool cont)
// if playback ends before the end of the file. // if playback ends before the end of the file.
SaveRecording(g_tmpRecordFile.c_str()); SaveRecording(g_tmpRecordFile.c_str());
fclose(g_recordfd); fclose(g_recordfd);
File::Delete(g_recordFile.c_str()); File::Delete(g_recordFile);
File::Copy(g_tmpRecordFile.c_str(), g_recordFile.c_str()); File::Copy(g_tmpRecordFile, g_recordFile);
g_recordfd = fopen(g_recordFile.c_str(), "r+b"); g_recordfd = fopen(g_recordFile.c_str(), "r+b");
fseeko(g_recordfd, 0, SEEK_END); fseeko(g_recordfd, 0, SEEK_END);
g_playMode = MODE_RECORDING; g_playMode = MODE_RECORDING;
@ -624,7 +619,7 @@ void SaveRecording(const char *filename)
bool success = false; bool success = false;
fclose(g_recordfd); fclose(g_recordfd);
File::Delete(filename); File::Delete(filename);
success = File::Copy(g_recordFile.c_str(), filename); success = File::Copy(g_recordFile, filename);
if (success && g_bRecordingFromSaveState) if (success && g_bRecordingFromSaveState)
{ {
@ -632,7 +627,7 @@ void SaveRecording(const char *filename)
tmpStateFilename.append(".sav"); tmpStateFilename.append(".sav");
std::string stateFilename = filename; std::string stateFilename = filename;
stateFilename.append(".sav"); stateFilename.append(".sav");
success = File::Copy(tmpStateFilename.c_str(), stateFilename.c_str()); success = File::Copy(tmpStateFilename, stateFilename);
} }
if (success /* && !g_bReadOnly*/) if (success /* && !g_bReadOnly*/)

View File

@ -86,7 +86,7 @@ void LoadPatchSection(const char *section, std::vector<Patch> &patches, IniFile
std::string::size_type loc = line.find_first_of('=', 0); std::string::size_type loc = line.find_first_of('=', 0);
if (loc != std::string::npos) if (loc != std::string::npos)
line.at(loc) = ':'; line[loc] = ':';
std::vector<std::string> items; std::vector<std::string> items;
SplitString(line, ':', items); SplitString(line, ':', items);

View File

@ -179,12 +179,12 @@ void CompressAndDumpState(saveStruct* saveArg)
Common::SetCurrentThreadName("SaveState thread"); Common::SetCurrentThreadName("SaveState thread");
// Moving to last overwritten save-state // Moving to last overwritten save-state
if (File::Exists(cur_filename.c_str())) if (File::Exists(cur_filename))
{ {
if (File::Exists((File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav").c_str())) if (File::Exists(File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav"))
File::Delete((File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav").c_str()); File::Delete((File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav"));
if (!File::Rename(cur_filename.c_str(), (File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav").c_str())) if (!File::Rename(cur_filename, File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav"))
Core::DisplayMessage("Failed to move previous state to state undo backup", 1000); Core::DisplayMessage("Failed to move previous state to state undo backup", 1000);
} }
@ -388,8 +388,8 @@ void LoadStateCallback(u64 userdata, int cyclesLate)
delete[] buffer; delete[] buffer;
if (File::Exists(StringFromFormat("%s.dtm", cur_filename.c_str()).c_str())) if (File::Exists(cur_filename + ".dtm"))
Frame::LoadInput(StringFromFormat("%s.dtm", cur_filename.c_str()).c_str()); Frame::LoadInput((cur_filename + ".dtm").c_str());
else if (!Frame::IsRecordingInputFromSaveState()) else if (!Frame::IsRecordingInputFromSaveState())
Frame::EndPlayInput(false); Frame::EndPlayInput(false);

View File

@ -157,11 +157,11 @@ CNANDContentLoader::CNANDContentLoader(const std::string& _rName)
, m_IosVersion(0x09) , m_IosVersion(0x09)
, m_BootIndex(-1) , m_BootIndex(-1)
{ {
if (File::IsDirectory(_rName.c_str())) if (File::IsDirectory(_rName))
{ {
m_Valid = CreateFromDirectory(_rName); m_Valid = CreateFromDirectory(_rName);
} }
else if (File::Exists(_rName.c_str())) else if (File::Exists(_rName))
{ {
m_Valid = CreateFromWAD(_rName); m_Valid = CreateFromWAD(_rName);
} }
@ -210,7 +210,7 @@ bool CNANDContentLoader::CreateFromDirectory(const std::string& _rPath)
TMDFileName.c_str()); TMDFileName.c_str());
return false; return false;
} }
u64 Size = File::GetSize(TMDFileName.c_str()); u64 Size = File::GetSize(TMDFileName);
u8* pTMD = new u8[(u32)Size]; u8* pTMD = new u8[(u32)Size];
fread(pTMD, (size_t)Size, 1, pTMDFile); fread(pTMD, (size_t)Size, 1, pTMDFile);
fclose(pTMDFile); fclose(pTMDFile);

View File

@ -92,7 +92,7 @@ CVolumeDirectory::~CVolumeDirectory()
bool CVolumeDirectory::IsValidDirectory(const std::string& _rDirectory) bool CVolumeDirectory::IsValidDirectory(const std::string& _rDirectory)
{ {
std::string directoryName = ExtractDirectoryName(_rDirectory); std::string directoryName = ExtractDirectoryName(_rDirectory);
return File::IsDirectory(directoryName.c_str()); return File::IsDirectory(directoryName);
} }
bool CVolumeDirectory::RAWRead( u64 _Offset, u64 _Length, u8* _pBuffer ) const bool CVolumeDirectory::RAWRead( u64 _Offset, u64 _Length, u8* _pBuffer ) const
@ -513,7 +513,7 @@ static u32 ComputeNameSize(const File::FSTEntry& parentEntry)
u32 CVolumeDirectory::AddDirectoryEntries(const std::string& _Directory, File::FSTEntry& parentEntry) u32 CVolumeDirectory::AddDirectoryEntries(const std::string& _Directory, File::FSTEntry& parentEntry)
{ {
u32 foundEntries = ScanDirectoryTree(_Directory.c_str(), parentEntry); u32 foundEntries = ScanDirectoryTree(_Directory, parentEntry);
m_totalNameSize += ComputeNameSize(parentEntry); m_totalNameSize += ComputeNameSize(parentEntry);
return foundEntries; return foundEntries;
} }

View File

@ -201,7 +201,7 @@ void CCodeWindow::OnProfilerMenu(wxCommandEvent& event)
if (jit != NULL) if (jit != NULL)
{ {
std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt"; std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt";
File::CreateFullPath(filename.c_str()); File::CreateFullPath(filename);
Profiler::WriteProfileResults(filename.c_str()); Profiler::WriteProfileResults(filename.c_str());
wxFileType* filetype = NULL; wxFileType* filetype = NULL;
@ -254,7 +254,7 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event)
break; break;
} }
case IDM_LOADMAPFILE: case IDM_LOADMAPFILE:
if (!File::Exists(mapfile.c_str())) if (!File::Exists(mapfile))
{ {
g_symbolDB.Clear(); g_symbolDB.Clear();
PPCAnalyst::FindFunctions(0x81300000, 0x81800000, &g_symbolDB); PPCAnalyst::FindFunctions(0x81300000, 0x81800000, &g_symbolDB);

View File

@ -255,7 +255,7 @@ void GFXDebuggerPanel::OnDumpButton(wxCommandEvent& event)
{ {
std::string dump_path = File::GetUserPath(D_DUMP_IDX) + "Debug/" + std::string dump_path = File::GetUserPath(D_DUMP_IDX) + "Debug/" +
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID + "/"; SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID + "/";
if (!File::CreateFullPath(dump_path.c_str())) if (!File::CreateFullPath(dump_path))
return; return;
switch (m_pDumpList->GetSelection()) switch (m_pDumpList->GetSelection())

View File

@ -677,7 +677,7 @@ void CFrame::DoOpen(bool Boot)
{ {
PanicAlertT("Current dir changed from %s to %s after wxFileSelector!", PanicAlertT("Current dir changed from %s to %s after wxFileSelector!",
currentDir.c_str(), currentDir2.c_str()); currentDir.c_str(), currentDir2.c_str());
File::SetCurrentDir(currentDir.c_str()); File::SetCurrentDir(currentDir);
} }
if (path.IsEmpty()) if (path.IsEmpty())
@ -1641,7 +1641,7 @@ void CFrame::GameListChanged(wxCommandEvent& event)
for (u32 i = 0; i < rFilenames.size(); i++) for (u32 i = 0; i < rFilenames.size(); i++)
{ {
File::Delete(rFilenames[i].c_str()); File::Delete(rFilenames[i]);
} }
break; break;
} }

View File

@ -544,7 +544,7 @@ void CGameListCtrl::ScanForISOs()
for (u32 i = 0; i < Directories.size(); i++) for (u32 i = 0; i < Directories.size(); i++)
{ {
File::FSTEntry FST_Temp; File::FSTEntry FST_Temp;
File::ScanDirectoryTree(Directories[i].c_str(), FST_Temp); File::ScanDirectoryTree(Directories[i], FST_Temp);
for (u32 j = 0; j < FST_Temp.children.size(); j++) for (u32 j = 0; j < FST_Temp.children.size(); j++)
{ {
if (FST_Temp.children[j].isDirectory) if (FST_Temp.children[j].isDirectory)
@ -1133,7 +1133,7 @@ void CGameListCtrl::OnDeleteGCM(wxCommandEvent& WXUNUSED (event))
if (wxMessageBox(_("Are you sure you want to delete this file? It will be gone forever!"), if (wxMessageBox(_("Are you sure you want to delete this file? It will be gone forever!"),
wxMessageBoxCaptionStr, wxYES_NO | wxICON_EXCLAMATION) == wxYES) wxMessageBoxCaptionStr, wxYES_NO | wxICON_EXCLAMATION) == wxYES)
{ {
File::Delete(iso->GetFileName().c_str()); File::Delete(iso->GetFileName());
Update(); Update();
} }
} }
@ -1147,7 +1147,7 @@ void CGameListCtrl::OnDeleteGCM(wxCommandEvent& WXUNUSED (event))
for (int i = 0; i < selected; i++) for (int i = 0; i < selected; i++)
{ {
const GameListItem *iso = GetSelectedISO(); const GameListItem *iso = GetSelectedISO();
File::Delete(iso->GetFileName().c_str()); File::Delete(iso->GetFileName());
} }
Update(); Update();
} }

View File

@ -78,7 +78,7 @@ GameListItem::GameListItem(const std::string& _rFileName)
m_Description[i] = "No Description"; m_Description[i] = "No Description";
} }
m_Country = pVolume->GetCountry(); m_Country = pVolume->GetCountry();
m_FileSize = File::GetSize(_rFileName.c_str()); m_FileSize = File::GetSize(_rFileName);
m_VolumeSize = pVolume->GetSize(); m_VolumeSize = pVolume->GetSize();
m_UniqueID = pVolume->GetUniqueID(); m_UniqueID = pVolume->GetUniqueID();
@ -153,9 +153,9 @@ bool GameListItem::LoadFromCache()
void GameListItem::SaveToCache() void GameListItem::SaveToCache()
{ {
if (!File::IsDirectory(File::GetUserPath(D_CACHE_IDX).c_str())) if (!File::IsDirectory(File::GetUserPath(D_CACHE_IDX)))
{ {
File::CreateDir(File::GetUserPath(D_CACHE_IDX).c_str()); File::CreateDir(File::GetUserPath(D_CACHE_IDX));
} }
CChunkFileReader::Save<GameListItem>(CreateCacheFilename(), CACHE_REVISION, *this); CChunkFileReader::Save<GameListItem>(CreateCacheFilename(), CACHE_REVISION, *this);
@ -188,7 +188,7 @@ std::string GameListItem::CreateCacheFilename()
// Append hash to prevent ISO name-clashing in different folders. // Append hash to prevent ISO name-clashing in different folders.
Filename.append(StringFromFormat("%s_%x_%llx.cache", Filename.append(StringFromFormat("%s_%x_%llx.cache",
extension.c_str(), HashFletcher((const u8 *)LegalPathname.c_str(), LegalPathname.size()), extension.c_str(), HashFletcher((const u8 *)LegalPathname.c_str(), LegalPathname.size()),
File::GetSize(m_FileName.c_str()))); File::GetSize(m_FileName)));
std::string fullname(File::GetUserPath(D_CACHE_IDX)); std::string fullname(File::GetUserPath(D_CACHE_IDX));
fullname += Filename; fullname += Filename;

View File

@ -591,7 +591,7 @@ void GamepadPage::LoadProfile(wxCommandEvent&)
std::string fname; std::string fname;
GamepadPage::GetProfilePath(fname); GamepadPage::GetProfilePath(fname);
if (false == File::Exists(fname.c_str())) if (false == File::Exists(fname))
return; return;
IniFile inifile; IniFile inifile;
@ -609,7 +609,7 @@ void GamepadPage::SaveProfile(wxCommandEvent&)
{ {
std::string fname; std::string fname;
GamepadPage::GetProfilePath(fname); GamepadPage::GetProfilePath(fname);
File::CreateFullPath(fname.c_str()); File::CreateFullPath(fname);
if (false == fname.empty()) if (false == fname.empty())
{ {

View File

@ -202,7 +202,7 @@ bool DolphinApp::OnInit()
#ifdef _WIN32 #ifdef _WIN32
// Keep the user config dir free unless user wants to save the working dir // Keep the user config dir free unless user wants to save the working dir
if (!File::Exists((File::GetUserPath(D_CONFIG_IDX) + "portable").c_str())) if (!File::Exists(File::GetUserPath(D_CONFIG_IDX) + "portable"))
{ {
char tmp[1024]; char tmp[1024];
sprintf(tmp, "%s/.dolphin%swd", (const char*)wxStandardPaths::Get().GetUserConfigDir().mb_str(), sprintf(tmp, "%s/.dolphin%swd", (const char*)wxStandardPaths::Get().GetUserConfigDir().mb_str(),
@ -263,35 +263,35 @@ bool DolphinApp::OnInit()
#else #else
//create all necessary directories in user directory //create all necessary directories in user directory
//TODO : detect the revision and upgrade where necessary //TODO : detect the revision and upgrade where necessary
File::CopyDir(std::string(SHARED_USER_DIR CONFIG_DIR DIR_SEP).c_str(), File::CopyDir(std::string(SHARED_USER_DIR CONFIG_DIR DIR_SEP),
File::GetUserPath(D_CONFIG_IDX).c_str()); File::GetUserPath(D_CONFIG_IDX));
File::CopyDir(std::string(SHARED_USER_DIR GAMECONFIG_DIR DIR_SEP).c_str(), File::CopyDir(std::string(SHARED_USER_DIR GAMECONFIG_DIR DIR_SEP),
File::GetUserPath(D_GAMECONFIG_IDX).c_str()); File::GetUserPath(D_GAMECONFIG_IDX));
File::CopyDir(std::string(SHARED_USER_DIR MAPS_DIR DIR_SEP).c_str(), File::CopyDir(std::string(SHARED_USER_DIR MAPS_DIR DIR_SEP),
File::GetUserPath(D_MAPS_IDX).c_str()); File::GetUserPath(D_MAPS_IDX));
File::CopyDir(std::string(SHARED_USER_DIR SHADERS_DIR DIR_SEP).c_str(), File::CopyDir(std::string(SHARED_USER_DIR SHADERS_DIR DIR_SEP),
File::GetUserPath(D_SHADERS_IDX).c_str()); File::GetUserPath(D_SHADERS_IDX));
File::CopyDir(std::string(SHARED_USER_DIR WII_USER_DIR DIR_SEP).c_str(), File::CopyDir(std::string(SHARED_USER_DIR WII_USER_DIR DIR_SEP),
File::GetUserPath(D_WIIUSER_IDX).c_str()); File::GetUserPath(D_WIIUSER_IDX));
File::CopyDir(std::string(SHARED_USER_DIR OPENCL_DIR DIR_SEP).c_str(), File::CopyDir(std::string(SHARED_USER_DIR OPENCL_DIR DIR_SEP),
File::GetUserPath(D_OPENCL_IDX).c_str()); File::GetUserPath(D_OPENCL_IDX));
if (!File::Exists(File::GetUserPath(D_GCUSER_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_GCUSER_IDX)))
File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX).c_str()); File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX));
if (!File::Exists(File::GetUserPath(D_CACHE_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_CACHE_IDX)))
File::CreateFullPath(File::GetUserPath(D_CACHE_IDX).c_str()); File::CreateFullPath(File::GetUserPath(D_CACHE_IDX));
if (!File::Exists(File::GetUserPath(D_DUMPDSP_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_DUMPDSP_IDX)))
File::CreateFullPath(File::GetUserPath(D_DUMPDSP_IDX).c_str()); File::CreateFullPath(File::GetUserPath(D_DUMPDSP_IDX));
if (!File::Exists(File::GetUserPath(D_DUMPTEXTURES_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_DUMPTEXTURES_IDX)))
File::CreateFullPath(File::GetUserPath(D_DUMPTEXTURES_IDX).c_str()); File::CreateFullPath(File::GetUserPath(D_DUMPTEXTURES_IDX));
if (!File::Exists(File::GetUserPath(D_HIRESTEXTURES_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_HIRESTEXTURES_IDX)))
File::CreateFullPath(File::GetUserPath(D_HIRESTEXTURES_IDX).c_str()); File::CreateFullPath(File::GetUserPath(D_HIRESTEXTURES_IDX));
if (!File::Exists(File::GetUserPath(D_SCREENSHOTS_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_SCREENSHOTS_IDX)))
File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX).c_str()); File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX));
if (!File::Exists(File::GetUserPath(D_STATESAVES_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_STATESAVES_IDX)))
File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX).c_str()); File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX));
if (!File::Exists(File::GetUserPath(D_MAILLOGS_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_MAILLOGS_IDX)))
File::CreateFullPath(File::GetUserPath(D_MAILLOGS_IDX).c_str()); File::CreateFullPath(File::GetUserPath(D_MAILLOGS_IDX));
#endif #endif
LogManager::Init(); LogManager::Init();
@ -374,14 +374,13 @@ void DolphinApp::AfterInit(wxTimerEvent& WXUNUSED(event))
if (main_frame->g_pCodeWindow->AutomaticStart()) if (main_frame->g_pCodeWindow->AutomaticStart())
{ {
if(!SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDefaultGCM.empty() if(!SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDefaultGCM.empty()
&& File::Exists(SConfig::GetInstance().m_LocalCoreStartupParameter. && File::Exists(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDefaultGCM))
m_strDefaultGCM.c_str()))
{ {
main_frame->BootGame(SConfig::GetInstance().m_LocalCoreStartupParameter. main_frame->BootGame(SConfig::GetInstance().m_LocalCoreStartupParameter.
m_strDefaultGCM); m_strDefaultGCM);
} }
else if(!SConfig::GetInstance().m_LastFilename.empty() else if(!SConfig::GetInstance().m_LastFilename.empty()
&& File::Exists(SConfig::GetInstance().m_LastFilename.c_str())) && File::Exists(SConfig::GetInstance().m_LastFilename))
{ {
main_frame->BootGame(SConfig::GetInstance().m_LastFilename); main_frame->BootGame(SConfig::GetInstance().m_LastFilename);
} }
@ -394,7 +393,7 @@ void DolphinApp::InitLanguageSupport()
unsigned int language = 0; unsigned int language = 0;
IniFile ini; IniFile ini;
ini.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX).c_str()); ini.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX));
ini.Get("Interface", "Language", &language, wxLANGUAGE_DEFAULT); ini.Get("Interface", "Language", &language, wxLANGUAGE_DEFAULT);
// Load language if possible, fall back to system default otherwise // Load language if possible, fall back to system default otherwise

View File

@ -569,7 +569,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
{ {
if (!CopyDeleteSwitch(memoryCard[slot]->ExportGci(index, fileName.mb_str(), NULL), -1)) if (!CopyDeleteSwitch(memoryCard[slot]->ExportGci(index, fileName.mb_str(), NULL), -1))
{ {
File::Delete(fileName.mb_str()); File::Delete(std::string(fileName.mb_str()));
} }
} }
} }
@ -582,7 +582,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
mpath = m_MemcardPath[slot]->GetPath().mb_str(); mpath = m_MemcardPath[slot]->GetPath().mb_str();
SplitPath(mpath, &path1, &path2, NULL); SplitPath(mpath, &path1, &path2, NULL);
path1 += path2; path1 += path2;
File::CreateDir(path1.c_str()); File::CreateDir(path1);
if(PanicYesNoT("Warning: This will overwrite any existing saves that are in the folder:\n" if(PanicYesNoT("Warning: This will overwrite any existing saves that are in the folder:\n"
"%s\nand have the same name as a file on your memcard\nContinue?", path1.c_str())) "%s\nand have the same name as a file on your memcard\nContinue?", path1.c_str()))
for (int i = 0; i < DIRLEN; i++) for (int i = 0; i < DIRLEN; i++)

View File

@ -350,15 +350,15 @@ void CWiiSaveCrypted::ExportWiiSaveFiles()
std::string __name, __ext; std::string __name, __ext;
memset(&tmpFileHDR, 0, FILE_HDR_SZ); memset(&tmpFileHDR, 0, FILE_HDR_SZ);
_fileSize = File::GetSize(FilesList.at(i).c_str()); _fileSize = File::GetSize(FilesList[i]);
_roundedfileSize = ROUND_UP(_fileSize, BLOCK_SZ); _roundedfileSize = ROUND_UP(_fileSize, BLOCK_SZ);
tmpFileHDR.magic = Common::swap32(FILE_HDR_MAGIC); tmpFileHDR.magic = Common::swap32(FILE_HDR_MAGIC);
tmpFileHDR.size = Common::swap32(_fileSize); tmpFileHDR.size = Common::swap32(_fileSize);
tmpFileHDR.Permissions = 0x3C; tmpFileHDR.Permissions = 0x3C;
tmpFileHDR.type = File::IsDirectory(FilesList.at(i).c_str()) ? 2 : 1; tmpFileHDR.type = File::IsDirectory(FilesList[i]) ? 2 : 1;
SplitPath(FilesList.at(i), NULL, &__name, &__ext); SplitPath(FilesList[i], NULL, &__name, &__ext);
__name += __ext; __name += __ext;
@ -392,14 +392,14 @@ void CWiiSaveCrypted::ExportWiiSaveFiles()
{ {
if (_fileSize == 0) if (_fileSize == 0)
{ {
PanicAlertT("%s is a 0 byte file", FilesList.at(i).c_str()); PanicAlertT("%s is a 0 byte file", FilesList[i].c_str());
b_valid = false; b_valid = false;
return; return;
} }
fpRawSaveFile = fopen(FilesList.at(i).c_str(), "rb"); fpRawSaveFile = fopen(FilesList[i].c_str(), "rb");
if (!fpRawSaveFile) if (!fpRawSaveFile)
{ {
PanicAlertT("%s failed to open", FilesList.at(i).c_str()); PanicAlertT("%s failed to open", FilesList[i].c_str());
b_valid = false; b_valid = false;
} }
__data = new u8[_roundedfileSize]; __data = new u8[_roundedfileSize];
@ -407,7 +407,7 @@ void CWiiSaveCrypted::ExportWiiSaveFiles()
memset(__data, 0, _roundedfileSize); memset(__data, 0, _roundedfileSize);
if (fread(__data, _fileSize, 1, fpRawSaveFile) != 1) if (fread(__data, _fileSize, 1, fpRawSaveFile) != 1)
{ {
PanicAlertT("failed to read data from file: %s", FilesList.at(i).c_str()); PanicAlertT("failed to read data from file: %s", FilesList[i].c_str());
b_valid = false; b_valid = false;
} }
fclose(fpRawSaveFile); fclose(fpRawSaveFile);
@ -564,10 +564,10 @@ void CWiiSaveCrypted::ScanForFiles(std::string savDir, std::vector<std::string>&
Directories.push_back(savDir); Directories.push_back(savDir);
for (u32 i = 0; i < Directories.size(); i++) for (u32 i = 0; i < Directories.size(); i++)
{ {
if (i) FileList.push_back(Directories.at(i));//add dir to fst if (i) FileList.push_back(Directories[i]);//add dir to fst
File::FSTEntry FST_Temp; File::FSTEntry FST_Temp;
File::ScanDirectoryTree(Directories.at(i).c_str(), FST_Temp); File::ScanDirectoryTree(Directories[i], FST_Temp);
for (u32 j = 0; j < FST_Temp.children.size(); j++) for (u32 j = 0; j < FST_Temp.children.size(); j++)
{ {
if (strncmp(FST_Temp.children.at(j).virtualName.c_str(), "banner.bin", 10) != 0) if (strncmp(FST_Temp.children.at(j).virtualName.c_str(), "banner.bin", 10) != 0)

View File

@ -120,7 +120,7 @@ void GFXDebuggerBase::DumpPixelShader(const char* path)
} }
File::CreateEmptyFile(filename); File::CreateEmptyFile(filename);
File::WriteStringToFile(true, output.c_str(), filename); File::WriteStringToFile(true, output, filename);
} }
void GFXDebuggerBase::DumpVertexShader(const char* path) void GFXDebuggerBase::DumpVertexShader(const char* path)

View File

@ -45,7 +45,7 @@ void Init(const char *gameCode)
for (u32 i = 0; i < Directories.size(); i++) for (u32 i = 0; i < Directories.size(); i++)
{ {
File::FSTEntry FST_Temp; File::FSTEntry FST_Temp;
File::ScanDirectoryTree(Directories.at(i).c_str(), FST_Temp); File::ScanDirectoryTree(Directories[i], FST_Temp);
for (u32 j = 0; j < FST_Temp.children.size(); j++) for (u32 j = 0; j < FST_Temp.children.size(); j++)
{ {
if (FST_Temp.children.at(j).isDirectory) if (FST_Temp.children.at(j).isDirectory)
@ -53,7 +53,7 @@ void Init(const char *gameCode)
bool duplicate = false; bool duplicate = false;
for (u32 k = 0; k < Directories.size(); k++) for (u32 k = 0; k < Directories.size(); k++)
{ {
if (strcmp(Directories.at(k).c_str(), FST_Temp.children.at(j).physicalName.c_str()) == 0) if (strcmp(Directories[k].c_str(), FST_Temp.children.at(j).physicalName.c_str()) == 0)
{ {
duplicate = true; duplicate = true;
break; break;

View File

@ -399,7 +399,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID; SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID;
// make sure that the directory exists // make sure that the directory exists
if (false == File::Exists(szDir.c_str()) || false == File::IsDirectory(szDir.c_str())) if (false == File::Exists(szDir) || false == File::IsDirectory(szDir))
File::CreateDir(szDir.c_str()); File::CreateDir(szDir.c_str());
sprintf(szTemp, "%s/%s_%08x_%i.png", szDir.c_str(), sprintf(szTemp, "%s/%s_%08x_%i.png", szDir.c_str(),

View File

@ -280,7 +280,7 @@ int main(int argc, const char *argv[])
return 1; return 1;
} }
input_name = argv[i]; input_name = argv[i];
if (!File::Exists(input_name.c_str())) if (!File::Exists(input_name))
{ {
printf("ERROR: Input path does not exist.\n"); printf("ERROR: Input path does not exist.\n");
return 1; return 1;

View File

@ -325,7 +325,7 @@ void PixelShaderCache::Init()
Clear(); Clear();
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str()); File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str());
SETSTAT(stats.numPixelShadersCreated, 0); SETSTAT(stats.numPixelShadersCreated, 0);

View File

@ -163,7 +163,7 @@ void VertexShaderCache::Init()
for (k = 0;k < 64;k++) vs_constant_offset_table[C_POSTTRANSFORMMATRICES+k] = 696+4*k; for (k = 0;k < 64;k++) vs_constant_offset_table[C_POSTTRANSFORMMATRICES+k] = 696+4*k;
for (k = 0;k < 4;k++) vs_constant_offset_table[C_DEPTHPARAMS+k] = 952+4*k; for (k = 0;k < 4;k++) vs_constant_offset_table[C_DEPTHPARAMS+k] = 952+4*k;
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str()); File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str());
SETSTAT(stats.numVertexShadersCreated, 0); SETSTAT(stats.numVertexShadersCreated, 0);

View File

@ -269,7 +269,7 @@ void PixelShaderCache::Init()
Clear(); Clear();
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str()); File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str());
SETSTAT(stats.numPixelShadersCreated, 0); SETSTAT(stats.numPixelShadersCreated, 0);

View File

@ -140,7 +140,7 @@ void VertexShaderCache::Init()
Clear(); Clear();
delete [] vProg; delete [] vProg;
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX).c_str())) if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str()); File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str());
SETSTAT(stats.numVertexShadersCreated, 0); SETSTAT(stats.numVertexShadersCreated, 0);

View File

@ -108,10 +108,10 @@ std::string VideoBackend::GetName()
void GetShaders(std::vector<std::string> &shaders) void GetShaders(std::vector<std::string> &shaders)
{ {
shaders.clear(); shaders.clear();
if (File::IsDirectory(File::GetUserPath(D_SHADERS_IDX).c_str())) if (File::IsDirectory(File::GetUserPath(D_SHADERS_IDX)))
{ {
File::FSTEntry entry; File::FSTEntry entry;
File::ScanDirectoryTree(File::GetUserPath(D_SHADERS_IDX).c_str(), entry); File::ScanDirectoryTree(File::GetUserPath(D_SHADERS_IDX), entry);
for (u32 i = 0; i < entry.children.size(); i++) for (u32 i = 0; i < entry.children.size(); i++)
{ {
std::string name = entry.children[i].virtualName.c_str(); std::string name = entry.children[i].virtualName.c_str();