Example #1
0
        void update(object sender, DoWorkEventArgs e)
        {
            init();

            try
            {
#if Public
                ReleaseStream stream = ReleaseStream.Stable40;
#else
                ReleaseStream stream = ReleaseStream.CuttingEdge;
#endif

                bool          hasFramework = File.Exists(@"OpenTK.dll");
                List <string> files        = new List <string>(Directory.GetFiles(Environment.CurrentDirectory));

                bool useCurrentDirectory = File.Exists(@"osu!.cfg") || files.Count == 1;

                if (!hasFramework)
                {
retry_with_default:
                    if (!useCurrentDirectory)
                    {
                        installPath  = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!");
                        label.Click += chooseFolder;

                        int seconds = 10;
                        while (seconds > 0)
                        {
                            setText(string.Format(LocalisationManager.GetString(OsuString.Maintenance_InstallationPath) + '\n' +
                                                  LocalisationManager.GetString(OsuString.Maintenance_InstallationPath2),
                                                  installPath, seconds), true);
                            Thread.Sleep(1000);
                            seconds--;

                            while (installPath == null)
                            {
                                Thread.Sleep(100);
                            }
                        }

                        label.Click -= chooseFolder;
                    }

retry:
                    if (installPath != Environment.CurrentDirectory)
                    {
                        string installExecutable = Path.Combine(installPath, @"osu!.exe");

                        try
                        {
                            if (!Directory.Exists(installPath))
                            {
                                Directory.CreateDirectory(installPath);
                            }

                            try
                            {
                                File.Delete(installExecutable);
                            }
                            catch (IOException)
                            {
                                //ignore IOExceptions for now
                            }

                            byte[] executable = File.ReadAllBytes(OsuMain.FullPath);
                            using (FileStream fs = File.Create(installExecutable))
                                fs.Write(executable, 0, executable.Length);
                        }
                        catch (UnauthorizedAccessException)
                        {
                            if (!OsuMain.IsElevated)
                            {
                                if (OsuMain.Elevate(@"-allowuserwrites " + installPath, true))
                                {
                                    goto retry;
                                }
                                else
                                {
                                    //error occurred while elevating. try again using the default path.
                                    goto retry_with_default;
                                }
                            }
                        }

                        Process.Start(installExecutable);
                        OsuMain.ExitImmediately();
                    }
                }

                try
                {
                    if (hasFramework)
                    {
                        stream = ConfigManager.sReleaseStream.Value;
                    }
                }
                catch (Exception ex)
                {
                    OsuMain.Repair(true, ex);
                }

                setText(string.Empty);

tryAgain:
                setProgress();

                if (hasFramework) //force a complete check.
                {
                    ConfigManager.ResetHashes();
                }

                CommonUpdater.Check(delegate(UpdateStates s) { }, stream);

                while (true)
                {
                    switch (CommonUpdater.State)
                    {
                    case UpdateStates.Checking:
                        setText(CommonUpdater.GetStatusString(), detailedTextImportant);
                        setProgress();
                        Thread.Sleep(20);
                        continue;

                    case UpdateStates.Updating:
                        setText(CommonUpdater.GetStatusString());
                        setProgress(CommonUpdater.Percentage);
                        Thread.Sleep(20);
                        continue;

                    case UpdateStates.Completed:
                    case UpdateStates.NeedsRestart:
                        setText(LocalisationManager.GetString(OsuString.CommonUpdater_Updated));
                        break;

                    case UpdateStates.NoUpdate:
                        setText(LocalisationManager.GetString(OsuString.CommonUpdater_Updated), true);
                        Thread.Sleep(1000);
                        break;

                    case UpdateStates.Error:
                        CommonUpdater.Reset();

                        setProgress();
                        setText(LocalisationManager.GetString(OsuString.Maintenance_ErrorOccurred), true);
                        Thread.Sleep(5000);

                        goto tryAgain;

                    default:
                        break;
                    }

                    break;
                }

                if (!OsuMain.IsWine && !hasFramework)
                {
                    //create desktop/start menu shortcuts only once per install
                    ShellLinkHelper.Create(icon_path_desktop, Path.Combine(Environment.CurrentDirectory, @"osu!.exe"), @"osu!");
                    ShellLinkHelper.Create(icon_path_startmenu, Path.Combine(Environment.CurrentDirectory, @"osu!.exe"), @"osu!");
                }

                instance.Dispose();

                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(@"Error occured (please report this!):\n\n" + ex.ToString());
            }
        }
Example #2
0
        void uninstall(object sender, DoWorkEventArgs e)
        {
            if (!OsuMain.IsElevated)
            {
                OsuMain.Elevate(@"-uninstall", false);
                return;
            }

            try
            {
                init();
                setProgress(0, OsuString.Maintenance_Bye);

                int seconds = 10;
                while (seconds > 0)
                {
                    setText(string.Format(LocalisationManager.GetString(OsuString.Maintenance_Uninstall) + '\n' +
                                          LocalisationManager.GetString(OsuString.Maintenance_Uninstall2), seconds), true);
                    Thread.Sleep(1000);
                    seconds--;

                    while (installPath == null)
                    {
                        Thread.Sleep(100);
                    }
                }

                setText(LocalisationManager.GetString(OsuString.Maintenance_Uninstalling), true);

                string[] directories = Directory.GetDirectories(Environment.CurrentDirectory);

                int totalProgressItems = directories.Length + 8;
                int currentProgress    = 0;

                //delete subdirectories
                foreach (string dir in directories)
                {
                    setProgress((int)(((float)++currentProgress / totalProgressItems) * 100));
                    try
                    {
                        Directory.Delete(dir, true);
                    }
                    catch
                    {
                    }

                    Thread.Sleep(100);
                }

                //delete main directory
                try
                {
                    setProgress((int)(((float)++currentProgress / totalProgressItems) * 100));
                    Directory.Delete(Environment.CurrentDirectory, true);
                }
                catch
                {
                }

                try
                {
                    setProgress((int)(((float)++currentProgress / totalProgressItems) * 100));
                    foreach (string file in Directory.GetFiles(Environment.CurrentDirectory))
                    {
                        GeneralHelper.FileDeleteOnReboot(file);
                    }
                }
                catch
                {
                }

                try
                {
                    setProgress((int)(((float)++currentProgress / totalProgressItems) * 100));
                    Directory.Delete(Environment.CurrentDirectory);
                }
                catch
                {
                }

                try
                {
                    setProgress((int)(((float)++currentProgress / totalProgressItems) * 100));
                    GeneralHelper.FileDeleteOnReboot(Environment.CurrentDirectory);
                }
                catch
                {
                }

                try
                {
                    setProgress((int)(((float)++currentProgress / totalProgressItems) * 100));
                    Uninstaller.RemoveUninstaller();
                }
                catch
                {
                }

                try
                {
                    setProgress((int)(((float)++currentProgress / totalProgressItems) * 100));
                    File.Delete(icon_path_desktop);
                    File.Delete(icon_path_startmenu);
                }
                catch
                {
                }

                try
                {
                    setProgress((int)(((float)++currentProgress / totalProgressItems) * 100));
                    GeneralHelper.RegistryDelete(@"osu!");
                    GeneralHelper.RegistryDelete(@"osu");
                }
                catch
                {
                }

                setProgress(100);
                setText(LocalisationManager.GetString(OsuString.Maintenance_Farewell), true);
                Thread.Sleep(5000);
            }
            catch { }
        }