Beispiel #1
0
 /// <summary>
 /// Creates an archive of the /data partition
 /// </summary>
 /// <returns>
 /// The output of the archive command.
 /// </returns>
 public string ArchiveDataPartition()
 {
     //Try to mount /data and /sdcard, the result is pretty much irrelevant since tar will error out if need be
     _parent.WriteToConsole(AdbCommand.ExecuteShellCommand(Constants.MOUNT_DATA).Replace("\r", "") + "\n");
     _parent.WriteToConsole(AdbCommand.ExecuteShellCommand(Constants.MOUNT_SDCARD).Replace("\r", "") + "\n");
     return(AdbCommand.ExecuteShellCommandWithOutput(Constants.TAR_CREATE, _parent));
 }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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();
        }
Beispiel #6
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));
 }
Beispiel #7
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");
 }