Skip to content

Commit

Permalink
'#2196: Extract LibreOffice (in Windows) even if --nogui was used
Browse files Browse the repository at this point in the history
  • Loading branch information
wladimirleite committed May 3, 2024
1 parent 889486a commit bc5a442
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
11 changes: 4 additions & 7 deletions iped-app/src/main/java/iped/app/bootstrap/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ protected void run(String args[]) {
classpath += separator + pluginConfig.getPluginFolder().getAbsolutePath() + "/*";
}

// user can't open analysis UI w/ --nogui, so no need to load libreoffice jars
if (!iped.getCmdLineArgs().isNogui()) {
classpath = fillClassPathWithLibreOfficeJars(iped, classpath);
}
classpath = fillClassPathWithLibreOfficeJars(iped, classpath, iped.getCmdLineArgs().isNogui());

String javaBin = "java";
if (SystemUtils.IS_OS_WINDOWS) {
Expand Down Expand Up @@ -278,14 +275,14 @@ private static List<String> getSystemProperties() {
return props;
}

private static String fillClassPathWithLibreOfficeJars(Main iped, String classpath)
private static String fillClassPathWithLibreOfficeJars(Main iped, String classpath, boolean isNogui)
throws URISyntaxException, IOException {
System.setProperty(IOfficeApplication.NOA_NATIVE_LIB_PATH,
new File(iped.getRootPath(), "lib/nativeview").getAbsolutePath());
LibreOfficeFinder loFinder = new LibreOfficeFinder(new File(iped.getRootPath()));
if (loFinder.getLOPath() != null) {
if (loFinder.getLOPath(isNogui) != null) {
List<File> jars = new ArrayList<>();
UNOLibFinder.addUNOJars(loFinder.getLOPath(), jars);
UNOLibFinder.addUNOJars(loFinder.getLOPath(isNogui), jars);
for (File jar : jars) {
classpath += separator + jar.getCanonicalPath();
}
Expand Down
2 changes: 1 addition & 1 deletion iped-app/src/main/java/iped/app/ui/ViewerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void run() {
URI jarUri = URLUtil.getURL(LibreOfficeViewer.class).toURI();
File moduledir = new File(jarUri).getParentFile().getParentFile();
LibreOfficeFinder loFinder = new LibreOfficeFinder(moduledir);
final String pathLO = loFinder.getLOPath();
final String pathLO = loFinder.getLOPath(false);
if (pathLO != null) {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void init(ConfigurationManager configurationManager) throws Exception {
URL url = URLUtil.getURL(this.getClass());
File jarDir = new File(url.toURI()).getParentFile();
LibreOfficeFinder loFinder = new LibreOfficeFinder(jarDir);
loPath = loFinder.getLOPath();
loPath = loFinder.getLOPath(true);
logger.info("LibreOffice Path: " + loPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public LOExtractor(File input, File output) {
this.input = input;
}

public boolean decompressLO() {
public boolean decompressLO(boolean isNogui) {

try {
if (output.exists()) {
Expand All @@ -44,14 +44,16 @@ public boolean decompressLO() {
}

if (input.exists()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
progressMonitor = new ProgressDialog(null, LOExtractor.this);
progressMonitor.setMaximum(numSubitens);
progressMonitor.setNote(Messages.getString("LOExtractor.DecompressingLO")); //$NON-NLS-1$
}
});
if (!isNogui) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
progressMonitor = new ProgressDialog(null, LOExtractor.this);
progressMonitor.setMaximum(numSubitens);
progressMonitor.setNote(Messages.getString("LOExtractor.DecompressingLO")); //$NON-NLS-1$
}
});
}

try (ZipFile zip = new ZipFile(input)) {
Enumeration<ZipArchiveEntry> e = zip.getEntries();
Expand All @@ -69,15 +71,17 @@ public void run() {
if (++progress == numSubitens)
completed = true;

progressMonitor.setProgress(progress);

if (progressMonitor.isCanceled())
break;
if (progressMonitor != null) {
progressMonitor.setProgress(progress);

if (progressMonitor.isCanceled())
break;
}
}
}
}

if (!progressMonitor.isCanceled()) {
if (progressMonitor != null && !progressMonitor.isCanceled()) {
progressMonitor.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public LibreOfficeFinder(File baseFolder) {
baseDir = baseFolder;
}

public String getLOPath() {
public String getLOPath(boolean isNogui) {
if (detectedPath == null) {
detectedPath = System.getProperty("libreOfficePath");
if (detectedPath != null)
Expand All @@ -62,7 +62,7 @@ public String getLOPath() {

if (winPathLO.exists() || compressedLO.exists()) { // $NON-NLS-1$ //$NON-NLS-2$
LOExtractor extractor = new LOExtractor(compressedLO, winPathLO);
if (extractor.decompressLO())
if (extractor.decompressLO(isNogui))
detectedPath = winPathLO.getAbsolutePath();
}
}
Expand Down

0 comments on commit bc5a442

Please sign in to comment.