iw4x-client/src/Components/Modules/Flags.cpp

61 lines
1.0 KiB
C++
Raw Normal View History

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-02-27 11:42:53 -05:00
static auto parsed = false;
2017-03-10 17:41:01 -05:00
2022-02-27 11:42:53 -05:00
if (!parsed)
{
Flags::ParseFlags();
parsed = true;
}
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()
{
int numArgs;
2022-02-27 11:42:53 -05:00
auto* const argv = CommandLineToArgvW(GetCommandLineW(), &numArgs);
assert(Flags::EnabledFlags.empty());
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());
Flags::EnabledFlags.push_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"))
{
Flags::EnabledFlags.push_back("stdout");
}
2017-01-19 16:23:59 -05:00
}
Flags::Flags()
{
}
}