From b4832d32e8a6739cf7b6be5332c459adb5cf59db Mon Sep 17 00:00:00 2001 From: MrTimscampi Date: Fri, 30 Mar 2018 11:58:46 +0200 Subject: [PATCH 1/2] Improved handling of headless mode & OS-specific config This adds changes the check for command-lines arguments to avoir throwing an error when no argument is passed on an headless system. It will instead gracefully show the help page to the user. It also adds a check for the Mac OS-specific properties, to avoid setting them on other systems. The OS-specific properties and the app initialization have been moved to after the Headless check for cleanliness (No need to set GUI properties on an headless app and no need to initialize if we're only going to show an help page). --- src/main/java/com/rarchives/ripme/App.java | 48 ++++++++++++------- .../ripme/ripper/rippers/FacebookRipper.java | 4 ++ 2 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/rarchives/ripme/ripper/rippers/FacebookRipper.java diff --git a/src/main/java/com/rarchives/ripme/App.java b/src/main/java/com/rarchives/ripme/App.java index 0bb5f3f6..9a6b1d09 100644 --- a/src/main/java/com/rarchives/ripme/App.java +++ b/src/main/java/com/rarchives/ripme/App.java @@ -1,5 +1,6 @@ package com.rarchives.ripme; +import java.awt.*; import java.io.File; import java.io.IOException; import java.io.BufferedReader; @@ -18,6 +19,7 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; +import org.apache.commons.lang.SystemUtils; import org.apache.log4j.Logger; import com.rarchives.ripme.ripper.AbstractRipper; @@ -34,35 +36,34 @@ import com.rarchives.ripme.utils.Utils; */ public class App { - public static final Logger logger; + public static final Logger logger = Logger.getLogger(App.class); private static final History HISTORY = new History(); - static { - //initialize logger - Utils.configureLogger(); - logger = Logger.getLogger(App.class); - } - public static void main(String[] args) throws MalformedURLException { CommandLine cl = getArgs(args); + if (args.length > 0 && cl.hasOption('v')){ - logger.error(UpdateUtils.getThisJarVersion()); + logger.info(UpdateUtils.getThisJarVersion()); System.exit(0); } - System.setProperty("apple.laf.useScreenMenuBar", "true"); - System.setProperty("com.apple.mrj.application.apple.menu.about.name", "RipMe"); - logger.info("Initialized ripme v" + UpdateUtils.getThisJarVersion()); - - if (args.length > 0) { - // CLI Mode + if (GraphicsEnvironment.isHeadless()) { handleArguments(args); } else { - // GUI Mode + if (SystemUtils.IS_OS_MAC_OSX) { + System.setProperty("apple.laf.useScreenMenuBar", "true"); + System.setProperty("com.apple.mrj.application.apple.menu.about.name", "RipMe"); + } + + Utils.configureLogger(); + + logger.info("Initialized ripme v" + UpdateUtils.getThisJarVersion()); + MainWindow mw = new MainWindow(); SwingUtilities.invokeLater(mw); } } + /** * Creates an abstract ripper and instructs it to rip. * @param url URL to be ripped @@ -80,20 +81,28 @@ public class App { */ private static void handleArguments(String[] args) { CommandLine cl = getArgs(args); - if (cl.hasOption('h')) { + + if (cl.hasOption('h') || args.length == 0) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("java -jar ripme.jar [OPTIONS]", getOptions()); System.exit(0); } + + Utils.configureLogger(); + logger.info("Initialized ripme v" + UpdateUtils.getThisJarVersion()); + if (cl.hasOption('w')) { Utils.setConfigBoolean("file.overwrite", true); } + if (cl.hasOption('t')) { Utils.setConfigInteger("threads.size", Integer.parseInt(cl.getOptionValue('t'))); } + if (cl.hasOption('4')) { Utils.setConfigBoolean("errors.skip404", true); } + if (cl.hasOption('r')) { // Re-rip all via command-line List history = Utils.getConfigList("download.history"); @@ -115,6 +124,7 @@ public class App { // Exit System.exit(0); } + if (cl.hasOption('R')) { loadHistory(); if (HISTORY.toList().isEmpty()) { @@ -146,20 +156,25 @@ public class App { System.exit(-1); } } + if (cl.hasOption('d')) { Utils.setConfigBoolean("download.save_order", true); } + if (cl.hasOption('D')) { Utils.setConfigBoolean("download.save_order", false); } + if ((cl.hasOption('d'))&&(cl.hasOption('D'))) { logger.error("\nCannot specify '-d' and '-D' simultaneously"); System.exit(-1); } + if (cl.hasOption('l')) { // change the default rips directory Utils.setConfigString("rips.directory", cl.getOptionValue('l')); } + if (cl.hasOption('f')) { String filename = cl.getOptionValue('f'); try { @@ -175,6 +190,7 @@ public class App { logger.error("[!] Failed reading file containing list of URLs. Cannot continue."); } } + if (cl.hasOption('u')) { String url = cl.getOptionValue('u').trim(); ripURL(url, cl.hasOption("n")); diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/FacebookRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/FacebookRipper.java new file mode 100644 index 00000000..acbf7a2e --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/FacebookRipper.java @@ -0,0 +1,4 @@ +package com.rarchives.ripme.ripper.rippers; + +public class FacebookRipper { +} From b5abdb6ae057484b25c9724a1c6835e35d753eeb Mon Sep 17 00:00:00 2001 From: MrTimscampi Date: Fri, 30 Mar 2018 12:15:20 +0200 Subject: [PATCH 2/2] Removed empty file comitted by accident --- .../com/rarchives/ripme/ripper/rippers/FacebookRipper.java | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/main/java/com/rarchives/ripme/ripper/rippers/FacebookRipper.java diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/FacebookRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/FacebookRipper.java deleted file mode 100644 index acbf7a2e..00000000 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/FacebookRipper.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.rarchives.ripme.ripper.rippers; - -public class FacebookRipper { -}