From 4418a5745df723c647251e185ed269c2221d448a Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Sat, 14 Jan 2023 21:53:16 +0900 Subject: [PATCH 1/5] Avoid hang-ups in engine setting dialog --- src/main/java/featurecat/lizzie/gui/ConfigDialog.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java index a0d50074e..2ffd12bf7 100644 --- a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java +++ b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java @@ -1898,10 +1898,9 @@ private void getCommandHelp() { commands.add(enginePath); commands.add("-h"); - ProcessBuilder processBuilder = new ProcessBuilder(commands); - processBuilder.directory(); - processBuilder.redirectErrorStream(true); try { + ProcessBuilder processBuilder = new ProcessBuilder(commands); + processBuilder.redirectErrorStream(true); Process process = processBuilder.start(); inputStream = new BufferedInputStream(process.getInputStream()); ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); From 7f06992eb4611f7cac4f545e74aad7f6be0f47ae Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Sat, 14 Jan 2023 21:53:16 +0900 Subject: [PATCH 2/5] Fix "Cannot run program" in engine setting on Linux --- src/main/java/featurecat/lizzie/gui/ConfigDialog.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java index 2ffd12bf7..fe483e15a 100644 --- a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java +++ b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java @@ -1838,8 +1838,7 @@ private String getEngineLine() { if (result == JFileChooser.APPROVE_OPTION) { engineFile = chooser.getSelectedFile(); if (engineFile != null) { - enginePath = engineFile.getAbsolutePath(); - enginePath = relativizePath(engineFile.toPath(), this.curPath); + enginePath = relativizePath(engineFile.toPath(), this.curPath, true); getCommandHelp(); JFileChooser chooserw = new JFileChooser("."); chooserw.setMultiSelectionEnabled(false); @@ -1883,12 +1882,20 @@ private String getImagePath() { } private String relativizePath(Path path, Path curPath) { + return relativizePath(path, curPath, false); + } + + private String relativizePath(Path path, Path curPath, Boolean isCommand) { Path relatPath; if (path.startsWith(curPath)) { relatPath = curPath.relativize(path); } else { relatPath = path; } + if (isCommand && relatPath.getFileName().equals(relatPath) && !isWindows()) { + // "leelaz" ==> "./leelaz" for Linux + relatPath = (new File(".")).toPath().resolve(relatPath); + } return relatPath.toString(); } From 4e6994d75250d5622cadf4cdb3ab0622c382b891 Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Sat, 14 Jan 2023 21:53:16 +0900 Subject: [PATCH 3/5] Modify default options depending on the engine (#914) --- .../java/featurecat/lizzie/gui/ConfigDialog.java | 13 ++++++++++++- .../java/featurecat/lizzie/gui/EngineParameter.java | 12 ++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java index fe483e15a..aa13e52c5 100644 --- a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java +++ b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java @@ -1848,7 +1848,8 @@ private String getEngineLine() { weightFile = chooserw.getSelectedFile(); if (weightFile != null) { weightPath = relativizePath(weightFile.toPath(), this.curPath); - EngineParameter ep = new EngineParameter(enginePath, weightPath, this); + EngineParameter ep = + new EngineParameter(enginePath, weightPath, guessedEngineType(), this); ep.setVisible(true); if (!ep.commandLine.isEmpty()) { engineLine = ep.commandLine; @@ -1860,6 +1861,13 @@ private String getEngineLine() { return engineLine; } + private String guessedEngineType() { + String engineFileName = (new File(enginePath)).toPath().getFileName().toString(); + // fixme: ad hoc! + Boolean isKataGo = engineFileName.toLowerCase().contains("katago"); + return isKataGo ? "katago" : "leelaz"; + } + private String getImagePath() { String imagePath = ""; File imageFile = null; @@ -1903,6 +1911,9 @@ private void getCommandHelp() { List commands = new ArrayList(); commands.add(enginePath); + if (guessedEngineType().equals("katago")) { + commands.add("gtp"); + } commands.add("-h"); try { diff --git a/src/main/java/featurecat/lizzie/gui/EngineParameter.java b/src/main/java/featurecat/lizzie/gui/EngineParameter.java index 536035432..a56ac573b 100644 --- a/src/main/java/featurecat/lizzie/gui/EngineParameter.java +++ b/src/main/java/featurecat/lizzie/gui/EngineParameter.java @@ -30,7 +30,8 @@ public class EngineParameter extends JDialog { private Color oriColor; /** Create the dialog. */ - public EngineParameter(String enginePath, String weightPath, ConfigDialog configDialog) { + public EngineParameter( + String enginePath, String weightPath, String engineType, ConfigDialog configDialog) { setTitle(configDialog.resourceBundle.getString("LizzieConfig.title.parameterConfig")); setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); setModal(true); @@ -48,7 +49,8 @@ public EngineParameter(String enginePath, String weightPath, ConfigDialog config txtCommandLine = new JTextField(); txtCommandLine.setEditable(false); txtCommandLine.setBounds(89, 12, 565, 26); - txtCommandLine.setText(enginePath + " --weights " + weightPath); + String weightOption = (engineType.equals("leelaz")) ? " --weights " : " gtp -model "; + txtCommandLine.setText(enginePath + weightOption + weightPath); contentPanel.add(txtCommandLine); txtCommandLine.setColumns(10); JLabel lblParameter = @@ -67,7 +69,9 @@ public void focusLost(FocusEvent e) { }); txtParameter.setColumns(10); txtParameter.setBounds(89, 44, 565, 26); - txtParameter.setText("-g --lagbuffer 0 "); + if (engineType.equals("leelaz")) { + txtParameter.setText("-g --lagbuffer 0 "); + } oriColor = txtParameter.getBackground(); contentPanel.add(txtParameter); @@ -95,7 +99,7 @@ public void focusLost(FocusEvent e) { okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { - if (txtParameter.getText().isEmpty()) { + if (txtParameter.getText().isEmpty() && engineType.equals("leelaz")) { txtParameter.setBackground(Color.RED); } else { parameters = txtParameter.getText().trim(); From 35afed8ec8aa255aeb65a5c26f32a870a1c17b10 Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Sun, 15 Jan 2023 06:10:09 +0900 Subject: [PATCH 4/5] Add "-config" in engine setting for KataGo (#914) --- .../featurecat/lizzie/gui/ConfigDialog.java | 18 +++++++++++++++++- .../featurecat/lizzie/gui/EngineParameter.java | 12 +++++++++--- .../resources/l10n/DisplayStrings.properties | 1 + 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java index aa13e52c5..798d4c59b 100644 --- a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java +++ b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java @@ -104,6 +104,7 @@ public class ConfigDialog extends JDialog { public String enginePath = ""; public String weightPath = ""; + public String configPath = ""; public String commandHelp = ""; private String osName; @@ -1848,8 +1849,9 @@ private String getEngineLine() { weightFile = chooserw.getSelectedFile(); if (weightFile != null) { weightPath = relativizePath(weightFile.toPath(), this.curPath); + configPath = selectConfigFile(); EngineParameter ep = - new EngineParameter(enginePath, weightPath, guessedEngineType(), this); + new EngineParameter(enginePath, weightPath, configPath, guessedEngineType(), this); ep.setVisible(true); if (!ep.commandLine.isEmpty()) { engineLine = ep.commandLine; @@ -1861,6 +1863,20 @@ private String getEngineLine() { return engineLine; } + private String selectConfigFile() { + if (!guessedEngineType().equals("katago")) return ""; + String titleKey = "LizzieConfig.prompt.selectConfig"; + // dare to copy code redundantly to keep the original code as much as possible + JFileChooser chooser = new JFileChooser("."); + chooser.setMultiSelectionEnabled(false); + chooser.setDialogTitle(resourceBundle.getString(titleKey)); + int result = chooser.showOpenDialog(this); + if (result != JFileChooser.APPROVE_OPTION) return ""; + File file = chooser.getSelectedFile(); + if (file == null) return ""; + return relativizePath(file.toPath(), this.curPath); + } + private String guessedEngineType() { String engineFileName = (new File(enginePath)).toPath().getFileName().toString(); // fixme: ad hoc! diff --git a/src/main/java/featurecat/lizzie/gui/EngineParameter.java b/src/main/java/featurecat/lizzie/gui/EngineParameter.java index a56ac573b..fdf5b01cb 100644 --- a/src/main/java/featurecat/lizzie/gui/EngineParameter.java +++ b/src/main/java/featurecat/lizzie/gui/EngineParameter.java @@ -31,7 +31,11 @@ public class EngineParameter extends JDialog { /** Create the dialog. */ public EngineParameter( - String enginePath, String weightPath, String engineType, ConfigDialog configDialog) { + String enginePath, + String weightPath, + String configPath, + String engineType, + ConfigDialog configDialog) { setTitle(configDialog.resourceBundle.getString("LizzieConfig.title.parameterConfig")); setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); setModal(true); @@ -49,8 +53,10 @@ public EngineParameter( txtCommandLine = new JTextField(); txtCommandLine.setEditable(false); txtCommandLine.setBounds(89, 12, 565, 26); - String weightOption = (engineType.equals("leelaz")) ? " --weights " : " gtp -model "; - txtCommandLine.setText(enginePath + weightOption + weightPath); + String weightOption = engineType.equals("leelaz") ? " --weights " : " gtp -model "; + String configArgs = + (engineType.equals("leelaz") || configPath.isEmpty()) ? "" : " -config " + configPath + " "; + txtCommandLine.setText(enginePath + weightOption + weightPath + configArgs); contentPanel.add(txtCommandLine); txtCommandLine.setColumns(10); JLabel lblParameter = diff --git a/src/main/resources/l10n/DisplayStrings.properties b/src/main/resources/l10n/DisplayStrings.properties index 04dfb56ff..3be3952c7 100644 --- a/src/main/resources/l10n/DisplayStrings.properties +++ b/src/main/resources/l10n/DisplayStrings.properties @@ -149,6 +149,7 @@ LizzieConfig.lizzie.contributorsTitle=cngoodboykaorahizsalchbittsittOlivierBlanvillaindfanniustoomasrapetrescTFiFiEaerisnjukuba97531bvandenbonKa-zamtypohhalreadydoneodCattomasz-warnielloinohirokiParmuzinAlexanderygrekpliuphysinfinity0yzyrayrexl2018gjm11bvandenbon-objtYi-KaiDuskEaglenjfoxkomu LizzieConfig.prompt.selectEngine=Please select a engine LizzieConfig.prompt.selectWeight=Please select a weight file +LizzieConfig.prompt.selectConfig=Please select a config file LizzieConfig.button.ok=OK LizzieConfig.button.cancel=Cancel LizzieConfig.button.add=Add From 88d0ae2a5944a4dcba25be46be2561093f25f29d Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Sun, 15 Jan 2023 06:10:09 +0900 Subject: [PATCH 5/5] Scroll to the top of help message in engine setting --- src/main/java/featurecat/lizzie/gui/EngineParameter.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/featurecat/lizzie/gui/EngineParameter.java b/src/main/java/featurecat/lizzie/gui/EngineParameter.java index fdf5b01cb..e30e81ccb 100644 --- a/src/main/java/featurecat/lizzie/gui/EngineParameter.java +++ b/src/main/java/featurecat/lizzie/gui/EngineParameter.java @@ -4,6 +4,7 @@ import java.awt.Color; import java.awt.FlowLayout; import java.awt.Font; +import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; @@ -15,6 +16,7 @@ import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JTextPane; +import javax.swing.SwingUtilities; import javax.swing.border.EmptyBorder; public class EngineParameter extends JDialog { @@ -93,6 +95,7 @@ public void focusLost(FocusEvent e) { txtParams.setFont(font); txtParams.setText(configDialog.commandHelp); txtParams.setEditable(false); + SwingUtilities.invokeLater(() -> txtParams.scrollRectToVisible(new Rectangle(0, 0, 0, 0))); JLabel lblParameterList = new JLabel(configDialog.resourceBundle.getString("LizzieConfig.title.parameterList"));