Exemple #1
0
        /// <summary>
        ///     Handles new incoming online users and dictates if they are available to display
        ///     <see cref="AvailableUsers"/>
        /// </summary>
        /// <param name="users"></param>
        public void HandleNewOnlineUsers(IEnumerable <User> users)
        {
            lock (AvailableUsers)
            {
                var incomingAvailableUsers = users.Where(CheckIfUserShouldBeDrawn).ToList();
                var allAvailableUsers      = new List <User>(AvailableUsers);

                // Concatenate the old list of available users with the new one, and order it properly.
                AvailableUsers = allAvailableUsers
                                 .Concat(incomingAvailableUsers)
                                 .ToList();

                SortUsers();
                RecalculateContainerHeight();

                Logger.Debug($"There are now {AvailableUsers.Count} total available users.", LogType.Runtime);

                // If we already have enough buffered objects, then just update all of the current buffered users.
                if (UserBufferObjectsUsed == MAX_USERS_SHOWN)
                {
                    UpdateBufferUsers();
                    return;
                }

                // Based on how many new available users we have, we can add that many new contained drawables.
                for (var i = 0; i < incomingAvailableUsers.Count && UserBufferObjectsUsed != MAX_USERS_SHOWN; i++)
                {
                    UserBufferObjectsUsed++;
                }

                UpdateBufferUsers();
            }
        }
Exemple #2
0
        /// <summary>
        ///     Exports the entire mapset to a zip (.qp) file.
        /// </summary>
        public void ExportToZip()
        {
            var exportsDir = $"{ConfigManager.DataDirectory}/Exports/";

            System.IO.Directory.CreateDirectory(exportsDir);

            var tempFolder = $"{ConfigManager.DataDirectory}/temp/{GameBase.Game.TimeRunning}/";

            System.IO.Directory.CreateDirectory(tempFolder);

            using (var archive = ZipArchive.Create())
            {
                foreach (var map in Maps)
                {
                    try
                    {
                        switch (map.Game)
                        {
                        case MapGame.Quaver:
                            var path = $"{ConfigManager.SongDirectory.Value}/{map.Directory}/{map.Path}";
                            File.Copy(path, $"{tempFolder}/{map.Path}");
                            break;

                        // Map is from osu!, so we need to convert it to .qua format
                        case MapGame.Osu:
                            var osuPath = $"{MapManager.OsuSongsFolder}{map.Directory}/{map.Path}";

                            var osu = new OsuBeatmap(osuPath);
                            map.BackgroundPath = osu.Background;

                            var name     = StringHelper.FileNameSafeString($"{map.Artist} - {map.Title} [{map.DifficultyName}].qua");
                            var savePath = $"{tempFolder}/{name}";

                            osu.ToQua().Save(savePath);

                            Logger.Debug($"Successfully converted osu beatmap: {osuPath}", LogType.Runtime);
                            break;
                        }

                        // Copy over audio file if necessary
                        if (File.Exists(MapManager.GetAudioPath(map)) && !File.Exists($"{tempFolder}/{map.AudioPath}"))
                        {
                            File.Copy(MapManager.GetAudioPath(map), $"{tempFolder}/{map.AudioPath}");
                        }

                        // Copy over background file if necessary
                        if (File.Exists(MapManager.GetBackgroundPath(map)) && !File.Exists($"{tempFolder}/{map.BackgroundPath}"))
                        {
                            File.Copy(MapManager.GetBackgroundPath(map), $"{tempFolder}/{map.BackgroundPath}");
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error(e, LogType.Runtime);
                    }
                }

                archive.AddAllFromDirectory(tempFolder);

                var outputPath = exportsDir +
                                 $"{StringHelper.FileNameSafeString(Artist + " - " + Title + " - " + GameBase.Game.TimeRunning)}.qp";

                archive.SaveTo(outputPath, CompressionType.Deflate);

                Utils.NativeUtils.HighlightInFileManager(outputPath);
            }

            System.IO.Directory.Delete(tempFolder, true);
        }