mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
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:
@@ -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.Pdf
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of preview handler for pdf files.
|
||||
/// </summary>
|
||||
[Guid("07665729-6243-4746-95b7-79579308d1b2")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ComVisible(true)]
|
||||
public class PdfPreviewHandler : StreamBasedPreviewHandler, IDisposable
|
||||
{
|
||||
private PdfPreviewHandlerControl _pdfPreviewHandlerControl;
|
||||
private bool _disposedValue;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PdfPreviewHandler"/> class.
|
||||
/// </summary>
|
||||
public PdfPreviewHandler()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void DoPreview()
|
||||
{
|
||||
_pdfPreviewHandlerControl.DoPreview(Stream);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IPreviewHandlerControl CreatePreviewHandlerControl()
|
||||
{
|
||||
PowerToysTelemetry.Log.WriteEvent(new Telemetry.Events.PdfFileHandlerLoaded());
|
||||
_pdfPreviewHandlerControl = new PdfPreviewHandlerControl();
|
||||
|
||||
return _pdfPreviewHandlerControl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes objects
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is Disposing</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_pdfPreviewHandlerControl.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<AssemblyTitle>PowerToys.PdfPreviewHandler</AssemblyTitle>
|
||||
<AssemblyDescription>PowerToys PdfPreviewHandler</AssemblyDescription>
|
||||
@@ -10,13 +12,21 @@
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
|
||||
<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>{69E1EE8D-143A-4060-9129-4658ACF14AAF}</ProjectGuid>
|
||||
<RootNamespace>Microsoft.PowerToys.PreviewHandler.Pdf</RootNamespace>
|
||||
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
|
||||
<EnableComHosting>true</EnableComHosting>
|
||||
<AssemblyName>PowerToys.PdfPreviewHandler</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -40,6 +50,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 +59,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>
|
||||
|
||||
@@ -55,12 +55,9 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
|
||||
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredPdfPreviewEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
|
||||
{
|
||||
// GPO is disabling this utility. Show an error message instead.
|
||||
InvokeOnControlThread(() =>
|
||||
{
|
||||
_infoBar = GetTextBoxControl(Resources.GpoDisabledErrorText);
|
||||
Controls.Add(_infoBar);
|
||||
base.DoPreview(dataSource);
|
||||
});
|
||||
_infoBar = GetTextBoxControl(Resources.GpoDisabledErrorText);
|
||||
Controls.Add(_infoBar);
|
||||
base.DoPreview(dataSource);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -69,7 +66,12 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
|
||||
|
||||
try
|
||||
{
|
||||
using (var dataStream = new ReadonlyStream(dataSource as IStream))
|
||||
if (!(dataSource is string filePath))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(dataSource)} for {nameof(PdfPreviewHandlerControl)} must be a string but was a '{typeof(T)}'");
|
||||
}
|
||||
|
||||
using (var dataStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
var memStream = new MemoryStream();
|
||||
dataStream.CopyTo(memStream);
|
||||
@@ -82,77 +84,71 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
|
||||
|
||||
if (pdf.PageCount > 0)
|
||||
{
|
||||
InvokeOnControlThread(() =>
|
||||
_flowLayoutPanel = new FlowLayoutPanel
|
||||
{
|
||||
_flowLayoutPanel = new FlowLayoutPanel
|
||||
{
|
||||
AutoScroll = true,
|
||||
AutoSize = true,
|
||||
Dock = DockStyle.Fill,
|
||||
FlowDirection = FlowDirection.TopDown,
|
||||
WrapContents = false,
|
||||
};
|
||||
_flowLayoutPanel.Resize += FlowLayoutPanel_Resize;
|
||||
AutoScroll = true,
|
||||
AutoSize = true,
|
||||
Dock = DockStyle.Fill,
|
||||
FlowDirection = FlowDirection.TopDown,
|
||||
WrapContents = false,
|
||||
};
|
||||
_flowLayoutPanel.Resize += FlowLayoutPanel_Resize;
|
||||
|
||||
// Only show first 10 pages.
|
||||
for (uint i = 0; i < pdf.PageCount && i < 10; i++)
|
||||
// Only show first 10 pages.
|
||||
for (uint i = 0; i < pdf.PageCount && i < 10; i++)
|
||||
{
|
||||
using (var page = pdf.GetPage(i))
|
||||
{
|
||||
using (var page = pdf.GetPage(i))
|
||||
var image = PageToImage(page);
|
||||
|
||||
var picturePanel = new Panel()
|
||||
{
|
||||
var image = PageToImage(page);
|
||||
|
||||
var picturePanel = new Panel()
|
||||
{
|
||||
Name = "picturePanel",
|
||||
Margin = new Padding(6, 6, 6, 0),
|
||||
Size = CalculateSize(image),
|
||||
BorderStyle = BorderStyle.FixedSingle,
|
||||
};
|
||||
|
||||
var picture = new PictureBox
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
Image = image,
|
||||
SizeMode = PictureBoxSizeMode.Zoom,
|
||||
};
|
||||
|
||||
picturePanel.Controls.Add(picture);
|
||||
_flowLayoutPanel.Controls.Add(picturePanel);
|
||||
}
|
||||
}
|
||||
|
||||
if (pdf.PageCount > 10)
|
||||
{
|
||||
var messageBox = new RichTextBox
|
||||
{
|
||||
Name = "messageBox",
|
||||
Text = Resources.PdfMorePagesMessage,
|
||||
BackColor = Color.LightYellow,
|
||||
Dock = DockStyle.Fill,
|
||||
Multiline = true,
|
||||
ReadOnly = true,
|
||||
ScrollBars = RichTextBoxScrollBars.None,
|
||||
BorderStyle = BorderStyle.None,
|
||||
Name = "picturePanel",
|
||||
Margin = new Padding(6, 6, 6, 0),
|
||||
Size = CalculateSize(image),
|
||||
BorderStyle = BorderStyle.FixedSingle,
|
||||
};
|
||||
messageBox.ContentsResized += RTBContentsResized;
|
||||
|
||||
_flowLayoutPanel.Controls.Add(messageBox);
|
||||
var picture = new PictureBox
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
Image = image,
|
||||
SizeMode = PictureBoxSizeMode.Zoom,
|
||||
};
|
||||
|
||||
picturePanel.Controls.Add(picture);
|
||||
_flowLayoutPanel.Controls.Add(picturePanel);
|
||||
}
|
||||
}
|
||||
|
||||
Controls.Add(_flowLayoutPanel);
|
||||
});
|
||||
if (pdf.PageCount > 10)
|
||||
{
|
||||
var messageBox = new RichTextBox
|
||||
{
|
||||
Name = "messageBox",
|
||||
Text = Resources.PdfMorePagesMessage,
|
||||
BackColor = Color.LightYellow,
|
||||
Dock = DockStyle.Fill,
|
||||
Multiline = true,
|
||||
ReadOnly = true,
|
||||
ScrollBars = RichTextBoxScrollBars.None,
|
||||
BorderStyle = BorderStyle.None,
|
||||
};
|
||||
messageBox.ContentsResized += RTBContentsResized;
|
||||
|
||||
_flowLayoutPanel.Controls.Add(messageBox);
|
||||
}
|
||||
|
||||
Controls.Add(_flowLayoutPanel);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex.Message.Contains("Unable to update the password. The value provided as the current password is incorrect.", StringComparison.Ordinal))
|
||||
{
|
||||
InvokeOnControlThread(() =>
|
||||
{
|
||||
Controls.Clear();
|
||||
_infoBar = GetTextBoxControl(Resources.PdfPasswordProtectedError);
|
||||
Controls.Add(_infoBar);
|
||||
});
|
||||
Controls.Clear();
|
||||
_infoBar = GetTextBoxControl(Resources.PdfPasswordProtectedError);
|
||||
Controls.Add(_infoBar);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -171,12 +167,9 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
|
||||
{
|
||||
PowerToysTelemetry.Log.WriteEvent(new PdfFilePreviewError { Message = ex.Message });
|
||||
|
||||
InvokeOnControlThread(() =>
|
||||
{
|
||||
Controls.Clear();
|
||||
_infoBar = GetTextBoxControl(Resources.PdfNotPreviewedError);
|
||||
Controls.Add(_infoBar);
|
||||
});
|
||||
Controls.Clear();
|
||||
_infoBar = GetTextBoxControl(Resources.PdfNotPreviewedError);
|
||||
Controls.Add(_infoBar);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
63
src/modules/previewpane/PdfPreviewHandler/Program.cs
Normal file
63
src/modules/previewpane/PdfPreviewHandler/Program.cs
Normal 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.Pdf
|
||||
{
|
||||
using System.Globalization;
|
||||
using System.Windows.Threading;
|
||||
using Common.UI;
|
||||
using interop;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
private static CancellationTokenSource _tokenSource = new CancellationTokenSource();
|
||||
|
||||
private static PdfPreviewHandlerControl _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 PdfPreviewHandlerControl();
|
||||
_previewHandlerControl.SetWindow((IntPtr)hwnd, s);
|
||||
_previewHandlerControl.DoPreview(filePath);
|
||||
|
||||
NativeEventWaiter.WaitForEventLoop(
|
||||
Constants.PdfPreviewResizeEvent(),
|
||||
() =>
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user