From 0270f77c97092796dc6766864a411f2f413ad6c3 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 21 Sep 2023 13:54:41 -0700 Subject: [PATCH] Fix crash if SpecialFolder.ApplicationData doesn't exist If the folder doesn't exist, the config variable will be 'ILSpy.xml', and the parent directory name will be an empty string. This will cause CreateDirectory to throw, and the application to potentially crash due to an exception in a background thread. This manifests as a native crash, NSInternalInconsistencyException, on my machine, with the message 'Terminating app due to uncaught exception 'NSInternalInconsistencyException',reason: 'NSWindow drag regions should only be invalidated on the Main Thread'. By passing 'DoNotVerify' to Environment.GetFolderPath we can avoid the check for directory existence and avoid the crash. --- ILSpy.Core/ILSpySettings.cs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/ILSpy.Core/ILSpySettings.cs b/ILSpy.Core/ILSpySettings.cs index 2faf748..f711a8e 100644 --- a/ILSpy.Core/ILSpySettings.cs +++ b/ILSpy.Core/ILSpySettings.cs @@ -1,14 +1,14 @@ // Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team -// +// // Permission is hereby granted, free of charge, to any person obtaining a copy of this // software and associated documentation files (the "Software"), to deal in the Software // without restriction, including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons // to whom the Software is furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in all copies or // substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE @@ -30,23 +30,23 @@ namespace ICSharpCode.ILSpy public class ILSpySettings { readonly XElement root; - + ILSpySettings() { this.root = new XElement("ILSpy"); } - + ILSpySettings(XElement root) { this.root = root; } - + public XElement this[XName section] { get { return root.Element(section) ?? new XElement(section); } } - + /// /// Loads the settings file from disk. /// @@ -66,12 +66,12 @@ public static ILSpySettings Load() } } } - + static XDocument LoadWithoutCheckingCharacters(string fileName) { return XDocument.Load(fileName, LoadOptions.None); } - + /// /// Saves a setting section. /// @@ -86,7 +86,7 @@ public static void SaveSettings(XElement section) root.Add(section); }); } - + /// /// Updates the saved settings. /// We always reload the file on updates to ensure we aren't overwriting unrelated changes performed @@ -111,7 +111,7 @@ public static void Update(Action action) doc.Save(config, SaveOptions.None); } } - + static string GetConfigFile() { if (App.CommandLineArguments.ConfigFile != null) @@ -119,18 +119,18 @@ static string GetConfigFile() string localPath = Path.Combine(AppContext.BaseDirectory, "ILSpy.xml"); if (File.Exists(localPath)) return localPath; - return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ILSpy.xml"); + return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify), "ILSpy.xml"); } - + const string ConfigFileMutex = "01A91708-49D1-410D-B8EB-4DE2662B3971"; - + /// /// Helper class for serializing access to the config file when multiple ILSpy instances are running. /// sealed class MutexProtector : IDisposable { readonly Mutex mutex; - + public MutexProtector(string name) { bool createdNew; @@ -142,7 +142,7 @@ public MutexProtector(string name) } } } - + public void Dispose() { mutex.ReleaseMutex();