public Collections GetPlayersCollections(CollectionGeneratorConfiguration cfg, LogCollectionGeneration logger) { int totalUsernames = cfg.Usernames.Count; int processedCounter = 0; var c = new Collections(); _osuApi.ApiKey = cfg.ApiKey; _logger = logger; _logger?.Invoke(StartingProcessing, 0d); _collectionManager.EditCollection(CollectionEditArgs.ClearCollections()); try { foreach (var username in cfg.Usernames) { var collections = GetPlayerCollections(username, cfg.CollectionNameSavePattern, cfg.ScoreSaveConditions); Log(username, ParsingFinished, ++processedCounter / (double)totalUsernames * 100); _collectionManager.EditCollection(CollectionEditArgs.AddOrMergeCollections(collections)); } c.AddRange(_collectionManager.LoadedCollections); _logger?.Invoke(string.Format(ParsingFinished, cfg.Usernames.Count), 100); _logger = null; return(c); } catch (ThreadAbortException) { _logger?.Invoke(Aborted, -1d); return(c); } }
public Collections LoadOsdbCollections(string fileLocation) { var collections = new Collections(); collections.AddRange(OsdbCollectionHandler.ReadOsdb(fileLocation, _mapCacher)); return(collections); }
public Collections GetCollectionsForBeatmaps(Beatmaps beatmaps) { var collections = new Collections(); var hashes = beatmaps.Select(b => b.Md5).ToArray(); collections.AddRange(LoadedCollections.Where(c => hashes.Intersect(c.BeatmapHashes).Any())); return(collections); }
private async void UploadNewCollections(object sender, object data = null) { if (!await Initalizer.WebCollectionProvider.IsCurrentKeyValid()) { _userDialogs.OkMessageBox("You need to login before uploading collections", "Error", MessageBoxType.Error); return; } var collectionList = (IList <ICollection>)data; foreach (var c in collectionList) { if (!c.AllBeatmaps().Any()) { _userDialogs.OkMessageBox("Empty collection - upload aborted", "Error", MessageBoxType.Error); return; } } var oldCollections = new Collections(); oldCollections.AddRange(collectionList); var newCollections = new Collections(); foreach (var c in collectionList) { var webCollection = new WebCollection(0, _osuFileIo.LoadedMaps, true); webCollection.Name = c.Name; webCollection.LastEditorUsername = c.LastEditorUsername; foreach (var collectionBeatmap in c.AllBeatmaps()) { webCollection.AddBeatmap(collectionBeatmap); } newCollections.AddRange(await webCollection.Save(Initalizer.WebCollectionProvider)); } _collectionEditor.EditCollection(CollectionEditArgs.RemoveCollections(oldCollections)); _collectionEditor.EditCollection(CollectionEditArgs.AddCollections(newCollections)); var sidePanel = (IOnlineCollectionList)_mainForm.SidePanelView; sidePanel.WebCollections.AddRange(newCollections.OfType <WebCollection>()); sidePanel.WebCollections.CallReset(); if (newCollections.Count > 0) { _userDialogs.OkMessageBox($"Collections uploaded", "Info", MessageBoxType.Success); } if (newCollections.Count == 1) { Process.Start($"https://osustats.ppy.sh/collection/{newCollections[0].OnlineId}"); } }
private void LoadConfig() { var history = _config.GetHistory(); History.AddRange(history); var collections = _config.GetCollections(); Collections.AddRange(collections); _applications = _config.GetOAuthApplications(); var authenticationUrls = _config.GetOAuthAuthenticationUrls(); var userCredentials = _config.GetUserCredentials(); _bus.PublishOnUIThread(new ConfigurationLoaded(_applications, authenticationUrls, userCredentials)); }
/// <summary> /// Loads music data collections from the default file path. /// </summary> /// <returns> /// True if loaded correctly, false if file doesn't exists. /// </returns> public bool LoadCollections() { IList <Collection> collections = null; try { collections = new JSONCollectionSource().Load(); } catch (IOException) { return(false); } Collections.AddRange(collections); Collections.ForEach(action => action.Reconnect()); RefreshBands(); return(true); }
/* * add collection * remove collection * edit collection name * merge x collections * intersect x collections * inverse map sum of x collections * difference x collections * clear collections * reorder collections * add beatmaps to collection * remove beatmaps from collection */ private void EditCollection(CollectionEditArgs args, bool suspendRefresh = false) { var action = args.Action; if ((int)action >= 100) { return; } if (action == CollectionEdit.Add) { List <string> collectionNames = new List <string>(); foreach (var collection in args.Collections) { var name = GetValidCollectionName(collection.Name, collectionNames); collection.Name = name; collectionNames.Add(name); } LoadedCollections.AddRange(args.Collections); } else if (action == CollectionEdit.AddOrMergeIfExists) { foreach (var collection in args.Collections) { if (CollectionNameExists(collection.Name)) { EditCollection(CollectionEditArgs.MergeCollections( new Collections() { GetCollectionByName(collection.Name), collection }, collection.Name), true); } else { EditCollection(CollectionEditArgs.AddCollections(new Collections() { collection }), true); } } } else if (action == CollectionEdit.Remove) { foreach (var collectionName in args.CollectionNames) { var collection = GetCollectionByName(collectionName); if (collection != null) { LoadedCollections.SilentRemove(collection); } } } else if (action == CollectionEdit.Merge) { var collections = args.Collections; var newCollectionName = args.NewName; if (collections.Count > 0) { var masterCollection = collections[0]; for (int i = 1; i < collections.Count; i++) { var collectionToMerge = collections[i]; foreach (var beatmap in collectionToMerge.AllBeatmaps()) { masterCollection.AddBeatmap(beatmap); } LoadedCollections.SilentRemove(collectionToMerge); } LoadedCollections.SilentRemove(masterCollection); masterCollection.Name = GetValidCollectionName(newCollectionName); EditCollection(CollectionEditArgs.AddCollections(new Collections() { masterCollection }), true); } } else if (action == CollectionEdit.Intersect) { var targetCollection = args.Collections.Last(); args.Collections.RemoveAt(args.Collections.Count - 1); var mainCollection = args.Collections[0]; args.Collections.RemoveAt(0); var beatmaps = mainCollection.AllBeatmaps(); foreach (var collection in args.Collections) { beatmaps = beatmaps.Intersect(collection.AllBeatmaps(), new CollectionBeatmapComparer()).ToList(); } foreach (var beatmap in beatmaps) { targetCollection.AddBeatmap(beatmap); } EditCollection(CollectionEditArgs.AddCollections(new Collections() { targetCollection }), true); } else if (action == CollectionEdit.Inverse) { var targetCollection = args.Collections.Last(); args.Collections.RemoveAt(args.Collections.Count - 1); var beatmaps = LoadedBeatmaps.AsEnumerable().Cast <BeatmapExtension>(); foreach (var collection in args.Collections) { beatmaps = beatmaps.Except(collection.AllBeatmaps(), new CollectionBeatmapComparer()); } foreach (var beatmap in beatmaps) { targetCollection.AddBeatmap(beatmap); } EditCollection(CollectionEditArgs.AddCollections(new Collections() { targetCollection }), true); } else if (action == CollectionEdit.Difference) { var targetCollection = args.Collections.Last(); args.Collections.RemoveAt(args.Collections.Count - 1); var mainCollection = args.Collections[0]; args.Collections.RemoveAt(0); var beatmaps = mainCollection.AllBeatmaps(); foreach (var collection in args.Collections) { beatmaps = beatmaps.Concat(collection.AllBeatmaps()); } var differenceMd5 = beatmaps.GroupBy(x => x.Md5).Where(group => group.Count() == 1).Select(group => group.Key).ToList(); var differenceMapId = beatmaps.GroupBy(x => x.MapId).Where(group => group.Count() == 1).Select(group => group.Key).ToList(); foreach (var beatmap in beatmaps) { if (differenceMd5.Contains(beatmap.Md5) || differenceMapId.Contains(beatmap.MapId)) { targetCollection.AddBeatmap(beatmap); } } EditCollection(CollectionEditArgs.AddCollections(new Collections() { targetCollection }), true); } else if (action == CollectionEdit.Clear) { LoadedCollections.Clear(); } else if (action == CollectionEdit.Reorder) { var targetCollection = args.TargetCollection; var collectionsToReorder = args.Collections.OrderBy(x => x.Name).ToList(); var orderedLoadedCollections = LoadedCollections.OrderBy(x => x.Name).ToList(); foreach (var coll in collectionsToReorder) { orderedLoadedCollections.Remove(coll); } var targetCollectionIndex = orderedLoadedCollections.IndexOf(targetCollection); orderedLoadedCollections.InsertRange(args.PlaceCollectionsBefore ? targetCollectionIndex : targetCollectionIndex + 1, collectionsToReorder); var amountOfCharactersRequired = 0; var variations = 0; while (orderedLoadedCollections.Count() > variations) { variations = Enumerable.Range(1, ++amountOfCharactersRequired).Aggregate(0, (acc, i) => Convert.ToInt32(Math.Pow(ReorderChars.Length, i)) + acc); } List <string> reorderStrings = new List <string>(variations); for (int i = 1; i <= amountOfCharactersRequired; i++) { reorderStrings.AddRange(CombinationsWithRepetition(ReorderCharsString, i)); } reorderStrings.Sort(); var collectionIndex = 0; foreach (var collection in orderedLoadedCollections) { if (collection.Name.Contains(reorderSeparator)) { collection.Name = collection.Name.TrimStart(ReorderCharsWithSeparator); } collection.Name = $"{reorderStrings[collectionIndex++]}{reorderSeparator} {collection.Name}"; } } else { var collection = GetCollectionByName(args.OrginalName); if (action == CollectionEdit.Rename) { collection.Name = GetValidCollectionName(args.NewName); } else if (action == CollectionEdit.AddBeatmaps) { if (collection != null) { foreach (var beatmap in args.Beatmaps) { collection.AddBeatmap(beatmap); } } } else if (action == CollectionEdit.RemoveBeatmaps) { if (collection != null) { foreach (var beatmap in args.Beatmaps) { collection.RemoveBeatmap(beatmap.Md5); } } } else if (action == CollectionEdit.Duplicate) { throw new NotImplementedException("Call AddCollections followed with AddBeatmaps instead"); } } if (!suspendRefresh) { AfterCollectionsEdit(); } }
public void RestoreCollections(List <CollectionData> collections) { Collections.Clear(); Collections.AddRange(collections); }
/* * add collection * remove collection * edit collection name * merge x collections * clear collections * add beatmaps to collection * remove beatmaps from collection */ private void EditCollection(CollectionEditArgs args, bool suspendRefresh = false) { var action = args.Action; if (action == CollectionEdit.Add) { foreach (var collection in args.Collections) { collection.Name = GetValidCollectionName(collection.Name); } LoadedCollections.AddRange(args.Collections); } else if (action == CollectionEdit.AddOrMergeIfExists) { foreach (var collection in args.Collections) { if (CollectionNameExists(collection.Name)) { EditCollection(CollectionEditArgs.MergeCollections( new Collections() { GetCollectionByName(collection.Name), collection }, collection.Name), true); } else { EditCollection(CollectionEditArgs.AddCollections(new Collections() { collection }), true); } } } else if (action == CollectionEdit.Remove) { foreach (var collectionName in args.CollectionNames) { var collection = GetCollectionByName(collectionName); if (collection != null) { LoadedCollections.SilentRemove(collection); } } } else if (action == CollectionEdit.Merge) { var collections = args.Collections; var newCollectionName = args.NewName; if (collections.Count > 0) { var masterCollection = collections[0]; for (int i = 1; i < collections.Count; i++) { var collectionToMerge = collections[i]; foreach (var beatmap in collectionToMerge.AllBeatmaps()) { masterCollection.AddBeatmap(beatmap); } LoadedCollections.SilentRemove(collectionToMerge); } LoadedCollections.SilentRemove(masterCollection); masterCollection.Name = GetValidCollectionName(newCollectionName); EditCollection(CollectionEditArgs.AddCollections(new Collections() { masterCollection }), true); } } else if (action == CollectionEdit.Clear) { LoadedCollections.Clear(); } else { var collection = GetCollectionByName(args.OrginalName); if (action == CollectionEdit.Rename) { collection.Name = GetValidCollectionName(args.NewName); } else if (action == CollectionEdit.AddBeatmaps) { if (collection != null) { foreach (var beatmap in args.Beatmaps) { collection.AddBeatmap(beatmap); } } } else if (action == CollectionEdit.RemoveBeatmaps) { if (collection != null) { foreach (var beatmap in args.Beatmaps) { collection.RemoveBeatmap(beatmap.Md5); } } } } if (!suspendRefresh) { AfterCollectionsEdit(); } }
/* * add collection * remove collection * edit collection name * merge x collections * intersect x collections * clear collections * add beatmaps to collection * remove beatmaps from collection */ private void EditCollection(CollectionEditArgs args, bool suspendRefresh = false) { var action = args.Action; if (action == CollectionEdit.Add) { List <string> collectionNames = new List <string>(); foreach (var collection in args.Collections) { var name = GetValidCollectionName(collection.Name, collectionNames); collection.Name = name; collectionNames.Add(name); } LoadedCollections.AddRange(args.Collections); } else if (action == CollectionEdit.AddOrMergeIfExists) { foreach (var collection in args.Collections) { if (CollectionNameExists(collection.Name)) { EditCollection(CollectionEditArgs.MergeCollections( new Collections() { GetCollectionByName(collection.Name), collection }, collection.Name), true); } else { EditCollection(CollectionEditArgs.AddCollections(new Collections() { collection }), true); } } } else if (action == CollectionEdit.Remove) { foreach (var collectionName in args.CollectionNames) { var collection = GetCollectionByName(collectionName); if (collection != null) { LoadedCollections.SilentRemove(collection); } } } else if (action == CollectionEdit.Merge) { var collections = args.Collections; var newCollectionName = args.NewName; if (collections.Count > 0) { var masterCollection = collections[0]; for (int i = 1; i < collections.Count; i++) { var collectionToMerge = collections[i]; foreach (var beatmap in collectionToMerge.AllBeatmaps()) { masterCollection.AddBeatmap(beatmap); } LoadedCollections.SilentRemove(collectionToMerge); } LoadedCollections.SilentRemove(masterCollection); masterCollection.Name = GetValidCollectionName(newCollectionName); EditCollection(CollectionEditArgs.AddCollections(new Collections() { masterCollection }), true); } } else if (action == CollectionEdit.Intersect) { var targetCollection = args.Collections.Last(); args.Collections.RemoveAt(args.Collections.Count - 1); var mainCollection = args.Collections[0]; args.Collections.RemoveAt(0); var beatmaps = mainCollection.AllBeatmaps().ToList(); foreach (var collection in args.Collections) { beatmaps = beatmaps.Intersect(collection.AllBeatmaps(), new CollectionBeatmapComparer()).ToList(); } foreach (var beatmap in beatmaps) { targetCollection.AddBeatmap(beatmap); } EditCollection(CollectionEditArgs.AddCollections(new Collections() { targetCollection }), true); } else if (action == CollectionEdit.Clear) { LoadedCollections.Clear(); } else { var collection = GetCollectionByName(args.OrginalName); if (action == CollectionEdit.Rename) { collection.Name = GetValidCollectionName(args.NewName); } else if (action == CollectionEdit.AddBeatmaps) { if (collection != null) { foreach (var beatmap in args.Beatmaps) { collection.AddBeatmap(beatmap); } } } else if (action == CollectionEdit.RemoveBeatmaps) { if (collection != null) { foreach (var beatmap in args.Beatmaps) { collection.RemoveBeatmap(beatmap.Md5); } } } else if (action == CollectionEdit.Duplicate) { throw new NotImplementedException("Call AddCollections followed with AddBeatmaps instead"); } } if (!suspendRefresh) { AfterCollectionsEdit(); } }