|
|
|
@ -88,7 +88,7 @@ bool IsDirectory(const std::string &filename)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s",
|
|
|
|
|
WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s",
|
|
|
|
|
filename.c_str(), GetLastErrorMsg());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -102,7 +102,7 @@ bool Delete(const std::string &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.
|
|
|
|
|
if (!Exists(filename))
|
|
|
|
|
{
|
|
|
|
@ -120,13 +120,13 @@ bool Delete(const std::string &filename)
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (!DeleteFile(Common::UTF8ToTStr(filename).c_str()))
|
|
|
|
|
{
|
|
|
|
|
WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s",
|
|
|
|
|
WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s",
|
|
|
|
|
filename.c_str(), GetLastErrorMsg());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
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.c_str(), GetLastErrorMsg());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -232,28 +232,28 @@ bool DeleteDir(const std::string &filename)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// renames file srcFilename to destFilename, returns true on success
|
|
|
|
|
// renames file srcFilename to destFilename, returns true on success
|
|
|
|
|
bool Rename(const std::string &srcFilename, const std::string &destFilename)
|
|
|
|
|
{
|
|
|
|
|
INFO_LOG(COMMON, "Rename: %s --> %s",
|
|
|
|
|
INFO_LOG(COMMON, "Rename: %s --> %s",
|
|
|
|
|
srcFilename.c_str(), destFilename.c_str());
|
|
|
|
|
if (rename(srcFilename.c_str(), destFilename.c_str()) == 0)
|
|
|
|
|
return true;
|
|
|
|
|
ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s",
|
|
|
|
|
ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s",
|
|
|
|
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// copies file srcFilename to destFilename, returns true on success
|
|
|
|
|
// copies file srcFilename to destFilename, returns true on success
|
|
|
|
|
bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
|
|
|
|
{
|
|
|
|
|
INFO_LOG(COMMON, "Copy: %s --> %s",
|
|
|
|
|
INFO_LOG(COMMON, "Copy: %s --> %s",
|
|
|
|
|
srcFilename.c_str(), destFilename.c_str());
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (CopyFile(Common::UTF8ToTStr(srcFilename).c_str(), Common::UTF8ToTStr(destFilename).c_str(), FALSE))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s",
|
|
|
|
|
ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s",
|
|
|
|
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
|
|
|
return false;
|
|
|
|
|
#else
|
|
|
|
@ -267,7 +267,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
|
|
|
|
FILE *input = fopen(srcFilename.c_str(), "rb");
|
|
|
|
|
if (!input)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s",
|
|
|
|
|
ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s",
|
|
|
|
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -277,7 +277,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
|
|
|
|
if (!output)
|
|
|
|
|
{
|
|
|
|
|
fclose(input);
|
|
|
|
|
ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s",
|
|
|
|
|
ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s",
|
|
|
|
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -291,8 +291,8 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
|
|
|
|
{
|
|
|
|
|
if (ferror(input) != 0)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(COMMON,
|
|
|
|
|
"Copy: failed reading from source, %s --> %s: %s",
|
|
|
|
|
ERROR_LOG(COMMON,
|
|
|
|
|
"Copy: failed reading from source, %s --> %s: %s",
|
|
|
|
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
|
|
|
goto bail;
|
|
|
|
|
}
|
|
|
|
@ -302,8 +302,8 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
|
|
|
|
int wnum = fwrite(buffer, sizeof(char), rnum, output);
|
|
|
|
|
if (wnum != rnum)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(COMMON,
|
|
|
|
|
"Copy: failed writing to output, %s --> %s: %s",
|
|
|
|
|
ERROR_LOG(COMMON,
|
|
|
|
|
"Copy: failed writing to output, %s --> %s: %s",
|
|
|
|
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
|
|
|
|
|
goto bail;
|
|
|
|
|
}
|
|
|
|
@ -335,7 +335,7 @@ u64 GetSize(const std::string &filename)
|
|
|
|
|
WARN_LOG(COMMON, "GetSize: failed %s: is a directory", filename.c_str());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct stat64 buf;
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (_tstat64(Common::UTF8ToTStr(filename).c_str(), &buf) == 0)
|
|
|
|
@ -384,10 +384,10 @@ u64 GetSize(FILE *f)
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// creates an empty file filename, returns true on success
|
|
|
|
|
// creates an empty file filename, returns true on success
|
|
|
|
|
bool CreateEmptyFile(const std::string &filename)
|
|
|
|
|
{
|
|
|
|
|
INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());
|
|
|
|
|
INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());
|
|
|
|
|
|
|
|
|
|
if (!FileUtil::IOFile(filename, "wb"))
|
|
|
|
|
{
|
|
|
|
@ -437,7 +437,7 @@ u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry)
|
|
|
|
|
#endif
|
|
|
|
|
// check for "." and ".."
|
|
|
|
|
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
|
|
|
|
|
((virtualName[0] == '.') && (virtualName[1] == '.') &&
|
|
|
|
|
((virtualName[0] == '.') && (virtualName[1] == '.') &&
|
|
|
|
|
(virtualName[2] == '\0')))
|
|
|
|
|
continue;
|
|
|
|
|
entry.virtualName = virtualName;
|
|
|
|
@ -452,14 +452,14 @@ u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry)
|
|
|
|
|
foundEntries += (u32)entry.size;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ // is a file
|
|
|
|
|
{ // is a file
|
|
|
|
|
entry.isDirectory = false;
|
|
|
|
|
entry.size = GetSize(entry.physicalName.c_str());
|
|
|
|
|
}
|
|
|
|
|
++foundEntries;
|
|
|
|
|
// Push into the tree
|
|
|
|
|
parentEntry.children.push_back(entry);
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
parentEntry.children.push_back(entry);
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
} while (FindNextFile(hFind, &ffd) != 0);
|
|
|
|
|
FindClose(hFind);
|
|
|
|
|
#else
|
|
|
|
@ -504,7 +504,7 @@ bool DeleteDirRecursively(const std::string &directory)
|
|
|
|
|
|
|
|
|
|
// check for "." and ".."
|
|
|
|
|
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
|
|
|
|
|
((virtualName[0] == '.') && (virtualName[1] == '.') &&
|
|
|
|
|
((virtualName[0] == '.') && (virtualName[1] == '.') &&
|
|
|
|
|
(virtualName[2] == '\0')))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
@ -540,7 +540,7 @@ bool DeleteDirRecursively(const std::string &directory)
|
|
|
|
|
closedir(dirp);
|
|
|
|
|
#endif
|
|
|
|
|
FileUtil::DeleteDir(directory);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -585,7 +585,7 @@ void CopyDir(const std::string &source_path, const std::string &dest_path)
|
|
|
|
|
std::string GetCurrentDir()
|
|
|
|
|
{
|
|
|
|
|
char *dir;
|
|
|
|
|
// Get the current working directory (getcwd uses malloc)
|
|
|
|
|
// Get the current working directory (getcwd uses malloc)
|
|
|
|
|
if (!(dir = __getcwd(NULL, 0))) {
|
|
|
|
|
|
|
|
|
|
ERROR_LOG(COMMON, "GetCurrentDirectory failed: %s",
|
|
|
|
@ -604,7 +604,7 @@ bool SetCurrentDir(const std::string &directory)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
|
std::string GetBundleDirectory()
|
|
|
|
|
std::string GetBundleDirectory()
|
|
|
|
|
{
|
|
|
|
|
CFURLRef BundleRef;
|
|
|
|
|
char AppBundlePath[MAXPATHLEN];
|
|
|
|
@ -666,8 +666,8 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
|
|
|
|
|
if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR))
|
|
|
|
|
paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
|
|
|
|
|
else
|
|
|
|
|
paths[D_USER_IDX] = std::string(getenv("HOME") ?
|
|
|
|
|
getenv("HOME") : getenv("PWD") ?
|
|
|
|
|
paths[D_USER_IDX] = std::string(getenv("HOME") ?
|
|
|
|
|
getenv("HOME") : getenv("PWD") ?
|
|
|
|
|
getenv("PWD") : "") + DIR_SEP EMU_DATA_DIR DIR_SEP;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -749,7 +749,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
|
|
|
|
|
paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return paths[DirIDX];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -762,7 +762,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
|
|
|
|
|
// if (!FileUtil::Exists(dir))
|
|
|
|
|
// dir = SHARED_USER_DIR THEMES_DIR "/" + theme_name + "/";
|
|
|
|
|
//#endif
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// return dir;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|