Example #1
0
        /// <summary>
        ///     Goes through all the mapsets in the queue and imports them.
        /// </summary>
        public static void ImportMapsetsInQueue()
        {
            Map selectedMap = null;

            if (MapManager.Selected.Value != null)
            {
                selectedMap = MapManager.Selected.Value;
            }

            for (var i = 0; i < Queue.Count; i++)
            {
                var file             = Queue[i];
                var time             = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).Milliseconds;
                var extractDirectory = $@"{ConfigManager.SongDirectory}/{Path.GetFileNameWithoutExtension(file)} - {time}/";
                ImportingMapset.Invoke(typeof(MapsetImporter), new ImportingMapsetEventArgs(Queue, Path.GetFileName(file), i));

                try
                {
                    if (file.EndsWith(".qp"))
                    {
                        ExtractQuaverMapset(file, extractDirectory);
                        File.Delete(file);
                    }
                    else if (file.EndsWith(".osz"))
                    {
                        Osu.ConvertOsz(file, extractDirectory);
                        File.Delete(file);
                    }
                    else if (file.EndsWith(".sm"))
                    {
                        Stepmania.ConvertFile(file, extractDirectory);
                    }

                    selectedMap = InsertAndUpdateSelectedMap(extractDirectory);

                    Logger.Important($"Successfully imported {file}", LogType.Runtime);
                }
                catch (Exception e)
                {
                    Logger.Error(e, LogType.Runtime);
                    NotificationManager.Show(NotificationLevel.Error, $"Failed to import file: {Path.GetFileName(file)}");
                }
            }

            MapDatabaseCache.OrderAndSetMapsets();

            var mapset = MapManager.Mapsets.Find(x => x.Maps.Any(y => y.Md5Checksum == selectedMap?.Md5Checksum));

            if (mapset == null)
            {
                mapset = MapManager.Mapsets.First();
                MapManager.Selected.Value = mapset.Maps.First();
            }
            else
            {
                MapManager.Selected.Value = mapset.Maps.Find(x => x.Md5Checksum == selectedMap?.Md5Checksum);
            }

            Queue.Clear();
        }
Example #2
0
        /// <summary>
        ///     Inserts an entire extracted directory of maps to the DB
        /// </summary>
        /// <param name="extractDirectory"></param>
        private static Map InsertAndUpdateSelectedMap(string extractDirectory)
        {
            // Go through each file in the directory and import it into the database.
            var quaFiles     = Directory.GetFiles(extractDirectory, "*.qua", SearchOption.AllDirectories).ToList();
            Map lastImported = null;

            try
            {
                foreach (var quaFile in quaFiles)
                {
                    var map = Map.FromQua(Qua.Parse(quaFile), quaFile);
                    map.DifficultyProcessorVersion = DifficultyProcessorKeys.Version;

                    var info = OnlineManager.Client?.RetrieveMapInfo(map.MapId);
                    if (info != null)
                    {
                        map.RankedStatus = info.Map.RankedStatus;
                    }

                    map.CalculateDifficulties();
                    MapDatabaseCache.InsertMap(map, quaFile);
                    lastImported = map;
                }
            }
            catch (Exception e)
            {
                Logger.Error(e, LogType.Runtime);
            }

            return(lastImported);
        }
Example #3
0
        /// <summary>
        ///     Runs the worker thread for the sync process
        /// </summary>
        public static void RunThread()
        {
            if (!EligibleToSync)
            {
                return;
            }

            if (MapsToCache == null && ConfigManager.AutoLoadOsuBeatmaps.Value)
            {
                MapDatabaseCache.OrderAndSetMapsets();
            }

            if (IsSyncing || !NeedsSync)
            {
                return;
            }

            Thread = new Thread(() =>
            {
                if (MapsToCache != null && NeedsSync)
                {
                    NotificationManager.Show(NotificationLevel.Info,
                                             $"Calculating difficulty ratings of other games' maps in the background. {SyncMapCount} maps left!");

                    Logger.Important($"Starting other game sync thread.", LogType.Runtime);
                }
                else
                {
                    return;
                }

                using (var conn = new SQLiteConnection(DatabasePath))
                {
                    AddMaps(conn);
                    UpdateMaps(conn);
                    DeleteMaps(conn);

                    if (SyncMapCount == 0)
                    {
                        NotificationManager.Show(NotificationLevel.Success, "Successfully completed difficulty rating calculations for other games!");
                    }
                }
            })
            {
                IsBackground = true,
                Priority     = ThreadPriority.AboveNormal
            };

            Thread.Start();
        }