Misc changes. #13
							
								
								
									
										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(); | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user