diff --git a/src/streams/netstream.cpp b/src/streams/netstream.cpp index 91e9ac9c607df3e8af2581978df96bf0329d4b41..04d3c49078ee88352feab3855d94aeddb1235a04 100644 --- a/src/streams/netstream.cpp +++ b/src/streams/netstream.cpp @@ -98,7 +98,7 @@ Net::Net(const std::string &uri, ftl::net::Universe *net, bool host) : name_.resize(1024); #ifdef WIN32 DWORD size = name_.capacity(); - GetComputerName(name_.data(), &size); + GetComputerNameA(name_.data(), &size); #else gethostname(name_.data(), name_.capacity()); #endif diff --git a/src/uri.cpp b/src/uri.cpp index a0310b8dbeb321101b7846be3d2e612f613d97d2..d28bbba8eb4f4531d1574175aa4f768fa6ccc058 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -14,15 +14,45 @@ #include <ftl/lib/loguru.hpp> #include <ftl/exception.hpp> -#ifndef WIN32 -#include <unistd.h> -#else +#if defined(WIN32) #include <direct.h> #include <shlwapi.h> #pragma comment(lib, "Shlwapi.lib") + +#else +#include <unistd.h> + #endif +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +// UWP/Windows Store app +#include <Windows.h> + +char* getcwd(char* buffer, int size) { + return _getcwd(buffer, size); +} + +std::string get_home_dir() { + return std::string(); // TODO +} + +#else // non-UWP + +std::string get_home_dir() { +#if defined(WIN32) + const char* homeDrive = std::getenv("HOMEDRIVE"); + const char* homePath = std::getenv("HOMEPATH"); + return string((homeDrive) ? homeDrive : "") + + string((homePath) ? homePath : ""); +#else + return std::getenv("HOME"); +#endif +} + +#endif // UWP + + using ftl::URI; using ftl::uri_t; using std::string; @@ -79,20 +109,13 @@ void URI::_parse(uri_t puri) { } else if (suri[0] == '/') { suri = std::string("file://") + suri; } else if (suri[0] == '~') { -#ifdef WIN32 - const char *homeDrive = std::getenv("HOMEDRIVE"); - const char *homePath = std::getenv("HOMEPATH"); - suri = string("file://") - + string((homeDrive) ? homeDrive : "") - + string((homePath) ? homePath : "") - + suri.substr(1); -#else - const char *homeDir = std::getenv("HOME"); - suri = string("file://") + string((homeDir) ? homeDir : "") + suri.substr(1); -#endif + suri = string("file://") + get_home_dir() + suri.substr(1); } -#ifdef WIN32 +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) + // TODO + +#elif defined(WIN32) if (std::regex_match(puri, std::regex("^[A-Z]:.*"))) { suri.resize(1024); DWORD size = suri.size(); @@ -210,7 +233,11 @@ std::string URI::toFilePath() const { throw FTL_Error("Not a file URI"); } -#ifdef WIN32 +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) + // TODO + return getPath(); + +#elif defined(WIN32) std::string result; result.resize(1024); DWORD size = result.size();