Self-contained .NET (#22217)

* dotnet sc

* MD preview - C# app

 - working self-contained

* Gcode preview - C# app

* DevFiles preview - C# app

* Fix passing path with spaces as cmd arg and monacocpp proj file

* Pdf preview - C# app

* Svg preview - C# app

* Fix comment

* Gcode thumbnail - C# app

TODO:
	- installer
	- why IThumbnailProvider and IIntializeWithFile doesn't work?

* Pdf thumbnail - C# app

TODO:
        - installer
        - why IThumbnailProvider and IIntializeWithFile doesn't work?

* Pdf thumbnail - C# app

TODO:
        - installer
        - why IThumbnailProvider and IIntializeWithFile doesn't work?

* Fix GcodeThumbnailProviderCpp.vcxproj

* Svg thumbnail - C# app

TODO:
        - installer
        - why IThumbnailProvider and IIntializeWithFile doesn't work?

* Fix Svg tests

* Thumbnail providers - installer

* Self-contained Hosts and FileLocksmith

* Fix hardcoded <RuntimeIdentifier>

* Remove unneeded files

* Try to fix Nuget in PR CI

* Prefix new dlls with PowerToys.
Sign new dlls and exes

* Add new .exe files to ProcessList

* ci: debug by listing all env vars

* ci: try setting variable in the right ci file

* Bring back hardcoded RuntimeIdentifier

* ci: Add comment and remove debug action

* Remove unneeded lib

* [WIP] Platform conditional dotnet files & hardlinks

* Cleanup

* Update expect.txt

* Test fix - ARM installer

* Fix uninstall bug

* Update docs

* Fix failing test

* Add dll details

* Minor cleanup

* Improve resizing

* Add some logs

* Test fix - release build

* Remove InvokeOnControlThread

* Test fix: logger initialization

* Fix arm64 installer

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
Co-authored-by: Dustin L. Howett <dustin@howett.net>
This commit is contained in:
Stefan Markovic
2022-12-14 13:37:23 +01:00
committed by GitHub
parent a2c0febccc
commit 6ac508fb93
215 changed files with 9060 additions and 2328 deletions

View File

@@ -1,71 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
using Common;
using Microsoft.PowerToys.Telemetry;
namespace Microsoft.PowerToys.PreviewHandler.Gcode
{
/// <summary>
/// Extends <see cref="StreamBasedPreviewHandler"/> for Gcode Preview Handler.
/// </summary>
[Guid("ec52dea8-7c9f-4130-a77b-1737d0418507")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class GcodePreviewHandler : StreamBasedPreviewHandler, IDisposable
{
private GcodePreviewHandlerControl _gcodePreviewControl;
private bool disposedValue;
/// <summary>
/// Initializes a new instance of the <see cref="GcodePreviewHandler"/> class.
/// </summary>
public GcodePreviewHandler()
{
Initialize();
}
/// <inheritdoc/>
public override void DoPreview()
{
_gcodePreviewControl.DoPreview(Stream);
}
/// <inheritdoc/>
protected override IPreviewHandlerControl CreatePreviewHandlerControl()
{
PowerToysTelemetry.Log.WriteEvent(new Telemetry.Events.GcodeFileHandlerLoaded());
_gcodePreviewControl = new GcodePreviewHandlerControl();
return _gcodePreviewControl;
}
/// <summary>
/// Disposes objects
/// </summary>
/// <param name="disposing">Is Disposing</param>
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
_gcodePreviewControl.Dispose();
}
disposedValue = true;
}
}
/// <inheritdoc/>
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View File

@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
<AssemblyTitle>PowerToys.GcodePreviewHandler</AssemblyTitle>
<AssemblyDescription>PowerToys GcodePreviewHandler</AssemblyDescription>
@@ -11,13 +12,21 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
<AssemblyName>PowerToys.GcodePreviewHandler</AssemblyName>
<SelfContained>true</SelfContained>
</PropertyGroup>
<!-- SelfContained=true requires RuntimeIdentifier to be set -->
<PropertyGroup Condition="'$(Platform)'=='x64'">
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='ARM64'">
<RuntimeIdentifier>win10-arm64</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup>
<ProjectGuid>{805306FF-A562-4415-8DEF-E493BDC45918}</ProjectGuid>
<RootNamespace>Microsoft.PowerToys.PreviewHandler.Gcode</RootNamespace>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<EnableComHosting>true</EnableComHosting>
</PropertyGroup>
<Import Project="..\..\..\Version.props" />
@@ -40,6 +49,7 @@
<PropertyGroup>
<!-- Disable missing comment warning. WinRT/C++ libraries added won't have comments on their reflections. -->
<NoWarn>$(NoWarn);1591</NoWarn>
<OutputType>WinExe</OutputType>
</PropertyGroup>
<ItemGroup>
@@ -48,7 +58,9 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\Common.UI\Common.UI.csproj" />
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\interop\PowerToys.Interop.vcxproj" />
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
<ProjectReference Include="..\common\PreviewHandlerCommon.csproj" />
</ItemGroup>

View File

@@ -46,52 +46,50 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredGcodePreviewEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
// GPO is disabling this utility. Show an error message instead.
InvokeOnControlThread(() =>
{
_infoBarAdded = true;
AddTextBoxControl(Properties.Resource.GpoDisabledErrorText);
Resize += FormResized;
base.DoPreview(dataSource);
});
_infoBarAdded = true;
AddTextBoxControl(Properties.Resource.GpoDisabledErrorText);
Resize += FormResized;
base.DoPreview(dataSource);
return;
}
InvokeOnControlThread(() =>
try
{
try
Bitmap thumbnail = null;
if (!(dataSource is string filePath))
{
Bitmap thumbnail = null;
using (var stream = new ReadonlyStream(dataSource as IStream))
{
using (var reader = new StreamReader(stream))
{
thumbnail = GetThumbnail(reader);
}
}
_infoBarAdded = false;
if (thumbnail == null)
{
_infoBarAdded = true;
AddTextBoxControl(Properties.Resource.GcodeWithoutEmbeddedThumbnails);
}
else
{
AddPictureBoxControl(thumbnail);
}
Resize += FormResized;
base.DoPreview(dataSource);
PowerToysTelemetry.Log.WriteEvent(new GcodeFilePreviewed());
throw new ArgumentException($"{nameof(dataSource)} for {nameof(GcodePreviewHandlerControl)} must be a string but was a '{typeof(T)}'");
}
catch (Exception ex)
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
using (var reader = new StreamReader(fs))
{
PreviewError(ex, dataSource);
thumbnail = GetThumbnail(reader);
}
});
_infoBarAdded = false;
if (thumbnail == null)
{
_infoBarAdded = true;
AddTextBoxControl(Properties.Resource.GcodeWithoutEmbeddedThumbnails);
}
else
{
AddPictureBoxControl(thumbnail);
}
Resize += FormResized;
base.DoPreview(fs);
PowerToysTelemetry.Log.WriteEvent(new GcodeFilePreviewed());
}
catch (Exception ex)
{
PreviewError(ex, dataSource);
}
}
/// <summary>

View File

@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.PreviewHandler.Gcode
{
using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
internal static class Program
{
private static CancellationTokenSource _tokenSource = new CancellationTokenSource();
private static GcodePreviewHandlerControl _previewHandlerControl;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main(string[] args)
{
ApplicationConfiguration.Initialize();
if (args != null)
{
if (args.Length == 6)
{
string filePath = args[0];
int hwnd = Convert.ToInt32(args[1], 16);
Rectangle s = default(Rectangle);
int left = Convert.ToInt32(args[2], 10);
int right = Convert.ToInt32(args[3], 10);
int top = Convert.ToInt32(args[4], 10);
int bottom = Convert.ToInt32(args[5], 10);
_previewHandlerControl = new GcodePreviewHandlerControl();
_previewHandlerControl.SetWindow((IntPtr)hwnd, s);
_previewHandlerControl.DoPreview(filePath);
NativeEventWaiter.WaitForEventLoop(
Constants.GcodePreviewResizeEvent(),
() =>
{
Rectangle s = default(Rectangle);
_previewHandlerControl.SetRect(s);
},
Dispatcher.CurrentDispatcher,
_tokenSource.Token);
}
else
{
MessageBox.Show("Wrong number of args: " + args.Length.ToString(CultureInfo.InvariantCulture));
}
}
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
Application.Run();
}
}
}