public void execute( int id, final ArrayList<String> files, final String FILE2, final boolean move) { if (utils.checkFolder((FILE2), c) == 1) { totalBytes = getTotalBytes(files, false); for (int i = 0; i < files.size(); i++) { HFile f1 = new HFile(files.get(i)); try { if (hash.get(id)) copyFiles((f1), new HFile(FILE2, f1.getName(), f1.isDirectory()), id, move); else { stopSelf(id); } } catch (Exception e) { System.out.println("amaze " + e); publishResults("" + e, 0, 0, id, 0, 0, false, move); stopSelf(id); } } if (move) { boolean b = hash.get(id); if (b) for (String a : files) { new HFile(a).delete(c); } } Intent intent = new Intent("loadlist"); sendBroadcast(intent); } else if (rootmode) { boolean m = true; for (int i = 0; i < files.size(); i++) { boolean b = RootTools.copyFile( getCommandLineString(files.get(i)), getCommandLineString(FILE2), true, true); if (!b && files.get(i).contains("/0/")) b = RootTools.copyFile( getCommandLineString(files.get(i).replace("/0/", "/legacy/")), getCommandLineString(FILE2), true, true); if (!b) m = false; utils.scanFile(FILE2 + "/" + new File(files.get(i)).getName(), c); } if (move && m) { new DeleteTask(getContentResolver(), c).execute((files)); } Intent intent = new Intent("loadlist"); sendBroadcast(intent); } else { System.out.println("Not Allowed"); } }
long getTotalBytes(ArrayList<String> files, boolean smb) { long totalBytes = 0l; try { for (int i = 0; i < files.size(); i++) { HFile f1 = new HFile(files.get(i)); if (f1.isDirectory()) { totalBytes = totalBytes + f1.folderSize(); } else { totalBytes = totalBytes + f1.length(); } } } catch (Exception e) { } return totalBytes; }
private void copyFiles(HFile sourceFile, HFile targetFile, int id, boolean move) throws IOException { if (sourceFile.isDirectory()) { if (!targetFile.exists()) targetFile.mkdir(c); /*try { targetFile.setLastModified(sourceFile.lastModified()); } catch (Exception e) { e.printStackTrace(); }*/ ArrayList<String[]> filePaths = sourceFile.listFiles(false); for (String[] filePath : filePaths) { HFile file = new HFile((filePath[0])); HFile destFile = new HFile(targetFile.getPath(), file.getName(), file.isDirectory()); copyFiles(file, destFile, id, move); } } else { long size = sourceFile.length(); InputStream in = sourceFile.getInputStream(); OutputStream out = targetFile.getOutputStream(c); copy(in, out, size, id, sourceFile.getName(), move); /* try { targetFile.setLastModified(sourceFile.lastModified()); } catch (Exception e) { e.printStackTrace(); }*/ if (!targetFile.isSmb()) utils.scanFile(targetFile.getPath(), c); } }