10#include "ll/api/base/CompilerPredefine.h"
11#include "ll/api/base/Macro.h"
12#include "ll/api/base/StdInt.h"
13#include "ll/api/data/TmWithMs.h"
14#include "ll/api/data/Version.h"
16namespace ll::inline utils::sys_utils {
20[[nodiscard]]
inline HandleT getCurrentModuleHandle() {
return internal::getCurrentModuleHandle(); }
22LLNDAPI HandleT getModuleHandle(
void* addr);
24LLNDAPI std::optional<std::filesystem::path> getModulePath(HandleT handle, HandleT process =
nullptr);
26LLNDAPI std::string getModuleFileName(HandleT handle, HandleT process =
nullptr);
28[[nodiscard]]
inline std::string getCallerModuleFileName(
void* addr = LL_RETURN_ADDRESS) {
29 return getModuleFileName(getModuleHandle(addr));
31LLNDAPI std::span<std::byte> getImageRange(std::string_view name =
"");
33LLNDAPI std::filesystem::path normalizePath(std::filesystem::path
const& path);
35LLNDAPI std::string getSystemLocaleCode();
37LLNDAPI std::string
const& getSystemName();
39LLNDAPI data::TmWithMs getLocalTime();
41LLNDAPI std::string getEnvironmentVariable(std::string_view name);
43LLAPI
bool setEnvironmentVariable(std::string_view name, std::string_view value);
45LLAPI
bool addOrSetEnvironmentVariable(std::string_view name, std::string_view value);
47LLNDAPI
bool isStdoutSupportAnsi();
51LLNDAPI data::Version getSystemVersion();
54 HandleT lib =
nullptr;
57 [[nodiscard]] DynamicLibrary() {}
58 [[nodiscard]] DynamicLibrary(std::filesystem::path
const& path) { load(path); }
63 DynamicLibrary(DynamicLibrary&&)
noexcept =
default;
64 DynamicLibrary& operator=(DynamicLibrary&&)
noexcept =
default;
65 DynamicLibrary(DynamicLibrary
const&) =
delete;
66 DynamicLibrary& operator=(DynamicLibrary
const&) =
delete;
68 LLAPI std::optional<std::system_error> load(std::filesystem::path
const& path)
noexcept;
69 LLAPI std::optional<std::system_error> free()
noexcept;
71 LLNDAPI
void* getAddress(
char const* name)
noexcept;
74 T getAddress(
char const* name)
noexcept {
75 return reinterpret_cast<T
>(getAddress(name));
78 [[nodiscard]]
constexpr HandleT handle()
const noexcept {
return lib; }
81template <std::invocable<
wchar_t*,
size_t,
size_t&> Fn>
82[[nodiscard]]
inline std::optional<std::wstring> adaptFixedSizeToAllocatedResult(Fn&& callback)
noexcept {
83 constexpr size_t arraySize = 256;
85 wchar_t value[arraySize]{};
86 size_t valueLengthNeededWithNull{};
88 std::optional<std::wstring> result{std::in_place};
90 if (!std::invoke(std::forward<Fn>(callback), value, arraySize, valueLengthNeededWithNull)) {
94 if (valueLengthNeededWithNull <= arraySize) {
95 return std::optional<std::wstring>{std::in_place, value, valueLengthNeededWithNull - 1};
98 result->resize(valueLengthNeededWithNull - 1);
99 if (!std::invoke(std::forward<Fn>(callback), result->data(), result->size() + 1, valueLengthNeededWithNull)) {
103 }
while (valueLengthNeededWithNull > result->size() + 1);
104 if (valueLengthNeededWithNull <= result->size()) {
105 result->resize(valueLengthNeededWithNull - 1);