Fix potential crash on startup when loading JNA

This commit is contained in:
Reinhard Pointner 2017-04-09 15:39:16 +08:00
parent 36412a864d
commit c357007510
2 changed files with 18 additions and 18 deletions

View File

@ -1,11 +1,9 @@
package net.filebot; package net.filebot;
import static java.awt.GraphicsEnvironment.*; import static java.awt.GraphicsEnvironment.*;
import static java.util.Arrays.*;
import static java.util.stream.Collectors.*; import static java.util.stream.Collectors.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.Settings.*; import static net.filebot.Settings.*;
import static net.filebot.util.ExceptionUtilities.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.XPathUtilities.*; import static net.filebot.util.XPathUtilities.*;
import static net.filebot.util.ui.SwingUI.*; import static net.filebot.util.ui.SwingUI.*;
@ -36,10 +34,8 @@ import org.w3c.dom.Document;
import net.filebot.cli.ArgumentBean; import net.filebot.cli.ArgumentBean;
import net.filebot.cli.ArgumentProcessor; import net.filebot.cli.ArgumentProcessor;
import net.filebot.cli.CmdlineException;
import net.filebot.format.ExpressionFormat; import net.filebot.format.ExpressionFormat;
import net.filebot.platform.mac.MacAppUtilities; import net.filebot.platform.mac.MacAppUtilities;
import net.filebot.platform.windows.WinAppUtilities;
import net.filebot.ui.FileBotMenuBar; import net.filebot.ui.FileBotMenuBar;
import net.filebot.ui.GettingStartedStage; import net.filebot.ui.GettingStartedStage;
import net.filebot.ui.MainFrame; import net.filebot.ui.MainFrame;
@ -134,7 +130,7 @@ public class Main {
System.exit(1); System.exit(1);
} catch (Throwable e) { } catch (Throwable e) {
// unexpected error => dump stack // unexpected error => dump stack
debug.log(Level.SEVERE, "Error during startup: " + getRootCause(e), e); debug.severe(cause("Error during startup", e));
System.exit(1); System.exit(1);
} }
} }
@ -181,16 +177,7 @@ public class Main {
} }
// start multi panel or single panel frame // start multi panel or single panel frame
PanelBuilder[] panels = PanelBuilder.defaultSequence(); PanelBuilder[] panels = args.getPanelBuilders();
if (args.mode != null) {
panels = stream(panels).filter(p -> p.getName().matches(args.mode)).toArray(PanelBuilder[]::new); // only selected panels
if (panels.length == 0) {
throw new CmdlineException("Illegal mode: " + args.mode);
}
}
JFrame frame = panels.length > 1 ? new MainFrame(panels) : new SinglePanelFrame(panels[0]); JFrame frame = panels.length > 1 ? new MainFrame(panels) : new SinglePanelFrame(panels[0]);
try { try {
@ -221,9 +208,6 @@ public class Main {
frame.setIconImages(ResourceManager.getApplicationIcons()); frame.setIconImages(ResourceManager.getApplicationIcons());
} else if (isWindowsApp()) { } else if (isWindowsApp()) {
// Windows specific configuration // Windows specific configuration
if (!isAppStore()) {
WinAppUtilities.setAppUserModelID(Settings.getApplicationUserModelID()); // support Windows 7 taskbar behaviours (not necessary for Windows 10 apps)
}
frame.setIconImages(ResourceManager.getApplicationIcons()); frame.setIconImages(ResourceManager.getApplicationIcons());
} else { } else {
// generic Linux/FreeBSD/Solaris configuration // generic Linux/FreeBSD/Solaris configuration

View File

@ -1,5 +1,6 @@
package net.filebot.cli; package net.filebot.cli;
import static java.util.Arrays.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.hash.VerificationUtilities.*; import static net.filebot.hash.VerificationUtilities.*;
@ -18,6 +19,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Pattern;
import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.CmdLineException;
@ -38,6 +40,7 @@ import net.filebot.format.ExpressionFormat;
import net.filebot.hash.HashType; import net.filebot.hash.HashType;
import net.filebot.subtitle.SubtitleFormat; import net.filebot.subtitle.SubtitleFormat;
import net.filebot.subtitle.SubtitleNaming; import net.filebot.subtitle.SubtitleNaming;
import net.filebot.ui.PanelBuilder;
import net.filebot.web.Datasource; import net.filebot.web.Datasource;
import net.filebot.web.EpisodeListProvider; import net.filebot.web.EpisodeListProvider;
import net.filebot.web.SortOrder; import net.filebot.web.SortOrder;
@ -304,6 +307,19 @@ public class ArgumentBean {
return Level.parse(log.toUpperCase()); return Level.parse(log.toUpperCase());
} }
public PanelBuilder[] getPanelBuilders() {
// default multi panel mode
if (mode == null) {
return PanelBuilder.defaultSequence();
}
// only selected panels
return optional(mode).map(m -> {
Pattern pattern = Pattern.compile(mode, Pattern.CASE_INSENSITIVE);
return stream(PanelBuilder.defaultSequence()).filter(p -> pattern.matcher(p.getName()).matches()).toArray(PanelBuilder[]::new);
}).orElseThrow(error("Illegal mode", mode));
}
private final String[] args; private final String[] args;
public ArgumentBean(String... args) throws CmdLineException { public ArgumentBean(String... args) throws CmdLineException {