mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-27 06:10:28 +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 pgnDir = "DroidFish/pgn";
|
||||||
private static String fenDir = "DroidFish/epd";
|
private static String fenDir = "DroidFish/epd";
|
||||||
private static String engineDir = "DroidFish/uci";
|
private static String engineDir = "DroidFish/uci";
|
||||||
|
private static String engineLogDir = "DroidFish/uci/logs";
|
||||||
private static String gtbDefaultDir = "DroidFish/gtb";
|
private static String gtbDefaultDir = "DroidFish/gtb";
|
||||||
private static String rtbDefaultDir = "DroidFish/rtb";
|
private static String rtbDefaultDir = "DroidFish/rtb";
|
||||||
private BookOptions bookOptions = new BookOptions();
|
private BookOptions bookOptions = new BookOptions();
|
||||||
|
@ -726,6 +727,7 @@ public class DroidFish extends Activity
|
||||||
new File(extDir + sep + fenDir).mkdirs();
|
new File(extDir + sep + fenDir).mkdirs();
|
||||||
new File(extDir + sep + engineDir).mkdirs();
|
new File(extDir + sep + engineDir).mkdirs();
|
||||||
new File(extDir + sep + engineDir + sep + EngineUtil.openExchangeDir).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 + gtbDefaultDir).mkdirs();
|
||||||
new File(extDir + sep + rtbDefaultDir).mkdirs();
|
new File(extDir + sep + rtbDefaultDir).mkdirs();
|
||||||
}
|
}
|
||||||
|
@ -1314,6 +1316,7 @@ public class DroidFish extends Activity
|
||||||
rtbPath = extDir.getAbsolutePath() + sep + rtbDefaultDir;
|
rtbPath = extDir.getAbsolutePath() + sep + rtbDefaultDir;
|
||||||
engineOptions.rtbPath = rtbPath;
|
engineOptions.rtbPath = rtbPath;
|
||||||
engineOptions.rtbPathNet = settings.getString("rtbPathNet", "").trim();
|
engineOptions.rtbPathNet = settings.getString("rtbPathNet", "").trim();
|
||||||
|
engineOptions.workDir = Environment.getExternalStorageDirectory() + sep + engineLogDir;
|
||||||
|
|
||||||
setEngineOptions(false);
|
setEngineOptions(false);
|
||||||
setEgtbHints(cb.getSelectedSquare());
|
setEgtbHints(cb.getSelectedSquare());
|
||||||
|
|
|
@ -31,6 +31,7 @@ public final class EngineOptions {
|
||||||
String rtbPath; // Syzygy directory path
|
String rtbPath; // Syzygy directory path
|
||||||
String rtbPathNet; // Syzygy directory path for network engines
|
String rtbPathNet; // Syzygy directory path for network engines
|
||||||
public String networkID; // host+port network settings
|
public String networkID; // host+port network settings
|
||||||
|
public String workDir; // Working directory for engine process
|
||||||
|
|
||||||
public EngineOptions() {
|
public EngineOptions() {
|
||||||
hashMB = 16;
|
hashMB = 16;
|
||||||
|
@ -44,6 +45,7 @@ public final class EngineOptions {
|
||||||
rtbPath = "";
|
rtbPath = "";
|
||||||
rtbPathNet = "";
|
rtbPathNet = "";
|
||||||
networkID = "";
|
networkID = "";
|
||||||
|
workDir = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public EngineOptions(EngineOptions other) {
|
public EngineOptions(EngineOptions other) {
|
||||||
|
@ -58,6 +60,7 @@ public final class EngineOptions {
|
||||||
rtbPath = other.rtbPath;
|
rtbPath = other.rtbPath;
|
||||||
rtbPathNet = other.rtbPathNet;
|
rtbPathNet = other.rtbPathNet;
|
||||||
networkID = other.networkID;
|
networkID = other.networkID;
|
||||||
|
workDir = other.workDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the GTB path for an engine. */
|
/** Get the GTB path for an engine. */
|
||||||
|
@ -90,7 +93,8 @@ public final class EngineOptions {
|
||||||
gtbPathNet.equals(other.gtbPathNet) &&
|
gtbPathNet.equals(other.gtbPathNet) &&
|
||||||
rtbPath.equals(other.rtbPath) &&
|
rtbPath.equals(other.rtbPath) &&
|
||||||
rtbPathNet.equals(other.rtbPathNet) &&
|
rtbPathNet.equals(other.rtbPathNet) &&
|
||||||
networkID.equals(other.networkID));
|
networkID.equals(other.networkID) &&
|
||||||
|
workDir.equals(other.workDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -37,6 +37,7 @@ public class ExternalEngine extends UCIEngineBase {
|
||||||
protected final Context context;
|
protected final Context context;
|
||||||
|
|
||||||
private File engineFileName;
|
private File engineFileName;
|
||||||
|
private File engineWorkDir;
|
||||||
private final Report report;
|
private final Report report;
|
||||||
private Process engineProc;
|
private Process engineProc;
|
||||||
private Thread startupThread;
|
private Thread startupThread;
|
||||||
|
@ -47,10 +48,11 @@ public class ExternalEngine extends UCIEngineBase {
|
||||||
private boolean startedOk;
|
private boolean startedOk;
|
||||||
private boolean isRunning;
|
private boolean isRunning;
|
||||||
|
|
||||||
public ExternalEngine(String engine, Report report) {
|
public ExternalEngine(String engine, String workDir, Report report) {
|
||||||
context = DroidFishApp.getContext();
|
context = DroidFishApp.getContext();
|
||||||
this.report = report;
|
this.report = report;
|
||||||
engineFileName = new File(engine);
|
engineFileName = new File(engine);
|
||||||
|
engineWorkDir = new File(workDir);
|
||||||
engineProc = null;
|
engineProc = null;
|
||||||
startupThread = null;
|
startupThread = null;
|
||||||
exitThread = null;
|
exitThread = null;
|
||||||
|
@ -75,6 +77,7 @@ public class ExternalEngine extends UCIEngineBase {
|
||||||
chmod(exePath);
|
chmod(exePath);
|
||||||
cleanUpExeDir(exeDir, exePath);
|
cleanUpExeDir(exeDir, exePath);
|
||||||
ProcessBuilder pb = new ProcessBuilder(exePath);
|
ProcessBuilder pb = new ProcessBuilder(exePath);
|
||||||
|
pb.directory(engineWorkDir);
|
||||||
synchronized (EngineUtil.nativeLock) {
|
synchronized (EngineUtil.nativeLock) {
|
||||||
engineProc = pb.start();
|
engineProc = pb.start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,8 @@ import android.os.Environment;
|
||||||
/** Stockfish engine running as process, started from assets resource. */
|
/** Stockfish engine running as process, started from assets resource. */
|
||||||
public class InternalStockFish extends ExternalEngine {
|
public class InternalStockFish extends ExternalEngine {
|
||||||
|
|
||||||
public InternalStockFish(Report report) {
|
public InternalStockFish(Report report, String workDir) {
|
||||||
super("", report);
|
super("", workDir, report);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -28,8 +28,8 @@ import com.kalab.chess.enginesupport.ChessEngineResolver;
|
||||||
/** Engine imported from a different android app, resolved using the open exchange format. */
|
/** Engine imported from a different android app, resolved using the open exchange format. */
|
||||||
public class OpenExchangeEngine extends ExternalEngine {
|
public class OpenExchangeEngine extends ExternalEngine {
|
||||||
|
|
||||||
public OpenExchangeEngine(String engine, Report report) {
|
public OpenExchangeEngine(String engine, String workDir, Report report) {
|
||||||
super(engine, report);
|
super(engine, workDir, report);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -42,13 +42,13 @@ public abstract class UCIEngineBase implements UCIEngine {
|
||||||
if ("cuckoochess".equals(engine))
|
if ("cuckoochess".equals(engine))
|
||||||
return new CuckooChessEngine();
|
return new CuckooChessEngine();
|
||||||
else if ("stockfish".equals(engine))
|
else if ("stockfish".equals(engine))
|
||||||
return new InternalStockFish(report);
|
return new InternalStockFish(report, engineOptions.workDir);
|
||||||
else if (EngineUtil.isOpenExchangeEngine(engine))
|
else if (EngineUtil.isOpenExchangeEngine(engine))
|
||||||
return new OpenExchangeEngine(engine, report);
|
return new OpenExchangeEngine(engine, engineOptions.workDir, report);
|
||||||
else if (EngineUtil.isNetEngine(engine))
|
else if (EngineUtil.isNetEngine(engine))
|
||||||
return new NetworkEngine(engine, engineOptions, report);
|
return new NetworkEngine(engine, engineOptions, report);
|
||||||
else
|
else
|
||||||
return new ExternalEngine(engine, report);
|
return new ExternalEngine(engine, engineOptions.workDir, report);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UCIEngineBase() {
|
protected UCIEngineBase() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user