コード例 #1
0
ファイル: DeviceBackup.cs プロジェクト: zidane0/droidexplorer
        /// <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));
                }
            }
        }