Create config dir if it does not exist; Fixed maxMemFreq detection

This commit is contained in:
KazushiM
2022-10-31 17:22:05 +08:00
parent 6a1ac29733
commit 72a8421df6
4 changed files with 59 additions and 1 deletions

View File

@@ -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);

View File

@@ -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");
}

View File

@@ -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;
}

View File

@@ -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'};