mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-07-07 11:00:32 +02:00
Compare commits
3 Commits
copilot/fi
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb4356bdee | ||
|
|
c93ecb49c5 | ||
|
|
2db145c56a |
@@ -55,13 +55,18 @@ namespace Wox.Infrastructure.Image
|
||||
return fs.Read(buffer, 0, buffer.Length) == buffer.Length && pngSignature.SequenceEqual(buffer);
|
||||
}
|
||||
|
||||
internal static string GetNormalizedPath(string path)
|
||||
{
|
||||
return PathNormalization.NormalizePath(path);
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
_hashGenerator = new ImageHashGenerator();
|
||||
|
||||
foreach (var icon in new[] { Constant.ErrorIcon, Constant.LightThemedErrorIcon })
|
||||
{
|
||||
var uri = new Uri(icon);
|
||||
var uri = new Uri(GetNormalizedPath(icon));
|
||||
|
||||
try
|
||||
{
|
||||
@@ -298,7 +303,7 @@ namespace Wox.Infrastructure.Image
|
||||
BitmapImage image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
image.UriSource = new Uri(path);
|
||||
image.UriSource = new Uri(GetNormalizedPath(path));
|
||||
image.EndInit();
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Wox.Plugin
|
||||
public static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location.NonNull()).ProductVersion;
|
||||
|
||||
public static readonly int ThumbnailSize = 64;
|
||||
public static readonly string ErrorIcon = Path.Combine(ProgramDirectory, "Assets", "PowerLauncher", "app_error.dark.png");
|
||||
public static readonly string LightThemedErrorIcon = Path.Combine(ProgramDirectory, "Assets", "PowerLauncher", "app_error.light.png");
|
||||
public static readonly string ErrorIcon = PathNormalization.NormalizePath(Path.Combine(ProgramDirectory, "Assets", "PowerLauncher", "app_error.dark.png"));
|
||||
public static readonly string LightThemedErrorIcon = PathNormalization.NormalizePath(Path.Combine(ProgramDirectory, "Assets", "PowerLauncher", "app_error.light.png"));
|
||||
}
|
||||
}
|
||||
|
||||
29
src/modules/launcher/Wox.Plugin/PathNormalization.cs
Normal file
29
src/modules/launcher/Wox.Plugin/PathNormalization.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
// 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;
|
||||
|
||||
namespace Wox.Plugin
|
||||
{
|
||||
public static class PathNormalization
|
||||
{
|
||||
private const string UncPrefix = @"\\?\UNC\";
|
||||
private const string ExtendedPrefix = @"\\?\";
|
||||
|
||||
public static string NormalizePath(string path)
|
||||
{
|
||||
if (path.StartsWith(UncPrefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return @"\\" + path.Substring(UncPrefix.Length);
|
||||
}
|
||||
|
||||
if (path.StartsWith(ExtendedPrefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return path.Substring(ExtendedPrefix.Length);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
src/modules/launcher/Wox.Test/ImageLoaderTest.cs
Normal file
41
src/modules/launcher/Wox.Test/ImageLoaderTest.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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 Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Test
|
||||
{
|
||||
[TestClass]
|
||||
public class ImageLoaderTest
|
||||
{
|
||||
[DataTestMethod]
|
||||
|
||||
// Regular Windows paths should be returned unchanged
|
||||
[DataRow(@"C:\path\to\file.png", @"C:\path\to\file.png")]
|
||||
[DataRow(@"C:\Program Files\PowerToys\Assets\PowerLauncher\app_error.dark.png", @"C:\Program Files\PowerToys\Assets\PowerLauncher\app_error.dark.png")]
|
||||
|
||||
// UNC paths should be returned unchanged
|
||||
[DataRow(@"\\server\share\path\file.png", @"\\server\share\path\file.png")]
|
||||
|
||||
// Extended-length local paths (\\?\C:\...) should have the \\?\ prefix stripped
|
||||
[DataRow(@"\\?\C:\path\to\file.png", @"C:\path\to\file.png")]
|
||||
[DataRow(@"\\?\C:\Program Files\PowerToys\Assets\app_error.dark.png", @"C:\Program Files\PowerToys\Assets\app_error.dark.png")]
|
||||
|
||||
// Extended-length UNC paths (\\?\UNC\server\...) should be converted to \\server\...
|
||||
[DataRow(@"\\?\UNC\server\share\path\file.png", @"\\server\share\path\file.png")]
|
||||
[DataRow(@"\\?\UNC\TH50\TH50_c\Program Files\PowerToys\Assets\PowerLauncher\app_error.dark.png", @"\\TH50\TH50_c\Program Files\PowerToys\Assets\PowerLauncher\app_error.dark.png")]
|
||||
|
||||
// Case-insensitive matching for the prefix
|
||||
[DataRow(@"\\?\unc\server\share\path\file.png", @"\\server\share\path\file.png")]
|
||||
public void GetNormalizedPath_ShouldStripExtendedLengthPrefix(string input, string expected)
|
||||
{
|
||||
// Act
|
||||
string result = PathNormalization.NormalizePath(input);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +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.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ViewModelTests
|
||||
{
|
||||
[TestClass]
|
||||
public class NewPlus
|
||||
{
|
||||
[TestMethod]
|
||||
public void CreateExplorerProcessStartInfoShouldQuoteTemplatePathAndUseFullExplorerPath()
|
||||
{
|
||||
// Arrange
|
||||
const string templatePath = @"C:\Users\Test User\Documents\My Templates";
|
||||
var createExplorerProcessStartInfoMethod = typeof(NewPlusViewModel).GetMethod("CreateExplorerProcessStartInfo", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
// Act
|
||||
var processStartInfo = (ProcessStartInfo)createExplorerProcessStartInfoMethod.Invoke(null, new object[] { templatePath });
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(processStartInfo);
|
||||
Assert.AreEqual(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe"), processStartInfo.FileName);
|
||||
Assert.AreEqual($"\"{templatePath}\"", processStartInfo.Arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,8 +330,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly string ExplorerExePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe");
|
||||
|
||||
private bool _isNewPlusEnabled;
|
||||
private string _templateLocation;
|
||||
private bool _hideFileExtension;
|
||||
@@ -358,7 +356,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
CopyTemplateExamples(_templateLocation);
|
||||
|
||||
Process.Start(CreateExplorerProcessStartInfo(_templateLocation));
|
||||
var process = new ProcessStartInfo()
|
||||
{
|
||||
FileName = _templateLocation,
|
||||
UseShellExecute = true,
|
||||
};
|
||||
Process.Start(process);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -366,15 +369,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private static ProcessStartInfo CreateExplorerProcessStartInfo(string templateLocation)
|
||||
{
|
||||
return new ProcessStartInfo
|
||||
{
|
||||
FileName = ExplorerExePath,
|
||||
Arguments = $"\"{templateLocation}\"",
|
||||
};
|
||||
}
|
||||
|
||||
private async void PickNewTemplateFolder()
|
||||
{
|
||||
var newPath = await PickFolderDialog();
|
||||
|
||||
Reference in New Issue
Block a user