Example #1
0
 public final Download getDownloadByContentUri(Uri paramUri)
 {
   
   String str;
   if (paramUri != null)
   {
     str = paramUri.toString();
     if (!TextUtils.isEmpty(str)) {
       break label26;
     }
   }
   label26:
   Download localDownload;
   do
   {
     Iterator localIterator;
     while (!localIterator.hasNext())
     {
       return null;
       str = null;
       break;
       localIterator = this.mRunningMap.values().iterator();
     }
     localDownload = (Download)localIterator.next();
   } while (!paramUri.equals(localDownload.getContentUri()));
   return localDownload;
 }
Example #2
0
 public final void notifyProgress(Download paramDownload, DownloadProgress paramDownloadProgress)
 {
   if (paramDownloadProgress.equals(paramDownload.getProgress())) {
     return;
   }
   paramDownload.setProgress(paramDownloadProgress);
   int i;
   if ((paramDownloadProgress.statusCode == this.mPreviousProgressStatus) && (this.mPreviousContentUri != null))
   {
     boolean bool = this.mPreviousContentUri.equals(paramDownload.getContentUri());
     i = 0;
     if (bool) {}
   }
   else
   {
     i = 1;
   }
   if (i != 0)
   {
     Object[] arrayOfObject = new Object[2];
     arrayOfObject[0] = paramDownload;
     arrayOfObject[1] = paramDownloadProgress.toString();
     FinskyLog.d("%s: onProgress %s.", arrayOfObject);
     this.mPreviousContentUri = paramDownload.getContentUri();
     this.mPreviousProgressStatus = paramDownloadProgress.statusCode;
   }
   notifyListeners(2, paramDownload);
 }
Example #3
0
 public final void cancel(Download paramDownload)
 {
   
   if ((paramDownload == null) || (paramDownload.isCompleted())) {
     return;
   }
   if (paramDownload.getState() == 2) {
     this.mDownloadManager.remove(paramDownload.getContentUri());
   }
   setDownloadState(paramDownload, 4);
 }
  public void test_FilemanagerPortrait() {
    solo.sleep(Resource.TIME_BIG);
    // 手机切换到竖屏→进入下载管理→查看剩余空间处的显示
    Download.switchOrientation("Portrait", this);
    solo.sleep(Resource.TIME_Middle);
    Download.enterDownloadScreen(this);
    solo.sleep(Resource.TIME_SMALL);
    solo.clickOnView(solo.getViewByPath("mobi.mgeek.TunnyBrowser:id/tabs_bg[0][1]"));
    solo.sleep(Resource.TIME_SMALL);

    solo.sleep(Resource.TIME_BIG);
  }
Example #5
0
 private void remove(Download paramDownload)
 {
   FinskyLog.d("Download %s removed from DownloadQueue", new Object[] { paramDownload });
   String str = paramDownload.getUrl();
   if (this.mPendingQueue.containsKey(str))
   {
     this.mPendingQueue.remove(str);
     return;
   }
   this.mRunningMap.remove(paramDownload.getUrl());
   startNextDownload();
 }
Example #6
0
 private void removeFromDownloadManager(Download paramDownload)
 {
   Uri localUri = paramDownload.getContentUri();
   if (localUri != null) {
     this.mDownloadManager.remove(localUri);
   }
 }
Example #7
0
 public void download() {
   if (download == null && !installed) {
     downloadFail = null;
     boolean wasSandboxed = SpoutClient.isSandboxed();
     if (wasSandboxed) SpoutClient.disableSandbox();
     download = new Download(this);
     downloads.put(getId(), download);
     download.start();
     if (wasSandboxed) SpoutClient.enableSandbox();
   }
 }
Example #8
0
 public final void addRecoveredDownload(Download paramDownload)
 {
   Utils.ensureOnMainThread();
   String str = paramDownload.getUrl();
   FinskyLog.d("Download queue recovering download %s.", new Object[] { paramDownload });
   setDownloadState(paramDownload, 2);
   this.mRunningMap.put(str, paramDownload);
   if (this.mDownloadProgressManager == null) {
     this.mDownloadProgressManager = new DownloadProgressManager(this);
   }
 }
Example #9
0
  public void render(int x, int y, int width, int height) {
    MCRenderDelegate r = (MCRenderDelegate) SpoutClient.getInstance().getRenderDelegate();
    FontRenderer font = SpoutClient.getHandle().fontRenderer;

    String sResolution = resolution + "x";
    int sWidth = font.getStringWidth(sResolution);
    font.drawStringWithShadow(sResolution, x + width - sWidth - 2, y + 2, 0xffaaaaaa);

    String name = r.getFittingText(getName(), width - 29 - sWidth - 2 - x);
    font.drawStringWithShadow(name, x + 29, y + 2, 0xffffffff);

    String sStatus = "";
    if (size > 1024 * 1024 * 9000) {
      sStatus = ChatColor.RED + "It's over 9000! ";
    }
    if (size > 1024 * 1024) {
      sStatus += size / (1024 * 1024) + " MB";
    } else if (size > 1024) {
      sStatus = size / 1024 + " KB";
    } else {
      sStatus = size + " Bytes";
    }
    if (isDownloading()) {
      sStatus = "Downloading: " + ChatColor.WHITE + download.getProgress() + "%";
    }
    if (downloadFail != null) {
      sStatus = downloadFail;
    }
    if (installed) {
      sStatus = ChatColor.GREEN + "Installed";
    }
    if (sStatus != null) {
      sWidth = font.getStringWidth(sStatus);
      font.drawStringWithShadow(sStatus, x + width - sWidth - 2, y + 11, 0xffaaaaaa);
    }

    String author = "by " + ChatColor.WHITE + getAuthor();
    author = r.getFittingText(author, width - 29 - sWidth - 2 - x);
    font.drawStringWithShadow(author, x + 29, y + 11, 0xffaaaaaa);

    String desc = r.getFittingText(getDescription(), width - 2 - 29);
    font.drawStringWithShadow(desc, x + 29, y + 20, 0xffaaaaaa);

    String iconUrl = getIconUrl();
    Texture icon = CustomTextureManager.getTextureFromUrl(iconUrl);
    if (icon == null) {
      CustomTextureManager.downloadTexture(iconUrl, true);
    } else {
      GL11.glPushMatrix();
      GL11.glTranslated(x + 2, y + 2, 0);
      r.drawTexture(icon, 25, 25);
      GL11.glPopMatrix();
    }
  }
Example #10
0
  public void run() {
    // Create a file channel for the file
    try {
      _parent.addToActive(this);
      file = new RandomAccessFile(Globals.ourHome + outFile, "rwd");
      channel = file.getChannel();

      // Create a segment downloader for each segment and run them simultaneously
      for (int i = 0; i < nSeg; i++) {
        segDownloads.add(new SegDownloader(this, peers.get(i % peers.size()) + "/" + path, i));
        (new Thread(segDownloads.get(segDownloads.size() - 1))).start();
      }

      // Wait for a download thread to either finish or fail, and update our bookkeeping
      try {
        while (!done) {
          // Get a new segment downloader off the stopped list.
          SegDownloader s = bstopped.take();

          // Give a new path to every download thread that failed.
          if (s.status() == Dstatus.FAILED) {
            synchronized (s) {
              s.dlPath = getNewPath();
              removeStopped(s);
              s.notify();
            }
          }

          // Check if that segment finishes off the download.
          else if (s.status() == Dstatus.FINISHED) {
            if (nSeg == doneSegs) {
              done = true;
              percentDone = 100;
              System.out.println("Download " + Globals.ourHome + outFile + " Finished!");

              // "Notify" the waiters that we're done.
              while (waiters > 0 && waitToken.take()) {
                waiters--;
              }
            }
          } else throw new RuntimeException("Impossible");
        }
      } catch (InterruptedException e) {
        status = Dstatus.FAILED;
      }

    } catch (IOException e) {
      Log.info("Could not open file for download!");
      status = Dstatus.FAILED;
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      status = Dstatus.FAILED;
    }
  }
Example #11
0
 public final Download getByPackageName(String paramString1, String paramString2)
 {
   
   if (TextUtils.isEmpty(paramString1)) {
     throw new IllegalArgumentException("empty packageName");
   }
   Iterator localIterator1 = this.mPendingQueue.values().iterator();
   while (localIterator1.hasNext())
   {
     Download localDownload2 = (Download)localIterator1.next();
     if (paramString1.equals(localDownload2.getPackageName()))
     {
       String str2 = localDownload2.getNodeId();
       if (((paramString2 == null) && (str2 == null)) || ((paramString2 != null) && (paramString2.equals(str2)))) {
         return localDownload2;
       }
     }
   }
   Iterator localIterator2 = this.mRunningMap.values().iterator();
   while (localIterator2.hasNext())
   {
     Download localDownload1 = (Download)localIterator2.next();
     if (paramString1.equals(localDownload1.getPackageName()))
     {
       String str1 = localDownload1.getNodeId();
       if (((paramString2 == null) && (str1 == null)) || ((paramString2 != null) && (paramString2.equals(str1)))) {
         return localDownload1;
       }
     }
   }
   return null;
 }
Example #12
0
 public final void add(Download paramDownload)
 {
   
   if (paramDownload.getState() != 0)
   {
     Object[] arrayOfObject2 = new Object[3];
     arrayOfObject2[0] = paramDownload;
     arrayOfObject2[1] = paramDownload.getUrl();
     arrayOfObject2[2] = Integer.valueOf(paramDownload.getState());
     FinskyLog.wtf("Added download %s (url=%s) while in state %d", arrayOfObject2);
   }
   String str = paramDownload.getUrl();
   Download localDownload;
   if (this.mRunningMap.containsKey(str)) {
     localDownload = (Download)this.mRunningMap.get(str);
   }
   for (;;)
   {
     if (localDownload != null)
     {
       Object[] arrayOfObject1 = new Object[4];
       arrayOfObject1[0] = paramDownload;
       arrayOfObject1[1] = paramDownload.getUrl();
       arrayOfObject1[2] = localDownload;
       arrayOfObject1[3] = localDownload.getUrl();
       FinskyLog.wtf("Added download %s (url=%s) while existing found %s (url=%s)", arrayOfObject1);
     }
     FinskyLog.d("Download %s added to DownloadQueue", new Object[] { paramDownload });
     this.mPendingQueue.put(paramDownload.getUrl(), paramDownload);
     if (this.mDownloadProgressManager == null) {
       this.mDownloadProgressManager = new DownloadProgressManager(this);
     }
     setDownloadState(paramDownload, 1);
     startNextDownload();
     return;
     if (this.mPendingQueue.containsKey(str)) {
       localDownload = (Download)this.mPendingQueue.get(str);
     } else {
       localDownload = null;
     }
   }
 }
Example #13
0
 public final void setDownloadState(Download paramDownload, int paramInt)
 {
   paramDownload.setState(paramInt);
   switch (paramInt)
   {
   default: 
     Object[] arrayOfObject = new Object[1];
     arrayOfObject[0] = Integer.valueOf(paramInt);
     FinskyLog.wtf("enum %d", arrayOfObject);
   case 0: 
   case 1: 
     return;
   case 2: 
     notifyListeners(4, paramDownload);
     return;
   case 4: 
     notifyListeners(3, paramDownload);
     return;
   case 5: 
     notifyListeners(5, paramDownload);
     return;
   }
   notifyListeners(1, paramDownload);
 }
Example #14
0
  public ArrayList<Mod> getMods(String versionToInstall, boolean isServer) {
    ArrayList<Mod> mods = new ArrayList<Mod>(); // ArrayList to hold the mods
    String xml = getXML(versionToInstall, false);
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      InputSource is = new InputSource(new StringReader(xml));
      Document document = builder.parse(is);
      document.getDocumentElement().normalize();
      NodeList nodeList = document.getElementsByTagName("mod");
      for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
          Element element = (Element) node;
          String name = element.getAttribute("name");
          String version = element.getAttribute("version");
          String url = element.getAttribute("url");
          String file = element.getAttribute("file");
          String website = element.getAttribute("website");
          String donation = element.getAttribute("donation");
          Color colour = null;
          if (element.hasAttribute("colour")) {
            String tempColour = getColour(versionToInstall, element.getAttribute("colour"));
            if (tempColour != null && tempColour.length() == 6) {
              int r, g, b;
              try {
                r = Integer.parseInt(tempColour.substring(0, 2), 16);
                g = Integer.parseInt(tempColour.substring(2, 4), 16);
                b = Integer.parseInt(tempColour.substring(4, 6), 16);
                colour = new Color(r, g, b);
              } catch (NumberFormatException e) {
                colour = null;
              }
            }
          }
          String warning = null;
          if (element.hasAttribute("warning")) {
            warning = element.getAttribute("warning");
          }
          String md5 = element.getAttribute("md5");
          Type type = Type.valueOf(element.getAttribute("type").toLowerCase());
          ExtractTo extractTo = null;
          String extractFolder = null;
          String decompFile = null;
          DecompType decompType = null;
          if (type == Type.extract) {
            extractTo = ExtractTo.valueOf(element.getAttribute("extractto").toLowerCase());
            if (element.hasAttribute("extractfolder")) {
              extractFolder = element.getAttribute("extractfolder");
            } else {
              extractFolder = "/";
            }
          } else if (type == Type.decomp) {
            decompFile = element.getAttribute("decompfile");
            decompType = DecompType.valueOf(element.getAttribute("decomptype").toLowerCase());
          }
          boolean filePattern = false;
          if (element.getAttribute("filepattern").equalsIgnoreCase("yes")) {
            filePattern = true;
          }
          String filePreference = null;
          if (element.hasAttribute("filepreference")) {
            filePreference = element.getAttribute("filepreference");
          }
          String fileCheck = null;
          if (element.hasAttribute("filecheck")) {
            fileCheck = element.getAttribute("filecheck");
          }
          boolean client = true;
          if (element.getAttribute("client").equalsIgnoreCase("no")) {
            client = false;
            if (!isServer) {
              continue; // Don't add this mod as its specified as server only
            }
          }
          boolean server = true;
          String serverURL = null;
          String serverFile = null;
          Type serverType = null;
          Download serverDownload = null;
          String serverMD5 = null;
          if (element.getAttribute("server").equalsIgnoreCase("seperate")) {
            server = false;
            serverURL = element.getAttribute("serverurl");
            serverFile = element.getAttribute("serverfile");
            serverType = Type.valueOf(element.getAttribute("servertype").toLowerCase());
            serverDownload = Download.valueOf(element.getAttribute("serverdownload").toLowerCase());
            serverMD5 = element.getAttribute("servermd5");
          } else if (element.getAttribute("server").equalsIgnoreCase("no")) {
            server = false;
            if (isServer) {
              continue;
            }
          }
          boolean optional = false;
          if (element.getAttribute("optional").equalsIgnoreCase("yes")) {
            optional = true;
          }
          boolean serverOptional = optional;
          if (element.getAttribute("serveroptional").equalsIgnoreCase("yes")) {
            serverOptional = true;
          } else if (element.getAttribute("serveroptional").equalsIgnoreCase("no")) {
            serverOptional = false;
          }
          boolean selected = false;
          if (element.hasAttribute("selected")) {
            if (element.getAttribute("selected").equalsIgnoreCase("yes")) {
              selected = true;
            }
          }
          Download download = Download.valueOf(element.getAttribute("download").toLowerCase());
          boolean hidden = false;
          if (element.getAttribute("hidden").equalsIgnoreCase("yes")) {
            hidden = true;
          }
          boolean library = false;
          if (element.getAttribute("library").equalsIgnoreCase("yes")) {
            library = true;
          }
          String group = element.getAttribute("group");
          String category = element.getAttribute("category");
          String linked = element.getAttribute("linked");
          String[] depends;
          if (element.hasAttribute("depends")) {
            String dependTemp = element.getAttribute("depends");
            if (dependTemp.contains(",")) {
              depends = dependTemp.split(",");
            } else {
              depends = new String[] {dependTemp};
            }
          } else {
            depends = null;
          }
          String filePrefix = element.getAttribute("fileprefix");
          boolean recommended = true;
          if (element.getAttribute("recommended").equalsIgnoreCase("no")) {
            recommended = false;
          }

          String description = element.getAttribute("description");
          mods.add(
              new Mod(
                  name,
                  version,
                  url,
                  file,
                  website,
                  donation,
                  colour,
                  warning,
                  md5,
                  type,
                  extractTo,
                  extractFolder,
                  decompFile,
                  decompType,
                  filePattern,
                  filePreference,
                  fileCheck,
                  client,
                  server,
                  serverURL,
                  serverFile,
                  serverDownload,
                  serverMD5,
                  serverType,
                  optional,
                  serverOptional,
                  selected,
                  download,
                  hidden,
                  library,
                  group,
                  category,
                  linked,
                  depends,
                  filePrefix,
                  recommended,
                  description));
        }
      }
    } catch (SAXException e) {
      App.settings.logStackTrace(e);
    } catch (ParserConfigurationException e) {
      App.settings.logStackTrace(e);
    } catch (IOException e) {
      App.settings.logStackTrace(e);
    }
    return mods;
  }
Example #15
0
 public final void run()
 {
   
   if (DownloadQueueImpl.this.mRunningMap.size() >= DownloadQueueImpl.this.mMaxConcurrent) {}
   label203:
   do
   {
     return;
     LinkedList localLinkedList = new LinkedList();
     Iterator localIterator1 = DownloadQueueImpl.this.mPendingQueue.keySet().iterator();
     Download localDownload;
     for (;;)
     {
       boolean bool = localIterator1.hasNext();
       localObject = null;
       if (!bool) {
         break label203;
       }
       String str2 = (String)localIterator1.next();
       localDownload = (Download)DownloadQueueImpl.this.mPendingQueue.get(str2);
       localLinkedList.add(str2);
       if (localDownload.getState() == 1)
       {
         long l1 = localDownload.getMaximumSize();
         long l2 = Storage.dataPartitionAvailableSpace();
         long l3 = Storage.externalStorageAvailableSpace();
         if (localDownload.getRequestedDestination() != null)
         {
           if (l3 >= l1) {
             break;
           }
           localDownload.setHttpStatus(198);
           DownloadQueueImpl.this.setDownloadState(localDownload, 5);
         }
         else
         {
           if (l2 >= l1) {
             break;
           }
           localDownload.setHttpStatus(198);
           DownloadQueueImpl.this.setDownloadState(localDownload, 5);
         }
       }
     }
     Object localObject = localDownload;
     Iterator localIterator2 = localLinkedList.iterator();
     while (localIterator2.hasNext())
     {
       String str1 = (String)localIterator2.next();
       DownloadQueueImpl.this.mPendingQueue.remove(str1);
     }
     DownloadQueueImpl localDownloadQueueImpl = DownloadQueueImpl.this;
     if (localObject != null)
     {
       FinskyLog.d("Download %s starting", new Object[] { localObject });
       localDownloadQueueImpl.mRunningMap.put(localObject.getUrl(), localObject);
       DownloadManagerFacade localDownloadManagerFacade = localDownloadQueueImpl.mDownloadManager;
       DownloadQueueImpl.7 local7 = new DownloadQueueImpl.7(localDownloadQueueImpl, localObject);
       localDownloadManagerFacade.enqueue(localObject, local7);
     }
   } while ((DownloadQueueImpl.this.mRunningMap.size() != 0) || (DownloadQueueImpl.this.mDownloadProgressManager == null));
   DownloadProgressManager localDownloadProgressManager = DownloadQueueImpl.this.mDownloadProgressManager;
   Handler localHandler = localDownloadProgressManager.mHandler;
   DownloadProgressManager.2 local2 = new DownloadProgressManager.2(localDownloadProgressManager);
   localHandler.post(local2);
   DownloadQueueImpl.this.mDownloadProgressManager = null;
 }
Example #16
0
 private void notifyListeners(int paramInt, final Download paramDownload)
 {
   final DownloadProgress localDownloadProgress;
   if (paramDownload == null)
   {
     localDownloadProgress = null;
     label6:
     if (paramDownload != null) {
       break label72;
     }
   }
   label72:
   for (final int i = -1;; i = paramDownload.getHttpStatus()) {
     switch (paramInt)
     {
     default: 
       throw new IllegalStateException("Bad listener type.");
       localDownloadProgress = paramDownload.getProgress();
       break label6;
     }
   }
   Object localObject = new ListenerNotifier(paramInt, paramDownload)
   {
     public final void updateListener(DownloadQueueListener paramAnonymousDownloadQueueListener)
     {
       paramAnonymousDownloadQueueListener.onNotificationClicked(paramDownload);
     }
   };
   for (;;)
   {
     new Handler(Looper.getMainLooper()).post((Runnable)localObject);
     return;
     localObject = new ListenerNotifier(paramInt, paramDownload)
     {
       public final void updateListener(DownloadQueueListener paramAnonymousDownloadQueueListener)
       {
         paramAnonymousDownloadQueueListener.onComplete(paramDownload);
       }
     };
     continue;
     localObject = new ListenerNotifier(paramInt, paramDownload)
     {
       public final void updateListener(DownloadQueueListener paramAnonymousDownloadQueueListener)
       {
         paramAnonymousDownloadQueueListener.onProgress(paramDownload, localDownloadProgress);
       }
     };
     continue;
     localObject = new ListenerNotifier(paramInt, paramDownload)
     {
       public final void updateListener(DownloadQueueListener paramAnonymousDownloadQueueListener)
       {
         paramAnonymousDownloadQueueListener.onCancel(paramDownload);
       }
     };
     continue;
     localObject = new ListenerNotifier(paramInt, paramDownload)
     {
       public final void updateListener(DownloadQueueListener paramAnonymousDownloadQueueListener)
       {
         paramAnonymousDownloadQueueListener.onError(paramDownload, i);
       }
     };
     continue;
     localObject = new ListenerNotifier(paramInt, paramDownload)
     {
       public final void updateListener(DownloadQueueListener paramAnonymousDownloadQueueListener)
       {
         paramAnonymousDownloadQueueListener.onStart(paramDownload);
       }
     };
   }
 }
Example #17
0
 public static void cancelAllDownloads() {
   for (Download d : downloads.values()) {
     d.cancel();
   }
 }
Example #18
0
 int CreateInstance(int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) {
   Download download = new Download();
   download.AddRef();
   XPCOM.memmove(result, new int /*long*/[] {download.getAddress()}, C.PTR_SIZEOF);
   return XPCOM.NS_OK;
 }