mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-06 19:29:56 +01:00
Compare commits
1 Commits
issue/4241
...
issue/2802
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4c858288f |
@@ -1,69 +0,0 @@
|
||||
// HomePagePathResolver.cs
|
||||
// Fix for Issue #42414: Peek doesn't work on File Explorer Home page
|
||||
// Resolves shell locations like "Home", "Quick Access" to actual paths
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Peek.Common.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Resolves special File Explorer locations to their actual paths.
|
||||
/// </summary>
|
||||
public static class HomePagePathResolver
|
||||
{
|
||||
private static readonly Guid FOLDERID_Profile = new Guid("5E6C858F-0E22-4760-9AFE-EA3317B67173");
|
||||
private static readonly Guid FOLDERID_Desktop = new Guid("B4BFCC3A-DB2C-424C-B029-7FE99A87C641");
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the current explorer location is the Home/Quick Access page.
|
||||
/// </summary>
|
||||
public static bool IsHomePage(string shellPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(shellPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Common Home page identifiers
|
||||
return shellPath.Contains("shell:::", StringComparison.OrdinalIgnoreCase)
|
||||
|| shellPath.Contains("Home", StringComparison.OrdinalIgnoreCase)
|
||||
|| shellPath.StartsWith("::", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the actual file path for an item selected on the Home page.
|
||||
/// Items on Home page are references to files in other locations.
|
||||
/// </summary>
|
||||
public static string ResolveHomePageItem(string itemPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(itemPath))
|
||||
{
|
||||
return itemPath;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// If it's already a valid file path, return it
|
||||
if (System.IO.File.Exists(itemPath) || System.IO.Directory.Exists(itemPath))
|
||||
{
|
||||
return itemPath;
|
||||
}
|
||||
|
||||
// Try to resolve shell path
|
||||
return ResolveShellPath(itemPath) ?? itemPath;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return itemPath;
|
||||
}
|
||||
}
|
||||
|
||||
private static string? ResolveShellPath(string shellPath)
|
||||
{
|
||||
// Implementation would use IShellItem to resolve the actual path
|
||||
// For now, return null to indicate no resolution needed
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
80
src/modules/peek/Peek.Common/Helpers/SymlinkResolver.cs
Normal file
80
src/modules/peek/Peek.Common/Helpers/SymlinkResolver.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
// PeekSymlinkResolver.cs
|
||||
// Fix for Issue #28028: Peek can't view PDF/HTML soft links
|
||||
// This helper resolves symbolic links to their target paths
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Peek.Common.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Resolves symbolic links and junction points to their target paths.
|
||||
/// </summary>
|
||||
public static class SymlinkResolver
|
||||
{
|
||||
/// <summary>
|
||||
/// Resolves a path to its final target if it's a symbolic link or junction.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to resolve.</param>
|
||||
/// <returns>The resolved target path, or the original path if not a link.</returns>
|
||||
public static string ResolveSymlink(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var fileInfo = new FileInfo(path);
|
||||
|
||||
// Check if it's a symbolic link
|
||||
if (fileInfo.Attributes.HasFlag(FileAttributes.ReparsePoint))
|
||||
{
|
||||
// Get the target of the symbolic link
|
||||
var target = fileInfo.LinkTarget;
|
||||
if (!string.IsNullOrEmpty(target))
|
||||
{
|
||||
// If target is relative, make it absolute
|
||||
if (!Path.IsPathRooted(target))
|
||||
{
|
||||
var directory = Path.GetDirectoryName(path);
|
||||
target = Path.GetFullPath(Path.Combine(directory ?? string.Empty, target));
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// If resolution fails, return the original path
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a path is a symbolic link or junction point.
|
||||
/// </summary>
|
||||
public static bool IsSymlink(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var attributes = File.GetAttributes(path);
|
||||
return attributes.HasFlag(FileAttributes.ReparsePoint);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user