diff --git a/src/common/utils/command_line.cpp b/src/common/utils/command_line.cpp new file mode 100644 index 0000000..c07d513 --- /dev/null +++ b/src/common/utils/command_line.cpp @@ -0,0 +1,35 @@ +#include "command_line.hpp" +#include "nt.hpp" + +#include +#include + +namespace utils::command_line +{ + template + constexpr std::unique_ptr make_unique_ptr(type* ptr, deleter&& del) + { + return std::unique_ptr(ptr, std::forward(del)); + } + + const std::vector& 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 vec(argc); + std::transform(argv, argv + argc, vec.begin(), [](const auto* path) + { + return std::filesystem::path(path); + }); + + return vec; + }(); + + return args; + } +} diff --git a/src/common/utils/command_line.hpp b/src/common/utils/command_line.hpp new file mode 100644 index 0000000..b1b13b0 --- /dev/null +++ b/src/common/utils/command_line.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +namespace utils::command_line +{ + [[nodiscard]] const std::vector& get_args(); +} \ No newline at end of file