mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +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:
39
src/modules/previewpane/SvgThumbnailProvider/Program.cs
Normal file
39
src/modules/previewpane/SvgThumbnailProvider/Program.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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.ThumbnailHandler.Svg
|
||||
{
|
||||
using System.Globalization;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
private static SvgThumbnailProvider _thumbnailProvider;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
if (args != null)
|
||||
{
|
||||
if (args.Length == 2)
|
||||
{
|
||||
string filePath = args[0];
|
||||
uint cx = Convert.ToUInt32(args[1], 10);
|
||||
|
||||
_thumbnailProvider = new SvgThumbnailProvider(filePath);
|
||||
Bitmap thumbnail = _thumbnailProvider.GetThumbnail(cx);
|
||||
filePath = filePath.Replace(".svg", ".bmp");
|
||||
thumbnail.Save(filePath, System.Drawing.Imaging.ImageFormat.Bmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Gcode thumbnail - wrong number of args: " + args.Length.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
|
||||
<PublishDir>$(PowerToysRoot)\$(Platform)\$(Configuration)\modules\FileExplorerPreview</PublishDir>
|
||||
<RuntimeIdentifier>win10-$(Platform)</RuntimeIdentifier>
|
||||
<SelfContained>false</SelfContained>
|
||||
<SelfContained>true</SelfContained>
|
||||
<PublishSingleFile>False</PublishSingleFile>
|
||||
<PublishReadyToRun>False</PublishReadyToRun>
|
||||
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
// 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.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Windows.Forms;
|
||||
using Common.ComInterlop;
|
||||
using Common.Utilities;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Microsoft.Web.WebView2.WinForms;
|
||||
@@ -21,15 +14,26 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Svg
|
||||
/// <summary>
|
||||
/// SVG Thumbnail Provider.
|
||||
/// </summary>
|
||||
[Guid("36B27788-A8BB-4698-A756-DF9F11F64F84")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ComVisible(true)]
|
||||
public class SvgThumbnailProvider : IInitializeWithStream, IThumbnailProvider, IDisposable
|
||||
public class SvgThumbnailProvider : IDisposable
|
||||
{
|
||||
public SvgThumbnailProvider(string filePath)
|
||||
{
|
||||
FilePath = filePath;
|
||||
if (FilePath != null && File.Exists(FilePath))
|
||||
{
|
||||
Stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file path to the file creating thumbnail for.
|
||||
/// </summary>
|
||||
public string FilePath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the stream object to access file.
|
||||
/// </summary>
|
||||
public IStream Stream { get; private set; }
|
||||
public Stream Stream { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The maximum dimension (width or height) thumbnail we will generate.
|
||||
@@ -254,47 +258,38 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Svg
|
||||
return destImage;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Initialize(IStream pstream, uint grfMode)
|
||||
/// <summary>
|
||||
/// Generate thumbnail bitmap for provided Gcode file/stream.
|
||||
/// </summary>
|
||||
/// <param name="cx">Maximum thumbnail size, in pixels.</param>
|
||||
/// <returns>Generated bitmap</returns>
|
||||
public Bitmap GetThumbnail(uint cx)
|
||||
{
|
||||
// Ignore the grfMode always use read mode to access the file.
|
||||
this.Stream = pstream;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void GetThumbnail(uint cx, out IntPtr phbmp, out WTS_ALPHATYPE pdwAlpha)
|
||||
{
|
||||
phbmp = IntPtr.Zero;
|
||||
pdwAlpha = WTS_ALPHATYPE.WTSAT_UNKNOWN;
|
||||
|
||||
if (cx == 0 || cx > MaxThumbnailSize)
|
||||
{
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredSvgThumbnailsEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
|
||||
{
|
||||
// GPO is disabling this utility.
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
string svgData = null;
|
||||
using (var stream = new ReadonlyStream(this.Stream as IStream))
|
||||
using (var reader = new StreamReader(this.Stream))
|
||||
{
|
||||
using (var reader = new StreamReader(stream))
|
||||
svgData = reader.ReadToEnd();
|
||||
try
|
||||
{
|
||||
// Fixes #17527 - Inkscape v1.1 swapped order of default and svg namespaces in svg file (default first, svg after).
|
||||
// That resulted in parser being unable to parse it correctly and instead of svg, text was previewed.
|
||||
// MS Edge and Firefox also couldn't preview svg files with mentioned order of namespaces definitions.
|
||||
svgData = SvgPreviewHandlerHelper.SwapNamespaces(svgData);
|
||||
svgData = SvgPreviewHandlerHelper.AddStyleSVG(svgData);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
svgData = reader.ReadToEnd();
|
||||
try
|
||||
{
|
||||
// Fixes #17527 - Inkscape v1.1 swapped order of default and svg namespaces in svg file (default first, svg after).
|
||||
// That resulted in parser being unable to parse it correctly and instead of svg, text was previewed.
|
||||
// MS Edge and Firefox also couldn't preview svg files with mentioned order of namespaces definitions.
|
||||
svgData = SvgPreviewHandlerHelper.SwapNamespaces(svgData);
|
||||
svgData = SvgPreviewHandlerHelper.AddStyleSVG(svgData);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,11 +299,12 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Svg
|
||||
{
|
||||
if (thumbnail != null && thumbnail.Size.Width > 0 && thumbnail.Size.Height > 0)
|
||||
{
|
||||
phbmp = thumbnail.GetHbitmap();
|
||||
pdwAlpha = WTS_ALPHATYPE.WTSAT_RGB;
|
||||
return (Bitmap)thumbnail.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ProjectGuid>{8FFE09DA-FA4F-4EE1-B3A2-AD5497FBD1AD}</ProjectGuid>
|
||||
<RootNamespace>Microsoft.PowerToys.ThumbnailHandler.Svg</RootNamespace>
|
||||
@@ -7,7 +8,6 @@
|
||||
<AssemblyTitle>PowerToys.SvgThumbnailProvider</AssemblyTitle>
|
||||
<AssemblyDescription>PowerToys SvgPreviewHandler</AssemblyDescription>
|
||||
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
|
||||
<EnableComHosting>true</EnableComHosting>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Description>PowerToys SvgPreviewHandler</Description>
|
||||
<OutputPath>..\..\..\..\$(Platform)\$(Configuration)\modules\FileExplorerPreview\</OutputPath>
|
||||
@@ -16,6 +16,15 @@
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<RuntimeIdentifiers>win10-x64;win10-arm64</RuntimeIdentifiers>
|
||||
<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>
|
||||
|
||||
<Import Project="..\..\..\Version.props" />
|
||||
@@ -29,6 +38,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>
|
||||
|
||||
Reference in New Issue
Block a user