2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
std::vector<std::string> Flags::EnabledFlags;
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
bool Flags::HasFlag(const std::string& flag)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2022-04-05 05:50:13 -04:00
|
|
|
Flags::ParseFlags();
|
2022-02-27 11:42:53 -05:00
|
|
|
|
|
|
|
for (const auto& entry : Flags::EnabledFlags)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
if (Utils::String::ToLower(entry) == Utils::String::ToLower(flag))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Flags::ParseFlags()
|
|
|
|
{
|
2022-04-05 05:50:13 -04:00
|
|
|
static auto flagsParsed = false;
|
|
|
|
if (flagsParsed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only parse flags once
|
|
|
|
flagsParsed = true;
|
2017-01-19 16:23:59 -05:00
|
|
|
int numArgs;
|
2022-02-27 11:42:53 -05:00
|
|
|
auto* const argv = CommandLineToArgvW(GetCommandLineW(), &numArgs);
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
if (argv)
|
|
|
|
{
|
2022-02-27 11:42:53 -05:00
|
|
|
for (auto i = 0; i < numArgs; ++i)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
std::wstring wFlag(argv[i]);
|
|
|
|
if (wFlag[0] == L'-')
|
|
|
|
{
|
2022-02-27 11:42:53 -05:00
|
|
|
wFlag.erase(wFlag.begin());
|
2022-04-05 05:50:13 -04:00
|
|
|
Flags::EnabledFlags.emplace_back(Utils::String::Convert(wFlag));
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalFree(argv);
|
|
|
|
}
|
2017-06-30 05:09:01 -04:00
|
|
|
|
|
|
|
// Workaround for wine
|
|
|
|
if (Utils::IsWineEnvironment() && Dedicated::IsEnabled() && !Flags::HasFlag("console") && !Flags::HasFlag("stdout"))
|
|
|
|
{
|
2022-04-05 05:50:13 -04:00
|
|
|
Flags::EnabledFlags.emplace_back("stdout");
|
2017-06-30 05:09:01 -04:00
|
|
|
}
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
}
|