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