Support SDMC/NAND path redirecting

Added inih as an external.
This commit is contained in:
Pengfei
2021-07-15 16:28:33 +08:00
parent e41151420f
commit 374470cd60
6 changed files with 46 additions and 1 deletions
+3
View File
@@ -7,3 +7,6 @@
[submodule "qdevicewatcher"] [submodule "qdevicewatcher"]
path = externals/qdevicewatcher/qdevicewatcher path = externals/qdevicewatcher/qdevicewatcher
url = https://github.com/wang-bin/qdevicewatcher.git url = https://github.com/wang-bin/qdevicewatcher.git
[submodule "inih"]
path = externals/inih/inih
url = https://github.com/benhoyt/inih.git
+3
View File
@@ -4,5 +4,8 @@ add_subdirectory(cryptopp)
# fmt # fmt
add_subdirectory(fmt) add_subdirectory(fmt)
# inih
add_subdirectory(inih)
# QDeviceWatcher # QDeviceWatcher
add_subdirectory(qdevicewatcher) add_subdirectory(qdevicewatcher)
+9
View File
@@ -0,0 +1,9 @@
add_library(inih
inih/ini.c
inih/ini.h
inih/cpp/INIReader.cpp
inih/cpp/INIReader.h
)
target_include_directories(inih INTERFACE .)
target_compile_definitions(inih PRIVATE -DINI_MAX_LINE=1000)
Vendored Submodule
+1
Submodule externals/inih/inih added at 4f251f0ff7
+1 -1
View File
@@ -18,4 +18,4 @@ add_library(common STATIC
thread.h thread.h
) )
target_link_libraries(common PUBLIC fmt) target_link_libraries(common PUBLIC fmt inih)
+29
View File
@@ -6,6 +6,7 @@
#include <array> #include <array>
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
#include <inih/cpp/INIReader.h>
#include "common/assert.h" #include "common/assert.h"
#include "common/common_funcs.h" #include "common/common_funcs.h"
#include "common/common_paths.h" #include "common/common_paths.h"
@@ -724,6 +725,32 @@ UserPathType GetUserPathType() {
#endif #endif
} }
static void UpdateUserPathFromConfig() {
// Locate config file. Choose one that exists, or, if both don't exist, quit.
std::string config_path = g_paths[UserPath::ConfigDir] + "qt-config.ini";
std::string section_name = "Data%20Storage"; // For whatever reason they're different
if (!Exists(config_path)) {
config_path = g_paths[UserPath::ConfigDir] + "sdl2-config.ini";
section_name = "Data Storage";
if (!Exists(config_path)) {
return;
}
}
INIReader ini(config_path);
const auto nand_dir = ini.GetString(section_name, "nand_directory", "");
if (!nand_dir.empty()) {
LOG_INFO(Common_Filesystem, "Using NAND directory {}", nand_dir);
g_paths[UserPath::NANDDir] = nand_dir + DIR_SEP;
}
const auto sdmc_dir = ini.GetString(section_name, "sdmc_directory", "");
if (!sdmc_dir.empty()) {
LOG_INFO(Common_Filesystem, "Using SDMC directory {}", sdmc_dir);
g_paths[UserPath::SDMCDir] = sdmc_dir + DIR_SEP;
}
}
void SetUserPath(const std::string& path) { void SetUserPath(const std::string& path) {
if (!g_paths.empty()) { if (!g_paths.empty()) {
g_paths.clear(); g_paths.clear();
@@ -780,6 +807,8 @@ void SetUserPath(const std::string& path) {
} }
g_paths.emplace(UserPath::SDMCDir, user_path + SDMC_DIR DIR_SEP); g_paths.emplace(UserPath::SDMCDir, user_path + SDMC_DIR DIR_SEP);
g_paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP); g_paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP);
UpdateUserPathFromConfig();
g_paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP); g_paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP);
// TODO: Put the logs in a better location for each OS // TODO: Put the logs in a better location for each OS
g_paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP); g_paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP);