diff --git a/core/src/browser/browser.cc b/core/src/browser/browser.cc index 0878bc4..7db48b4 100644 --- a/core/src/browser/browser.cc +++ b/core/src/browser/browser.cc @@ -146,13 +146,7 @@ static void CEF_CALLBACK Hooked_OnBeforeCommandLineProcessing( // Extract args string. auto args = CefScopedStr(command_line->get_command_line_string(command_line)).cstr(); - auto chromiumArgs = config::getConfigValue(L"ChromiumArgs"); - if (!chromiumArgs.empty()) - { - args += L" " + chromiumArgs; - } - - if (!config::getConfigValueBool(L"NoProxyServer", true)) + if (config::options::AllowProxyServer()) { size_t pos = args.find(L"--no-proxy-server"); if (pos != std::wstring::npos) @@ -165,26 +159,26 @@ static void CEF_CALLBACK Hooked_OnBeforeCommandLineProcessing( OnBeforeCommandLineProcessing(self, process_type, command_line); - if (remote_debugging_port_ = config::getConfigValueInt(L"RemoteDebuggingPort", 0)) + if (remote_debugging_port_ = config::options::RemoteDebuggingPort()) { // Set remote debugging port. command_line->append_switch_with_value(command_line, &u"remote-debugging-port"_s, &CefStr(std::to_string(remote_debugging_port_))); } - if (config::getConfigValueBool(L"DisableWebSecurity", false)) + if (config::options::DisableWebSecurity()) { // Disable web security. command_line->append_switch(command_line, &u"disable-web-security"_s); } - if (config::getConfigValueBool(L"IgnoreCertificateErrors", false)) + if (config::options::IgnoreCertificateErrors()) { // Ignore invalid certs. command_line->append_switch(command_line, &u"ignore-certificate-errors"_s); } - if (config::getConfigValueBool(L"OptimizeClient", true)) + if (config::options::OptimizeClient()) { // Optimize Client. command_line->append_switch(command_line, &u"disable-async-dns"_s); @@ -207,7 +201,7 @@ static void CEF_CALLBACK Hooked_OnBeforeCommandLineProcessing( command_line->append_switch(command_line, &u"no-sandbox"_s); } - if (config::getConfigValueBool(L"SuperLowSpecMode", false)) + if (config::options::SuperLowSpecMode()) { // Super Low Spec Mode. command_line->append_switch(command_line, &u"disable-smooth-scrolling"_s); diff --git a/core/src/commons.h b/core/src/commons.h index 13d8567..7e105eb 100644 --- a/core/src/commons.h +++ b/core/src/commons.h @@ -321,9 +321,17 @@ namespace config path cacheDir(); path leagueDir(); - wstr getConfigValue(const wstr &key, const wstr &fallback = L""); - bool getConfigValueBool(const wstr &key, bool fallback); - int getConfigValueInt(const wstr &key, int fallback); + namespace options + { + bool AllowProxyServer(); + int RemoteDebuggingPort(); + + bool DisableWebSecurity(); + bool IgnoreCertificateErrors(); + + bool OptimizeClient(); + bool SuperLowSpecMode(); + } } namespace utils diff --git a/core/src/config.cc b/core/src/config.cc index 8bff8f5..ded188a 100644 --- a/core/src/config.cc +++ b/core/src/config.cc @@ -67,28 +67,28 @@ path config::leagueDir() return path.substr(0, path.find_last_of(L"/\\")); } -static map getConfigMap() +static map getConfigMap() { static bool cached = false; - static map map{}; + static map map{}; if (!cached) { - auto path = config::loaderDir() / L"config"; - std::wifstream file(path); + auto path = config::loaderDir() / "config"; + std::ifstream file(path); if (file.is_open()) { - std::wstring line; + std::string line; while (std::getline(file, line)) { - if (!line.empty() && line[0] != L';') + if (!line.empty() && line[0] != ';') { - size_t pos = line.find(L"="); - if (pos != std::wstring::npos) + size_t pos = line.find("="); + if (pos != std::string::npos) { - std::wstring key = line.substr(0, pos); - std::wstring value = line.substr(pos + 1); + std::string key = line.substr(0, pos); + std::string value = line.substr(pos + 1); map[key] = value; } } @@ -102,55 +102,74 @@ static map getConfigMap() return map; } -wstr config::getConfigValue(const wstr &key, const wstr &fallback) +static str getConfigValue(const char *key, const char *fallback) { auto map = getConfigMap(); auto it = map.find(key); - auto value = fallback; + str value = fallback; if (it != map.end()) value = it->second; -#ifdef _DEBUG - wprintf(L"config: %s -> %s\n", key.c_str(), value.c_str()); -#endif - return value; } -bool config::getConfigValueBool(const wstr &key, bool fallback) +static bool getConfigValueBool(const char *key, bool fallback) { auto map = getConfigMap(); auto it = map.find(key); - auto value = fallback; + bool value = fallback; if (it != map.end()) { - if (it->second == L"0" || it->second == L"false") + if (it->second == "0" || it->second == "false") value = false; - else if (it->second == L"1" || it->second == L"true") + else if (it->second == "1" || it->second == "true") value = true; } -#ifdef _DEBUG - wprintf(L"config: %s -> %s\n", key.c_str(), value ? L"true" : L"false"); -#endif - return value; } -int config::getConfigValueInt(const wstr &key, int fallback) +static int getConfigValueInt(const char *key, int fallback) { auto map = getConfigMap(); auto it = map.find(key); - auto value = fallback; + int value = fallback; if (it != map.end()) value = std::stoi(it->second); - -#ifdef _DEBUG - wprintf(L"config: %s -> %d\n", key.c_str(), value); -#endif return value; +} + +namespace config::options +{ + bool AllowProxyServer() + { + return getConfigValueBool("AllowProxyServer", false) + || !getConfigValueBool("NoProxyServer", true); + } + + int RemoteDebuggingPort() + { + return getConfigValueInt("RemoteDebuggingPort", 0); + } + bool DisableWebSecurity() + { + return getConfigValueBool("DisableWebSecurity", false); + } + bool IgnoreCertificateErrors() + { + return getConfigValueBool("IgnoreCertificateErrors", false); + } + + bool OptimizeClient() + { + return getConfigValueBool("OptimizeClient", true); + } + bool SuperLowSpecMode() + { + return getConfigValueBool("SuperLowSpecMode", false); + } } \ No newline at end of file diff --git a/core/src/renderer/renderer.cc b/core/src/renderer/renderer.cc index 8cb5183..658fda4 100644 --- a/core/src/renderer/renderer.cc +++ b/core/src/renderer/renderer.cc @@ -212,7 +212,7 @@ static void LoadPlugins(V8Object *window) pengu->set(&u"version"_s, version, V8_PROPERTY_ATTRIBUTE_READONLY); // Pengu.superPotato - auto superPotato = V8Value::boolean(config::getConfigValueBool(L"SuperLowSpecMode", false)); + auto superPotato = V8Value::boolean(config::options::SuperLowSpecMode()); pengu->set(&u"superPotato"_s, superPotato, V8_PROPERTY_ATTRIBUTE_READONLY); pengu->set(&u"os"_s, V8Value::string(&u"win"_s), V8_PROPERTY_ATTRIBUTE_READONLY);