/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App/ViewModels/UserControls/Previews/FolderPreviewViewModel.cs
74 строки
3 KB
yair100
Feature: Added cloud drive overview to Details Pane (#18235)
09 мар 2026, 19:11
Не верифицирован
09 мар 2026, 19:11
ae18e7e
Код
Авторство
О чём код?
// Copyright (c) Files Community // Licensed under the MIT License. using Files.App.ViewModels.Properties; using Microsoft.UI.Xaml.Media.Imaging; using System.IO; namespace Files.App.ViewModels.Previews { public sealed class FolderPreviewViewModel { private readonly InfoPaneViewModel infoPaneViewModel = Ioc.Default.GetRequiredService<InfoPaneViewModel>(); public ListedItem Item { get; } public BitmapImage Thumbnail { get; set; } = new(); private BaseStorageFolder Folder { get; set; } public FolderPreviewViewModel(ListedItem item) => Item = item; public Task LoadAsync() => LoadPreviewAndDetailsAsync(); private async Task LoadPreviewAndDetailsAsync() { var rootItem = await FilesystemTasks.Wrap(() => DriveHelpers.GetRootFromPathAsync(Item.ItemPath)); Folder = await StorageFileExtensions.DangerousGetFolderFromPathAsync(Item.ItemPath, rootItem); var items = await Folder.GetItemsAsync(); var result = await FileThumbnailHelper.GetIconAsync( Item.ItemPath, Constants.ShellIconSizes.Jumbo, true, IconOptions.None); if (result is not null) Thumbnail = await result.ToBitmapAsync(); // If the selected item is the root of a drive (e.g. "C:\") or a cloud drive, // we do not need to load the properties below, since they will not be shown. // Drive properties will be obtained through the DrivesViewModel service. if (Item.IsDriveRoot || infoPaneViewModel?.SelectedDriveItem is not null) return; var info = await Folder.GetBasicPropertiesAsync(); Item.FileDetails = [ GetFileProperty("PropertyItemCount", infoPaneViewModel?.DirectoryItemCount), GetFileProperty("PropertyDateModified", info.DateModified), GetFileProperty("PropertyDateCreated", info.DateCreated), GetFileProperty("PropertyParsingPath", Folder.Path), ]; if (GitHelpers.IsRepositoryEx(Item.ItemPath, out var repoPath) && !string.IsNullOrEmpty(repoPath)) { var gitDirectory = GitHelpers.GetGitRepositoryPath(Folder.Path, Path.GetPathRoot(Folder.Path)); var headName = (await GitHelpers.GetRepositoryHead(gitDirectory))?.Name ?? string.Empty; var repositoryName = GitHelpers.GetOriginRepositoryName(gitDirectory); if (!string.IsNullOrEmpty(gitDirectory)) Item.FileDetails.Add(GetFileProperty("GitOriginRepositoryName", repositoryName)); if (!string.IsNullOrWhiteSpace(headName)) Item.FileDetails.Add(GetFileProperty("GitCurrentBranch", headName)); } } private static FileProperty GetFileProperty(string nameResource, object value) => new() { NameResource = nameResource, Value = value }; } }