2014-04-19 02:30:29 -04:00
package net.filebot ;
2009-01-04 13:28:28 -05:00
2012-07-14 03:58:53 -04:00
import static java.awt.GraphicsEnvironment.* ;
2018-08-09 02:58:04 -04:00
import static java.util.Arrays.* ;
2016-03-07 07:30:12 -05:00
import static java.util.stream.Collectors.* ;
2016-03-02 10:55:06 -05:00
import static net.filebot.Logging.* ;
2018-06-14 06:11:00 -04:00
import static net.filebot.MediaTypes.* ;
2014-04-19 02:30:29 -04:00
import static net.filebot.Settings.* ;
import static net.filebot.util.FileUtilities.* ;
2018-06-28 15:13:32 -04:00
import static net.filebot.util.FileUtilities.getChildren ;
2016-03-07 07:30:12 -05:00
import static net.filebot.util.XPathUtilities.* ;
2014-07-29 02:45:15 -04:00
import static net.filebot.util.ui.SwingUI.* ;
2009-03-13 20:30:24 -04:00
2012-07-14 03:58:53 -04:00
import java.awt.Dialog.ModalityType ;
import java.io.File ;
import java.io.IOException ;
2016-03-07 07:30:12 -05:00
import java.net.URL ;
2012-07-14 03:58:53 -04:00
import java.security.CodeSource ;
import java.security.Permission ;
import java.security.PermissionCollection ;
import java.security.Permissions ;
import java.security.Policy ;
import java.security.ProtectionDomain ;
2016-03-19 10:42:40 -04:00
import java.util.List ;
2016-03-07 07:30:12 -05:00
import java.util.Map ;
2016-03-09 14:26:00 -05:00
import java.util.logging.Handler ;
2012-07-14 03:58:53 -04:00
import java.util.logging.Level ;
2018-03-17 09:18:03 -04:00
import java.util.prefs.Preferences ;
2012-07-14 03:58:53 -04:00
import javax.swing.JDialog ;
import javax.swing.JFrame ;
import javax.swing.JLabel ;
import javax.swing.JPanel ;
import javax.swing.SwingUtilities ;
2016-03-10 14:43:21 -05:00
import org.kohsuke.args4j.CmdLineException ;
import org.w3c.dom.Document ;
2014-04-19 02:30:29 -04:00
import net.filebot.cli.ArgumentBean ;
import net.filebot.cli.ArgumentProcessor ;
import net.filebot.format.ExpressionFormat ;
2017-03-06 07:52:04 -05:00
import net.filebot.platform.mac.MacAppUtilities ;
2018-02-25 22:35:42 -05:00
import net.filebot.platform.windows.WinAppUtilities ;
2015-05-09 04:07:38 -04:00
import net.filebot.ui.FileBotMenuBar ;
2015-05-10 14:06:04 -04:00
import net.filebot.ui.GettingStartedStage ;
2014-04-19 02:30:29 -04:00
import net.filebot.ui.MainFrame ;
2016-03-09 11:18:20 -05:00
import net.filebot.ui.NotificationHandler ;
2014-04-19 02:30:29 -04:00
import net.filebot.ui.PanelBuilder ;
import net.filebot.ui.SinglePanelFrame ;
2016-04-23 13:05:33 -04:00
import net.filebot.ui.SupportDialog ;
2014-08-27 08:08:00 -04:00
import net.filebot.ui.transfer.FileTransferable ;
2014-04-19 02:30:29 -04:00
import net.filebot.util.PreferencesMap.PreferencesEntry ;
2016-04-16 17:41:13 -04:00
import net.filebot.util.ui.SwingEventBus ;
2014-06-23 11:09:43 -04:00
import net.miginfocom.swing.MigLayout ;
2009-03-14 06:20:59 -04:00
2007-12-23 14:28:04 -05:00
public class Main {
2013-10-17 03:11:03 -04:00
2016-10-18 13:02:51 -04:00
public static void main ( String [ ] argv ) {
2012-07-14 03:58:53 -04:00
try {
// parse arguments
2018-08-09 02:58:04 -04:00
ArgumentBean args = isMacSandbox ( ) ? new ArgumentBean ( ) : new ArgumentBean ( argv ) ; // MAS does not support or allow command-line applications and may run executables with strange arguments for no apparent reason (e.g. filebot.launcher -psn_0_774333)
2013-10-17 03:11:03 -04:00
2016-10-18 14:30:07 -04:00
// just print help message or version string and then exit
if ( args . printHelp ( ) ) {
log . info ( String . format ( " %s%n%n%s " , getApplicationIdentifier ( ) , args . usage ( ) ) ) ;
System . exit ( 0 ) ;
}
2013-10-17 03:11:03 -04:00
2016-10-18 14:30:07 -04:00
if ( args . printVersion ( ) ) {
log . info ( String . join ( " / " , getApplicationIdentifier ( ) , getJavaRuntimeIdentifier ( ) , getSystemIdentifier ( ) ) ) ;
2012-07-14 03:58:53 -04:00
System . exit ( 0 ) ;
}
2013-10-17 03:11:03 -04:00
2013-11-07 02:43:58 -05:00
if ( args . clearCache ( ) | | args . clearUserData ( ) ) {
2016-06-12 06:16:18 -04:00
// clear persistent user preferences
2013-11-07 02:43:58 -05:00
if ( args . clearUserData ( ) ) {
2016-10-18 13:02:51 -04:00
log . info ( " Reset preferences " ) ;
2013-11-07 02:43:58 -05:00
Settings . forPackage ( Main . class ) . clear ( ) ;
2018-03-17 09:40:31 -04:00
// restore preferences on start if empty (TODO: remove after a few releases)
ApplicationFolder . AppData . resolve ( " preferences.backup.xml " ) . delete ( ) ;
2013-11-07 02:43:58 -05:00
}
2016-06-12 06:16:18 -04:00
// clear caches
2013-11-07 02:43:58 -05:00
if ( args . clearCache ( ) ) {
2017-03-24 09:57:00 -04:00
// clear cache must be called manually
if ( System . console ( ) = = null ) {
2018-06-29 06:23:31 -04:00
log . severe ( " `filebot -clear-cache` must be called from an interactive console. " ) ;
2017-03-24 09:57:00 -04:00
System . exit ( 1 ) ;
}
2016-10-18 13:02:51 -04:00
log . info ( " Clear cache " ) ;
2016-11-25 12:37:09 -05:00
for ( File folder : getChildren ( ApplicationFolder . Cache . get ( ) , FOLDERS ) ) {
2016-10-18 13:02:51 -04:00
log . fine ( " * Delete " + folder ) ;
2016-05-15 15:09:30 -04:00
delete ( folder ) ;
2013-11-07 02:43:58 -05:00
}
}
// just clear cache and/or settings and then exit
System . exit ( 0 ) ;
}
2016-03-11 03:16:57 -05:00
// make sure we can access application arguments at any time
2016-10-18 13:02:51 -04:00
setApplicationArguments ( args ) ;
2016-03-11 03:16:57 -05:00
2016-03-08 11:21:10 -05:00
// update system properties
initializeSystemProperties ( args ) ;
2016-03-10 09:05:56 -05:00
initializeLogging ( args ) ;
2013-10-17 03:11:03 -04:00
2012-10-27 22:52:49 -04:00
// initialize this stuff before anything else
2016-03-06 13:11:30 -05:00
CacheManager . getInstance ( ) ;
2012-10-27 22:52:49 -04:00
initializeSecurityManager ( ) ;
2013-10-17 03:11:03 -04:00
2014-11-10 03:18:32 -05:00
// initialize history spooler
2016-03-05 16:06:26 -05:00
HistorySpooler . getInstance ( ) . setPersistentHistoryEnabled ( useRenameHistory ( ) ) ;
2013-10-17 03:11:03 -04:00
2012-07-14 03:58:53 -04:00
// CLI mode => run command-line interface and then exit
if ( args . runCLI ( ) ) {
2018-06-10 11:45:24 -04:00
// just import and print license when running with --license option
2018-06-11 16:48:52 -04:00
if ( LICENSE . isFile ( ) ) {
args . getLicenseFile ( ) . ifPresent ( f - > {
configureLicense ( f ) ;
System . exit ( 0 ) ;
} ) ;
2018-07-23 10:36:43 -04:00
// manually set AUMID for legacy processes
if ( isWindowsApp ( ) ) {
WinAppUtilities . initializeApplication ( getApplicationName ( ) ) ;
}
2018-07-23 09:24:44 -04:00
}
2018-06-10 11:45:24 -04:00
int status = new ArgumentProcessor ( ) . run ( args ) ;
System . exit ( status ) ;
}
// just print help page if we can't run any command and also can't start the GUI
if ( isHeadless ( ) ) {
log . info ( String . format ( " %s / %s (headless)%n%n%s " , getApplicationIdentifier ( ) , getJavaRuntimeIdentifier ( ) , args . usage ( ) ) ) ;
System . exit ( 1 ) ;
2016-10-18 14:30:07 -04:00
}
2012-07-14 03:58:53 -04:00
// GUI mode => start user interface
2016-10-18 13:02:51 -04:00
SwingUtilities . invokeLater ( ( ) - > {
2018-03-17 09:18:03 -04:00
// restore preferences on start if empty (TODO: remove after a few releases)
try {
if ( Preferences . userNodeForPackage ( Main . class ) . keys ( ) . length = = 0 ) {
File f = ApplicationFolder . AppData . resolve ( " preferences.backup.xml " ) ;
if ( f . exists ( ) ) {
2018-03-17 09:42:34 -04:00
log . fine ( " Restore user preferences: " + f ) ;
2018-03-17 09:18:03 -04:00
Settings . restore ( f ) ;
} else {
2018-03-17 09:42:34 -04:00
log . fine ( " No user preferences found: " + f ) ;
2018-03-17 09:18:03 -04:00
}
}
} catch ( Exception e ) {
debug . log ( Level . WARNING , " Failed to restore preferences " , e ) ;
}
2016-03-20 03:52:13 -04:00
startUserInterface ( args ) ;
2013-10-17 03:11:03 -04:00
2016-10-18 13:02:51 -04:00
// run background tasks
2016-10-30 13:38:12 -04:00
newSwingWorker ( ( ) - > onStart ( args ) ) . execute ( ) ;
2016-10-18 13:02:51 -04:00
} ) ;
2015-10-11 12:56:01 -04:00
} catch ( CmdLineException e ) {
// illegal arguments => print CLI error message
2016-10-18 13:02:51 -04:00
log . severe ( e : : getMessage ) ;
2016-06-12 06:23:36 -04:00
System . exit ( 1 ) ;
2015-10-11 12:56:01 -04:00
} catch ( Throwable e ) {
// unexpected error => dump stack
2017-10-04 07:05:14 -04:00
debug . log ( Level . SEVERE , " Error during startup " , e ) ;
2016-06-12 06:23:36 -04:00
System . exit ( 1 ) ;
2012-07-14 03:58:53 -04:00
}
}
2013-10-17 03:11:03 -04:00
2018-05-21 05:33:58 -04:00
private static void onStart ( ArgumentBean args ) throws Exception {
2016-10-18 13:02:51 -04:00
// publish file arguments
List < File > files = args . getFiles ( false ) ;
if ( files . size ( ) > 0 ) {
SwingEventBus . getInstance ( ) . post ( new FileTransferable ( files ) ) ;
}
2018-06-11 05:32:23 -04:00
if ( LICENSE . isFile ( ) ) {
// import license if launched with license file
2018-06-11 16:48:52 -04:00
args . getLicenseFile ( ) . ifPresent ( f - > configureLicense ( f ) ) ;
2018-06-10 05:16:51 -04:00
2018-06-11 05:32:23 -04:00
// make sure license is validated and cached
2018-06-14 06:11:00 -04:00
SwingEventBus . getInstance ( ) . post ( LICENSE ) ;
2018-06-10 15:13:53 -04:00
}
2016-10-16 05:34:10 -04:00
// JavaFX is used for ProgressMonitor and GettingStartedDialog
try {
initJavaFX ( ) ;
} catch ( Throwable e ) {
2018-06-10 05:16:51 -04:00
log . log ( Level . SEVERE , " Failed to initialize JavaFX " , e ) ;
2016-10-16 05:34:10 -04:00
}
2016-10-16 03:46:42 -04:00
// check if application help should be shown
if ( ! " skip " . equals ( System . getProperty ( " application.help " ) ) ) {
try {
checkGettingStarted ( ) ;
} catch ( Throwable e ) {
debug . log ( Level . WARNING , " Failed to show Getting Started help " , e ) ;
}
}
// check for application updates
if ( ! " skip " . equals ( System . getProperty ( " application.update " ) ) ) {
try {
checkUpdate ( ) ;
} catch ( Throwable e ) {
debug . log ( Level . WARNING , " Failed to check for updates " , e ) ;
}
}
}
2012-07-14 03:58:53 -04:00
private static void startUserInterface ( ArgumentBean args ) {
2018-07-01 12:36:32 -04:00
// use native LaF an all platforms
setSystemLookAndFeel ( ) ;
2016-03-09 11:02:36 -05:00
2018-08-09 02:58:04 -04:00
// start standard frame or single panel frame
2017-04-09 03:39:16 -04:00
PanelBuilder [ ] panels = args . getPanelBuilders ( ) ;
2016-11-25 07:47:08 -05:00
2018-08-09 02:58:04 -04:00
// MAS does not allow subtitle applications
if ( isMacSandbox ( ) ) {
panels = stream ( panels ) . filter ( p - > ! p . getName ( ) . equals ( " Subtitles " ) ) . toArray ( PanelBuilder [ ] : : new ) ;
}
JFrame frame = panels . length > 1 ? new MainFrame ( panels ) : new SinglePanelFrame ( panels [ 0 ] ) ;
2013-04-09 14:20:52 -04:00
try {
2016-11-25 07:47:08 -05:00
restoreWindowBounds ( frame , Settings . forPackage ( MainFrame . class ) ) ; // restore previous size and location
2013-04-09 14:20:52 -04:00
} catch ( Exception e ) {
2016-11-25 07:47:08 -05:00
frame . setLocation ( 120 , 80 ) ; // make sure the main window is not displayed out of screen bounds
2013-04-09 14:20:52 -04:00
}
2013-10-17 03:11:03 -04:00
2016-11-23 15:51:40 -05:00
frame . addWindowListener ( windowClosed ( evt - > {
evt . getWindow ( ) . setVisible ( false ) ;
2013-10-17 03:11:03 -04:00
2018-07-23 09:24:44 -04:00
// make sure any long running operations are done now and not later on the
// shutdown hook thread
2016-11-23 15:51:40 -05:00
HistorySpooler . getInstance ( ) . commit ( ) ;
2018-06-14 11:26:39 -04:00
if ( isAppStore ( ) ) {
SupportDialog . AppStoreReview . maybeShow ( ) ;
}
2014-10-09 13:30:43 -04:00
2018-03-17 09:40:31 -04:00
// restore preferences on start if empty (TODO: remove after a few releases)
2018-03-17 08:43:06 -04:00
Settings . store ( ApplicationFolder . AppData . resolve ( " preferences.backup.xml " ) ) ;
2016-11-23 15:51:40 -05:00
System . exit ( 0 ) ;
} ) ) ;
2013-10-17 03:11:03 -04:00
2014-10-18 11:52:35 -04:00
// configure main window
2014-10-09 09:37:15 -04:00
if ( isMacApp ( ) ) {
2018-07-01 12:36:32 -04:00
// macOS-specific configuration
2018-06-11 16:48:52 -04:00
MacAppUtilities . initializeApplication ( FileBotMenuBar . createHelp ( ) , files - > {
2018-06-14 06:11:00 -04:00
if ( LICENSE . isFile ( ) & & files . size ( ) = = 1 & & containsOnly ( files , LICENSE_FILES ) ) {
2018-06-11 16:48:52 -04:00
configureLicense ( files . get ( 0 ) ) ;
2018-06-14 06:11:00 -04:00
SwingEventBus . getInstance ( ) . post ( LICENSE ) ;
2018-06-11 16:48:52 -04:00
} else {
SwingEventBus . getInstance ( ) . post ( new FileTransferable ( files ) ) ;
}
} ) ;
2016-07-13 10:02:33 -04:00
} else if ( isWindowsApp ( ) ) {
2018-07-01 12:36:32 -04:00
// Windows-specific configuration
2018-07-23 10:14:07 -04:00
WinAppUtilities . initializeApplication ( isUWP ( ) ? null : getApplicationName ( ) ) ;
2018-03-05 06:44:24 -05:00
frame . setIconImages ( ResourceManager . getApplicationIconImages ( ) ) ;
2014-10-18 11:52:35 -04:00
} else {
2018-07-01 12:36:32 -04:00
// generic Linux / FreeBSD / Solaris configuration
2018-03-05 06:44:24 -05:00
frame . setIconImages ( ResourceManager . getApplicationIconImages ( ) ) ;
2014-07-30 21:20:27 -04:00
}
2012-07-14 03:58:53 -04:00
// start application
2015-05-09 04:07:38 -04:00
frame . setDefaultCloseOperation ( JFrame . DISPOSE_ON_CLOSE ) ;
2012-07-14 03:58:53 -04:00
frame . setVisible ( true ) ;
}
2013-10-17 03:11:03 -04:00
2012-07-14 03:58:53 -04:00
/ * *
* Show update notifications if updates are available
* /
private static void checkUpdate ( ) throws Exception {
2016-03-07 07:30:12 -05:00
Cache cache = Cache . getCache ( getApplicationName ( ) , CacheType . Persistent ) ;
2016-03-07 11:01:10 -05:00
Document dom = cache . xml ( " update.url " , s - > new URL ( getApplicationProperty ( s ) ) ) . expire ( Cache . ONE_WEEK ) . retry ( 0 ) . get ( ) ;
2013-10-17 03:11:03 -04:00
2016-03-07 07:30:12 -05:00
// parse update xml
2016-11-23 15:51:40 -05:00
Map < String , String > update = streamElements ( dom . getFirstChild ( ) ) . collect ( toMap ( n - > n . getNodeName ( ) , n - > n . getTextContent ( ) . trim ( ) ) ) ;
2013-10-17 03:11:03 -04:00
2012-07-14 03:58:53 -04:00
// check if update is required
2016-03-07 07:30:12 -05:00
int latestRev = Integer . parseInt ( update . get ( " revision " ) ) ;
2013-10-17 03:11:03 -04:00
int currentRev = getApplicationRevisionNumber ( ) ;
if ( latestRev > currentRev & & currentRev > 0 ) {
2016-03-07 07:30:12 -05:00
SwingUtilities . invokeLater ( ( ) - > {
2016-11-23 15:51:40 -05:00
JDialog dialog = new JDialog ( JFrame . getFrames ( ) [ 0 ] , update . get ( " title " ) , ModalityType . APPLICATION_MODAL ) ;
JPanel pane = new JPanel ( new MigLayout ( " fill, nogrid, insets dialog " ) ) ;
2016-03-07 07:30:12 -05:00
dialog . setContentPane ( pane ) ;
2013-10-17 03:11:03 -04:00
2016-03-07 07:30:12 -05:00
pane . add ( new JLabel ( ResourceManager . getIcon ( " window.icon.medium " ) ) , " aligny top " ) ;
2016-11-19 13:52:01 -05:00
pane . add ( new JLabel ( update . get ( " message " ) ) , " aligny top, gap 10, wrap paragraph:push " ) ;
2013-10-17 03:11:03 -04:00
2016-03-07 07:30:12 -05:00
pane . add ( newButton ( " Download " , ResourceManager . getIcon ( " dialog.continue " ) , evt - > {
openURI ( update . get ( " download " ) ) ;
dialog . setVisible ( false ) ;
} ) , " tag ok " ) ;
pane . add ( newButton ( " Details " , ResourceManager . getIcon ( " action.report " ) , evt - > {
openURI ( update . get ( " discussion " ) ) ;
} ) , " tag help2 " ) ;
pane . add ( newButton ( " Ignore " , ResourceManager . getIcon ( " dialog.cancel " ) , evt - > {
dialog . setVisible ( false ) ;
} ) , " tag cancel " ) ;
dialog . pack ( ) ;
dialog . setLocation ( getOffsetLocation ( dialog . getOwner ( ) ) ) ;
dialog . setVisible ( true ) ;
2012-07-14 03:58:53 -04:00
} ) ;
}
}
2013-10-17 03:11:03 -04:00
2015-05-10 14:06:04 -04:00
/ * *
* Show Getting Started to new users
* /
private static void checkGettingStarted ( ) throws Exception {
PreferencesEntry < String > started = Settings . forPackage ( Main . class ) . entry ( " getting.started " ) . defaultValue ( " 0 " ) ;
if ( " 0 " . equals ( started . getValue ( ) ) ) {
2015-09-12 11:49:47 -04:00
started . setValue ( " 1 " ) ;
started . flush ( ) ;
2016-03-07 07:30:12 -05:00
// open Getting Started
2018-06-11 06:25:09 -04:00
SwingUtilities . invokeLater ( ( ) - > GettingStartedStage . start ( " show " . equals ( System . getProperty ( " application.help " ) ) ) ) ;
2015-05-10 14:06:04 -04:00
}
}
2016-11-23 15:51:40 -05:00
private static void restoreWindowBounds ( JFrame window , Settings settings ) {
2012-07-14 03:58:53 -04:00
// store bounds on close
2016-11-23 15:51:40 -05:00
window . addWindowListener ( windowClosed ( evt - > {
// don't save window bounds if window is maximized
if ( ! isMaximized ( window ) ) {
settings . put ( " window.x " , String . valueOf ( window . getX ( ) ) ) ;
settings . put ( " window.y " , String . valueOf ( window . getY ( ) ) ) ;
settings . put ( " window.width " , String . valueOf ( window . getWidth ( ) ) ) ;
settings . put ( " window.height " , String . valueOf ( window . getHeight ( ) ) ) ;
2012-07-14 03:58:53 -04:00
}
2016-11-23 15:51:40 -05:00
} ) ) ;
2013-10-17 03:11:03 -04:00
2012-07-14 03:58:53 -04:00
// restore bounds
int x = Integer . parseInt ( settings . get ( " window.x " ) ) ;
int y = Integer . parseInt ( settings . get ( " window.y " ) ) ;
int width = Integer . parseInt ( settings . get ( " window.width " ) ) ;
int height = Integer . parseInt ( settings . get ( " window.height " ) ) ;
window . setBounds ( x , y , width , height ) ;
}
2013-10-17 03:11:03 -04:00
2012-07-14 03:58:53 -04:00
/ * *
2018-08-09 02:58:04 -04:00
* Initialize default SecurityManager and grant all permissions via security policy . Initialization is required in order to run { @link ExpressionFormat } in a secure sandbox .
2012-07-14 03:58:53 -04:00
* /
private static void initializeSecurityManager ( ) {
try {
// initialize security policy used by the default security manager
2018-07-23 09:24:44 -04:00
// because default the security policy is very restrictive (e.g. no
// FilePermission)
2012-07-14 03:58:53 -04:00
Policy . setPolicy ( new Policy ( ) {
2013-10-17 03:11:03 -04:00
2012-07-14 03:58:53 -04:00
@Override
public boolean implies ( ProtectionDomain domain , Permission permission ) {
// all permissions
return true ;
}
2013-10-17 03:11:03 -04:00
2012-07-14 03:58:53 -04:00
@Override
public PermissionCollection getPermissions ( CodeSource codesource ) {
2013-10-17 03:11:03 -04:00
// VisualVM can't connect if this method does return
2012-07-14 03:58:53 -04:00
// a checked immutable PermissionCollection
return new Permissions ( ) ;
}
} ) ;
2013-10-17 03:11:03 -04:00
2012-07-14 03:58:53 -04:00
// set default security manager
System . setSecurityManager ( new SecurityManager ( ) ) ;
} catch ( Exception e ) {
// security manager was probably set via system property
2016-03-09 15:36:28 -05:00
debug . log ( Level . WARNING , e . getMessage ( ) , e ) ;
2012-07-14 03:58:53 -04:00
}
2009-05-02 19:34:04 -04:00
}
2013-10-17 03:11:03 -04:00
2016-03-08 11:21:10 -05:00
public static void initializeSystemProperties ( ArgumentBean args ) {
2018-06-29 06:23:31 -04:00
System . setProperty ( " http.agent " , String . format ( " %s/%s " , getApplicationName ( ) , getApplicationVersion ( ) ) ) ;
2016-03-08 11:21:10 -05:00
System . setProperty ( " sun.net.client.defaultConnectTimeout " , " 10000 " ) ;
System . setProperty ( " sun.net.client.defaultReadTimeout " , " 60000 " ) ;
System . setProperty ( " swing.crossplatformlaf " , " javax.swing.plaf.nimbus.NimbusLookAndFeel " ) ;
2016-11-25 10:59:26 -05:00
System . setProperty ( " grape.root " , ApplicationFolder . AppData . resolve ( " grape " ) . getPath ( ) ) ;
2016-03-08 11:21:10 -05:00
System . setProperty ( " org.apache.commons.logging.Log " , " org.apache.commons.logging.impl.NoOpLog " ) ;
2016-05-07 05:01:39 -04:00
if ( args . unixfs ) {
System . setProperty ( " unixfs " , " true " ) ;
}
2016-11-25 07:47:08 -05:00
if ( args . disableExtendedAttributes ) {
2016-05-07 05:01:39 -04:00
System . setProperty ( " useExtendedFileAttributes " , " false " ) ;
System . setProperty ( " useCreationDate " , " false " ) ;
}
2016-03-08 11:21:10 -05:00
}
2016-03-10 09:05:56 -05:00
public static void initializeLogging ( ArgumentBean args ) throws IOException {
2016-11-25 12:23:56 -05:00
// make sure that these folders exist
2016-11-25 12:37:09 -05:00
ApplicationFolder . TemporaryFiles . get ( ) . mkdirs ( ) ;
ApplicationFolder . AppData . get ( ) . mkdirs ( ) ;
2016-11-25 12:23:56 -05:00
2016-03-15 10:57:21 -04:00
if ( args . runCLI ( ) ) {
// CLI logging settings
log . setLevel ( args . getLogLevel ( ) ) ;
} else {
// GUI logging settings
log . setLevel ( Level . INFO ) ;
log . addHandler ( new NotificationHandler ( getApplicationName ( ) ) ) ;
// log errors to file
try {
2017-01-27 12:22:46 -05:00
Handler errorLogHandler = createSimpleFileHandler ( ApplicationFolder . AppData . resolve ( " error.log " ) , Level . WARNING ) ;
log . addHandler ( errorLogHandler ) ;
debug . addHandler ( errorLogHandler ) ;
2016-03-15 10:57:21 -04:00
} catch ( Exception e ) {
2016-11-25 12:23:56 -05:00
log . log ( Level . WARNING , " Failed to initialize error log " , e ) ;
2016-03-15 10:57:21 -04:00
}
}
2017-01-28 06:07:12 -05:00
// tee stdout and stderr to log file if --log-file is set
2016-03-10 09:05:56 -05:00
if ( args . logFile ! = null ) {
2017-01-28 06:07:12 -05:00
Handler logFileHandler = createLogFileHandler ( args . getLogFile ( ) , args . logLock , Level . ALL ) ;
2017-01-27 12:22:46 -05:00
log . addHandler ( logFileHandler ) ;
debug . addHandler ( logFileHandler ) ;
2016-03-10 09:05:56 -05:00
}
}
2007-12-23 14:28:04 -05:00
}