Esempio n. 1
0
 @Override
 public void setTitle(final String title) {
   String t = Configuration.NAME + " v" + Configuration.getVersionFormatted();
   final int v = Configuration.getVersion(), l = UpdateChecker.getLatestVersion();
   if (v > l) {
     t += " beta";
   }
   if (title != null) {
     t = title + " - " + t;
   }
   super.setTitle(t);
 }
Esempio n. 2
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) {
     }
   }
 }
Esempio n. 3
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;
 }
Esempio n. 4
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;
   }
 }
Esempio n. 5
0
 private void init() {
   setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
   addWindowListener(
       new WindowAdapter() {
         @Override
         public void windowClosing(final WindowEvent e) {
           cleanExit();
         }
       });
   addWindowStateListener(
       new WindowStateListener() {
         public void windowStateChanged(final WindowEvent arg0) {
           switch (arg0.getID()) {
             case WindowEvent.WINDOW_ICONIFIED:
               lessCpu(true);
               break;
             case WindowEvent.WINDOW_DEICONIFIED:
               lessCpu(false);
               break;
           }
         }
       });
   setIconImage(Configuration.getImage(Configuration.Paths.Resources.ICON));
   JPopupMenu.setDefaultLightWeightPopupEnabled(false);
   WindowUtil.setFrame(this);
   panel = new BotPanel();
   menuBar = new BotMenuBar(this);
   toolBar = new BotToolBar(this, menuBar);
   panel.setFocusTraversalKeys(0, new HashSet<AWTKeyStroke>());
   new BotKeyboardShortcuts(KeyboardFocusManager.getCurrentKeyboardFocusManager(), this, this);
   menuBar.setBot(null);
   setJMenuBar(menuBar);
   textScroll =
       new JScrollPane(
           TextAreaLogHandler.TEXT_AREA,
           ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
           ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
   textScroll.setBorder(null);
   textScroll.setPreferredSize(new Dimension(PANEL_WIDTH, 120));
   textScroll.setVisible(true);
   JScrollPane scrollableBotPanel = new JScrollPane(panel);
   add(toolBar, BorderLayout.NORTH);
   add(scrollableBotPanel, BorderLayout.CENTER);
   add(textScroll, BorderLayout.SOUTH);
 }
Esempio n. 6
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();
 }
Esempio n. 7
0
  public void setTray() {
    boolean showTip = false;
    if (tray == null) {
      showTip = true;
      final Image image = Configuration.getImage(Configuration.Paths.Resources.ICON);
      tray = new TrayIcon(image, Configuration.NAME, null);
      tray.setImageAutoSize(true);
      tray.addMouseListener(
          new MouseListener() {
            public void mouseClicked(MouseEvent arg0) {}

            public void mouseEntered(MouseEvent arg0) {}

            public void mouseExited(MouseEvent arg0) {}

            public void mouseReleased(MouseEvent arg0) {}

            public void mousePressed(MouseEvent arg0) {
              SystemTray.getSystemTray().remove(tray);
              setVisible(true);
              lessCpu(false);
            }
          });
    }
    try {
      SystemTray.getSystemTray().add(tray);
      if (showTip) {
        tray.displayMessage(
            Configuration.NAME + " Hidden",
            "Bots are still running in the background.\nClick this icon to restore the window.",
            MessageType.INFO);
      }
    } catch (Exception ignored) {
      log.warning("Unable to hide window");
    }
    setVisible(false);
    lessCpu(true);
  }
Esempio n. 8
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);
   }
 }