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
|
||||
}
|
||||
|
||||
private final File persistentHistoryFile = ApplicationFolder.AppData.resolve("history.xml");
|
||||
private final File persistentHistoryFile = ApplicationFolder.AppData.path("history.xml");
|
||||
|
||||
private int persistentHistoryTotalSize = -1;
|
||||
private boolean persistentHistoryEnabled = true;
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.w3c.dom.Document;
|
|||
|
||||
import net.filebot.cli.ArgumentBean;
|
||||
import net.filebot.cli.ArgumentProcessor;
|
||||
import net.filebot.cli.CmdlineException;
|
||||
import net.filebot.format.ExpressionFormat;
|
||||
import net.filebot.mac.MacAppUtilities;
|
||||
import net.filebot.ui.FileBotMenuBar;
|
||||
|
@ -190,27 +191,23 @@ public class Main {
|
|||
setSystemLookAndFeel();
|
||||
}
|
||||
|
||||
// default frame
|
||||
JFrame frame = new MainFrame(PanelBuilder.defaultSequence());
|
||||
// start multi panel or single panel frame
|
||||
PanelBuilder[] panels = PanelBuilder.defaultSequence();
|
||||
|
||||
// single panel frame
|
||||
if (args.mode != null) {
|
||||
PanelBuilder[] selection = stream(PanelBuilder.defaultSequence()).filter(p -> p.getName().matches(args.mode)).toArray(PanelBuilder[]::new);
|
||||
if (selection.length == 1) {
|
||||
frame = new SinglePanelFrame(selection[0]);
|
||||
} else if (selection.length > 1) {
|
||||
frame = new MainFrame(selection);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Illegal mode: " + args.mode);
|
||||
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]);
|
||||
|
||||
try {
|
||||
// restore previous size and location
|
||||
restoreWindowBounds(frame, Settings.forPackage(MainFrame.class));
|
||||
restoreWindowBounds(frame, Settings.forPackage(MainFrame.class)); // restore previous size and location
|
||||
} catch (Exception e) {
|
||||
// make sure the main window is not displayed out of screen bounds
|
||||
frame.setLocation(120, 80);
|
||||
frame.setLocation(120, 80); // make sure the main window is not displayed out of screen bounds
|
||||
}
|
||||
|
||||
frame.addWindowListener(windowClosed(evt -> {
|
||||
|
@ -368,19 +365,17 @@ public class Main {
|
|||
System.setProperty("sun.net.client.defaultReadTimeout", "60000");
|
||||
|
||||
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");
|
||||
|
||||
if (args.unixfs) {
|
||||
System.setProperty("unixfs", "true");
|
||||
}
|
||||
if (args.disableExtendedAttributes || "TEST".equalsIgnoreCase(args.action)) {
|
||||
|
||||
if (args.disableExtendedAttributes) {
|
||||
System.setProperty("useExtendedFileAttributes", "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 {
|
||||
|
@ -394,7 +389,7 @@ public class Main {
|
|||
|
||||
// log errors to file
|
||||
try {
|
||||
Handler error = createSimpleFileHandler(ApplicationFolder.AppData.resolve("error.log"), Level.WARNING);
|
||||
Handler error = createSimpleFileHandler(ApplicationFolder.AppData.path("error.log"), Level.WARNING);
|
||||
log.addHandler(error);
|
||||
debug.addHandler(error);
|
||||
} catch (Exception e) {
|
||||
|
@ -406,7 +401,7 @@ public class Main {
|
|||
if (args.logFile != null) {
|
||||
File logFile = new File(args.logFile);
|
||||
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()) {
|
||||
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 net.filebot.Language;
|
||||
import net.filebot.StandardRenameAction;
|
||||
import net.filebot.web.SortOrder;
|
||||
|
||||
public class ArgumentBean {
|
||||
|
||||
|
@ -180,6 +182,18 @@ public class ArgumentBean {
|
|||
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() {
|
||||
return new Locale(lang);
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ public class GroovyPad extends JFrame {
|
|||
|
||||
try {
|
||||
// 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()) {
|
||||
ScriptShellMethods.saveAs(DEFAULT_SCRIPT, pad);
|
||||
|
|
|
@ -499,8 +499,8 @@ public abstract class ScriptShellBaseClass extends Script {
|
|||
for (Entry<String, ?> it : parameters.entrySet()) {
|
||||
try {
|
||||
options.put(Option.valueOf(it.getKey()), it.getValue());
|
||||
} catch (IllegalArgumentException e) {
|
||||
// just ignore illegal options
|
||||
} catch (Exception e) {
|
||||
debug.warning(e::toString);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ class ExpressionFormatter implements MatchFormatter {
|
|||
|
||||
// resolve against home folder
|
||||
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
|
||||
|
|
|
@ -67,7 +67,6 @@ import net.filebot.format.MediaBindingBean;
|
|||
import net.filebot.format.SuppressedThrowables;
|
||||
import net.filebot.mac.MacAppUtilities;
|
||||
import net.filebot.media.MetaAttributes;
|
||||
import net.filebot.mediainfo.MediaInfo;
|
||||
import net.filebot.util.DefaultThreadFactory;
|
||||
import net.filebot.util.ExceptionUtilities;
|
||||
import net.filebot.util.PreferencesList;
|
||||
|
@ -305,16 +304,18 @@ public class FormatDialog extends JDialog {
|
|||
}
|
||||
|
||||
public void setFormatCode(String text) {
|
||||
try {
|
||||
// update format code
|
||||
editor.setText(text);
|
||||
|
||||
// scroll to last character and focus
|
||||
try {
|
||||
if (text != null && text.length() > 0) {
|
||||
editor.scrollRectToVisible(new Rectangle(0, 0)); // reset scroll
|
||||
editor.setCaretPosition(text.length()); // scroll to end of format
|
||||
editor.setCaretPosition(editor.getText().length()); // scroll to end of format
|
||||
editor.requestFocusInWindow();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warning(e::getMessage);
|
||||
debug.warning(e::toString);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -713,15 +714,4 @@ public class FormatDialog extends JDialog {
|
|||
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