stuff-from-scratch/src/core/CommandLineArgs.cpp
2023-01-12 11:54:08 +00:00

77 lines
1.5 KiB
C++

#include "CommandLineArgs.h"
#include "StringUtils.h"
#ifdef _WIN32
#include "Windows.h"
#endif
CommandLineArgs::CommandLineArgs()
: mArugments(),
mLaunchPath()
{
}
void CommandLineArgs::initialize(CommandLineArgs* args)
{
#ifdef _WIN32
int nArgs{ 0 };
auto szArglist = ::CommandLineToArgvW(::GetCommandLineW(), &nArgs);
if (szArglist == nullptr)
{
return;
}
std::vector<std::string> windowsArgs(nArgs);
for (int idx = 0; idx < nArgs; idx++)
{
windowsArgs[idx] = StringUtils::convert(szArglist[idx]);
}
::LocalFree(szArglist);
args->process(windowsArgs);
#endif
}
std::unique_ptr<CommandLineArgs> CommandLineArgs::Create()
{
return std::make_unique<CommandLineArgs>();
}
std::filesystem::path CommandLineArgs::getLaunchPath()
{
return mLaunchPath;
}
void CommandLineArgs::recordLaunchPath()
{
mLaunchPath = std::filesystem::current_path();
}
void CommandLineArgs::process(int argc, char *argv[])
{
for(int idx=0; idx<argc; idx++)
{
mArugments.push_back(std::string(argv[idx]));
}
}
void CommandLineArgs::process(const std::vector<std::string>& args)
{
mArugments = args;
}
std::vector<std::string> CommandLineArgs::getUserArgs() const
{
std::vector<std::string> user_args;
for(unsigned idx=1; idx<mArugments.size(); idx++)
{
user_args.push_back(mArugments[idx]);
}
return user_args;
}
const std::vector<std::string> CommandLineArgs::getArgs() const
{
return mArugments;
}