Skip to content
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

Fix crash on illegal paste operation #580

Merged
merged 4 commits into from
Apr 12, 2020
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
6 changes: 3 additions & 3 deletions Files/Dialogs/AddItemDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static async void CreateFile(AddItemType fileType)
{
folder = await folderToCreateItem.CreateFolderAsync("New Folder", CreationCollisionOption.GenerateUniqueName);
}
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(folder.FolderRelativeId) { ItemName = folder.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = false, LoadFolderGlyph = true, LoadFileIcon = false, ItemType = "Folder", FileImage = null, ItemPath = folder.Path });
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(folder.FolderRelativeId) { PrimaryItemAttribute = StorageItemTypes.Folder, ItemName = folder.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = false, LoadFolderGlyph = true, LoadFileIcon = false, ItemType = "Folder", FileImage = null, ItemPath = folder.Path });
}
else if (fileType == AddItemType.TextDocument)
{
Expand All @@ -84,7 +84,7 @@ public static async void CreateFile(AddItemType fileType)
{
item = await folderToCreateItem.CreateFileAsync("New Text Document" + ".txt", CreationCollisionOption.GenerateUniqueName);
}
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId) { ItemName = item.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = true, LoadFolderGlyph = false, LoadFileIcon = false, ItemType = item.DisplayType, FileImage = null, ItemPath = item.Path, FileExtension = item.FileType });
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId) { PrimaryItemAttribute = StorageItemTypes.File, ItemName = item.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = true, LoadFolderGlyph = false, LoadFileIcon = false, ItemType = item.DisplayType, FileImage = null, ItemPath = item.Path, FileExtension = item.FileType });
}
else if (fileType == AddItemType.BitmapImage)
{
Expand All @@ -97,7 +97,7 @@ public static async void CreateFile(AddItemType fileType)
{
item = await folderToCreateItem.CreateFileAsync("New Bitmap Image" + ".bmp", CreationCollisionOption.GenerateUniqueName);
}
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId) { ItemName = item.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = true, LoadFolderGlyph = false, LoadFileIcon = false, ItemType = item.DisplayType, FileImage = null, ItemPath = item.Path, FileExtension = item.FileType });
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId) { PrimaryItemAttribute = StorageItemTypes.File, ItemName = item.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = true, LoadFolderGlyph = false, LoadFileIcon = false, ItemType = item.DisplayType, FileImage = null, ItemPath = item.Path, FileExtension = item.FileType });
}
}
}
Expand Down
40 changes: 36 additions & 4 deletions Files/Interacts/Interaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using Windows.UI.WindowManagement.Preview;
using Windows.UI;
using Files.View_Models;
using GalaSoft.MvvmLight.Command;

namespace Files.Interacts
{
Expand Down Expand Up @@ -906,9 +907,16 @@ public async void CopyItem_ClickAsync(object sender, RoutedEventArgs e)

}

enum ImpossibleActionResponseTypes
{
Skip,
Abort
}

public async void PasteItem_ClickAsync(object sender, RoutedEventArgs e)
{
string destinationPath = CurrentInstance.ViewModel.WorkingDirectory;
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForViewIndependentUse();

DataPackageView packageView = Clipboard.GetContent();
itemsToPaste = await packageView.GetStorageItemsAsync();
Expand All @@ -921,12 +929,36 @@ public async void PasteItem_ClickAsync(object sender, RoutedEventArgs e)

foreach (IStorageItem item in itemsToPaste)
{

if (item.IsOfType(StorageItemTypes.Folder))
{
StorageFolder pastedFolder = await CloneDirectoryAsync(item.Path, destinationPath, item.Name, false);
CurrentInstance.ViewModel.AddFolder(pastedFolder.Path);
pastedItemPaths.Add(pastedFolder.Path);
if (destinationPath.Contains(item.Path, StringComparison.OrdinalIgnoreCase))
{
ImpossibleActionResponseTypes responseType = ImpossibleActionResponseTypes.Abort;
ContentDialog dialog = new ContentDialog()
{
Title = resourceLoader.GetString("ErrorDialogThisActionCannotBeDone"),
Content = resourceLoader.GetString("ErrorDialogTheDestinationFolder") + " (" + destinationPath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries).Last() + ") " + resourceLoader.GetString("ErrorDialogIsASubfolder") + "(" + item.Name + ")",
PrimaryButtonText = resourceLoader.GetString("ErrorDialogSkip"),
CloseButtonText = resourceLoader.GetString("ErrorDialogCancel"),
PrimaryButtonCommand = new RelayCommand(() => { responseType = ImpossibleActionResponseTypes.Skip; }),
CloseButtonCommand = new RelayCommand(() => { responseType = ImpossibleActionResponseTypes.Abort; })
};
await dialog.ShowAsync();
if (responseType == ImpossibleActionResponseTypes.Skip)
{
continue;
}
else if (responseType == ImpossibleActionResponseTypes.Abort)
{
return;
}
}
else
{
StorageFolder pastedFolder = await CloneDirectoryAsync(item.Path, destinationPath, item.Name, false);
CurrentInstance.ViewModel.AddFolder(pastedFolder.Path);
pastedItemPaths.Add(pastedFolder.Path);
}
}
else if (item.IsOfType(StorageItemTypes.File))
{
Expand Down
22 changes: 21 additions & 1 deletion Files/MultilingualResources/Files.de-DE.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,27 @@
<source>Settings</source>
<target state="translated">Einstellungen</target>
</trans-unit>
<trans-unit id="ErrorDialogThisActionCannotBeDone" translate="yes" xml:space="preserve">
<source>This action cannot be done</source>
<target state="new">This action cannot be done</target>
</trans-unit>
<trans-unit id="ErrorDialogTheDestinationFolder" translate="yes" xml:space="preserve">
<source>The destination folder</source>
<target state="new">The destination folder</target>
</trans-unit>
<trans-unit id="ErrorDialogIsASubfolder" translate="yes" xml:space="preserve">
<source>is a subfolder of the source folder</source>
<target state="new">is a subfolder of the source folder</target>
</trans-unit>
<trans-unit id="ErrorDialogSkip" translate="yes" xml:space="preserve">
<source>Skip</source>
<target state="new">Skip</target>
</trans-unit>
<trans-unit id="ErrorDialogCancel" translate="yes" xml:space="preserve">
<source>Cancel</source>
<target state="new">Cancel</target>
</trans-unit>
</group>
</body>
</file>
</xliff>
</xliff>
22 changes: 21 additions & 1 deletion Files/MultilingualResources/Files.es-ES.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,27 @@
<source>Settings</source>
<target state="translated">Ajustes</target>
</trans-unit>
<trans-unit id="ErrorDialogThisActionCannotBeDone" translate="yes" xml:space="preserve">
<source>This action cannot be done</source>
<target state="new">This action cannot be done</target>
</trans-unit>
<trans-unit id="ErrorDialogTheDestinationFolder" translate="yes" xml:space="preserve">
<source>The destination folder</source>
<target state="new">The destination folder</target>
</trans-unit>
<trans-unit id="ErrorDialogIsASubfolder" translate="yes" xml:space="preserve">
<source>is a subfolder of the source folder</source>
<target state="new">is a subfolder of the source folder</target>
</trans-unit>
<trans-unit id="ErrorDialogSkip" translate="yes" xml:space="preserve">
<source>Skip</source>
<target state="new">Skip</target>
</trans-unit>
<trans-unit id="ErrorDialogCancel" translate="yes" xml:space="preserve">
<source>Cancel</source>
<target state="new">Cancel</target>
</trans-unit>
</group>
</body>
</file>
</xliff>
</xliff>
20 changes: 20 additions & 0 deletions Files/MultilingualResources/Files.fr-FR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@
<source>Settings</source>
<target state="new">Settings</target>
</trans-unit>
<trans-unit id="ErrorDialogThisActionCannotBeDone" translate="yes" xml:space="preserve">
<source>This action cannot be done</source>
<target state="new">This action cannot be done</target>
</trans-unit>
<trans-unit id="ErrorDialogTheDestinationFolder" translate="yes" xml:space="preserve">
<source>The destination folder</source>
<target state="new">The destination folder</target>
</trans-unit>
<trans-unit id="ErrorDialogIsASubfolder" translate="yes" xml:space="preserve">
<source>is a subfolder of the source folder</source>
<target state="new">is a subfolder of the source folder</target>
</trans-unit>
<trans-unit id="ErrorDialogSkip" translate="yes" xml:space="preserve">
<source>Skip</source>
<target state="new">Skip</target>
</trans-unit>
<trans-unit id="ErrorDialogCancel" translate="yes" xml:space="preserve">
<source>Cancel</source>
<target state="new">Cancel</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
20 changes: 20 additions & 0 deletions Files/MultilingualResources/Files.nl-NL.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@
<source>Settings</source>
<target state="new">Settings</target>
</trans-unit>
<trans-unit id="ErrorDialogThisActionCannotBeDone" translate="yes" xml:space="preserve">
<source>This action cannot be done</source>
<target state="new">This action cannot be done</target>
</trans-unit>
<trans-unit id="ErrorDialogTheDestinationFolder" translate="yes" xml:space="preserve">
<source>The destination folder</source>
<target state="new">The destination folder</target>
</trans-unit>
<trans-unit id="ErrorDialogIsASubfolder" translate="yes" xml:space="preserve">
<source>is a subfolder of the source folder</source>
<target state="new">is a subfolder of the source folder</target>
</trans-unit>
<trans-unit id="ErrorDialogSkip" translate="yes" xml:space="preserve">
<source>Skip</source>
<target state="new">Skip</target>
</trans-unit>
<trans-unit id="ErrorDialogCancel" translate="yes" xml:space="preserve">
<source>Cancel</source>
<target state="new">Cancel</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
20 changes: 20 additions & 0 deletions Files/MultilingualResources/Files.pl-PL.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@
<source>Settings</source>
<target state="new">Settings</target>
</trans-unit>
<trans-unit id="ErrorDialogThisActionCannotBeDone" translate="yes" xml:space="preserve">
<source>This action cannot be done</source>
<target state="new">This action cannot be done</target>
</trans-unit>
<trans-unit id="ErrorDialogTheDestinationFolder" translate="yes" xml:space="preserve">
<source>The destination folder</source>
<target state="new">The destination folder</target>
</trans-unit>
<trans-unit id="ErrorDialogIsASubfolder" translate="yes" xml:space="preserve">
<source>is a subfolder of the source folder</source>
<target state="new">is a subfolder of the source folder</target>
</trans-unit>
<trans-unit id="ErrorDialogSkip" translate="yes" xml:space="preserve">
<source>Skip</source>
<target state="new">Skip</target>
</trans-unit>
<trans-unit id="ErrorDialogCancel" translate="yes" xml:space="preserve">
<source>Cancel</source>
<target state="new">Cancel</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
20 changes: 20 additions & 0 deletions Files/MultilingualResources/Files.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@
<source>Settings</source>
<target state="new">Settings</target>
</trans-unit>
<trans-unit id="ErrorDialogThisActionCannotBeDone" translate="yes" xml:space="preserve">
<source>This action cannot be done</source>
<target state="new">This action cannot be done</target>
</trans-unit>
<trans-unit id="ErrorDialogTheDestinationFolder" translate="yes" xml:space="preserve">
<source>The destination folder</source>
<target state="new">The destination folder</target>
</trans-unit>
<trans-unit id="ErrorDialogIsASubfolder" translate="yes" xml:space="preserve">
<source>is a subfolder of the source folder</source>
<target state="new">is a subfolder of the source folder</target>
</trans-unit>
<trans-unit id="ErrorDialogSkip" translate="yes" xml:space="preserve">
<source>Skip</source>
<target state="new">Skip</target>
</trans-unit>
<trans-unit id="ErrorDialogCancel" translate="yes" xml:space="preserve">
<source>Cancel</source>
<target state="new">Cancel</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
2 changes: 1 addition & 1 deletion Files/Strings/de-DE/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<value>Sind Sie sicher, dass sie die ausgewählten Dateien löschen möchten?</value>
</data>
<data name="ConfirmDeleteDialogPermanentlyDeleteCheckBox.Content" xml:space="preserve">
<value>Dauerhaft löschen</value>
<value>Endgültig löschen</value>
</data>
<data name="SettingsPreferencesShowConfirmDeleteDialog.Text" xml:space="preserve">
<value>Einen Bestätigungsdialog anzeigen bevor Dateien und Ordner gelöscht werden</value>
Expand Down
15 changes: 15 additions & 0 deletions Files/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@
<data name="PropertiesItemSize.Text" xml:space="preserve">
<value>Size:</value>
</data>
<data name="ErrorDialogThisActionCannotBeDone" xml:space="preserve">
<value>This action cannot be done</value>
</data>
<data name="ErrorDialogTheDestinationFolder" xml:space="preserve">
<value>The destination folder</value>
</data>
<data name="ErrorDialogIsASubfolder" xml:space="preserve">
<value>is a subfolder of the source folder</value>
</data>
<data name="ErrorDialogSkip" xml:space="preserve">
<value>Skip</value>
</data>
<data name="ErrorDialogCancel" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="PropertiesItemType.Text" xml:space="preserve">
<value>Item type:</value>
</data>
Expand Down
Loading