Exemple #1
0
        /// <summary>
        /// Does the LS.
        /// </summary>
        /// <param name="entry">The entry.</param>
        private void DoLS(FileEntry entry)
        {
            // create a list that will receive the list of the entries
            List <FileEntry> entryList = new List <FileEntry> ( );

            // create a list that will receive the link to compute post ls;
            List <String> linkList = new List <String> ( );

            try {
                // create the command
                String command = String.Format(TOOLBOX_LS, entry.FullPath);
                // create the receiver object that will parse the result from ls
                ListingServiceReceiver receiver = new ListingServiceReceiver(entry, entryList, linkList);

                // call ls.
                Device.ExecuteShellCommand(command, receiver);

                // finish the process of the receiver to handle links
                receiver.FinishLinks( );
            } catch (IOException e) {
                Log.e("ddms", e);
                throw;
            }


            // at this point we need to refresh the viewer
            entry.FetchTime = DateTime.Now.ToUnixEpoch();
            // sort the children and set them as the new children
            entryList.Sort(new FileEntry.FileEntryComparer( ));
            entry.Children = entryList;
        }
Exemple #2
0
        /// <summary>
        /// Unmounts the specified mount point.
        /// </summary>
        /// <param name="mountPoint">The mount point.</param>
        /// <param name="options">The options.</param>
        public void Unmount(String mountPoint, String options)
        {
            mountPoint.ThrowIfNull("mountPoint");
            Device.ThrowIfNull("Device");

            CommandErrorReceiver cer = new CommandErrorReceiver();

            Device.ExecuteShellCommand("umount {1} {0}", cer, !String.IsNullOrEmpty(options) ? String.Format("-o {0}", options) : String.Empty, mountPoint);
        }
Exemple #3
0
        /// <summary>
        /// Attempts to mount the mount point to the associated device without knowing the device or the type.
        /// Some devices may not support this method.
        /// </summary>
        /// <param name="mountPoint"></param>
        public void Mount(String mountPoint)
        {
            mountPoint.ThrowIfNull("mountPoint");
            Device.ThrowIfNull("Device");

            CommandErrorReceiver cer = new CommandErrorReceiver();

            Device.ExecuteShellCommand("mount {0}", cer, mountPoint);
        }
Exemple #4
0
        /// <summary>
        /// Mounts the specified device.
        /// </summary>
        /// <param name="mountPoint">The mp.</param>
        /// <param name="options">The options.</param>
        public void Mount(MountPoint mountPoint, String options)
        {
            mountPoint.ThrowIfNull("mountPoint");
            Device.ThrowIfNull("Device");

            CommandErrorReceiver cer = new CommandErrorReceiver();

            Device.ExecuteShellCommand("mount {0} {4} -t {1} {2} {3}", cer, mountPoint.IsReadOnly ? "-r" : "-w",
                                       mountPoint.FileSystem, mountPoint.Block, mountPoint.Name,
                                       !String.IsNullOrEmpty(options) ? String.Format("-o {0}", options) : String.Empty);
        }
Exemple #5
0
 /// <summary>
 /// Checks for busy box.
 /// </summary>
 private void CheckForBusyBox( )
 {
     if (this.Device.IsOnline)
     {
         try {
             Commands.Clear( );
             Device.ExecuteShellCommand(BUSYBOX_COMMAND, new BusyBoxCommandsReceiver(this));
             Available = true;
         } catch (FileNotFoundException) {
             Available = false;
         }
     }
     else
     {
         Available = false;
     }
 }
Exemple #6
0
        /// <summary>
        /// Creates the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public FileEntry Create(String path)
        {
            Device.ThrowIfNull("Device");

            path.ThrowIfNullOrWhiteSpace("path");

            if (!Device.IsOffline)
            {
                if (Exists(path))
                {
                    throw new ArgumentException("The specified path already exists.");
                }
                else
                {
                    var cer     = new CommandErrorReceiver();
                    var escaped = LinuxPath.Escape(path);
                    // use native touch command if its available.
                    var cmd     = ">";
                    var command = String.Format("{0} {1}", cmd, escaped);
                    if (Device.CanSU())
                    {
                        Device.ExecuteRootShellCommand(command, cer);
                    }
                    else
                    {
                        Device.ExecuteShellCommand(command, cer);
                    }
                    if (!String.IsNullOrEmpty(cer.ErrorMessage))
                    {
                        throw new IOException(String.Format("Error creating file: {0}", cer.ErrorMessage));
                    }
                    else
                    {
                        // at this point, the newly created file should exist.
                        return(this.fileListingService.FindFileEntry(path));
                    }
                }
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
Exemple #7
0
        /// <include file='.\BusyBox.xml' path='/BusyBox/Install/*'/>
        public bool Install(String busybox)
        {
            busybox.ThrowIfNullOrWhiteSpace("busybox");

            FileEntry bb = null;

            try {
                Device.ExecuteShellCommand(BUSYBOX_COMMAND, null);
                return(true);
            } catch {
                // we are just checking if it is already installed so we really expect it to wind up here.
            }

            try {
                MountPoint mp   = Device.MountPoints["/data"];
                bool       isRO = mp.IsReadOnly;
                Device.RemountMountPoint(Device.MountPoints["/data"], false);

                FileEntry path = null;
                try {
                    path = this.fileListingService.FindFileEntry(BUSYBOX_BIN);
                } catch (FileNotFoundException) {
                    // path doesn't exist, so we make it.
                    this.fileSystem.MakeDirectory(BUSYBOX_BIN);
                    // attempt to get the FileEntry after the directory has been made
                    path = this.fileListingService.FindFileEntry(BUSYBOX_BIN);
                }

                this.fileSystem.Chmod(path.FullPath, "0755");

                String bbPath = LinuxPath.Combine(path.FullPath, BUSYBOX_COMMAND);

                this.fileSystem.Copy(busybox, bbPath);


                bb = this.fileListingService.FindFileEntry(bbPath);
                this.fileSystem.Chmod(bb.FullPath, "0755");

                Device.ExecuteShellCommand("{0}/busybox --install {0}", new ConsoleOutputReceiver( ), path.FullPath);

                // check if this path exists in the path already
                if (Device.EnvironmentVariables.ContainsKey("PATH"))
                {
                    var paths = Device.EnvironmentVariables["PATH"].Split(':');
                    var found = paths.Where(p => String.Compare(p, BUSYBOX_BIN, false) == 0).Count( ) > 0;

                    // we didnt find it, so add it.
                    if (!found)
                    {
                        // this doesn't seem to actually work
                        Device.ExecuteShellCommand(@"echo \ Mad Bee buxybox >> /init.rc", null);
                        Device.ExecuteShellCommand(@"echo export PATH={0}:\$PATH >> /init.rc", null, BUSYBOX_BIN);
                    }
                }


                if (mp.IsReadOnly != isRO)
                {
                    // Put it back, if we changed it
                    Device.RemountMountPoint(mp, isRO);
                }

                Device.ExecuteShellCommand("sync", null);
            } catch (Exception) {
                throw;
            }

            CheckForBusyBox( );
            return(true);
        }