summaryrefslogtreecommitdiffstats
path: root/src/common/file_util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/file_util.cpp')
-rw-r--r--src/common/file_util.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index b8dd92b65..b30a67ff9 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -706,6 +706,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) {
paths.emplace(UserPath::SDMCDir, user_path + SDMC_DIR DIR_SEP);
paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP);
paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP);
+ paths.emplace(UserPath::KeysDir, user_path + KEYS_DIR DIR_SEP);
// TODO: Put the logs in a better location for each OS
paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP);
}
@@ -736,6 +737,25 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) {
return paths[path];
}
+std::string GetHactoolConfigurationPath() {
+#ifdef _WIN32
+ PWSTR pw_local_path = nullptr;
+ if (SHGetKnownFolderPath(FOLDERID_Profile, 0, nullptr, &pw_local_path) != S_OK)
+ return "";
+ std::string local_path = Common::UTF16ToUTF8(pw_local_path);
+ CoTaskMemFree(pw_local_path);
+ return local_path + "\\.switch";
+#else
+ return GetHomeDirectory() + "/.switch";
+#endif
+}
+
+std::string GetNANDRegistrationDir(bool system) {
+ if (system)
+ return GetUserPath(UserPath::NANDDir) + "system/Contents/registered/";
+ return GetUserPath(UserPath::NANDDir) + "user/Contents/registered/";
+}
+
size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) {
return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
}
@@ -870,11 +890,21 @@ std::string_view RemoveTrailingSlash(std::string_view path) {
return path;
}
-std::string SanitizePath(std::string_view path_) {
+std::string SanitizePath(std::string_view path_, DirectorySeparator directory_separator) {
std::string path(path_);
- std::replace(path.begin(), path.end(), '\\', '/');
+ char type1 = directory_separator == DirectorySeparator::BackwardSlash ? '/' : '\\';
+ char type2 = directory_separator == DirectorySeparator::BackwardSlash ? '\\' : '/';
+
+ if (directory_separator == DirectorySeparator::PlatformDefault) {
+#ifdef _WIN32
+ type1 = '/';
+ type2 = '\\';
+#endif
+ }
+
+ std::replace(path.begin(), path.end(), type1, type2);
path.erase(std::unique(path.begin(), path.end(),
- [](char c1, char c2) { return c1 == '/' && c2 == '/'; }),
+ [type2](char c1, char c2) { return c1 == type2 && c2 == type2; }),
path.end());
return std::string(RemoveTrailingSlash(path));
}