diff options
Diffstat (limited to 'src/common/file_util.cpp')
| -rw-r--r-- | src/common/file_util.cpp | 130 |
1 files changed, 61 insertions, 69 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index b6dec838c..bba830c70 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project | 1 | // Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project |
| 2 | // Licensed under GPLv2 | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | 5 | ||
| @@ -88,7 +88,7 @@ bool IsDirectory(const std::string &filename) | |||
| 88 | #endif | 88 | #endif |
| 89 | 89 | ||
| 90 | if (result < 0) { | 90 | if (result < 0) { |
| 91 | WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s", | 91 | LOG_WARNING(Common_Filesystem, "stat failed on %s: %s", |
| 92 | filename.c_str(), GetLastErrorMsg()); | 92 | filename.c_str(), GetLastErrorMsg()); |
| 93 | return false; | 93 | return false; |
| 94 | } | 94 | } |
| @@ -100,33 +100,33 @@ bool IsDirectory(const std::string &filename) | |||
| 100 | // Doesn't supports deleting a directory | 100 | // Doesn't supports deleting a directory |
| 101 | bool Delete(const std::string &filename) | 101 | bool Delete(const std::string &filename) |
| 102 | { | 102 | { |
| 103 | INFO_LOG(COMMON, "Delete: file %s", filename.c_str()); | 103 | LOG_INFO(Common_Filesystem, "file %s", filename.c_str()); |
| 104 | 104 | ||
| 105 | // Return true because we care about the file no | 105 | // Return true because we care about the file no |
| 106 | // being there, not the actual delete. | 106 | // being there, not the actual delete. |
| 107 | if (!Exists(filename)) | 107 | if (!Exists(filename)) |
| 108 | { | 108 | { |
| 109 | WARN_LOG(COMMON, "Delete: %s does not exist", filename.c_str()); | 109 | LOG_WARNING(Common_Filesystem, "%s does not exist", filename.c_str()); |
| 110 | return true; | 110 | return true; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | // We can't delete a directory | 113 | // We can't delete a directory |
| 114 | if (IsDirectory(filename)) | 114 | if (IsDirectory(filename)) |
| 115 | { | 115 | { |
| 116 | WARN_LOG(COMMON, "Delete failed: %s is a directory", filename.c_str()); | 116 | LOG_ERROR(Common_Filesystem, "Failed: %s is a directory", filename.c_str()); |
| 117 | return false; | 117 | return false; |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | #ifdef _WIN32 | 120 | #ifdef _WIN32 |
| 121 | if (!DeleteFile(Common::UTF8ToTStr(filename).c_str())) | 121 | if (!DeleteFile(Common::UTF8ToTStr(filename).c_str())) |
| 122 | { | 122 | { |
| 123 | WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s", | 123 | LOG_ERROR(Common_Filesystem, "DeleteFile failed on %s: %s", |
| 124 | filename.c_str(), GetLastErrorMsg()); | 124 | filename.c_str(), GetLastErrorMsg()); |
| 125 | return false; | 125 | return false; |
| 126 | } | 126 | } |
| 127 | #else | 127 | #else |
| 128 | if (unlink(filename.c_str()) == -1) { | 128 | if (unlink(filename.c_str()) == -1) { |
| 129 | WARN_LOG(COMMON, "Delete: unlink failed on %s: %s", | 129 | LOG_ERROR(Common_Filesystem, "unlink failed on %s: %s", |
| 130 | filename.c_str(), GetLastErrorMsg()); | 130 | filename.c_str(), GetLastErrorMsg()); |
| 131 | return false; | 131 | return false; |
| 132 | } | 132 | } |
| @@ -138,17 +138,17 @@ bool Delete(const std::string &filename) | |||
| 138 | // Returns true if successful, or path already exists. | 138 | // Returns true if successful, or path already exists. |
| 139 | bool CreateDir(const std::string &path) | 139 | bool CreateDir(const std::string &path) |
| 140 | { | 140 | { |
| 141 | INFO_LOG(COMMON, "CreateDir: directory %s", path.c_str()); | 141 | LOG_TRACE(Common_Filesystem, "directory %s", path.c_str()); |
| 142 | #ifdef _WIN32 | 142 | #ifdef _WIN32 |
| 143 | if (::CreateDirectory(Common::UTF8ToTStr(path).c_str(), NULL)) | 143 | if (::CreateDirectory(Common::UTF8ToTStr(path).c_str(), nullptr)) |
| 144 | return true; | 144 | return true; |
| 145 | DWORD error = GetLastError(); | 145 | DWORD error = GetLastError(); |
| 146 | if (error == ERROR_ALREADY_EXISTS) | 146 | if (error == ERROR_ALREADY_EXISTS) |
| 147 | { | 147 | { |
| 148 | WARN_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: already exists", path.c_str()); | 148 | LOG_WARNING(Common_Filesystem, "CreateDirectory failed on %s: already exists", path.c_str()); |
| 149 | return true; | 149 | return true; |
| 150 | } | 150 | } |
| 151 | ERROR_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: %i", path.c_str(), error); | 151 | LOG_ERROR(Common_Filesystem, "CreateDirectory failed on %s: %i", path.c_str(), error); |
| 152 | return false; | 152 | return false; |
| 153 | #else | 153 | #else |
| 154 | if (mkdir(path.c_str(), 0755) == 0) | 154 | if (mkdir(path.c_str(), 0755) == 0) |
| @@ -158,11 +158,11 @@ bool CreateDir(const std::string &path) | |||
| 158 | 158 | ||
| 159 | if (err == EEXIST) | 159 | if (err == EEXIST) |
| 160 | { | 160 | { |
| 161 | WARN_LOG(COMMON, "CreateDir: mkdir failed on %s: already exists", path.c_str()); | 161 | LOG_WARNING(Common_Filesystem, "mkdir failed on %s: already exists", path.c_str()); |
| 162 | return true; | 162 | return true; |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | ERROR_LOG(COMMON, "CreateDir: mkdir failed on %s: %s", path.c_str(), strerror(err)); | 165 | LOG_ERROR(Common_Filesystem, "mkdir failed on %s: %s", path.c_str(), strerror(err)); |
| 166 | return false; | 166 | return false; |
| 167 | #endif | 167 | #endif |
| 168 | } | 168 | } |
| @@ -171,11 +171,11 @@ bool CreateDir(const std::string &path) | |||
| 171 | bool CreateFullPath(const std::string &fullPath) | 171 | bool CreateFullPath(const std::string &fullPath) |
| 172 | { | 172 | { |
| 173 | int panicCounter = 100; | 173 | int panicCounter = 100; |
| 174 | INFO_LOG(COMMON, "CreateFullPath: path %s", fullPath.c_str()); | 174 | LOG_TRACE(Common_Filesystem, "path %s", fullPath.c_str()); |
| 175 | 175 | ||
| 176 | if (FileUtil::Exists(fullPath)) | 176 | if (FileUtil::Exists(fullPath)) |
| 177 | { | 177 | { |
| 178 | INFO_LOG(COMMON, "CreateFullPath: path exists %s", fullPath.c_str()); | 178 | LOG_WARNING(Common_Filesystem, "path exists %s", fullPath.c_str()); |
| 179 | return true; | 179 | return true; |
| 180 | } | 180 | } |
| 181 | 181 | ||
| @@ -192,7 +192,7 @@ bool CreateFullPath(const std::string &fullPath) | |||
| 192 | // Include the '/' so the first call is CreateDir("/") rather than CreateDir("") | 192 | // Include the '/' so the first call is CreateDir("/") rather than CreateDir("") |
| 193 | std::string const subPath(fullPath.substr(0, position + 1)); | 193 | std::string const subPath(fullPath.substr(0, position + 1)); |
| 194 | if (!FileUtil::IsDirectory(subPath) && !FileUtil::CreateDir(subPath)) { | 194 | if (!FileUtil::IsDirectory(subPath) && !FileUtil::CreateDir(subPath)) { |
| 195 | ERROR_LOG(COMMON, "CreateFullPath: directory creation failed"); | 195 | LOG_ERROR(Common, "CreateFullPath: directory creation failed"); |
| 196 | return false; | 196 | return false; |
| 197 | } | 197 | } |
| 198 | 198 | ||
| @@ -200,7 +200,7 @@ bool CreateFullPath(const std::string &fullPath) | |||
| 200 | panicCounter--; | 200 | panicCounter--; |
| 201 | if (panicCounter <= 0) | 201 | if (panicCounter <= 0) |
| 202 | { | 202 | { |
| 203 | ERROR_LOG(COMMON, "CreateFullPath: directory structure is too deep"); | 203 | LOG_ERROR(Common, "CreateFullPath: directory structure is too deep"); |
| 204 | return false; | 204 | return false; |
| 205 | } | 205 | } |
| 206 | position++; | 206 | position++; |
| @@ -211,12 +211,12 @@ bool CreateFullPath(const std::string &fullPath) | |||
| 211 | // Deletes a directory filename, returns true on success | 211 | // Deletes a directory filename, returns true on success |
| 212 | bool DeleteDir(const std::string &filename) | 212 | bool DeleteDir(const std::string &filename) |
| 213 | { | 213 | { |
| 214 | INFO_LOG(COMMON, "DeleteDir: directory %s", filename.c_str()); | 214 | LOG_INFO(Common_Filesystem, "directory %s", filename.c_str()); |
| 215 | 215 | ||
| 216 | // check if a directory | 216 | // check if a directory |
| 217 | if (!FileUtil::IsDirectory(filename)) | 217 | if (!FileUtil::IsDirectory(filename)) |
| 218 | { | 218 | { |
| 219 | ERROR_LOG(COMMON, "DeleteDir: Not a directory %s", filename.c_str()); | 219 | LOG_ERROR(Common_Filesystem, "Not a directory %s", filename.c_str()); |
| 220 | return false; | 220 | return false; |
| 221 | } | 221 | } |
| 222 | 222 | ||
| @@ -227,7 +227,7 @@ bool DeleteDir(const std::string &filename) | |||
| 227 | if (rmdir(filename.c_str()) == 0) | 227 | if (rmdir(filename.c_str()) == 0) |
| 228 | return true; | 228 | return true; |
| 229 | #endif | 229 | #endif |
| 230 | ERROR_LOG(COMMON, "DeleteDir: %s: %s", filename.c_str(), GetLastErrorMsg()); | 230 | LOG_ERROR(Common_Filesystem, "failed %s: %s", filename.c_str(), GetLastErrorMsg()); |
| 231 | 231 | ||
| 232 | return false; | 232 | return false; |
| 233 | } | 233 | } |
| @@ -235,11 +235,11 @@ bool DeleteDir(const std::string &filename) | |||
| 235 | // renames file srcFilename to destFilename, returns true on success | 235 | // renames file srcFilename to destFilename, returns true on success |
| 236 | bool Rename(const std::string &srcFilename, const std::string &destFilename) | 236 | bool Rename(const std::string &srcFilename, const std::string &destFilename) |
| 237 | { | 237 | { |
| 238 | INFO_LOG(COMMON, "Rename: %s --> %s", | 238 | LOG_TRACE(Common_Filesystem, "%s --> %s", |
| 239 | srcFilename.c_str(), destFilename.c_str()); | 239 | srcFilename.c_str(), destFilename.c_str()); |
| 240 | if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) | 240 | if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) |
| 241 | return true; | 241 | return true; |
| 242 | ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s", | 242 | LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", |
| 243 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); | 243 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
| 244 | return false; | 244 | return false; |
| 245 | } | 245 | } |
| @@ -247,13 +247,13 @@ bool Rename(const std::string &srcFilename, const std::string &destFilename) | |||
| 247 | // copies file srcFilename to destFilename, returns true on success | 247 | // copies file srcFilename to destFilename, returns true on success |
| 248 | bool Copy(const std::string &srcFilename, const std::string &destFilename) | 248 | bool Copy(const std::string &srcFilename, const std::string &destFilename) |
| 249 | { | 249 | { |
| 250 | INFO_LOG(COMMON, "Copy: %s --> %s", | 250 | LOG_TRACE(Common_Filesystem, "%s --> %s", |
| 251 | srcFilename.c_str(), destFilename.c_str()); | 251 | srcFilename.c_str(), destFilename.c_str()); |
| 252 | #ifdef _WIN32 | 252 | #ifdef _WIN32 |
| 253 | if (CopyFile(Common::UTF8ToTStr(srcFilename).c_str(), Common::UTF8ToTStr(destFilename).c_str(), FALSE)) | 253 | if (CopyFile(Common::UTF8ToTStr(srcFilename).c_str(), Common::UTF8ToTStr(destFilename).c_str(), FALSE)) |
| 254 | return true; | 254 | return true; |
| 255 | 255 | ||
| 256 | ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s", | 256 | LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s", |
| 257 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); | 257 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
| 258 | return false; | 258 | return false; |
| 259 | #else | 259 | #else |
| @@ -267,7 +267,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) | |||
| 267 | FILE *input = fopen(srcFilename.c_str(), "rb"); | 267 | FILE *input = fopen(srcFilename.c_str(), "rb"); |
| 268 | if (!input) | 268 | if (!input) |
| 269 | { | 269 | { |
| 270 | ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s", | 270 | LOG_ERROR(Common_Filesystem, "opening input failed %s --> %s: %s", |
| 271 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); | 271 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
| 272 | return false; | 272 | return false; |
| 273 | } | 273 | } |
| @@ -277,7 +277,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) | |||
| 277 | if (!output) | 277 | if (!output) |
| 278 | { | 278 | { |
| 279 | fclose(input); | 279 | fclose(input); |
| 280 | ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s", | 280 | LOG_ERROR(Common_Filesystem, "opening output failed %s --> %s: %s", |
| 281 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); | 281 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
| 282 | return false; | 282 | return false; |
| 283 | } | 283 | } |
| @@ -291,8 +291,8 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) | |||
| 291 | { | 291 | { |
| 292 | if (ferror(input) != 0) | 292 | if (ferror(input) != 0) |
| 293 | { | 293 | { |
| 294 | ERROR_LOG(COMMON, | 294 | LOG_ERROR(Common_Filesystem, |
| 295 | "Copy: failed reading from source, %s --> %s: %s", | 295 | "failed reading from source, %s --> %s: %s", |
| 296 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); | 296 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
| 297 | goto bail; | 297 | goto bail; |
| 298 | } | 298 | } |
| @@ -302,8 +302,8 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) | |||
| 302 | int wnum = fwrite(buffer, sizeof(char), rnum, output); | 302 | int wnum = fwrite(buffer, sizeof(char), rnum, output); |
| 303 | if (wnum != rnum) | 303 | if (wnum != rnum) |
| 304 | { | 304 | { |
| 305 | ERROR_LOG(COMMON, | 305 | LOG_ERROR(Common_Filesystem, |
| 306 | "Copy: failed writing to output, %s --> %s: %s", | 306 | "failed writing to output, %s --> %s: %s", |
| 307 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); | 307 | srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); |
| 308 | goto bail; | 308 | goto bail; |
| 309 | } | 309 | } |
| @@ -326,13 +326,13 @@ u64 GetSize(const std::string &filename) | |||
| 326 | { | 326 | { |
| 327 | if (!Exists(filename)) | 327 | if (!Exists(filename)) |
| 328 | { | 328 | { |
| 329 | WARN_LOG(COMMON, "GetSize: failed %s: No such file", filename.c_str()); | 329 | LOG_ERROR(Common_Filesystem, "failed %s: No such file", filename.c_str()); |
| 330 | return 0; | 330 | return 0; |
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | if (IsDirectory(filename)) | 333 | if (IsDirectory(filename)) |
| 334 | { | 334 | { |
| 335 | WARN_LOG(COMMON, "GetSize: failed %s: is a directory", filename.c_str()); | 335 | LOG_ERROR(Common_Filesystem, "failed %s: is a directory", filename.c_str()); |
| 336 | return 0; | 336 | return 0; |
| 337 | } | 337 | } |
| 338 | 338 | ||
| @@ -343,12 +343,12 @@ u64 GetSize(const std::string &filename) | |||
| 343 | if (stat64(filename.c_str(), &buf) == 0) | 343 | if (stat64(filename.c_str(), &buf) == 0) |
| 344 | #endif | 344 | #endif |
| 345 | { | 345 | { |
| 346 | DEBUG_LOG(COMMON, "GetSize: %s: %lld", | 346 | LOG_TRACE(Common_Filesystem, "%s: %lld", |
| 347 | filename.c_str(), (long long)buf.st_size); | 347 | filename.c_str(), (long long)buf.st_size); |
| 348 | return buf.st_size; | 348 | return buf.st_size; |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | ERROR_LOG(COMMON, "GetSize: Stat failed %s: %s", | 351 | LOG_ERROR(Common_Filesystem, "Stat failed %s: %s", |
| 352 | filename.c_str(), GetLastErrorMsg()); | 352 | filename.c_str(), GetLastErrorMsg()); |
| 353 | return 0; | 353 | return 0; |
| 354 | } | 354 | } |
| @@ -358,7 +358,7 @@ u64 GetSize(const int fd) | |||
| 358 | { | 358 | { |
| 359 | struct stat64 buf; | 359 | struct stat64 buf; |
| 360 | if (fstat64(fd, &buf) != 0) { | 360 | if (fstat64(fd, &buf) != 0) { |
| 361 | ERROR_LOG(COMMON, "GetSize: stat failed %i: %s", | 361 | LOG_ERROR(Common_Filesystem, "GetSize: stat failed %i: %s", |
| 362 | fd, GetLastErrorMsg()); | 362 | fd, GetLastErrorMsg()); |
| 363 | return 0; | 363 | return 0; |
| 364 | } | 364 | } |
| @@ -371,13 +371,13 @@ u64 GetSize(FILE *f) | |||
| 371 | // can't use off_t here because it can be 32-bit | 371 | // can't use off_t here because it can be 32-bit |
| 372 | u64 pos = ftello(f); | 372 | u64 pos = ftello(f); |
| 373 | if (fseeko(f, 0, SEEK_END) != 0) { | 373 | if (fseeko(f, 0, SEEK_END) != 0) { |
| 374 | ERROR_LOG(COMMON, "GetSize: seek failed %p: %s", | 374 | LOG_ERROR(Common_Filesystem, "GetSize: seek failed %p: %s", |
| 375 | f, GetLastErrorMsg()); | 375 | f, GetLastErrorMsg()); |
| 376 | return 0; | 376 | return 0; |
| 377 | } | 377 | } |
| 378 | u64 size = ftello(f); | 378 | u64 size = ftello(f); |
| 379 | if ((size != pos) && (fseeko(f, pos, SEEK_SET) != 0)) { | 379 | if ((size != pos) && (fseeko(f, pos, SEEK_SET) != 0)) { |
| 380 | ERROR_LOG(COMMON, "GetSize: seek failed %p: %s", | 380 | LOG_ERROR(Common_Filesystem, "GetSize: seek failed %p: %s", |
| 381 | f, GetLastErrorMsg()); | 381 | f, GetLastErrorMsg()); |
| 382 | return 0; | 382 | return 0; |
| 383 | } | 383 | } |
| @@ -387,11 +387,11 @@ u64 GetSize(FILE *f) | |||
| 387 | // creates an empty file filename, returns true on success | 387 | // creates an empty file filename, returns true on success |
| 388 | bool CreateEmptyFile(const std::string &filename) | 388 | bool CreateEmptyFile(const std::string &filename) |
| 389 | { | 389 | { |
| 390 | INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str()); | 390 | LOG_TRACE(Common_Filesystem, "%s", filename.c_str()); |
| 391 | 391 | ||
| 392 | if (!FileUtil::IOFile(filename, "wb")) | 392 | if (!FileUtil::IOFile(filename, "wb")) |
| 393 | { | 393 | { |
| 394 | ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s", | 394 | LOG_ERROR(Common_Filesystem, "failed %s: %s", |
| 395 | filename.c_str(), GetLastErrorMsg()); | 395 | filename.c_str(), GetLastErrorMsg()); |
| 396 | return false; | 396 | return false; |
| 397 | } | 397 | } |
| @@ -404,7 +404,7 @@ bool CreateEmptyFile(const std::string &filename) | |||
| 404 | // results into parentEntry. Returns the number of files+directories found | 404 | // results into parentEntry. Returns the number of files+directories found |
| 405 | u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry) | 405 | u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry) |
| 406 | { | 406 | { |
| 407 | INFO_LOG(COMMON, "ScanDirectoryTree: directory %s", directory.c_str()); | 407 | LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str()); |
| 408 | // How many files + directories we found | 408 | // How many files + directories we found |
| 409 | u32 foundEntries = 0; | 409 | u32 foundEntries = 0; |
| 410 | #ifdef _WIN32 | 410 | #ifdef _WIN32 |
| @@ -423,7 +423,7 @@ u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry) | |||
| 423 | FSTEntry entry; | 423 | FSTEntry entry; |
| 424 | const std::string virtualName(Common::TStrToUTF8(ffd.cFileName)); | 424 | const std::string virtualName(Common::TStrToUTF8(ffd.cFileName)); |
| 425 | #else | 425 | #else |
| 426 | struct dirent dirent, *result = NULL; | 426 | struct dirent dirent, *result = nullptr; |
| 427 | 427 | ||
| 428 | DIR *dirp = opendir(directory.c_str()); | 428 | DIR *dirp = opendir(directory.c_str()); |
| 429 | if (!dirp) | 429 | if (!dirp) |
| @@ -474,7 +474,7 @@ u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry) | |||
| 474 | // Deletes the given directory and anything under it. Returns true on success. | 474 | // Deletes the given directory and anything under it. Returns true on success. |
| 475 | bool DeleteDirRecursively(const std::string &directory) | 475 | bool DeleteDirRecursively(const std::string &directory) |
| 476 | { | 476 | { |
| 477 | INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str()); | 477 | LOG_TRACE(Common_Filesystem, "%s", directory.c_str()); |
| 478 | #ifdef _WIN32 | 478 | #ifdef _WIN32 |
| 479 | // Find the first file in the directory. | 479 | // Find the first file in the directory. |
| 480 | WIN32_FIND_DATA ffd; | 480 | WIN32_FIND_DATA ffd; |
| @@ -491,7 +491,7 @@ bool DeleteDirRecursively(const std::string &directory) | |||
| 491 | { | 491 | { |
| 492 | const std::string virtualName(Common::TStrToUTF8(ffd.cFileName)); | 492 | const std::string virtualName(Common::TStrToUTF8(ffd.cFileName)); |
| 493 | #else | 493 | #else |
| 494 | struct dirent dirent, *result = NULL; | 494 | struct dirent dirent, *result = nullptr; |
| 495 | DIR *dirp = opendir(directory.c_str()); | 495 | DIR *dirp = opendir(directory.c_str()); |
| 496 | if (!dirp) | 496 | if (!dirp) |
| 497 | return false; | 497 | return false; |
| @@ -552,7 +552,7 @@ void CopyDir(const std::string &source_path, const std::string &dest_path) | |||
| 552 | if (!FileUtil::Exists(source_path)) return; | 552 | if (!FileUtil::Exists(source_path)) return; |
| 553 | if (!FileUtil::Exists(dest_path)) FileUtil::CreateFullPath(dest_path); | 553 | if (!FileUtil::Exists(dest_path)) FileUtil::CreateFullPath(dest_path); |
| 554 | 554 | ||
| 555 | struct dirent dirent, *result = NULL; | 555 | struct dirent dirent, *result = nullptr; |
| 556 | DIR *dirp = opendir(source_path.c_str()); | 556 | DIR *dirp = opendir(source_path.c_str()); |
| 557 | if (!dirp) return; | 557 | if (!dirp) return; |
| 558 | 558 | ||
| @@ -586,11 +586,11 @@ std::string GetCurrentDir() | |||
| 586 | { | 586 | { |
| 587 | char *dir; | 587 | char *dir; |
| 588 | // Get the current working directory (getcwd uses malloc) | 588 | // Get the current working directory (getcwd uses malloc) |
| 589 | if (!(dir = __getcwd(NULL, 0))) { | 589 | if (!(dir = __getcwd(nullptr, 0))) { |
| 590 | 590 | ||
| 591 | ERROR_LOG(COMMON, "GetCurrentDirectory failed: %s", | 591 | LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s", |
| 592 | GetLastErrorMsg()); | 592 | GetLastErrorMsg()); |
| 593 | return NULL; | 593 | return nullptr; |
| 594 | } | 594 | } |
| 595 | std::string strDir = dir; | 595 | std::string strDir = dir; |
| 596 | free(dir); | 596 | free(dir); |
| @@ -626,7 +626,7 @@ std::string& GetExeDirectory() | |||
| 626 | if (DolphinPath.empty()) | 626 | if (DolphinPath.empty()) |
| 627 | { | 627 | { |
| 628 | TCHAR Dolphin_exe_Path[2048]; | 628 | TCHAR Dolphin_exe_Path[2048]; |
| 629 | GetModuleFileName(NULL, Dolphin_exe_Path, 2048); | 629 | GetModuleFileName(nullptr, Dolphin_exe_Path, 2048); |
| 630 | DolphinPath = Common::TStrToUTF8(Dolphin_exe_Path); | 630 | DolphinPath = Common::TStrToUTF8(Dolphin_exe_Path); |
| 631 | DolphinPath = DolphinPath.substr(0, DolphinPath.find_last_of('\\')); | 631 | DolphinPath = DolphinPath.substr(0, DolphinPath.find_last_of('\\')); |
| 632 | } | 632 | } |
| @@ -647,7 +647,7 @@ std::string GetSysDirectory() | |||
| 647 | #endif | 647 | #endif |
| 648 | sysDir += DIR_SEP; | 648 | sysDir += DIR_SEP; |
| 649 | 649 | ||
| 650 | INFO_LOG(COMMON, "GetSysDirectory: Setting to %s:", sysDir.c_str()); | 650 | LOG_DEBUG(Common_Filesystem, "Setting to %s:", sysDir.c_str()); |
| 651 | return sysDir; | 651 | return sysDir; |
| 652 | } | 652 | } |
| 653 | 653 | ||
| @@ -676,6 +676,9 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new | |||
| 676 | paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP; | 676 | paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP; |
| 677 | paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; | 677 | paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; |
| 678 | paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; | 678 | paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; |
| 679 | paths[D_SAVEDATA_IDX] = paths[D_USER_IDX] + SAVEDATA_DIR DIR_SEP; | ||
| 680 | paths[D_SYSDATA_IDX] = paths[D_USER_IDX] + SYSDATA_DIR DIR_SEP; | ||
| 681 | paths[D_SYSSAVEDATA_IDX] = paths[D_USER_IDX] + SYSSAVEDATA_DIR DIR_SEP; | ||
| 679 | paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP; | 682 | paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP; |
| 680 | paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP; | 683 | paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP; |
| 681 | paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP; | 684 | paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP; |
| @@ -694,7 +697,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new | |||
| 694 | { | 697 | { |
| 695 | if (!FileUtil::IsDirectory(newPath)) | 698 | if (!FileUtil::IsDirectory(newPath)) |
| 696 | { | 699 | { |
| 697 | WARN_LOG(COMMON, "Invalid path specified %s", newPath.c_str()); | 700 | LOG_ERROR(Common_Filesystem, "Invalid path specified %s", newPath.c_str()); |
| 698 | return paths[DirIDX]; | 701 | return paths[DirIDX]; |
| 699 | } | 702 | } |
| 700 | else | 703 | else |
| @@ -717,6 +720,8 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new | |||
| 717 | paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP; | 720 | paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP; |
| 718 | paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; | 721 | paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; |
| 719 | paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; | 722 | paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; |
| 723 | paths[D_SAVEDATA_IDX] = paths[D_USER_IDX] + SAVEDATA_DIR DIR_SEP; | ||
| 724 | paths[D_SYSSAVEDATA_IDX] = paths[D_USER_IDX] + SYSSAVEDATA_DIR DIR_SEP; | ||
| 720 | paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP; | 725 | paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP; |
| 721 | paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP; | 726 | paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP; |
| 722 | paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP; | 727 | paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP; |
| @@ -753,19 +758,6 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new | |||
| 753 | return paths[DirIDX]; | 758 | return paths[DirIDX]; |
| 754 | } | 759 | } |
| 755 | 760 | ||
| 756 | //std::string GetThemeDir(const std::string& theme_name) | ||
| 757 | //{ | ||
| 758 | // std::string dir = FileUtil::GetUserPath(D_THEMES_IDX) + theme_name + "/"; | ||
| 759 | // | ||
| 760 | //#if !defined(_WIN32) | ||
| 761 | // // If theme does not exist in user's dir load from shared directory | ||
| 762 | // if (!FileUtil::Exists(dir)) | ||
| 763 | // dir = SHARED_USER_DIR THEMES_DIR "/" + theme_name + "/"; | ||
| 764 | //#endif | ||
| 765 | // | ||
| 766 | // return dir; | ||
| 767 | //} | ||
| 768 | |||
| 769 | size_t WriteStringToFile(bool text_file, const std::string &str, const char *filename) | 761 | size_t WriteStringToFile(bool text_file, const std::string &str, const char *filename) |
| 770 | { | 762 | { |
| 771 | return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size()); | 763 | return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size()); |
| @@ -826,7 +818,7 @@ void SplitFilename83(const std::string& filename, std::array<char, 9>& short_nam | |||
| 826 | } | 818 | } |
| 827 | 819 | ||
| 828 | IOFile::IOFile() | 820 | IOFile::IOFile() |
| 829 | : m_file(NULL), m_good(true) | 821 | : m_file(nullptr), m_good(true) |
| 830 | {} | 822 | {} |
| 831 | 823 | ||
| 832 | IOFile::IOFile(std::FILE* file) | 824 | IOFile::IOFile(std::FILE* file) |
| @@ -834,7 +826,7 @@ IOFile::IOFile(std::FILE* file) | |||
| 834 | {} | 826 | {} |
| 835 | 827 | ||
| 836 | IOFile::IOFile(const std::string& filename, const char openmode[]) | 828 | IOFile::IOFile(const std::string& filename, const char openmode[]) |
| 837 | : m_file(NULL), m_good(true) | 829 | : m_file(nullptr), m_good(true) |
| 838 | { | 830 | { |
| 839 | Open(filename, openmode); | 831 | Open(filename, openmode); |
| 840 | } | 832 | } |
| @@ -845,7 +837,7 @@ IOFile::~IOFile() | |||
| 845 | } | 837 | } |
| 846 | 838 | ||
| 847 | IOFile::IOFile(IOFile&& other) | 839 | IOFile::IOFile(IOFile&& other) |
| 848 | : m_file(NULL), m_good(true) | 840 | : m_file(nullptr), m_good(true) |
| 849 | { | 841 | { |
| 850 | Swap(other); | 842 | Swap(other); |
| 851 | } | 843 | } |
| @@ -880,14 +872,14 @@ bool IOFile::Close() | |||
| 880 | if (!IsOpen() || 0 != std::fclose(m_file)) | 872 | if (!IsOpen() || 0 != std::fclose(m_file)) |
| 881 | m_good = false; | 873 | m_good = false; |
| 882 | 874 | ||
| 883 | m_file = NULL; | 875 | m_file = nullptr; |
| 884 | return m_good; | 876 | return m_good; |
| 885 | } | 877 | } |
| 886 | 878 | ||
| 887 | std::FILE* IOFile::ReleaseHandle() | 879 | std::FILE* IOFile::ReleaseHandle() |
| 888 | { | 880 | { |
| 889 | std::FILE* const ret = m_file; | 881 | std::FILE* const ret = m_file; |
| 890 | m_file = NULL; | 882 | m_file = nullptr; |
| 891 | return ret; | 883 | return ret; |
| 892 | } | 884 | } |
| 893 | 885 | ||