Skip to content

Commit

Permalink
Fix crash if SpecialFolder.ApplicationData doesn't exist
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agocke committed Sep 21, 2023
1 parent bc00df4 commit 0270f77
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions ILSpy.Core/ILSpySettings.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}
}

/// <summary>
/// Loads the settings file from disk.
/// </summary>
Expand All @@ -66,12 +66,12 @@ public static ILSpySettings Load()
}
}
}

static XDocument LoadWithoutCheckingCharacters(string fileName)
{
return XDocument.Load(fileName, LoadOptions.None);
}

/// <summary>
/// Saves a setting section.
/// </summary>
Expand All @@ -86,7 +86,7 @@ public static void SaveSettings(XElement section)
root.Add(section);
});
}

/// <summary>
/// Updates the saved settings.
/// We always reload the file on updates to ensure we aren't overwriting unrelated changes performed
Expand All @@ -111,26 +111,26 @@ public static void Update(Action<XElement> action)
doc.Save(config, SaveOptions.None);
}
}

static string GetConfigFile()
{
if (App.CommandLineArguments.ConfigFile != null)
return App.CommandLineArguments.ConfigFile;
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";

/// <summary>
/// Helper class for serializing access to the config file when multiple ILSpy instances are running.
/// </summary>
sealed class MutexProtector : IDisposable
{
readonly Mutex mutex;

public MutexProtector(string name)
{
bool createdNew;
Expand All @@ -142,7 +142,7 @@ public MutexProtector(string name)
}
}
}

public void Dispose()
{
mutex.ReleaseMutex();
Expand Down

0 comments on commit 0270f77

Please sign in to comment.