Integrated InstallationFinder into :desktop

This commit is contained in:
Collin Smith 2020-11-21 04:15:27 -08:00
parent e660f2bd78
commit c888c9beb2
3 changed files with 24 additions and 26 deletions

View File

@ -258,6 +258,7 @@ public class Client extends Game {
DateFormat format = DateFormat.getDateTimeInstance();
console.out.println(format.format(calendar.getTime()));
console.out.println(home.path());
console.out.println(saves.path());
}
if (!home.exists() || !home.child("d2data.mpq").exists()) {

View File

@ -3,7 +3,6 @@ package com.riiablo.util;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.SystemUtils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
@ -94,7 +93,7 @@ public abstract class InstallationFinder {
log.traceEntry("resolve() paths: {}", homeDirs);
Array<FileHandle> result = null;
for (String path : homeDirs) {
FileHandle handle = Gdx.files.absolute(path);
FileHandle handle = new FileHandle(path);
log.trace("Trying {}", handle);
if (isD2Home(handle)) {
if (result == null) result = new Array<>();
@ -125,9 +124,12 @@ public abstract class InstallationFinder {
final FileHandle homeSaves = home == null ? null : home.child(SAVE);
log.trace("homeSaves: {}", homeSaves);
if (D2_SAVE != null) saveDirs.add(Gdx.files.absolute(D2_SAVE));
if (NewSavePath != null) saveDirs.add(Gdx.files.absolute(NewSavePath));
if (home != null) saveDirs.add(homeSaves);
if (D2_SAVE != null) saveDirs.add(new FileHandle(D2_SAVE));
if (NewSavePath != null) saveDirs.add(new FileHandle(NewSavePath));
if (home != null) {
homeSaves.mkdirs();
saveDirs.add(homeSaves);
}
return saveDirs;
}
}

View File

@ -16,10 +16,12 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.riiablo.cvar.Cvar;
import com.riiablo.cvar.CvarStateAdapter;
import com.riiablo.util.InstallationFinder;
public class DesktopLauncher {
public static void main(String[] args) {
@ -61,37 +63,30 @@ public class DesktopLauncher {
}
}
FileHandle home = null;
final InstallationFinder finder = InstallationFinder.getInstance();
final FileHandle home;
if (cmd != null && cmd.hasOption("home")) {
home = new FileHandle(cmd.getOptionValue("home"));
if (!home.child("d2data.mpq").exists()) {
if (!InstallationFinder.isD2Home(home)) {
throw new GdxRuntimeException("home does not refer to a valid D2 installation");
}
} else {
home = new FileHandle(System.getProperty("user.home")).child("diablo");
System.out.println("Home not specified, using " + home);
home.mkdirs();
final Array<FileHandle> homeDirs = finder.getHomeDirs();
if (homeDirs.size > 0) {
home = homeDirs.first();
} else {
home = new FileHandle(SystemUtils.USER_HOME).child("riiablo");
home.mkdirs();
System.out.println("Created home directory " + home);
}
}
FileHandle saves = null;
final FileHandle saves;
if (cmd != null && cmd.hasOption("saves")) {
saves = new FileHandle(cmd.getOptionValue("saves"));
} else if (SystemUtils.IS_OS_WINDOWS) {
FileHandle savedGames = new FileHandle(System.getProperty("user.home")).child("Saved Games\\Diablo II");
if (savedGames.exists()) {
saves = savedGames;
} else {
saves = home.child("Save");
if (!saves.exists()) {
saves = home;
}
System.out.println("Saves not specified, using " + saves);
}
} else {
saves = home.child("Save");
System.out.println("Saves not specified, using " + saves);
saves.mkdirs();
final Array<FileHandle> saveDirs = finder.getSaveDirs(home);
saves = saveDirs.first();
}
final LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();