Exemplo n.º 1
0
        /// <summary>
        /// Resizes the sdcard partition (this should be non-destructive to the data)
        /// </summary>
        /// <param name="begin">Where the new partition will start</param>
        /// <param name="end">Where the new partition will end</param>
        public void ResizeSdcard(int begin, int end)
        {
            _parent.WriteToConsole("Resizing /sdcard partition (begin=" + begin + ", end=" + end + ")...\n");

            AdbCommand.ExecutePartitionCommand(Constants.PARTED_RESIZE + Constants.SDCARD_PART_NUMBER + " " + begin + " " + end, _parent);

            _parent.WriteToConsole("Sdcard resized successfully.\n\n");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Restarts the ADB daemon.
        /// </summary>
        private void RestartAdb()
        {
            WriteToConsole("Restarting adb server, please wait (this should only take a few seconds)...\n");

            AdbCommand.StartServer();

            WriteToConsole("Done. Ready to go!\n");

            EnableButtons();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Preps the device for repartitioning by unmounting all partitions and deleting the cache
        /// and data partitions.
        /// </summary>
        public void RepartitionPreparation()
        {
            //Unmount the data, cache, and sdcard partitions since we can't modify them
            //if they're mounted.
            AdbCommand.ExecuteShellCommand(Constants.UMOUNT_CACHE);
            AdbCommand.ExecuteShellCommand(Constants.UMOUNT_DATA);
            AdbCommand.ExecuteShellCommand(Constants.UMOUNT_SDCARD);

            //Remove the data and cache partitions up front
            AdbCommand.ExecutePartitionCommand(Constants.PARTED_REMOVE + Constants.CACHE_PART_NUMBER, _parent);
            AdbCommand.ExecutePartitionCommand(Constants.PARTED_REMOVE + Constants.DATA_PART_NUMBER, _parent);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Reads the current partition table's values.
        /// </summary>
        /// <returns>
        /// A dictionary that maps partition names to their sizes.
        /// </returns>
        public Dictionary <string, uint> ReadPartitionTable()
        {
            Dictionary <string, uint> partTable = new Dictionary <string, uint>();

            string partInfo = AdbCommand.ExecuteShellCommand(Constants.PARTED_PRINT);

            if (!String.IsNullOrEmpty(partInfo))
            {
                _parent.WriteToConsole(partInfo.Replace("\r", ""));
                ProcessPartitionTable(partInfo, partTable);
            }

            return(partTable);
        }
Exemplo n.º 5
0
        private void btnReboot_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Reboot device now?", "Reboot", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                WriteToConsole("Rebooting device...\n");

                _partitionTableRead = false;
                DisableButtons();
                AdbCommand.Reboot();
                EnableButtons();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Recreates the /cache partition
        /// </summary>
        /// <param name="begin">Where the partition will start</param>
        /// <param name="end">Where the partition will end</param>
        public void RepartitionCache(int begin, int end)
        {
            _parent.WriteToConsole("Repartitioning /cache (begin=" + begin + ", end=" + end + ")...\n");

            AdbCommand.ExecutePartitionCommand(Constants.PARTED_MAKE_EXTFS + begin + " " + end, _parent);
            AdbCommand.ExecutePartitionCommand(Constants.PARTED_NAME + Constants.CACHE_PART_NUMBER + " cache", _parent);

            _parent.WriteToConsole("Running e2fsck and tune2fs...\n");

            AdbCommand.ExecutePartitionCommand(Constants.TUNE2FS_EXT3 + Constants.CACHE_DEVICE, _parent);
            AdbCommand.ExecutePartitionCommand(Constants.E2FSCK + Constants.CACHE_DEVICE, _parent);
            AdbCommand.ExecutePartitionCommand(Constants.TUNE2FS_EXT4 + Constants.CACHE_DEVICE, _parent);
            AdbCommand.ExecutePartitionCommand(Constants.E2FSCK + Constants.CACHE_DEVICE, _parent);

            _parent.WriteToConsole("Cache repartitioning complete.\n\n");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Reads the current usage of each partition.
        /// </summary>
        /// <returns>
        /// A dictionary that maps partition names to their usage.
        /// </returns>
        public Dictionary <string, int> ReadPartitionUsage()
        {
            Dictionary <string, int> partUsage = new Dictionary <string, int>();

            AdbCommand.ExecuteShellCommand(Constants.MOUNT_DATA);
            AdbCommand.ExecuteShellCommand(Constants.MOUNT_SDCARD);

            string dataUsageInfo = AdbCommand.ExecuteShellCommand(Constants.USED_DATA);
            string sdUsageInfo   = AdbCommand.ExecuteShellCommand(Constants.USED_SDCARD);

            AdbCommand.ExecuteShellCommand(Constants.UMOUNT_DATA);
            AdbCommand.ExecuteShellCommand(Constants.UMOUNT_SDCARD);

            if (!String.IsNullOrEmpty(dataUsageInfo) && !String.IsNullOrEmpty(sdUsageInfo))
            {
                ProcessUsageData(dataUsageInfo, sdUsageInfo, partUsage);
            }

            return(partUsage);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Restores a local data backup to the device's /data partition.
        /// </summary>
        private void RestoreData()
        {
            DisableButtons();

            WriteToConsole("Restoring /data from backup archive...\n");
            WriteToConsole("Pushing archive to device. Please wait, this can take several minutes...\n");

            string pushOutput = _command.PushDataArchive();

            if (pushOutput.Contains("KB/s"))
            {
                WriteToConsole(pushOutput.Substring(7) + "\n");
                WriteToConsole("Extracting archive...\n");

                pushOutput = _command.ExtractDataArchive();

                if (!pushOutput.StartsWith("Error:"))
                {
                    WriteToConsole("Cleaning up...\n");
                    AdbCommand.ExecuteShellCommand("rm /data/data.tgz");
                    WriteToConsole("Done.\n");
                }
                else
                {
                    WriteToConsole("Error extracting archive.\n");
                    WriteToConsole(pushOutput);
                }
            }
            else
            {
                WriteToConsole("Error pushing archive to device.\n");
                WriteToConsole(pushOutput);
            }

            EnableButtons();
        }
Exemplo n.º 9
0
 /// <summary>
 /// Extracts a data archive on the remote device, effectively restoring the /data partition.
 /// </summary>
 /// <returns>
 /// The output of the extract command.
 /// </returns>
 public string ExtractDataArchive()
 {
     return(AdbCommand.ExecuteShellCommandWithOutput(Constants.TAR_EXTRACT, _parent));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Pushes a data.tgz archive from the local machine to the device.
 /// </summary>
 /// <returns>
 /// The output of the push command.
 /// </returns>
 public string PushDataArchive()
 {
     _parent.WriteToConsole(AdbCommand.ExecuteShellCommand(Constants.MOUNT_DATA).Replace("\r", "") + "\n");
     return(AdbCommand.ExecuteCommand(Constants.PUSH_DATA_ARCHIVE));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Pulls the data.tgz archive from the device.
 /// </summary>
 /// <returns>
 /// he output of the pull command.
 /// </returns>
 public string PullDataArchive()
 {
     return(AdbCommand.ExecuteCommand(Constants.PULL_DATA_ARCHIVE));
 }
Exemplo n.º 12
0
 private void fmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     //Try to clean up leftover adb process(es), if any
     AdbCommand.KillAdbServer();
 }
Exemplo n.º 13
0
 /// <summary>
 /// Removes a data.tgz archive from the device.
 /// </summary>
 private void RemoveRemoteArchive()
 {
     WriteToConsole("Deleting archive from /sdcard...");
     WriteToConsole(AdbCommand.ExecuteShellCommand("rm /sdcard/data.tgz") + "\n");
     WriteToConsole("Done.\n");
 }