Skip to content

Commit

Permalink
Consolidate all options/settings to use a consistent WFP MVVM pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert committed Sep 10, 2024
1 parent 30cf7f9 commit c592abc
Show file tree
Hide file tree
Showing 40 changed files with 615 additions and 774 deletions.
4 changes: 2 additions & 2 deletions ICSharpCode.ILSpyX/AssemblyListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public AssemblyListManager(ISettingsProvider settingsProvider)

public bool UseDebugSymbols { get; set; }

public ObservableCollection<string> AssemblyLists { get; } = new ObservableCollection<string>();
public ObservableCollection<string> AssemblyLists { get; } = [];

public FileLoaderRegistry LoaderRegistry { get; } = new FileLoaderRegistry();
public FileLoaderRegistry LoaderRegistry { get; } = new();

/// <summary>
/// Loads an assembly list from the ILSpySettings.
Expand Down
24 changes: 9 additions & 15 deletions ICSharpCode.ILSpyX/Settings/ILSpySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ public void Update(Action<XElement> action)
}
}

void ISettingsProvider.Update(Action<XElement> action)
{
Update(action);
}

static string GetConfigFile()
{
if (null != SettingsFilePathProvider)
Expand All @@ -148,17 +143,16 @@ sealed class MutexProtector : IDisposable

public MutexProtector(string name)
{
bool createdNew;
this.mutex = new Mutex(true, name, out createdNew);
if (!createdNew)
this.mutex = new Mutex(true, name, out bool createdNew);
if (createdNew)
return;

try
{
mutex.WaitOne();
}
catch (AbandonedMutexException)
{
try
{
mutex.WaitOne();
}
catch (AbandonedMutexException)
{
}
}
}

Expand Down
42 changes: 0 additions & 42 deletions ICSharpCode.ILSpyX/Settings/IMiscSettings.cs

This file was deleted.

2 changes: 0 additions & 2 deletions ICSharpCode.ILSpyX/Settings/ISettingsFilePathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
// 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
{
public interface ISettingsFilePathProvider
Expand Down
36 changes: 1 addition & 35 deletions ICSharpCode.ILSpyX/Settings/ISettingsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
// DEALINGS IN THE SOFTWARE.

using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;

namespace ICSharpCode.ILSpyX.Settings
Expand All @@ -30,37 +27,6 @@ public interface ISettingsProvider

void Update(Action<XElement> action);

public static Decompiler.DecompilerSettings LoadDecompilerSettings(ISettingsProvider settingsProvider)
{
XElement e = settingsProvider["DecompilerSettings"];
var newSettings = new Decompiler.DecompilerSettings();
var properties = typeof(Decompiler.DecompilerSettings).GetProperties()
.Where(p => p.GetCustomAttribute<BrowsableAttribute>()?.Browsable != false);
foreach (var p in properties)
{
var value = (bool?)e.Attribute(p.Name);
if (value.HasValue)
p.SetValue(newSettings, value.Value);
}
return newSettings;
}

public static void SaveDecompilerSettings(XElement root, Decompiler.DecompilerSettings newSettings)
{
var properties = typeof(Decompiler.DecompilerSettings).GetProperties()
.Where(p => p.GetCustomAttribute<BrowsableAttribute>()?.Browsable != false);

XElement section = new XElement("DecompilerSettings");
foreach (var p in properties)
{
section.SetAttributeValue(p.Name, p.GetValue(newSettings));
}

XElement? existingElement = root.Element("DecompilerSettings");
if (existingElement != null)
existingElement.ReplaceWith(section);
else
root.Add(section);
}
void SaveSettings(XElement section);
}
}
32 changes: 0 additions & 32 deletions ICSharpCode.ILSpyX/Settings/ISettingsSection.cs

This file was deleted.

14 changes: 8 additions & 6 deletions ILSpy.ReadyToRun/ReadyToRunDisassembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ public void Disassemble(PEFile currentFile, int bitness, ulong address, bool sho
ReadyToRunMethod readyToRunMethod = runtimeFunction.Method;
WriteCommentLine(readyToRunMethod.SignatureString);

if (ReadyToRunOptions.GetIsShowGCInfo(null))
var options = SettingsService.Instance.GetSettings<ReadyToRunOptions>();

if (options.IsShowGCInfo)
{
if (readyToRunMethod.GcInfo != null)
{
string[] lines = readyToRunMethod.GcInfo.ToString().Split(Environment.NewLine);
string[] lines = readyToRunMethod.GcInfo.ToString()?.Split(Environment.NewLine) ?? [];
WriteCommentLine("GC info:");
foreach (string line in lines)
{
Expand All @@ -69,12 +71,12 @@ public void Disassemble(PEFile currentFile, int bitness, ulong address, bool sho
}

Dictionary<ulong, UnwindCode> unwindInfo = null;
if (ReadyToRunOptions.GetIsShowUnwindInfo(null) && bitness == 64)
if (options.IsShowUnwindInfo && bitness == 64)
{
unwindInfo = WriteUnwindInfo();
}

bool isShowDebugInfo = ReadyToRunOptions.GetIsShowDebugInfo(null);
bool isShowDebugInfo = options.IsShowDebugInfo;
DebugInfoHelper debugInfo = null;
if (isShowDebugInfo)
{
Expand All @@ -98,7 +100,7 @@ public void Disassemble(PEFile currentFile, int bitness, ulong address, bool sho
decoder.Decode(out instructions.AllocUninitializedElement());
}

string disassemblyFormat = ReadyToRunOptions.GetDisassemblyFormat(null);
string disassemblyFormat = options.DisassemblyFormat;
Formatter formatter = null;
if (disassemblyFormat.Equals(ReadyToRunOptions.intel))
{
Expand Down Expand Up @@ -145,7 +147,7 @@ public void Disassemble(PEFile currentFile, int bitness, ulong address, bool sho
}
}
}
if (ReadyToRunOptions.GetIsShowGCInfo(null))
if (options.IsShowGCInfo)
{
DecorateGCInfo(instr, baseInstrIP, readyToRunMethod.GcInfo);
}
Expand Down
16 changes: 10 additions & 6 deletions ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<UserControl x:Class="ICSharpCode.ILSpy.ReadyToRun.ReadyToRunOptionPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:properties="clr-namespace:ILSpy.ReadyToRun.Properties"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d:DesignHeight="500" d:DesignWidth="500" mc:Ignorable="d"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:readyToRun="clr-namespace:ICSharpCode.ILSpy.ReadyToRun"
d:DataContext="{d:DesignInstance readyToRun:ReadyToRunOptionsViewModel}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
Expand All @@ -14,12 +18,12 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Margin="3" Text="{x:Static properties:Resources.DisassemblyFormat}" />
<ComboBox Grid.Column="1" Margin="3" ItemsSource="{Binding DisassemblyFormats}" SelectedItem="{Binding DisassemblyFormat}" />
<TextBlock Grid.Row="1" Margin="3" Text="{x:Static properties:Resources.ShowStackUnwindInfo}"/>
<CheckBox Grid.Row="1" Grid.Column="1" Margin="3" IsChecked="{Binding IsShowUnwindInfo}" />
<ComboBox Grid.Row="0" Grid.Column="1" Margin="3" ItemsSource="{Binding Options.DisassemblyFormats}" SelectedItem="{Binding Options.DisassemblyFormat}" />
<TextBlock Grid.Row="1" Grid.Column="0" Margin="3" Text="{x:Static properties:Resources.ShowStackUnwindInfo}"/>
<CheckBox Grid.Row="1" Grid.Column="1" Margin="3" IsChecked="{Binding Options.IsShowUnwindInfo}" />
<TextBlock Grid.Row="2" Margin="3" Text="{x:Static properties:Resources.ShowDebugInfo}"/>
<CheckBox Grid.Row="2" Grid.Column="1" Margin="3" IsChecked="{Binding IsShowDebugInfo}" />
<CheckBox Grid.Row="2" Grid.Column="1" Margin="3" IsChecked="{Binding Options.IsShowDebugInfo}" />
<TextBlock Grid.Row="3" Margin="3" Text="{x:Static properties:Resources.ShowGCInfo}"/>
<CheckBox Grid.Row="3" Grid.Column="1" Margin="3" IsChecked="{Binding IsShowGCInfo}" />
<CheckBox Grid.Row="3" Grid.Column="1" Margin="3" IsChecked="{Binding Options.IsShowGCInfo}" />
</Grid>
</UserControl>
Loading

0 comments on commit c592abc

Please sign in to comment.