Skip to content

Feature: Added support for copying files with ADS to FAT32 #12039

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 1 commit into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ await sourceMatch.Select(x => x.dest).ToListAsync(),
{
await DialogDisplayHelper.ShowDialogAsync("ItemAlreadyExistsDialogTitle".GetLocalizedResource(), "ItemAlreadyExistsDialogContent".GetLocalizedResource());
}
else if (copyResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.PropertyLoss))
{
var failedSources = copyResult.Items.Where(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.PropertyLoss);
var filePath = failedSources.Select(x => x.Source);
switch (await GetFileListDialog(filePath, "FilePropertiesCannotBeCopied".GetLocalizedResource(), "CopyFileWithoutProperties".GetLocalizedResource(), "OK".GetLocalizedResource(), "Cancel".GetLocalizedResource()))
{
case DialogResult.Primary:
var copyZip = sourceNoSkip.Zip(destinationNoSkip, (src, dest) => new { src, dest }).Zip(collisionsNoSkip, (z1, coll) => new { z1.src, z1.dest, coll });
var sourceMatch = await failedSources.Select(x => copyZip.SingleOrDefault(s => s.src.Path.Equals(x.Source, StringComparison.OrdinalIgnoreCase))).Where(x => x is not null).ToListAsync();
return await CopyItemsAsync(
await sourceMatch.Select(x => x.src).ToListAsync(),
await sourceMatch.Select(x => x.dest).ToListAsync(),
// Force collision option to "replace" to accept copying with property loss
// Ok since property loss error is raised after checking if the destination already exists
await sourceMatch.Select(x => FileNameConflictResolveOptionType.ReplaceExisting).ToListAsync(), progress, cancellationToken);
}
}
else if (copyResult.Items.All(x => x.HResult == -1)) // ADS
{
// Retry with StorageFile API
Expand Down Expand Up @@ -535,6 +552,23 @@ await sourceMatch.Select(x => x.dest).ToListAsync(),
{
await DialogDisplayHelper.ShowDialogAsync("ItemAlreadyExistsDialogTitle".GetLocalizedResource(), "ItemAlreadyExistsDialogContent".GetLocalizedResource());
}
else if (moveResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.PropertyLoss))
{
var failedSources = moveResult.Items.Where(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.PropertyLoss);
var filePath = failedSources.Select(x => x.Source);
switch (await GetFileListDialog(filePath, "FilePropertiesCannotBeMoved".GetLocalizedResource(), "MoveFileWithoutProperties".GetLocalizedResource(), "OK".GetLocalizedResource(), "Cancel".GetLocalizedResource()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change the text to "Continue" or "Yes"?

{
case DialogResult.Primary:
var copyZip = sourceNoSkip.Zip(destinationNoSkip, (src, dest) => new { src, dest }).Zip(collisionsNoSkip, (z1, coll) => new { z1.src, z1.dest, coll });
var sourceMatch = await failedSources.Select(x => copyZip.SingleOrDefault(s => s.src.Path.Equals(x.Source, StringComparison.OrdinalIgnoreCase))).Where(x => x is not null).ToListAsync();
return await CopyItemsAsync(
await sourceMatch.Select(x => x.src).ToListAsync(),
await sourceMatch.Select(x => x.dest).ToListAsync(),
// Force collision option to "replace" to accept moving with property loss
// Ok since property loss error is raised after checking if the destination already exists
await sourceMatch.Select(x => FileNameConflictResolveOptionType.ReplaceExisting).ToListAsync(), progress, cancellationToken);
}
}
else if (moveResult.Items.All(x => x.HResult == -1)) // ADS
{
// Retry with StorageFile API
Expand Down
17 changes: 2 additions & 15 deletions src/Files.App/Helpers/Convert/ErrorCodeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,22 @@ public static ReturnResult ToStatus(this FileSystemStatusCode errorCode)
case FileSystemStatusCode.Success:
return ReturnResult.Success;

case FileSystemStatusCode.Generic:
return ReturnResult.Failed;

case FileSystemStatusCode.Unauthorized:
case FileSystemStatusCode.InUse:
return ReturnResult.AccessUnauthorized;

case FileSystemStatusCode.NotFound:
return ReturnResult.IntegrityCheckFailed;

case FileSystemStatusCode.InUse:
return ReturnResult.AccessUnauthorized;

case FileSystemStatusCode.NameTooLong:
return ReturnResult.UnknownException;

case FileSystemStatusCode.AlreadyExists:
return ReturnResult.Failed;

case FileSystemStatusCode.NotAFolder:
return ReturnResult.BadArgumentException;

case FileSystemStatusCode.NotAFile:
return ReturnResult.BadArgumentException;

case FileSystemStatusCode.InProgress:
return ReturnResult.InProgress;

default:
return default;
return ReturnResult.Failed;
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2878,4 +2878,16 @@
<data name="CloseTab" xml:space="preserve">
<value>Closes current tab</value>
</data>
<data name="CopyFileWithoutProperties" xml:space="preserve">
<value>Are you sure you want to copy these files without their properties?</value>
</data>
<data name="FilePropertiesCannotBeCopied" xml:space="preserve">
<value>These files have properties that can't be copied to the new location</value>
</data>
<data name="FilePropertiesCannotBeMoved" xml:space="preserve">
<value>These files have properties that can't be moved to the new location</value>
</data>
<data name="MoveFileWithoutProperties" xml:space="preserve">
<value>Are you sure you want to move these files without their properties?</value>
</data>
</root>
11 changes: 11 additions & 0 deletions src/Files.Shared/Enums/CopyEngineResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public struct CopyEngineResult
//public const int COPYENGINE_E_SAME_FILE = -2144927741;
//public const int COPYENGINE_E_DEST_SAME_TREE = -2144927734;
//public const int COPYENGINE_E_DEST_SUBTREE = -2144927735;
// Property loss
public const int COPYENGINE_E_STREAM_LOSS = -2144927699; // Secondary Stream information would be lost
public const int COPYENGINE_E_EA_LOSS = -2144927698; // Extended Attributes would be lost
public const int COPYENGINE_E_PROPERTY_LOSS = -2144927697; // Property would be lost
public const int COPYENGINE_E_PROPERTIES_LOSS = -2144927696; // Properties would be lost
public const int COPYENGINE_E_ENCRYPTION_LOSS = -2144927695; // Encryption would be lost

public static FileSystemStatusCode Convert(int? hres)
{
Expand Down Expand Up @@ -73,6 +79,11 @@ public static FileSystemStatusCode Convert(int? hres)
CopyEngineResult.COPYENGINE_E_FLD_IS_FILE_DEST => FileSystemStatusCode.NotAFolder,
CopyEngineResult.COPYENGINE_E_SHARING_VIOLATION_SRC => FileSystemStatusCode.InUse,
CopyEngineResult.COPYENGINE_E_SHARING_VIOLATION_DEST => FileSystemStatusCode.InUse,
CopyEngineResult.COPYENGINE_E_STREAM_LOSS => FileSystemStatusCode.PropertyLoss,
CopyEngineResult.COPYENGINE_E_EA_LOSS => FileSystemStatusCode.PropertyLoss,
CopyEngineResult.COPYENGINE_E_PROPERTY_LOSS => FileSystemStatusCode.PropertyLoss,
CopyEngineResult.COPYENGINE_E_PROPERTIES_LOSS => FileSystemStatusCode.PropertyLoss,
CopyEngineResult.COPYENGINE_E_ENCRYPTION_LOSS => FileSystemStatusCode.PropertyLoss,
null => FileSystemStatusCode.Generic,
_ => FileSystemStatusCode.Generic
};
Expand Down
3 changes: 2 additions & 1 deletion src/Files.Shared/Enums/FileSystemStatusCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum FileSystemStatusCode
NotAFolder = 64,
NotAFile = 128,
ReadOnly = 256,
InProgress = 512
PropertyLoss = 512,
InProgress = 1024
}
}