Fix error prone code
This commit is contained in:
parent
fd54c59c71
commit
742e3aea2d
|
@ -31,7 +31,7 @@ public final class HistorySpooler {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(HistorySpooler.getInstance()::commit, "HistorySpoolerShutdownHook")); // commit session history on shutdown
|
Runtime.getRuntime().addShutdownHook(new Thread(HistorySpooler.getInstance()::commit, "HistorySpoolerShutdownHook")); // commit session history on shutdown
|
||||||
}
|
}
|
||||||
|
|
||||||
private final File persistentHistoryFile = ApplicationFolder.AppData.resolve("history.xml");
|
private final File persistentHistoryFile = ApplicationFolder.AppData.path("history.xml");
|
||||||
|
|
||||||
private int persistentHistoryTotalSize = -1;
|
private int persistentHistoryTotalSize = -1;
|
||||||
private boolean persistentHistoryEnabled = true;
|
private boolean persistentHistoryEnabled = true;
|
||||||
|
|
|
@ -40,6 +40,7 @@ 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.mac.MacAppUtilities;
|
import net.filebot.mac.MacAppUtilities;
|
||||||
import net.filebot.ui.FileBotMenuBar;
|
import net.filebot.ui.FileBotMenuBar;
|
||||||
|
@ -190,27 +191,23 @@ public class Main {
|
||||||
setSystemLookAndFeel();
|
setSystemLookAndFeel();
|
||||||
}
|
}
|
||||||
|
|
||||||
// default frame
|
// start multi panel or single panel frame
|
||||||
JFrame frame = new MainFrame(PanelBuilder.defaultSequence());
|
PanelBuilder[] panels = PanelBuilder.defaultSequence();
|
||||||
|
|
||||||
// single panel frame
|
|
||||||
if (args.mode != null) {
|
if (args.mode != null) {
|
||||||
PanelBuilder[] selection = stream(PanelBuilder.defaultSequence()).filter(p -> p.getName().matches(args.mode)).toArray(PanelBuilder[]::new);
|
panels = stream(panels).filter(p -> p.getName().matches(args.mode)).toArray(PanelBuilder[]::new); // only selected panels
|
||||||
if (selection.length == 1) {
|
|
||||||
frame = new SinglePanelFrame(selection[0]);
|
if (panels.length == 0) {
|
||||||
} else if (selection.length > 1) {
|
throw new CmdlineException("Illegal mode: " + args.mode);
|
||||||
frame = new MainFrame(selection);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Illegal mode: " + args.mode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JFrame frame = panels.length > 1 ? new MainFrame(panels) : new SinglePanelFrame(panels[0]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// restore previous size and location
|
restoreWindowBounds(frame, Settings.forPackage(MainFrame.class)); // restore previous size and location
|
||||||
restoreWindowBounds(frame, Settings.forPackage(MainFrame.class));
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// make sure the main window is not displayed out of screen bounds
|
frame.setLocation(120, 80); // make sure the main window is not displayed out of screen bounds
|
||||||
frame.setLocation(120, 80);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frame.addWindowListener(windowClosed(evt -> {
|
frame.addWindowListener(windowClosed(evt -> {
|
||||||
|
@ -368,19 +365,17 @@ public class Main {
|
||||||
System.setProperty("sun.net.client.defaultReadTimeout", "60000");
|
System.setProperty("sun.net.client.defaultReadTimeout", "60000");
|
||||||
|
|
||||||
System.setProperty("swing.crossplatformlaf", "javax.swing.plaf.nimbus.NimbusLookAndFeel");
|
System.setProperty("swing.crossplatformlaf", "javax.swing.plaf.nimbus.NimbusLookAndFeel");
|
||||||
System.setProperty("grape.root", ApplicationFolder.AppData.resolve("grape").getAbsolutePath());
|
System.setProperty("grape.root", ApplicationFolder.AppData.path("grape").getPath());
|
||||||
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
|
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
|
||||||
|
|
||||||
if (args.unixfs) {
|
if (args.unixfs) {
|
||||||
System.setProperty("unixfs", "true");
|
System.setProperty("unixfs", "true");
|
||||||
}
|
}
|
||||||
if (args.disableExtendedAttributes || "TEST".equalsIgnoreCase(args.action)) {
|
|
||||||
|
if (args.disableExtendedAttributes) {
|
||||||
System.setProperty("useExtendedFileAttributes", "false");
|
System.setProperty("useExtendedFileAttributes", "false");
|
||||||
System.setProperty("useCreationDate", "false");
|
System.setProperty("useCreationDate", "false");
|
||||||
}
|
}
|
||||||
if ("TEST".equalsIgnoreCase(args.action)) {
|
|
||||||
System.setProperty("application.rename.history", "false"); // do not keep history of --action test rename operations
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initializeLogging(ArgumentBean args) throws IOException {
|
public static void initializeLogging(ArgumentBean args) throws IOException {
|
||||||
|
@ -394,7 +389,7 @@ public class Main {
|
||||||
|
|
||||||
// log errors to file
|
// log errors to file
|
||||||
try {
|
try {
|
||||||
Handler error = createSimpleFileHandler(ApplicationFolder.AppData.resolve("error.log"), Level.WARNING);
|
Handler error = createSimpleFileHandler(ApplicationFolder.AppData.path("error.log"), Level.WARNING);
|
||||||
log.addHandler(error);
|
log.addHandler(error);
|
||||||
debug.addHandler(error);
|
debug.addHandler(error);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -406,7 +401,7 @@ public class Main {
|
||||||
if (args.logFile != null) {
|
if (args.logFile != null) {
|
||||||
File logFile = new File(args.logFile);
|
File logFile = new File(args.logFile);
|
||||||
if (!logFile.isAbsolute()) {
|
if (!logFile.isAbsolute()) {
|
||||||
logFile = new File(ApplicationFolder.AppData.resolve("logs"), logFile.getPath()).getAbsoluteFile(); // by default resolve relative paths against {applicationFolder}/logs/{logFile}
|
logFile = new File(ApplicationFolder.AppData.path("logs"), logFile.getPath()).getAbsoluteFile(); // by default resolve relative paths against {applicationFolder}/logs/{logFile}
|
||||||
}
|
}
|
||||||
if (!logFile.exists() && !logFile.getParentFile().mkdirs() && !logFile.createNewFile()) {
|
if (!logFile.exists() && !logFile.getParentFile().mkdirs() && !logFile.createNewFile()) {
|
||||||
throw new IOException("Failed to create log file: " + logFile);
|
throw new IOException("Failed to create log file: " + logFile);
|
||||||
|
|
|
@ -21,6 +21,8 @@ import org.kohsuke.args4j.ParserProperties;
|
||||||
import org.kohsuke.args4j.spi.ExplicitBooleanOptionHandler;
|
import org.kohsuke.args4j.spi.ExplicitBooleanOptionHandler;
|
||||||
|
|
||||||
import net.filebot.Language;
|
import net.filebot.Language;
|
||||||
|
import net.filebot.StandardRenameAction;
|
||||||
|
import net.filebot.web.SortOrder;
|
||||||
|
|
||||||
public class ArgumentBean {
|
public class ArgumentBean {
|
||||||
|
|
||||||
|
@ -180,6 +182,18 @@ public class ArgumentBean {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StandardRenameAction getRenameAction() {
|
||||||
|
return StandardRenameAction.forName(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConflictAction getConflictAction() {
|
||||||
|
return ConflictAction.forName(conflict);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortOrder getSortOrder() {
|
||||||
|
return SortOrder.forName(order);
|
||||||
|
}
|
||||||
|
|
||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
return new Locale(lang);
|
return new Locale(lang);
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ public class GroovyPad extends JFrame {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// use this default value so people can easily submit bug reports with fn:sysinfo logs
|
// use this default value so people can easily submit bug reports with fn:sysinfo logs
|
||||||
File pad = ApplicationFolder.AppData.resolve("pad.groovy");
|
File pad = ApplicationFolder.AppData.path("pad.groovy");
|
||||||
|
|
||||||
if (!pad.exists()) {
|
if (!pad.exists()) {
|
||||||
ScriptShellMethods.saveAs(DEFAULT_SCRIPT, pad);
|
ScriptShellMethods.saveAs(DEFAULT_SCRIPT, pad);
|
||||||
|
|
|
@ -499,8 +499,8 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
for (Entry<String, ?> it : parameters.entrySet()) {
|
for (Entry<String, ?> it : parameters.entrySet()) {
|
||||||
try {
|
try {
|
||||||
options.put(Option.valueOf(it.getKey()), it.getValue());
|
options.put(Option.valueOf(it.getKey()), it.getValue());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (Exception e) {
|
||||||
// just ignore illegal options
|
debug.warning(e::toString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ class ExpressionFormatter implements MatchFormatter {
|
||||||
|
|
||||||
// resolve against home folder
|
// resolve against home folder
|
||||||
if (destination.startsWith("~")) {
|
if (destination.startsWith("~")) {
|
||||||
return ApplicationFolder.UserHome.resolve(destination.substring(1)).getAbsolutePath();
|
return ApplicationFolder.UserHome.path(destination.substring(1)).getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to resolve against structure root folder by default
|
// try to resolve against structure root folder by default
|
||||||
|
|
|
@ -67,7 +67,6 @@ import net.filebot.format.MediaBindingBean;
|
||||||
import net.filebot.format.SuppressedThrowables;
|
import net.filebot.format.SuppressedThrowables;
|
||||||
import net.filebot.mac.MacAppUtilities;
|
import net.filebot.mac.MacAppUtilities;
|
||||||
import net.filebot.media.MetaAttributes;
|
import net.filebot.media.MetaAttributes;
|
||||||
import net.filebot.mediainfo.MediaInfo;
|
|
||||||
import net.filebot.util.DefaultThreadFactory;
|
import net.filebot.util.DefaultThreadFactory;
|
||||||
import net.filebot.util.ExceptionUtilities;
|
import net.filebot.util.ExceptionUtilities;
|
||||||
import net.filebot.util.PreferencesList;
|
import net.filebot.util.PreferencesList;
|
||||||
|
@ -305,16 +304,18 @@ public class FormatDialog extends JDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFormatCode(String text) {
|
public void setFormatCode(String text) {
|
||||||
// update format code
|
|
||||||
editor.setText(text);
|
|
||||||
|
|
||||||
// scroll to last character and focus
|
|
||||||
try {
|
try {
|
||||||
editor.scrollRectToVisible(new Rectangle(0, 0)); // reset scroll
|
// update format code
|
||||||
editor.setCaretPosition(text.length()); // scroll to end of format
|
editor.setText(text);
|
||||||
editor.requestFocusInWindow();
|
|
||||||
|
// scroll to last character and focus
|
||||||
|
if (text != null && text.length() > 0) {
|
||||||
|
editor.scrollRectToVisible(new Rectangle(0, 0)); // reset scroll
|
||||||
|
editor.setCaretPosition(editor.getText().length()); // scroll to end of format
|
||||||
|
editor.requestFocusInWindow();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warning(e::getMessage);
|
debug.warning(e::toString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,15 +714,4 @@ public class FormatDialog extends JDialog {
|
||||||
firePropertyChange("sample", null, sample);
|
firePropertyChange("sample", null, sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
// load all necessarily classes to avoid focus issues with RSyntaxTextArea
|
|
||||||
new RSyntaxTextArea(new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_GROOVY));
|
|
||||||
new ExpressionFormat("{n.space('.').lower()}.{s}{e.pad(2)}");
|
|
||||||
new MediaInfo();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
debug.log(Level.SEVERE, "Failed to initialize FormatDialog", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue