summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/file_util.cpp72
-rw-r--r--src/common/file_util.h31
-rw-r--r--src/common/logging/backend.cpp1
-rw-r--r--src/common/logging/log.h1
-rw-r--r--src/common/vector_math.h4
5 files changed, 59 insertions, 50 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 1e0d33313..4c7113390 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -420,11 +420,13 @@ bool CreateEmptyFile(const std::string &filename)
}
-int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int(const std::string&, const std::string&)> callback)
+bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback)
{
LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str());
+
// How many files + directories we found
- int found_entries = 0;
+ unsigned found_entries = 0;
+
#ifdef _WIN32
// Find the first file in the directory.
WIN32_FIND_DATA ffd;
@@ -432,7 +434,7 @@ int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int
HANDLE handle_find = FindFirstFile(Common::UTF8ToTStr(directory + "\\*").c_str(), &ffd);
if (handle_find == INVALID_HANDLE_VALUE) {
FindClose(handle_find);
- return found_entries;
+ return false;
}
// windows loop
do {
@@ -442,25 +444,20 @@ int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int
DIR *dirp = opendir(directory.c_str());
if (!dirp)
- return 0;
+ return false;
// non windows loop
while (!readdir_r(dirp, &dirent, &result) && result) {
const std::string virtual_name(result->d_name);
#endif
- // check for "." and ".."
- if (((virtual_name[0] == '.') && (virtual_name[1] == '\0')) ||
- ((virtual_name[0] == '.') && (virtual_name[1] == '.') &&
- (virtual_name[2] == '\0')))
+
+ if (virtual_name == "." || virtual_name == "..")
continue;
- int ret = callback(directory, virtual_name);
- if (ret < 0) {
- if (ret != -1)
- found_entries = ret;
+ unsigned ret_entries;
+ if (!callback(&ret_entries, directory, virtual_name))
break;
- }
- found_entries += ret;
+ found_entries += ret_entries;
#ifdef _WIN32
} while (FindNextFile(handle_find, &ffd) != 0);
@@ -469,16 +466,18 @@ int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int
}
closedir(dirp);
#endif
- // Return number of entries found.
- return found_entries;
+
+ // num_entries_out is allowed to be specified nullptr, in which case we shouldn't try to set it
+ if (num_entries_out != nullptr)
+ *num_entries_out = found_entries;
}
-int ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry)
+unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry)
{
- const auto callback = [&parent_entry](const std::string& directory,
- const std::string& virtual_name) -> int {
+ const auto callback = [&parent_entry](unsigned* num_entries_out,
+ const std::string& directory,
+ const std::string& virtual_name) -> bool {
FSTEntry entry;
- int found_entries = 0;
entry.virtualName = virtual_name;
entry.physicalName = directory + DIR_SEP + virtual_name;
@@ -486,41 +485,40 @@ int ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry)
entry.isDirectory = true;
// is a directory, lets go inside
entry.size = ScanDirectoryTree(entry.physicalName, entry);
- found_entries += (int)entry.size;
+ *num_entries_out += (int)entry.size;
} else { // is a file
entry.isDirectory = false;
entry.size = GetSize(entry.physicalName);
}
- ++found_entries;
+ (*num_entries_out)++;
+
// Push into the tree
parent_entry.children.push_back(entry);
- return found_entries;
+ return true;
};
- return ScanDirectoryTreeAndCallback(directory, callback);
+ unsigned num_entries;
+ return ForeachDirectoryEntry(&num_entries, directory, callback) ? num_entries : 0;
}
bool DeleteDirRecursively(const std::string &directory)
{
- const static auto callback = [](const std::string& directory,
- const std::string& virtual_name) -> int {
+ const static auto callback = [](unsigned* num_entries_out,
+ const std::string& directory,
+ const std::string& virtual_name) -> bool {
std::string new_path = directory + DIR_SEP_CHR + virtual_name;
- if (IsDirectory(new_path)) {
- if (!DeleteDirRecursively(new_path)) {
- return -2;
- }
- } else if (!Delete(new_path)) {
- return -2;
- }
- return 0;
+ if (IsDirectory(new_path))
+ return DeleteDirRecursively(new_path);
+
+ return Delete(new_path);
};
- if (ScanDirectoryTreeAndCallback(directory, callback) == -2) {
+ if (!ForeachDirectoryEntry(nullptr, directory, callback))
return false;
- }
- FileUtil::DeleteDir(directory);
+ // Delete the outermost directory
+ FileUtil::DeleteDir(directory);
return true;
}
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);
bool CreateEmptyFile(const std::string &filename);
/**
- * Scans the directory tree, calling the callback for each file/directory found.
- * The callback must return the number of files and directories which the provided path contains.
- * If the callback's return value is -1, the callback loop is broken immediately.
- * If the callback's return value is otherwise negative, the callback loop is broken immediately
- * and the callback's return value is returned from this function (to allow for error handling).
- * @param directory the parent directory to start scanning from
- * @param callback The callback which will be called for each file/directory. It is called
- * with the arguments (const std::string& directory, const std::string& virtual_name).
- * The `directory `parameter is the path to the directory which contains the file/directory.
- * The `virtual_name` parameter is the incomplete file path, without any directory info.
- * @return the total number of files/directories found
+ * @param num_entries_out to be assigned by the callable with the number of iterated directory entries, never null
+ * @param directory the path to the enclosing directory
+ * @param virtual_name the entry name, without any preceding directory info
+ * @return whether handling the entry succeeded
+ */
+using DirectoryEntryCallable = std::function<bool(unsigned* num_entries_out,
+ const std::string& directory,
+ const std::string& virtual_name)>;
+
+/**
+ * Scans a directory, calling the callback for each file/directory contained within.
+ * If the callback returns failure, scanning halts and this function returns failure as well
+ * @param num_entries_out assigned by the function with the number of iterated directory entries, can be null
+ * @param directory the directory to scan
+ * @param callback The callback which will be called for each entry
+ * @return whether scanning the directory succeeded
*/
-int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int(const std::string&, const std::string&)> callback);
+bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback);
/**
* Scans the directory tree, storing the results.
@@ -118,7 +123,7 @@ int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int
* @param parent_entry FSTEntry where the filesystem tree results will be stored.
* @return the total number of files/directories found
*/
-int ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry);
+unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry);
// deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string &directory);
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 92e8e742d..21a9ae8d0 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -29,6 +29,7 @@ namespace Log {
SUB(Debug, Emulated) \
SUB(Debug, GPU) \
SUB(Debug, Breakpoint) \
+ SUB(Debug, GDBStub) \
CLS(Kernel) \
SUB(Kernel, SVC) \
CLS(Service) \
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index 5fd3bd7f5..43f0c59e4 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -43,6 +43,7 @@ enum class Class : ClassType {
Debug_Emulated, ///< Debug messages from the emulated programs
Debug_GPU, ///< GPU debugging tools
Debug_Breakpoint, ///< Logging breakpoints and watchpoints
+ Debug_GDBStub, ///< GDB Stub
Kernel, ///< The HLE implementation of the CTR kernel
Kernel_SVC, ///< Kernel system calls
Service, ///< HLE implementation of system services. Each major 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 @@
#pragma once
#include <cmath>
+#include <type_traits>
namespace Math {
@@ -90,6 +91,7 @@ public:
{
x-=other.x; y-=other.y;
}
+ template<typename Q = T,class = typename std::enable_if<std::is_signed<Q>::value>::type>
Vec2<decltype(-T{})> operator -() const
{
return MakeVec(-x,-y);
@@ -220,6 +222,7 @@ public:
{
x-=other.x; y-=other.y; z-=other.z;
}
+ template<typename Q = T,class = typename std::enable_if<std::is_signed<Q>::value>::type>
Vec3<decltype(-T{})> operator -() const
{
return MakeVec(-x,-y,-z);
@@ -390,6 +393,7 @@ public:
{
x-=other.x; y-=other.y; z-=other.z; w-=other.w;
}
+ template<typename Q = T,class = typename std::enable_if<std::is_signed<Q>::value>::type>
Vec4<decltype(-T{})> operator -() const
{
return MakeVec(-x,-y,-z,-w);