This commit is contained in:
Diavolo 2022-04-05 11:50:13 +02:00
parent 3982dfe5cc
commit 7e8d14120d
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
2 changed files with 13 additions and 13 deletions

View File

@ -5,14 +5,8 @@ namespace Components
std::vector<std::string> Flags::EnabledFlags;
bool Flags::HasFlag(const std::string& flag)
{
static auto parsed = false;
if (!parsed)
{
Flags::ParseFlags();
parsed = true;
}
for (const auto& entry : Flags::EnabledFlags)
{
@ -27,11 +21,17 @@ namespace Components
void Flags::ParseFlags()
{
static auto flagsParsed = false;
if (flagsParsed)
{
return;
}
// Only parse flags once
flagsParsed = true;
int numArgs;
auto* const argv = CommandLineToArgvW(GetCommandLineW(), &numArgs);
assert(Flags::EnabledFlags.empty());
if (argv)
{
for (auto i = 0; i < numArgs; ++i)
@ -40,7 +40,7 @@ namespace Components
if (wFlag[0] == L'-')
{
wFlag.erase(wFlag.begin());
Flags::EnabledFlags.push_back(Utils::String::Convert(wFlag));
Flags::EnabledFlags.emplace_back(Utils::String::Convert(wFlag));
}
}
@ -50,7 +50,7 @@ namespace Components
// Workaround for wine
if (Utils::IsWineEnvironment() && Dedicated::IsEnabled() && !Flags::HasFlag("console") && !Flags::HasFlag("stdout"))
{
Flags::EnabledFlags.push_back("stdout");
Flags::EnabledFlags.emplace_back("stdout");
}
}

View File

@ -107,9 +107,9 @@ namespace Utils
void SetEnvironment()
{
wchar_t exeName[512];
GetModuleFileNameW(GetModuleHandle(nullptr), exeName, sizeof(exeName) / 2);
GetModuleFileNameW(GetModuleHandle(nullptr), exeName, sizeof(exeName) / sizeof(wchar_t));
wchar_t* exeBaseName = wcsrchr(exeName, L'\\');
auto* exeBaseName = wcsrchr(exeName, L'\\');
exeBaseName[0] = L'\0';
SetCurrentDirectoryW(exeName);