[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:
Ani
2024-06-14 16:40:25 +02:00
committed by GitHub
parent fc32fe29ba
commit bc0811e6a1
20 changed files with 599 additions and 54 deletions

View 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;
}

View 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();
}
}
}

View File

@@ -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);

View File

@@ -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)
{

View File

@@ -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;