Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Workaround Inferno startmovie regression
Browse files Browse the repository at this point in the history
startmovie command fails with an 'Invalid Path' error unless you
use a path under the tf folder. This makes sure the path is then
resolved as a relative path to work around the regression.

Paths sharing the same root drive as the game also work with this
workaround. Paths in a different drive won't work and no warning
(other than this message) will be given.
  • Loading branch information
quanticc committed Nov 19, 2017
1 parent 6534e71 commit 732421c
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/main/java/lwrt/MovieManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;

class MovieManager {

private static final Logger log = Logger.getLogger("lawena");

private SettingsManager cfg;

public MovieManager(SettingsManager cfg) {
Expand Down Expand Up @@ -50,11 +53,38 @@ public void createMovienameCfgs() throws IOException {
if (!Files.exists(folder)) {
Files.createDirectories(folder);
}
String moviePath = "";
if (cfg.getMoviePath().startsWith(cfg.getTfPath())) {
try {
Path movieRelatedToGame = cfg.getTfPath().relativize(cfg.getMoviePath());
moviePath = movieRelatedToGame.toString();
} catch (IllegalArgumentException e) {
// different root
log.info("Cannot relativize path: " + e.toString());
}
} else if (shareSameRoot(cfg.getMoviePath(), cfg.getTfPath())) {
moviePath = cfg.getMoviePath().toString().replaceFirst("^[A-Z]:(.*)$", "$1");
} else {
moviePath = cfg.getMoviePath().toString();
}
String escape = needsEscape(moviePath) ? "\"" : "";
moviePath = moviePath.replace("\\", "/") + (moviePath.isEmpty() ? "" : "/");
log.info("Resolved movie recording path: " + moviePath);
for (String prefix : prefixes) {
List<String> lines =
Collections.singletonList("startmovie \"" + cfg.getMoviePath() + "/" + prefix + "_\" " + video +
" " + audio + (video.equals("jpg") ? " jpeg_quality " + quality : ""));
String command = "startmovie " + escape + moviePath + prefix + "_" + escape + " " +
video + " " + audio + (video.equals("jpg") ? " jpeg_quality " + quality : "");
List<String> lines = Collections.singletonList(command);
Files.write(Paths.get("cfg/mov/" + prefix + ".cfg"), lines, Charset.forName("UTF-8"));
}
}

private boolean shareSameRoot(Path path1, Path path2) {
String root1 = path1.toString().replaceFirst("^([A-Z]):.*$", "$1");
String root2 = path2.toString().replaceFirst("^([A-Z]):.*$", "$1");
return root1.equals(root2);
}

private boolean needsEscape(String str) {
return str != null && str.contains(" ");
}
}

1 comment on commit 732421c

@quanticc
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#82

Please sign in to comment.