Пример #1
0
        private void buttonRepair_Click(object sender, EventArgs e)
        {
            try
            {
                ConfigManager.SaveConfig();
            }
            catch { }

            OsuMain.Repair();
        }
Пример #2
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());
            }
        }
Пример #3
0
 private void buttonRestart_Click(object sender, EventArgs e)
 {
     OsuMain.Repair();
     Close();
 }