Browse Source

Replace ISettingsFilePathProvider with Func<string> and move IResourceFileHandler to ILSpyX.

pull/3755/head
Siegfried Pammer 2 months ago
parent
commit
e02097dccf
  1. 2
      ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs
  2. 88
      ICSharpCode.ILSpyX/Abstractions/IResourceFileHandler.cs
  3. 40
      ICSharpCode.ILSpyX/Settings/DefaultSettingsFilePathProvider.cs
  4. 10
      ICSharpCode.ILSpyX/Settings/ILSpySettings.cs
  5. 25
      ICSharpCode.ILSpyX/Settings/ISettingsFilePathProvider.cs

2
ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs

@ -371,7 +371,7 @@ Examples: @@ -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<ILSpyX.Settings.DecompilerSettings>();
}

88
ICSharpCode.ILSpyX/Abstractions/IResourceFileHandler.cs

@ -0,0 +1,88 @@ @@ -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
{
/// <summary>
/// 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 <c>[Export(typeof(IResourceFileHandler))]</c> and consulted by the project-export
/// path; the first one to <see cref="CanHandle"/> 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.
/// </summary>
public interface IResourceFileHandler
{
/// <summary>
/// MSBuild item type for the produced project entry — <c>"Page"</c> for BAML→XAML,
/// <c>"EmbeddedResource"</c> for the default raw fallback, etc.
/// </summary>
string EntryType { get; }
/// <summary>Returns true when this handler can process the named resource.</summary>
bool CanHandle(string name, ResourceFileHandlerContext context);
/// <summary>
/// Writes the decoded resource into the project directory (taken from
/// <see cref="ResourceFileHandlerContext.SaveAsProjectDirectory"/>) and returns the
/// resulting file name (relative to that directory). May add partial-type info to
/// <paramref name="context"/> for downstream WPF page x:Class binding.
/// </summary>
string WriteResourceToFile(LoadedAssembly assembly, string fileName, Stream stream, ResourceFileHandlerContext context);
}
/// <summary>
/// Per-project-export context shared across every <see cref="IResourceFileHandler"/>
/// 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.
/// </summary>
public class ResourceFileHandlerContext
{
readonly List<PartialTypeInfo> partialTypes = new();
public List<PartialTypeInfo> PartialTypes => partialTypes;
readonly Dictionary<string, string> additionalProperties = new();
public Dictionary<string, string> 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);
}
}
}

40
ICSharpCode.ILSpyX/Settings/DefaultSettingsFilePathProvider.cs

@ -1,40 +0,0 @@ @@ -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
{
/// <summary>
/// Used in scenarios where the user passes a path and that is to be used, eg ilspycmd parameter
/// </summary>
public class DefaultSettingsFilePathProvider : ISettingsFilePathProvider
{
private readonly string _providedPath;
public DefaultSettingsFilePathProvider(string providedPath)
{
_providedPath = providedPath;
}
public string GetSettingsFilePath()
{
return _providedPath;
}
}
}

10
ICSharpCode.ILSpyX/Settings/ILSpySettings.cs

@ -25,14 +25,14 @@ using System.Xml.Linq; @@ -25,14 +25,14 @@ using System.Xml.Linq;
namespace ICSharpCode.ILSpyX.Settings
{
/// <summary>
/// Manages IL Spy settings.
/// Manages ILSpy settings.
/// </summary>
public class ILSpySettings : ISettingsProvider
{
/// <summary>
/// This settings file path provider determines where to load settings file from, includes filename
/// </summary>
public static ISettingsFilePathProvider? SettingsFilePathProvider { get; set; }
public static Func<string>? SettingsFilePathProvider { get; set; }
XElement root;
@ -125,11 +125,7 @@ namespace ICSharpCode.ILSpyX.Settings @@ -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";

25
ICSharpCode.ILSpyX/Settings/ISettingsFilePathProvider.cs

@ -1,25 +0,0 @@ @@ -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();
}
}
Loading…
Cancel
Save