From 0009e3fa1563617cca186cd7e94721fc6a12a5e7 Mon Sep 17 00:00:00 2001 From: Lolginer Date: Tue, 5 Jun 2018 21:19:04 +0200 Subject: [PATCH] Fixed encoding-related crash (#190) Some cultures return invalid code page identifiers. This crashes the program on startup if the exception isn't handled. --- GUI/ImagePreview.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/GUI/ImagePreview.cs b/GUI/ImagePreview.cs index df722758..a8302588 100644 --- a/GUI/ImagePreview.cs +++ b/GUI/ImagePreview.cs @@ -102,9 +102,19 @@ namespace GARbro.GUI internal static IEnumerable GetEncodingList (bool exclude_utf16 = false) { var list = new HashSet(); - list.Add (Encoding.Default); - var oem = CultureInfo.CurrentCulture.TextInfo.OEMCodePage; - list.Add (Encoding.GetEncoding (oem)); + try + { + list.Add(Encoding.Default); + var oem = CultureInfo.CurrentCulture.TextInfo.OEMCodePage; + list.Add(Encoding.GetEncoding(oem)); + } + catch (Exception X) + { + if (X is ArgumentException || X is NotSupportedException) + list.Add(Encoding.GetEncoding(20127)); //default to US-ASCII + else + throw; + } list.Add (Encoding.GetEncoding (932)); list.Add (Encoding.GetEncoding (936)); list.Add (Encoding.UTF8);