Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanity checks #284

Merged
merged 1 commit into from
Jun 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/featurecat/lizzie/Lizzie.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import featurecat.lizzie.plugin.PluginManager;
import featurecat.lizzie.rules.Board;
import featurecat.lizzie.gui.LizzieFrame;
import org.json.JSONObject;

import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.util.ResourceBundle;

/**
* Main class.
Expand All @@ -27,6 +30,21 @@ public static void main(String[] args) throws IOException, JSONException, ClassN

config = new Config();

// Check that user has installed leela zero
JSONObject leelazconfig = Lizzie.config.config.getJSONObject("leelaz");
ResourceBundle resourceBundle = ResourceBundle.getBundle("l10n.DisplayStrings");
String startfolder = leelazconfig.optString("engine-start-location", ".");

// Check if engine is present
File lef = new File(startfolder + '/' + "leelaz");
if (!lef.exists()) {
File leexe = new File(startfolder + '/' + "leelaz.exe");
if (!leexe.exists()) {
JOptionPane.showMessageDialog(null, resourceBundle.getString("LizzieFrame.display.leelaz-missing"), "Lizzie - Error!", JOptionPane.ERROR_MESSAGE);
return;
}
}

PluginManager.loadPlugins();

board = new Board();
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/featurecat/lizzie/analysis/Leelaz.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public Leelaz() throws IOException, JSONException {
updateToLatestNetwork();
}

String startfolder = config.optString("engine-start-location", ".");

// Check if network file is present
File wf = new File(startfolder + '/' + config.getString("network-file"));
if (!wf.exists()) {
JOptionPane.showMessageDialog(null, resourceBundle.getString("LizzieFrame.display.network-missing"));
}


// command string for starting the engine
String engineCommand = config.getString("engine-command");
// substitute in the weights file
Expand All @@ -91,7 +100,7 @@ public Leelaz() throws IOException, JSONException {

// run leelaz
ProcessBuilder processBuilder = new ProcessBuilder(commands);
processBuilder.directory(new File(config.optString("engine-start-location", ".")));
processBuilder.directory(new File(startfolder));
processBuilder.redirectErrorStream(true);
process = processBuilder.start();

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/l10n/DisplayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ LizzieFrame.display.pondering=Pondering
LizzieFrame.display.on=on
LizzieFrame.display.off=off
LizzieFrame.display.loading=Leela Zero is loading...
LizzieFrame.display.download-latest-network-prompt=Download the latest network file? This may take some time.
LizzieFrame.display.download-latest-network-prompt=Download the latest network file? This may take some time.
LizzieFrame.display.leelaz-missing=Did not find Leela Zero, update config.txt or download from Leela Zero homepage
LizzieFrame.display.network-missing=Did not find network/weights.\nUpdate config.txt (network-file) or download from Leela Zero homepage
2 changes: 2 additions & 0 deletions src/main/resources/l10n/DisplayStrings_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ LizzieFrame.display.on=\u5F00\u542F
LizzieFrame.display.off=\u6682\u505C
LizzieFrame.display.loading=Leela Zero\u6B63\u5728\u8F7D\u5165\u4E2D...
LizzieFrame.display.download-latest-network-prompt=Download the latest network file? This may take some time.
LizzieFrame.display.leelaz-missing=Did not find Leela Zero, update config.txt or download from Leela Zero homepage
LizzieFrame.display.network-missing=Did not find network/weights.\nUpdate config.txt (network-file) or download from Leela Zero homepage