cli arg for workdir

v5stable
ondra 11 years ago
parent 2699d8d549
commit dedd194925
  1. 1
      .gitignore
  2. 2
      build/Makefile
  3. 6
      src/mightypork/gamecore/app/BaseApp.java
  4. 6
      src/mightypork/gamecore/util/files/OsUtils.java
  5. 28
      src/mightypork/rogue/App.java
  6. 60
      src/mightypork/rogue/Paths.java

1
.gitignore vendored

@ -7,3 +7,4 @@
/build/in/*.jar
*.log
.attach_pid*
*~

@ -34,7 +34,7 @@ $(OUT): $(IN) $(STUB)
run: $(OUT)
java -jar $(OUT)
java -jar $(OUT) -w ../.rogue-save
clean:
rm -rf $(OUT)

@ -67,9 +67,6 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
*/
initLock();
// hook
preInit();
/*
* Setup logging
*/
@ -79,6 +76,9 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log));
}
// hook
preInit();
// only here it makes sense to log.
Log.i("=== Starting initialization sequence ===");

@ -112,16 +112,16 @@ public class OsUtils {
switch (getOs()) {
case linux:
case solaris:
file = new File(userhome, "." + dirname + '/');
file = new File(userhome, dirname + '/');
break;
case windows:
final String appdata = System.getenv("APPDATA");
if (appdata != null) {
file = new File(appdata, "." + dirname + '/');
file = new File(appdata, dirname + '/');
} else {
file = new File(userhome, "." + dirname + '/');
file = new File(userhome, dirname + '/');
}
break;

@ -2,6 +2,7 @@ package mightypork.rogue;
import java.io.File;
import java.util.Arrays;
import java.util.Locale;
import mightypork.gamecore.app.BaseApp;
@ -17,6 +18,7 @@ import mightypork.gamecore.logging.writers.LogWriter;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.resources.loading.AsyncResourceLoader;
import mightypork.gamecore.util.ion.Ion;
import mightypork.gamecore.util.strings.StringUtils;
import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType;
@ -45,6 +47,32 @@ public final class App extends BaseApp {
*/
public static void main(String[] args)
{
Log.f3(Arrays.toString(args));
try {
boolean lwd = false;
String lwdDir = null;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("--workdir") || args[i].equals("-w")) {
lwd = true;
lwdDir = args[i + 1];
i++;
}
}
if (!lwd) {
Paths.init();
} else {
Paths.init(lwdDir);
}
} catch (ArrayIndexOutOfBoundsException e) {
Log.e("Malformed arguments.");
}
Log.i("Using workdir: " + Paths.WORKDIR.getAbsolutePath());
(new App()).start();
}

@ -3,25 +3,63 @@ package mightypork.rogue;
import java.io.File;
import mightypork.gamecore.util.files.OsUtils;
public final class Paths {
public static final File WORKDIR = new File("./.rogue-save");//OsUtils.getWorkDir(APPDIR_NAME);
private static final String WORKDIR_NAME = ".rogue-save";
public static File WORKDIR;
public static File LOG_FILE;
public static File SCREENSHOTS;
public static File CONFIG;
public static File LOCK;
public static File SAVE_SLOT_1;
public static File SAVE_SLOT_2;
public static File SAVE_SLOT_3;
/**
* Initialize for local workdir
*
* @param local_wd_name workdir name
*/
public static void init(String local_wd_name)
{
init(true, local_wd_name);
}
/**
* Initialize for gloal workdir
*/
public static void init()
{
init(false, WORKDIR_NAME);
}
public static final File LOG_FILE = new File(WORKDIR, "runtime.log");
private static void init(boolean local_workdir, String workdir_name)
{
if (local_workdir) {
WORKDIR = new File(workdir_name);
} else {
WORKDIR = OsUtils.getWorkDir(workdir_name);
}
public static final File SCREENSHOTS = new File(WORKDIR, "screenshots");
LOG_FILE = new File(WORKDIR, "runtime.log");
public static final File CONFIG = new File(WORKDIR, "config.ini");
SCREENSHOTS = new File(WORKDIR, "screenshots");
public static final File LOCK = new File(WORKDIR, ".lock");
CONFIG = new File(WORKDIR, "config.ini");
public static final String DIR_EFFECTS = "res/sounds/effects/";
public static final String DIR_MUSIC = "res/sounds/music/";
public static final String DIR_LOOPS = "res/sounds/loops/";
LOCK = new File(WORKDIR, ".lock");
public static final File SAVE_SLOT_1 = new File(WORKDIR, "saves/slot_1.ion");
public static final File SAVE_SLOT_2 = new File(WORKDIR, "saves/slot_2.ion");
public static final File SAVE_SLOT_3 = new File(WORKDIR, "saves/slot_3.ion");
SAVE_SLOT_1 = new File(WORKDIR, "saves/slot_1.ion");
SAVE_SLOT_2 = new File(WORKDIR, "saves/slot_2.ion");
SAVE_SLOT_3 = new File(WORKDIR, "saves/slot_3.ion");
}
}

Loading…
Cancel
Save