/// <summary>
        /// Extracts the installers.
        /// </summary>
        private void ExtractInstallers( )
        {
            this.LogDebug("Extracting installer");

            using (Stream strm = this.GetType( ).Assembly.GetManifestResourceStream("DroidExplorer.Bootstrapper.Installs.Setup.msi")) {
                if (strm != null)
                {
                    extractProgress.SetMaximum((int)strm.Length);
                    extractProgress.SetMinimum(0);
                    extractProgress.SetValue(0);
                    byte[] buffer = new byte[2048];
                    int    bread  = 0;
                    using (FileStream fs = new FileStream(Path.Combine(InstallersPath, "Setup.msi"), FileMode.Create, FileAccess.Write)) {
                        while ((bread = strm.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            fs.Write(buffer, 0, bread);
                            extractProgress.IncrementExt(bread);
                        }
                        fs.Close( );
                    }
                    strm.Close( );
                }
            }

            LaunchInstaller( );
            Wizard.Next( );
        }
        /// <summary>
        /// Extracts the installers.
        /// </summary>
        private void ExtractInstallers( )
        {
            this.LogDebug("Extracting installer");
            using (Stream strm = this.GetType( ).Assembly.GetManifestResourceStream("DroidExplorer.Bootstrapper.Installs.Setup.msi")) {
                if (strm != null)
                {
                    extractProgress.SetMaximum((int)strm.Length);
                    extractProgress.SetMinimum(0);
                    extractProgress.SetValue(0);
                    byte[] buffer = new byte[2048];
                    int    bread  = 0;
                    using (FileStream fs = new FileStream(Path.Combine(InstallersPath, "Setup.msi"), FileMode.Create, FileAccess.Write)) {
                        while ((bread = strm.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            fs.Write(buffer, 0, bread);
                            extractProgress.IncrementExt(bread);
                        }
                        fs.Close( );
                    }
                    strm.Close( );
                }
            }

            int result = LaunchInstaller( );

            switch (result)
            {
            case 0:
                Wizard.Next( );
                break;

            case 1602:
                this.LogWarning("Installer was canceled by the user");
                Wizard.PromptExit   = false;
                Wizard.PromptCancel = false;
                Wizard.Cancel( );
                break;

            default:
                Exception ex = new Exception(string.Format(CultureInfo.InvariantCulture, "Installer exited with code {0}.", result));
                this.LogFatal(ex.Message);
                Wizard.Error(ex);
                break;
            }
        }
예제 #3
0
        private void RunRemoval( )
        {
            this.progress.SetValue(0);
            this.progress.SetMinimum(0);
            status.SetText("Gathering removal information (adb processes)...");

            DirectoryInfo sdkPath = new DirectoryInfo(Wizard.GetSdkPath( ));

            Process[] procs = new Process[] { };

            try {
                procs = Process.GetProcessesByName("adb");
            } catch (Exception ex) {
                this.LogWarning(ex.Message, ex);
            }

            FileInfo[] files = new FileInfo[0];
            if (sdkPath.Exists && !Wizard.UseExistingSdk)
            {
                status.SetText("Gathering removal information (sdk files)...");
                files = sdkPath.GetFiles("*", SearchOption.AllDirectories);
            }

            this.progress.SetMaximum(files.Length + procs.Length + 3);

            this.LogDebug("Stopping service");
            status.SetText("Killing ADB Server...");
            try {
                Process proc = new Process( );
                proc.StartInfo = new ProcessStartInfo("adb.exe", "kill-server");
                proc.StartInfo.CreateNoWindow = true;
                proc.StartInfo.ErrorDialog    = false;
                proc.Start( );
            } catch (Exception ex) {
                this.LogWarning(ex.Message, ex);
            }
            progress.IncrementExt(1);

            try {
                this.LogDebug("Stopping service");
                status.SetText("Stopping Service...");
                ServiceController controller = new ServiceController("DroidExplorerService");
                if (controller.Status != ServiceControllerStatus.Stopped && controller.Status != ServiceControllerStatus.StopPending)
                {
                    controller.Stop( );
                    controller.WaitForStatus(ServiceControllerStatus.Stopped);
                }
            } catch (InvalidOperationException ioe) {
                if (!ioe.Message.Contains("not found on computer"))
                {
                    // its ok if it doesnt exist, but lets log it.
                    this.LogWarning(ioe.Message, ioe);
                }
            } catch (Exception ex) {
                this.LogFatal(ex.Message, ex);
                Wizard.Error(ex);
            } finally {
                progress.IncrementExt(1);
            }

            status.SetText("Killing all ADB processes");
            this.LogDebug("Killing all running adb processes");
            foreach (Process proc in procs)
            {
                try {
                    proc.Kill( );
                    progress.IncrementExt(1);
                } catch (Exception ex) {
                    this.LogFatal(ex.Message, ex);
                    Wizard.Error(ex);
                }
            }

            // only delete if we are using a "local" sdk
            if (!Wizard.UseExistingSdk)
            {
                status.SetText("Deleting files...");
                this.LogDebug("Deleting all sdk files");
                foreach (FileInfo file in files)
                {
                    try {
                        DirectoryInfo dir = file.Directory;
                        status.SetText(string.Format(CultureInfo.InvariantCulture, "Deleting {0}...", file.FullName.Substring(sdkPath.FullName.Length)));
                        file.Delete( );
                        this.progress.IncrementExt(1);
                        if (dir.GetFiles("*").Length == 0)
                        {
                            dir.Delete( );
                        }
                    } catch (Exception ex) {
                    }
                }

                try {
                    if (sdkPath.Exists)
                    {
                        sdkPath.Delete(true);
                    }
                } catch (Exception ex) { }
            }

            try {
                this.LogDebug("Removing registry settings");
                status.SetText("Removing Registry Keys...");
                Registry.LocalMachine.DeleteSubKey(WizardForm.ROOT_REGISTRY_KEY);
            } catch {
            } finally {
                this.progress.IncrementExt(1);
            }
            Wizard.Next( );
        }