Skip to content

Commit

Permalink
Fixes for Windows (it's apparently an OS from some company in Washing…
Browse files Browse the repository at this point in the history
…ton State)
  • Loading branch information
cpurdy committed Jun 15, 2022
1 parent 7b669b2 commit dddfb43
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions javatools/src/main/java/org/xvm/runtime/NativeContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import java.io.File;
import java.io.IOException;

import java.net.URLDecoder;

import java.nio.charset.StandardCharsets;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -127,6 +131,8 @@ private ConstantPool loadNativeTemplates()
}

String sRoot = xObject.class.getProtectionDomain().getCodeSource().getLocation().getFile();
sRoot = URLDecoder.decode(sRoot, StandardCharsets.UTF_8);

Map<String, Class> mapTemplateClasses = new HashMap<>();
if (sRoot.endsWith(".jar"))
{
Expand Down
Binary file modified javatools_launcher/build/exe/windows_launcher.exe
Binary file not shown.
39 changes: 39 additions & 0 deletions javatools_launcher/src/main/c/os_windows.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ const char* resolveLinks(const char* path)
return path;
}

const char* escapePath(const char* path)
{
if (*path == '\0' || *path == '\"' || !strchr(path, ' '))
{
return path;
}

int len = strlen(path);
char* result = allocBuffer(len+3);
result[0] = '\"';
strcpy(result+1, path);

// disallow path ending in slash
while (len >= 0 && result[len] == '\\')
{
--len;
}

result[len+1] = '\"';
result[len+2] = '\0';
return result;
}

void execJava(const char* javaPath,
const char* javaOpts,
const char* jarPath,
Expand Down Expand Up @@ -66,6 +89,22 @@ void execJava(const char* javaPath,
--argc;
++argv;

// handle windows weirdness with paths
javaPath = escapePath(javaPath);
jarFile = escapePath(jarFile);
libPath = escapePath(libPath);
mackFile = escapePath(mackFile);
libFile = escapePath(libFile);

#ifdef DEBUG
printf("after escape: javaPath=%s, jarFile=%s, tool=%s, libPath=%s, mackFile=%s, libFile=%s\n",
javaPath, jarFile, tool, libPath, mackFile, libFile);
for (int i = 0; i < argc; ++i)
{
printf("[%d] = \"%s\"\n", i, argv[i]);
}
#endif // DEBUG

// collect all arguments into one giant string, starting with the call to java
int len = strlen(javaPath)
+ strlen(" ")
Expand Down

0 comments on commit dddfb43

Please sign in to comment.