Skip to content

Commit

Permalink
improve config options & remove ChromiumArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
nomi-san committed Jan 12, 2024
1 parent efbe524 commit 3632edc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 46 deletions.
18 changes: 6 additions & 12 deletions core/src/browser/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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);
Expand Down
14 changes: 11 additions & 3 deletions core/src/commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
79 changes: 49 additions & 30 deletions core/src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,28 @@ path config::leagueDir()
return path.substr(0, path.find_last_of(L"/\\"));
}

static map<wstr, wstr> getConfigMap()
static map<str, str> getConfigMap()
{
static bool cached = false;
static map<wstr, wstr> map{};
static map<str, str> 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;
}
}
Expand All @@ -102,55 +102,74 @@ static map<wstr, wstr> 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);
}
}
2 changes: 1 addition & 1 deletion core/src/renderer/renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3632edc

Please sign in to comment.