Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/UUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

#include "Prefix/StdAfx.h"

#if _LINUX
#if defined(__EMSCRIPTEN__)
// Emscripten/WASM: no libuuid available, we generate random (v4) UUIDs
#include <random>
#elif _LINUX
// If this include fails, run this command to install it:
// sudo apt-get install uuid-dev
#include <uuid/uuid.h>
Expand Down Expand Up @@ -309,6 +312,17 @@ void VWFC::Tools::VWUUID::New()
fData[13] = guid.Data4[5];
fData[14] = guid.Data4[6];
fData[15] = guid.Data4[7];
#elif defined(__EMSCRIPTEN__)
// Generate a random (version 4) UUID.
// std::random_device maps to a secure entropy source in Emscripten
{
std::random_device rd;
std::uniform_int_distribution<unsigned int> dist(0, 255);
for (size_t i = 0; i < 16; i++) { fData[i] = (Uint8)dist(rd); }

fData[6] = (Uint8)((fData[6] & 0x0F) | 0x40); // version 4
fData[8] = (Uint8)((fData[8] & 0x3F) | 0x80); // variant 10xx
}
#elif _LINUX
uuid_t myUUID;
uuid_generate_time_safe( myUUID );
Expand Down
6 changes: 6 additions & 0 deletions src/Wrapper/FilingWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ bool VectorworksMVR::Filing::GetFolderAppDataPath(TXString& outPath)

if(!result) return false;
outPath = TXString(buffer);
#elif defined(__EMSCRIPTEN__)
// Emscripten/WASM: getpwuid() returns NULL; use $HOME or the default
// MEMFS home directory instead
const char* homedir = getenv("HOME");
if (homedir == nullptr || homedir[0] == 0) { homedir = "/home/web_user"; }
outPath = TXString(homedir);
#elif _LINUX
// LINUX_IMPLEMENTATION - done
struct passwd *pw = getpwuid(getuid());
Expand Down
4 changes: 2 additions & 2 deletions src/XmlFileHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ bool SceneData::GdtfConverter::ConvertColorArray(TXString values, const IXMLFile
return valueStr;
}

#ifdef IS64BIT
#if defined(IS64BIT) || defined(__EMSCRIPTEN__)
/*static*/ TXString GdtfConverter::ConvertInteger(Uint32 value)
{
TXString valueStr;
Expand Down Expand Up @@ -449,7 +449,7 @@ bool SceneData::GdtfConverter::ConvertColorArray(TXString values, const IXMLFile
return true;
}

#ifdef IS64BIT
#if defined(IS64BIT) || defined(__EMSCRIPTEN__)
/*static*/ bool GdtfConverter::ConvertInteger(const TXString& value, const IXMLFileNodePtr& node, Uint32& intValue)
{
if(value.IsEmpty()) return false;
Expand Down
4 changes: 2 additions & 2 deletions src/XmlFileHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace SceneData
static TXString ConvertDouble(double value);
static TXString ConvertDoubleArray(TDoubleArray& values, bool includeBrackets);
static TXString ConvertInteger(Sint32 value);
#ifdef IS64BIT
#if defined(IS64BIT) || defined(__EMSCRIPTEN__)
static TXString ConvertInteger(Uint32 value);
#endif
static TXString ConvertDmxBreak(Sint32 value);
Expand Down Expand Up @@ -118,7 +118,7 @@ namespace SceneData
static bool ConvertPrimitiveType( const TXString& value, const IXMLFileNodePtr& node, EGdtfModel_PrimitiveType& type);
static bool ConvertLampeType( const TXString& value, const IXMLFileNodePtr& node, EGdtfLampType& lampType);
static bool ConvertInteger( const TXString& value, const IXMLFileNodePtr& node, Sint32& intValue);
#ifdef IS64BIT
#if defined(IS64BIT) || defined(__EMSCRIPTEN__)
static bool ConvertInteger( const TXString& value, const IXMLFileNodePtr& node, Uint32& intValue);
#endif
static bool ConvertDmxBreak( const TXString& value, const IXMLFileNodePtr& node, Sint32& intValue);
Expand Down