Pull down LegacyChartResourceManager
.
This commit is contained in:
@@ -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<LegacyChartDetail> {
|
||||
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<Texture2D> cover = null;
|
||||
var metaFile = new FileInfo(Path.Combine(dir.FullName, Extension));
|
||||
if (metaFile.Exists) {
|
||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
}
|
||||
if (meta.cover != null && meta.cover != "") {
|
||||
var coverFile = dir.GetFiles(meta.cover);
|
||||
if (coverFile.Length > 0) {
|
||||
cover = new AsyncDelivery<Texture2D>();
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44f8b6ac1c92fea45b8acbec25f86e1b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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<LegacyChartDetail> {
|
||||
internal abstract class LegacyResourceManager<T> : IPathedResourceManager<T> 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<Texture2D> cover = null;
|
||||
var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
|
||||
if (metaFile.Exists) {
|
||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
}
|
||||
if (meta.cover != null && meta.cover != "") {
|
||||
var coverFile = item.GetFiles(meta.cover);
|
||||
if (coverFile.Length > 0) {
|
||||
cover = new AsyncDelivery<Texture2D>();
|
||||
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<ChartMeta>(reader.ReadToEnd());
|
||||
}
|
||||
|
Reference in New Issue
Block a user