/// <summary> /// Executes the specified plugin host. /// </summary> /// <param name="pluginHost">The plugin host.</param> /// <param name="currentDirectory">The current directory.</param> /// <param name="args">The args.</param> public override void Execute(IPluginHost pluginHost, Core.IO.LinuxDirectoryInfo currentDirectory, string[] args) { var arguments = new Arguments(args); if (!HasRequiredArguments(arguments)) { this.LogError("Missing required arguments"); } // get password StringBuilder argumentBuilder = new StringBuilder( ); var abe = System.IO.Path.Combine(Settings.Instance.ToolsDirectory, "abe.jar"); argumentBuilder.AppendFormat("-jar {0} ", abe.QuoteIfHasSpace( )); bool isPack = false; var tar = String.Empty; var backup = String.Empty; var workingDir = String.Empty; if (arguments.Contains("p", "pack")) { argumentBuilder.Append("pack "); tar = Path.GetFullPath(arguments["tar"]); workingDir = Path.GetFullPath(Path.GetDirectoryName(tar)); backup = Path.GetFullPath(System.IO.Path.Combine(workingDir, System.IO.Path.GetFileNameWithoutExtension(tar) + ".ab")); isPack = true; } else if (arguments.Contains("u", "unpack")) { backup = Path.GetFullPath(arguments["b", "backup"]); var bc = new BackupConverter(this.PluginHost); if (bc.IsExtendedBackup(backup)) { argumentBuilder.Append("unpackex "); } else { argumentBuilder.Append("unpack "); } workingDir = Path.GetFullPath(Path.GetDirectoryName(backup)); tar = Path.GetFullPath(System.IO.Path.Combine(workingDir, System.IO.Path.GetFileNameWithoutExtension(backup) + ".tar")); isPack = false; } argumentBuilder.AppendFormat("{0} {1} ", (isPack ? tar : backup).QuoteIfHasSpace( ), (isPack ? backup : tar).QuoteIfHasSpace( )); var password = String.Empty; if (arguments.Contains("pass", "password")) { password = arguments["pass", "password"]; } else { // show password dialog var ppf = new PackPasswordForm() { Text = isPack ? "Pack Password" : "Unpack Password" }; if (ppf.ShowDialog() == DialogResult.OK) { password = ppf.Password; } } if (!String.IsNullOrEmpty(password)) { argumentBuilder.Append(password); } this.LogDebug("running: java.exe {0}", argumentBuilder.ToString( )); var proc = new Process { StartInfo = new ProcessStartInfo { Arguments = argumentBuilder.ToString( ).Trim( ), WindowStyle = ProcessWindowStyle.Hidden, FileName = "java.exe", WorkingDirectory = Environment.CurrentDirectory, CreateNoWindow = true } }; proc.Start( ); }
/// <summary> /// Executes the specified plugin host. /// </summary> /// <param name="pluginHost">The plugin host.</param> /// <param name="currentDirectory">The current directory.</param> /// <param name="args">The args.</param> public override void Execute(IPluginHost pluginHost, Core.IO.LinuxDirectoryInfo currentDirectory, string[] args) { var arguments = new Arguments(args ?? new string[] { "/backup" }); if (arguments.Contains("b", "backup") || !arguments.Contains("r", "restore")) { if (!PluginHelper.CanExecute(this)) { MessageBox.Show("This plugin cannot execute on this device. The platform is not supported", "Unsupported Device", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var bdf = new BackupDeviceForm(pluginHost); if (pluginHost.GetHostWindow( ) != null) { bdf.Show( ); } else { bdf.ShowInTaskbar = true; bdf.ShowDialog( ); } } else if (arguments.Contains("r", "restore")) { var backupFile = String.Empty; var bc = new BackupConverter(pluginHost); var defDevice = String.Empty; var isExtended = arguments.Contains("extended"); if (arguments.Contains("file", "f")) { backupFile = System.IO.Path.GetFullPath(arguments["file", "f"]); } else { var ofd = new System.Windows.Forms.OpenFileDialog( ); ofd.Title = "Select Android Backup"; ofd.Filter = "Android Backup|*.ab;*.abex"; ofd.CheckFileExists = true; ofd.Multiselect = false; if (ofd.ShowDialog( ) == DialogResult.OK) { backupFile = ofd.FileName; } else { return; } } if (isExtended && bc.IsExtendedBackup(backupFile)) { var devices = CommandRunner.Instance.GetDevices( ).Select(d => d.SerialNumber).ToList( ); this.LogDebug("Restoring from Extended Backup"); var extInfo = bc.GetExtendedHeader(backupFile); if (extInfo != null) { this.LogDebug("Found Extended Info"); defDevice = extInfo.Device; this.LogDebug("Backup for {0}", defDevice); var device = devices.FirstOrDefault(m => String.Compare(defDevice, m, true) == 0); if (String.IsNullOrEmpty(device)) { MessageBox.Show("The device that this backup is tied to is not connected. If you want to apply to another device, first convert to a normal Android Backup", "Device not connected", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } } else { this.LogDebug("Unable to load Extended info"); defDevice = UseDevicePicker( ); } } else { this.LogDebug("Basic Backup"); defDevice = UseDevicePicker( ); } if (!String.IsNullOrEmpty(defDevice)) { Application.Run(new RestoreDeviceForm(this.PluginHost, backupFile)); } } }
/// <summary> /// Executes the specified plugin host. /// </summary> /// <param name="pluginHost">The plugin host.</param> /// <param name="currentDirectory">The current directory.</param> /// <param name="args">The args.</param> public override void Execute( IPluginHost pluginHost, Core.IO.LinuxDirectoryInfo currentDirectory, string[] args ) { var arguments = new Arguments ( args ); if ( !HasRequiredArguments ( arguments ) ) { this.LogError ( "Missing required arguments" ); } // get password StringBuilder argumentBuilder = new StringBuilder ( ); var abe = System.IO.Path.Combine ( Settings.Instance.ToolsDirectory, "abe.jar" ); argumentBuilder.AppendFormat ( "-jar {0} ", abe.QuoteIfHasSpace ( ) ); bool isPack = false; var tar = String.Empty; var backup = String.Empty; var workingDir = String.Empty; if ( arguments.Contains ( "p", "pack" ) ) { argumentBuilder.Append ( "pack " ); tar = Path.GetFullPath ( arguments["tar"] ); workingDir = Path.GetFullPath ( Path.GetDirectoryName ( tar ) ); backup = Path.GetFullPath ( System.IO.Path.Combine ( workingDir, System.IO.Path.GetFileNameWithoutExtension ( tar ) + ".ab" ) ); isPack = true; } else if ( arguments.Contains ( "u", "unpack" ) ) { backup = Path.GetFullPath ( arguments["b", "backup"] ); var bc = new BackupConverter ( this.PluginHost ); if ( bc.IsExtendedBackup ( backup ) ) { argumentBuilder.Append ( "unpackex " ); } else { argumentBuilder.Append ( "unpack " ); } workingDir = Path.GetFullPath ( Path.GetDirectoryName ( backup ) ); tar = Path.GetFullPath ( System.IO.Path.Combine ( workingDir, System.IO.Path.GetFileNameWithoutExtension ( backup ) + ".tar" ) ); isPack = false; } argumentBuilder.AppendFormat ( "{0} {1} ", ( isPack ? tar : backup ).QuoteIfHasSpace ( ), ( isPack ? backup : tar ).QuoteIfHasSpace ( ) ); var password = String.Empty; if ( arguments.Contains ( "pass", "password" ) ) { password = arguments["pass", "password"]; } else { // show password dialog var ppf = new PackPasswordForm() { Text = isPack ? "Pack Password" : "Unpack Password" }; if ( ppf.ShowDialog() == DialogResult.OK ) { password = ppf.Password; } } if ( !String.IsNullOrEmpty ( password ) ) { argumentBuilder.Append( password ); } this.LogDebug ( "running: java.exe {0}", argumentBuilder.ToString ( ) ); var proc = new Process { StartInfo = new ProcessStartInfo { Arguments = argumentBuilder.ToString ( ).Trim ( ), WindowStyle = ProcessWindowStyle.Hidden, FileName = "java.exe", WorkingDirectory = Environment.CurrentDirectory, CreateNoWindow = true } }; proc.Start ( ); }