Example #1
0
        public override string Run(string exepath, string version)
        {
            using (RegistryKey key = Win32RegHelper.OpenOrCreateKey(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\Olympus", true)) {
                if (key == null)
                {
                    return(null);
                }

                key.SetValue("DisplayName", "Olympus");
                key.SetValue("Publisher", "Everest Team");
                key.SetValue("HelpLink", "https://everestapi.github.io/");
                key.SetValue("DisplayIcon", $"{exepath},0");
                key.SetValue("DisplayVersion", version);
                DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(exepath));
                key.SetValue("InstallLocation", dir);
                key.SetValue("InstallDate", dir.CreationTime.ToString("yyyyMMdd"));
                key.SetValue("EstimatedSize", (int)(GetDirectorySize(dir) / 1024));
                key.SetValue("UninstallString", $"\"{Program.SelfPath}\" --uninstall");
                key.SetValue("QuietUninstallString", $"\"{Program.SelfPath}\" --uninstall --quiet");
                key.SetValue("NoModify", 1);
                key.SetValue("NoRepair", 1);

                return(null);
            }
        }
Example #2
0
        public override object Run(string key)
        {
            int indexOfSlash = key.LastIndexOf('\\');

            if (indexOfSlash == -1)
            {
                return(null);
            }

            try {
                return(Win32RegHelper.OpenOrCreateKey(key.Substring(0, indexOfSlash), false)?.GetValue(key.Substring(indexOfSlash + 1)));
            } catch (Exception e) {
                Console.Error.WriteLine($"Cannot get registry value: {key}");
                Console.Error.WriteLine(e);
                return(null);
            }
        }
Example #3
0
        public override bool Run(string key, object value)
        {
            int indexOfSlash = key.LastIndexOf('\\');

            if (indexOfSlash == -1)
            {
                return(false);
            }

            try {
                using (RegistryKey regkey = Win32RegHelper.OpenOrCreateKey(key.Substring(0, indexOfSlash), true))
                    regkey.SetValue(key.Substring(indexOfSlash + 1), value);
            } catch (Exception e) {
                Console.Error.WriteLine($"Cannot set registry value: {key} = {value}");
                Console.Error.WriteLine(e);
            }
            return(true);
        }
Example #4
0
        public override string Run(bool quiet)
        {
            if (!quiet)
            {
                try {
                    Application.EnableVisualStyles();
                } catch {
                }
            }

            string root = Environment.GetEnvironmentVariable("OLYMPUS_ROOT");

            if (string.IsNullOrEmpty(root))
            {
                root = Win32RegHelper.OpenOrCreateKey(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\Olympus", false)?.GetValue("InstallLocation") as string;
            }
            if (string.IsNullOrEmpty(root))
            {
                root = Path.GetDirectoryName(Path.GetDirectoryName(Program.SelfPath));
            }

            if (!File.Exists(Path.Combine(root, "main.exe")) ||
                !File.Exists(Path.Combine(root, "love.dll")) ||
                !Directory.Exists(Path.Combine(root, "sharp")))
            {
                if (!quiet)
                {
                    MessageBox.Show("The Olympus uninstaller has encountered an error:\nCan't verify the main folder.\n\nPlease delete %AppData%/Olympus manually.", "Olympus", MessageBoxButtons.OK);
                }
                return(null);
            }

            if (Program.SelfPath.StartsWith(root))
            {
                string tmpDir = Path.Combine(Path.GetTempPath(), "Olympus.Uninstall");
                string tmp    = Path.Combine(tmpDir, "Olympus.Sharp.exe");
                try {
                    if (!Directory.Exists(tmpDir))
                    {
                        Directory.CreateDirectory(tmpDir);
                    }
                    string tmpDep = Path.Combine(tmpDir, "MonoMod.Utils.dll");
                    if (File.Exists(tmpDep))
                    {
                        File.Delete(tmpDep);
                    }
                    File.Copy(Path.Combine(Path.GetDirectoryName(Program.SelfPath), "MonoMod.Utils.dll"), tmpDep);
                    if (File.Exists(tmp))
                    {
                        File.Delete(tmp);
                    }
                    File.Copy(Program.SelfPath, tmp);
                } catch {
                    if (!quiet)
                    {
                        MessageBox.Show("The Olympus uninstaller has encountered an error:\nCan't copy the uninstaller into %TMP%.\n\nPlease delete %AppData%/Olympus manually.", "Olympus", MessageBoxButtons.OK);
                    }
                    return(null);
                }

                Environment.SetEnvironmentVariable("OLYMPUS_ROOT", root);

                Process process = new Process();
                process.StartInfo.FileName   = tmp;
                process.StartInfo.Arguments  = "--uninstall" + (quiet ? " --quiet" : "");
                Environment.CurrentDirectory = process.StartInfo.WorkingDirectory = tmpDir;
                process.Start();
                return(null);
            }

            if (!quiet && MessageBox.Show($"Do you want to uninstall Olympus from the following folder?\n{root}\n\nEverest and all your mods will stay installed.", "Olympus", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return(null);
            }

            try {
                Directory.Delete(root, true);
            } catch {
                if (!quiet)
                {
                    MessageBox.Show("The Olympus uninstaller has encountered an error:\nCan't delete the Olympus folder.\n\nPlease delete %AppData%/Olympus manually.", "Olympus", MessageBoxButtons.OK);
                }
                return(null);
            }

            try {
                using (RegistryKey key = Win32RegHelper.OpenOrCreateKey(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall", true))
                    key?.DeleteSubKeyTree("Olympus");
            } catch {
            }

            if (!quiet)
            {
                MessageBox.Show("Olympus was uninstalled successfully.", "Olympus", MessageBoxButtons.OK);
            }

            return(null);
        }