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

View File

@ -685,6 +685,9 @@ namespace GARbro.GUI
} }
catch (Exception X) 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); SetStatusText (X.Message);
return false; return false;
} }