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

62 lines
1.0 KiB
C++
Raw Normal View History

2017-01-19 16:23:59 -05:00
#include "STDInclude.hpp"
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
{
2017-03-10 17:41:01 -05:00
Flags::ParseFlags();
2017-01-19 16:23:59 -05:00
for (auto entry : Flags::EnabledFlags)
{
if (Utils::String::ToLower(entry) == Utils::String::ToLower(flag))
{
return true;
}
}
return false;
}
void Flags::ParseFlags()
{
2017-03-10 17:41:01 -05:00
static bool flagsParsed = false;
if (flagsParsed) return;
flagsParsed = true;
2017-01-19 16:23:59 -05:00
int numArgs;
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &numArgs);
if (argv)
{
for (int i = 0; i < numArgs; ++i)
{
std::wstring wFlag(argv[i]);
if (wFlag[0] == L'-')
{
Flags::EnabledFlags.push_back(std::string(++wFlag.begin(), wFlag.end()));
}
}
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()
{
Flags::ParseFlags();
}
Flags::~Flags()
{
Flags::EnabledFlags.clear();
}
}