コード例 #1
0
ファイル: SyncService.cs プロジェクト: rbergen/CherryUpdater
        /// <summary>
        /// Pulls a single file.
        /// <para>Because this method just deals with a string for the remote file instead of FileEntry,
        /// the size of the file being pulled is unknown and the ISyncProgressMonitor will not properly
        /// show the progress</para>
        /// </summary>
        /// <param name="remoteFilepath">the full path to the remote file</param>
        /// <param name="localFilename">The local destination.</param>
        /// <param name="monitor">The progress monitor. Cannot be null.</param>
        /// <returns>a SyncResult object with a code and an optional message.</returns>
        /// <exception cref="ArgumentNullException">Throws if monitor is null</exception>
        public SyncResult PullFile(string remoteFilepath, string localFilename, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            long totalWork = 0;

            try
            {
                FileListingService fls             = new FileListingService(this.Device);
                FileEntry          remoteFileEntry = fls.FindFileEntry(remoteFilepath);
                totalWork = remoteFileEntry.Size;
            }
            catch (FileNotFoundException ffe)
            {
                Log.W(TAG, ffe);
            }
            monitor.Start(totalWork);

            SyncResult result = DoPullFile(remoteFilepath, localFilename, monitor);

            monitor.Stop();
            return(result);
        }
コード例 #2
0
ファイル: Device.cs プロジェクト: NasC0/Side_Stuff
        /// <summary>
        /// Installs the application package that was pushed to a temporary location on the device.
        /// </summary>
        /// <param name="remoteFilePath">absolute file path to package file on device</param>
        /// <param name="reinstall">set to <code>true</code> if re-install of app should be performed</param>
        public void InstallRemotePackage(String remoteFilePath, bool reinstall)
        {
            InstallReceiver receiver = new InstallReceiver( );
            FileEntry       entry    = FileListingService.FindFileEntry(remoteFilePath);
            String          cmd      = String.Format("pm install {1}{0}", entry.FullEscapedPath, reinstall ? "-r " : String.Empty);

            ExecuteShellCommand(cmd, receiver);

            if (!String.IsNullOrEmpty(receiver.ErrorMessage))
            {
                throw new PackageInstallationException(receiver.ErrorMessage);
            }
        }
コード例 #3
0
ファイル: FileEntry.cs プロジェクト: sttt/madb
        /// <summary>
        /// Gets a file entry from the specified path on the device.
        /// </summary>
        /// <param name="device">The device to check</param>
        /// <param name="path">the path to check</param>
        /// <exception cref="IOException">If the device is not connected.</exception>
        /// <exception cref="ArgumentNullException">If the device or path is null.</exception>
        /// <exception cref="FileNotFoundException">If the entrty is not found.</exception>
        /// <returns></returns>
        public static FileEntry Find(IDevice device, FileListingService fileListingService, String path)
        {
            device.ThrowIfNull("device");
            path.ThrowIfNullOrEmpty("path");

            if (!device.IsOffline)
            {
                return(fileListingService.FindFileEntry(path));
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
コード例 #4
0
ファイル: SyncService.cs プロジェクト: thechampanurag/madb
        /// <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 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);
        }
コード例 #5
0
ファイル: FileEntry.cs プロジェクト: sttt/madb
        /// <summary>
        /// Finds the file entry, or creates an empty FileEntry if it does not exist.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="path">The path.</param>
        /// <remarks>This does not create the FileEntry on disk. It only creates the FileEntry object.</remarks>
        /// <returns></returns>
        public static FileEntry FindOrCreate(IDevice device, FileListingService fileListingService, String path)
        {
            device.ThrowIfNull("device");
            path.ThrowIfNullOrEmpty("path");

            if (!device.IsOffline)
            {
                try
                {
                    return(fileListingService.FindFileEntry(path));
                }
                catch (FileNotFoundException)
                {
                    var fe = new FileEntry(device, path);
                    fe.Create();
                    return(fe);
                }
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
コード例 #6
0
ファイル: SyncService.cs プロジェクト: thechampanurag/madb
        /// <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 &gt; 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>
        /// <returns>
        /// a SyncResult object with a code and an optional message.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">monitor;Monitor cannot be null</exception>
        /// <gist id="c9ca09c0c0779d0a5fb8" />
        public SyncResult Pull(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(Device);

            // compute the number of file to move
            long total = GetTotalRemoteFileSize(entries, fls);

            Log.d(TAG, "total transfer: {0}", total);

            // start the monitor
            monitor.Start(total);

            SyncResult result = DoPull(entries, localPath, fls, monitor);

            monitor.Stop( );

            return(result);
        }
コード例 #7
0
ファイル: SyncService.cs プロジェクト: thechampanurag/madb
        /// <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 SyncResult DoPull(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   = 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 = 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 = 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));
        }
コード例 #8
0
        /// <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 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;
        }
コード例 #9
0
        /// <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 SyncResult DoPull( 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 = 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 = 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 = 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 );
        }
コード例 #10
0
        /// <summary>
        /// Pulls a single file.
        /// <para>Because this method just deals with a String for the remote file instead of FileEntry,
        /// the size of the file being pulled is unknown and the ISyncProgressMonitor will not properly
        /// show the progress</para>
        /// </summary>
        /// <param name="remoteFilepath">the full path to the remote file</param>
        /// <param name="localFilename">The local destination.</param>
        /// <param name="monitor">The progress monitor. Cannot be null.</param>
        /// <returns>
        /// a SyncResult object with a code and an optional message.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">monitor;Monitor cannot be null</exception>
        /// <exception cref="ArgumentNullException">Throws if monitor is null</exception>
        /// <gist id="9021e6c39ee20a6e122b" />
        public SyncResult PullFile( String remoteFilepath, String localFilename, ISyncProgressMonitor monitor )
        {
            if ( monitor == null ) {
                throw new ArgumentNullException ( "monitor", "Monitor cannot be null" );
            }

            long totalWork = 0;
            try {
                FileListingService fls = new FileListingService ( this.Device );
                FileEntry remoteFileEntry = fls.FindFileEntry ( remoteFilepath );
                totalWork = remoteFileEntry.Size;
            } catch ( FileNotFoundException ffe ) {
                Console.WriteLine ( ffe.ToString ( ) );
                Log.w ( "ddms", ffe );
            }
            monitor.Start ( totalWork );

            SyncResult result = DoPullFile ( remoteFilepath, localFilename, monitor );

            monitor.Stop ( );
            return result;
        }
コード例 #11
0
        /// <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 &gt; 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>
        /// <returns>
        /// a SyncResult object with a code and an optional message.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">monitor;Monitor cannot be null</exception>
        /// <gist id="c9ca09c0c0779d0a5fb8" />
        public SyncResult Pull( 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 ( Device );

            // compute the number of file to move
            long total = GetTotalRemoteFileSize ( entries, fls );
            Console.WriteLine ( "total transfer: {0}", total );

            // start the monitor
            monitor.Start ( total );

            SyncResult result = DoPull ( entries, localPath, fls, monitor );

            monitor.Stop ( );

            return result;
        }
コード例 #12
0
ファイル: FileSystem.cs プロジェクト: sttt/madb
 /// <summary>
 /// Initializes a new instance of the <see cref="FileSystem"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 public FileSystem(IDevice device)
 {
     Device = device;
     this.fileListingService = new FileListingService(device);
 }
コード例 #13
0
ファイル: FileSystem.cs プロジェクト: phaufe/madb
 /// <summary>
 /// Initializes a new instance of the <see cref="FileSystem"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 public FileSystem(IDevice device)
 {
     Device = device;
     this.fileListingService = new FileListingService(device);
 }