Implement resource searching and directory items.
This commit is contained in:
@@ -17,9 +17,11 @@ namespace Cryville.Crtr.Browsing {
|
||||
DirectoryInfo _cd;
|
||||
readonly FileSystemWatcher _watcher = new FileSystemWatcher();
|
||||
DirectoryInfo[] _items = new DirectoryInfo[0];
|
||||
DirectoryInfo[] _filteredItems = new DirectoryInfo[0];
|
||||
string _filter = string.Empty;
|
||||
readonly List<string> _dirParts = new List<string>();
|
||||
public IList<string> CurrentDirectory { get { return _dirParts.AsReadOnly(); } }
|
||||
public int Count { get { return _items.Length; } }
|
||||
public int Count { get { return _filteredItems.Length; } }
|
||||
|
||||
static bool _init;
|
||||
|
||||
@@ -56,7 +58,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
|
||||
void ReloadFiles() {
|
||||
_items = _cd.GetDirectories();
|
||||
ItemChanged?.Invoke();
|
||||
ApplyFilter();
|
||||
}
|
||||
void OnDirectoryChange() {
|
||||
string path = Path.Combine(_rootPath, "charts", string.Join(Path.DirectorySeparatorChar, _dirParts));
|
||||
@@ -71,8 +73,9 @@ namespace Cryville.Crtr.Browsing {
|
||||
foreach (string dirPart in dir) _dirParts.Add(dirPart);
|
||||
OnDirectoryChange();
|
||||
}
|
||||
public void OpenDirectory(int id) {
|
||||
_dirParts.Add(_items[id].Name);
|
||||
public bool IsDirectory(int index) { return false; }
|
||||
public void OpenDirectory(int index) {
|
||||
_dirParts.Add(_filteredItems[index].Name);
|
||||
OnDirectoryChange();
|
||||
}
|
||||
public void ReturnToDirectory(int index) {
|
||||
@@ -80,9 +83,22 @@ namespace Cryville.Crtr.Browsing {
|
||||
OnDirectoryChange();
|
||||
}
|
||||
|
||||
public void ApplyFilter(string filter) {
|
||||
_filter = filter;
|
||||
ApplyFilter();
|
||||
}
|
||||
void ApplyFilter() {
|
||||
IEnumerable<DirectoryInfo> items = _items;
|
||||
foreach (var keyword in _filter.Split(' ', StringSplitOptions.RemoveEmptyEntries)) {
|
||||
items = items.Where(i => i.Name.Contains(keyword, StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
_filteredItems = items.ToArray();
|
||||
ItemChanged?.Invoke();
|
||||
}
|
||||
|
||||
public ChartDetail this[int index] {
|
||||
get {
|
||||
var item = _items[index];
|
||||
var item = _filteredItems[index];
|
||||
ChartMeta meta = null;
|
||||
AsyncDelivery<Texture2D> cover = null;
|
||||
var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
|
||||
@@ -108,19 +124,19 @@ namespace Cryville.Crtr.Browsing {
|
||||
}
|
||||
IResourceMeta IResourceManager.this[int index] { get { return this[index]; } }
|
||||
|
||||
public Uri GetItemUri(int id) {
|
||||
var item = _items[id];
|
||||
public Uri GetItemUri(int index) {
|
||||
var item = _filteredItems[index];
|
||||
var meta = new ChartMeta();
|
||||
var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
|
||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
}
|
||||
return new Uri(PlatformConfig.FileProtocolPrefix + Path.Combine(_items[id].FullName, string.Format("{0}.json", meta.data)));
|
||||
return new Uri(PlatformConfig.FileProtocolPrefix + Path.Combine(_filteredItems[index].FullName, string.Format("{0}.json", meta.data)));
|
||||
}
|
||||
|
||||
public bool IsReadOnly { get { return false; } }
|
||||
public void RemoveAt(int index) {
|
||||
_items[index].Delete(true);
|
||||
_filteredItems[index].Delete(true);
|
||||
}
|
||||
public bool ImportFrom(Uri uri) {
|
||||
if (!uri.IsFile) throw new NotSupportedException();
|
||||
|
Reference in New Issue
Block a user