Skip to content

Commit

Permalink
Feature: Display error message when transferring files that are too l…
Browse files Browse the repository at this point in the history
…arge for FAT32 (#13137)
  • Loading branch information
ferrariofilippo authored Aug 8, 2023
1 parent be42aea commit 3221267
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 2 deletions.
32 changes: 32 additions & 0 deletions src/Files.App/Dialogs/FileTooLargeDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!-- Copyright (c) 2023 Files Community. Licensed under the MIT License. See the LICENSE. -->
<ContentDialog
x:Class="Files.App.Dialogs.FileTooLargeDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.App.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="{helpers:ResourceString Name=CopyFailureFileToLarge}"
CornerRadius="{StaticResource OverlayCornerRadius}"
DefaultButton="Primary"
PrimaryButtonText="{helpers:ResourceString Name=OK}"
RequestedTheme="{x:Bind helpers:ThemeHelper.RootTheme}"
Style="{StaticResource DefaultContentDialogStyle}"
mc:Ignorable="d">

<ListView
MaxHeight="300"
ItemsSource="{x:Bind ViewModel.Paths}"
SelectionMode="None">
<ListView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<TextBlock
Padding="4"
IsTabStop="False"
Text="{x:Bind}"
TextWrapping="Wrap" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

</ContentDialog>
35 changes: 35 additions & 0 deletions src/Files.App/Dialogs/FileTooLargeDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Xaml.Controls;

namespace Files.App.Dialogs
{
public sealed partial class FileTooLargeDialog : ContentDialog, IDialog<FileTooLargeDialogViewModel>
{
public FileTooLargeDialogViewModel ViewModel
{
get => (FileTooLargeDialogViewModel)DataContext;
set => DataContext = value;
}

public FileTooLargeDialog()
{
InitializeComponent();
}

public new async Task<DialogResult> ShowAsync()
{
return (DialogResult)await SetContentDialogRoot(this).TryShowAsync();
}

// WINUI3
private ContentDialog SetContentDialogRoot(ContentDialog contentDialog)
{
if (Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
contentDialog.XamlRoot = MainWindow.Instance.Content.XamlRoot;

return contentDialog;
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public DialogService()
{ typeof(ReorderSidebarItemsDialogViewModel), () => new ReorderSidebarItemsDialog() },
{ typeof(AddBranchDialogViewModel), () => new AddBranchDialog() },
{ typeof(GitHubLoginDialogViewModel), () => new GitHubLoginDialog() },
{ typeof(FileTooLargeDialogViewModel), () => new FileTooLargeDialog() },
};
}

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 @@ -3429,4 +3429,7 @@
<data name="ShortcutItemWorkingDir" xml:space="preserve">
<value>Start in:</value>
</data>
<data name="CopyFailureFileToLarge" xml:space="preserve">
<value>The following items are too large to be copied to this drive</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ await sourceMatch.Select(x => x.dest).ToListAsync(),
await sourceMatch.Select(x => FileNameConflictResolveOptionType.ReplaceExisting).ToListAsync(), progress, cancellationToken);
}
}
else if (copyResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.FileTooLarge))
{
var failingItems = copyResult.Items
.Where(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.FileTooLarge)
.Select(item => item.Source);

await Ioc.Default.GetRequiredService<IDialogService>().ShowDialogAsync(new FileTooLargeDialogViewModel(failingItems));
}
// ADS
else if (copyResult.Items.All(x => x.HResult == -1))
{
Expand Down
3 changes: 2 additions & 1 deletion src/Files.Core/Data/Enums/CopyEngineResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct CopyEngineResult
public const int COPYENGINE_E_ALREADY_EXISTS_SYSTEM = -2144927701;
public const int COPYENGINE_E_ALREADY_EXISTS_FOLDER = -2144927700;
// File too big
//public const int COPYENGINE_E_FILE_TOO_LARGE = -2144927731;
public const int COPYENGINE_E_FILE_TOO_LARGE = -2144927731;
//public const int COPYENGINE_E_REMOVABLE_FULL = -2144927730;
//public const int COPYENGINE_E_DISK_FULL = -2144927694;
//public const int COPYENGINE_E_DISK_FULL_CLEAN = -2144927693;
Expand Down Expand Up @@ -78,6 +78,7 @@ public static FileSystemStatusCode Convert(int? hres)
CopyEngineResult.COPYENGINE_E_ALREADY_EXISTS_READONLY => FileSystemStatusCode.AlreadyExists,
CopyEngineResult.COPYENGINE_E_ALREADY_EXISTS_SYSTEM => FileSystemStatusCode.AlreadyExists,
CopyEngineResult.COPYENGINE_E_ALREADY_EXISTS_FOLDER => FileSystemStatusCode.AlreadyExists,
CopyEngineResult.COPYENGINE_E_FILE_TOO_LARGE => FileSystemStatusCode.FileTooLarge,
CopyEngineResult.COPYENGINE_E_FILE_IS_FLD_DEST => FileSystemStatusCode.NotAFile,
CopyEngineResult.COPYENGINE_E_FLD_IS_FILE_DEST => FileSystemStatusCode.NotAFolder,
CopyEngineResult.COPYENGINE_E_SHARING_VIOLATION_SRC => FileSystemStatusCode.InUse,
Expand Down
7 changes: 6 additions & 1 deletion src/Files.Core/Data/Enums/FileSystemStatusCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public enum FileSystemStatusCode
/// <summary>
/// InProgress
/// </summary>
InProgress = 1024
InProgress = 1024,

/// <summary>
/// FileTooLarge
/// </summary>
FileTooLarge = 2048
}
}
15 changes: 15 additions & 0 deletions src/Files.Core/ViewModels/Dialogs/FileTooLargeDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.Core.ViewModels.Dialogs
{
public sealed class FileTooLargeDialogViewModel: ObservableObject
{
public IEnumerable<string> Paths { get; private set; }

public FileTooLargeDialogViewModel(IEnumerable<string> paths)
{
Paths = paths;
}
}
}

0 comments on commit 3221267

Please sign in to comment.