Files
PowerToys/src/modules/peek/Peek.Common/Models/FolderItem.cs
Ani bc0811e6a1 [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
2024-06-14 15:40:25 +01:00

50 lines
1.4 KiB
C#

// 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.Tasks;
using ManagedCommon;
using Windows.Storage;
#nullable enable
namespace Peek.Common.Models
{
public class FolderItem(string path, string name, string parsingName) : IFileSystemItem
{
private StorageFolder? storageFolder;
public string Name { get; init; } = name;
public string ParsingName { get; init; } = parsingName;
public string Path { get; init; } = path;
public string Extension => string.Empty;
public async Task<IStorageItem?> GetStorageItemAsync()
{
return await GetStorageFolderAsync();
}
public async Task<StorageFolder?> GetStorageFolderAsync()
{
if (storageFolder == null)
{
try
{
storageFolder = string.IsNullOrEmpty(Path) ? null : await StorageFolder.GetFolderFromPathAsync(Path);
}
catch (Exception ex)
{
Logger.LogError("Error getting folder from path. " + ex.Message);
storageFolder = null;
}
}
return storageFolder;
}
}
}