Jamie Reece Wilson
bdec6ff8ba
[+] AuProcess::EnvironmentGetOne [+] AuProcess::EnvironmentSetOne [+] AuProcess::EnvironmentRemoveOne [+] AuProcess::EnvironmentRemoveMany [+] AuProcess::EnvironmentSetMany [+] AuProcess::GetProcessStartupTimeNS [+] AuProcess::GetProcessStartupTimeMS [*] Note WakeOnAddress on all platforms [*] Updated READMEs
132 lines
3.3 KiB
C++
132 lines
3.3 KiB
C++
/***
|
|
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuProcessEnvironment.NT.cpp
|
|
Date: 2023-7-10
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "AuProcessEnvironment.hpp"
|
|
#include "AuProcessEnvironment.NT.hpp"
|
|
|
|
namespace Aurora::Process
|
|
{
|
|
AUKN_SYM AuList<AuPair<AuString, AuString>> EnvironmentGetAll()
|
|
{
|
|
AuList<AuPair<AuString, AuString>> ret;
|
|
|
|
auto pWideStrings = ::GetEnvironmentStringsW();
|
|
auto pFreeBase = pWideStrings;
|
|
|
|
while (auto uLength = ::wcslen(pWideStrings))
|
|
{
|
|
auto utfString = AuLocale::ConvertFromWChar(pWideStrings, uLength);
|
|
|
|
if (utfString.empty())
|
|
{
|
|
::FreeEnvironmentStringsW(pFreeBase);
|
|
SysPushErrorNested();
|
|
return {};
|
|
}
|
|
|
|
try
|
|
{
|
|
auto optSplit = EnvironmentSplitString(utfString);
|
|
if (optSplit)
|
|
{
|
|
ret.push_back(optSplit.value());
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
::FreeEnvironmentStringsW(pFreeBase);
|
|
SysPushErrorCatch();
|
|
return {};
|
|
}
|
|
|
|
|
|
pWideStrings += uLength;
|
|
pWideStrings += 1;
|
|
}
|
|
|
|
::FreeEnvironmentStringsW(pFreeBase);
|
|
|
|
return ret;
|
|
}
|
|
|
|
AUKN_SYM AuOptional<AuString> EnvironmentGetOne(const AuString &key)
|
|
{
|
|
auto keyString = AuLocale::ConvertFromUTF8(key);
|
|
|
|
if (keyString.empty())
|
|
{
|
|
return {};
|
|
}
|
|
|
|
auto uLength = ::GetEnvironmentVariableW(keyString.c_str(),
|
|
nullptr,
|
|
0);
|
|
|
|
if (uLength == 0)
|
|
{
|
|
if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
|
|
{
|
|
SysPushErrorResourceMissing();
|
|
return {};
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
std::wstring temp;
|
|
|
|
if (!AuTryResize(temp, uLength))
|
|
{
|
|
SysPushErrorMemory();
|
|
return {};
|
|
}
|
|
|
|
uLength = ::GetEnvironmentVariableW(keyString.c_str(),
|
|
temp.data(),
|
|
temp.size());
|
|
|
|
if (!uLength)
|
|
{
|
|
SysPushErrorGeneric();
|
|
return {};
|
|
}
|
|
|
|
temp.resize(uLength);
|
|
return AuLocale::ConvertFromWChar(temp.c_str());
|
|
}
|
|
|
|
AUKN_SYM bool EnvironmentSetOne(const AuString &key, const AuString &value)
|
|
{
|
|
auto keyString = AuLocale::ConvertFromUTF8(key);
|
|
auto valString = AuLocale::ConvertFromUTF8(value);
|
|
|
|
if (keyString.empty() || valString.empty())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return ::SetEnvironmentVariableW(keyString.c_str(),
|
|
valString.c_str());
|
|
}
|
|
|
|
AUKN_SYM bool EnvironmentRemoveOne(const AuString &key)
|
|
{
|
|
std::wstring keyString;
|
|
|
|
if ((keyString = AuLocale::ConvertFromUTF8(key)).size())
|
|
{
|
|
return ::SetEnvironmentVariableW(keyString.c_str(), nullptr);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
} |