Added functions to parse the command line arguments.

This commit is contained in:
Caball 2024-12-30 23:28:21 +01:00
parent 51e831cbfe
commit 1db89c64c6
2 changed files with 44 additions and 0 deletions

View 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;
}
}

View File

@ -0,0 +1,9 @@
#pragma once
#include <filesystem>
#include <vector>
namespace utils::command_line
{
[[nodiscard]] const std::vector<std::filesystem::path>& get_args();
}