implemented checking for required applications
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>BelegScanner</groupId>
|
<groupId>BelegScanner</groupId>
|
||||||
<artifactId>BelegScanner</artifactId>
|
<artifactId>BelegScanner</artifactId>
|
||||||
<version>1.0.4</version>
|
<version>1.0.5</version>
|
||||||
|
|
||||||
<name>BelegScanner</name>
|
<name>BelegScanner</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class Application {
|
|||||||
Configuration config = new Configuration(Constants.APPLICATION_NAME);
|
Configuration config = new Configuration(Constants.APPLICATION_NAME);
|
||||||
MainFrame app = new MainFrame(config);
|
MainFrame app = new MainFrame(config);
|
||||||
app.setDefaultCloseOperation(MainFrame.EXIT_ON_CLOSE);
|
app.setDefaultCloseOperation(MainFrame.EXIT_ON_CLOSE);
|
||||||
|
app.checkDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,17 +8,16 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Vector;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
@@ -32,6 +31,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import static de.srsoftware.belegscanner.Application.*;
|
import static de.srsoftware.belegscanner.Application.*;
|
||||||
import de.srsoftware.belegscanner.Configuration;
|
import de.srsoftware.belegscanner.Configuration;
|
||||||
|
import de.srsoftware.belegscanner.Constants;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,7 +136,25 @@ public class MainFrame extends JFrame {
|
|||||||
while (matches.find()) marks.add(matches.group(1));
|
while (matches.find()) marks.add(matches.group(1));
|
||||||
toolbar.addFieldsFor(marks);
|
toolbar.addFieldsFor(marks);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public void checkDependencies() {
|
||||||
|
List<String> missing = List.of("convert --version", "killall --version", "pdfsandwich -version", "pdftk --version", "scanimage --version",Constants.FILE_BROWSER+" --version").stream().map(this::appMissing).filter(app -> app != null).collect(Collectors.toList());
|
||||||
|
if (!missing.isEmpty()) notifyAppsMissing(missing);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String appMissing(String appTest){
|
||||||
|
List<String> cmd = Arrays.asList(appTest.split(" "));
|
||||||
|
|
||||||
|
try {
|
||||||
|
Process process = new ProcessBuilder(cmd).start();
|
||||||
|
int errorCode = process.waitFor();
|
||||||
|
if (errorCode == 0) return null;
|
||||||
|
} catch (InterruptedException | IOException e) {
|
||||||
|
LOG.error(t("{} terminated: "),appTest,e);
|
||||||
|
}
|
||||||
|
return cmd.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks, whether the scan button may be enabled.
|
* checks, whether the scan button may be enabled.
|
||||||
*/
|
*/
|
||||||
@@ -144,6 +162,22 @@ public class MainFrame extends JFrame {
|
|||||||
toolbar.readyToScan(!(isScanning || patchedPath==null || patchedPath.isBlank() || patchedPath.contains("$")));
|
toolbar.readyToScan(!(isScanning || patchedPath==null || patchedPath.isBlank() || patchedPath.contains("$")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void notifyAppsMissing(List<String> missingApps) {
|
||||||
|
StringBuilder message = new StringBuilder();
|
||||||
|
message.append("<html>");
|
||||||
|
message.append(t("This application requires the following helper commands to be installed:"));
|
||||||
|
message.append("<ul>");
|
||||||
|
missingApps.forEach(app -> message.append("<li>").append(app).append("</li>"));
|
||||||
|
message.append("</ul>");
|
||||||
|
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
message,
|
||||||
|
t("Apps missing"),
|
||||||
|
JOptionPane.WARNING_MESSAGE);
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* scan a new document, convert it to pdf and perform text recognition
|
* scan a new document, convert it to pdf and perform text recognition
|
||||||
* @param path
|
* @param path
|
||||||
|
|||||||
Reference in New Issue
Block a user