From 3916cd94a11025f0e45c2108c962a18b13207b23 Mon Sep 17 00:00:00 2001 From: Joe Tretter Date: Tue, 27 Jul 2021 08:16:29 -0500 Subject: [PATCH] Error handling for corrupt images. --- WPicView/MainWindow.xaml.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/WPicView/MainWindow.xaml.cs b/WPicView/MainWindow.xaml.cs index 86959c0..8bd2a79 100644 --- a/WPicView/MainWindow.xaml.cs +++ b/WPicView/MainWindow.xaml.cs @@ -40,13 +40,21 @@ namespace WPicView dPos = allDirs.Length - 1; allFiles = System.IO.Directory.GetFiles(allDirs[dPos], searchPattern); fPos = allFiles.Length-1; - this.Title = allFiles[fPos]; - IMG1.Source = new BitmapImage(new Uri(allFiles[fPos])); + showFile(allFiles[fPos]); group.Children.Add(st); group.Children.Add(tt); } + private void showFile(String fileName) { + this.Title = allFiles[fPos]; + try { + IMG1.Source = new BitmapImage(new Uri(fileName)); + } catch (Exception ex) { + this.Title = "ERRROR LOADING FILE " + this.Title; + } + } + private void OnKeyDownHandler(object sender, KeyEventArgs e) { // Directory Navigation @@ -102,8 +110,7 @@ namespace WPicView // Display file if (allFiles.Length > 0) { - this.Title = allFiles[fPos]; - IMG1.Source = new BitmapImage(new Uri(allFiles[fPos])); + showFile(allFiles[fPos]); } // zoom - TODO