From 3a377f9198d45ebb40278003f35ffa7f9f05bc78 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 3 Dec 2016 09:32:18 -0800 Subject: [PATCH] Add save detection exception handling Yay for jksv allowing invalid filenames --- PKHeX/Saves/SaveUtil.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/PKHeX/Saves/SaveUtil.cs b/PKHeX/Saves/SaveUtil.cs index 117e937b1..c6c4e1b7a 100644 --- a/PKHeX/Saves/SaveUtil.cs +++ b/PKHeX/Saves/SaveUtil.cs @@ -463,8 +463,18 @@ public static IEnumerable getSavesFromFolder(string folderPath, bool dee { if (!Directory.Exists(folderPath)) return null; - return Directory.GetFiles(folderPath, "*", deep ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) - .Where(f => SizeValidSAV((int)new FileInfo(f).Length)); + string[] files = new string[0]; + try + { + var searchOption = deep ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; + files = Directory.GetFiles(folderPath, "*", searchOption); + } + catch (ArgumentException) + { + Util.Error("Error encountered when detecting saves in the following folder:" + Environment.NewLine + folderPath, + "Advise manually scanning to remove bad filenames from the folder." + Environment.NewLine + "Likely caused via Homebrew creating invalid filenames."); + } + return files.Where(f => SizeValidSAV((int)new FileInfo(f).Length)); } ///