diff --git a/.gitmodules b/.gitmodules index 1259297..1324f5c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "qdevicewatcher"] path = externals/qdevicewatcher/qdevicewatcher url = https://github.com/wang-bin/qdevicewatcher.git +[submodule "inih"] + path = externals/inih/inih + url = https://github.com/benhoyt/inih.git diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 06ae28d..b8cc1fb 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -4,5 +4,8 @@ add_subdirectory(cryptopp) # fmt add_subdirectory(fmt) +# inih +add_subdirectory(inih) + # QDeviceWatcher add_subdirectory(qdevicewatcher) diff --git a/externals/inih/CMakeLists.txt b/externals/inih/CMakeLists.txt new file mode 100644 index 0000000..11dddb6 --- /dev/null +++ b/externals/inih/CMakeLists.txt @@ -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) diff --git a/externals/inih/inih b/externals/inih/inih new file mode 160000 index 0000000..4f251f0 --- /dev/null +++ b/externals/inih/inih @@ -0,0 +1 @@ +Subproject commit 4f251f0ff766052c342823dfa52a04f486cc4f94 diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 1880a54..0bab817 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -18,4 +18,4 @@ add_library(common STATIC thread.h ) -target_link_libraries(common PUBLIC fmt) +target_link_libraries(common PUBLIC fmt inih) diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 23490b4..fc3d7a3 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "common/assert.h" #include "common/common_funcs.h" #include "common/common_paths.h" @@ -724,6 +725,32 @@ UserPathType GetUserPathType() { #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) { if (!g_paths.empty()) { 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::NANDDir, user_path + NAND_DIR DIR_SEP); + UpdateUserPathFromConfig(); + g_paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP); // TODO: Put the logs in a better location for each OS g_paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP);