Example #1
0
        /// <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;
        }
Example #2
0
        /// <summary>
        /// Push a single file.
        /// </summary>
        /// <param name="local">the local filepath.</param>
        /// <param name="remote">The remote filepath.</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>
        public SyncResult PushFile(String local, String remote, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            FileInfo f = new FileInfo(local);

            if (!f.Exists)
            {
                return(new SyncResult(ErrorCodeHelper.RESULT_NO_LOCAL_FILE));
            }

            if (f.IsDirectory( ))
            {
                return(new SyncResult(ErrorCodeHelper.RESULT_LOCAL_IS_DIRECTORY));
            }

            monitor.Start(f.Length);
            SyncResult result = DoPushFile(local, remote, monitor);

            monitor.Stop( );

            return(result);
        }
Example #3
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="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);
        }
Example #4
0
        /// <summary>
        /// Push multiple files </summary>
        /// <param name="fileArray"> </param>
        /// <param name="remotePath"> </param>
        /// <param name="monitor">
        /// </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 doPush(java.io.File[] fileArray, String remotePath, ISyncProgressMonitor monitor) throws SyncException, java.io.IOException, TimeoutException
        private void doPush(IEnumerable <string> fileArray, string remotePath, ISyncProgressMonitor monitor)
        {
            foreach (var f in fileArray)
            {
                // check if we're canceled
                if (monitor.canceled == true)
                {
                    throw new SyncException(SyncException.SyncError.CANCELED);
                }
                if (Directory.Exists(f))
                {
                    // append the name of the directory to the remote path
                    var    name = Path.GetFileName(f);
                    string dest = remotePath + "/" + name; // $NON-NLS-1S
                    monitor.startSubTask(dest);
                    doPush(Directory.GetFileSystemEntries(f), dest, monitor);

                    monitor.advance(1);
                }
                else if (File.Exists(f))
                {
                    // append the name of the file to the remote path
                    var    name       = Path.GetFileName(f);
                    string remoteFile = remotePath + "/" + name; // $NON-NLS-1S
                    monitor.startSubTask(remoteFile);
                    doPushFile(f, remoteFile, monitor);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Push several files.
        /// </summary>
        /// <param name="local">An array of local files to push</param>
        /// <param name="remote">the remote FileEntry representing a directory.</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 cannot be null</exception>
        /// <gist id="380b3c149499bf31e49d" />
        public SyncResult Push(IEnumerable <String> local, FileEntry remote, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            if (!remote.IsDirectory)
            {
                return(new SyncResult(ErrorCodeHelper.RESULT_REMOTE_IS_FILE));
            }

            // make a list of File from the list of String
            List <FileSystemInfo> files = new List <FileSystemInfo> ( );

            foreach (String path in local)
            {
                files.Add(path.GetFileSystemInfo( ));
            }

            // get the total count of the bytes to transfer
            long total = GetTotalLocalFileSize(files);

            monitor.Start(total);
            SyncResult result = DoPush(files, remote.FullPath, monitor);

            monitor.Stop( );

            return(result);
        }
Example #6
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 > 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();
        }
Example #7
0
        /// <include file='.\ISyncService.xml' path='/SyncService/Push/*'/>
        public static SyncResult Push(this ISyncService syncService, IEnumerable<String> local, FileEntry remote, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            if (!remote.IsDirectory)
            {
                return new SyncResult(ErrorCodeHelper.RESULT_REMOTE_IS_FILE);
            }

            // make a list of File from the list of String
            List<FileSystemInfo> files = new List<FileSystemInfo>();
            foreach (String path in local)
            {
                files.Add(path.GetFileSystemInfo());
            }

            // get the total count of the bytes to transfer
            long total = syncService.GetTotalLocalFileSize(files);

            monitor.Start(total);
            SyncResult result = syncService.DoPush(files, remote.FullPath, monitor);
            monitor.Stop();

            return result;
        }
Example #8
0
        /// <include file='.\ISyncService.xml' path='/SyncService/PullFile/*'/>
        public static SyncResult PullFile(this ISyncService syncService, FileEntry remote, String localFilename, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            long total = remote.Size;
            monitor.Start(total);

            SyncResult result = syncService.DoPullFile(remote.FullPath, localFilename, monitor);

            monitor.Stop();
            return result;
        }
Example #9
0
        /// <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();
        }
Example #10
0
        /// <summary>
        /// Pulls a single file.
        /// </summary>
        /// <param name="remote">remote 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="39fdc76b6f394b9bdf88" />
        public SyncResult PullFile(FileEntry remote, String localFilename, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            long total = remote.Size;

            monitor.Start(total);

            SyncResult result = DoPullFile(remote.FullPath, localFilename, monitor);

            monitor.Stop( );
            return(result);
        }
Example #11
0
        /// <include file='.\ISyncService.xml' path='/SyncService/PullFile2/*'/>
        public SyncResult PullFile(string remoteFilepath, string localFilename, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            long totalWork = 0;

            monitor.Start(totalWork);

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

            monitor.Stop();
            return(result);
        }
Example #12
0
        /// <summary>
        /// Push a single file. </summary>
        /// <param name="local"> the local filepath. </param>
        /// <param name="remote"> The remote filepath. </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 pushFile(String local, String remote, ISyncProgressMonitor monitor) throws SyncException, java.io.IOException, TimeoutException
        public void pushFile(string local, string remote, ISyncProgressMonitor monitor)
        {
            if (!File.Exists(local))
            {
                throw new SyncException(SyncException.SyncError.NO_LOCAL_FILE);
            }

            if (Directory.Exists(local))
            {
                throw new SyncException(SyncException.SyncError.LOCAL_IS_DIRECTORY);
            }

            monitor.start((int)new FileInfo(local).Length);

            doPushFile(local, remote, monitor);

            monitor.stop();
        }
Example #13
0
        /// <summary>
        /// Pulls a single file.
        /// <p/>Because this method just deals with a String for the remote file instead of a
        /// <seealso cref="FileListingService.FileEntry"/>, the size of the file being pulled is unknown and the
        /// <seealso cref="ISyncProgressMonitor"/> will not properly show the progress </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>
        /// <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= #getNullProgressMonitor() </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void pullFile(String remoteFilepath, String localFilename, ISyncProgressMonitor monitor) throws TimeoutException, java.io.IOException, SyncException
        public void pullFile(string remoteFilepath, string localFilename, ISyncProgressMonitor monitor)
        {
            int?mode = readMode(remoteFilepath);

            if (mode == null)
            {
                // attempts to download anyway
            }
            else if (mode == 0)
            {
                throw new SyncException(SyncException.SyncError.NO_REMOTE_OBJECT);
            }

            monitor.start(0);
            //TODO: use the {@link FileListingService} to get the file size.

            doPullFile(remoteFilepath, localFilename, monitor);

            monitor.stop();
        }
Example #14
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);

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

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

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

            monitor.Stop( );

            return(result);
        }
Example #15
0
        /// <summary>
        /// Pulls a remote file
        /// </summary>
        /// <param name="remotePath">the remote file (length max is 1024)</param>
        /// <param name="localPath">the local destination</param>
        /// <param name="monitor">the monitor. The monitor must be started already.</param>
        /// <returns>a SyncResult object with a code and an optional message.</returns>
        /// <exception cref="ArgumentNullException">Throws if monitor is null</exception>
        private SyncResult DoPullFile( string remotePath, string localPath, ISyncProgressMonitor monitor )
        {
            if ( monitor == null ) {
                throw new ArgumentNullException ( "monitor", "Monitor cannot be null" );
            }

            byte[] msg = null;
            byte[] pullResult = new byte[8];

            int timeOut = DdmPreferences.Timeout;

            try {
                byte[] remotePathContent = remotePath.GetBytes ( AdbHelper.DEFAULT_ENCODING );

                if ( remotePathContent.Length > REMOTE_PATH_MAX_LENGTH ) {
                    return new SyncResult ( ErrorCodeHelper.RESULT_REMOTE_PATH_LENGTH );
                }

                // create the full request message
                msg = CreateFileRequest ( RECV.GetBytes ( ), remotePathContent );

                // and send it.
                AdbHelper.Instance.Write ( Channel, msg, -1, timeOut );

                // read the result, in a byte array containing 2 ints
                // (id, size)
                AdbHelper.Instance.Read ( Channel, pullResult, -1, timeOut );

                // check we have the proper data back
                if ( CheckResult ( pullResult, DATA.GetBytes ( ) ) == false &&
                                CheckResult ( pullResult, DONE.GetBytes ( ) ) == false ) {
                    return new SyncResult ( ErrorCodeHelper.RESULT_CONNECTION_ERROR );
                }
            } catch ( EncoderFallbackException e ) {
                Console.WriteLine ( e );
                return new SyncResult ( ErrorCodeHelper.RESULT_REMOTE_PATH_ENCODING, e );
            } catch ( IOException e ) {
                Console.WriteLine ( e );
                return new SyncResult ( ErrorCodeHelper.RESULT_CONNECTION_ERROR, e );
            }

            // access the destination file
            FileInfo f = new FileInfo ( localPath );

            // create the stream to write in the file. We use a new try/catch block to differentiate
            // between file and network io exceptions.
            FileStream fos = null;
            try {
                fos = new FileStream ( f.FullName,System.IO.FileMode.Create,FileAccess.Write );
            } catch ( FileNotFoundException e ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_FILE_WRITE_ERROR, e );
            }

            // the buffer to read the data
            byte[] data = new byte[SYNC_DATA_MAX];
            using ( fos ) {
                // loop to get data until we're done.
                while ( true ) {
                    // check if we're canceled
                    if ( monitor.IsCanceled ) {
                        return new SyncResult ( ErrorCodeHelper.RESULT_CANCELED );
                    }

                    // if we're done, we stop the loop
                    if ( CheckResult ( pullResult, DONE.GetBytes ( ) ) ) {
                        break;
                    }
                    if ( CheckResult ( pullResult, DATA.GetBytes ( ) ) == false ) {
                        // hmm there's an error
                        return new SyncResult ( ErrorCodeHelper.RESULT_CONNECTION_ERROR );
                    }
                    int length = pullResult.Swap32bitFromArray ( 4 );
                    if ( length > SYNC_DATA_MAX ) {
                        // buffer overrun!
                        // error and exit
                        return new SyncResult ( ErrorCodeHelper.RESULT_BUFFER_OVERRUN );
                    }

                    try {
                        // now read the length we received
                        AdbHelper.Instance.Read ( Channel, data, length, timeOut );

                        // get the header for the next packet.
                        AdbHelper.Instance.Read ( Channel, pullResult, -1, timeOut );
                    } catch ( IOException e ) {
                        Console.WriteLine ( e );
                        return new SyncResult ( ErrorCodeHelper.RESULT_CONNECTION_ERROR, e );
                    }
                    // write the content in the file
                    try {
                        fos.Write ( data, 0, length );
                    } catch ( IOException e ) {
                        return new SyncResult ( ErrorCodeHelper.RESULT_FILE_WRITE_ERROR, e );
                    }

                    monitor.Advance ( length );
                }

                try {
                    fos.Flush ( );
                } catch ( IOException e ) {
                    Console.WriteLine ( e );
                    return new SyncResult ( ErrorCodeHelper.RESULT_FILE_WRITE_ERROR, e );
                }
            }
            return new SyncResult ( ErrorCodeHelper.RESULT_OK );
        }
Example #16
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 );
        }
Example #17
0
        /// <summary>
        /// Push a single file.
        /// </summary>
        /// <param name="local">the local filepath.</param>
        /// <param name="remote">The remote filepath.</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>
        public SyncResult PushFile( String local, String remote, ISyncProgressMonitor monitor )
        {
            if ( monitor == null ) {
                throw new ArgumentNullException ( "monitor", "Monitor cannot be null" );
            }

            FileInfo f = new FileInfo ( local );
            if ( !f.Exists ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_NO_LOCAL_FILE );
            }

            if ( f.IsDirectory ( ) ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_LOCAL_IS_DIRECTORY );
            }

            monitor.Start ( f.Length );
            SyncResult result = DoPushFile ( local, remote, monitor );
            monitor.Stop ( );

            return result;
        }
Example #18
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;
        }
Example #19
0
        /// <summary>
        /// Push a single file </summary>
        /// <param name="localPath"> the local file to push </param>
        /// <param name="remotePath"> the remote file (length max is 1024) </param>
        /// <param name="monitor"> the monitor. The 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 doPushFile(String localPath, String remotePath, ISyncProgressMonitor monitor) throws SyncException, java.io.IOException, TimeoutException
        private void doPushFile(string localPath, string remotePath, ISyncProgressMonitor monitor)
        {
            byte[] msg;

            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final int timeOut = DdmPreferences.getTimeOut();
            int timeOut = DdmPreferences.timeOut;

            try
            {
                var remotePathContent = remotePath.getBytes(AdbHelper.DEFAULT_ENCODING);

                if (remotePathContent.Length > REMOTE_PATH_MAX_LENGTH)
                {
                    throw new SyncException(SyncException.SyncError.REMOTE_PATH_LENGTH);
                }

                // create the header for the action
                //JAVA TO C# CONVERTER TODO TASK: Octal literals cannot be represented in C#:
                msg = createSendFileReq(ID_SEND, remotePathContent, 0644);
            }
            catch (ArgumentException e)
            {
                throw new SyncException(SyncException.SyncError.REMOTE_PATH_ENCODING, e);
            }

            // create the stream to read the file
            using (var fis = File.OpenRead(localPath))
            {

                // and send it. We use a custom try/catch block to make the difference between
                // file and network IO exceptions.
                AdbHelper.write(mChannel, msg, -1, timeOut);

                // create the buffer used to read.
                // we read max SYNC_DATA_MAX, but we need 2 4 bytes at the beginning.
                if (mBuffer == null)
                {
                    mBuffer = new byte[SYNC_DATA_MAX + 8];
                }
                Array.Copy(ID_DATA, 0, mBuffer, 0, ID_DATA.Length);

                // look while there is something to read
                while (true)
                {
                    // check if we're canceled
                    if (monitor.canceled == true)
                    {
                        throw new SyncException(SyncException.SyncError.CANCELED);
                    }

                    // read up to SYNC_DATA_MAX
                    int readCount = fis.Read(mBuffer, 8, SYNC_DATA_MAX);

                    if (readCount == -1)
                    {
                        // we reached the end of the file
                        break;
                    }

                    // now send the data to the device
                    // first write the amount read
                    ArrayHelper.swap32bitsToArray(readCount, mBuffer, 4);

                    // now write it
                    AdbHelper.write(mChannel, mBuffer, readCount + 8, timeOut);

                    // and advance the monitor
                    monitor.advance(readCount);
                }
            }

            // create the DONE message
            long time = Environment.TickCount/1000;
            msg = createReq(ID_DONE, (int) time);

            // and send it.
            AdbHelper.write(mChannel, msg, -1, timeOut);

            // read the result, in a byte array containing 2 ints
            // (id, size)
            var result = new byte[8];
            AdbHelper.read(mChannel, result, -1, timeOut); // full length

            if (checkResult(result, ID_OKAY) == false)
            {
                throw new SyncException(SyncException.SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(result, timeOut));
            }
        }
Example #20
0
        /// <summary>
        /// Push multiple files </summary>
        /// <param name="fileArray"> </param>
        /// <param name="remotePath"> </param>
        /// <param name="monitor">
        /// </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 doPush(java.io.File[] fileArray, String remotePath, ISyncProgressMonitor monitor) throws SyncException, java.io.IOException, TimeoutException
        private void doPush(IEnumerable<string> fileArray, string remotePath, ISyncProgressMonitor monitor)
        {
            foreach (var f in fileArray)
            {
                // check if we're canceled
                if (monitor.canceled == true)
                {
                    throw new SyncException(SyncException.SyncError.CANCELED);
                }
                if (Directory.Exists(f))
                {
                    // append the name of the directory to the remote path
                    var name = Path.GetFileName(f);
                    string dest = remotePath + "/" + name; // $NON-NLS-1S
                    monitor.startSubTask(dest);
                    doPush(Directory.GetFileSystemEntries(f), dest, monitor);

                    monitor.advance(1);
                }
                else if (File.Exists(f))
                {
                    // append the name of the file to the remote path
                    var name = Path.GetFileName(f);
                    string remoteFile = remotePath + "/" + name; // $NON-NLS-1S
                    monitor.startSubTask(remoteFile);
                    doPushFile(f, remoteFile, monitor);
                }
            }
        }
Example #21
0
        /// <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);
                }
            }
        }
Example #22
0
        private SyncResult DoPush( IEnumerable<FileSystemInfo> files, string remotePath, ISyncProgressMonitor monitor )
        {
            if ( monitor == null ) {
                throw new ArgumentNullException ( "monitor", "Monitor cannot be null" );
            }

            // check if we're canceled
            if ( monitor.IsCanceled ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_CANCELED );
            }

            foreach ( FileSystemInfo f in files ) {
                // check if we're canceled
                if ( monitor.IsCanceled ) {
                    return new SyncResult ( ErrorCodeHelper.RESULT_CANCELED );
                }
                // append the name of the directory/file to the remote path
                String dest = LinuxPath.Combine ( remotePath, f.Name );
                if ( f.Exists ) {
                    if ( f.IsDirectory ( ) ) {
                        DirectoryInfo fsiDir = f as DirectoryInfo;
                        monitor.StartSubTask ( f.FullName, dest );
                        SyncResult result = DoPush ( fsiDir.GetFileSystemInfos ( ), dest, monitor );

                        if ( result.Code != ErrorCodeHelper.RESULT_OK ) {
                            return result;
                        }

                        monitor.Advance ( 1 );
                    } else if ( f.IsFile ( ) ) {
                        monitor.StartSubTask ( f.FullName, dest );
                        SyncResult result = DoPushFile ( f.FullName, dest, monitor );
                        if ( result.Code != ErrorCodeHelper.RESULT_OK ) {
                            return result;
                        }
                    }
                }
            }

            return new SyncResult ( ErrorCodeHelper.RESULT_OK );
        }
Example #23
0
        /// <include file='.\ISyncService.xml' path='/SyncService/PullFile2/*'/>
        public SyncResult PullFile(string remoteFilepath, string localFilename, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            long totalWork = 0;
            monitor.Start(totalWork);

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

            monitor.Stop();
            return result;
        }
Example #24
0
        /// <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();
        }
Example #25
0
        /// <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();
        }
Example #26
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 > 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();
        }
Example #27
0
        /// <summary>
        /// Push a single file </summary>
        /// <param name="localPath"> the local file to push </param>
        /// <param name="remotePath"> the remote file (length max is 1024) </param>
        /// <param name="monitor"> the monitor. The 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 doPushFile(String localPath, String remotePath, ISyncProgressMonitor monitor) throws SyncException, java.io.IOException, TimeoutException
        private void doPushFile(string localPath, string remotePath, ISyncProgressMonitor monitor)
        {
            byte[] msg;

            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final int timeOut = DdmPreferences.getTimeOut();
            int timeOut = DdmPreferences.timeOut;

            try
            {
                var remotePathContent = remotePath.getBytes(AdbHelper.DEFAULT_ENCODING);

                if (remotePathContent.Length > REMOTE_PATH_MAX_LENGTH)
                {
                    throw new SyncException(SyncException.SyncError.REMOTE_PATH_LENGTH);
                }

                // create the header for the action
                //JAVA TO C# CONVERTER TODO TASK: Octal literals cannot be represented in C#:
                msg = createSendFileReq(ID_SEND, remotePathContent, 0644);
            }
            catch (ArgumentException e)
            {
                throw new SyncException(SyncException.SyncError.REMOTE_PATH_ENCODING, e);
            }

            // create the stream to read the file
            using (var fis = File.OpenRead(localPath))
            {
                // and send it. We use a custom try/catch block to make the difference between
                // file and network IO exceptions.
                AdbHelper.write(mChannel, msg, -1, timeOut);

                // create the buffer used to read.
                // we read max SYNC_DATA_MAX, but we need 2 4 bytes at the beginning.
                if (mBuffer == null)
                {
                    mBuffer = new byte[SYNC_DATA_MAX + 8];
                }
                Array.Copy(ID_DATA, 0, mBuffer, 0, ID_DATA.Length);

                // look while there is something to read
                while (true)
                {
                    // check if we're canceled
                    if (monitor.canceled == true)
                    {
                        throw new SyncException(SyncException.SyncError.CANCELED);
                    }

                    // read up to SYNC_DATA_MAX
                    int readCount = fis.Read(mBuffer, 8, SYNC_DATA_MAX);

                    if (readCount == -1)
                    {
                        // we reached the end of the file
                        break;
                    }

                    // now send the data to the device
                    // first write the amount read
                    ArrayHelper.swap32bitsToArray(readCount, mBuffer, 4);

                    // now write it
                    AdbHelper.write(mChannel, mBuffer, readCount + 8, timeOut);

                    // and advance the monitor
                    monitor.advance(readCount);
                }
            }

            // create the DONE message
            long time = Environment.TickCount / 1000;

            msg = createReq(ID_DONE, (int)time);

            // and send it.
            AdbHelper.write(mChannel, msg, -1, timeOut);

            // read the result, in a byte array containing 2 ints
            // (id, size)
            var result = new byte[8];

            AdbHelper.read(mChannel, result, -1, timeOut);         // full length

            if (checkResult(result, ID_OKAY) == false)
            {
                throw new SyncException(SyncException.SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(result, timeOut));
            }
        }
Example #28
0
        /// <summary>
        /// Pulls a remote file </summary>
        /// <param name="remotePath"> the remote file (length max is 1024) </param>
        /// <param name="localPath"> the local destination </param>
        /// <param name="monitor"> the monitor. The 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 doPullFile(String remotePath, String localPath, ISyncProgressMonitor monitor) throws java.io.IOException, SyncException, TimeoutException
        private void doPullFile(string remotePath, string localPath, ISyncProgressMonitor monitor)
        {
            var pullResult = new byte[8];

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int timeOut = DdmPreferences.getTimeOut();
            int timeOut = DdmPreferences.timeOut;

            try
            {
                var remotePathContent = remotePath.getBytes(AdbHelper.DEFAULT_ENCODING);

                if (remotePathContent.Length > REMOTE_PATH_MAX_LENGTH)
                {
                    throw new SyncException(SyncException.SyncError.REMOTE_PATH_LENGTH);
                }

                // create the full request message
                var msg = createFileReq(ID_RECV, remotePathContent);

                // and send it.
                AdbHelper.write(mChannel, msg, -1, timeOut);

                // read the result, in a byte array containing 2 ints
                // (id, size)
                AdbHelper.read(mChannel, pullResult, -1, timeOut);

                // check we have the proper data back
                if (checkResult(pullResult, ID_DATA) == false && checkResult(pullResult, ID_DONE) == false)
                {
                    throw new SyncException(SyncException.SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(pullResult, timeOut));
                }
            }
            catch (ArgumentException e)
            {
                throw new SyncException(SyncException.SyncError.REMOTE_PATH_ENCODING, e);
            }

            // access the destination file
            // create the stream to write in the file. We use a new try/catch block to differentiate
            // between file and network io exceptions.
            FileStream fos = null;

            try
            {
                fos = File.Create(localPath);
            }
            catch (IOException e)
            {
                Log.e("ddms", string.Format("Failed to open local file {0} for writing, Reason: {1}", localPath, e));
                throw new SyncException(SyncException.SyncError.FILE_WRITE_ERROR);
            }

            using (fos)
            {
                // the buffer to read the data
                var data = new byte[SYNC_DATA_MAX];

                // loop to get data until we're done.
                while (true)
                {
                    // check if we're cancelled
                    if (monitor.canceled == true)
                    {
                        throw new SyncException(SyncException.SyncError.CANCELED);
                    }

                    // if we're done, we stop the loop
                    if (checkResult(pullResult, ID_DONE))
                    {
                        break;
                    }
                    if (checkResult(pullResult, ID_DATA) == false)
                    {
                        // hmm there's an error
                        throw new SyncException(SyncException.SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(pullResult, timeOut));
                    }
                    int length = ArrayHelper.swap32bitFromArray(pullResult, 4);
                    if (length > SYNC_DATA_MAX)
                    {
                        // buffer overrun!
                        // error and exit
                        throw new SyncException(SyncException.SyncError.BUFFER_OVERRUN);
                    }

                    // now read the length we received
                    AdbHelper.read(mChannel, data, length, timeOut);

                    // get the header for the next packet.
                    AdbHelper.read(mChannel, pullResult, -1, timeOut);

                    // write the content in the file
                    fos.Write(data, 0, length);

                    monitor.advance(length);
                }

                fos.Flush();
            }
        }
Example #29
0
        /// <summary>
        /// Push a single file
        /// </summary>
        /// <param name="local">the local file to push</param>
        /// <param name="remotePath">the remote file (length max is 1024)</param>
        /// <param name="monitor">the monitor. The monitor must be started already.</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>
        private SyncResult DoPushFile( string local, string remotePath, ISyncProgressMonitor monitor )
        {
            if ( monitor == null ) {
                throw new ArgumentNullException ( "monitor", "Monitor cannot be null" );
            }

            FileStream fs = null;
            byte[] msg;

            int timeOut = DdmPreferences.Timeout;
            Console.WriteLine ( "Remote File: {0}", remotePath );
            try {
                byte[] remotePathContent = remotePath.GetBytes ( AdbHelper.DEFAULT_ENCODING );

                if ( remotePathContent.Length > REMOTE_PATH_MAX_LENGTH ) {
                    return new SyncResult ( ErrorCodeHelper.RESULT_REMOTE_PATH_LENGTH );
                }

                // this shouldn't happen but still...
                if ( !File.Exists ( local ) ) {
                    return new SyncResult ( ErrorCodeHelper.RESULT_NO_LOCAL_FILE );
                }

                // create the stream to read the file
                fs = new FileStream ( local, System.IO.FileMode.Open, FileAccess.Read );

                // create the header for the action
                msg = CreateSendFileRequest ( SEND.GetBytes ( ), remotePathContent, (FileMode)0644 );
            } catch ( EncoderFallbackException e ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_REMOTE_PATH_ENCODING, e );
            } catch ( FileNotFoundException e ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_FILE_READ_ERROR, e );
            }

            // and send it. We use a custom try/catch block to make the difference between
            // file and network IO exceptions.
            try {
                AdbHelper.Instance.Write ( Channel, msg, -1, timeOut );
            } catch ( IOException e ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_CONNECTION_ERROR, e );
            }

            // create the buffer used to read.
            // we read max SYNC_DATA_MAX, but we need 2 4 bytes at the beginning.
            if ( DataBuffer == null ) {
                DataBuffer = new byte[SYNC_DATA_MAX + 8];
            }
            byte[] bDATA = DATA.GetBytes ( );
            Array.Copy ( bDATA, 0, DataBuffer, 0, bDATA.Length );

            // look while there is something to read
            while ( true ) {
                // check if we're canceled
                if ( monitor.IsCanceled ) {
                    return new SyncResult ( ErrorCodeHelper.RESULT_CANCELED );
                }

                // read up to SYNC_DATA_MAX
                int readCount = 0;
                try {
                    readCount = fs.Read ( DataBuffer, 8, SYNC_DATA_MAX );
                } catch ( IOException e ) {
                    return new SyncResult ( ErrorCodeHelper.RESULT_FILE_READ_ERROR, e );
                }

                if ( readCount == 0 ) {
                    // we reached the end of the file
                    break;
                }

                // now send the data to the device
                // first write the amount read
                readCount.Swap32bitsToArray(DataBuffer, 4);

                // now write it
                try {
                    AdbHelper.Instance.Write ( Channel, DataBuffer, readCount + 8, timeOut );
                } catch ( IOException e ) {
                    return new SyncResult ( ErrorCodeHelper.RESULT_CONNECTION_ERROR, e );
                }

                // and advance the monitor
                monitor.Advance ( readCount );
            }
            // close the local file
            try {
                fs.Close ( );
            } catch ( IOException e ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_FILE_READ_ERROR, e );
            }

            try {
                // create the DONE message
                long time = DateTime.Now.CurrentTimeMillis ( ) / 1000;
                msg = CreateRequest ( DONE, (int)time );

                // and send it.
                AdbHelper.Instance.Write ( Channel, msg, -1, timeOut );

                // read the result, in a byte array containing 2 ints
                // (id, size)
                byte[] result = new byte[8];
                AdbHelper.Instance.Read ( Channel, result, -1 /* full length */, timeOut );

                if ( !CheckResult ( result, OKAY.GetBytes ( ) ) ) {
                    if ( CheckResult ( result, FAIL.GetBytes ( ) ) ) {
                        // read some error message...
                        int len = result.Swap32bitFromArray ( 4 );

                        AdbHelper.Instance.Read ( Channel, DataBuffer, len, timeOut );

                        // output the result?
                        String message = DataBuffer.GetString ( 0, len );
                        Log.e ( "ddms", "transfer error: " + message );
                        return new SyncResult ( ErrorCodeHelper.RESULT_UNKNOWN_ERROR, message );
                    }

                    return new SyncResult ( ErrorCodeHelper.RESULT_UNKNOWN_ERROR );
                }
            } catch ( IOException e ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_CONNECTION_ERROR, e );
            }

            // files pushed have no permissions...
            // lets check if we can get to the file...
            if(this.Device.FileSystem.Exists(remotePath)) {
                this.Device.FileSystem.Chmod(remotePath, "0666");
            }
            return new SyncResult ( ErrorCodeHelper.RESULT_OK );
        }
Example #30
0
        /// <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);
                }
            }
        }
Example #31
0
        /// <summary>
        /// Push a single file
        /// </summary>
        /// <param name="local">the local file to push</param>
        /// <param name="remotePath">the remote file (length max is 1024)</param>
        /// <param name="monitor">the monitor. The monitor must be started already.</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>
        private SyncResult DoPushFile(string local, string remotePath, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            FileStream fs = null;

            byte[] msg;

            int timeOut = DdmPreferences.Timeout;

            Log.d(TAG, "Remote File: {0}", remotePath);
            try {
                byte[] remotePathContent = remotePath.GetBytes(AdbHelper.DEFAULT_ENCODING);

                if (remotePathContent.Length > REMOTE_PATH_MAX_LENGTH)
                {
                    return(new SyncResult(ErrorCodeHelper.RESULT_REMOTE_PATH_LENGTH));
                }

                // this shouldn't happen but still...
                if (!File.Exists(local))
                {
                    return(new SyncResult(ErrorCodeHelper.RESULT_NO_LOCAL_FILE));
                }

                // create the stream to read the file
                fs = new FileStream(local, System.IO.FileMode.Open, FileAccess.Read);

                // create the header for the action
                msg = CreateSendFileRequest(SEND.GetBytes( ), remotePathContent, (FileMode)0644);
            } catch (EncoderFallbackException e) {
                return(new SyncResult(ErrorCodeHelper.RESULT_REMOTE_PATH_ENCODING, e));
            } catch (FileNotFoundException e) {
                return(new SyncResult(ErrorCodeHelper.RESULT_FILE_READ_ERROR, e));
            }

            // and send it. We use a custom try/catch block to make the difference between
            // file and network IO exceptions.
            try {
                AdbHelper.Instance.Write(Channel, msg, -1, timeOut);
            } catch (IOException e) {
                return(new SyncResult(ErrorCodeHelper.RESULT_CONNECTION_ERROR, e));
            }

            // create the buffer used to read.
            // we read max SYNC_DATA_MAX, but we need 2 4 bytes at the beginning.
            if (DataBuffer == null)
            {
                DataBuffer = new byte[SYNC_DATA_MAX + 8];
            }
            byte[] bDATA = DATA.GetBytes( );
            Array.Copy(bDATA, 0, DataBuffer, 0, bDATA.Length);

            // look while there is something to read
            while (true)
            {
                // check if we're canceled
                if (monitor.IsCanceled)
                {
                    return(new SyncResult(ErrorCodeHelper.RESULT_CANCELED));
                }

                // read up to SYNC_DATA_MAX
                int readCount = 0;
                try {
                    readCount = fs.Read(DataBuffer, 8, SYNC_DATA_MAX);
                } catch (IOException e) {
                    return(new SyncResult(ErrorCodeHelper.RESULT_FILE_READ_ERROR, e));
                }

                if (readCount == 0)
                {
                    // we reached the end of the file
                    break;
                }

                // now send the data to the device
                // first write the amount read
                readCount.Swap32bitsToArray(DataBuffer, 4);

                // now write it
                try {
                    AdbHelper.Instance.Write(Channel, DataBuffer, readCount + 8, timeOut);
                } catch (IOException e) {
                    return(new SyncResult(ErrorCodeHelper.RESULT_CONNECTION_ERROR, e));
                }

                // and advance the monitor
                monitor.Advance(readCount);
            }
            // close the local file
            try {
                fs.Close( );
            } catch (IOException e) {
                return(new SyncResult(ErrorCodeHelper.RESULT_FILE_READ_ERROR, e));
            }

            try {
                // create the DONE message
                long time = DateTime.Now.CurrentTimeMillis( ) / 1000;
                msg = CreateRequest(DONE, (int)time);

                // and send it.
                AdbHelper.Instance.Write(Channel, msg, -1, timeOut);

                // read the result, in a byte array containing 2 ints
                // (id, size)
                byte[] result = new byte[8];
                AdbHelper.Instance.Read(Channel, result, -1 /* full length */, timeOut);

                if (!CheckResult(result, OKAY.GetBytes( )))
                {
                    if (CheckResult(result, FAIL.GetBytes( )))
                    {
                        // read some error message...
                        int len = result.Swap32bitFromArray(4);

                        AdbHelper.Instance.Read(Channel, DataBuffer, len, timeOut);

                        // output the result?
                        String message = DataBuffer.GetString(0, len);
                        Log.e("ddms", "transfer error: " + message);
                        return(new SyncResult(ErrorCodeHelper.RESULT_UNKNOWN_ERROR, message));
                    }

                    return(new SyncResult(ErrorCodeHelper.RESULT_UNKNOWN_ERROR));
                }
            } catch (IOException e) {
                return(new SyncResult(ErrorCodeHelper.RESULT_CONNECTION_ERROR, e));
            }

            // files pushed have no permissions...
            // lets check if we can get to the file...
            if (this.Device.FileSystem.Exists(remotePath))
            {
                this.Device.FileSystem.Chmod(remotePath, "0666");
            }
            return(new SyncResult(ErrorCodeHelper.RESULT_OK));
        }
Example #32
0
        /// <summary>
        /// Pulls a remote file </summary>
        /// <param name="remotePath"> the remote file (length max is 1024) </param>
        /// <param name="localPath"> the local destination </param>
        /// <param name="monitor"> the monitor. The 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 doPullFile(String remotePath, String localPath, ISyncProgressMonitor monitor) throws java.io.IOException, SyncException, TimeoutException
        private void doPullFile(string remotePath, string localPath, ISyncProgressMonitor monitor)
        {
            var pullResult = new byte[8];

            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final int timeOut = DdmPreferences.getTimeOut();
            int timeOut = DdmPreferences.timeOut;

            try
            {
                var remotePathContent = remotePath.getBytes(AdbHelper.DEFAULT_ENCODING);

                if (remotePathContent.Length > REMOTE_PATH_MAX_LENGTH)
                {
                    throw new SyncException(SyncException.SyncError.REMOTE_PATH_LENGTH);
                }

                // create the full request message
                var msg = createFileReq(ID_RECV, remotePathContent);

                // and send it.
                AdbHelper.write(mChannel, msg, -1, timeOut);

                // read the result, in a byte array containing 2 ints
                // (id, size)
                AdbHelper.read(mChannel, pullResult, -1, timeOut);

                // check we have the proper data back
                if (checkResult(pullResult, ID_DATA) == false && checkResult(pullResult, ID_DONE) == false)
                {
                    throw new SyncException(SyncException.SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(pullResult, timeOut));
                }
            }
            catch (ArgumentException e)
            {
                throw new SyncException(SyncException.SyncError.REMOTE_PATH_ENCODING, e);
            }

            // access the destination file
            // create the stream to write in the file. We use a new try/catch block to differentiate
            // between file and network io exceptions.
            FileStream fos = null;
            try
            {
                fos = File.Create(localPath);
            }
            catch (IOException e)
            {
                Log.e("ddms", string.Format("Failed to open local file {0} for writing, Reason: {1}", localPath, e));
                throw new SyncException(SyncException.SyncError.FILE_WRITE_ERROR);
            }

            using (fos)
            {
                // the buffer to read the data
                var data = new byte[SYNC_DATA_MAX];

                // loop to get data until we're done.
                while (true)
                {
                    // check if we're cancelled
                    if (monitor.canceled == true)
                    {
                        throw new SyncException(SyncException.SyncError.CANCELED);
                    }

                    // if we're done, we stop the loop
                    if (checkResult(pullResult, ID_DONE))
                    {
                        break;
                    }
                    if (checkResult(pullResult, ID_DATA) == false)
                    {
                        // hmm there's an error
                        throw new SyncException(SyncException.SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(pullResult, timeOut));
                    }
                    int length = ArrayHelper.swap32bitFromArray(pullResult, 4);
                    if (length > SYNC_DATA_MAX)
                    {
                        // buffer overrun!
                        // error and exit
                        throw new SyncException(SyncException.SyncError.BUFFER_OVERRUN);
                    }

                    // now read the length we received
                    AdbHelper.read(mChannel, data, length, timeOut);

                    // get the header for the next packet.
                    AdbHelper.read(mChannel, pullResult, -1, timeOut);

                    // write the content in the file
                    fos.Write(data, 0, length);

                    monitor.advance(length);
                }

                fos.Flush();
            }
        }
Example #33
0
        /// <summary>
        /// Pulls a single file.
        /// <p/>Because this method just deals with a String for the remote file instead of a
        /// <seealso cref="FileListingService.FileEntry"/>, the size of the file being pulled is unknown and the
        /// <seealso cref="ISyncProgressMonitor"/> will not properly show the progress </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>
        /// <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= #getNullProgressMonitor() </seealso>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void pullFile(String remoteFilepath, String localFilename, ISyncProgressMonitor monitor) throws TimeoutException, java.io.IOException, SyncException
        public void pullFile(string remoteFilepath, string localFilename, ISyncProgressMonitor monitor)
        {
            int? mode = readMode(remoteFilepath);
            if (mode == null)
            {
                // attempts to download anyway
            }
            else if (mode == 0)
            {
                throw new SyncException(SyncException.SyncError.NO_REMOTE_OBJECT);
            }

            monitor.start(0);
            //TODO: use the {@link FileListingService} to get the file size.

            doPullFile(remoteFilepath, localFilename, monitor);

            monitor.stop();
        }
Example #34
0
        /// <summary>
        /// Pulls a remote file
        /// </summary>
        /// <param name="remotePath">the remote file (length max is 1024)</param>
        /// <param name="localPath">the local destination</param>
        /// <param name="monitor">the monitor. The monitor must be started already.</param>
        /// <returns>a SyncResult object with a code and an optional message.</returns>
        /// <exception cref="ArgumentNullException">Throws if monitor is null</exception>
        private SyncResult DoPullFile(string remotePath, string localPath, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }


            byte[] msg        = null;
            byte[] pullResult = new byte[8];

            int timeOut = DdmPreferences.Timeout;

            try {
                byte[] remotePathContent = remotePath.GetBytes(AdbHelper.DEFAULT_ENCODING);

                if (remotePathContent.Length > REMOTE_PATH_MAX_LENGTH)
                {
                    return(new SyncResult(ErrorCodeHelper.RESULT_REMOTE_PATH_LENGTH));
                }

                // create the full request message
                msg = CreateFileRequest(RECV.GetBytes( ), remotePathContent);

                // and send it.
                AdbHelper.Instance.Write(Channel, msg, -1, timeOut);

                // read the result, in a byte array containing 2 ints
                // (id, size)
                AdbHelper.Instance.Read(Channel, pullResult, -1, timeOut);

                // check we have the proper data back
                if (CheckResult(pullResult, DATA.GetBytes( )) == false &&
                    CheckResult(pullResult, DONE.GetBytes( )) == false)
                {
                    return(new SyncResult(ErrorCodeHelper.RESULT_CONNECTION_ERROR));
                }
            } catch (EncoderFallbackException e) {
                Log.e(TAG, e);
                return(new SyncResult(ErrorCodeHelper.RESULT_REMOTE_PATH_ENCODING, e));
            } catch (IOException e) {
                Log.e(TAG, e);
                return(new SyncResult(ErrorCodeHelper.RESULT_CONNECTION_ERROR, e));
            }

            // access the destination file
            FileInfo f = new FileInfo(localPath);

            // create the stream to write in the file. We use a new try/catch block to differentiate
            // between file and network io exceptions.
            FileStream fos = null;

            try {
                fos = new FileStream(f.FullName, System.IO.FileMode.Create, FileAccess.Write);
            } catch (FileNotFoundException e) {
                return(new SyncResult(ErrorCodeHelper.RESULT_FILE_WRITE_ERROR, e));
            }

            // the buffer to read the data
            byte[] data = new byte[SYNC_DATA_MAX];
            using ( fos ) {
                // loop to get data until we're done.
                while (true)
                {
                    // check if we're canceled
                    if (monitor.IsCanceled)
                    {
                        return(new SyncResult(ErrorCodeHelper.RESULT_CANCELED));
                    }

                    // if we're done, we stop the loop
                    if (CheckResult(pullResult, DONE.GetBytes( )))
                    {
                        break;
                    }
                    if (CheckResult(pullResult, DATA.GetBytes( )) == false)
                    {
                        // hmm there's an error
                        return(new SyncResult(ErrorCodeHelper.RESULT_CONNECTION_ERROR));
                    }
                    int length = pullResult.Swap32bitFromArray(4);
                    if (length > SYNC_DATA_MAX)
                    {
                        // buffer overrun!
                        // error and exit
                        return(new SyncResult(ErrorCodeHelper.RESULT_BUFFER_OVERRUN));
                    }

                    try {
                        // now read the length we received
                        AdbHelper.Instance.Read(Channel, data, length, timeOut);

                        // get the header for the next packet.
                        AdbHelper.Instance.Read(Channel, pullResult, -1, timeOut);
                    } catch (IOException e) {
                        Log.e(TAG, e);
                        return(new SyncResult(ErrorCodeHelper.RESULT_CONNECTION_ERROR, e));
                    }
                    // write the content in the file
                    try {
                        fos.Write(data, 0, length);
                    } catch (IOException e) {
                        return(new SyncResult(ErrorCodeHelper.RESULT_FILE_WRITE_ERROR, e));
                    }

                    monitor.Advance(length);
                }

                try {
                    fos.Flush( );
                } catch (IOException e) {
                    Log.e(TAG, e);
                    return(new SyncResult(ErrorCodeHelper.RESULT_FILE_WRITE_ERROR, e));
                }
            }
            return(new SyncResult(ErrorCodeHelper.RESULT_OK));
        }
Example #35
0
        private SyncResult DoPush(IEnumerable <FileSystemInfo> files, string remotePath, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            // check if we're canceled
            if (monitor.IsCanceled)
            {
                return(new SyncResult(ErrorCodeHelper.RESULT_CANCELED));
            }

            foreach (FileSystemInfo f in files)
            {
                // check if we're canceled
                if (monitor.IsCanceled)
                {
                    return(new SyncResult(ErrorCodeHelper.RESULT_CANCELED));
                }
                // append the name of the directory/file to the remote path
                String dest = LinuxPath.Combine(remotePath, f.Name);
                if (f.Exists)
                {
                    if (f.IsDirectory( ))
                    {
                        DirectoryInfo fsiDir = f as DirectoryInfo;
                        monitor.StartSubTask(f.FullName, dest);
                        SyncResult result = DoPush(fsiDir.GetFileSystemInfos( ), dest, monitor);

                        if (result.Code != ErrorCodeHelper.RESULT_OK)
                        {
                            return(result);
                        }

                        monitor.Advance(1);
                    }
                    else if (f.IsFile( ))
                    {
                        monitor.StartSubTask(f.FullName, dest);
                        SyncResult result = DoPushFile(f.FullName, dest, monitor);
                        if (result.Code != ErrorCodeHelper.RESULT_OK)
                        {
                            return(result);
                        }
                    }
                }
            }

            return(new SyncResult(ErrorCodeHelper.RESULT_OK));
        }
Example #36
0
        /// <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();
        }
Example #37
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));
        }
Example #38
0
        /// <summary>
        /// Push a single file. </summary>
        /// <param name="local"> the local filepath. </param>
        /// <param name="remote"> The remote filepath. </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 pushFile(String local, String remote, ISyncProgressMonitor monitor) throws SyncException, java.io.IOException, TimeoutException
        public void pushFile(string local, string remote, ISyncProgressMonitor monitor)
        {
            if (!File.Exists(local))
            {
                throw new SyncException(SyncException.SyncError.NO_LOCAL_FILE);
            }

            if (Directory.Exists(local))
            {
                throw new SyncException(SyncException.SyncError.LOCAL_IS_DIRECTORY);
            }

            monitor.start((int)new FileInfo(local).Length);

            doPushFile(local, remote, monitor);

            monitor.stop();
        }