예제 #1
0
  private boolean unpackFile(ZipFile zip, byte[] buf, ZipEntry fileEntry, String name)
      throws IOException, FileNotFoundException {
    if (fileEntry == null) fileEntry = zip.getEntry(name);
    if (fileEntry == null)
      throw new FileNotFoundException("Can't find " + name + " in " + zip.getName());

    File outFile = new File(sGREDir, name);
    if (outFile.lastModified() == fileEntry.getTime() && outFile.length() == fileEntry.getSize())
      return false;

    File dir = outFile.getParentFile();
    if (!dir.exists()) dir.mkdirs();

    InputStream fileStream;
    fileStream = zip.getInputStream(fileEntry);

    OutputStream outStream = new FileOutputStream(outFile);

    while (fileStream.available() > 0) {
      int read = fileStream.read(buf, 0, buf.length);
      outStream.write(buf, 0, read);
    }

    fileStream.close();
    outStream.close();
    outFile.setLastModified(fileEntry.getTime());
    return true;
  }
예제 #2
0
  private void wrapFiles() {
    listedDirectory = new File(backStack.get(backStack.size() - 1).path);

    if (!listedDirectory.isDirectory()) {
      throw new IllegalArgumentException("Directory is not valid.");
    }

    adapter.clear();
    setTitle(listedDirectory.getAbsolutePath());

    if (isDirectoryTarget) adapter.add(new FileWrapper(null, FileWrapper.DIRSELECT, true));

    if (listedDirectory.getParentFile() != null)
      adapter.add(new FileWrapper(null, FileWrapper.PARENT, true));

    // Copy new items
    final File[] files = listedDirectory.listFiles();
    if (files != null) {
      for (File file : files) {
        String path = file.getName();

        boolean allowFile = file.isDirectory() || (filterPath(path) && !isDirectoryTarget);

        if (allowFile)
          adapter.add(new FileWrapper(file, FileWrapper.FILE, file.isDirectory() || true));
      }
    }

    // Sort items
    adapter.sort(
        new Comparator<FileWrapper>() {
          @Override
          public int compare(FileWrapper aLeft, FileWrapper aRight) {
            return aLeft.compareTo(aRight);
          };
        });

    // Update
    adapter.notifyDataSetChanged();
  }
예제 #3
0
  @Override
  public void onItemClick(AdapterView<?> aListView, View aView, int aPosition, long aID) {
    final FileWrapper item = adapter.getItem(aPosition);

    if (item.parentItem && backStack.get(backStack.size() - 1).parentIsBack) {
      backStack.remove(backStack.size() - 1);
      wrapFiles();
      return;
    } else if (item.dirSelectItem) {
      finishWithPath(listedDirectory.getAbsolutePath());
      return;
    }

    final File selected = item.parentItem ? listedDirectory.getParentFile() : item.file;

    if (selected.isDirectory()) {
      backStack.add(new BackStackItem(selected.getAbsolutePath(), !item.parentItem));
      wrapFiles();
    } else {
      String filePath = selected.getAbsolutePath();
      finishWithPath(filePath);
    }
  }