Skip to content

Commit

Permalink
Merge pull request #284 from bittsitt/sanity_checks
Browse files Browse the repository at this point in the history
Sanity checks - fixing #281 after merging.
  • Loading branch information
featurecat authored Jun 9, 2018
2 parents 8c5b22c + e471fef commit 21525dc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
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

0 comments on commit 21525dc

Please sign in to comment.