Skip to content

Fix: Fixed issue where opening properties would download OneDrive files #13714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 9, 2023
8 changes: 6 additions & 2 deletions src/Files.App/Data/Items/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public string ItemTooltipText
tooltipBuilder.AppendLine($"{"NameWithColon".GetLocalizedResource()} {Name}");
tooltipBuilder.AppendLine($"{"ItemType".GetLocalizedResource()} {itemType}");
tooltipBuilder.Append($"{"ToolTipDescriptionDate".GetLocalizedResource()} {ItemDateModified}");
if(!string.IsNullOrWhiteSpace(FileSize))
if (!string.IsNullOrWhiteSpace(FileSize))
tooltipBuilder.Append($"{Environment.NewLine}{"SizeLabel".GetLocalizedResource()} {FileSize}");
if(SyncStatusUI.LoadSyncStatus)
if (SyncStatusUI.LoadSyncStatus)
tooltipBuilder.Append($"{Environment.NewLine}{"syncStatusColumn/Header".GetLocalizedResource()}: {syncStatusUI.SyncStatusString}");

return tooltipBuilder.ToString();
Expand Down Expand Up @@ -401,6 +401,10 @@ public void UpdateContainsFilesFolders()

private bool CheckElevationRights()
{
// Avoid downloading file to check elevation
if (SyncStatusUI.SyncStatus is CloudDriveSyncStatus.FileOnline or CloudDriveSyncStatus.FolderOnline)
return false;

return IsShortcut
? ElevationHelpers.IsElevationRequired(((ShortcutItem)this).TargetPath)
: ElevationHelpers.IsElevationRequired(this.ItemPath);
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2328,6 +2328,9 @@
<data name="CalculationError" xml:space="preserve">
<value>An error occurred during the calculation</value>
</data>
<data name="CalculationOnlineFileHashError" xml:space="preserve">
<value>Hashes aren't available for online files</value>
</data>
<data name="Algorithm" xml:space="preserve">
<value>Algorithm</value>
</data>
Expand Down
19 changes: 7 additions & 12 deletions src/Files.App/ViewModels/Properties/HashesViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.WinUI;
using Files.App.Extensions;
using Files.App.Utils;
using Files.Shared.Extensions;
using Files.Shared.Helpers;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Input;

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

// Don't calculate hashes for online files
if (_item.SyncStatusUI.SyncStatus is CloudDriveSyncStatus.FileOnline or CloudDriveSyncStatus.FolderOnline)
{
hashInfoItem.HashValue = "CalculationOnlineFileHashError".GetLocalizedResource();
return;
}

if (hashInfoItem.HashValue is null && hashInfoItem.IsEnabled)
{
hashInfoItem.IsCalculating = true;
Expand Down
15 changes: 8 additions & 7 deletions src/Files.App/ViewModels/Properties/Items/CombinedProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ public override async Task GetSpecialPropertiesAsync()
long filesSize = List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File).Sum(x => x.FileSizeBytes);
long foldersSize = 0;
long totalSizeOnDisk = 0;
long filesSizeOnDisk = List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File)
.Sum(x => NativeFileOperationsHelper.GetFileSizeOnDisk(x.ItemPath) ?? 0);
long filesSizeOnDisk = List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File &&
x.SyncStatusUI.SyncStatus is not CloudDriveSyncStatus.FileOnline and not CloudDriveSyncStatus.FolderOnline)
.Sum(x => NativeFileOperationsHelper.GetFileSizeOnDisk(x.ItemPath) ?? 0);
long foldersSizeOnDisk = 0;

ViewModel.ItemSizeProgressVisibility = true;
Expand All @@ -84,12 +85,12 @@ public override async Task GetSpecialPropertiesAsync()
{
if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
{
var fileSizeTask = Task.Run(async () =>
{
var size = await CalculateFolderSizeAsync(item.ItemPath, TokenSource.Token);
if (item.SyncStatusUI.SyncStatus is CloudDriveSyncStatus.FileOnline or
CloudDriveSyncStatus.FolderOnline or
CloudDriveSyncStatus.FolderOfflinePartial)
continue;

return size;
});
var fileSizeTask = Task.Run(() => CalculateFolderSizeAsync(item.ItemPath, TokenSource.Token));

try
{
Expand Down
24 changes: 13 additions & 11 deletions src/Files.App/ViewModels/Properties/Items/FileProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ public override async Task GetSpecialPropertiesAsync()

ViewModel.ItemSizeVisibility = true;
ViewModel.ItemSize = Item.FileSizeBytes.ToLongSizeString();
ViewModel.ItemSizeOnDisk = NativeFileOperationsHelper.GetFileSizeOnDisk(Item.ItemPath)?.ToLongSizeString() ??
string.Empty;

// Only load the size for items on the device
if (Item.SyncStatusUI.SyncStatus is not CloudDriveSyncStatus.FileOnline and not CloudDriveSyncStatus.FolderOnline)
ViewModel.ItemSizeOnDisk = NativeFileOperationsHelper.GetFileSizeOnDisk(Item.ItemPath)?.ToLongSizeString() ??
string.Empty;

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

if (FileExtensionHelpers.IsBrowsableZipFile(Item.FileExtension, out _))
{
if (await ZipStorageFolder.FromPathAsync(Item.ItemPath) is ZipStorageFolder zipFolder)
{
var uncompressedSize = await zipFolder.GetUncompressedSize();
ViewModel.UncompressedItemSize = uncompressedSize.ToLongSizeString();
ViewModel.UncompressedItemSizeBytes = uncompressedSize;
}
}
if (Item.SyncStatusUI.SyncStatus is not CloudDriveSyncStatus.FileOnline and not CloudDriveSyncStatus.FolderOnline)
if (FileExtensionHelpers.IsBrowsableZipFile(Item.FileExtension, out _))
if (await ZipStorageFolder.FromPathAsync(Item.ItemPath) is ZipStorageFolder zipFolder)
{
var uncompressedSize = await zipFolder.GetUncompressedSize();
ViewModel.UncompressedItemSize = uncompressedSize.ToLongSizeString();
ViewModel.UncompressedItemSizeBytes = uncompressedSize;
}

if (file.Properties is not null)
GetOtherPropertiesAsync(file.Properties);
Expand Down
22 changes: 13 additions & 9 deletions src/Files.App/ViewModels/Properties/Items/FolderProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override void GetBaseProperties()
ViewModel.ItemType = Item.ItemType;
ViewModel.ItemLocation = (Item as RecycleBinItem)?.ItemOriginalFolder ??
(Path.IsPathRooted(Item.ItemPath) ? Path.GetDirectoryName(Item.ItemPath) : Item.ItemPath);
ViewModel.ItemModifiedTimestampReal= Item.ItemDateModifiedReal;
ViewModel.ItemModifiedTimestampReal = Item.ItemDateModifiedReal;
ViewModel.ItemCreatedTimestampReal = Item.ItemDateCreatedReal;
ViewModel.LoadCustomIcon = Item.LoadCustomIcon;
ViewModel.CustomIconSource = Item.CustomIconSource;
Expand Down Expand Up @@ -86,11 +86,12 @@ public async override Task GetSpecialPropertiesAsync()
{
ViewModel.ItemSizeVisibility = true;
ViewModel.ItemSize = Item.FileSizeBytes.ToLongSizeString();
var sizeOnDisk = NativeFileOperationsHelper.GetFileSizeOnDisk(Item.ItemPath);
if (sizeOnDisk is not null)
{
ViewModel.ItemSizeOnDisk = ((long)sizeOnDisk).ToLongSizeString();
}

// Only load the size for items on the device
if (Item.SyncStatusUI.SyncStatus is not CloudDriveSyncStatus.FileOnline and not CloudDriveSyncStatus.FolderOnline)
ViewModel.ItemSizeOnDisk = NativeFileOperationsHelper.GetFileSizeOnDisk(Item.ItemPath)?.ToLongSizeString() ??
string.Empty;

ViewModel.ItemCreatedTimestampReal = Item.ItemDateCreatedReal;
ViewModel.ItemAccessedTimestampReal = Item.ItemDateAccessedReal;
if (Item.IsLinkItem || string.IsNullOrWhiteSpace(((ShortcutItem)Item).TargetPath))
Expand All @@ -107,10 +108,13 @@ public async override Task GetSpecialPropertiesAsync()
{
ViewModel.ItemCreatedTimestampReal = storageFolder.DateCreated;
if (storageFolder.Properties is not null)
{
GetOtherPropertiesAsync(storageFolder.Properties);
}
GetFolderSizeAsync(storageFolder.Path, TokenSource.Token);

// Only load the size for items on the device
if (Item.SyncStatusUI.SyncStatus is not CloudDriveSyncStatus.FileOnline and not
CloudDriveSyncStatus.FolderOnline and not
CloudDriveSyncStatus.FolderOfflinePartial)
GetFolderSizeAsync(storageFolder.Path, TokenSource.Token);
}
else if (Item.ItemPath.Equals(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
{
Expand Down