private void MainForm_Load(object sender, EventArgs e)
        {
            tboxLocation.Text = "C:\\Users\\" + Environment.UserName + "\\Desktop\\GrainBound";

            WebRequest.DefaultWebProxy = null;
            webClient       = new WebClient();
            webClient.Proxy = null;
            webClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(DownloadCompleted);
            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);

            string installLoc = GBRegistry.checkRegistryKey(GBRegistry.GRAINBOUND_INSTALL_KEY);

            if (installLoc != null)
            {
                if (Directory.Exists(installLoc))
                {
                    this.Hide();
                    (new UninstallForm()).ShowDialog();
                }
                else
                {
                    GBRegistry.removeRegistryKey();
                }
            }
        }
Exemple #2
0
        private void btnUninstall_Click(object sender, EventArgs e)
        {
            bool   backedUpProjects = false;
            string newPath          = "";

            if (MessageBox.Show("This operation will permanently remove GrainBound from your computer. Are you sure you wish to proceed?", "Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                string[] files = Directory.GetFiles(tboxLocation.Text, "*.grainbound", SearchOption.AllDirectories);
                if (files.Length > 0)
                {
                    DialogResult result = MessageBox.Show("GrainBound files have been detected inside the install folder. Do you want to save these files before uninstalling?\n\nYes = GrainBound projects will be moved to a different folder, then the program will be uninstalled.\nNo = Delete all files, including GrainBound projects.\nCancel = Stop uninstallation process.", "GrainBound Saved Projects Detected", MessageBoxButtons.YesNoCancel);
                    if (result == DialogResult.Yes)
                    {
                        newPath = tboxLocation.Text.Substring(0, tboxLocation.Text.LastIndexOf("\\")) + "\\GrainBound Projects";
                        try
                        {
                            Directory.CreateDirectory(newPath);
                            for (int i = 0; i < files.Length; i++)
                            {
                                File.Move(files[i], newPath + files[i].Substring(files[i].LastIndexOf("\\")));
                            }
                            backedUpProjects = true;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("An error occurred while moving GrainBound projects: " + ex.Message + "\n\nThe uninstall process has been cancelled.", "Error");
                        }
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        return;
                    }
                }

                btnUninstall.Text    = "Uninstalling...";
                btnUninstall.Enabled = false;
                Directory.Delete(tboxLocation.Text, true);
                if (File.Exists("C:\\Users\\" + Environment.UserName + "\\Desktop\\GrainBound.lnk"))
                {
                    File.Delete("C:\\Users\\" + Environment.UserName + "\\Desktop\\GrainBound.lnk");
                }
                try
                {
                    File.Delete("C:\\Windows\\System32\\pythoncom37.dll");
                    File.Delete("C:\\Windows\\System32\\pywintypes37.dll");
                }
                catch { }
                GBRegistry.removeRegistryKey();
                MessageBox.Show("GrainBound uninstalled successfully." + (backedUpProjects ? (" Existing projects have been moved to " + newPath) : ""), "Success");
                this.Close();
            }
        }