Skip to content

Commit

Permalink
Prepare support for PublishAot
Browse files Browse the repository at this point in the history
  • Loading branch information
sungaila committed Oct 2, 2024
1 parent f87651c commit 23a4c31
Show file tree
Hide file tree
Showing 32 changed files with 178 additions and 126 deletions.
2 changes: 1 addition & 1 deletion src/App.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity type="win32"
name="Sungaila.SUBSTitute"
version="2.1.0.0" />
version="2.1.1.0" />

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/AddDriveCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static class AddDriveCommands
parameter.SelectedLetter = parameter.AvailableLetters.FirstOrDefault();
});

public static readonly IRelayCommand<AddDriveViewModel> AddVirtualDrive = new AsyncRelayCommand<AddDriveViewModel>(async parameter =>
public static readonly IRelayCommand<AddDriveViewModel> AddVirtualDrive = new RelayCommand<AddDriveViewModel>(parameter =>
{
parameter!.CancelClose = false;

Expand All @@ -55,7 +55,7 @@ public static class AddDriveCommands

var selectedPath = Path.GetFullPath(parameter.SelectedPath.Trim('\"'));

_ = await StorageFolder.GetFolderFromPathAsync(selectedPath);
_ = StorageFolder.GetFolderFromPathAsync(selectedPath).GetAwaiter().GetResult();

if (parameter.IsPermanent)
{
Expand Down
30 changes: 19 additions & 11 deletions src/Commands/MappingCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,29 @@ internal static DriveViewModel GetDriveViewModel(MappingViewModel mappingViewMod

Task.Run(async () =>
{
// get the disk label and file system
string? driveName = null;
string? driveFormat = null;

try
{
var folder = await StorageFolder.GetFolderFromPathAsync(driveInfo.Name);
var properties = await folder.GetBasicPropertiesAsync();
var prop = await properties.RetrievePropertiesAsync(["System.Volume.FileSystem"]);
var filesystem = prop.First().Value as string;

App.MainWindow?.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () =>
{
result.Label = folder.DisplayName;
result.DriveFormat = filesystem ?? string.Empty;
});
driveName = (await StorageFolder.GetFolderFromPathAsync(driveInfo.Name)).DisplayName;
}
catch { }

try
{
driveFormat = driveInfo.DriveFormat;
}
catch (IOException ex) when (ex.HResult == unchecked((int)0x80070015))
{
// ERROR_NOT_READY: Device not ready
}

App.MainWindow?.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () =>
{
result.Label = driveName ?? string.Empty;
result.DriveFormat = driveFormat ?? string.Empty;
});
});

return result;
Expand Down
35 changes: 35 additions & 0 deletions src/Converters/ElementThemeToIntConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using System;

namespace Sungaila.SUBSTitute.Converters
{
public partial class ElementThemeToIntConverter : IValueConverter
{
public object? Convert(object value, Type targetType, object parameter, string language)
{
if (value is not ElementTheme theme)
return DependencyProperty.UnsetValue;

return theme switch
{
ElementTheme.Light => 0,
ElementTheme.Dark => 1,
_ => 2
};
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (value is not int selectedIndex)
return DependencyProperty.UnsetValue;

return selectedIndex switch
{
0 => ElementTheme.Light,
1 => ElementTheme.Dark,
_ => ElementTheme.Default
};
}
}
}
8 changes: 3 additions & 5 deletions src/Extensions/HackedCollectionView.Defer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public IDisposable DeferRefresh()
/// <summary>
/// Notification deferrer helper class
/// </summary>
#pragma warning disable CA1063 // Implement IDisposable Correctly
public partial class NotificationDeferrer : IDisposable
#pragma warning restore CA1063 // Implement IDisposable Correctly
{
private readonly HackedCollectionView _acvs;
private readonly object _currentItem;
Expand All @@ -45,13 +43,13 @@ public NotificationDeferrer(HackedCollectionView acvs)
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <filterpriority>2</filterpriority>
#pragma warning disable CA1063 // Implement IDisposable Correctly
#pragma warning disable CA1816
public void Dispose()
#pragma warning restore CA1063 // Implement IDisposable Correctly
#pragma warning restore CA1816
{
_acvs.MoveCurrentTo(_currentItem);
_acvs._deferCounter--;
_acvs.Refresh();
}
}
}
}
2 changes: 1 addition & 1 deletion src/Extensions/HackedCollectionView.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ private void OnVectorChanged(IVectorChangedEventArgs e)
// ReSharper disable once ExplicitCallerInfoArgument
OnPropertyChanged(nameof(Count));
}
}
}
27 changes: 15 additions & 12 deletions src/Extensions/HackedCollectionView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using CommunityToolkit.WinUI.Collections;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using CommunityToolkit.WinUI.Collections;
using CommunityToolkit.WinUI.Helpers;
using Microsoft.UI.Xaml.Data;
using System;
Expand All @@ -15,6 +19,10 @@

namespace Sungaila.SUBSTitute.Extensions;

/// <summary>
/// A collection view implementation that supports filtering, sorting and incremental loading
/// </summary>
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Item sorting uses reflection to get property types and may not be AOT compatible.")]
public partial class HackedCollectionView : IAdvancedCollectionView, INotifyPropertyChanged, ISupportIncrementalLoading, IComparer<object>
{
private readonly List<object> _view;
Expand All @@ -25,7 +33,7 @@ public partial class HackedCollectionView : IAdvancedCollectionView, INotifyProp

private readonly bool _liveShapingEnabled;

private readonly HashSet<string> _observedFilterProperties = new HashSet<string>();
private readonly HashSet<string> _observedFilterProperties = [];

private IList _source;

Expand All @@ -47,7 +55,6 @@ public HackedCollectionView()
/// </summary>
/// <param name="source">source IEnumerable</param>
/// <param name="isLiveShaping">Denotes whether or not this ACV should re-filter/re-sort if a PropertyChanged is raised for an observed property.</param>
#pragma warning disable CS8767
#pragma warning disable CS8769
#pragma warning disable CS8622
#pragma warning disable CS8600
Expand All @@ -58,10 +65,10 @@ public HackedCollectionView()
public HackedCollectionView(IList source, bool isLiveShaping = false)
{
_liveShapingEnabled = isLiveShaping;
_view = new List<object>();
_sortDescriptions = new ObservableCollection<SortDescription>();
_view = [];
_sortDescriptions = [];
_sortDescriptions.CollectionChanged += SortDescriptions_CollectionChanged;
_sortProperties = new Dictionary<string, PropertyInfo>();
_sortProperties = [];
Source = source;
}

Expand Down Expand Up @@ -378,11 +385,9 @@ public Predicate<object> Filter
/// <param name="x">Object A</param>
/// <param name="y">Object B</param>
/// <returns>Comparison value</returns>
#pragma warning disable CA1033 // Interface methods should be callable by child types
int IComparer<object>.Compare(object x, object y)
#pragma warning restore CA1033 // Interface methods should be callable by child types
{
if (!_sortProperties.Any())
if (_sortProperties.Count == 0)
{
var listType = _source?.GetType();
Type type;
Expand Down Expand Up @@ -802,11 +807,9 @@ private bool MoveCurrentToIndex(int i)
}
}

#pragma warning restore CS8767
#pragma warning restore CS8769
#pragma warning restore CS8622
#pragma warning restore CS8601
#pragma warning restore CS8600
#pragma warning restore CS8604
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#pragma warning restore CS8603 // Possible null reference return.
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
6 changes: 3 additions & 3 deletions src/Extensions/TypeExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Sungaila.SUBSTitute.Extensions
{
[MarkupExtensionReturnType(ReturnType = typeof(string))]
[MarkupExtensionReturnType(ReturnType = typeof(Type))]
public partial class TypeExtension : MarkupExtension
{
public Type? Type { get; set; }

protected override object? ProvideValue() => Type?.FullName;
protected override object? ProvideValue() => Type;

protected override object? ProvideValue(IXamlServiceProvider serviceProvider) => Type?.FullName;
protected override object? ProvideValue(IXamlServiceProvider serviceProvider) => Type;
}
}
25 changes: 11 additions & 14 deletions src/Extensions/VectorChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,30 @@ namespace Sungaila.SUBSTitute.Extensions;
/// <summary>
/// Vector changed EventArgs
/// </summary>
internal partial class VectorChangedEventArgs : IVectorChangedEventArgs
/// <remarks>
/// Initializes a new instance of the <see cref="VectorChangedEventArgs"/> class.
/// </remarks>
/// <param name="cc">collection change type</param>
/// <param name="index">index of item changed</param>
/// <param name="item">item changed</param>
#pragma warning disable CS9113
internal partial class VectorChangedEventArgs(CollectionChange cc, int index = -1, object item = null!) : IVectorChangedEventArgs
#pragma warning restore CS9113
{
/// <summary>
/// Initializes a new instance of the <see cref="VectorChangedEventArgs"/> class.
/// </summary>
/// <param name="cc">collection change type</param>
/// <param name="index">index of item changed</param>
/// <param name="item">item changed</param>
public VectorChangedEventArgs(CollectionChange cc, int index = -1, object item = null!)
{
CollectionChange = cc;
Index = (uint)index;
}

/// <summary>
/// Gets the type of change that occurred in the vector.
/// </summary>
/// <returns>
/// The type of change in the vector.
/// </returns>
public CollectionChange CollectionChange { get; }
public CollectionChange CollectionChange { get; } = cc;

/// <summary>
/// Gets the position where the change occurred in the vector.
/// </summary>
/// <returns>
/// The zero-based position where the change occurred in the vector, if applicable.
/// </returns>
public uint Index { get; }
public uint Index { get; } = (uint)index;
}
3 changes: 0 additions & 3 deletions src/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
DefineDosDevice
QueryDosDevice
IFileOpenDialog
FileOpenDialog
CoCreateInstance
GetWindowPlacement
2 changes: 1 addition & 1 deletion src/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Identity
Name="42088DavidSungaila.426978D2B4847"
Publisher="CN=A7B45941-28FC-4F92-B416-DDCDFFD9BCBC"
Version="2.1.0.0" />
Version="2.1.1.0" />

<mp:PhoneIdentity PhoneProductId="7524fd35-31df-41fe-9a89-532682530c83" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
2 changes: 1 addition & 1 deletion src/Properties/PublishProfiles/win-arm64.pubxml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<PublishAot Condition="'$(ExcludeRestorePackageImports)'=='true' or '$(Configuration)' != 'Debug'">False</PublishAot>
<PublishAot Condition="'$(ExcludeRestorePackageImports)'=='true' or '$(Configuration)' != 'Debug'">True</PublishAot>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Properties/PublishProfiles/win-x64.pubxml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<PublishAot Condition="'$(ExcludeRestorePackageImports)'=='true' or '$(Configuration)' != 'Debug'">False</PublishAot>
<PublishAot Condition="'$(ExcludeRestorePackageImports)'=='true' or '$(Configuration)' != 'Debug'">True</PublishAot>
</PropertyGroup>
</Project>
16 changes: 7 additions & 9 deletions src/SUBSTitute.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
<PackageCertificateThumbprint>8CD1A8DE2BD78D45B0761089D621324F934DA0CA</PackageCertificateThumbprint>
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<IsPackable>false</IsPackable>
<TrimMode>partial</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<TrimMode>full</TrimMode>
<PublishReadyToRunComposite>true</PublishReadyToRunComposite>
</PropertyGroup>

<!-- NuGet -->
<PropertyGroup>
<VersionPrefix>2.1.0</VersionPrefix>
<VersionPrefix>2.1.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Authors>David Sungaila</Authors>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
Expand Down Expand Up @@ -96,16 +95,15 @@
<!-- NuGet packages -->
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="CommunityToolkit.WinUI.Collections" Version="8.1.240916" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.Segmented" Version="8.1.240916" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.1.240916" />
<PackageReference Include="CommunityToolkit.WinUI.Converters" Version="8.1.240916" />
<PackageReference Include="CommunityToolkit.WinUI.Collections" Version="8.2.240918-build.1202" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.Segmented" Version="8.2.240918-build.1202" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.2.240918-build.1202" />
<PackageReference Include="CommunityToolkit.WinUI.Converters" Version="8.2.240918-build.1202" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.2" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.3" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240829007" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240923002" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106" PrivateAssets="all" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="Sungaila.ImmersiveDarkMode.WinUI" Version="1.0.0" />
<PackageReference Include="System.Drawing.Common" Version="8.0.8" />
Expand Down
16 changes: 0 additions & 16 deletions src/TrimmerRoots.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<!-- needed for the FolderPicker -->
<assembly fullname="System.Private.CoreLib">
<type fullname="System.StubHelpers.InterfaceMarshaler" />
</assembly>

<!-- needed for the language name in the settings -->
<assembly fullname="System.Runtime">
<type fullname="System.Globalization.CultureInfo">
<property name="NativeName" />
</type>
</assembly>

<!-- needed for the SettingsExpander -->
<!-- the app crashes when it is expanded (ItemContainerStyleSelector.SelectStyle fails in ItemsRepeater_ElementPrepared) -->
<assembly fullname="Microsoft.WinUI">
<type fullname="Microsoft.UI.Xaml.Controls.StyleSelector" />
</assembly>
</linker>
2 changes: 2 additions & 0 deletions src/ViewModels/AddDriveViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using Sungaila.SUBSTitute.Commands;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using WinRT;

namespace Sungaila.SUBSTitute.ViewModels
{
[GeneratedBindableCustomProperty]
public partial class AddDriveViewModel : ViewModel
{
public required MappingViewModel ParentViewModel { get; init; }
Expand Down
Loading

0 comments on commit 23a4c31

Please sign in to comment.