Skip to content

Commit 1fdaf76

Browse files
authored
Fix: Fixed issue where opening properties would download OneDrive files (#13714)
1 parent 84ef7b6 commit 1fdaf76

File tree

6 files changed

+50
-41
lines changed

6 files changed

+50
-41
lines changed

src/Files.App/Data/Items/ListedItem.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public string ItemTooltipText
4141
tooltipBuilder.AppendLine($"{"NameWithColon".GetLocalizedResource()} {Name}");
4242
tooltipBuilder.AppendLine($"{"ItemType".GetLocalizedResource()} {itemType}");
4343
tooltipBuilder.Append($"{"ToolTipDescriptionDate".GetLocalizedResource()} {ItemDateModified}");
44-
if(!string.IsNullOrWhiteSpace(FileSize))
44+
if (!string.IsNullOrWhiteSpace(FileSize))
4545
tooltipBuilder.Append($"{Environment.NewLine}{"SizeLabel".GetLocalizedResource()} {FileSize}");
46-
if(SyncStatusUI.LoadSyncStatus)
46+
if (SyncStatusUI.LoadSyncStatus)
4747
tooltipBuilder.Append($"{Environment.NewLine}{"syncStatusColumn/Header".GetLocalizedResource()}: {syncStatusUI.SyncStatusString}");
4848

4949
return tooltipBuilder.ToString();
@@ -401,6 +401,10 @@ public void UpdateContainsFilesFolders()
401401

402402
private bool CheckElevationRights()
403403
{
404+
// Avoid downloading file to check elevation
405+
if (SyncStatusUI.SyncStatus is CloudDriveSyncStatus.FileOnline or CloudDriveSyncStatus.FolderOnline)
406+
return false;
407+
404408
return IsShortcut
405409
? ElevationHelpers.IsElevationRequired(((ShortcutItem)this).TargetPath)
406410
: ElevationHelpers.IsElevationRequired(this.ItemPath);

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,9 @@
23282328
<data name="CalculationError" xml:space="preserve">
23292329
<value>An error occurred during the calculation</value>
23302330
</data>
2331+
<data name="CalculationOnlineFileHashError" xml:space="preserve">
2332+
<value>Hashes aren't available for online files</value>
2333+
</data>
23312334
<data name="Algorithm" xml:space="preserve">
23322335
<value>Algorithm</value>
23332336
</data>

src/Files.App/ViewModels/Properties/HashesViewModel.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using CommunityToolkit.Mvvm.ComponentModel;
5-
using CommunityToolkit.Mvvm.DependencyInjection;
6-
using CommunityToolkit.Mvvm.Input;
7-
using CommunityToolkit.WinUI;
8-
using Files.App.Extensions;
9-
using Files.App.Utils;
10-
using Files.Shared.Extensions;
114
using Files.Shared.Helpers;
12-
using System;
13-
using System.Collections.Generic;
14-
using System.Collections.ObjectModel;
155
using System.IO;
16-
using System.Linq;
17-
using System.Threading;
186
using System.Windows.Input;
197

208
namespace Files.App.ViewModels.Properties
@@ -80,6 +68,13 @@ private void ToggleIsEnabled(string? algorithm)
8068
UserSettingsService.GeneralSettingsService.ShowHashesDictionary = ShowHashes;
8169
}
8270

71+
// Don't calculate hashes for online files
72+
if (_item.SyncStatusUI.SyncStatus is CloudDriveSyncStatus.FileOnline or CloudDriveSyncStatus.FolderOnline)
73+
{
74+
hashInfoItem.HashValue = "CalculationOnlineFileHashError".GetLocalizedResource();
75+
return;
76+
}
77+
8378
if (hashInfoItem.HashValue is null && hashInfoItem.IsEnabled)
8479
{
8580
hashInfoItem.IsCalculating = true;

src/Files.App/ViewModels/Properties/Items/CombinedProperties.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ public override async Task GetSpecialPropertiesAsync()
7373
long filesSize = List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File).Sum(x => x.FileSizeBytes);
7474
long foldersSize = 0;
7575
long totalSizeOnDisk = 0;
76-
long filesSizeOnDisk = List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File)
77-
.Sum(x => NativeFileOperationsHelper.GetFileSizeOnDisk(x.ItemPath) ?? 0);
76+
long filesSizeOnDisk = List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File &&
77+
x.SyncStatusUI.SyncStatus is not CloudDriveSyncStatus.FileOnline and not CloudDriveSyncStatus.FolderOnline)
78+
.Sum(x => NativeFileOperationsHelper.GetFileSizeOnDisk(x.ItemPath) ?? 0);
7879
long foldersSizeOnDisk = 0;
7980

8081
ViewModel.ItemSizeProgressVisibility = true;
@@ -84,12 +85,12 @@ public override async Task GetSpecialPropertiesAsync()
8485
{
8586
if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
8687
{
87-
var fileSizeTask = Task.Run(async () =>
88-
{
89-
var size = await CalculateFolderSizeAsync(item.ItemPath, TokenSource.Token);
88+
if (item.SyncStatusUI.SyncStatus is CloudDriveSyncStatus.FileOnline or
89+
CloudDriveSyncStatus.FolderOnline or
90+
CloudDriveSyncStatus.FolderOfflinePartial)
91+
continue;
9092

91-
return size;
92-
});
93+
var fileSizeTask = Task.Run(() => CalculateFolderSizeAsync(item.ItemPath, TokenSource.Token));
9394

9495
try
9596
{

src/Files.App/ViewModels/Properties/Items/FileProperties.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ public override async Task GetSpecialPropertiesAsync()
9797

9898
ViewModel.ItemSizeVisibility = true;
9999
ViewModel.ItemSize = Item.FileSizeBytes.ToLongSizeString();
100-
ViewModel.ItemSizeOnDisk = NativeFileOperationsHelper.GetFileSizeOnDisk(Item.ItemPath)?.ToLongSizeString() ??
101-
string.Empty;
100+
101+
// Only load the size for items on the device
102+
if (Item.SyncStatusUI.SyncStatus is not CloudDriveSyncStatus.FileOnline and not CloudDriveSyncStatus.FolderOnline)
103+
ViewModel.ItemSizeOnDisk = NativeFileOperationsHelper.GetFileSizeOnDisk(Item.ItemPath)?.ToLongSizeString() ??
104+
string.Empty;
102105

103106
var fileIconData = await FileThumbnailHelper.LoadIconFromPathAsync(Item.ItemPath, 80, Windows.Storage.FileProperties.ThumbnailMode.DocumentsView, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail, false);
104107
if (fileIconData is not null)
@@ -131,15 +134,14 @@ public override async Task GetSpecialPropertiesAsync()
131134
if (Item.IsShortcut)
132135
return;
133136

134-
if (FileExtensionHelpers.IsBrowsableZipFile(Item.FileExtension, out _))
135-
{
136-
if (await ZipStorageFolder.FromPathAsync(Item.ItemPath) is ZipStorageFolder zipFolder)
137-
{
138-
var uncompressedSize = await zipFolder.GetUncompressedSize();
139-
ViewModel.UncompressedItemSize = uncompressedSize.ToLongSizeString();
140-
ViewModel.UncompressedItemSizeBytes = uncompressedSize;
141-
}
142-
}
137+
if (Item.SyncStatusUI.SyncStatus is not CloudDriveSyncStatus.FileOnline and not CloudDriveSyncStatus.FolderOnline)
138+
if (FileExtensionHelpers.IsBrowsableZipFile(Item.FileExtension, out _))
139+
if (await ZipStorageFolder.FromPathAsync(Item.ItemPath) is ZipStorageFolder zipFolder)
140+
{
141+
var uncompressedSize = await zipFolder.GetUncompressedSize();
142+
ViewModel.UncompressedItemSize = uncompressedSize.ToLongSizeString();
143+
ViewModel.UncompressedItemSizeBytes = uncompressedSize;
144+
}
143145

144146
if (file.Properties is not null)
145147
GetOtherPropertiesAsync(file.Properties);

src/Files.App/ViewModels/Properties/Items/FolderProperties.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public override void GetBaseProperties()
3939
ViewModel.ItemType = Item.ItemType;
4040
ViewModel.ItemLocation = (Item as RecycleBinItem)?.ItemOriginalFolder ??
4141
(Path.IsPathRooted(Item.ItemPath) ? Path.GetDirectoryName(Item.ItemPath) : Item.ItemPath);
42-
ViewModel.ItemModifiedTimestampReal= Item.ItemDateModifiedReal;
42+
ViewModel.ItemModifiedTimestampReal = Item.ItemDateModifiedReal;
4343
ViewModel.ItemCreatedTimestampReal = Item.ItemDateCreatedReal;
4444
ViewModel.LoadCustomIcon = Item.LoadCustomIcon;
4545
ViewModel.CustomIconSource = Item.CustomIconSource;
@@ -86,11 +86,12 @@ public async override Task GetSpecialPropertiesAsync()
8686
{
8787
ViewModel.ItemSizeVisibility = true;
8888
ViewModel.ItemSize = Item.FileSizeBytes.ToLongSizeString();
89-
var sizeOnDisk = NativeFileOperationsHelper.GetFileSizeOnDisk(Item.ItemPath);
90-
if (sizeOnDisk is not null)
91-
{
92-
ViewModel.ItemSizeOnDisk = ((long)sizeOnDisk).ToLongSizeString();
93-
}
89+
90+
// Only load the size for items on the device
91+
if (Item.SyncStatusUI.SyncStatus is not CloudDriveSyncStatus.FileOnline and not CloudDriveSyncStatus.FolderOnline)
92+
ViewModel.ItemSizeOnDisk = NativeFileOperationsHelper.GetFileSizeOnDisk(Item.ItemPath)?.ToLongSizeString() ??
93+
string.Empty;
94+
9495
ViewModel.ItemCreatedTimestampReal = Item.ItemDateCreatedReal;
9596
ViewModel.ItemAccessedTimestampReal = Item.ItemDateAccessedReal;
9697
if (Item.IsLinkItem || string.IsNullOrWhiteSpace(((ShortcutItem)Item).TargetPath))
@@ -107,10 +108,13 @@ public async override Task GetSpecialPropertiesAsync()
107108
{
108109
ViewModel.ItemCreatedTimestampReal = storageFolder.DateCreated;
109110
if (storageFolder.Properties is not null)
110-
{
111111
GetOtherPropertiesAsync(storageFolder.Properties);
112-
}
113-
GetFolderSizeAsync(storageFolder.Path, TokenSource.Token);
112+
113+
// Only load the size for items on the device
114+
if (Item.SyncStatusUI.SyncStatus is not CloudDriveSyncStatus.FileOnline and not
115+
CloudDriveSyncStatus.FolderOnline and not
116+
CloudDriveSyncStatus.FolderOfflinePartial)
117+
GetFolderSizeAsync(storageFolder.Path, TokenSource.Token);
114118
}
115119
else if (Item.ItemPath.Equals(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
116120
{

0 commit comments

Comments
 (0)