diff --git a/osu.Game.Rulesets.IGPlayer/Feature/Gosumemory/GosuRealmDirectAccessor.cs b/osu.Game.Rulesets.IGPlayer/Feature/Gosumemory/GosuRealmDirectAccessor.cs index a4d5a14..329c4ce 100644 --- a/osu.Game.Rulesets.IGPlayer/Feature/Gosumemory/GosuRealmDirectAccessor.cs +++ b/osu.Game.Rulesets.IGPlayer/Feature/Gosumemory/GosuRealmDirectAccessor.cs @@ -39,6 +39,12 @@ private string storageRoot() return storage.GetFullPath("."); } + public Task ExportSingleTask(BeatmapSetInfo setInfo, string targetFile, string? desti) + { + string? val = ExportFileSingle(setInfo, targetFile, desti); + return Task.FromResult(val); + } + public string? ExportFileSingle(BeatmapSetInfo setInfo, string targetFile, string? desti) { try @@ -89,12 +95,13 @@ private string storageRoot() if (!parent.Exists) parent.Create(); - Logger.Log($"Trying copy {path} to {desti}"); + //Logger.Log($"Trying copy {path} to {desti}"); if (File.Exists(desti)) { - File.Delete(desti); - Logger.Log("File already exists! Replacing..."); + //File.Delete(desti); + //Logger.Log("File already exists! Skipping..."); + return desti; } File.Copy(path, desti); @@ -111,16 +118,7 @@ private string getRealmedFileName(string hash) { string str = Path.Combine(hash[..1], hash[..2], hash); - Logger.Log("File is located at " + str); + //Logger.Log("File is located at " + str); return str; } - - private void buildTree() - { - var allBeatmaps = realm.All(); - - foreach (BeatmapSetInfo setInfo in allBeatmaps) - { - } - } } diff --git a/osu.Game.Rulesets.IGPlayer/Feature/Gosumemory/Tracker/BeatmapTracker.cs b/osu.Game.Rulesets.IGPlayer/Feature/Gosumemory/Tracker/BeatmapTracker.cs index 14f6c7f..b014688 100644 --- a/osu.Game.Rulesets.IGPlayer/Feature/Gosumemory/Tracker/BeatmapTracker.cs +++ b/osu.Game.Rulesets.IGPlayer/Feature/Gosumemory/Tracker/BeatmapTracker.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using osu.Framework.Allocation; using osu.Framework.Bindables; -using osu.Framework.Logging; using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Database; @@ -43,7 +42,19 @@ private void load(Bindable globalBeatmap) private string staticRoot() { - return storage.GetFullPath("static", true); + string? path = storage.GetFullPath("gosu_statics", true); + + try + { + if (!Path.Exists(path)) + Directory.CreateDirectory(path); + } + catch (Exception e) + { + Logging.LogError(e, "Unable to create statics directory"); + } + + return path; } protected override void LoadComplete() @@ -101,7 +112,7 @@ private void onBeatmapChanged(WorkingBeatmap newBeatmap) { Hub.GetDataRoot().UpdateBeatmap(newBeatmap); - Logger.Log($"~BACKGROUND IS {newBeatmap.Metadata.BackgroundFile}"); + //Logger.Log($"~BACKGROUND IS {newBeatmap.Metadata.BackgroundFile}"); updateFileSupporters(newBeatmap.BeatmapSetInfo, newBeatmap); this.onModsChanged(this.mods.Value); @@ -132,30 +143,46 @@ private void updateFileSupporters(BeatmapSetInfo setInfo, WorkingBeatmap beatmap if (directAccessor == null) return; - string root = staticRoot(); - - if (directAccessor == null) return; + if (beatmap.Metadata.BackgroundFile == null) + { + var dataRoot = Hub.GetDataRoot(); + string defaultVal = "_default.png"; - string? final = directAccessor.ExportFileSingle(setInfo, beatmap.Metadata.BackgroundFile, $"{root}/cover_{beatmap.GetHashCode()}"); + dataRoot.MenuValues.GosuBeatmapInfo.Path.BackgroundPath = defaultVal; + dataRoot.MenuValues.GosuBeatmapInfo.Path.BgPath = defaultVal; + return; + } - if (final == null) return; + string root = staticRoot(); - Logger.Log("~~~PUSH TO GOSU!"); - var dataRoot = Hub.GetDataRoot(); + Task.Run(async () => + { + string? final = await directAccessor.ExportSingleTask(setInfo, beatmap.Metadata.BackgroundFile, $"{root}/{beatmap.BeatmapSetInfo.OnlineID}_{beatmap.Metadata.BackgroundFile.GetHashCode()}") + .ConfigureAwait(false); - string boardcast = final.Replace(root, "").Replace("/", ""); - Logger.Log("~~~BOARDCAST IS " + boardcast); - dataRoot.MenuValues.GosuBeatmapInfo.Path.BackgroundPath = boardcast; - dataRoot.MenuValues.GosuBeatmapInfo.Path.BgPath = boardcast; + if (final == null) return; - try - { - var server = Hub.GetWsLoader()?.Server; - server?.AddStaticContent(staticRoot(), "/Songs"); - } - catch (Exception e) - { - Logging.LogError(e, "Unable to add cache"); - } + this.Schedule(() => + { + //Logger.Log("~~~PUSH TO GOSU!"); + var dataRoot = Hub.GetDataRoot(); + + string boardcast = final.Replace(root, "").Replace("/", ""); + //Logger.Log("~~~BOARDCAST IS " + boardcast); + dataRoot.MenuValues.GosuBeatmapInfo.Path.BackgroundPath = boardcast; + dataRoot.MenuValues.GosuBeatmapInfo.Path.BgPath = boardcast; + + try + { + var server = Hub.GetWsLoader()?.Server; + server?.RemoveStaticContent(staticRoot()); + server?.AddStaticContent(staticRoot(), "/Songs"); + } + catch (Exception e) + { + Logging.LogError(e, "Unable to add cache"); + } + }); + }); } }