Skip to content

Commit

Permalink
[Linux] Solve issues with paths containing upper-case letters
Browse files Browse the repository at this point in the history
WeiDU automatically lower-cases all paths on Linux.
Using relative paths where possible reduces the chance of dealing with upper-case path names.
  • Loading branch information
Argent77 committed Oct 25, 2023
1 parent 4802de2 commit 4f8e4fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/main/java/io/infinitytools/wit/gui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -2443,16 +2443,20 @@ private void executeGuided() throws IllegalArgumentException, IndexOutOfBoundsEx
}
}

final String[] command = getWeiduCommand(gameLang, tp2File);
final String[] command = getWeiduCommand(gameLang, tp2File, workingDir);

final SysProc sp = new SysProc(workingDir, true, command);
runProcess(sp);
}

/**
* Assembles the WeiDU command line for a guided mod installation.
*
* @param gameLang Mod language index.
* @param tp2File Full path of the tp2 file.
* @param workingDir Working directory for the WeiDU call.
*/
private String[] getWeiduCommand(String gameLang, Path tp2File) {
private String[] getWeiduCommand(String gameLang, Path tp2File, Path workingDir) {
final List<String> command = new ArrayList<>(Configuration.getInstance().getWeiduArgs());

// custom WeiDU options
Expand Down Expand Up @@ -2491,7 +2495,11 @@ private String[] getWeiduCommand(String gameLang, Path tp2File) {

// standard options
if (!command.contains("--log")) {
final Path logFile = getEffectiveLogFilePath(true);
Path logFile = getEffectiveLogFilePath(true);
// creating relative log file path (recommended on Linux to work around issues with upper case paths)
if (workingDir != null) {
logFile = workingDir.relativize(logFile);
}
command.add(0, logFile.toString());
command.add(0, "--log");
}
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/io/infinitytools/wit/weidu/Weidu.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,11 @@ public String[] getModLanguages(Path tp2File) throws FileNotFoundException {
throw new FileNotFoundException("File does not exist: " + tp2File);
}

final byte[] data = ProcessUtils.getProcessOutput(getWorkingDir(tp2File), weidu.toString(), "--nogame",
"--list-languages", tp2File.toString());
final Path workingDir = getWorkingDir(tp2File);
// creating relative tp2 file path (recommended on Linux to work around issues with upper case paths)
final Path tp2FileRelative = workingDir.relativize(tp2File);
final byte[] data = ProcessUtils.getProcessOutput(workingDir, weidu.toString(), "--nogame",
"--list-languages", tp2FileRelative.toString());
final String output = BufferConvert.decodeBytes(data).decoded();

return parseLanguages(output);
Expand Down Expand Up @@ -316,8 +319,11 @@ public JSONArray getModComponentInfo(Path tp2File, int language, Charset... char
}

// Getting mod info data as raw byte data and determine best character encoding based on selected language
final byte[] outputData = ProcessUtils.getProcessOutput(getWorkingDir(tp2File), weidu.toString(), "--nogame",
"--list-components-json", tp2File.toString(), Integer.toString(language));
final Path workingDir = getWorkingDir(tp2File);
// creating relative tp2 file path (recommended on Linux to work around issues with upper case paths)
final Path tp2FileRelative = workingDir.relativize(tp2File);
final byte[] outputData = ProcessUtils.getProcessOutput(workingDir, weidu.toString(), "--nogame",
"--list-components-json", tp2FileRelative.toString(), Integer.toString(language));
Logger.debug("Parsing mod component JSON data (buffer={} bytes)", outputData.length);

// preparing list of potential character sets
Expand Down

0 comments on commit 4f8e4fd

Please sign in to comment.