fixed filesystem traversal.

This commit is contained in:
morkt 2015-09-22 22:39:10 +04:00
parent 6481dee23c
commit f9448e4613
2 changed files with 15 additions and 21 deletions

View File

@ -582,31 +582,22 @@ namespace GameRes
if (!value.Any())
return;
var desired = value.ToArray();
if (desired.Length == Count)
int desired_vfs_count = desired.Length;
var arc_iterator = m_vfs.ArcStack.Reverse().GetEnumerator();
int i = 0;
while (i < desired_vfs_count - 1 && arc_iterator.MoveNext())
{
var cur_stack = m_vfs.ArcStack.Reverse();
if (1 == Count || cur_stack.SequenceEqual (desired.Take (desired.Length-1)))
if (arc_iterator.Current != desired[i])
break;
++i;
}
while (Count > i+1)
m_vfs.Pop();
while (Count < desired_vfs_count)
{
// desired path is identical to current, adjust final component only
m_vfs.ChDir (m_vfs.Top.FindFile (desired[Count-1]));
}
m_vfs.Top.CurrentDirectory = desired.Last();
return;
}
}
// desired path is different, rebuild filesystem hierarchy from scratch
var new_vfs = new FileSystemStack();
try
{
for (int i = 0; i < desired.Length-1; ++i)
new_vfs.ChDir (new_vfs.Top.FindFile (desired[i]));
new_vfs.Top.CurrentDirectory = desired.Last();
m_vfs.Dispose();
}
catch
{
new_vfs.Dispose();
throw;
}
m_vfs = new_vfs;
}
}

View File

@ -685,6 +685,9 @@ namespace GARbro.GUI
}
catch (Exception X)
{
// if VFS.FullPath throws an exception, ViewModel becomes inconsistent at this point
// and should be rebuilt
ViewModel = CreateViewModel (VFS.Top.CurrentDirectory, true);
SetStatusText (X.Message);
return false;
}