예제 #1
0
 public static void createDirectories() {
   final String[] dirs = {
     Paths.getHomeDirectory(),
     Paths.getLogsDirectory(),
     Paths.getCacheDirectory(),
     Paths.getSettingsDirectory(),
     Paths.getScriptsDirectory(),
     Paths.getScriptsSourcesDirectory(),
     Paths.getScriptsPrecompiledDirectory(),
     Paths.getScriptsNetworkDirectory(),
   };
   for (final String name : dirs) {
     final File dir = new File(name);
     if (!dir.isDirectory()) {
       dir.mkdirs();
     }
   }
   if (Configuration.getCurrentOperatingSystem() == Configuration.OperatingSystem.WINDOWS) {
     try {
       Runtime.getRuntime()
           .exec(
               "attrib +H \""
                   + new File(Paths.getScriptsNetworkDirectory()).getAbsolutePath()
                   + "\"");
     } catch (final IOException ignored) {
     }
   }
 }
예제 #2
0
 public static String getAccountsFile() {
   final String path;
   if (Configuration.getCurrentOperatingSystem() == OperatingSystem.WINDOWS) {
     path = System.getenv("APPDATA") + File.separator + Configuration.NAME + "_Accounts.ini";
   } else {
     path = Paths.getUnixHome() + File.separator + "." + Configuration.NAME_LOWERCASE + "acct";
   }
   return path;
 }
예제 #3
0
 public static String getHomeDirectory() {
   final String env = System.getenv(Configuration.NAME.toUpperCase() + "_HOME");
   if (env == null || env.isEmpty()) {
     return (Configuration.getCurrentOperatingSystem() == OperatingSystem.WINDOWS
             ? FileSystemView.getFileSystemView().getDefaultDirectory().getAbsolutePath()
             : Paths.getUnixHome())
         + File.separator
         + Configuration.NAME;
   } else {
     return env;
   }
 }
예제 #4
0
 private static String getDefaultHttpUserAgent() {
   final boolean x64 = System.getProperty("sun.arch.data.model").equals("64");
   final String os;
   switch (Configuration.getCurrentOperatingSystem()) {
     case MAC:
       os = "Macintosh; Intel Mac OS X 10_6_6";
       break;
     case LINUX:
       os = "X11; Linux " + (x64 ? "x86_64" : "i686");
       break;
     default:
       os = "Windows NT 6.1" + (x64 ? "; WOW64" : "");
       break;
   }
   final StringBuilder buf = new StringBuilder(125);
   buf.append("Mozilla/5.0 (").append(os).append(")");
   buf.append(" AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24");
   return buf.toString();
 }
예제 #5
0
 public static void openURL(final String url) {
   final Configuration.OperatingSystem os = Configuration.getCurrentOperatingSystem();
   try {
     if (os == Configuration.OperatingSystem.MAC) {
       final Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
       final Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
       openURL.invoke(null, url);
     } else if (os == Configuration.OperatingSystem.WINDOWS) {
       Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
     } else {
       final String[] browsers = {
         "firefox",
         "opera",
         "konqueror",
         "epiphany",
         "mozilla",
         "netscape",
         "google-chrome",
         "chromium-browser"
       };
       String browser = null;
       for (int count = 0; count < browsers.length && browser == null; count++) {
         if (Runtime.getRuntime().exec(new String[] {"which", browsers[count]}).waitFor() == 0) {
           browser = browsers[count];
         }
       }
       if (browser == null) {
         throw new Exception("Could not find web browser");
       } else {
         Runtime.getRuntime().exec(new String[] {browser, url});
       }
     }
   } catch (final Exception e) {
     log.warning("Unable to open " + url);
   }
 }