Re: [Program] FTL SpaceDock
Posted: Wed Jul 24, 2013 11:25 pm
Well, I'm hardly a pro (Vhati's or shark's input would've been far more valuable), but I'm happy I was able to help :)
Regarding the launching issue; I've encountered that a month or two ago. It was a really tricky one.
The problem is: when you launch a new process, it is executed in the same working directory as the parent application that created the process.
So, when you execute FTLGame.exe that way, it executes the correct exe in FTL's installation, but it's working directory is set to Spacedock's directory -- so if the child process uses relative paths anywhere, they'll all resolve to [Spacedock path]/[relative path], and not [FTL installation path]/[relative path].
This causes FTL to spill its guts, since it can't find the .dat archives, and thus causes it to quit.
Also, I'd recommend against using waitFor() in this case -- it causes your application to stop working, only resuming once the child process has quit.
Another thing, though I'm not sure if I recall it correctly, is that processes created using exec() are child processes of the parent application, so if the parent quits, all children also quit. Don't trust me on that one, though.
Either way, here's a snippet of my code from my earlier project that executes FTL correctly:
However, for the future I'd recommend making an extensive use of Google and Stack Overflow -- it is often said that roughly half of programming is googling for a solution, the other half is problem solving and actual coding... And coding accounts for the smaller part of that half :)
Regarding the launching issue; I've encountered that a month or two ago. It was a really tricky one.
The problem is: when you launch a new process, it is executed in the same working directory as the parent application that created the process.
So, when you execute FTLGame.exe that way, it executes the correct exe in FTL's installation, but it's working directory is set to Spacedock's directory -- so if the child process uses relative paths anywhere, they'll all resolve to [Spacedock path]/[relative path], and not [FTL installation path]/[relative path].
This causes FTL to spill its guts, since it can't find the .dat archives, and thus causes it to quit.
Also, I'd recommend against using waitFor() in this case -- it causes your application to stop working, only resuming once the child process has quit.
Another thing, though I'm not sure if I recall it correctly, is that processes created using exec() are child processes of the parent application, so if the parent quits, all children also quit. Don't trust me on that one, though.
Either way, here's a snippet of my code from my earlier project that executes FTL correctly:
Code: Select all
File ftl = new File(Main.ftlIntallPath.getAbsolutePath() + "/FTLGame.exe");
Main.logger.info(String.format("Running FTL... [%s]", ftl.getAbsolutePath()));
if (ftl.exists())
try {
ProcessBuilder builder = new ProcessBuilder(ftl.getAbsolutePath());
builder.directory(ftl.getParentFile()); // this call corrects the working directory for the exe
builder.start();
} catch (IOException ex) {
Main.logger.error("An exception occured while executing FTL.");
ex.printStackTrace();
}
else
Main.logger.error("Could not find FTL executable.");
However, for the future I'd recommend making an extensive use of Google and Stack Overflow -- it is often said that roughly half of programming is googling for a solution, the other half is problem solving and actual coding... And coding accounts for the smaller part of that half :)