Integrated InstallationFinder folder searching directly into InstallationFinder

This commit is contained in:
Collin Smith
2021-09-16 11:54:30 -07:00
parent 69bfbfbf4f
commit c5c98ce48c
2 changed files with 89 additions and 25 deletions

View File

@ -62,12 +62,96 @@ public abstract class InstallationFinder {
return EMPTY_ARRAY;
}
public Array<FileHandle> getTestDirs() {
return EMPTY_ARRAY;
}
public Array<FileHandle> getSaveDirs(FileHandle home) {
return EMPTY_ARRAY;
}
public Array<FileHandle> getTestDirs() {
return EMPTY_ARRAY;
public final FileHandle defaultHomeDir() throws DefaultNotFound {
try {
return defaultHomeDir(null);
} catch (ArgNotFound t) {
throw new AssertionError("null arg should not throw " + ArgNotFound.class.getCanonicalName(), t);
}
}
public final FileHandle defaultHomeDir(String arg) throws ArgNotFound, DefaultNotFound {
if (arg != null) {
final FileHandle handle = new FileHandle(arg);
if (InstallationFinder.isD2Home(handle)) {
return handle;
} else {
throw new ArgNotFound(handle, "Unable to locate any D2 installation!");
}
}
log.trace("Locating D2 installations...");
Array<FileHandle> homeDirs = getHomeDirs();
log.trace("D2 installations: {}", homeDirs);
if (homeDirs.size > 0) {
return homeDirs.first();
} else {
throw new DefaultNotFound(homeDirs, "Unable to locate any D2 installation!");
}
}
public final FileHandle defaultTestDir() throws DefaultNotFound {
try {
return defaultTestDir(null);
} catch (ArgNotFound t) {
throw new AssertionError("null arg should not throw " + ArgNotFound.class.getCanonicalName(), t);
}
}
public final FileHandle defaultTestDir(String arg) throws ArgNotFound, DefaultNotFound {
if (arg != null) {
final FileHandle handle = new FileHandle(arg);
if (InstallationFinder.isD2Home(handle)) {
return handle;
} else {
throw new ArgNotFound(handle, "Unable to locate any D2 test installation!");
}
}
log.trace("Locating D2 test installations...");
Array<FileHandle> testDirs = getTestDirs();
log.trace("D2 test installations: {}", testDirs);
if (testDirs.size > 0) {
return testDirs.first();
} else {
throw new DefaultNotFound(testDirs, "Unable to locate any D2 test installation!");
}
}
public static final class ArgNotFound extends Exception {
public final FileHandle dir;
ArgNotFound(FileHandle dir, String message) {
super(message);
this.dir = dir;
}
ArgNotFound(FileHandle dir, String message, Throwable cause) {
super(message, cause);
this.dir = dir;
}
}
public static final class DefaultNotFound extends Exception {
public final Array<FileHandle> dirs;
DefaultNotFound(Array<FileHandle> dirs, String message) {
super(message);
this.dirs = dirs;
}
DefaultNotFound(Array<FileHandle> dirs, String message, Throwable cause) {
super(message, cause);
this.dirs = dirs;
}
}
public static final class StubbedInstallationFinder extends InstallationFinder {

View File

@ -1,13 +1,11 @@
package com.riiablo;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.headless.HeadlessApplication;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
import com.riiablo.codec.StringTBLs;
import com.riiablo.logger.LogManager;
@ -23,34 +21,16 @@ public class RiiabloTest {
}
@BeforeAll
public static void setup() {
public static void setup() throws InstallationFinder.DefaultNotFound {
Gdx.app = new HeadlessApplication(new ApplicationAdapter() {});
final InstallationFinder finder = InstallationFinder.getInstance();
Riiablo.home = getHomeDir(finder);
Riiablo.home = finder.defaultHomeDir();
Riiablo.mpqs = new MPQFileHandleResolver();
Riiablo.string = new StringTBLs(Riiablo.mpqs);
Riiablo.files = new Files();
Riiablo.logs = new GdxLoggerManager(LogManager.getRegistry());
Riiablo.logs.getRootLogger().addAppender(new OutputStreamAppender(System.out));
testHome = getTestDir(finder);
}
static FileHandle getHomeDir(InstallationFinder finder) {
Array<FileHandle> homeDirs = finder.getHomeDirs();
if (homeDirs.size > 0) {
return homeDirs.first();
} else {
return fail("Unable to locate D2 installation!");
}
}
static FileHandle getTestDir(InstallationFinder finder) {
Array<FileHandle> testDirs = finder.getTestDirs();
if (testDirs.size > 0) {
return testDirs.first();
} else {
return fail("Unable to locate D2 test files!");
}
testHome = finder.defaultTestDir();
}
@AfterAll