hrehfeld/QuakeInjector — pull request #90 by neogeographica (2014-04-13 05:25:19+00:00)
Title: allow setting working dir if engine exe is not in basedir

## functional changes

Previously the code was setting the working directory to be the basedir
(directory containing the id1 folder etc.) which is usually kosher but not
always.

This change adds a configuration option to instead use the directory of the
engine executable as the working directory. The option is visible only if that
executable is located somewhere outside of the basedir.

A couple of examples of the engine not being in the basedir:

- DarkPlaces has so many libraries that I usually like to corral all its files
into their own folder (and use the -basedir command line arg).

- Using Steam.exe to launch Quake through Steam (cf. comments 124-126 at
http://www.celephais.net/board/view_thread.php?id=60441 ).

## comments

This is working fine as far as I can tell, but I'll still be poking at it for
a bit longer to shake out any quirks. For example I've noticed that running
DirectQ outside of the basedir doesn't work like I'd expect -- I don't think
it has anything to do with Quake Injector, but I want to see if I can figure
out what is going on there.

In the meantime I'll go ahead and start this PR to gather feedback. Any
comments welcome, but particularly on UI issues:
- Any suggestions on the presentation, text blurbs, etc.
- Technical fixes for Swing stuff. I'm familiar with layout concepts from
working with Gtk and CSS, but this is the first time I've used Swing.

## examples

Here's some example shots of the config dialog, using Quake Injector in
various ways with the data in my Steam Quake directory.

This first shot is the "normal case" for Quake deployments, where the exe is
in the basedir. The new option doesn't matter in this case, so it is hidden:

![exe_in_basedir](https://cloud.githubusercontent.com/assets/2068148/2688791/03b74816-c2cb-11e3-9710-e28b8ac46fc4.png)

Next shot is using Steam to run Quake (with Steam's Quake exe actually
replaced by QuakeSpasm). I've manually added the applaunch arg to make it work:

![exe_out_of_basedir_steam](https://cloud.githubusercontent.com/assets/2068148/2688792/267ed850-c2cb-11e3-9f1e-243ad7d48810.png)

Next shot is still using Steam's Quake data, but I've switched the engine to
some DarkPlaces files elsewhere on my disk. I've manually added the basedir
arg to make it work:

![exe_out_of_basedir_dp](https://cloud.githubusercontent.com/assets/2068148/2688793/43f6d518-c2cb-11e3-857b-52e3f6cbd934.png)

And the last shot is again with an engine out of the basedir, this time
Fitzquake Mark V. Fitz doesn't have any libraries or other resources to load
with the engine, so I can run with its working directory in the basedir, and
not use the basedir arg (which is good because the basedir arg is flaky with
Fitz Mark V):

![exe_out_of_basedir_fmv](https://cloud.githubusercontent.com/assets/2068148/2688795/6ed61410-c2cb-11e3-8404-d1a72506f677.png)

All of these situations worked to the extent that I used Quake Injector to
launch Quake into a custom map ("The Epoch Turning") and play.

## code changes

### EngineStarter.java

- Rename quakeDir to workingDir to be more explicit about what it's used for.

### Configuration.java

- Added workingDirAtExecutable, a boolean config var w/ default false.

### QuakeInjector.java

- Accomodate the EngineStarter terminology change.

- Use the workingDirAtExecutable flag to determine which working directory to
pass to EngineStarter. This logic affects both the original creation of
EngineStarter, and also subsequent updates of EngineStarter whenever the
config is changed.

### EngineConfigDialog.java

- In the constructor, build the necessary widgets for the new option. The
boolean flag is exposed as a pair of radio buttons so that we can be explicit
about what the two choices mean.

- Add the call to fetch the option value from the widgets.

- Implement the logic for hiding/showing the new option. We'll show the option
if and only if the exe location and basedir are valid & different.

- Trigger the option's hide/show logic at the end of the constructor, as well
as whenever the exe location or basedir are changed.