diff --git a/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs b/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs index 4dcc350b3..221b74e09 100644 --- a/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs +++ b/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs @@ -371,7 +371,7 @@ Examples: { try { - ILSpyX.Settings.ILSpySettings.SettingsFilePathProvider = new ILSpyX.Settings.DefaultSettingsFilePathProvider(ILSpySettingsFile); + ILSpyX.Settings.ILSpySettings.SettingsFilePathProvider = () => ILSpySettingsFile; var settingsService = new ILSpyX.Settings.SettingsServiceBase(ILSpyX.Settings.ILSpySettings.Load()); decompilerSettings = settingsService.GetSettings(); } diff --git a/ICSharpCode.ILSpyX/Abstractions/IResourceFileHandler.cs b/ICSharpCode.ILSpyX/Abstractions/IResourceFileHandler.cs new file mode 100644 index 000000000..5f9b4ef8a --- /dev/null +++ b/ICSharpCode.ILSpyX/Abstractions/IResourceFileHandler.cs @@ -0,0 +1,88 @@ +// Copyright (c) 2026 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 +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System.Collections.Generic; +using System.IO; +using System.Threading; + +using ICSharpCode.Decompiler; + +namespace ICSharpCode.ILSpyX.Abstractions +{ + /// + /// Plug-in contract for converting a resource entry from its raw byte form into a + /// language-specific source file during project export. Implementations are MEF-discovered + /// via [Export(typeof(IResourceFileHandler))] and consulted by the project-export + /// path; the first one to the resource wins. The handler returns + /// the on-disk file name it emitted so the project file picks the right MSBuild item group + /// + Generator / SubType properties. + /// + public interface IResourceFileHandler + { + /// + /// MSBuild item type for the produced project entry — "Page" for BAML→XAML, + /// "EmbeddedResource" for the default raw fallback, etc. + /// + string EntryType { get; } + + /// Returns true when this handler can process the named resource. + bool CanHandle(string name, ResourceFileHandlerContext context); + + /// + /// Writes the decoded resource into the project directory (taken from + /// ) and returns the + /// resulting file name (relative to that directory). May add partial-type info to + /// for downstream WPF page x:Class binding. + /// + string WriteResourceToFile(LoadedAssembly assembly, string fileName, Stream stream, ResourceFileHandlerContext context); + } + + /// + /// Per-project-export context shared across every + /// invocation in a single export run. Carries the three host-supplied parameters the + /// handler actually needs (settings, cancellation, output directory) and collects + /// partial-type info + additional MSBuild properties for the project file emitter to + /// stitch into the produced .csproj. Lives in ILSpyX rather than in the host so plugin + /// authors and headless consumers like ilspycmd can implement and host handlers + /// without depending on the GUI app. + /// + public class ResourceFileHandlerContext + { + readonly List partialTypes = new(); + public List PartialTypes => partialTypes; + + readonly Dictionary additionalProperties = new(); + public Dictionary AdditionalProperties => additionalProperties; + + public DecompilerSettings DecompilerSettings { get; } + public CancellationToken CancellationToken { get; } + public string? SaveAsProjectDirectory { get; } + + public ResourceFileHandlerContext(DecompilerSettings decompilerSettings, CancellationToken cancellationToken, string? saveAsProjectDirectory) + { + this.DecompilerSettings = decompilerSettings; + this.CancellationToken = cancellationToken; + this.SaveAsProjectDirectory = saveAsProjectDirectory; + } + + public void AddPartialTypeInfo(PartialTypeInfo info) + { + this.PartialTypes.Add(info); + } + } +} diff --git a/ICSharpCode.ILSpyX/Settings/DefaultSettingsFilePathProvider.cs b/ICSharpCode.ILSpyX/Settings/DefaultSettingsFilePathProvider.cs deleted file mode 100644 index f40d303f4..000000000 --- a/ICSharpCode.ILSpyX/Settings/DefaultSettingsFilePathProvider.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2022 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 -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -using System; - -namespace ICSharpCode.ILSpyX.Settings -{ - /// - /// Used in scenarios where the user passes a path and that is to be used, eg ilspycmd parameter - /// - public class DefaultSettingsFilePathProvider : ISettingsFilePathProvider - { - private readonly string _providedPath; - - public DefaultSettingsFilePathProvider(string providedPath) - { - _providedPath = providedPath; - } - - public string GetSettingsFilePath() - { - return _providedPath; - } - } -} diff --git a/ICSharpCode.ILSpyX/Settings/ILSpySettings.cs b/ICSharpCode.ILSpyX/Settings/ILSpySettings.cs index c1d830ae0..4abb404f3 100644 --- a/ICSharpCode.ILSpyX/Settings/ILSpySettings.cs +++ b/ICSharpCode.ILSpyX/Settings/ILSpySettings.cs @@ -25,14 +25,14 @@ using System.Xml.Linq; namespace ICSharpCode.ILSpyX.Settings { /// - /// Manages IL Spy settings. + /// Manages ILSpy settings. /// public class ILSpySettings : ISettingsProvider { /// /// This settings file path provider determines where to load settings file from, includes filename /// - public static ISettingsFilePathProvider? SettingsFilePathProvider { get; set; } + public static Func? SettingsFilePathProvider { get; set; } XElement root; @@ -125,11 +125,7 @@ namespace ICSharpCode.ILSpyX.Settings static string GetConfigFile() { - if (null != SettingsFilePathProvider) - return SettingsFilePathProvider.GetSettingsFilePath(); - - throw new ArgumentNullException(nameof(SettingsFilePathProvider)); - // return "ILSpy.xml"; + return SettingsFilePathProvider?.Invoke() ?? throw new ArgumentNullException(nameof(SettingsFilePathProvider)); } const string ConfigFileMutex = "01A91708-49D1-410D-B8EB-4DE2662B3971"; diff --git a/ICSharpCode.ILSpyX/Settings/ISettingsFilePathProvider.cs b/ICSharpCode.ILSpyX/Settings/ISettingsFilePathProvider.cs deleted file mode 100644 index d411eebbe..000000000 --- a/ICSharpCode.ILSpyX/Settings/ISettingsFilePathProvider.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2022 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 -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -namespace ICSharpCode.ILSpyX.Settings -{ - public interface ISettingsFilePathProvider - { - string GetSettingsFilePath(); - } -}