Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
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);
                }
            }
        }
Exemplo n.º 7
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));
            }
        }
Exemplo n.º 8
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();
            }
        }