Exemplo n.º 1
0
        private void clean_Load(object sender, EventArgs e)
        {
            string sysPath = Environment.GetFolderPath(Environment.SpecialFolder.System);

            sysDrive   = Path.GetPathRoot(sysPath);
            SubutaiDir = AP.get_env_var("Subutai");
            logger.Info("Uninstalling: date = {0}", $"{ DateTime.Now.ToString("yyyyMMddhhmm")}");
            if (toLog)
            {
                logger.Info("Starting to uninstall Subutai with parameters: sysDrive: {0}; SubutaiDir: {1}; isSilent: {2}; removeAll: {3}", sysDrive, SubutaiDir, isSilent, removeAll);
                MessageBox.Show($"sysDrive: {sysDrive}; SubutaiDir: {SubutaiDir}; isSilent: {isSilent}; removeAll: {removeAll}; toLog: {toLog}", "OnLoad", MessageBoxButtons.OK);
            }
            if (isSilent)
            {
                runCleaning();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes Subutai from Path environment variable
        /// </summary>
        /// <param name="str2delete">The str2delete.</param>
        /// <returns></returns>
        public static string remove_from_Path(string str2delete)
        {
            //logger.Info("Remove env");

            string strPath = AP.get_env_var("Path");

            //if (str2delete == "Subutai")
            //{
            //    str2delete = AP.get_env_var("Subutai");
            //}

            if (strPath == null || strPath == "")
            {
                return("Path Empty");
            }

            if (str2delete == null || str2delete == "")
            {
                return($"{str2delete} Empty");
            }

            string[]      strP  = strPath.Split(';');
            List <string> lPath = new List <string>();

            foreach (string sP in strP)
            {
                if (!lPath.Contains(sP) && !sP.Contains(str2delete))
                {
                    lPath.Add(sP);
                }
            }

            string[] slPath  = lPath.ToArray();
            string   newPath = string.Join(";", slPath);

            newPath = newPath.Replace(";;", ";");

            Environment.SetEnvironmentVariable("Path", newPath, EnvironmentVariableTarget.Machine);
            Environment.SetEnvironmentVariable("Path", newPath, EnvironmentVariableTarget.Process);

            return(newPath);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes the Oracle VirtualBox application.
        /// Problematic for now
        /// </summary>
        /// <param name="app_name">Name of the application.</param>
        public static void remove_app_vbox(string app_name)
        {
            string mesg = string.Format("Remove {0}? \n\nPlease do not try to remove {1} if uninstalling from Control Panel. \n\nNote: it is better to remove {2} separately.", app_name, app_name, app_name);
            //DialogResult drs = MessageBox.Show($"Remove {app_name}? Please, do not remove if uninstalling from Control Panel. Uninstall {app_name} separately."  , $"Removing {app_name}",
            DialogResult drs = MessageBox.Show(mesg, $"Removing {app_name}",
                                               MessageBoxButtons.YesNo,
                                               MessageBoxIcon.Question,
                                               MessageBoxDefaultButton.Button1);

            if (drs == DialogResult.No)
            {
                return;
            }
            string res = "";

            //VirtualBox Manager, VirtualBox Interface
            //Stop VMs

            //Remove all host-only interfaces
            remove_host_only();
            //Stop Processes/Services
            clean.StageReporter("", "Stopping VirtualBox processes");
            Process[] vboxProcesses = Process.GetProcesses();
            foreach (Process process in vboxProcesses)
            {
                if (process.ProcessName.Contains("VBox") || process.ProcessName.Contains("VirtualBox"))
                {
                    MessageBox.Show($"Process: {process.ProcessName}", "Removing processes", MessageBoxButtons.OK);
                    try
                    {
                        process.Kill();
                        Thread.Sleep(2000);
                    }
                    catch (Exception e)
                    {
                        string tmp = e.Message;
                    }
                }
            }

            //Stopping services

            //Remove drivers C:\Windows\System32\drivers
            //C:\Windows\System32\drivers\VBoxDrv.sys, VBoxNetAdp6.sys, VBoxNetLwf.sys, VBoxUSBMon.sys

            clean.StageReporter("", "Removing VirtualBox drivers ");

            string dirStart = Path.Combine(clean.sysDrive, "Windows", "System32", "drivers");

            string[] vbDrv = { "VBoxDrv.sys", "VBoxNetAdp6.sys", "VBoxNetLwf.sys", "VBoxUSBMon.sys" };
            foreach (string drvName in vbDrv)
            {
                res = SCP.LaunchCommandLineApp("sc", $"stop {drvName.Replace(".sys","")}",
                                               true, false, 420000);

                string drvPath = Path.Combine(dirStart, drvName);

                bool b_res = FD.del_sysfile(drvPath);
            }

            clean.StageReporter("", "Removing VirtualBox directory");
            dirStart = AP.get_env_var("VBOX_MSI_INSTALL_PATH");
            if (dirStart == null || dirStart == "")
            {
                dirStart = Path.Combine(clean.sysDrive, "Program Files", "Oracle", "VirtualBox");
            }

            //MessageBox.Show($"Dir: {dirStart}", "Removing Oracle Dir", MessageBoxButtons.OK);
            if (Directory.Exists(dirStart))
            {
                Directory.Delete(dirStart, true);
            }

            //Clear Registry: VBoxDrv, VBoxNetAdp, VBoxUSBMon
            vb_clean_reg();

            //Remove Env VBOX_MSI_INSTALL_PATH
            Environment.SetEnvironmentVariable("VBOX_MSI_INSTALL_PATH", "", EnvironmentVariableTarget.Machine);
            Environment.SetEnvironmentVariable("VBOX_MSI_INSTALL_PATH", "", EnvironmentVariableTarget.User);
            Environment.SetEnvironmentVariable("VBOX_MSI_INSTALL_PATH", "", EnvironmentVariableTarget.Process);
            clean.StageReporter("", "Removing shortcuts");
            //Remove shortcuts
            var shcutPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
            //    Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            //delete_Shortcut(shcutPath, appName);
            string appName = "Oracle VM VirtualBox";

            FD.delete_Shortcut(shcutPath, appName, false);
            shcutPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);

            var shcutStartPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);

            //Folder files
            shcutPath = Path.Combine(shcutStartPath, "Programs");
            //Uninstall.lnk
            FD.delete_Shortcut(shcutPath, appName, false);
            //Remove folder
            FD.delete_Shortcut(shcutPath, appName, true);
            clean.StageReporter("", "Removing from %Path%");
            FD.remove_from_Path(dirStart);
            mesg = string.Format("Oracle VirtualBox removed from Your machine. \n\n Please do not forget to RESTART windows before new installation!");
            MessageBox.Show(mesg, "Removing Oracle VirtualBox", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Task factory actually perfoeming cleaning
        /// </summary>
        private void runCleaning()
        {
            string mess = "";

            SetIndeterminate(false);
            UpdateProgress(0);
            logger.Info("sysDrive: {0}; SubutaiDir: {1}; isSilent: {2}; removeAll: {3}", sysDrive, SubutaiDir, isSilent, removeAll);
            Task.Factory.StartNew(() =>
            {
                StageReporter("", "Starting uninstall");
                if (toLog)
                {
                    logger.Info("sysDrive: {0}; SubutaiDir: {1}; isSilent: {2}; removeAll: {3}", sysDrive, SubutaiDir, isSilent, removeAll);
                    logger.Info("Will delete: TAP software: {0}; Chrome: {1}; VBox: {2}; Subutai Directory: {3}", bTAP, bChrome, bVBox, bFolder);
                    mess = string.Format("Will delete: TAP software: {0}; Chrome: {1}; VBox: {2}; Subutai Directory: {3}", bTAP, bChrome, bVBox, bFolder);
                    MessageBox.Show(mess, "Start", MessageBoxButtons.OK);
                    mess = "";
                }
                SetIndeterminate(true);
            })

            .ContinueWith((prevTask) =>
            {
                Exception ex = prevTask.Exception;
                if (prevTask.IsFaulted)
                {
                    while (ex is AggregateException && ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        if (toLog)
                        {
                            logger.Info("Exception on start: {0}", ex.Message);
                        }
                        MessageBox.Show(ex.Message, "Start", MessageBoxButtons.OK);
                    }
                }
                StageReporter("", "Removing firewall rules");
                if (toLog)
                {
                    logger.Info("Removing firewall rules");
                    MessageBox.Show("Removing firewall rules", "Removing", MessageBoxButtons.OK);
                }
                SetIndeterminate(true);
                SCP.remove_fw_rules(SubutaiDir);
                //UpdateProgress(10);
            }, TaskContinuationOptions.OnlyOnRanToCompletion)

            .ContinueWith((prevTask) =>
            {
                Exception ex = prevTask.Exception;
                if (prevTask.IsFaulted)
                {
                    while (ex is AggregateException && ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        if (toLog)
                        {
                            logger.Info("Exception on Firewall rules: {0}", ex.Message);
                        }
                        MessageBox.Show(ex.Message, "Firewall rules", MessageBoxButtons.OK);
                    }
                }
                StageReporter("", "Removing Subutai Social P2P service");
                if (toLog)
                {
                    logger.Info("Removing Subutai Social P2P service");
                    MessageBox.Show("Removing Subutai Social P2P service", "Removing", MessageBoxButtons.OK);
                }
                mess = SCP.stop_process("p2p");
                mess = "";
                mess = SCP.stop_service("Subutai Social P2P", 5000);
                mess = "";
                mess = SCP.remove_service("Subutai Social P2P");
                //UpdateProgress(20);
                StageReporter("", "Stopping SubutaiTray processes");
                if (toLog)
                {
                    logger.Info("Stopping SubutaiTray processes");
                    MessageBox.Show("Stopping SubutaiTray processes", "Removing", MessageBoxButtons.OK);
                }
                mess = SCP.stop_process("SubutaiTray");
                //UpdateProgress(30);
            }, TaskContinuationOptions.OnlyOnRanToCompletion)

            .ContinueWith((prevTask) =>
            {
                Exception ex = prevTask.Exception;
                if (prevTask.IsFaulted)
                {
                    while (ex is AggregateException && ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        if (toLog)
                        {
                            logger.Info("Exception on Removing Subutai Social P2P service and tray: {0}", ex.Message);
                        }
                        MessageBox.Show(ex.Message, "Subutai P2P service and SubutaiTray", MessageBoxButtons.OK);
                    }
                }
                StageReporter("", "Removing /home directory link");
                if (toLog)
                {
                    logger.Info("Removing //home directory link");
                    MessageBox.Show("Removing //home directory link", "Removing", MessageBoxButtons.OK);
                }
                //Remove /home shortcut
                if (SubutaiDir != "")
                {
                    mess = FD.remove_from_home(SubutaiDir);
                    mess = FD.remove_home(SubutaiDir);
                }
                //Remove Subutai dirs from Path
                //UpdateProgress(55);

                StageReporter("", "Removing Subutai dirs from %Path%");
                if (toLog)
                {
                    logger.Info("Removing Subutai dirs from %Path%");
                    MessageBox.Show("Removing Subutai dirs from %Path%", "Removing", MessageBoxButtons.OK);
                }
                //Remove Subutai dirs from Path
                mess = FD.remove_from_Path("Subutai");
                //Remove %Subutai%
                Environment.SetEnvironmentVariable("Subutai", "", EnvironmentVariableTarget.Machine);
                Environment.SetEnvironmentVariable("Subutai", "", EnvironmentVariableTarget.User);
                Environment.SetEnvironmentVariable("Subutai", "", EnvironmentVariableTarget.Process);
                //UpdateProgress(60);
            }, TaskContinuationOptions.OnlyOnRanToCompletion)

            .ContinueWith((prevTask) =>
            {
                Exception ex = prevTask.Exception;
                if (prevTask.IsFaulted)
                {
                    while (ex is AggregateException && ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        if (toLog)
                        {
                            logger.Info("Exception on Removing link, Subutai dirs from %Path% and envs: {0}", ex.Message);
                        }
                        MessageBox.Show(ex.Message, "Subutai dirs", MessageBoxButtons.OK);
                    }
                }
                StageReporter("", "Cleaning Registry");
                if (toLog)
                {
                    logger.Info("Cleaning Registry");
                    MessageBox.Show("Cleaning Registry", "Removing", MessageBoxButtons.OK);
                }
                //Clean registry
                RG.delete_from_reg();
                //UpdateProgress(70);
            }, TaskContinuationOptions.OnlyOnRanToCompletion)

            .ContinueWith((prevTask) =>
            {
                Exception ex = prevTask.Exception;
                if (prevTask.IsFaulted)
                {
                    while (ex is AggregateException && ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        if (toLog)
                        {
                            logger.Info("Exception on Cleaning Registry: {0}", ex.Message);
                        }
                        MessageBox.Show(ex.Message, "Cleaning Registry", MessageBoxButtons.OK);
                    }
                }
                StageReporter("", "Removing TAP interfaces");
                if (toLog)
                {
                    logger.Info("Removing TAP interfaces");
                    MessageBox.Show("Removing TAP interfaces", "Removing", MessageBoxButtons.OK);
                }
                AP.del_TAP();
                //UpdateProgress(80);
            }, TaskContinuationOptions.OnlyOnRanToCompletion)

            .ContinueWith((prevTask) =>
            {
                Exception ex = prevTask.Exception;
                if (prevTask.IsFaulted)
                {
                    while (ex is AggregateException && ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        if (toLog)
                        {
                            logger.Info("Exception on Removing TAP interfaces: {0}", ex.Message);
                        }
                        MessageBox.Show(ex.Message, "Removing TAP interfaces", MessageBoxButtons.OK);
                    }
                }
                StageReporter("", "Removing old logs");
                if (toLog)
                {
                    logger.Info("Removing old logs");
                    MessageBox.Show("Removing old logs", "Removing", MessageBoxButtons.OK);
                }
                //Remove log dir
                FD.remove_log_dir();
            }, TaskContinuationOptions.OnlyOnRanToCompletion)

            .ContinueWith((prevTask) =>
            {
                Exception ex = prevTask.Exception;
                if (prevTask.IsFaulted)
                {
                    while (ex is AggregateException && ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        if (toLog)
                        {
                            logger.Info("Exception on Removing old logs: {0}", ex.Message);
                        }
                        MessageBox.Show(ex.Message, "Removing old logs", MessageBoxButtons.OK);
                    }
                }
                StageReporter("", "Removing Subutai Virtual Machines");
                if (toLog)
                {
                    logger.Info("Removing Subutai Virtual Machines");
                    MessageBox.Show("Removing Subutai Virtual Machines", "Removing", MessageBoxButtons.OK);
                }
                //Remove snappy and subutai machines
                VBx.remove_vm();
                //Remove Oracle VirtualBox
                StageReporter("", "Removing Oracle Virtual Box software");
                if (toLog)
                {
                    logger.Info("Removing Subutai Virtual  Box software");
                    MessageBox.Show("Removing Subutai Virtual  Box software", "Removing", MessageBoxButtons.OK);
                }
                if (!isSilent && bVBox)
                {
                    if (toLog)
                    {
                        logger.Info("Removing Subutai Virtual Box software - yes");
                        MessageBox.Show("Removing Subutai Virtual Box software - yes", "Removing", MessageBoxButtons.OK);
                    }
                    VBx.remove_app_vbox_short("Oracle VirtualBox");
                }
            }, TaskContinuationOptions.OnlyOnRanToCompletion)

            .ContinueWith((prevTask) =>
            {
                Exception ex = prevTask.Exception;
                if (prevTask.IsFaulted)
                {
                    while (ex is AggregateException && ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        if (toLog)
                        {
                            logger.Info("Exception on Removing virtual machines: {0}", ex.Message);
                        }
                        MessageBox.Show(ex.Message, "VirtualBox", MessageBoxButtons.OK);
                    }
                }
                StageReporter("", "Removing Google Chrome");
                if (toLog)
                {
                    logger.Info("Removing Google Chrome");
                    MessageBox.Show("Removing Google Chrome", "Removing", MessageBoxButtons.OK);
                }
                if (!isSilent && bChrome)
                {
                    if (toLog)
                    {
                        logger.Info("Removing Google Chrome - yes");
                        MessageBox.Show("Removing Google Chrome - yes", "Removing", MessageBoxButtons.OK);
                    }
                    AP.remove_chrome();
                }
            }, TaskContinuationOptions.OnlyOnRanToCompletion)



            .ContinueWith((prevTask) =>
            {
                Exception ex = prevTask.Exception;
                if (prevTask.IsFaulted)
                {
                    while (ex is AggregateException && ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        if (toLog)
                        {
                            logger.Info("Exception on Removing Google Chrome:{0}", ex.Message);
                        }
                        MessageBox.Show(ex.Message, "Chrome", MessageBoxButtons.OK);
                    }
                }
                //Remove service if was installed during cancelling
                if (toLog)
                {
                    logger.Info("Removing Subutai P2P service if was installed after uninstall started");
                    MessageBox.Show("Removing Subutai P2P service if was installed after uninstall started", "Removing", MessageBoxButtons.OK);
                }
                mess = SCP.stop_process("p2p");
                mess = "";
                mess = SCP.stop_service("Subutai Social P2P", 5000);
                mess = "";
                mess = SCP.remove_service("Subutai Social P2P");
            }, TaskContinuationOptions.OnlyOnRanToCompletion)

            .ContinueWith((prevTask) =>
            {
                Exception ex = prevTask.Exception;
                if (prevTask.IsFaulted)
                {
                    while (ex is AggregateException && ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        if (toLog)
                        {
                            logger.Info("Exception on Removing Subutai P2P Service: {0}", ex.Message);
                        }
                        MessageBox.Show(ex.Message, "Subutai P2P Service", MessageBoxButtons.OK);
                    }
                }
                StageReporter("", "Removing Subutai shortcuts");
                if (toLog)
                {
                    logger.Info("Removing Subutai shortcuts");
                    MessageBox.Show("Removing Subutai shortcuts", "Removing", MessageBoxButtons.OK);
                }
                FD.delete_Shortcuts("Subutai");
                //UpdateProgress(80);
                StageReporter("", "Removing Subutai directories");
                if (toLog)
                {
                    logger.Info("Removing Subutai directories");
                    MessageBox.Show("Removing Subutai directories", "Removing", MessageBoxButtons.OK);
                }
                mess        = "";
                string mesg = "";
                if (SubutaiDir != "" && SubutaiDir != null && SubutaiDir != "C:\\" && SubutaiDir != "D:\\" && SubutaiDir != "E:\\" && !(SubutaiDir.Length < 4))
                {
                    if (!isSilent)
                    {
                        if (bFolder)
                        {
                            if (toLog)
                            {
                                logger.Info("Not silent, Removing Subutai directories completely");
                                MessageBox.Show("Not silent, Removing Subutai directories completely", "Removing", MessageBoxButtons.OK);
                            }
                            //checked, need to remove
                            mess = FD.delete_dir(SubutaiDir);
                        }
                        else
                        {
                            if (toLog)
                            {
                                logger.Info("Not silent, Removing Subutai bin directory");
                                MessageBox.Show("Not silent, Removing Subutai bin directory", "Removing", MessageBoxButtons.OK);
                            }

                            mess = FD.delete_dir_bin(SubutaiDir);
                        }
                    }
                    else     //silent
                    {
                        if (removeAll)
                        {
                            if (toLog)
                            {
                                logger.Info("Silent, Removing Subutai directories completely");
                                MessageBox.Show("Silent, Removing Subutai directories completely", "Removing", MessageBoxButtons.OK);
                            }
                            mess = FD.delete_dir(SubutaiDir);
                        }
                        else
                        {
                            if (toLog)
                            {
                                logger.Info("Silent, Removing Subutai bin directory");
                                MessageBox.Show("Silent, Removing Subutai bin directory", "Removing", MessageBoxButtons.OK);
                            }
                            mess = FD.delete_dir_bin(SubutaiDir);
                        }
                    }

                    if (mess.Contains("Can not"))
                    {
                        mesg = string.Format("Folder {0}\\bin can not be removed.\n\n Please close running applications that can lock files (ssh sessions, file manager windows, stop p2p service if running etc) and delete it manually", SubutaiDir);
                        if (toLog)
                        {
                            logger.Info("Failed to remove Subutai directory");
                            MessageBox.Show("Failed to remove Subutai directory", "Removing", MessageBoxButtons.OK);
                        }
                        MessageBox.Show(mesg, "Removing Subutai folder", MessageBoxButtons.OK);
                    }
                }

                //Remove Subutai dir from ApplicationData
                string appUserDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                //MessageBox.Show($"AppData: {appUserDir}", "AppData", MessageBoxButtons.OK);
                appUserDir = Path.Combine(appUserDir, "Subutai Social");
                if (Directory.Exists(appUserDir))
                {
                    try
                    {
                        Directory.Delete(appUserDir, true);
                    }
                    catch (Exception exx)
                    {
                        mesg = exx.Message;
                    }
                }
                SetIndeterminate(false);
                UpdateProgress(100);
                StageReporter("", "Finished");
                string mes  = "Subutai Social uninstalled. \n";
                string mes1 = "\nPlease delete ";
                string mes2 = "";
                string mes3 = " software manually from Control Panel if You are not going to use it";
                if (AP.app_installed("Clients\\StartMenuInternet\\Google Chrome") == 1)
                {
                    mes1 += "Google Chrome ";
                    mes  += $"{mes1}{mes2}";
                }
                if (AP.app_installed("Oracle\\VirtualBox") == 1)
                {
                    if (mes.Contains("Chrome"))
                    {
                        mes += " and Oracle VirtualBox ";
                    }
                    else
                    {
                        mes += "\nPlease delete Oracle VirtualBox ";
                    }
                }

                if (mes.Contains("Chrome") || mes.Contains("VirtualBox"))
                {
                    mes += mes3;
                }
                mesg = string.Format($"{mes}");
                if (toLog)
                {
                    logger.Info("Subutai Social uninstalled");
                }
                MessageBox.Show(mesg, "Uninstall Subutai Social", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Environment.Exit(0);
            });
        }