mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-23 11:31:33 +01:00
Set working directory for external engines
When running an external engine set the working directory of the engine process to .../DroidFish/uci/logs. This makes it possible for the engine to create log files or other auxiliary files in that directory. This is useful for the OpenCL version of LC0, which needs to create a tuning file somewhere. With this change it can be placed in the current working directory.
This commit is contained in:
parent
71221314e6
commit
be1b667f35
|
@ -260,6 +260,7 @@ public class DroidFish extends Activity
|
|||
private static String pgnDir = "DroidFish/pgn";
|
||||
private static String fenDir = "DroidFish/epd";
|
||||
private static String engineDir = "DroidFish/uci";
|
||||
private static String engineLogDir = "DroidFish/uci/logs";
|
||||
private static String gtbDefaultDir = "DroidFish/gtb";
|
||||
private static String rtbDefaultDir = "DroidFish/rtb";
|
||||
private BookOptions bookOptions = new BookOptions();
|
||||
|
@ -726,6 +727,7 @@ public class DroidFish extends Activity
|
|||
new File(extDir + sep + fenDir).mkdirs();
|
||||
new File(extDir + sep + engineDir).mkdirs();
|
||||
new File(extDir + sep + engineDir + sep + EngineUtil.openExchangeDir).mkdirs();
|
||||
new File(extDir + sep + engineLogDir).mkdirs();
|
||||
new File(extDir + sep + gtbDefaultDir).mkdirs();
|
||||
new File(extDir + sep + rtbDefaultDir).mkdirs();
|
||||
}
|
||||
|
@ -1314,6 +1316,7 @@ public class DroidFish extends Activity
|
|||
rtbPath = extDir.getAbsolutePath() + sep + rtbDefaultDir;
|
||||
engineOptions.rtbPath = rtbPath;
|
||||
engineOptions.rtbPathNet = settings.getString("rtbPathNet", "").trim();
|
||||
engineOptions.workDir = Environment.getExternalStorageDirectory() + sep + engineLogDir;
|
||||
|
||||
setEngineOptions(false);
|
||||
setEgtbHints(cb.getSelectedSquare());
|
||||
|
|
|
@ -31,6 +31,7 @@ public final class EngineOptions {
|
|||
String rtbPath; // Syzygy directory path
|
||||
String rtbPathNet; // Syzygy directory path for network engines
|
||||
public String networkID; // host+port network settings
|
||||
public String workDir; // Working directory for engine process
|
||||
|
||||
public EngineOptions() {
|
||||
hashMB = 16;
|
||||
|
@ -44,6 +45,7 @@ public final class EngineOptions {
|
|||
rtbPath = "";
|
||||
rtbPathNet = "";
|
||||
networkID = "";
|
||||
workDir = "";
|
||||
}
|
||||
|
||||
public EngineOptions(EngineOptions other) {
|
||||
|
@ -58,6 +60,7 @@ public final class EngineOptions {
|
|||
rtbPath = other.rtbPath;
|
||||
rtbPathNet = other.rtbPathNet;
|
||||
networkID = other.networkID;
|
||||
workDir = other.workDir;
|
||||
}
|
||||
|
||||
/** Get the GTB path for an engine. */
|
||||
|
@ -90,7 +93,8 @@ public final class EngineOptions {
|
|||
gtbPathNet.equals(other.gtbPathNet) &&
|
||||
rtbPath.equals(other.rtbPath) &&
|
||||
rtbPathNet.equals(other.rtbPathNet) &&
|
||||
networkID.equals(other.networkID));
|
||||
networkID.equals(other.networkID) &&
|
||||
workDir.equals(other.workDir));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,6 +37,7 @@ public class ExternalEngine extends UCIEngineBase {
|
|||
protected final Context context;
|
||||
|
||||
private File engineFileName;
|
||||
private File engineWorkDir;
|
||||
private final Report report;
|
||||
private Process engineProc;
|
||||
private Thread startupThread;
|
||||
|
@ -47,10 +48,11 @@ public class ExternalEngine extends UCIEngineBase {
|
|||
private boolean startedOk;
|
||||
private boolean isRunning;
|
||||
|
||||
public ExternalEngine(String engine, Report report) {
|
||||
public ExternalEngine(String engine, String workDir, Report report) {
|
||||
context = DroidFishApp.getContext();
|
||||
this.report = report;
|
||||
engineFileName = new File(engine);
|
||||
engineWorkDir = new File(workDir);
|
||||
engineProc = null;
|
||||
startupThread = null;
|
||||
exitThread = null;
|
||||
|
@ -75,6 +77,7 @@ public class ExternalEngine extends UCIEngineBase {
|
|||
chmod(exePath);
|
||||
cleanUpExeDir(exeDir, exePath);
|
||||
ProcessBuilder pb = new ProcessBuilder(exePath);
|
||||
pb.directory(engineWorkDir);
|
||||
synchronized (EngineUtil.nativeLock) {
|
||||
engineProc = pb.start();
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ import android.os.Environment;
|
|||
/** Stockfish engine running as process, started from assets resource. */
|
||||
public class InternalStockFish extends ExternalEngine {
|
||||
|
||||
public InternalStockFish(Report report) {
|
||||
super("", report);
|
||||
public InternalStockFish(Report report, String workDir) {
|
||||
super("", workDir, report);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,8 +28,8 @@ import com.kalab.chess.enginesupport.ChessEngineResolver;
|
|||
/** Engine imported from a different android app, resolved using the open exchange format. */
|
||||
public class OpenExchangeEngine extends ExternalEngine {
|
||||
|
||||
public OpenExchangeEngine(String engine, Report report) {
|
||||
super(engine, report);
|
||||
public OpenExchangeEngine(String engine, String workDir, Report report) {
|
||||
super(engine, workDir, report);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -42,13 +42,13 @@ public abstract class UCIEngineBase implements UCIEngine {
|
|||
if ("cuckoochess".equals(engine))
|
||||
return new CuckooChessEngine();
|
||||
else if ("stockfish".equals(engine))
|
||||
return new InternalStockFish(report);
|
||||
return new InternalStockFish(report, engineOptions.workDir);
|
||||
else if (EngineUtil.isOpenExchangeEngine(engine))
|
||||
return new OpenExchangeEngine(engine, report);
|
||||
return new OpenExchangeEngine(engine, engineOptions.workDir, report);
|
||||
else if (EngineUtil.isNetEngine(engine))
|
||||
return new NetworkEngine(engine, engineOptions, report);
|
||||
else
|
||||
return new ExternalEngine(engine, report);
|
||||
return new ExternalEngine(engine, engineOptions.workDir, report);
|
||||
}
|
||||
|
||||
protected UCIEngineBase() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user