/// <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"); }
/// <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(); }
/// <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); }
/// <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); }
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(); } }
/// <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"); }
/// <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); }
/// <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(); }
/// <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)); }
/// <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)); }
/// <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)); }
private void fmMain_FormClosing(object sender, FormClosingEventArgs e) { //Try to clean up leftover adb process(es), if any AdbCommand.KillAdbServer(); }
/// <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"); }