internal static void CompleteUpdate(bool instant = false)
        {
            if (!instant && UpdateState != UpdateStates.NeedsRestart && UpdateState != UpdateStates.Error)
            {
                return;
            }

            switch (Mode)
            {
            default:
                //if we aren't in a mostly-idle mode, wait before completing the restart.
                Scheduler.AddDelayed(delegate { CompleteUpdate(); }, 1000);
                return;

            case OsuModes.Menu:
            case OsuModes.SelectPlay:
            case OsuModes.SelectEdit:
                break;
            }

            if (!instant)
            {
                NotificationManager.ShowMessageMassive(LocalisationManager.GetString(OsuString.Update_Restart), 120000);
            }

            GameBase.Scheduler.AddDelayed(delegate
            {
                if (UpdateState == UpdateStates.NeedsRestart || UpdateState == UpdateStates.Completed)
                {
                    Restart();
                }
                else
                {
                    //an error may have occurred; run the standard updater.
                    GameBase.ChangeMode(OsuModes.Update);
                }
            }, instant ? 0 : 6000);
        }
示例#2
0
        private static void Main()
        {
            string[] args = Environment.GetCommandLineArgs();

            if (args.Length > 1 && args[1] == "-setpermissions")
            {
                System.Security.Principal.SecurityIdentifier sid  = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
                System.Security.Principal.NTAccount          acct = sid.Translate(typeof(System.Security.Principal.NTAccount)) as System.Security.Principal.NTAccount;
                string strEveryoneAccount = acct.ToString();
                GeneralHelper.AddDirectorySecurity(".\\", strEveryoneAccount, FileSystemRights.FullControl, InheritanceFlags.None, PropagationFlags.NoPropagateInherit, AccessControlType.Allow);
                GeneralHelper.AddDirectorySecurity(".\\", strEveryoneAccount, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow);

                GeneralHelper.RemoveReadOnlyRecursive(".\\");

                return;
            }

            string name = Path.GetFileNameWithoutExtension(Application.ExecutablePath);

            bool moved = false;

#if DEBUG
            bool firstInstance = true;
#else
            bool firstInstance = Process.GetProcessesByName(name).Length < 2;
#endif

            string file = "";

            if (args.Length > 1)
            {
                for (int i = 1; i < args.Length; i++)
                {
                    file += args[i] + " ";
                }
                file = file.Trim();

                moved = true;
            }

            if (!firstInstance)
            {
                Thread.Sleep(1500);
                firstInstance = Process.GetProcessesByName(name).Length < 2;
                if (!firstInstance && !moved)
                {
                    if (DialogResult.OK == MessageBox.Show("osu! is already running!\nWould you like to force-kill the other copy?", name,
                                                           MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1))
                    {
                        KillStuckProcesses(name);
                        int count = 0;
                        while (count++ < 20 && !firstInstance)
                        {
                            Thread.Sleep(100);
                            firstInstance = Process.GetProcessesByName(name).Length < 2;
                        }
                        if (!firstInstance)
                        {
                            MessageBox.Show("Killing failed.  Please manually kill the process using Task Manager.", name,
                                            MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }

            if (moved || firstInstance)
            {
                if (firstInstance)
                {
                    try
                    {
                        IPC.AcceptConnections();
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    try
                    {
                        TcpClient    c = new TcpClient("localhost", 13373);
                        StreamWriter w = new StreamWriter(c.GetStream());
                        w.WriteLine(file);

                        w.Flush();

                        c.Close();
                    }
                    catch (Exception)
                    {
                    }
                    return;
                }
            }


            Environment.CurrentDirectory = Application.StartupPath;

            using (GameBase game = new GameBase(file))
            {
                if (File.Exists("_osume.exe"))
                {
                    File.Delete("osume.exe");
                    File.Move("_osume.exe", "osume.exe");
                    GeneralHelper.ProcessStart("osume.exe");
                }
                else
#if !DEBUG
                { try
                  {
#endif
                    game.Run(); }
                if (Restart)
                {
                    GeneralHelper.ProcessStart("osu!.exe");
                }
#if !DEBUG
            }
示例#3
0
        /// <summary>
        /// This code is run in a separate method as it *requires* XNA framework.
        /// Anything before this point can be executed without XNA present (updater etc.)
        /// </summary>
        private static void runGame(string fileArgs, bool isTournamentManager, bool isDrawings)
        {
            if (fileArgs != null && fileArgs.StartsWith(@"-"))
            {
                fileArgs = null;
            }

#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += (s, e) => handleException(e.ExceptionObject as Exception, true);
            Application.ThreadException += (s, e) => handleException(e.Exception, false);
#endif

            GameBase.CheckForUpdates();

            try
            {
                if (isTournamentManager || isDrawings)
                {
                    GameBase.Tournament        = true;
                    GameBase.TournamentManager = true;
                    GameBase.QueuedMode        = OsuModes.Tourney;

                    allowSplashScreen = false;
                }

                if (TabletHandler.IsRunningInTabletMode)
                {
                    allowSplashScreen = false;
                }

                if (isDrawings)
                {
                    GameBase.TournamentDrawings = true;
                    GameBase.QueuedMode         = OsuModes.SelectDrawings;
                }

                showSplash();

                Started = true;

                using (Process currentProcess = Process.GetCurrentProcess())
                {
                    currentProcess.PriorityBoostEnabled = true;
                    currentProcess.PriorityClass        = ProcessPriorityClass.High;
                }

                using (TimePeriod p = new TimePeriod(1))
                    new GameBase(fileArgs).Run();
            }
            catch (MissingManifestResourceException e)
            {
                Repair(true, e);
            }
#if !DEBUG
            catch (UnauthorizedAccessException)
            {
                Restart = true;
            }
            catch (TypeInitializationException e)
            {
                Repair(true, e);
            }
            catch (Exception e)
            {
                if (e is BadImageFormatException && handleBadImageFormat(e as BadImageFormatException))
                {
                    return;
                }

                new ErrorDialog(e, true).ShowDialog();
            }
#endif
            BanchoClient.Exit();
        }
示例#4
0
        private void InitializeTester()
        {
            if (!PREDEFINED_TEST)
            {
                return;
            }

            if (BeatmapManager.Beatmaps.Count > 0)
            {
                if (USE_LAST_PLAYED_BEATMAP)
                {
                    List <Beatmap> temp = new List <Beatmap>(BeatmapManager.Beatmaps);
                    temp.Sort((a, b) => { return(a.DateLastPlayed.CompareTo(b.DateLastPlayed)); });
                    BeatmapManager.Current = temp[temp.Count - 1];
                }
                else //Choose a random beatmap
                {
                    BeatmapManager.Current = BeatmapManager.Beatmaps[RNG.Next(0, BeatmapManager.Beatmaps.Count)];
                }
            }

            if (MULTIPLAYER_MATCH)
            {
                if (BeatmapManager.Current == null)
                {
                    NotificationManager.ShowMessage("Couldn't start in specified test mode because no beatmaps were available.");
                    return;
                }

                BanchoClient.Start();

                Mode = OsuModes.MatchSetup;

                const int player_count = 8;

                while (!BanchoClient.Connected || !BanchoClient.InitializationComplete)
                {
                    Scheduler.Update();
                }

                PresenceCache.QueryAll();

                while (User.Id <= 0 || BanchoClient.Users.Count < player_count)
                {
                    Scheduler.Update();
                }

                List <User> users = BanchoClient.Users.FindAll(u => u.InitialLoadComplete && u.Id != User.Id);
                users.Insert(0, User); //we are the first user.

                MatchSetup.Match = new ClientSideMatch(new bMatch(MatchTypes.Standard,
                                                                  MatchScoringTypes.Score,
                                                                  MatchTeamTypes.TeamVs,
                                                                  PlayModes.Osu,
                                                                  @"My test game",
                                                                  string.Empty,
                                                                  player_count,
                                                                  BeatmapManager.Current.SortTitle,
                                                                  BeatmapManager.Current.BeatmapChecksum,
                                                                  BeatmapManager.Current.BeatmapId,
                                                                  MODS_TO_USE,
                                                                  2,
                                                                  MultiSpecialModes.FreeMod
                                                                  ));

                for (int i = 0; i < player_count; i++)
                {
                    MatchSetup.Match.slotId[i]    = users[i].Id;
                    MatchSetup.Match.UserSlots[i] = users[i];

                    MatchSetup.Match.slotStatus[i] = SlotStatus.Playing;
                    switch (MatchSetup.Match.matchTeamType)
                    {
                    case MatchTeamTypes.TagTeamVs:
                    case MatchTeamTypes.TeamVs:
                        MatchSetup.Match.slotTeam[i] = i % 2 == 0 ? SlotTeams.Blue : SlotTeams.Red;
                        break;
                    }
                }

                bScoreFrame[] frames = new bScoreFrame[player_count];
                for (int i = 0; i < player_count; i++)
                {
                    frames[i] = new bScoreFrame {
                        id = (byte)i, pass = true, currentHp = 200
                    }
                }
                ;

                RunBackgroundThread(delegate
                {
                    Thread.Sleep(5000);

                    for (int i = 0; i < player_count; i++)
                    {
                        PlayerVs.MatchPlayerSkipped(i);
                        Thread.Sleep(100);
                    }

                    Thread.Sleep(2000);

                    Player.QueueSkip();
                    Player.Instance?.DoSkip();

                    PlayerVs.AllPlayersLoaded    = true;
                    PlayerVs.AllPlayersCompleted = true;

                    while (true)
                    {
                        byte player = (byte)RNG.Next(0, player_count);

                        switch (RNG.Next(0, 30))
                        {
                        default:
                            frames[player].count300 += 1;
                            frames[player].currentCombo++;
                            frames[player].currentHp += 3;
                            break;

                        case 1:
                        case 2:
                        case 3:
                            frames[player].count100 += 1;
                            frames[player].currentCombo++;
                            frames[player].currentHp += 2;
                            break;

                        case 4:
                        case 5:
                            frames[player].count50   += 1;
                            frames[player].currentHp += 1;
                            frames[player].currentCombo++;
                            break;

                        case 6:
                            frames[player].countMiss   += 1;
                            frames[player].currentHp   -= 50;
                            frames[player].currentCombo = 0;
                            break;
                        }

                        frames[player].currentHp = OsuMathHelper.Clamp(frames[player].currentHp, 0, 200);

                        if (frames[player].currentHp == 0)
                        {
                            frames[player].pass = false;
                        }
                        else if (frames[player].currentHp > 100)
                        {
                            frames[player].pass = true;
                        }

                        frames[player].totalScore += frames[player].currentCombo * 300;
                        frames[player].maxCombo    = Math.Max(frames[player].maxCombo, frames[player].currentCombo);


                        PlayerVs.MatchScoreUpdate(frames[player]);

                        Thread.Sleep(50);
                    }
                });
            }

            switch (INITIAL_MODE)
            {
            case OsuModes.Play:
                if (BeatmapManager.Current == null)
                {
                    NotificationManager.ShowMessage("Couldn't start in specified test mode because no beatmaps were available.");
                    return;
                }

                ModManager.ModStatus = MODS_TO_USE;

                if (AUTOMATIC_SKIP)
                {
                    GameBase.RunBackgroundThread(delegate
                    {
                        while (true)
                        {
                            if (Player.Instance != null && Player.Instance.Status != PlayerStatus.Busy)
                            {
                                Scheduler.Add(delegate { Player.Instance?.DoSkip(); });
                                if (Player.HasSkipped)
                                {
                                    break;
                                }
                            }

                            Thread.Sleep(200);
                        }
                    });
                }

                if (AUTOPLAY)
                {
                    ModManager.ModStatus |= Mods.Autoplay;
                }

                break;
            }

            QueuedMode  = INITIAL_MODE;
            Player.Mode = INITIAL_PLAY_MODE;
        }
    }
        internal static void SetUpdateState(UpdateStates state)
        {
            Scheduler.Add(delegate
            {
                if (state == UpdateState)
                {
                    return;
                }

                UpdateState = state;

                VoidDelegate d = UpdateStateChanged;
                if (d != null)
                {
                    d();
                }

                switch (UpdateState)
                {
                case UpdateStates.EmergencyFallback:
                    //let's hope we never need this.
                    OsuMain.Repair(true);
                    break;

                case UpdateStates.Completed:
                    ConfigManager.sUpdateFailCount.Value = 0;

                    //Update has completed and doesn't need a restart.
                    ConfigManager.sUpdatePending.Value = false;
                    ConfigManager.SaveConfig();

                    string lastVersion = ConfigManager.sLastVersion;

                    NotificationManager.ShowMessage(
                        string.Format(LocalisationManager.GetString(OsuString.Update_Complete), General.BUILD_NAME) + '\n' +
                        LocalisationManager.GetString(OsuString.GameBase_Updater_Changelog),
                        Color.Pink, 10000, delegate
                    {
                        if (string.IsNullOrEmpty(General.SUBVERSION))
                        {
                            //public releases
                            GameBase.ProcessStart(string.Format(@"https://osu.ppy.sh/p/changelog?v={0}&s={1}&l={2}",
                                                                General.BUILD_NAME, General.TargetedPublicStream.ToString().ToLower(), lastVersion));
                        }
                        else
                        {
                            //beta or cutting edge
                            GameBase.ProcessStart(@"https://osu.ppy.sh/p/changelog?v=next");
                        }
                    });
                    break;

                case UpdateStates.Error:
                    ConfigManager.sUpdatePending.Value = false;

                    if (CommonUpdater.LastError != null)
                    {
                        if (CommonUpdater.LastError is MissingFrameworkVersionException)
                        {
                            CommonUpdater.ResetError();
                            NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.GameBase_UpdateFailedFrameworkVersion), Color.Red, 300000, delegate { OsuMain.ForceUpdate(true); });
                        }
                        else
                        {
                            RunBackgroundThread(delegate
                            {
                                ErrorSubmission.Submit(new OsuError(CommonUpdater.LastError)
                                {
                                    Feedback = @"update error",
                                    ILTrace  = CommonUpdater.LastErrorExtraInformation ?? string.Empty
                                });

                                CommonUpdater.ResetError();
                            });
                        }
                    }

                    ConfigManager.ResetHashes();

                    ConfigManager.sUpdateFailCount.Value++;
                    break;

                case UpdateStates.NeedsRestart:

                    //the update could have already moved the files into their new place, so we want to make sure we have reloaded the master config file.
                    ConfigManager.ReloadHashCache();

                    ConfigManager.sUpdateFailCount.Value = 0;

                    bool isNewUpdate = !ConfigManager.sUpdatePending.Value;

                    ConfigManager.sUpdatePending.Value = true;

                    //Update completed but needs a restart. We either want to force a restart or just wait for the next user-triggered restart.
                    if (UpdateForceRestart)
                    {
                        CompleteUpdate();
                    }
                    else if (Mode != OsuModes.Menu && isNewUpdate)
                    {
                        NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.General_NewVersion), Color.Pink, 10000);
                    }

                    UpdatePendingRestart = true;
                    break;

                case UpdateStates.NoUpdate:
                    ConfigManager.sUpdateFailCount.Value = 0;
                    break;
                }
            });
        }