Implement enumerator for legacy resource manager.
This commit is contained in:
@@ -24,6 +24,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
static bool _init;
|
||||
|
||||
public event Action ItemChanged;
|
||||
int _version;
|
||||
|
||||
public LegacyResourceManager(string rootPath) {
|
||||
_rootPath = rootPath;
|
||||
@@ -38,6 +39,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
cd = new DirectoryInfo(_rootPath + "/charts/" + string.Join("/", dir));
|
||||
items = cd.GetDirectories();
|
||||
ItemChanged?.Invoke();
|
||||
_version++;
|
||||
}
|
||||
|
||||
public void OpenDirectory(int id) {
|
||||
@@ -174,18 +176,39 @@ namespace Cryville.Crtr.Browsing {
|
||||
|
||||
public struct Enumerator : IEnumerator<ChartDetail> {
|
||||
readonly LegacyResourceManager _list;
|
||||
public ChartDetail Current => throw new NotImplementedException();
|
||||
int _index;
|
||||
readonly int _version;
|
||||
ChartDetail _current;
|
||||
public ChartDetail Current => _current;
|
||||
object IEnumerator.Current => Current;
|
||||
|
||||
public Enumerator(LegacyResourceManager list) { _list = list; }
|
||||
public Enumerator(LegacyResourceManager list) {
|
||||
_list = list;
|
||||
_index = 0;
|
||||
_version = list._version;
|
||||
_current = default(ChartDetail);
|
||||
}
|
||||
public void Dispose() { }
|
||||
|
||||
public bool MoveNext() {
|
||||
throw new NotImplementedException();
|
||||
LegacyResourceManager list = _list;
|
||||
if (_version != list._version)
|
||||
throw new InvalidOperationException("Collection was changed.");
|
||||
if (_index < list.Count) {
|
||||
_current = list[_index++];
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
_current = default(ChartDetail);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
throw new NotImplementedException();
|
||||
void IEnumerator.Reset() {
|
||||
if (_version != _list._version)
|
||||
throw new InvalidOperationException("Collection was changed.");
|
||||
_index = 0;
|
||||
_current = default(ChartDetail);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user