diff --git a/Source/sys-clk-OC/sysmodule/src/clocks.h b/Source/sys-clk-OC/sysmodule/src/clocks.h index 6779bf54..0d1319c6 100644 --- a/Source/sys-clk-OC/sysmodule/src/clocks.h +++ b/Source/sys-clk-OC/sysmodule/src/clocks.h @@ -20,7 +20,7 @@ class Clocks { public: static inline uint32_t boostCpuFreq = 1785000000; - static inline uint32_t maxMemFreq = MAX_MEM_CLOCK; + static inline uint32_t maxMemFreq = 0; static void GetRange(SysClkModule module, SysClkProfile profile, uint32_t** min, uint32_t** max); static Result GetTable(SysClkModule module, SysClkProfile profile, SysClkFrequencyTable* out_table); diff --git a/Source/sys-clk-OC/sysmodule/src/config.cpp b/Source/sys-clk-OC/sysmodule/src/config.cpp index 6e48d470..4890bde2 100644 --- a/Source/sys-clk-OC/sysmodule/src/config.cpp +++ b/Source/sys-clk-OC/sysmodule/src/config.cpp @@ -47,6 +47,9 @@ Config::~Config() Config *Config::CreateDefault() { + if (R_FAILED(FileUtils::mkdir_p(FILE_CONFIG_DIR))) + ERROR_THROW("Cannot create " FILE_CONFIG_DIR); + return new Config(FILE_CONFIG_DIR "/config.ini"); } diff --git a/Source/sys-clk-OC/sysmodule/src/file_utils.cpp b/Source/sys-clk-OC/sysmodule/src/file_utils.cpp index d6b58b9b..95338f23 100644 --- a/Source/sys-clk-OC/sysmodule/src/file_utils.cpp +++ b/Source/sys-clk-OC/sysmodule/src/file_utils.cpp @@ -305,3 +305,57 @@ Result FileUtils::CustParser(const char* filepath, size_t filesize) { return ParseError_Success; } + +Result FileUtils::mkdir_p(const char* dirpath) { + // https://gist.github.com/JonathonReinhart/8c0d90191c38af2dcadb102c4e202950 + auto mkdir_wrapper = [](char* path) { + errno = 0; + size_t len = strnlen(path, 0x1000); + bool isCWDir = (len == 0) || (len == 1 && (path[0] == '.' || path[0] == '/')); + if (isCWDir) + return 0; + + if (R_SUCCEEDED(mkdir(path, S_IRWXU))) + return 0; + + struct stat st; + if (errno == EEXIST && + R_SUCCEEDED(stat(path, &st)) && + S_ISDIR(st.st_mode)) { + errno = 0; + return 0; + } + + errno = ENOTDIR; + return -1; + }; + + errno = 0; + Result res = 0; + + size_t path_len = strnlen(dirpath, 0x1000); + char* path_copy = new char[path_len]; + memcpy(path_copy, dirpath, path_len); + char* p = path_copy; + while (*p) { + if (*p == '/') { + // Temporarily truncate + *p = '\0'; + + if (R_FAILED(mkdir_wrapper(path_copy))) { + res = -1; + goto end; + } + + *p = '/'; + } + p++; + } + + if (R_FAILED(mkdir_wrapper(path_copy))) + res = -1; + + end: + delete[] path_copy; + return res; +} diff --git a/Source/sys-clk-OC/sysmodule/src/file_utils.h b/Source/sys-clk-OC/sysmodule/src/file_utils.h index e3b9fed2..b2ec0c00 100644 --- a/Source/sys-clk-OC/sysmodule/src/file_utils.h +++ b/Source/sys-clk-OC/sysmodule/src/file_utils.h @@ -36,6 +36,7 @@ class FileUtils static void LogLine(const char *format, ...); static void WriteContextToCsv(const SysClkContext* context); static void ParseLoaderKip(); + static Result mkdir_p(const char* dirpath); protected: typedef struct CustTable { uint8_t cust[4] = {'C', 'U', 'S', 'T'};