Skip to content

Fix create folder with selection #8929

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 3 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fixed create folder with selection command
Show access denied dialog if operation fails despite being admin
  • Loading branch information
gave92 committed Apr 16, 2022
commit e245b361e69ff3bb38eaacd81aabceef836922b9
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ await DialogDisplayHelper.ShowDialogAsync(
if (result == ContentDialogResult.Primary)
{
progress?.Report(100.0f);
errorCode?.Report(FileSystemStatusCode.InProgress | FileSystemStatusCode.Success);
errorCode?.Report(FileSystemStatusCode.Success);
}
else
{
progress?.Report(100.0f);
errorCode?.Report(FileSystemStatusCode.InProgress | FileSystemStatusCode.Generic);
errorCode?.Report(FileSystemStatusCode.Generic);
}
return null;
}
Expand Down Expand Up @@ -369,12 +369,12 @@ await DialogDisplayHelper.ShowDialogAsync(
if (result == ContentDialogResult.Primary)
{
progress?.Report(100.0f);
errorCode?.Report(FileSystemStatusCode.InProgress | FileSystemStatusCode.Success);
errorCode?.Report(FileSystemStatusCode.Success);
}
else
{
progress?.Report(100.0f);
errorCode?.Report(FileSystemStatusCode.InProgress | FileSystemStatusCode.Generic);
errorCode?.Report(FileSystemStatusCode.Generic);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public async Task<IStorageHistory> CopyItemsAsync(IList<IStorageItemWithPath> so
{
return await CopyItemsAsync(source, destination, collisions, progress, errorCode, cancellationToken);
}
else if (App.MainViewModel.IsFullTrustElevated) // App elevated but still gettting AccessDenied
{
await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "AccessDeniedDialog/Text".GetLocalized());
}
}
else if (copyResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.InUse))
{
Expand Down Expand Up @@ -260,7 +264,8 @@ await sourceMatch.Select(x => x.dest).ToListAsync(),
if (createdSources.Any())
{
var item = StorageHelpers.FromPathAndType(createdSources.Single().Destination, source.ItemType);
return (new StorageHistory(FileOperationType.CreateNew, item.CreateList(), null), item.Item);
var storageItem = await item.ToStorageItem(associatedInstance);
return (new StorageHistory(FileOperationType.CreateNew, item.CreateList(), null), storageItem);
}
return (null, null);
}
Expand All @@ -272,6 +277,10 @@ await sourceMatch.Select(x => x.dest).ToListAsync(),
{
return await CreateAsync(source, errorCode, cancellationToken);
}
else if (App.MainViewModel.IsFullTrustElevated) // App elevated but still gettting AccessDenied
{
await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "AccessDeniedCreateDialog/Text".GetLocalized());
}
}
else if (createResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.NameTooLong))
{
Expand Down Expand Up @@ -421,6 +430,10 @@ public async Task<IStorageHistory> DeleteItemsAsync(IList<IStorageItemWithPath>
{
return await DeleteItemsAsync(source, progress, errorCode, permanently, cancellationToken);
}
else if (App.MainViewModel.IsFullTrustElevated) // App elevated but still gettting AccessDenied
{
await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "AccessDeniedDeleteDialog/Text".GetLocalized());
}
}
else if (deleteResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.InUse))
{
Expand Down Expand Up @@ -557,6 +570,10 @@ public async Task<IStorageHistory> MoveItemsAsync(IList<IStorageItemWithPath> so
{
return await MoveItemsAsync(source, destination, collisions, progress, errorCode, cancellationToken);
}
else if (App.MainViewModel.IsFullTrustElevated) // App elevated but still gettting AccessDenied
{
await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "AccessDeniedDialog/Text".GetLocalized());
}
}
else if (source.Zip(destination, (src, dest) => (src, dest)).FirstOrDefault(x => x.src.ItemType == FilesystemItemType.Directory && PathNormalization.GetParentDir(x.dest).IsSubPathOf(x.src.Path)) is (IStorageItemWithPath, string) subtree)
{
Expand Down Expand Up @@ -646,6 +663,10 @@ public async Task<IStorageHistory> RenameAsync(IStorageItemWithPath source, stri
{
return await RenameAsync(source, newName, collision, errorCode, cancellationToken);
}
else if (App.MainViewModel.IsFullTrustElevated) // App elevated but still gettting AccessDenied
{
await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "AccessDeniedDialog/Text".GetLocalized());
}
}
else if (renameResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.InUse))
{
Expand Down Expand Up @@ -754,6 +775,10 @@ public async Task<IStorageHistory> RestoreItemsFromTrashAsync(IList<IStorageItem
{
return await RestoreItemsFromTrashAsync(source, destination, progress, errorCode, cancellationToken);
}
else if (App.MainViewModel.IsFullTrustElevated) // App elevated but still gettting AccessDenied
{
await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "");
}
}
else if (moveResult.Items.Any(x => CopyEngineResult.Convert(x.HResult) == FileSystemStatusCode.InUse))
{
Expand Down
10 changes: 5 additions & 5 deletions src/Files.Uwp/Helpers/Convert/ErrorCodeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static ReturnResult ToStatus(this FileSystemStatusCode errorCode)
return ReturnResult.Success;

case FileSystemStatusCode.Generic:
return ReturnResult.InProgress | ReturnResult.Cancelled;
return ReturnResult.Failed;

case FileSystemStatusCode.Unauthorized:
return ReturnResult.AccessUnauthorized;
Expand All @@ -24,16 +24,16 @@ public static ReturnResult ToStatus(this FileSystemStatusCode errorCode)
return ReturnResult.AccessUnauthorized;

case FileSystemStatusCode.NameTooLong:
return ReturnResult.UnknownException;
return ReturnResult.Failed;

case FileSystemStatusCode.AlreadyExists:
return ReturnResult.Failed | ReturnResult.UnknownException;
return ReturnResult.Failed;

case FileSystemStatusCode.NotAFolder:
return ReturnResult.BadArgumentException | ReturnResult.IntegrityCheckFailed;
return ReturnResult.BadArgumentException;

case FileSystemStatusCode.NotAFile:
return ReturnResult.BadArgumentException | ReturnResult.IntegrityCheckFailed;
return ReturnResult.BadArgumentException;

case FileSystemStatusCode.InProgress:
return ReturnResult.InProgress;
Expand Down
51 changes: 19 additions & 32 deletions src/Files.Uwp/Helpers/UIFilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,53 +329,40 @@ public static async Task<IStorageItem> CreateFileFromDialogResultTypeForResult(A
}

// Create file based on dialog result
var folderRes = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(currentPath);
var created = new FilesystemResult<(ReturnResult, IStorageItem)>((ReturnResult.Failed, null), FileSystemStatusCode.Generic);
if (folderRes)
(ReturnResult Status, IStorageItem Item) created = (ReturnResult.Failed, null);
switch (itemType)
{
switch (itemType)
{
case AddItemDialogItemType.Folder:
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized();
created = await FilesystemTasks.Wrap(async () =>
{
return await associatedInstance.FilesystemHelpers.CreateAsync(
StorageHelpers.FromPathAndType(PathNormalization.Combine(folderRes.Result.Path, userInput), FilesystemItemType.Directory),
true);
});
break;
case AddItemDialogItemType.Folder:
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized();
created = await associatedInstance.FilesystemHelpers.CreateAsync(
StorageHelpers.FromPathAndType(PathNormalization.Combine(currentPath, userInput), FilesystemItemType.Directory),
true);
break;

case AddItemDialogItemType.File:
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : itemInfo?.Name ?? "NewFile".GetLocalized();
created = await FilesystemTasks.Wrap(async () =>
{
return await associatedInstance.FilesystemHelpers.CreateAsync(
StorageHelpers.FromPathAndType(PathNormalization.Combine(folderRes.Result.Path, userInput + itemInfo?.Extension), FilesystemItemType.File),
true);
});
break;
}
}

if (created == FileSystemStatusCode.Unauthorized)
{
await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "AccessDeniedCreateDialog/Text".GetLocalized());
case AddItemDialogItemType.File:
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : itemInfo?.Name ?? "NewFile".GetLocalized();
created = await associatedInstance.FilesystemHelpers.CreateAsync(
StorageHelpers.FromPathAndType(PathNormalization.Combine(currentPath, userInput + itemInfo?.Extension), FilesystemItemType.File),
true);
break;
}

return created.Result.Item2;
return created.Item;
}

public static async Task CreateFolderWithSelectionAsync(IShellPage associatedInstance)
{
try
{
await CopyItem(associatedInstance);
var items = associatedInstance.SlimContentPage.SelectedItems.ToList().Select((item) => StorageHelpers.FromPathAndType(
item.ItemPath,
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
var folder = await CreateFileFromDialogResultTypeForResult(AddItemDialogItemType.Folder, null, associatedInstance);
if (folder == null)
{
return;
}
await associatedInstance.FilesystemHelpers.MoveItemsFromClipboard(Clipboard.GetContent(), folder.Path, false, true);
await associatedInstance.FilesystemHelpers.MoveItemsAsync(items, items.Select(x => PathNormalization.Combine(folder.Path, x.Name)), false, true);
}
catch (Exception ex)
{
Expand Down
24 changes: 20 additions & 4 deletions src/Files.Uwp/MultilingualResources/Files.it-IT.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@
<source>Application</source>
<target state="translated">Applicazione</target>
</trans-unit>
<trans-unit id="SystemTimeStye" translate="yes" xml:space="preserve">
<source>System</source>
<target state="translated">Sistema</target>
</trans-unit>
<trans-unit id="NewFolder" translate="yes" xml:space="preserve">
<source>New Folder</source>
<target state="translated">Nuova cartella</target>
Expand Down Expand Up @@ -3522,6 +3518,26 @@ Usiamo App Center per tenere traccia dell'utilizzo dell'app, trovare bug e risol
<source>File is in use</source>
<target state="translated">Il file è in uso</target>
</trans-unit>
<trans-unit id="SystemTimeStyle" translate="yes" xml:space="preserve">
<source>System</source>
<target state="new">System</target>
</trans-unit>
<trans-unit id="Universal" translate="yes" xml:space="preserve">
<source>Universal</source>
<target state="new">Universal</target>
</trans-unit>
<trans-unit id="DateFormatSample" translate="yes" xml:space="preserve">
<source>ex: {0}, {1}</source>
<target state="new">ex: {0}, {1}</target>
</trans-unit>
<trans-unit id="SettingsFilesAndFoldersShowThumbnails" translate="yes" xml:space="preserve">
<source>Show thumbnails</source>
<target state="new">Show thumbnails</target>
</trans-unit>
<trans-unit id="AccessDeniedDialog.Text" translate="yes" xml:space="preserve">
<source>We weren't able to complete this operation</source>
<target state="translated">Non è stato possibile completare questa operazione</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
57 changes: 30 additions & 27 deletions src/Files.Uwp/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

<!--
Microsoft ResX Schema
Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -2759,4 +2759,7 @@ We use App Center to track which settings are being used, find bugs, and fix cra
<data name="SettingsFilesAndFoldersShowThumbnails" xml:space="preserve">
<value>Show thumbnails</value>
</data>
<data name="AccessDeniedDialog.Text" xml:space="preserve">
<value>We weren't able to complete this operation</value>
</data>
</root>