diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/file_util.cpp | 80 | ||||
| -rw-r--r-- | src/common/file_util.h | 31 | ||||
| -rw-r--r-- | src/common/logging/backend.cpp | 2 | ||||
| -rw-r--r-- | src/common/logging/log.h | 2 | ||||
| -rw-r--r-- | src/common/vector_math.h | 4 |
5 files changed, 70 insertions, 49 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 1e0d33313..052c0ecd6 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -420,11 +420,16 @@ bool CreateEmptyFile(const std::string &filename) | |||
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | 422 | ||
| 423 | int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int(const std::string&, const std::string&)> callback) | 423 | bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback) |
| 424 | { | 424 | { |
| 425 | LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str()); | 425 | LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str()); |
| 426 | |||
| 426 | // How many files + directories we found | 427 | // How many files + directories we found |
| 427 | int found_entries = 0; | 428 | unsigned found_entries = 0; |
| 429 | |||
| 430 | // Save the status of callback function | ||
| 431 | bool callback_error = false; | ||
| 432 | |||
| 428 | #ifdef _WIN32 | 433 | #ifdef _WIN32 |
| 429 | // Find the first file in the directory. | 434 | // Find the first file in the directory. |
| 430 | WIN32_FIND_DATA ffd; | 435 | WIN32_FIND_DATA ffd; |
| @@ -432,7 +437,7 @@ int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int | |||
| 432 | HANDLE handle_find = FindFirstFile(Common::UTF8ToTStr(directory + "\\*").c_str(), &ffd); | 437 | HANDLE handle_find = FindFirstFile(Common::UTF8ToTStr(directory + "\\*").c_str(), &ffd); |
| 433 | if (handle_find == INVALID_HANDLE_VALUE) { | 438 | if (handle_find == INVALID_HANDLE_VALUE) { |
| 434 | FindClose(handle_find); | 439 | FindClose(handle_find); |
| 435 | return found_entries; | 440 | return false; |
| 436 | } | 441 | } |
| 437 | // windows loop | 442 | // windows loop |
| 438 | do { | 443 | do { |
| @@ -442,25 +447,22 @@ int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int | |||
| 442 | 447 | ||
| 443 | DIR *dirp = opendir(directory.c_str()); | 448 | DIR *dirp = opendir(directory.c_str()); |
| 444 | if (!dirp) | 449 | if (!dirp) |
| 445 | return 0; | 450 | return false; |
| 446 | 451 | ||
| 447 | // non windows loop | 452 | // non windows loop |
| 448 | while (!readdir_r(dirp, &dirent, &result) && result) { | 453 | while (!readdir_r(dirp, &dirent, &result) && result) { |
| 449 | const std::string virtual_name(result->d_name); | 454 | const std::string virtual_name(result->d_name); |
| 450 | #endif | 455 | #endif |
| 451 | // check for "." and ".." | 456 | |
| 452 | if (((virtual_name[0] == '.') && (virtual_name[1] == '\0')) || | 457 | if (virtual_name == "." || virtual_name == "..") |
| 453 | ((virtual_name[0] == '.') && (virtual_name[1] == '.') && | ||
| 454 | (virtual_name[2] == '\0'))) | ||
| 455 | continue; | 458 | continue; |
| 456 | 459 | ||
| 457 | int ret = callback(directory, virtual_name); | 460 | unsigned ret_entries; |
| 458 | if (ret < 0) { | 461 | if (!callback(&ret_entries, directory, virtual_name)) { |
| 459 | if (ret != -1) | 462 | callback_error = true; |
| 460 | found_entries = ret; | ||
| 461 | break; | 463 | break; |
| 462 | } | 464 | } |
| 463 | found_entries += ret; | 465 | found_entries += ret_entries; |
| 464 | 466 | ||
| 465 | #ifdef _WIN32 | 467 | #ifdef _WIN32 |
| 466 | } while (FindNextFile(handle_find, &ffd) != 0); | 468 | } while (FindNextFile(handle_find, &ffd) != 0); |
| @@ -469,16 +471,23 @@ int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int | |||
| 469 | } | 471 | } |
| 470 | closedir(dirp); | 472 | closedir(dirp); |
| 471 | #endif | 473 | #endif |
| 472 | // Return number of entries found. | 474 | |
| 473 | return found_entries; | 475 | if (!callback_error) { |
| 476 | // num_entries_out is allowed to be specified nullptr, in which case we shouldn't try to set it | ||
| 477 | if (num_entries_out != nullptr) | ||
| 478 | *num_entries_out = found_entries; | ||
| 479 | return true; | ||
| 480 | } else { | ||
| 481 | return false; | ||
| 482 | } | ||
| 474 | } | 483 | } |
| 475 | 484 | ||
| 476 | int ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry) | 485 | unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry) |
| 477 | { | 486 | { |
| 478 | const auto callback = [&parent_entry](const std::string& directory, | 487 | const auto callback = [&parent_entry](unsigned* num_entries_out, |
| 479 | const std::string& virtual_name) -> int { | 488 | const std::string& directory, |
| 489 | const std::string& virtual_name) -> bool { | ||
| 480 | FSTEntry entry; | 490 | FSTEntry entry; |
| 481 | int found_entries = 0; | ||
| 482 | entry.virtualName = virtual_name; | 491 | entry.virtualName = virtual_name; |
| 483 | entry.physicalName = directory + DIR_SEP + virtual_name; | 492 | entry.physicalName = directory + DIR_SEP + virtual_name; |
| 484 | 493 | ||
| @@ -486,41 +495,40 @@ int ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry) | |||
| 486 | entry.isDirectory = true; | 495 | entry.isDirectory = true; |
| 487 | // is a directory, lets go inside | 496 | // is a directory, lets go inside |
| 488 | entry.size = ScanDirectoryTree(entry.physicalName, entry); | 497 | entry.size = ScanDirectoryTree(entry.physicalName, entry); |
| 489 | found_entries += (int)entry.size; | 498 | *num_entries_out += (int)entry.size; |
| 490 | } else { // is a file | 499 | } else { // is a file |
| 491 | entry.isDirectory = false; | 500 | entry.isDirectory = false; |
| 492 | entry.size = GetSize(entry.physicalName); | 501 | entry.size = GetSize(entry.physicalName); |
| 493 | } | 502 | } |
| 494 | ++found_entries; | 503 | (*num_entries_out)++; |
| 504 | |||
| 495 | // Push into the tree | 505 | // Push into the tree |
| 496 | parent_entry.children.push_back(entry); | 506 | parent_entry.children.push_back(entry); |
| 497 | return found_entries; | 507 | return true; |
| 498 | }; | 508 | }; |
| 499 | 509 | ||
| 500 | return ScanDirectoryTreeAndCallback(directory, callback); | 510 | unsigned num_entries; |
| 511 | return ForeachDirectoryEntry(&num_entries, directory, callback) ? num_entries : 0; | ||
| 501 | } | 512 | } |
| 502 | 513 | ||
| 503 | 514 | ||
| 504 | bool DeleteDirRecursively(const std::string &directory) | 515 | bool DeleteDirRecursively(const std::string &directory) |
| 505 | { | 516 | { |
| 506 | const static auto callback = [](const std::string& directory, | 517 | const static auto callback = [](unsigned* num_entries_out, |
| 507 | const std::string& virtual_name) -> int { | 518 | const std::string& directory, |
| 519 | const std::string& virtual_name) -> bool { | ||
| 508 | std::string new_path = directory + DIR_SEP_CHR + virtual_name; | 520 | std::string new_path = directory + DIR_SEP_CHR + virtual_name; |
| 509 | if (IsDirectory(new_path)) { | 521 | if (IsDirectory(new_path)) |
| 510 | if (!DeleteDirRecursively(new_path)) { | 522 | return DeleteDirRecursively(new_path); |
| 511 | return -2; | 523 | |
| 512 | } | 524 | return Delete(new_path); |
| 513 | } else if (!Delete(new_path)) { | ||
| 514 | return -2; | ||
| 515 | } | ||
| 516 | return 0; | ||
| 517 | }; | 525 | }; |
| 518 | 526 | ||
| 519 | if (ScanDirectoryTreeAndCallback(directory, callback) == -2) { | 527 | if (!ForeachDirectoryEntry(nullptr, directory, callback)) |
| 520 | return false; | 528 | return false; |
| 521 | } | ||
| 522 | FileUtil::DeleteDir(directory); | ||
| 523 | 529 | ||
| 530 | // Delete the outermost directory | ||
| 531 | FileUtil::DeleteDir(directory); | ||
| 524 | return true; | 532 | return true; |
| 525 | } | 533 | } |
| 526 | 534 | ||
diff --git a/src/common/file_util.h b/src/common/file_util.h index 3d617f573..a85121aa6 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -98,19 +98,24 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename); | |||
| 98 | bool CreateEmptyFile(const std::string &filename); | 98 | bool CreateEmptyFile(const std::string &filename); |
| 99 | 99 | ||
| 100 | /** | 100 | /** |
| 101 | * Scans the directory tree, calling the callback for each file/directory found. | 101 | * @param num_entries_out to be assigned by the callable with the number of iterated directory entries, never null |
| 102 | * The callback must return the number of files and directories which the provided path contains. | 102 | * @param directory the path to the enclosing directory |
| 103 | * If the callback's return value is -1, the callback loop is broken immediately. | 103 | * @param virtual_name the entry name, without any preceding directory info |
| 104 | * If the callback's return value is otherwise negative, the callback loop is broken immediately | 104 | * @return whether handling the entry succeeded |
| 105 | * and the callback's return value is returned from this function (to allow for error handling). | 105 | */ |
| 106 | * @param directory the parent directory to start scanning from | 106 | using DirectoryEntryCallable = std::function<bool(unsigned* num_entries_out, |
| 107 | * @param callback The callback which will be called for each file/directory. It is called | 107 | const std::string& directory, |
| 108 | * with the arguments (const std::string& directory, const std::string& virtual_name). | 108 | const std::string& virtual_name)>; |
| 109 | * The `directory `parameter is the path to the directory which contains the file/directory. | 109 | |
| 110 | * The `virtual_name` parameter is the incomplete file path, without any directory info. | 110 | /** |
| 111 | * @return the total number of files/directories found | 111 | * Scans a directory, calling the callback for each file/directory contained within. |
| 112 | * If the callback returns failure, scanning halts and this function returns failure as well | ||
| 113 | * @param num_entries_out assigned by the function with the number of iterated directory entries, can be null | ||
| 114 | * @param directory the directory to scan | ||
| 115 | * @param callback The callback which will be called for each entry | ||
| 116 | * @return whether scanning the directory succeeded | ||
| 112 | */ | 117 | */ |
| 113 | int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int(const std::string&, const std::string&)> callback); | 118 | bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback); |
| 114 | 119 | ||
| 115 | /** | 120 | /** |
| 116 | * Scans the directory tree, storing the results. | 121 | * Scans the directory tree, storing the results. |
| @@ -118,7 +123,7 @@ int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int | |||
| 118 | * @param parent_entry FSTEntry where the filesystem tree results will be stored. | 123 | * @param parent_entry FSTEntry where the filesystem tree results will be stored. |
| 119 | * @return the total number of files/directories found | 124 | * @return the total number of files/directories found |
| 120 | */ | 125 | */ |
| 121 | int ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry); | 126 | unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry); |
| 122 | 127 | ||
| 123 | // deletes the given directory and anything under it. Returns true on success. | 128 | // deletes the given directory and anything under it. Returns true on success. |
| 124 | bool DeleteDirRecursively(const std::string &directory); | 129 | bool DeleteDirRecursively(const std::string &directory); |
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 92e8e742d..d186ba8f8 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -29,6 +29,7 @@ namespace Log { | |||
| 29 | SUB(Debug, Emulated) \ | 29 | SUB(Debug, Emulated) \ |
| 30 | SUB(Debug, GPU) \ | 30 | SUB(Debug, GPU) \ |
| 31 | SUB(Debug, Breakpoint) \ | 31 | SUB(Debug, Breakpoint) \ |
| 32 | SUB(Debug, GDBStub) \ | ||
| 32 | CLS(Kernel) \ | 33 | CLS(Kernel) \ |
| 33 | SUB(Kernel, SVC) \ | 34 | SUB(Kernel, SVC) \ |
| 34 | CLS(Service) \ | 35 | CLS(Service) \ |
| @@ -43,6 +44,7 @@ namespace Log { | |||
| 43 | SUB(Service, LDR) \ | 44 | SUB(Service, LDR) \ |
| 44 | SUB(Service, NIM) \ | 45 | SUB(Service, NIM) \ |
| 45 | SUB(Service, NWM) \ | 46 | SUB(Service, NWM) \ |
| 47 | SUB(Service, CAM) \ | ||
| 46 | SUB(Service, CFG) \ | 48 | SUB(Service, CFG) \ |
| 47 | SUB(Service, DSP) \ | 49 | SUB(Service, DSP) \ |
| 48 | SUB(Service, HID) \ | 50 | SUB(Service, HID) \ |
diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 5fd3bd7f5..2d9323a7b 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h | |||
| @@ -43,6 +43,7 @@ enum class Class : ClassType { | |||
| 43 | Debug_Emulated, ///< Debug messages from the emulated programs | 43 | Debug_Emulated, ///< Debug messages from the emulated programs |
| 44 | Debug_GPU, ///< GPU debugging tools | 44 | Debug_GPU, ///< GPU debugging tools |
| 45 | Debug_Breakpoint, ///< Logging breakpoints and watchpoints | 45 | Debug_Breakpoint, ///< Logging breakpoints and watchpoints |
| 46 | Debug_GDBStub, ///< GDB Stub | ||
| 46 | Kernel, ///< The HLE implementation of the CTR kernel | 47 | Kernel, ///< The HLE implementation of the CTR kernel |
| 47 | Kernel_SVC, ///< Kernel system calls | 48 | Kernel_SVC, ///< Kernel system calls |
| 48 | Service, ///< HLE implementation of system services. Each major service | 49 | Service, ///< HLE implementation of system services. Each major service |
| @@ -58,6 +59,7 @@ enum class Class : ClassType { | |||
| 58 | Service_LDR, ///< The LDR (3ds dll loader) service | 59 | Service_LDR, ///< The LDR (3ds dll loader) service |
| 59 | Service_NIM, ///< The NIM (Network interface manager) service | 60 | Service_NIM, ///< The NIM (Network interface manager) service |
| 60 | Service_NWM, ///< The NWM (Network wlan manager) service | 61 | Service_NWM, ///< The NWM (Network wlan manager) service |
| 62 | Service_CAM, ///< The CAM (Camera) service | ||
| 61 | Service_CFG, ///< The CFG (Configuration) service | 63 | Service_CFG, ///< The CFG (Configuration) service |
| 62 | Service_DSP, ///< The DSP (DSP control) service | 64 | Service_DSP, ///< The DSP (DSP control) service |
| 63 | Service_HID, ///< The HID (Human interface device) service | 65 | Service_HID, ///< The HID (Human interface device) service |
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 4928c9bf2..02688e35e 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | #pragma once | 32 | #pragma once |
| 33 | 33 | ||
| 34 | #include <cmath> | 34 | #include <cmath> |
| 35 | #include <type_traits> | ||
| 35 | 36 | ||
| 36 | namespace Math { | 37 | namespace Math { |
| 37 | 38 | ||
| @@ -90,6 +91,7 @@ public: | |||
| 90 | { | 91 | { |
| 91 | x-=other.x; y-=other.y; | 92 | x-=other.x; y-=other.y; |
| 92 | } | 93 | } |
| 94 | template<typename Q = T,class = typename std::enable_if<std::is_signed<Q>::value>::type> | ||
| 93 | Vec2<decltype(-T{})> operator -() const | 95 | Vec2<decltype(-T{})> operator -() const |
| 94 | { | 96 | { |
| 95 | return MakeVec(-x,-y); | 97 | return MakeVec(-x,-y); |
| @@ -220,6 +222,7 @@ public: | |||
| 220 | { | 222 | { |
| 221 | x-=other.x; y-=other.y; z-=other.z; | 223 | x-=other.x; y-=other.y; z-=other.z; |
| 222 | } | 224 | } |
| 225 | template<typename Q = T,class = typename std::enable_if<std::is_signed<Q>::value>::type> | ||
| 223 | Vec3<decltype(-T{})> operator -() const | 226 | Vec3<decltype(-T{})> operator -() const |
| 224 | { | 227 | { |
| 225 | return MakeVec(-x,-y,-z); | 228 | return MakeVec(-x,-y,-z); |
| @@ -390,6 +393,7 @@ public: | |||
| 390 | { | 393 | { |
| 391 | x-=other.x; y-=other.y; z-=other.z; w-=other.w; | 394 | x-=other.x; y-=other.y; z-=other.z; w-=other.w; |
| 392 | } | 395 | } |
| 396 | template<typename Q = T,class = typename std::enable_if<std::is_signed<Q>::value>::type> | ||
| 393 | Vec4<decltype(-T{})> operator -() const | 397 | Vec4<decltype(-T{})> operator -() const |
| 394 | { | 398 | { |
| 395 | return MakeVec(-x,-y,-z,-w); | 399 | return MakeVec(-x,-y,-z,-w); |