forked from alterware/iw6-mod
Added functions to parse the command line arguments.
This commit is contained in:
parent
51e831cbfe
commit
1db89c64c6
35
src/common/utils/command_line.cpp
Normal file
35
src/common/utils/command_line.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include "command_line.hpp"
|
||||||
|
#include "nt.hpp"
|
||||||
|
|
||||||
|
#include <shellapi.h>
|
||||||
|
#include <winrt/Windows.Foundation.h>
|
||||||
|
|
||||||
|
namespace utils::command_line
|
||||||
|
{
|
||||||
|
template <typename type, typename deleter>
|
||||||
|
constexpr std::unique_ptr<type, deleter> make_unique_ptr(type* ptr, deleter&& del)
|
||||||
|
{
|
||||||
|
return std::unique_ptr<type, deleter&&>(ptr, std::forward<deleter>(del));
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<std::filesystem::path>& get_args()
|
||||||
|
{
|
||||||
|
static const auto args = []()
|
||||||
|
{
|
||||||
|
auto argc = 0;
|
||||||
|
const auto cmd_line = winrt::check_pointer(::GetCommandLineW());
|
||||||
|
const auto up = make_unique_ptr(winrt::check_pointer(::CommandLineToArgvW(cmd_line, &argc)), ::LocalFree);
|
||||||
|
const auto argv = up.get();
|
||||||
|
|
||||||
|
std::vector<std::filesystem::path> vec(argc);
|
||||||
|
std::transform(argv, argv + argc, vec.begin(), [](const auto* path)
|
||||||
|
{
|
||||||
|
return std::filesystem::path(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
return vec;
|
||||||
|
}();
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
}
|
9
src/common/utils/command_line.hpp
Normal file
9
src/common/utils/command_line.hpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace utils::command_line
|
||||||
|
{
|
||||||
|
[[nodiscard]] const std::vector<std::filesystem::path>& get_args();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user