Ejemplo n.º 1
0
Archivo: Map.cs Proyecto: jaydn/Quaver
        /// <summary>
        ///     Responsible for converting a Qua object, to a Map object
        ///     a Map object is one that is stored in the db.
        /// </summary>
        /// <param name="qua"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static Map FromQua(Qua qua, string path)
        {
            var map = new Map
            {
                Md5Checksum      = MapsetHelper.GetMd5Checksum(path),
                Directory        = new DirectoryInfo(System.IO.Path.GetDirectoryName(path) ?? throw new InvalidOperationException()).Name.Replace("\\", "/"),
                Path             = System.IO.Path.GetFileName(path)?.Replace("\\", "/"),
                Artist           = qua.Artist,
                Title            = qua.Title,
                HighestRank      = Grade.None,
                AudioPath        = qua.AudioFile,
                AudioPreviewTime = qua.SongPreviewTime,
                BackgroundPath   = qua.BackgroundFile,
                Description      = qua.Description,
                MapId            = qua.MapId,
                MapSetId         = qua.MapSetId,
                Bpm            = qua.GetCommonBpm(),
                Creator        = qua.Creator,
                DifficultyName = qua.DifficultyName,
                Source         = qua.Source,
                Tags           = qua.Tags,
                SongLength     = qua.Length,
                Mode           = qua.Mode,
            };

            map.LastFileWrite = File.GetLastWriteTimeUtc(map.Path);
            return(map);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Checks the maps in the database vs. the amount of .qua files on disk.
        ///     If there's a mismatch, it will add any missing ones
        /// </summary>
        private static void SyncMissingOrUpdatedFiles(IReadOnlyCollection <string> files)
        {
            var maps = FetchAll();

            foreach (var map in maps)
            {
                var filePath = BackslashToForward($"{ConfigManager.SongDirectory.Value}/{map.Directory}/{map.Path}");

                // Check if the file actually exists.
                if (files.Any(x => BackslashToForward(x) == filePath))
                {
                    // Check if the file was updated. In this case, we check if the last write times are different
                    // BEFORE checking Md5 checksum of the file since it's faster to check if we even need to
                    // bother updating it.
                    if (map.LastFileWrite != File.GetLastWriteTimeUtc(filePath))
                    {
                        if (map.Md5Checksum == MapsetHelper.GetMd5Checksum(filePath))
                        {
                            continue;
                        }

                        Map newMap;

                        try
                        {
                            newMap = Map.FromQua(map.LoadQua(false), filePath);
                        }
                        catch (Exception e)
                        {
                            Logger.Error(e, LogType.Runtime);
                            File.Delete(filePath);
                            new SQLiteConnection(DatabasePath).Delete(map);
                            Logger.Important($"Removed {filePath} from the cache, as the file could not be parsed.", LogType.Runtime);
                            continue;
                        }

                        newMap.CalculateDifficulties();

                        newMap.Id = map.Id;
                        new SQLiteConnection(DatabasePath).Update(newMap);

                        Logger.Important($"Updated cached map: {newMap.Id}, as the file was updated.", LogType.Runtime);
                    }

                    continue;
                }

                // The file doesn't exist, so we can safely delete it from the cache.
                new SQLiteConnection(DatabasePath).Delete(map);
                Logger.Important($"Removed {filePath} from the cache, as the file no longer exists", LogType.Runtime);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Fetches all maps, groups them into mapsets, sets them to allow them to be played.
        /// </summary>
        public static void OrderAndSetMapsets()
        {
            var maps = FetchAll();

            if (ConfigManager.AutoLoadOsuBeatmaps.Value)
            {
                maps = maps.Concat(OtherGameMapDatabaseCache.Load()).ToList();
            }

            var mapsets = MapsetHelper.ConvertMapsToMapsets(maps);

            MapManager.Mapsets = MapsetHelper.OrderMapsByDifficulty(MapsetHelper.OrderMapsetsByArtist(mapsets));
        }
Ejemplo n.º 4
0
Archivo: Map.cs Proyecto: AiAe/Quaver-1
        /// <summary>
        ///     Responsible for converting a Qua object, to a Map object
        ///     a Map object is one that is stored in the db.
        /// </summary>
        /// <param name="qua"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static Map FromQua(Qua qua, string path, bool skipPathSetting = false)
        {
            var map = new Map
            {
                Artist           = qua.Artist,
                Title            = qua.Title,
                HighestRank      = Grade.None,
                AudioPath        = qua.AudioFile,
                AudioPreviewTime = qua.SongPreviewTime,
                BackgroundPath   = qua.BackgroundFile,
                Description      = qua.Description,
                MapId            = qua.MapId,
                MapSetId         = qua.MapSetId,
                Creator          = qua.Creator,
                DifficultyName   = qua.DifficultyName,
                Source           = qua.Source,
                Tags             = qua.Tags,
                SongLength       = qua.Length,
                Mode             = qua.Mode,
                RegularNoteCount = qua.HitObjects.Count(x => !x.IsLongNote),
                LongNoteCount    = qua.HitObjects.Count(x => x.IsLongNote),
            };

            if (!skipPathSetting)
            {
                try
                {
                    map.Md5Checksum   = MapsetHelper.GetMd5Checksum(path);
                    map.Directory     = new DirectoryInfo(System.IO.Path.GetDirectoryName(path) ?? throw new InvalidOperationException()).Name.Replace("\\", "/");
                    map.Path          = System.IO.Path.GetFileName(path)?.Replace("\\", "/");
                    map.LastFileWrite = File.GetLastWriteTimeUtc(map.Path);
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch (Exception)
                {
                }
            }

            try
            {
                map.Bpm = qua.GetCommonBpm();
            }
            catch (Exception)
            {
                map.Bpm = 0;
            }

            map.DateAdded = DateTime.Now;
            return(map);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Fetches all maps, groups them into mapsets, sets them to allow them to be played.
        /// </summary>
        public static void OrderAndSetMapsets()
        {
            var maps = FetchAll();

            if (ConfigManager.AutoLoadOsuBeatmaps.Value)
            {
                maps = maps.Concat(LoadOsuBeatmapDatabase()).ToList();
                LoadedMapsFromOtherGames = true;
            }
            else
            {
                LoadedMapsFromOtherGames = false;
            }

            var mapsets = MapsetHelper.ConvertMapsToMapsets(maps);

            MapManager.Mapsets = MapsetHelper.OrderMapsByDifficulty(MapsetHelper.OrderMapsetsByArtist(mapsets));
        }