|
1 | 1 | using ByteSizeLib;
|
2 | 2 | using Files.Enums;
|
| 3 | +using Files.Common; |
3 | 4 | using Files.Filesystem;
|
4 | 5 | using Files.Helpers;
|
5 | 6 | using Microsoft.Toolkit.Mvvm.Input;
|
|
11 | 12 | using Windows.ApplicationModel.Core;
|
12 | 13 | using Windows.Foundation.Collections;
|
13 | 14 | using Windows.Storage;
|
| 15 | +using Windows.Storage.FileProperties; |
14 | 16 | using Windows.UI.Core;
|
15 | 17 | using Windows.UI.Xaml;
|
| 18 | +using Windows.UI.Xaml.Media.Imaging; |
16 | 19 |
|
17 | 20 | namespace Files.View_Models.Properties
|
18 | 21 | {
|
@@ -76,80 +79,111 @@ public async override void GetSpecialProperties()
|
76 | 79 | + " (" + ByteSize.FromBytes(Item.FileSizeBytes).Bytes.ToString("#,##0") + " " + ResourceController.GetTranslation("ItemSizeBytes") + ")";
|
77 | 80 | ViewModel.ItemCreatedTimestamp = Item.ItemDateCreated;
|
78 | 81 | ViewModel.ItemAccessedTimestamp = Item.ItemDateAccessed;
|
79 |
| - // Can't show any other property |
80 |
| - return; |
| 82 | + if (Item.IsLinkItem || string.IsNullOrWhiteSpace(((ShortcutItem)Item).TargetPath)) |
| 83 | + { |
| 84 | + // Can't show any other property |
| 85 | + return; |
| 86 | + } |
81 | 87 | }
|
82 |
| - ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; |
83 |
| - string returnformat = Enum.Parse<TimeStyle>(localSettings.Values[LocalSettings.DateTimeFormat].ToString()) == TimeStyle.Application ? "D" : "g"; |
84 | 88 |
|
85 |
| - StorageFolder storageFolder; |
86 |
| - bool isItemSelected; |
| 89 | + var parentDirectory = App.CurrentInstance.FilesystemViewModel.CurrentFolder; |
87 | 90 |
|
| 91 | + StorageFolder storageFolder = null; |
88 | 92 | try
|
89 | 93 | {
|
90 |
| - isItemSelected = await CoreApplication.MainView.ExecuteOnUIThreadAsync(() => App.CurrentInstance.ContentPage.IsItemSelected); |
| 94 | + var isItemSelected = await CoreApplication.MainView.ExecuteOnUIThreadAsync(() => App.CurrentInstance?.ContentPage?.IsItemSelected ?? true); |
| 95 | + if (isItemSelected) |
| 96 | + { |
| 97 | + storageFolder = await ItemViewModel.GetFolderFromPathAsync((Item as ShortcutItem)?.TargetPath ?? Item.ItemPath); |
| 98 | + } |
| 99 | + else if (!parentDirectory.ItemPath.StartsWith(App.AppSettings.RecycleBinPath)) |
| 100 | + { |
| 101 | + storageFolder = await ItemViewModel.GetFolderFromPathAsync(parentDirectory.ItemPath); |
| 102 | + } |
91 | 103 | }
|
92 |
| - catch |
| 104 | + catch (Exception ex) |
93 | 105 | {
|
94 |
| - isItemSelected = true; |
| 106 | + NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message); |
| 107 | + // Could not access folder, can't show any other property |
| 108 | + return; |
95 | 109 | }
|
96 | 110 |
|
97 |
| - if (isItemSelected) |
| 111 | + if (storageFolder != null) |
98 | 112 | {
|
99 |
| - storageFolder = await ItemViewModel.GetFolderFromPathAsync(Item.ItemPath); |
| 113 | + ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; |
| 114 | + string returnformat = Enum.Parse<TimeStyle>(localSettings.Values[LocalSettings.DateTimeFormat].ToString()) == TimeStyle.Application ? "D" : "g"; |
100 | 115 | ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDateFromFormat(storageFolder.DateCreated, returnformat);
|
| 116 | + LoadFolderIcon(storageFolder); |
101 | 117 | GetOtherProperties(storageFolder.Properties);
|
102 | 118 | GetFolderSize(storageFolder, TokenSource.Token);
|
103 | 119 | }
|
104 |
| - else |
| 120 | + else if (parentDirectory.ItemPath.StartsWith(App.AppSettings.RecycleBinPath)) |
105 | 121 | {
|
106 |
| - var parentDirectory = App.CurrentInstance.FilesystemViewModel.CurrentFolder; |
107 |
| - if (parentDirectory.ItemPath.StartsWith(App.AppSettings.RecycleBinPath)) |
| 122 | + // GetFolderFromPathAsync cannot access recyclebin folder |
| 123 | + if (App.Connection != null) |
108 | 124 | {
|
109 |
| - // GetFolderFromPathAsync cannot access recyclebin folder |
110 |
| - if (App.Connection != null) |
| 125 | + var value = new ValueSet(); |
| 126 | + value.Add("Arguments", "RecycleBin"); |
| 127 | + value.Add("action", "Query"); |
| 128 | + // Send request to fulltrust process to get recyclebin properties |
| 129 | + var response = await App.Connection.SendMessageAsync(value); |
| 130 | + if (response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success) |
111 | 131 | {
|
112 |
| - var value = new ValueSet(); |
113 |
| - value.Add("Arguments", "RecycleBin"); |
114 |
| - value.Add("action", "Query"); |
115 |
| - // Send request to fulltrust process to get recyclebin properties |
116 |
| - var response = await App.Connection.SendMessageAsync(value); |
117 |
| - if (response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success) |
| 132 | + if (response.Message.TryGetValue("BinSize", out var binSize)) |
| 133 | + { |
| 134 | + ViewModel.ItemSizeBytes = (long)binSize; |
| 135 | + ViewModel.ItemSize = ByteSize.FromBytes((long)binSize).ToString(); |
| 136 | + ViewModel.ItemSizeVisibility = Visibility.Visible; |
| 137 | + } |
| 138 | + else |
118 | 139 | {
|
119 |
| - if (response.Message.TryGetValue("BinSize", out var binSize)) |
120 |
| - { |
121 |
| - ViewModel.ItemSizeBytes = (long)binSize; |
122 |
| - ViewModel.ItemSize = ByteSize.FromBytes((long)binSize).ToString(); |
123 |
| - ViewModel.ItemSizeVisibility = Visibility.Visible; |
124 |
| - } |
125 |
| - else |
126 |
| - { |
127 |
| - ViewModel.ItemSizeVisibility = Visibility.Collapsed; |
128 |
| - } |
129 |
| - if (response.Message.TryGetValue("NumItems", out var numItems)) |
130 |
| - { |
131 |
| - ViewModel.FilesCount = (int)(long)numItems; |
132 |
| - SetItemsCountString(); |
133 |
| - ViewModel.FilesAndFoldersCountVisibility = Visibility.Visible; |
134 |
| - } |
135 |
| - else |
136 |
| - { |
137 |
| - ViewModel.FilesAndFoldersCountVisibility = Visibility.Collapsed; |
138 |
| - } |
139 |
| - ViewModel.ItemCreatedTimestampVisibiity = Visibility.Collapsed; |
140 |
| - ViewModel.ItemAccessedTimestampVisibility = Visibility.Collapsed; |
141 |
| - ViewModel.ItemModifiedTimestampVisibility = Visibility.Collapsed; |
142 |
| - ViewModel.ItemFileOwnerVisibility = Visibility.Collapsed; |
143 |
| - ViewModel.LastSeparatorVisibility = Visibility.Collapsed; |
| 140 | + ViewModel.ItemSizeVisibility = Visibility.Collapsed; |
144 | 141 | }
|
| 142 | + if (response.Message.TryGetValue("NumItems", out var numItems)) |
| 143 | + { |
| 144 | + ViewModel.FilesCount = (int)(long)numItems; |
| 145 | + SetItemsCountString(); |
| 146 | + ViewModel.FilesAndFoldersCountVisibility = Visibility.Visible; |
| 147 | + } |
| 148 | + else |
| 149 | + { |
| 150 | + ViewModel.FilesAndFoldersCountVisibility = Visibility.Collapsed; |
| 151 | + } |
| 152 | + ViewModel.ItemCreatedTimestampVisibiity = Visibility.Collapsed; |
| 153 | + ViewModel.ItemAccessedTimestampVisibility = Visibility.Collapsed; |
| 154 | + ViewModel.ItemModifiedTimestampVisibility = Visibility.Collapsed; |
| 155 | + ViewModel.ItemFileOwnerVisibility = Visibility.Collapsed; |
| 156 | + ViewModel.LastSeparatorVisibility = Visibility.Collapsed; |
145 | 157 | }
|
146 | 158 | }
|
147 |
| - else |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + private async void LoadFolderIcon(StorageFolder storageFolder) |
| 163 | + { |
| 164 | + if (App.Connection != null) |
| 165 | + { |
| 166 | + var value = new ValueSet(); |
| 167 | + value.Add("Arguments", "CheckCustomIcon"); |
| 168 | + value.Add("folderPath", Item.ItemPath); |
| 169 | + var response = await App.Connection.SendMessageAsync(value); |
| 170 | + var hasCustomIcon = (response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success) |
| 171 | + && response.Message.Get("HasCustomIcon", false); |
| 172 | + if (hasCustomIcon) |
148 | 173 | {
|
149 |
| - storageFolder = await ItemViewModel.GetFolderFromPathAsync(parentDirectory.ItemPath); |
150 |
| - ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDateFromFormat(storageFolder.DateCreated, returnformat); |
151 |
| - GetOtherProperties(storageFolder.Properties); |
152 |
| - GetFolderSize(storageFolder, TokenSource.Token); |
| 174 | + // Only set folder icon if it's a custom icon |
| 175 | + using (var Thumbnail = await storageFolder.GetThumbnailAsync(ThumbnailMode.SingleItem, 80, ThumbnailOptions.UseCurrentScale)) |
| 176 | + { |
| 177 | + BitmapImage icon = new BitmapImage(); |
| 178 | + if (Thumbnail != null) |
| 179 | + { |
| 180 | + ViewModel.FileIconSource = icon; |
| 181 | + await icon.SetSourceAsync(Thumbnail); |
| 182 | + ViewModel.LoadUnknownTypeGlyph = false; |
| 183 | + ViewModel.LoadFolderGlyph = false; |
| 184 | + ViewModel.LoadFileIcon = true; |
| 185 | + } |
| 186 | + } |
153 | 187 | }
|
154 | 188 | }
|
155 | 189 | }
|
|
0 commit comments