private final static NullSyncProgressMonitor sNullSyncProgressMonitor =
new NullSyncProgressMonitor();
+ public static final String MESSAGE_SIZECHECKING = "File size checking: it can take some time.";
+
private final static int SYNC_DATA_MAX = 64*1024;
private final static int REMOTE_PATH_MAX_LENGTH = 1024;
// get a FileListingService object
FileListingService fls = new FileListingService(mDevice);
+ monitor.start(-1);
+
+ monitor.startSubTask(MESSAGE_SIZECHECKING);
+
// compute the number of file to move
- long total = getTotalRemoteFileSizeLong(entries, fls);
+ long total;
+ try {
+ total = getTotalRemoteFileSizeLong(entries, fls, monitor);
+ } catch (InterruptedException e) {
+ return new SyncResult(RESULT_CANCELED);
+ } finally {
+ monitor.stop();
+ }
+
TransferInfo transferInfo = new TransferInfo();
// start the monitor
for (String path : local) {
files.add(new File(path));
}
+
+ monitor.start(-1);
+
+ monitor.startSubTask(MESSAGE_SIZECHECKING);
// get the total count of the bytes to transfer
File[] fileArray = files.toArray(new File[files.size()]);
- long total = getTotalLocalFileSizeLong(fileArray);
+
+ long total;
+ try {
+ total = getTotalLocalFileSizeLong(fileArray, monitor);
+ } catch (InterruptedException e) {
+ return new SyncResult(RESULT_CANCELED);
+ } finally {
+ monitor.stop();
+ }
+
TransferInfo sizeInfo = new TransferInfo();
monitor.start(sizeInfo.downSizing(total));
return count;
}
+
+ /**
+ * compute the recursive file size of all the files in the list. Folder
+ * have a weight of 1.
+ * @param entries
+ * @param fls
+ * @param monitor
+ * @return long typed file size
+ * @throws InterruptedException
+ */
+ private long getTotalRemoteFileSizeLong(FileEntry[] entries, FileListingService fls, ISyncProgressMonitor monitor) throws InterruptedException {
+ long count = 0;
+ for (FileEntry e : entries) {
+ if (monitor.isCanceled()) {
+ throw new InterruptedException("The computing file size was cancelled");
+ }
+ int type = e.getType();
+ if (type == FileListingService.TYPE_DIRECTORY || type == FileListingService.TYPE_ROOT_DEVICE
+ || type == FileListingService.TYPE_ROOT_EMULATOR) {
+ // get the children
+ FileEntry[] children = fls.getChildren(e, false, null);
+ count += getTotalRemoteFileSizeLong(children, fls, monitor) + 1;
+ } else if (type == FileListingService.TYPE_FILE) {
+ count += e.getSizeValue();
+ }
+ }
+
+ return count;
+ }
/**
* compute the recursive file size of all the files in the list. Folder
* This does not check for circular links.
* @param files
* @return long typed file size
+ * @throws InterruptedException
+ */
+ private long getTotalLocalFileSizeLong(File[] files, ISyncProgressMonitor monitor) throws InterruptedException {
+ long count = 0;
+
+ for (File f : files) {
+ if (monitor.isCanceled()) {
+ throw new InterruptedException("The computing file size was cancelled");
+ }
+ if (f.exists()) {
+ if (f.isDirectory()) {
+ return getTotalLocalFileSizeLong(f.listFiles(), monitor) + 1;
+ } else if (f.isFile()) {
+ count += f.length();
+ }
+ }
+ }
+
+ return count;
+ }
+
+ /**
+ * compute the recursive file size of all the files in the list. Folder
+ * have a weight of 1.
+ * This does not check for circular links.
+ * @param files
+ * @return long typed file size
*/
private long getTotalLocalFileSizeLong(File[] files) {
long count = 0;