mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[Peek]Support for special folders like Recycle Bin and My PC (#33310)
* Peek support for special folders * Renamed ThisComputer->ThisPC * Used different variable name to avoid spellcheck issues * Made label of empty fields hidden * Removed ThisPC special handling and last modified date of recycle bin
This commit is contained in:
12
src/modules/peek/Peek.Common/Helpers/PathHelper.cs
Normal file
12
src/modules/peek/Peek.Common/Helpers/PathHelper.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
// 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 Peek.Common.Helpers;
|
||||
|
||||
public static class PathHelper
|
||||
{
|
||||
public static bool IsUncPath(string path) => Uri.TryCreate(path, UriKind.Absolute, out Uri? uri) && uri != null && uri.IsUnc;
|
||||
}
|
||||
26
src/modules/peek/Peek.Common/Helpers/ThreadHelper.cs
Normal file
26
src/modules/peek/Peek.Common/Helpers/ThreadHelper.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
// 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.Threading;
|
||||
|
||||
namespace Peek.Common.Helpers;
|
||||
|
||||
public static class ThreadHelper
|
||||
{
|
||||
public static void RunOnSTAThread(ThreadStart action)
|
||||
{
|
||||
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
|
||||
{
|
||||
action();
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread staThread = new(action);
|
||||
staThread.SetApartmentState(ApartmentState.STA);
|
||||
staThread.Start();
|
||||
staThread.Join();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ namespace Peek.Common.Models
|
||||
|
||||
public string Name { get; init; }
|
||||
|
||||
public string ParsingName => string.Empty;
|
||||
|
||||
public string Path { get; init; }
|
||||
|
||||
public string Extension => System.IO.Path.GetExtension(Path).ToLower(CultureInfo.InvariantCulture);
|
||||
|
||||
@@ -11,19 +11,15 @@ using Windows.Storage;
|
||||
|
||||
namespace Peek.Common.Models
|
||||
{
|
||||
public class FolderItem : IFileSystemItem
|
||||
public class FolderItem(string path, string name, string parsingName) : IFileSystemItem
|
||||
{
|
||||
private StorageFolder? storageFolder;
|
||||
|
||||
public FolderItem(string path, string name)
|
||||
{
|
||||
Path = path;
|
||||
Name = name;
|
||||
}
|
||||
public string Name { get; init; } = name;
|
||||
|
||||
public string Name { get; init; }
|
||||
public string ParsingName { get; init; } = parsingName;
|
||||
|
||||
public string Path { get; init; }
|
||||
public string Path { get; init; } = path;
|
||||
|
||||
public string Extension => string.Empty;
|
||||
|
||||
@@ -38,7 +34,7 @@ namespace Peek.Common.Models
|
||||
{
|
||||
try
|
||||
{
|
||||
storageFolder = await StorageFolder.GetFolderFromPathAsync(Path);
|
||||
storageFolder = string.IsNullOrEmpty(Path) ? null : await StorageFolder.GetFolderFromPathAsync(Path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -17,25 +17,24 @@ namespace Peek.Common.Models
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime? dateModified;
|
||||
try
|
||||
{
|
||||
dateModified = System.IO.File.GetCreationTime(Path);
|
||||
return string.IsNullOrEmpty(Path) ? null : System.IO.File.GetCreationTime(Path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dateModified = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
return dateModified;
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension { get; }
|
||||
|
||||
public string Name { get; init; }
|
||||
public string Name { get; }
|
||||
|
||||
public string Path { get; init; }
|
||||
public string ParsingName { get; }
|
||||
|
||||
public string Path { get; }
|
||||
|
||||
public ulong FileSizeBytes => PropertyStoreHelper.TryGetUlongProperty(Path, PropertyKey.FileSizeBytes) ?? 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user