From 21652280df7a2becba9cd46e2eae532d11d36734 Mon Sep 17 00:00:00 2001 From: morkt Date: Fri, 14 Oct 2016 10:21:50 +0400 Subject: [PATCH] (EntryViewModel): ignore invalid characters in filenames. --- GUI/ViewModel.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/GUI/ViewModel.cs b/GUI/ViewModel.cs index 10dc8690..408f8c56 100644 --- a/GUI/ViewModel.cs +++ b/GUI/ViewModel.cs @@ -78,10 +78,23 @@ namespace GARbro.GUI public EntryViewModel (Entry entry, int priority) { Source = entry; - Name = Path.GetFileName (entry.Name); + Name = SafeGetFileName (entry.Name); Priority = priority; } + static char[] SeparatorCharacters = { '\\', '/', ':' }; + + /// + /// Same as Path.GetFileName, but ignores invalid charactes + /// + 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 Entry Source { get; private set; }