From 4dd4c5f20dd8c822316bf2fdc72e6d7db1d91c89 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Tue, 19 Dec 2023 16:47:21 +0800 Subject: [PATCH] Pull down `LegacyChartResourceManager`. --- .../Legacy/LegacyChartResourceManager.cs | 41 +++++++++++++++++++ .../Legacy/LegacyChartResourceManager.cs.meta | 11 +++++ .../Browsing/Legacy/LegacyResourceManager.cs | 40 +++++------------- 3 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 Assets/Cryville/Crtr/Browsing/Legacy/LegacyChartResourceManager.cs create mode 100644 Assets/Cryville/Crtr/Browsing/Legacy/LegacyChartResourceManager.cs.meta diff --git a/Assets/Cryville/Crtr/Browsing/Legacy/LegacyChartResourceManager.cs b/Assets/Cryville/Crtr/Browsing/Legacy/LegacyChartResourceManager.cs new file mode 100644 index 0000000..43ee3ce --- /dev/null +++ b/Assets/Cryville/Crtr/Browsing/Legacy/LegacyChartResourceManager.cs @@ -0,0 +1,41 @@ +using Cryville.Common.Unity; +using Cryville.Common; +using Cryville.Crtr.Extension; +using Newtonsoft.Json; +using System.IO; +using UnityEngine; + +namespace Cryville.Crtr.Browsing.Legacy { + internal class LegacyChartResourceManager : LegacyResourceManager { + protected override string Extension { get { return ".umgc"; } } + + public LegacyChartResourceManager(string rootPath) : base(rootPath) { } + + protected override string GetSubRootPath(string rootPath) { + return Path.Combine(rootPath, "charts"); + } + protected override LegacyChartDetail GetMeta(DirectoryInfo dir) { + ChartMeta meta = null; + AsyncDelivery cover = null; + var metaFile = new FileInfo(Path.Combine(dir.FullName, Extension)); + if (metaFile.Exists) { + using (var reader = new StreamReader(metaFile.FullName)) { + meta = JsonConvert.DeserializeObject(reader.ReadToEnd()); + } + if (meta.cover != null && meta.cover != "") { + var coverFile = dir.GetFiles(meta.cover); + if (coverFile.Length > 0) { + cover = new AsyncDelivery(); + var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver); + cover.CancelSource = task.Cancel; + Game.NetworkTaskWorker.SubmitNetworkTask(task); + } + } + } + return new LegacyChartDetail { + Cover = cover, + Meta = meta, + }; + } + } +} diff --git a/Assets/Cryville/Crtr/Browsing/Legacy/LegacyChartResourceManager.cs.meta b/Assets/Cryville/Crtr/Browsing/Legacy/LegacyChartResourceManager.cs.meta new file mode 100644 index 0000000..f175acc --- /dev/null +++ b/Assets/Cryville/Crtr/Browsing/Legacy/LegacyChartResourceManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 44f8b6ac1c92fea45b8acbec25f86e1b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceManager.cs b/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceManager.cs index 5419a08..42d5fb1 100644 --- a/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceManager.cs +++ b/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceManager.cs @@ -1,5 +1,3 @@ -using Cryville.Common; -using Cryville.Common.Unity; using Cryville.Crtr.Extension; using Cryville.Crtr.Extensions; using Cryville.Crtr.Extensions.Umg; @@ -9,10 +7,9 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using UnityEngine; namespace Cryville.Crtr.Browsing.Legacy { - internal class LegacyResourceManager : IPathedResourceManager { + internal abstract class LegacyResourceManager : IPathedResourceManager where T : IResourceMeta { readonly string _rootPath; DirectoryInfo _cd; readonly FileSystemWatcher _watcher = new FileSystemWatcher(); @@ -58,12 +55,13 @@ namespace Cryville.Crtr.Browsing.Legacy { _watcher.EnableRaisingEvents = false; } + protected abstract string GetSubRootPath(string rootPath); void ReloadFiles() { _items = _cd.GetDirectories(); ApplyFilter(); } void OnDirectoryChange() { - string path = Path.Combine(_rootPath, "charts", string.Join(Path.DirectorySeparatorChar, _dirParts)); + string path = Path.Combine(GetSubRootPath(_rootPath), string.Join(Path.DirectorySeparatorChar, _dirParts)); _cd = new DirectoryInfo(path); _watcher.Path = path; _watcher.EnableRaisingEvents = true; @@ -75,7 +73,9 @@ namespace Cryville.Crtr.Browsing.Legacy { foreach (string dirPart in dir) _dirParts.Add(dirPart); OnDirectoryChange(); } - public bool IsDirectory(int index) { return false; } + public bool IsDirectory(int index) { + return _filteredItems[index].GetFiles(Extension).Length == 0; + } public void OpenDirectory(int index) { _dirParts.Add(_filteredItems[index].Name); OnDirectoryChange(); @@ -98,38 +98,20 @@ namespace Cryville.Crtr.Browsing.Legacy { ItemChanged?.Invoke(); } - public LegacyChartDetail this[int index] { + protected abstract T GetMeta(DirectoryInfo dir); + public T this[int index] { get { var item = _filteredItems[index]; - ChartMeta meta = null; - AsyncDelivery cover = null; - var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc")); - if (metaFile.Exists) { - using (var reader = new StreamReader(metaFile.FullName)) { - meta = JsonConvert.DeserializeObject(reader.ReadToEnd()); - } - if (meta.cover != null && meta.cover != "") { - var coverFile = item.GetFiles(meta.cover); - if (coverFile.Length > 0) { - cover = new AsyncDelivery(); - var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver); - cover.CancelSource = task.Cancel; - Game.NetworkTaskWorker.SubmitNetworkTask(task); - } - } - } - return new LegacyChartDetail { - Cover = cover, - Meta = meta, - }; + return GetMeta(item); } } IResourceMeta IResourceManager.this[int index] { get { return this[index]; } } + protected abstract string Extension { get; } public Uri GetItemUri(int index) { var item = _filteredItems[index]; var meta = new ChartMeta(); - var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc")); + var metaFile = new FileInfo(Path.Combine(item.FullName, Extension)); using (var reader = new StreamReader(metaFile.FullName)) { meta = JsonConvert.DeserializeObject(reader.ReadToEnd()); }