(EntryViewModel): ignore invalid characters in filenames.

This commit is contained in:
morkt 2016-10-14 10:21:50 +04:00
parent 3391bcfa46
commit 21652280df

View File

@ -78,10 +78,23 @@ namespace GARbro.GUI
public EntryViewModel (Entry entry, int priority) public EntryViewModel (Entry entry, int priority)
{ {
Source = entry; Source = entry;
Name = Path.GetFileName (entry.Name); Name = SafeGetFileName (entry.Name);
Priority = priority; Priority = priority;
} }
static char[] SeparatorCharacters = { '\\', '/', ':' };
/// <summary>
/// Same as Path.GetFileName, but ignores invalid charactes
/// </summary>
string SafeGetFileName (string filename)
{
var name_start = filename.LastIndexOfAny (SeparatorCharacters);
if (-1 == name_start)
return filename;
return filename.Substring (name_start+1);
}
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public Entry Source { get; private set; } public Entry Source { get; private set; }