diff --git a/Source/Engine/Platform/Web/WebPlatform.cpp b/Source/Engine/Platform/Web/WebPlatform.cpp index 286639a0b..24dcf4f16 100644 --- a/Source/Engine/Platform/Web/WebPlatform.cpp +++ b/Source/Engine/Platform/Web/WebPlatform.cpp @@ -8,6 +8,7 @@ #include "Engine/Core/Types/String.h" #include "Engine/Core/Types/Version.h" #include "Engine/Core/Types/Guid.h" +#include "Engine/Core/Collections/Dictionary.h" #include "Engine/Platform/CPUInfo.h" #include "Engine/Platform/MemoryStats.h" #if !BUILD_RELEASE @@ -15,6 +16,7 @@ #include "Engine/Utilities/StringConverter.h" #endif #include +#include #include #include #include @@ -236,6 +238,46 @@ void WebPlatform::Exit() { } +extern char** environ; + +void WebPlatform::GetEnvironmentVariables(Dictionary& result) +{ + char** s = environ; + for (; *s; s++) + { + char* var = *s; + int32 split = -1; + for (int32 i = 0; var[i]; i++) + { + if (var[i] == '=') + { + split = i; + break; + } + } + if (split == -1) + result[String(var)] = String::Empty; + else + result[String(var, split)] = String(var + split + 1); + } +} + +bool WebPlatform::GetEnvironmentVariable(const String& name, String& value) +{ + char* env = getenv(StringAsANSI<>(*name).Get()); + if (env) + { + value = String(env); + return false; + } + return true; +} + +bool WebPlatform::SetEnvironmentVariable(const String& name, const String& value) +{ + return setenv(StringAsANSI<>(*name).Get(), StringAsANSI<>(*value).Get(), true) != 0; +} + void* WebPlatform::LoadLibrary(const Char* filename) { return nullptr; diff --git a/Source/Engine/Platform/Web/WebPlatform.h b/Source/Engine/Platform/Web/WebPlatform.h index 7361d066a..bb9ec9d30 100644 --- a/Source/Engine/Platform/Web/WebPlatform.h +++ b/Source/Engine/Platform/Web/WebPlatform.h @@ -108,6 +108,9 @@ public: static void LogInfo(); static void Tick(); static void Exit(); + static void GetEnvironmentVariables(Dictionary& result); + static bool GetEnvironmentVariable(const String& name, String& value); + static bool SetEnvironmentVariable(const String& name, const String& value); static void* LoadLibrary(const Char* filename); static void FreeLibrary(void* handle); static void* GetProcAddress(void* handle, const char* symbol);