|
|
@ -118,7 +118,7 @@ bool IsDirectory(const std::string& filename) { |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
if (result < 0) { |
|
|
if (result < 0) { |
|
|
LOG_DEBUG(Common_Filesystem, "stat failed on %s: %s", filename.c_str(), GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_DEBUG(Common_Filesystem, "stat failed on {}: {}", filename, GetLastErrorMsg()); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -128,31 +128,29 @@ bool IsDirectory(const std::string& 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 std::string& filename) { |
|
|
bool Delete(const std::string& filename) { |
|
|
LOG_TRACE(Common_Filesystem, "file %s", filename.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_TRACE(Common_Filesystem, "file {}", filename); |
|
|
|
|
|
|
|
|
// 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)) { |
|
|
LOG_DEBUG(Common_Filesystem, "%s does not exist", filename.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_DEBUG(Common_Filesystem, "{} does not exist", filename); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// We can't delete a directory
|
|
|
// We can't delete a directory
|
|
|
if (IsDirectory(filename)) { |
|
|
if (IsDirectory(filename)) { |
|
|
LOG_ERROR(Common_Filesystem, "Failed: %s is a directory", filename.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "Failed: {} is a directory", filename); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
if (!DeleteFileW(Common::UTF8ToUTF16W(filename).c_str())) { |
|
|
if (!DeleteFileW(Common::UTF8ToUTF16W(filename).c_str())) { |
|
|
LOG_ERROR(Common_Filesystem, "DeleteFile failed on %s: %s", filename.c_str(), |
|
|
|
|
|
GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "DeleteFile failed on {}: {}", filename, GetLastErrorMsg()); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
#else
|
|
|
#else
|
|
|
if (unlink(filename.c_str()) == -1) { |
|
|
if (unlink(filename.c_str()) == -1) { |
|
|
LOG_ERROR(Common_Filesystem, "unlink failed on %s: %s", filename.c_str(), |
|
|
|
|
|
GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "unlink failed on {}: {}", filename, GetLastErrorMsg()); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
#endif
|
|
|
#endif
|
|
|
@ -162,16 +160,16 @@ bool Delete(const std::string& filename) { |
|
|
|
|
|
|
|
|
// Returns true if successful, or path already exists.
|
|
|
// Returns true if successful, or path already exists.
|
|
|
bool CreateDir(const std::string& path) { |
|
|
bool CreateDir(const std::string& path) { |
|
|
LOG_TRACE(Common_Filesystem, "directory %s", path.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_TRACE(Common_Filesystem, "directory {}", path); |
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
if (::CreateDirectoryW(Common::UTF8ToUTF16W(path).c_str(), nullptr)) |
|
|
if (::CreateDirectoryW(Common::UTF8ToUTF16W(path).c_str(), nullptr)) |
|
|
return true; |
|
|
return true; |
|
|
DWORD error = GetLastError(); |
|
|
DWORD error = GetLastError(); |
|
|
if (error == ERROR_ALREADY_EXISTS) { |
|
|
if (error == ERROR_ALREADY_EXISTS) { |
|
|
LOG_DEBUG(Common_Filesystem, "CreateDirectory failed on %s: already exists", path.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_DEBUG(Common_Filesystem, "CreateDirectory failed on {}: already exists", path); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
LOG_ERROR(Common_Filesystem, "CreateDirectory failed on %s: %i", path.c_str(), error); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "CreateDirectory failed on {}: {}", path, error); |
|
|
return false; |
|
|
return false; |
|
|
#else
|
|
|
#else
|
|
|
if (mkdir(path.c_str(), 0755) == 0) |
|
|
if (mkdir(path.c_str(), 0755) == 0) |
|
|
@ -180,11 +178,11 @@ bool CreateDir(const std::string& path) { |
|
|
int err = errno; |
|
|
int err = errno; |
|
|
|
|
|
|
|
|
if (err == EEXIST) { |
|
|
if (err == EEXIST) { |
|
|
LOG_DEBUG(Common_Filesystem, "mkdir failed on %s: already exists", path.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_DEBUG(Common_Filesystem, "mkdir failed on {}: already exists", path); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
LOG_ERROR(Common_Filesystem, "mkdir failed on %s: %s", path.c_str(), strerror(err)); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "mkdir failed on {}: {}", path, strerror(err)); |
|
|
return false; |
|
|
return false; |
|
|
#endif
|
|
|
#endif
|
|
|
} |
|
|
} |
|
|
@ -192,10 +190,10 @@ bool CreateDir(const std::string& path) { |
|
|
// Creates the full path of fullPath returns true on success
|
|
|
// Creates the full path of fullPath returns true on success
|
|
|
bool CreateFullPath(const std::string& fullPath) { |
|
|
bool CreateFullPath(const std::string& fullPath) { |
|
|
int panicCounter = 100; |
|
|
int panicCounter = 100; |
|
|
LOG_TRACE(Common_Filesystem, "path %s", fullPath.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_TRACE(Common_Filesystem, "path {}", fullPath); |
|
|
|
|
|
|
|
|
if (FileUtil::Exists(fullPath)) { |
|
|
if (FileUtil::Exists(fullPath)) { |
|
|
LOG_DEBUG(Common_Filesystem, "path exists %s", fullPath.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_DEBUG(Common_Filesystem, "path exists {}", fullPath); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -211,14 +209,14 @@ bool CreateFullPath(const std::string& fullPath) { |
|
|
// Include the '/' so the first call is CreateDir("/") rather than CreateDir("")
|
|
|
// Include the '/' so the first call is CreateDir("/") rather than CreateDir("")
|
|
|
std::string const subPath(fullPath.substr(0, position + 1)); |
|
|
std::string const subPath(fullPath.substr(0, position + 1)); |
|
|
if (!FileUtil::IsDirectory(subPath) && !FileUtil::CreateDir(subPath)) { |
|
|
if (!FileUtil::IsDirectory(subPath) && !FileUtil::CreateDir(subPath)) { |
|
|
LOG_ERROR(Common, "CreateFullPath: directory creation failed"); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common, "CreateFullPath: directory creation failed"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// A safety check
|
|
|
// A safety check
|
|
|
panicCounter--; |
|
|
panicCounter--; |
|
|
if (panicCounter <= 0) { |
|
|
if (panicCounter <= 0) { |
|
|
LOG_ERROR(Common, "CreateFullPath: directory structure is too deep"); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common, "CreateFullPath: directory structure is too deep"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
position++; |
|
|
position++; |
|
|
@ -227,11 +225,11 @@ bool CreateFullPath(const std::string& fullPath) { |
|
|
|
|
|
|
|
|
// Deletes a directory filename, returns true on success
|
|
|
// Deletes a directory filename, returns true on success
|
|
|
bool DeleteDir(const std::string& filename) { |
|
|
bool DeleteDir(const std::string& filename) { |
|
|
LOG_TRACE(Common_Filesystem, "directory %s", filename.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_TRACE(Common_Filesystem, "directory {}", filename); |
|
|
|
|
|
|
|
|
// check if a directory
|
|
|
// check if a directory
|
|
|
if (!FileUtil::IsDirectory(filename)) { |
|
|
if (!FileUtil::IsDirectory(filename)) { |
|
|
LOG_ERROR(Common_Filesystem, "Not a directory %s", filename.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "Not a directory {}", filename); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -242,14 +240,14 @@ bool DeleteDir(const std::string& filename) { |
|
|
if (rmdir(filename.c_str()) == 0) |
|
|
if (rmdir(filename.c_str()) == 0) |
|
|
return true; |
|
|
return true; |
|
|
#endif
|
|
|
#endif
|
|
|
LOG_ERROR(Common_Filesystem, "failed %s: %s", filename.c_str(), GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "failed {}: {}", 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 std::string& srcFilename, const std::string& destFilename) { |
|
|
bool Rename(const std::string& srcFilename, const std::string& destFilename) { |
|
|
LOG_TRACE(Common_Filesystem, "%s --> %s", srcFilename.c_str(), destFilename.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_TRACE(Common_Filesystem, "{} --> {}", srcFilename, destFilename); |
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
if (_wrename(Common::UTF8ToUTF16W(srcFilename).c_str(), |
|
|
if (_wrename(Common::UTF8ToUTF16W(srcFilename).c_str(), |
|
|
Common::UTF8ToUTF16W(destFilename).c_str()) == 0) |
|
|
Common::UTF8ToUTF16W(destFilename).c_str()) == 0) |
|
|
@ -258,20 +256,20 @@ bool Rename(const std::string& srcFilename, const std::string& destFilename) { |
|
|
if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) |
|
|
if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) |
|
|
return true; |
|
|
return true; |
|
|
#endif
|
|
|
#endif
|
|
|
LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", srcFilename.c_str(), destFilename.c_str(), |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "failed {} --> {}: {}", srcFilename, destFilename, |
|
|
GetLastErrorMsg()); |
|
|
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) { |
|
|
LOG_TRACE(Common_Filesystem, "%s --> %s", srcFilename.c_str(), destFilename.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_TRACE(Common_Filesystem, "{} --> {}", srcFilename, destFilename); |
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
if (CopyFileW(Common::UTF8ToUTF16W(srcFilename).c_str(), |
|
|
if (CopyFileW(Common::UTF8ToUTF16W(srcFilename).c_str(), |
|
|
Common::UTF8ToUTF16W(destFilename).c_str(), FALSE)) |
|
|
Common::UTF8ToUTF16W(destFilename).c_str(), FALSE)) |
|
|
return true; |
|
|
return true; |
|
|
|
|
|
|
|
|
LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", srcFilename.c_str(), destFilename.c_str(), |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "failed {} --> {}: {}", srcFilename, destFilename, |
|
|
GetLastErrorMsg()); |
|
|
GetLastErrorMsg()); |
|
|
return false; |
|
|
return false; |
|
|
#else
|
|
|
#else
|
|
|
@ -284,8 +282,8 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename) { |
|
|
// Open input file
|
|
|
// Open input file
|
|
|
FILE* input = fopen(srcFilename.c_str(), "rb"); |
|
|
FILE* input = fopen(srcFilename.c_str(), "rb"); |
|
|
if (!input) { |
|
|
if (!input) { |
|
|
LOG_ERROR(Common_Filesystem, "opening input failed %s --> %s: %s", srcFilename.c_str(), |
|
|
|
|
|
destFilename.c_str(), GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "opening input failed {} --> {}: {}", srcFilename, |
|
|
|
|
|
destFilename, GetLastErrorMsg()); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -293,8 +291,8 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename) { |
|
|
FILE* output = fopen(destFilename.c_str(), "wb"); |
|
|
FILE* output = fopen(destFilename.c_str(), "wb"); |
|
|
if (!output) { |
|
|
if (!output) { |
|
|
fclose(input); |
|
|
fclose(input); |
|
|
LOG_ERROR(Common_Filesystem, "opening output failed %s --> %s: %s", srcFilename.c_str(), |
|
|
|
|
|
destFilename.c_str(), GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "opening output failed {} --> {}: {}", srcFilename, |
|
|
|
|
|
destFilename, GetLastErrorMsg()); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -304,8 +302,8 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename) { |
|
|
size_t rnum = fread(buffer, sizeof(char), BSIZE, input); |
|
|
size_t rnum = fread(buffer, sizeof(char), BSIZE, input); |
|
|
if (rnum != BSIZE) { |
|
|
if (rnum != BSIZE) { |
|
|
if (ferror(input) != 0) { |
|
|
if (ferror(input) != 0) { |
|
|
LOG_ERROR(Common_Filesystem, "failed reading from source, %s --> %s: %s", |
|
|
|
|
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "failed reading from source, {} --> {}: {}", |
|
|
|
|
|
srcFilename, destFilename, GetLastErrorMsg()); |
|
|
goto bail; |
|
|
goto bail; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -313,8 +311,8 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename) { |
|
|
// write output
|
|
|
// write output
|
|
|
size_t wnum = fwrite(buffer, sizeof(char), rnum, output); |
|
|
size_t wnum = fwrite(buffer, sizeof(char), rnum, output); |
|
|
if (wnum != rnum) { |
|
|
if (wnum != rnum) { |
|
|
LOG_ERROR(Common_Filesystem, "failed writing to output, %s --> %s: %s", |
|
|
|
|
|
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "failed writing to output, {} --> {}: {}", srcFilename, |
|
|
|
|
|
destFilename, GetLastErrorMsg()); |
|
|
goto bail; |
|
|
goto bail; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -334,12 +332,12 @@ bail: |
|
|
// Returns the size of filename (64bit)
|
|
|
// Returns the size of filename (64bit)
|
|
|
u64 GetSize(const std::string& filename) { |
|
|
u64 GetSize(const std::string& filename) { |
|
|
if (!Exists(filename)) { |
|
|
if (!Exists(filename)) { |
|
|
LOG_ERROR(Common_Filesystem, "failed %s: No such file", filename.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "failed {}: No such file", filename); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (IsDirectory(filename)) { |
|
|
if (IsDirectory(filename)) { |
|
|
LOG_ERROR(Common_Filesystem, "failed %s: is a directory", filename.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "failed {}: is a directory", filename); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -350,11 +348,11 @@ u64 GetSize(const std::string& filename) { |
|
|
if (stat(filename.c_str(), &buf) == 0) |
|
|
if (stat(filename.c_str(), &buf) == 0) |
|
|
#endif
|
|
|
#endif
|
|
|
{ |
|
|
{ |
|
|
LOG_TRACE(Common_Filesystem, "%s: %lld", filename.c_str(), (long long)buf.st_size); |
|
|
|
|
|
|
|
|
NGLOG_TRACE(Common_Filesystem, "{}: {}", filename, buf.st_size); |
|
|
return buf.st_size; |
|
|
return buf.st_size; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
LOG_ERROR(Common_Filesystem, "Stat failed %s: %s", filename.c_str(), GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "Stat failed {}: {}", filename, GetLastErrorMsg()); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -362,7 +360,7 @@ u64 GetSize(const std::string& filename) { |
|
|
u64 GetSize(const int fd) { |
|
|
u64 GetSize(const int fd) { |
|
|
struct stat buf; |
|
|
struct stat buf; |
|
|
if (fstat(fd, &buf) != 0) { |
|
|
if (fstat(fd, &buf) != 0) { |
|
|
LOG_ERROR(Common_Filesystem, "GetSize: stat failed %i: %s", fd, GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "GetSize: stat failed {}: {}", fd, GetLastErrorMsg()); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
return buf.st_size; |
|
|
return buf.st_size; |
|
|
@ -373,12 +371,14 @@ u64 GetSize(FILE* f) { |
|
|
// can't use off_t here because it can be 32-bit
|
|
|
// can't use off_t here because it can be 32-bit
|
|
|
u64 pos = ftello(f); |
|
|
u64 pos = ftello(f); |
|
|
if (fseeko(f, 0, SEEK_END) != 0) { |
|
|
if (fseeko(f, 0, SEEK_END) != 0) { |
|
|
LOG_ERROR(Common_Filesystem, "GetSize: seek failed %p: %s", f, GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "GetSize: seek failed {}: {}", fmt::ptr(f), |
|
|
|
|
|
GetLastErrorMsg()); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
u64 size = ftello(f); |
|
|
u64 size = ftello(f); |
|
|
if ((size != pos) && (fseeko(f, pos, SEEK_SET) != 0)) { |
|
|
if ((size != pos) && (fseeko(f, pos, SEEK_SET) != 0)) { |
|
|
LOG_ERROR(Common_Filesystem, "GetSize: seek failed %p: %s", f, GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "GetSize: seek failed {}: {}", fmt::ptr(f), |
|
|
|
|
|
GetLastErrorMsg()); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
return size; |
|
|
return size; |
|
|
@ -386,10 +386,10 @@ 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 std::string& filename) { |
|
|
bool CreateEmptyFile(const std::string& filename) { |
|
|
LOG_TRACE(Common_Filesystem, "%s", filename.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_TRACE(Common_Filesystem, "{}", filename); |
|
|
|
|
|
|
|
|
if (!FileUtil::IOFile(filename, "wb")) { |
|
|
if (!FileUtil::IOFile(filename, "wb")) { |
|
|
LOG_ERROR(Common_Filesystem, "failed %s: %s", filename.c_str(), GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "failed {}: {}", filename, GetLastErrorMsg()); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -398,7 +398,7 @@ bool CreateEmptyFile(const std::string& filename) { |
|
|
|
|
|
|
|
|
bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directory, |
|
|
bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directory, |
|
|
DirectoryEntryCallable callback) { |
|
|
DirectoryEntryCallable callback) { |
|
|
LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_TRACE(Common_Filesystem, "directory {}", directory); |
|
|
|
|
|
|
|
|
// How many files + directories we found
|
|
|
// How many files + directories we found
|
|
|
unsigned found_entries = 0; |
|
|
unsigned found_entries = 0; |
|
|
@ -556,7 +556,7 @@ std::string GetCurrentDir() { |
|
|
char* dir; |
|
|
char* dir; |
|
|
if (!(dir = getcwd(nullptr, 0))) { |
|
|
if (!(dir = getcwd(nullptr, 0))) { |
|
|
#endif
|
|
|
#endif
|
|
|
LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s", GetLastErrorMsg()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: {}", GetLastErrorMsg()); |
|
|
return nullptr; |
|
|
return nullptr; |
|
|
} |
|
|
} |
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
@ -676,7 +676,7 @@ std::string GetSysDirectory() { |
|
|
#endif
|
|
|
#endif
|
|
|
sysDir += DIR_SEP; |
|
|
sysDir += DIR_SEP; |
|
|
|
|
|
|
|
|
LOG_DEBUG(Common_Filesystem, "Setting to %s:", sysDir.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_DEBUG(Common_Filesystem, "Setting to {}:", sysDir); |
|
|
return sysDir; |
|
|
return sysDir; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -692,7 +692,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new |
|
|
if (!FileUtil::IsDirectory(paths[D_USER_IDX])) { |
|
|
if (!FileUtil::IsDirectory(paths[D_USER_IDX])) { |
|
|
paths[D_USER_IDX] = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP; |
|
|
paths[D_USER_IDX] = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP; |
|
|
} else { |
|
|
} else { |
|
|
LOG_INFO(Common_Filesystem, "Using the local user directory"); |
|
|
|
|
|
|
|
|
NGLOG_INFO(Common_Filesystem, "Using the local user directory"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; |
|
|
paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; |
|
|
@ -719,7 +719,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new |
|
|
|
|
|
|
|
|
if (!newPath.empty()) { |
|
|
if (!newPath.empty()) { |
|
|
if (!FileUtil::IsDirectory(newPath)) { |
|
|
if (!FileUtil::IsDirectory(newPath)) { |
|
|
LOG_ERROR(Common_Filesystem, "Invalid path specified %s", newPath.c_str()); |
|
|
|
|
|
|
|
|
NGLOG_ERROR(Common_Filesystem, "Invalid path specified {}", newPath); |
|
|
return paths[DirIDX]; |
|
|
return paths[DirIDX]; |
|
|
} else { |
|
|
} else { |
|
|
paths[DirIDX] = newPath; |
|
|
paths[DirIDX] = newPath; |
|
|
|