private void load(String pkg) {
    try {
      URL infourl =
          Application.getRessourceURL(JD_CONTROLLING_RECONNECT_PLUGINS + pkg + "/info.json");
      if (infourl == null) {
        LogController.CL().finer("Could not load Reconnect Plugin " + pkg);
        return;
      }

      ReconnectPluginInfo plgInfo =
          JSonStorage.restoreFromString(
              IO.readURLToString(infourl), new TypeRef<ReconnectPluginInfo>() {}, null);
      if (plgInfo == null) {
        LogController.CL().finer("Could not load Reconnect Plugin (no info.json)" + pkg);
        return;
      }
      Class<?> clazz =
          getClass()
              .getClassLoader()
              .loadClass(
                  JD_CONTROLLING_RECONNECT_PLUGINS.replace("/", ".")
                      + pkg
                      + "."
                      + plgInfo.getClassName());
      for (RouterPlugin plg : plugins) {
        if (plg.getClass() == clazz) {
          LogController.CL().finer("Dupe found: " + pkg);
          return;
        }
      }
      plugins.add((RouterPlugin) clazz.newInstance());
    } catch (Throwable e) {
      LogController.CL().log(e);
    }
  }
 ExtractionController(
     ExtractionExtension extractionExtension, Archive archiv, IExtraction extractor) {
   this.archive = archiv;
   logger = LogController.CL(false);
   logger.setAllowTimeoutFlush(false);
   logger.info("Extraction of" + archive);
   this.extractor = extractor;
   extractionProgress = new ExtractionProgress(this, 0, 0, null);
   extractor.setArchiv(archiv);
   extractor.setExtractionController(this);
   extension = extractionExtension;
   extractor.setLogger(logger);
   passwordList = new CopyOnWriteArrayList<String>();
   archive.onControllerAssigned(this);
 }
 private void save(List<LazyHostPlugin> save, final AtomicLong lastFolderModification) {
   if (save != null) {
     LOCK.writeLock();
     final File cache = Application.getTempResource(getCache());
     try {
       LazyHostPluginCache.write(save, cache, lastFolderModification);
     } catch (final Throwable e) {
       final LogSource log = LogController.CL(false);
       log.log(e);
       log.close();
       cache.delete();
     } finally {
       LOCK.writeUnlock();
       FileCreationManager.getInstance()
           .delete(Application.getTempResource(TMP_INVALIDPLUGINS), null);
     }
   }
 }
Beispiel #4
0
  public static Icon getIcon(final String name, final ExtensionsFilterInterface extension) {
    Icon newIcon = null;
    final String ext = Files.getExtension(name);
    if (CrossSystem.isWindows() && ext != null) {
      try {
        newIcon = CrossSystem.getMime().getFileIcon(ext, 16, 16);

      } catch (Throwable e) {
        LogController.CL().log(e);
      }
    }
    if (newIcon == null) {
      String iconID = null;
      if (extension != null && extension.getIconID() != null) {
        iconID = extension.getIconID();
      }
      if (StringUtils.isEmpty(iconID)) {
        iconID = "file";
      }
      newIcon = NewTheme.I().getIcon(iconID, 16);
    }
    return newIcon;
  }
Beispiel #5
0
  private void addCircles(PixelObject pixelObject, java.util.List<PixelObject> obnew) {
    if (pixelObject.getArea() < minArea) {
      return;
    }
    int[] bounds = getBounds(pixelObject);
    int r = 0;
    if (bounds != null) {
      r = (bounds[1] - pixelObject.getLocation()[1]) / 2;

      // System.out.println(r + ":" + bounds[0] + ":" + bounds[1]);
      // System.out.println(pixelObject.getHeight() / 2);

      PixelObject object = getCircle(bounds[0], bounds[1] - r, r);

      if (object != null) {
        int ratio = object.getHeight() * 100 / object.getWidth();
        // BasicWindow.showImage(object.toColoredLetter().getImage(),""+ratio);

        if (ratio > 90 && ratio < 110) {
          obnew.add(object);
          int oldArea = pixelObject.getArea();
          // BasicWindow.showImage(object.toColoredLetter().getImage(),""+pixelObject.getArea());

          pixelObject.del(object);

          if (oldArea != pixelObject.getArea()) {
            addCircles(pixelObject, obnew);
          }
        }
      }
    } else {
      LogController.CL().warning("can not detect circle bounds");
      // BasicWindow.showImage(pixelObject.toColoredLetter().getImage(),""+pixelObject.getArea());

    }
  }
  /** Scans for reconnection plugins */
  private void scan() {
    try {
      final File[] files =
          JDUtilities.getResourceFile("reconnect")
              .listFiles(new JDFileFilter(null, ".reconnect", false));
      this.plugins = new ArrayList<RouterPlugin>();
      this.plugins.add(DummyRouterPlugin.getInstance());
      plugins.add(new ExternBatchReconnectPlugin());
      plugins.add(new ExternReconnectPlugin());
      plugins.add(new UPNPRouterPlugin());
      plugins.add(new LiveHeaderReconnect());
      plugins.add(new SpeedPortHybrid());
      plugins.add(new EasyBox804());
      final java.util.List<URL> urls = new ArrayList<URL>();
      if (files != null) {
        final int length = files.length;

        for (int i = 0; i < length; i++) {
          try {
            urls.add(files[i].toURI().toURL());
            Application.addUrlToClassPath(files[i].toURI().toURL(), getClass().getClassLoader());
          } catch (final Throwable e) {
            LogController.CL().log(e);
          }
        }
      }

      Enumeration<URL> found =
          getClass()
              .getClassLoader()
              .getResources(ReconnectPluginController.JD_CONTROLLING_RECONNECT_PLUGINS);
      Pattern pattern =
          Pattern.compile(Pattern.quote(JD_CONTROLLING_RECONNECT_PLUGINS) + "(\\w+)/");
      while (found.hasMoreElements()) {
        URL url = found.nextElement();

        if (url.getProtocol().equalsIgnoreCase("jar")) {
          // // jarred addon (JAR)
          String path = url.getPath();
          File jarFile = new File(new URL(path.substring(0, path.lastIndexOf('!'))).toURI());
          JarInputStream jis = null;
          try {
            jis = new JarInputStream(new FileInputStream(jarFile));
            JarEntry e;

            while ((e = jis.getNextJarEntry()) != null) {

              // try {
              Matcher matcher = pattern.matcher(e.getName());
              while (matcher.find()) {
                try {
                  String pkg = matcher.group(1);
                  load(pkg);

                  System.out.println(pkg);
                } catch (Exception e1) {
                  e1.printStackTrace();
                }
              }
            }
          } finally {
            try {
              jis.close();
            } catch (final Throwable e) {
            }
          }
        } else {

          for (File dir :
              new File(url.toURI())
                  .listFiles(
                      new FileFilter() {

                        public boolean accept(File pathname) {
                          return pathname.isDirectory();
                        }
                      })) {
            File file = new File(dir, "info.json");
            if (file.exists()) {
              load(dir.getName());
            }
          }
          //
        }
      }
    } catch (Throwable e) {
      LogController.CL().log(e);
    }
  }
  public synchronized Map<String, LazyHostPlugin> init() {
    final LogSource logger = LogController.CL(false);
    logger.info("HostPluginController: init");
    logger.setAllowTimeoutFlush(false);
    logger.setAutoFlushOnThrowable(true);
    LogController.setRebirthLogger(logger);
    final long completeTimeStamp = System.currentTimeMillis();
    try {
      /* try to load from cache */
      long timeStamp = System.currentTimeMillis();
      if (lastKnownPlugins == null || lastModification.get() <= 0) {
        try {
          lastKnownPlugins = loadFromCache(lastModification);
        } catch (Throwable e) {
          if (lastModification != null) {
            lastModification.set(-1l);
          }
          logger.log(e);
          logger.severe("@HostPluginController: cache failed!");
        } finally {
          if (lastKnownPlugins != null && lastKnownPlugins.size() > 0) {
            logger.info(
                "@HostPluginController: loadFromCache took "
                    + (System.currentTimeMillis() - timeStamp)
                    + "ms for "
                    + lastKnownPlugins.size());
          }
        }
      }
      List<LazyHostPlugin> plugins = null;
      timeStamp = System.currentTimeMillis();
      try {
        /* do a fresh scan */
        plugins = update(logger, lastKnownPlugins, lastModification);
      } catch (Throwable e) {
        if (lastModification != null) {
          lastModification.set(-1l);
        }
        logger.log(e);
        logger.severe("@HostPluginController: update failed!");
      } finally {
        if (plugins != null && plugins.size() > 0) {
          logger.info(
              "@HostPluginController: update took "
                  + (System.currentTimeMillis() - timeStamp)
                  + "ms for "
                  + plugins.size());
        }
      }
      if (plugins == null || plugins.size() == 0) {
        if (plugins == null) {
          plugins = new ArrayList<LazyHostPlugin>();
        }
        logger.severe("@HostPluginController: WTF, no plugins!");
      }
      lastKnownPlugins = new ArrayList<LazyHostPlugin>(plugins);
      timeStamp = System.currentTimeMillis();
      try {
        if (false) {
          Collections.sort(
              plugins,
              new Comparator<LazyHostPlugin>() {
                public final boolean smallestCharacter(char a, char b) {
                  return Character.toLowerCase(a) < Character.toLowerCase(b);
                }

                public int compare(LazyHostPlugin o1, LazyHostPlugin o2) {
                  char a = o1.getDisplayName().charAt(0);
                  char b = o2.getDisplayName().charAt(0);
                  if (a == b) {
                    return 0;
                  }
                  return smallestCharacter(a, b) ? -1 : 1;
                }
              });
        } else {
          Collections.sort(
              plugins,
              new Comparator<LazyHostPlugin>() {

                public int compare(LazyHostPlugin o1, LazyHostPlugin o2) {
                  return o1.getDisplayName().compareTo(o2.getDisplayName());
                }
              });
        }
      } catch (final Throwable e) {
        logger.log(e);
        logger.severe("@HostPluginController: sort failed!");
      } finally {
        logger.info(
            "@HostPluginController: sort took "
                + (System.currentTimeMillis() - timeStamp)
                + "ms for "
                + plugins.size());
      }
      timeStamp = System.currentTimeMillis();
      final LinkedHashMap<String, LazyHostPlugin> retMap =
          new LinkedHashMap<String, LazyHostPlugin>();
      LazyHostPlugin fallBackPlugin = null;
      for (final LazyHostPlugin plugin : plugins) {
        plugin.setPluginClass(null);
        plugin.setClassLoader(null);
        if (fallBackPlugin == null && "UpdateRequired".equalsIgnoreCase(plugin.getDisplayName())) {
          fallBackPlugin = plugin;
          this.fallBackPlugin = plugin;
          continue;
        }
        final String pluginID = plugin.getDisplayName().toLowerCase(Locale.ENGLISH);
        final LazyHostPlugin existingPlugin = retMap.put(pluginID, plugin);
        if (existingPlugin != null) {
          if (existingPlugin.getLazyPluginClass().getInterfaceVersion()
              > plugin.getLazyPluginClass().getInterfaceVersion()) {
            retMap.put(pluginID, existingPlugin);
            // logger.finest("@HostPlugin keep:" + existingPlugin.getLazyPluginClass() + ":" +
            // existingPlugin.getVersion() +
            // " instead " + plugin.getLazyPluginClass() + ":" + plugin.getVersion());
          } else {
            // logger.finest("@HostPlugin replaced:" + existingPlugin.getLazyPluginClass() + ":" +
            // existingPlugin.getVersion() +
            // " with " + plugin.getLazyPluginClass() + ":" + plugin.getVersion());
          }
        }
      }
      logger.info(
          "@HostPluginController: mapping took "
              + (System.currentTimeMillis() - timeStamp)
              + "ms for "
              + plugins.size());
      list = retMap;
    } finally {
      final Map<String, LazyHostPlugin> llist = list;
      if (llist != null) {
        logger.info(
            "@HostPluginController: init took "
                + (System.currentTimeMillis() - completeTimeStamp)
                + "ms for "
                + llist.size());
      } else {
        logger.info(
            "@HostPluginController: init took " + (System.currentTimeMillis() - completeTimeStamp));
      }
      LogController.setRebirthLogger(null);
      validateCache();
      final List<LazyHostPlugin> lLastKnownPlugins = lastKnownPlugins;
      if (lLastKnownPlugins != null) {
        final AtomicLong lastModification = new AtomicLong(this.lastModification.get());
        final Thread saveThread =
            new Thread("@HostPluginController:save") {
              public void run() {
                save(lLastKnownPlugins, lastModification);
              };
            };
        saveThread.setDaemon(true);
        saveThread.start();
      }
      logger.close();
      System.gc();
    }
    if (SecondLevelLaunch.HOST_PLUGINS_COMPLETE.isReached()) {
      SecondLevelLaunch.INIT_COMPLETE.executeWhenReached(
          new Runnable() {

            @Override
            public void run() {
              TaskQueue.getQueue()
                  .add(
                      new QueueAction<Void, RuntimeException>() {

                        @Override
                        protected Void run() throws RuntimeException {
                          LinkCollector.getInstance().checkPluginUpdates();
                          DownloadController.getInstance().checkPluginUpdates();
                          AccountController.getInstance().checkPluginUpdates();
                          HosterRuleController.getInstance().checkPluginUpdates();
                          return null;
                        }
                      });
            }
          });
    }
    return list;
  }