/// <include file='.\ISyncService.xml' path='/SyncService/Pull/*'/> public static SyncResult Pull(this ISyncService syncService, IEnumerable<FileEntry> entries, String localPath, ISyncProgressMonitor monitor) { if (monitor == null) { throw new ArgumentNullException("monitor", "Monitor cannot be null"); } // first we check the destination is a directory and exists DirectoryInfo d = new DirectoryInfo(localPath); if (!d.Exists) { return new SyncResult(ErrorCodeHelper.RESULT_NO_DIR_TARGET); } if (!d.IsDirectory()) { return new SyncResult(ErrorCodeHelper.RESULT_TARGET_IS_FILE); } // get a FileListingService object FileListingService fls = new FileListingService(syncService.Device); // compute the number of file to move long total = GetTotalRemoteFileSize(entries, fls); Log.i(TAG, "total transfer: {0}", total); // start the monitor monitor.Start(total); SyncResult result = syncService.DoPull(entries, localPath, fls, monitor); monitor.Stop(); return result; }
public void SyncServicePullFileTest() { Device device = GetFirstDevice(); FileListingService fileListingService = new FileListingService(device); using (ISyncService sync = device.SyncService) { String rfile = "/sdcard/bootanimations/bootanimation-cm.zip"; FileEntry rentry = fileListingService.FindFileEntry(rfile); String lpath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); String lfile = Path.Combine(lpath, LinuxPath.GetFileName(rfile)); FileInfo lfi = new FileInfo(lfile); SyncResult result = sync.PullFile(rfile, lfile, new FileSyncProgressMonitor()); Assert.IsTrue(lfi.Exists); Assert.IsTrue(ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString(result.Code)); lfi.Delete(); result = sync.PullFile(rentry, lfile, new FileSyncProgressMonitor()); Assert.IsTrue(lfi.Exists); Assert.IsTrue(ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString(result.Code)); lfi.Delete(); } }
public void FileListingServiceTest() { Device device = GetFirstDevice(); FileListingService fileListingService = new FileListingService(device); FileEntry[] entries = fileListingService.GetChildren(fileListingService.Root, false, null); foreach (var item in entries) { Console.WriteLine(item.FullPath); } }
public void FindOrCreateTest( ) { Device device = GetFirstDevice ( ); FileListingService fileListingService = new FileListingService(device); FileSystem fileSystem = new FileSystem(device); var path ="/mnt/sdcard/test/delete/"; FileEntry fe = FileEntry.FindOrCreate ( device, fileListingService, path ); Assert.IsTrue ( fe.Exists ); fileSystem.Delete ( fe.FullResolvedPath ); }
public void FileListingService_ListDirectories_CorrectName() { var fileListingService = new FileListingService(); var directoryName = Guid.NewGuid(); Directory.CreateDirectory(tmpFolder + Path.DirectorySeparatorChar + directoryName); var files = fileListingService.ListDirectories(tmpFolder); Assert.That(files.First().Name, Is.EqualTo(directoryName.ToString())); }
public void FindOrCreateTest() { Device device = GetFirstDevice(); FileListingService fileListingService = new FileListingService(device); FileSystem fileSystem = new FileSystem(device); var path = "/mnt/sdcard/test/delete/"; FileEntry fe = FileEntry.FindOrCreate(device, fileListingService, path); Assert.True(fe.Exists); fileSystem.Delete(fe.FullResolvedPath); }
public void FindEntryTest( ) { Device device = GetFirstDevice ( ); FileListingService fileListingService = new FileListingService(device); FileEntry fe = FileEntry.Find ( device, fileListingService, "/system/" ); fe = FileEntry.Find ( device, fileListingService, "/system/bin/" ); fe = FileEntry.Find ( device, fileListingService, "/mnt/sdcard/Android/data/com.camalotdesigns.myandroider/Injector.jar" ); // test links fe = FileEntry.Find ( device, fileListingService, "/sdcard/Android/data/com.camalotdesigns.myandroider/Injector.jar" ); }
public void FindEntryTest() { Device device = GetFirstDevice(); FileListingService fileListingService = new FileListingService(device); FileEntry fe = FileEntry.Find(device, fileListingService, "/system/"); fe = FileEntry.Find(device, fileListingService, "/system/bin/"); fe = FileEntry.Find(device, fileListingService, "/mnt/sdcard/Android/data/com.camalotdesigns.myandroider/Injector.jar"); // test links fe = FileEntry.Find(device, fileListingService, "/sdcard/Android/data/com.camalotdesigns.myandroider/Injector.jar"); }
public void FileListingService_LoadFileInfo_CorrectSize() { var fileListingService = new FileListingService(); var fileName = Guid.NewGuid(); var filePath = tmpFolder + Path.DirectorySeparatorChar + fileName; var fs = File.Create(filePath); fs.Dispose(); File.WriteAllBytes(filePath, new byte[1337]); var fileInfo = fileListingService.LoadFileInfo(filePath); Assert.That(fileInfo.ByteSize, Is.EqualTo(1337)); }
public void FileListingService_ListFiles_CorrectAmount() { var fileListingService = new FileListingService(); for (var i = 0; i < 3; i++) { File.Create(tmpFolder + Path.DirectorySeparatorChar + Guid.NewGuid()); } var files = fileListingService.ListFiles(tmpFolder) .ToList(); // ToList makes it easier to debug, than enumerable Assert.That(files.Count(), Is.EqualTo(3)); }
public void ResolveStorageDirectoryTest() { // Tests the path to the /storage/emulated/legacy folder on a Nexus 10 device. var device = this.GetFirstDevice(); FileListingService fileListingService = new FileListingService(device); // Make sure the /storage/ folder is resolved correctly. It is not a symlink, but it may // contain symlinks - e.g. /storage/sdcard. // In previous builds, the /storage/ folder would be resolved to symlink of its children. FileEntry storage = fileListingService.FindFileEntry("/storage/"); Assert.AreEqual("/storage/", storage.FullResolvedPath); FileEntry apk = fileListingService.FindFileEntry("/storage/emulated/legacy/a584a9d6-1e29-4a4b-b8fb-23aa3f378b56.apk"); Assert.AreEqual("/mnt/shell/emulated/0/a584a9d6-1e29-4a4b-b8fb-23aa3f378b56.apk", apk.FullEscapedPath); }
public void FileListingService_LoadFileInfo_CorrectDates() { var fileListingService = new FileListingService(); var fileName = Guid.NewGuid(); var filePath = tmpFolder + Path.DirectorySeparatorChar + fileName; var fs = File.Create(filePath); fs.Dispose(); File.WriteAllBytes(filePath, new byte[1337]); var fileInfo = fileListingService.LoadFileInfo(filePath); Assert.That(fileInfo.CreateDate, Is.GreaterThanOrEqualTo(DateTime.Now.Subtract(TimeSpan.FromMinutes(1)))); Assert.That(fileInfo.CreateDate, Is.LessThanOrEqualTo(DateTime.Now.Add(TimeSpan.FromMinutes(1)))); Assert.That(fileInfo.AccessDate, Is.GreaterThanOrEqualTo(DateTime.Now.Subtract(TimeSpan.FromMinutes(1)))); Assert.That(fileInfo.AccessDate, Is.LessThanOrEqualTo(DateTime.Now.Add(TimeSpan.FromMinutes(1)))); Assert.That(fileInfo.ModifiedDate, Is.GreaterThanOrEqualTo(DateTime.Now.Subtract(TimeSpan.FromMinutes(1)))); Assert.That(fileInfo.ModifiedDate, Is.LessThanOrEqualTo(DateTime.Now.Add(TimeSpan.FromMinutes(1)))); }
/// <summary> /// compute the recursive file size of all the files in the list. Folder have a weight of 1. /// </summary> /// <param name="entries">The remote files</param> /// <param name="fls">The FileListingService</param> /// <returns>The total number of bytes of the specified remote files</returns> private static long GetTotalRemoteFileSize(IEnumerable <FileEntry> entries, FileListingService fls) { long count = 0; foreach (FileEntry e in entries) { FileListingService.FileTypes type = e.Type; if (type == FileListingService.FileTypes.Directory) { // get the children IEnumerable <FileEntry> children = fls.GetChildren(e, false, null); count += GetTotalRemoteFileSize(children, fls) + 1; } else if (type == FileListingService.FileTypes.File) { count += e.Size; } } return(count); }
public void SyncServicePullFilesTest() { Device device = GetFirstDevice(); FileListingService fileListingService = new FileListingService(device); using (ISyncService sync = device.SyncService) { String lpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "apps"); String rpath = "/system/app/"; DirectoryInfo ldir = new DirectoryInfo(lpath); if (!ldir.Exists) { ldir.Create(); } FileEntry fentry = fileListingService.FindFileEntry(rpath); Assert.IsTrue(fentry.IsDirectory); FileEntry[] entries = fileListingService.GetChildren(fentry, false, null); SyncResult result = sync.Pull(entries, ldir.FullName, new FileSyncProgressMonitor()); Assert.IsTrue(ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString(result.Code)); } }
public void SyncServicePushFileTest() { String testFile = CreateTestFile(); FileInfo localFile = new FileInfo(testFile); String remoteFile = String.Format("/sdcard/{0}", Path.GetFileName(testFile)); Device device = GetFirstDevice(); FileListingService fileListingService = new FileListingService(device); using (ISyncService sync = device.SyncService) { SyncResult result = sync.PushFile(localFile.FullName, remoteFile, new FileSyncProgressMonitor()); Assert.IsTrue(ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString(result.Code)); FileEntry remoteEntry = null; remoteEntry = fileListingService.FindFileEntry(remoteFile); // check the size Assert.AreEqual <long>(localFile.Length, remoteEntry.Size); // clean up temp file on sdcard device.ExecuteShellCommand(String.Format("rm {0}", remoteEntry.FullEscapedPath), new ConsoleOutputReceiver()); } }
/// <include file='.\ISyncService.xml' path='/SyncService/Pull/*'/> public static SyncResult Pull(this ISyncService syncService, IEnumerable <FileEntry> entries, String localPath, ISyncProgressMonitor monitor) { if (monitor == null) { throw new ArgumentNullException("monitor", "Monitor cannot be null"); } // first we check the destination is a directory and exists DirectoryInfo d = new DirectoryInfo(localPath); if (!d.Exists) { return(new SyncResult(ErrorCodeHelper.RESULT_NO_DIR_TARGET)); } if (!d.IsDirectory()) { return(new SyncResult(ErrorCodeHelper.RESULT_TARGET_IS_FILE)); } // get a FileListingService object FileListingService fls = new FileListingService(syncService.Device); // compute the number of file to move long total = GetTotalRemoteFileSize(entries, fls); Log.i(TAG, "total transfer: {0}", total); // start the monitor monitor.Start(total); SyncResult result = syncService.DoPull(entries, localPath, fls, monitor); monitor.Stop(); return(result); }
/// <summary> /// compute the recursive file size of all the files in the list. Folder /// have a weight of 1. </summary> /// <param name="entries"> </param> /// <param name="fls"> /// @return </param> private int getTotalRemoteFileSize(FileListingService.FileEntry[] entries, FileListingService fls) { int count = 0; foreach (FileListingService.FileEntry e in entries) { int type = e.type; if (type == FileListingService.TYPE_DIRECTORY) { // get the children FileListingService.FileEntry[] children = fls.getChildren(e, false, null); count += getTotalRemoteFileSize(children, fls) + 1; } else if (type == FileListingService.TYPE_FILE) { count += e.sizeValue; } } return count; }
/// <summary> /// Pulls multiple files/folders recursively. </summary> /// <param name="entries"> The list of entry to pull </param> /// <param name="localPath"> the localpath to a directory </param> /// <param name="fileListingService"> a FileListingService object to browse through remote directories. </param> /// <param name="monitor"> the progress monitor. Must be started already. /// </param> /// <exception cref="SyncException"> if file could not be pushed </exception> /// <exception cref="IOException"> in case of I/O error on the connection. </exception> /// <exception cref="TimeoutException"> in case of a timeout reading responses from the device. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void doPull(com.android.ddmlib.FileListingService.FileEntry[] entries, String localPath, FileListingService fileListingService, ISyncProgressMonitor monitor) throws SyncException, java.io.IOException, TimeoutException private void doPull(FileListingService.FileEntry[] entries, string localPath, FileListingService fileListingService, ISyncProgressMonitor monitor) { foreach (FileListingService.FileEntry e in entries) { // check if we're cancelled if (monitor.canceled == true) { throw new SyncException(SyncException.SyncError.CANCELED); } // get type (we only pull directory and files for now) int type = e.type; if (type == FileListingService.TYPE_DIRECTORY) { monitor.startSubTask(e.fullPath); var dest = Path.Combine(localPath, e.name); // make the directory Directory.CreateDirectory(dest); // then recursively call the content. Since we did a ls command // to get the number of files, we can use the cache FileListingService.FileEntry[] children = fileListingService.getChildren(e, true, null); doPull(children, dest, fileListingService, monitor); monitor.advance(1); } else if (type == FileListingService.TYPE_FILE) { monitor.startSubTask(e.fullPath); string dest = Path.Combine(localPath, e.name); doPullFile(e.fullPath, dest, monitor); } } }
/// <summary> /// Push several files. </summary> /// <param name="local"> An array of loca files to push </param> /// <param name="remote"> the remote <seealso cref="FileListingService.FileEntry"/> representing a directory. </param> /// <param name="monitor"> The progress monitor. Cannot be null. </param> /// <exception cref="SyncException"> if file could not be pushed </exception> /// <exception cref="IOException"> in case of I/O error on the connection. </exception> /// <exception cref="TimeoutException"> in case of a timeout reading responses from the device. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void push(String[] local, com.android.ddmlib.FileListingService.FileEntry remote, ISyncProgressMonitor monitor) throws SyncException, java.io.IOException, TimeoutException public void push(string[] local, FileListingService.FileEntry remote, ISyncProgressMonitor monitor) { if (remote.directory == false) { throw new SyncException(SyncException.SyncError.REMOTE_IS_FILE); } // get the total count of the bytes to transfer int total = getTotalLocalFileSize(local); monitor.start(total); doPush(local, remote.fullPath, monitor); monitor.stop(); }
/// <summary> /// Pulls a single file. </summary> /// <param name="remote"> the remote file </param> /// <param name="localFilename"> The local destination. </param> /// <param name="monitor"> The progress monitor. Cannot be null. /// </param> /// <exception cref="IOException"> in case of an IO exception. </exception> /// <exception cref="TimeoutException"> in case of a timeout reading responses from the device. </exception> /// <exception cref="SyncException"> in case of a sync exception. /// </exception> /// <seealso cref= FileListingService.FileEntry </seealso> /// <seealso cref= #getNullProgressMonitor() </seealso> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void pullFile(com.android.ddmlib.FileListingService.FileEntry remote, String localFilename, ISyncProgressMonitor monitor) throws java.io.IOException, SyncException, TimeoutException public void pullFile(FileListingService.FileEntry remote, string localFilename, ISyncProgressMonitor monitor) { int total = remote.sizeValue; monitor.start(total); doPullFile(remote.fullPath, localFilename, monitor); monitor.stop(); }
/// <summary> /// Pulls file(s) or folder(s). </summary> /// <param name="entries"> the remote item(s) to pull </param> /// <param name="localPath"> The local destination. If the entries count is > 1 or /// if the unique entry is a folder, this should be a folder. </param> /// <param name="monitor"> The progress monitor. Cannot be null. </param> /// <exception cref="SyncException"> </exception> /// <exception cref="IOException"> </exception> /// <exception cref="TimeoutException"> /// </exception> /// <seealso cref= FileListingService.FileEntry </seealso> /// <seealso cref= #getNullProgressMonitor() </seealso> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void pull(com.android.ddmlib.FileListingService.FileEntry[] entries, String localPath, ISyncProgressMonitor monitor) throws SyncException, java.io.IOException, TimeoutException public void pull(FileListingService.FileEntry[] entries, string localPath, ISyncProgressMonitor monitor) { // first we check the destination is a directory and exists if (!Directory.Exists(localPath)) { throw new SyncException(SyncException.SyncError.NO_DIR_TARGET); } if (File.Exists(localPath)) { throw new SyncException(SyncException.SyncError.TARGET_IS_FILE); } // get a FileListingService object FileListingService fls = new FileListingService(mDevice); // compute the number of file to move int total = getTotalRemoteFileSize(entries, fls); // start the monitor monitor.start(total); doPull(entries, localPath, fls, monitor); monitor.stop(); }
public void SyncServicePushFileTest() { String testFile = CreateTestFile(); FileInfo localFile = new FileInfo(testFile); String remoteFile = String.Format("/sdcard/{0}", Path.GetFileName(testFile)); Device device = GetFirstDevice(); FileListingService fileListingService = new FileListingService(device); using (ISyncService sync = device.SyncService) { SyncResult result = sync.PushFile(localFile.FullName, remoteFile, new FileSyncProgressMonitor()); Assert.IsTrue(ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString(result.Code)); FileEntry remoteEntry = null; remoteEntry = fileListingService.FindFileEntry(remoteFile); // check the size Assert.AreEqual<long>(localFile.Length, remoteEntry.Size); // clean up temp file on sdcard device.ExecuteShellCommand(String.Format("rm {0}", remoteEntry.FullEscapedPath), new ConsoleOutputReceiver()); } }
/// <summary> /// /// </summary> /// <param name="entries"></param> /// <param name="localPath"></param> /// <param name="fls"></param> /// <param name="monitor"></param> /// <returns></returns> /// <exception cref="System.IO.IOException">Throws if unable to create a file or folder</exception> /// <exception cref="System.ArgumentNullException">Throws if the ISyncProgressMonitor is null</exception> private static SyncResult DoPull(this ISyncService syncService, IEnumerable <FileEntry> entries, string localPath, FileListingService fileListingService, ISyncProgressMonitor monitor) { if (monitor == null) { throw new ArgumentNullException("monitor", "Monitor cannot be null"); } // check if we're cancelled if (monitor.IsCanceled) { return(new SyncResult(ErrorCodeHelper.RESULT_CANCELED)); } // check if we need to create the local directory DirectoryInfo localDir = new DirectoryInfo(localPath); if (!localDir.Exists) { localDir.Create(); } foreach (FileEntry e in entries) { // check if we're canceled if (monitor.IsCanceled) { return(new SyncResult(ErrorCodeHelper.RESULT_CANCELED)); } // the destination item (folder or file) String dest = Path.Combine(localPath, e.Name); // get type (we only pull directory and files for now) FileListingService.FileTypes type = e.Type; if (type == FileListingService.FileTypes.Directory) { monitor.StartSubTask(e.FullPath, dest); // then recursively call the content. Since we did a ls command // to get the number of files, we can use the cache FileEntry[] children = fileListingService.GetChildren(e, true, null); SyncResult result = syncService.DoPull(children, dest, fileListingService, monitor); if (result.Code != ErrorCodeHelper.RESULT_OK) { return(result); } monitor.Advance(1); } else if (type == FileListingService.FileTypes.File) { monitor.StartSubTask(e.FullPath, dest); SyncResult result = syncService.DoPullFile(e.FullPath, dest, monitor); if (result.Code != ErrorCodeHelper.RESULT_OK) { return(result); } } else if (type == FileListingService.FileTypes.Link) { monitor.StartSubTask(e.FullPath, dest); SyncResult result = syncService.DoPullFile(e.FullResolvedPath, dest, monitor); if (result.Code != ErrorCodeHelper.RESULT_OK) { return(result); } } else { Log.d("ddms-sync", String.Format("unknown type to transfer: {0}", type)); } } return(new SyncResult(ErrorCodeHelper.RESULT_OK)); }
/// <summary> /// /// </summary> /// <param name="entries"></param> /// <param name="localPath"></param> /// <param name="fls"></param> /// <param name="monitor"></param> /// <returns></returns> /// <exception cref="System.IO.IOException">Throws if unable to create a file or folder</exception> /// <exception cref="System.ArgumentNullException">Throws if the ISyncProgressMonitor is null</exception> private static SyncResult DoPull(this ISyncService syncService, IEnumerable<FileEntry> entries, string localPath, FileListingService fileListingService, ISyncProgressMonitor monitor) { if (monitor == null) { throw new ArgumentNullException("monitor", "Monitor cannot be null"); } // check if we're cancelled if (monitor.IsCanceled) { return new SyncResult(ErrorCodeHelper.RESULT_CANCELED); } // check if we need to create the local directory DirectoryInfo localDir = new DirectoryInfo(localPath); if (!localDir.Exists) { localDir.Create(); } foreach (FileEntry e in entries) { // check if we're canceled if (monitor.IsCanceled) { return new SyncResult(ErrorCodeHelper.RESULT_CANCELED); } // the destination item (folder or file) String dest = Path.Combine(localPath, e.Name); // get type (we only pull directory and files for now) FileListingService.FileTypes type = e.Type; if (type == FileListingService.FileTypes.Directory) { monitor.StartSubTask(e.FullPath, dest); // then recursively call the content. Since we did a ls command // to get the number of files, we can use the cache FileEntry[] children = fileListingService.GetChildren(e, true, null); SyncResult result = syncService.DoPull(children, dest, fileListingService, monitor); if (result.Code != ErrorCodeHelper.RESULT_OK) { return result; } monitor.Advance(1); } else if (type == FileListingService.FileTypes.File) { monitor.StartSubTask(e.FullPath, dest); SyncResult result = syncService.DoPullFile(e.FullPath, dest, monitor); if (result.Code != ErrorCodeHelper.RESULT_OK) { return result; } } else if (type == FileListingService.FileTypes.Link) { monitor.StartSubTask(e.FullPath, dest); SyncResult result = syncService.DoPullFile(e.FullResolvedPath, dest, monitor); if (result.Code != ErrorCodeHelper.RESULT_OK) { return result; } } else { Log.d("ddms-sync", String.Format("unknown type to transfer: {0}", type)); } } return new SyncResult(ErrorCodeHelper.RESULT_OK); }
/// <summary> /// compute the recursive file size of all the files in the list. Folder have a weight of 1. /// </summary> /// <param name="entries">The remote files</param> /// <param name="fls">The FileListingService</param> /// <returns>The total number of bytes of the specified remote files</returns> private static long GetTotalRemoteFileSize(IEnumerable<FileEntry> entries, FileListingService fls) { long count = 0; foreach (FileEntry e in entries) { FileListingService.FileTypes type = e.Type; if (type == FileListingService.FileTypes.Directory) { // get the children IEnumerable<FileEntry> children = fls.GetChildren(e, false, null); count += GetTotalRemoteFileSize(children, fls) + 1; } else if (type == FileListingService.FileTypes.File) { count += e.Size; } } return count; }