2 Commits

9 changed files with 61 additions and 23 deletions

View File

@@ -13,6 +13,7 @@ using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Formats;
using osu.Game.Configuration;
using osu.Game.Collections; using osu.Game.Collections;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Extensions; using osu.Game.Extensions;
@@ -36,8 +37,8 @@ namespace osu.Game.Beatmaps
public ProcessBeatmapDelegate? ProcessBeatmap { private get; set; } public ProcessBeatmapDelegate? ProcessBeatmap { private get; set; }
public BeatmapImporter(Storage storage, RealmAccess realm) public BeatmapImporter(Storage storage, RealmAccess realm, OsuConfigManager? config)
: base(storage, realm) : base(storage, realm, config)
{ {
} }

View File

@@ -17,6 +17,7 @@ using osu.Framework.IO.Stores;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Formats;
using osu.Game.Configuration;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.IO.Archives; using osu.Game.IO.Archives;
@@ -59,7 +60,7 @@ namespace osu.Game.Beatmaps
} }
public BeatmapManager(Storage storage, RealmAccess realm, IAPIProvider? api, AudioManager audioManager, IResourceStore<byte[]> gameResources, GameHost? host = null, public BeatmapManager(Storage storage, RealmAccess realm, IAPIProvider? api, AudioManager audioManager, IResourceStore<byte[]> gameResources, GameHost? host = null,
WorkingBeatmap? defaultBeatmap = null, BeatmapDifficultyCache? difficultyCache = null, bool performOnlineLookups = false) WorkingBeatmap? defaultBeatmap = null, BeatmapDifficultyCache? difficultyCache = null, bool performOnlineLookups = false, OsuConfigManager? config = null)
: base(storage, realm) : base(storage, realm)
{ {
if (performOnlineLookups) if (performOnlineLookups)
@@ -75,7 +76,7 @@ namespace osu.Game.Beatmaps
BeatmapTrackStore = audioManager.GetTrackStore(userResources); BeatmapTrackStore = audioManager.GetTrackStore(userResources);
beatmapImporter = CreateBeatmapImporter(storage, realm); beatmapImporter = CreateBeatmapImporter(storage, realm, config);
beatmapImporter.ProcessBeatmap = (beatmapSet, scope) => ProcessBeatmap?.Invoke(beatmapSet, scope); beatmapImporter.ProcessBeatmap = (beatmapSet, scope) => ProcessBeatmap?.Invoke(beatmapSet, scope);
beatmapImporter.PostNotification = obj => PostNotification?.Invoke(obj); beatmapImporter.PostNotification = obj => PostNotification?.Invoke(obj);
@@ -98,7 +99,7 @@ namespace osu.Game.Beatmaps
return new WorkingBeatmapCache(BeatmapTrackStore, audioManager, resources, storage, defaultBeatmap, host); return new WorkingBeatmapCache(BeatmapTrackStore, audioManager, resources, storage, defaultBeatmap, host);
} }
protected virtual BeatmapImporter CreateBeatmapImporter(Storage storage, RealmAccess realm) => new BeatmapImporter(storage, realm); protected virtual BeatmapImporter CreateBeatmapImporter(Storage storage, RealmAccess realm, OsuConfigManager? config = null) => new BeatmapImporter(storage, realm, config);
/// <summary> /// <summary>
/// Create a new beatmap set, backed by a <see cref="BeatmapSetInfo"/> model, /// Create a new beatmap set, backed by a <see cref="BeatmapSetInfo"/> model,

View File

@@ -202,6 +202,8 @@ namespace osu.Game.Configuration
SetDefault(OsuSetting.DiscordRichPresence, DiscordRichPresenceMode.Full); SetDefault(OsuSetting.DiscordRichPresence, DiscordRichPresenceMode.Full);
SetDefault(OsuSetting.DeleteImportedArchives, true);
SetDefault(OsuSetting.EditorDim, 0.25f, 0f, 0.75f, 0.25f); SetDefault(OsuSetting.EditorDim, 0.25f, 0f, 0.75f, 0.25f);
SetDefault(OsuSetting.EditorWaveformOpacity, 0.25f, 0f, 1f, 0.25f); SetDefault(OsuSetting.EditorWaveformOpacity, 0.25f, 0f, 1f, 0.25f);
SetDefault(OsuSetting.EditorShowHitMarkers, true); SetDefault(OsuSetting.EditorShowHitMarkers, true);
@@ -449,6 +451,7 @@ namespace osu.Game.Configuration
EditorShowHitMarkers, EditorShowHitMarkers,
EditorAutoSeekOnPlacement, EditorAutoSeekOnPlacement,
DiscordRichPresence, DiscordRichPresence,
DeleteImportedArchives,
ShowOnlineExplicitContent, ShowOnlineExplicitContent,
LastProcessedMetadataId, LastProcessedMetadataId,

View File

@@ -8,11 +8,14 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Humanizer; using Humanizer;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Configuration;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.IO.Archives; using osu.Game.IO.Archives;
using osu.Game.Models; using osu.Game.Models;
@@ -77,11 +80,19 @@ namespace osu.Game.Database
/// </summary> /// </summary>
public Action<Notification>? PostNotification { get; set; } public Action<Notification>? PostNotification { get; set; }
protected RealmArchiveModelImporter(Storage storage, RealmAccess realm) private readonly OsuConfigManager? config;
private Bindable<bool>? deleteImportedArchives;
protected RealmArchiveModelImporter(Storage storage, RealmAccess realm, OsuConfigManager? config = null)
{ {
Realm = realm; Realm = realm;
Files = new RealmFileStore(realm, storage); Files = new RealmFileStore(realm, storage);
deleteImportedArchives = config?.GetBindable<bool>(OsuSetting.DeleteImportedArchives);
this.config = config;
} }
public Task Import(params string[] paths) => Import(paths.Select(p => new ImportTask(p)).ToArray()); public Task Import(params string[] paths) => Import(paths.Select(p => new ImportTask(p)).ToArray());
@@ -241,9 +252,10 @@ namespace osu.Game.Database
// e.g. reconstructing/repairing database with items from default storage. // e.g. reconstructing/repairing database with items from default storage.
// Also, not always a single file, i.e. for LegacyFilesystemReader // Also, not always a single file, i.e. for LegacyFilesystemReader
// TODO: Add a check to prevent files from storage to be deleted. // TODO: Add a check to prevent files from storage to be deleted.
bool allowDelete = deleteImportedArchives?.Value ?? true;
try try
{ {
if (import != null && ShouldDeleteArchive(task.Path)) if (import != null && ShouldDeleteArchive(task.Path) && allowDelete)
task.DeleteFile(); task.DeleteFile();
} }
catch (Exception e) catch (Exception e)

View File

@@ -298,7 +298,7 @@ namespace osu.Game
Audio.Samples.PlaybackConcurrency = SAMPLE_CONCURRENCY; Audio.Samples.PlaybackConcurrency = SAMPLE_CONCURRENCY;
dependencies.Cache(SkinManager = new SkinManager(Storage, realm, Host, Resources, Audio, Scheduler)); dependencies.Cache(SkinManager = new SkinManager(Storage, realm, Host, Resources, Audio, Scheduler, LocalConfig));
dependencies.CacheAs<ISkinSource>(SkinManager); dependencies.CacheAs<ISkinSource>(SkinManager);
EndpointConfiguration endpoints = CreateEndpoints(); EndpointConfiguration endpoints = CreateEndpoints();
@@ -322,7 +322,7 @@ namespace osu.Game
// ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup() // ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup()
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, realm, API, LocalConfig)); dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, realm, API, LocalConfig));
dependencies.Cache(BeatmapManager = new BeatmapManager(Storage, realm, API, Audio, Resources, Host, defaultBeatmap, difficultyCache, performOnlineLookups: true)); dependencies.Cache(BeatmapManager = new BeatmapManager(Storage, realm, API, Audio, Resources, Host, defaultBeatmap, difficultyCache, performOnlineLookups: true, config: LocalConfig));
dependencies.CacheAs<IWorkingBeatmapCache>(BeatmapManager); dependencies.CacheAs<IWorkingBeatmapCache>(BeatmapManager);
dependencies.Cache(BeatmapDownloader = new BeatmapModelDownloader(BeatmapManager, API)); dependencies.Cache(BeatmapDownloader = new BeatmapModelDownloader(BeatmapManager, API));

View File

@@ -8,6 +8,7 @@ using osu.Framework.Graphics;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Configuration;
using osu.Game.Localisation; using osu.Game.Localisation;
using osu.Game.Screens; using osu.Game.Screens;
using osu.Game.Screens.Import; using osu.Game.Screens.Import;
@@ -22,13 +23,19 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
private ISystemFileSelector? selector; private ISystemFileSelector? selector;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase game, GameHost host, IPerformFromScreenRunner? performer) private void load(OsuGameBase game, GameHost host, IPerformFromScreenRunner? performer, OsuConfigManager config)
{ {
if ((selector = host.CreateSystemFileSelector(game.HandledExtensions.ToArray())) != null) if ((selector = host.CreateSystemFileSelector(game.HandledExtensions.ToArray())) != null)
selector.Selected += f => Task.Run(() => game.Import(f.FullName)); selector.Selected += f => Task.Run(() => game.Import(f.FullName));
AddRange(new Drawable[] AddRange(new Drawable[]
{ {
new SettingsCheckbox
{
LabelText = "Delete archives on import",
Current = config.GetBindable<bool>(OsuSetting.DeleteImportedArchives),
ClassicDefault = true
},
new SettingsButton new SettingsButton
{ {
Text = DebugSettingsStrings.ImportFiles, Text = DebugSettingsStrings.ImportFiles,
@@ -44,7 +51,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
{ {
Text = DebugSettingsStrings.RunLatencyCertifier, Text = DebugSettingsStrings.RunLatencyCertifier,
Action = () => performer?.PerformFromScreen(menu => menu.Push(new LatencyCertifierScreen())) Action = () => performer?.PerformFromScreen(menu => menu.Push(new LatencyCertifierScreen()))
} },
}); });
} }
} }

View File

@@ -1402,24 +1402,36 @@ namespace osu.Game.Screens.Edit
private void anonymizeBeatmap() private void anonymizeBeatmap()
{ {
dialogOverlay.Push(new ConfirmDialog( dialogOverlay.Push(new ConfirmDialog(
"Really remove online IDs?", () => "Really remove online IDs?", () => attemptAsyncMutationOperation(anonymizeMaps))
);
Task anonymizeMaps()
{
var maps = editorBeatmap.BeatmapInfo.BeatmapSet.Beatmaps;
foreach (BeatmapInfo map in maps)
{ {
var maps = editorBeatmap.BeatmapInfo.BeatmapSet.Beatmaps; try
foreach (BeatmapInfo map in maps)
{ {
map.OnlineID = -1; map.OnlineID = -1;
map.BeatmapSet.OnlineID = -1; map.BeatmapSet.OnlineID = -1;
map.ResetOnlineInfo(true); map.ResetOnlineInfo(true);
beatmapManager.Save( beatmapManager.Save(
map, map,
beatmapManager.GetWorkingBeatmap(map, true)!.Beatmap, beatmapManager.GetWorkingBeatmap(map, true).Beatmap,
editorBeatmap.BeatmapSkin editorBeatmap.BeatmapSkin
); // as much as I don't want to mutate this much, there's no other choice );
}
catch (Exception ex)
{
Logger.Error(ex, ex.Message);
notifications?.Post(new SimpleErrorNotification { Text = "Failed to update beatmap difficulty!\nCheck logs for details" });
throw; // we don't want to handle it further, task will do it for us
} }
updateLastSavedHash();
onScreenDisplay?.Display(new BeatmapEditorToast("Online IDs removed", editorBeatmap.BeatmapInfo.GetDisplayTitle()));
} }
)); updateLastSavedHash();
onScreenDisplay?.Display(new BeatmapEditorToast("Online IDs removed", editorBeatmap.BeatmapInfo.GetDisplayTitle()));
return Task.CompletedTask;
}
} }
private void exportBeatmap(bool legacy) private void exportBeatmap(bool legacy)

View File

@@ -11,6 +11,7 @@ using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.IO; using osu.Game.IO;
@@ -28,8 +29,8 @@ namespace osu.Game.Skinning
private readonly ModelManager<SkinInfo> modelManager; private readonly ModelManager<SkinInfo> modelManager;
public SkinImporter(Storage storage, RealmAccess realm, IStorageResourceProvider skinResources) public SkinImporter(Storage storage, RealmAccess realm, IStorageResourceProvider skinResources, OsuConfigManager? config = null)
: base(storage, realm) : base(storage, realm, config)
{ {
this.skinResources = skinResources; this.skinResources = skinResources;

View File

@@ -21,6 +21,7 @@ using osu.Framework.Platform;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Configuration;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.Overlays.Notifications; using osu.Game.Overlays.Notifications;
@@ -74,7 +75,7 @@ namespace osu.Game.Skinning
} }
} }
public SkinManager(Storage storage, RealmAccess realm, GameHost host, IResourceStore<byte[]> resources, AudioManager audio, Scheduler scheduler) public SkinManager(Storage storage, RealmAccess realm, GameHost host, IResourceStore<byte[]> resources, AudioManager audio, Scheduler scheduler, OsuConfigManager config)
: base(storage, realm) : base(storage, realm)
{ {
this.audio = audio; this.audio = audio;
@@ -84,7 +85,7 @@ namespace osu.Game.Skinning
userFiles = new StorageBackedResourceStore(storage.GetStorageForDirectory("files")); userFiles = new StorageBackedResourceStore(storage.GetStorageForDirectory("files"));
skinImporter = new SkinImporter(storage, realm, this) skinImporter = new SkinImporter(storage, realm, this, config)
{ {
PostNotification = obj => PostNotification?.Invoke(obj), PostNotification = obj => PostNotification?.Invoke(obj),
}; };