diff --git a/fmusim/FMIZip.c b/fmusim/FMIZip.c index 394d2c82..502ada67 100644 --- a/fmusim/FMIZip.c +++ b/fmusim/FMIZip.c @@ -3,6 +3,7 @@ #include #include #include +#pragma comment(lib, "shlwapi.lib") #include #include #else diff --git a/include/FMI.h b/include/FMI.h index 8b45f7d2..70faaf43 100644 --- a/include/FMI.h +++ b/include/FMI.h @@ -152,8 +152,6 @@ FMI_STATIC void FMIAppendToLogMessageBuffer(FMIInstance* instance, const char* f FMI_STATIC void FMIAppendArrayToLogMessageBuffer(FMIInstance* instance, const void* values, size_t nValues, const size_t sizes[], FMIVariableType variableType); -FMI_STATIC FMIStatus FMIURIToPath(const char *uri, char *path, const size_t pathLength); - FMI_STATIC FMIStatus FMIPathToURI(const char *path, char *uri, const size_t uriLength); FMI_STATIC FMIStatus FMIPlatformBinaryPath(const char *unzipdir, const char *modelIdentifier, FMIVersion fmiVersion, char *platformBinaryPath, size_t size); diff --git a/src/FMI.c b/src/FMI.c index 9a6a35bf..66813b82 100644 --- a/src/FMI.c +++ b/src/FMI.c @@ -4,8 +4,6 @@ #include #ifdef _WIN32 -#include -#pragma comment(lib, "shlwapi.lib") #else #include #include @@ -29,9 +27,6 @@ FMIInstance *FMICreateInstance(const char *instanceName, const char *libraryPath // convert path to unicode mbstowcs(dllDirectory, libraryPath, MAX_PATH); - // remove the file name - PathRemoveFileSpecW(dllDirectory); - // add the binaries directory temporarily to the DLL path to allow discovery of dependencies DLL_DIRECTORY_COOKIE dllDirectoryCookie = AddDllDirectory(dllDirectory); @@ -246,60 +241,23 @@ void FMIAppendArrayToLogMessageBuffer(FMIInstance* instance, const void* values, } } -FMIStatus FMIURIToPath(const char *uri, char *path, const size_t pathLength) { - -#ifdef _WIN32 - DWORD pcchPath = (DWORD)pathLength; - - if (PathCreateFromUrlA(uri, path, &pcchPath, 0) != S_OK) { - return FMIError; - } -#else - const char *scheme1 = "file:///"; - const char *scheme2 = "file:/"; +FMIStatus FMIPathToURI(const char *path, char *uri, const size_t uriLength) { - strncpy(path, uri, pathLength); + const size_t pathLen = strlen(path); - if (strncmp(uri, scheme1, strlen(scheme1)) == 0) { - strncpy(path, &uri[strlen(scheme1)] - 1, pathLength); - } else if (strncmp(uri, scheme2, strlen(scheme2)) == 0) { - strncpy(path, &uri[strlen(scheme2) - 1], pathLength); - } else { + if (uriLength < strlen(path) + 8) { return FMIError; } -#endif #ifdef _WIN32 - const char* sep = "\\"; + const char* scheme = "file:///"; #else - const char* sep = "/"; + const char* scheme = "file://"; #endif - if (path[strlen(path) - 1] != sep[0]) { - strncat(path, sep, pathLength); - } + strcpy(uri, scheme); - return FMIOK; -} - -FMIStatus FMIPathToURI(const char *path, char *uri, const size_t uriLength) { - -#ifdef _WIN32 - DWORD pcchUri = (DWORD)uriLength; - - if (UrlCreateFromPathA(path, uri, &pcchUri, 0) != S_OK) { - return FMIError; - } -#else - const size_t pathLen = strlen(path); - - if (uriLength < strlen(path) + 8) { - return FMIError; - } - - strcpy(uri, "file://"); - - size_t p = 7; + size_t p = strlen(scheme); // percent encode special characters for (size_t i = 0; i < pathLen; i++) { @@ -308,7 +266,13 @@ FMIStatus FMIPathToURI(const char *path, char *uri, const size_t uriLength) { return FMIError; } - const char c = path[i]; + char c = path[i]; + +#ifdef _WIN32 + if (c == '\\') { + c = '/'; + } +#endif bool encode = true; @@ -331,7 +295,6 @@ FMIStatus FMIPathToURI(const char *path, char *uri, const size_t uriLength) { } uri[p] = '\0'; -#endif return FMIOK; } diff --git a/src/FMI2.c b/src/FMI2.c index 116ce37c..a10b04aa 100644 --- a/src/FMI2.c +++ b/src/FMI2.c @@ -1,7 +1,5 @@ #ifdef _WIN32 #include -#include "Shlwapi.h" -#pragma comment(lib, "shlwapi.lib") #define strdup _strdup #define INTERNET_MAX_URL_LENGTH 2083 // from wininet.h #else diff --git a/src/FMI3.c b/src/FMI3.c index 04deae91..3cecf9ee 100644 --- a/src/FMI3.c +++ b/src/FMI3.c @@ -1,7 +1,5 @@ #ifdef _WIN32 #include -#include "Shlwapi.h" -#pragma comment(lib, "shlwapi.lib") #else #include #include