diff --git a/Files.Launcher/DragDropForm.cs b/Files.Launcher/DragDropForm.cs
index a9b1fe759aea..081c4d1852c9 100644
--- a/Files.Launcher/DragDropForm.cs
+++ b/Files.Launcher/DragDropForm.cs
@@ -2,9 +2,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using System.Windows.Forms;
namespace FilesFullTrust
@@ -45,7 +42,8 @@ public DragDropForm(string dropPath, string dropText, System.Threading.Cancellat
this.Size = new System.Drawing.Size(lpRect.Width, lpRect.Height);
this.Location = new System.Drawing.Point(lpRect.Location.X, lpRect.Location.Y);
- token.Register(() => {
+ token.Register(() =>
+ {
if (this.IsHandleCreated)
{
// If another window is created, close this one
@@ -127,4 +125,4 @@ protected override CreateParams CreateParams
}
}
}
-}
+}
\ No newline at end of file
diff --git a/Files.Launcher/Program.cs b/Files.Launcher/Program.cs
index 0664b5f9c75c..23c861db3470 100644
--- a/Files.Launcher/Program.cs
+++ b/Files.Launcher/Program.cs
@@ -462,9 +462,13 @@ await Win32API.StartSTATask(() =>
}
using var shi = new ShellItem(fileToDeletePath);
op.QueueDeleteOperation(shi);
+ op.PostDeleteItem += async (s, e) =>
+ {
+ await args.Request.SendResponseAsync(new ValueSet() {
+ { "Success", e.Result.Succeeded } });
+ };
op.PerformOperations();
}
- //ShellFileOperations.Delete(fileToDeletePath, ShellFileOperations.OperationFlags.AllowUndo | ShellFileOperations.OperationFlags.NoUI);
break;
case "ParseLink":
diff --git a/Files.Package/Files.Package.wapproj b/Files.Package/Files.Package.wapproj
index 8c601af6c80e..5c1dfd98b981 100644
--- a/Files.Package/Files.Package.wapproj
+++ b/Files.Package/Files.Package.wapproj
@@ -54,6 +54,8 @@
x86|x64|arm|arm64
False
True
+ Scale|DXFeatureLevel
+ Language=en-US;de-DE;es-ES;fr-FR;he-IL;hi-IN;hu-HU;it-IT;ja-JP;nl-NL;or-IN;pl-PL;pt-BR;ru-RU;ta;tr-TR;uk-UA;zh-Hans;zh-Hant
StoreUpload
0
..\Files\Files.csproj
@@ -142,8 +144,6 @@
-
-
\ No newline at end of file
diff --git a/Files.Package/Package.appxmanifest b/Files.Package/Package.appxmanifest
index 765d819cb53c..a3558edd496c 100644
--- a/Files.Package/Package.appxmanifest
+++ b/Files.Package/Package.appxmanifest
@@ -9,7 +9,7 @@
xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4"
xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
IgnorableNamespaces="uap uap5 mp rescap desktop4 desktop">
-
+
Files - Dev
Yair A
diff --git a/Files.Package/priconfig.default.xml b/Files.Package/priconfig.default.xml
deleted file mode 100644
index 980fc1a84224..000000000000
--- a/Files.Package/priconfig.default.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/Files.Package/priconfig.packaging.xml b/Files.Package/priconfig.packaging.xml
deleted file mode 100644
index a8b3b89f6e65..000000000000
--- a/Files.Package/priconfig.packaging.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/Files/BaseLayout.cs b/Files/BaseLayout.cs
index fba410d6d789..d60364888570 100644
--- a/Files/BaseLayout.cs
+++ b/Files/BaseLayout.cs
@@ -1,4 +1,5 @@
using Files.Common;
+using Files.DataModels;
using Files.Filesystem;
using Files.Helpers;
using Files.UserControls;
@@ -9,9 +10,9 @@
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Newtonsoft.Json;
using System;
+using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
-using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
@@ -136,6 +137,8 @@ internal set
public ListedItem SelectedItem { get; private set; }
+ private List cachedNewContextMenuEntries { get; set; }
+
public BaseLayout()
{
SelectedItemsPropertiesViewModel = new SelectedItemsPropertiesViewModel(this);
@@ -151,9 +154,19 @@ public BaseLayout()
}
}
+ public abstract void FocusFileList();
+
public abstract void SelectAllItems();
- public abstract void InvertSelection();
+ public virtual void InvertSelection()
+ {
+ List newSelectedItems = GetAllItems()
+ .Cast()
+ .Except(SelectedItems)
+ .ToList();
+
+ SetSelectedItemsOnUi(newSelectedItems);
+ }
public abstract void ClearSelection();
@@ -161,13 +174,29 @@ public BaseLayout()
public abstract void ScrollIntoView(ListedItem item);
- public abstract int GetSelectedIndex();
+ protected abstract void AddSelectedItem(ListedItem item);
+
+ protected abstract IEnumerable GetAllItems();
- public abstract void SetSelectedItemOnUi(ListedItem selectedItem);
+ public virtual void SetSelectedItemOnUi(ListedItem selectedItem)
+ {
+ ClearSelection();
+ AddSelectedItem(selectedItem);
+ }
- public abstract void SetSelectedItemsOnUi(List selectedItems);
+ public virtual void SetSelectedItemsOnUi(List selectedItems)
+ {
+ ClearSelection();
+ AddSelectedItemsOnUi(selectedItems);
+ }
- public abstract void AddSelectedItemsOnUi(List selectedItems);
+ public virtual void AddSelectedItemsOnUi(List selectedItems)
+ {
+ foreach (ListedItem selectedItem in selectedItems)
+ {
+ AddSelectedItem(selectedItem);
+ }
+ }
private void ClearShellContextMenus(MenuFlyout menuFlyout)
{
@@ -176,6 +205,7 @@ private void ClearShellContextMenus(MenuFlyout menuFlyout)
{
menuFlyout.Items.RemoveAt(menuFlyout.Items.IndexOf(contextMenuItems[i]));
}
+
if (menuFlyout.Items[0] is MenuFlyoutSeparator flyoutSeperator)
{
menuFlyout.Items.RemoveAt(menuFlyout.Items.IndexOf(flyoutSeperator));
@@ -219,9 +249,31 @@ public virtual void SetShellContextmenu(MenuFlyout menuFlyout, bool shiftPressed
public abstract void StartRenameItem();
- public abstract void ResetItemOpacity();
+ public virtual void ResetItemOpacity()
+ {
+ IEnumerable items = GetAllItems();
+ if (items == null)
+ {
+ return;
+ }
+
+ foreach (ListedItem listedItem in items)
+ {
+ if (listedItem.IsHiddenItem)
+ {
+ listedItem.Opacity = 0.4;
+ }
+ else
+ {
+ listedItem.Opacity = 1;
+ }
+ }
+ }
- public abstract void SetItemOpacity(ListedItem item);
+ public virtual void SetItemOpacity(ListedItem item)
+ {
+ item.Opacity = 0.4;
+ }
protected abstract ListedItem GetItemFromElement(object element);
@@ -301,6 +353,10 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
ParentShellPageInstance.InstanceViewModel.IsPageTypeNotHome = true; // show controls that were hidden on the home page
ParentShellPageInstance.Clipboard_ContentChanged(null, null);
+
+ cachedNewContextMenuEntries = await RegistryHelper.GetNewContextMenuEntries();
+
+ FocusFileList(); // Set focus on layout specific file list control
}
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
@@ -314,10 +370,17 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
private void UnloadMenuFlyoutItemByName(string nameToUnload)
{
- var menuItem = this.FindName(nameToUnload) as DependencyObject;
- if (menuItem != null) // Prevent crash if the MenuFlyoutItem is missing
+ if (FindName(nameToUnload) is MenuFlyoutItemBase menuItem) // Prevent crash if the MenuFlyoutItem is missing
+ {
+ menuItem.Visibility = Visibility.Collapsed;
+ }
+ }
+
+ private void LoadMenuFlyoutItemByName(string nameToUnload)
+ {
+ if (FindName(nameToUnload) is MenuFlyoutItemBase menuItem) // Prevent crash if the MenuFlyoutItem is missing
{
- (menuItem as MenuFlyoutItemBase).Visibility = Visibility.Collapsed;
+ menuItem.Visibility = Visibility.Visible;
}
}
@@ -451,6 +514,48 @@ public void RightClickContextMenu_Opening(object sender, object e)
ClearSelection();
var shiftPressed = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
SetShellContextmenu(BaseLayoutContextFlyout, shiftPressed, false);
+ var newItemMenu = (MenuFlyoutSubItem)BaseLayoutContextFlyout.Items.SingleOrDefault(x => x.Name == "NewEmptySpace");
+ if (newItemMenu == null || cachedNewContextMenuEntries == null)
+ {
+ return;
+ }
+ if (!newItemMenu.Items.Any(x => (x.Tag as string) == "CreateNewFile"))
+ {
+ var separatorIndex = newItemMenu.Items.IndexOf(newItemMenu.Items.Single(x => x.Name == "NewMenuFileFolderSeparator"));
+ foreach (var newEntry in Enumerable.Reverse(cachedNewContextMenuEntries))
+ {
+ MenuFlyoutItem menuLayoutItem;
+ if (newEntry.Icon != null)
+ {
+ var image = new BitmapImage();
+#pragma warning disable CS4014
+ image.SetSourceAsync(newEntry.Icon);
+#pragma warning restore CS4014
+ menuLayoutItem = new MenuFlyoutItemWithImage()
+ {
+ Text = newEntry.Name,
+ BitmapIcon = image,
+ Tag = "CreateNewFile"
+ };
+ }
+ else
+ {
+ menuLayoutItem = new MenuFlyoutItem()
+ {
+ Text = newEntry.Name,
+ Icon = new FontIcon()
+ {
+ FontFamily = App.Current.Resources["FluentUIGlyphs"] as Windows.UI.Xaml.Media.FontFamily,
+ Glyph = "\xea00"
+ },
+ Tag = "CreateNewFile"
+ };
+ }
+ menuLayoutItem.Command = ParentShellPageInstance.InteractionOperations.CreateNewFile;
+ menuLayoutItem.CommandParameter = newEntry;
+ newItemMenu.Items.Insert(separatorIndex + 1, menuLayoutItem);
+ }
+ }
}
public void RightClickItemContextMenu_Opening(object sender, object e)
@@ -485,7 +590,7 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
{
if (SelectedItem.IsShortcutItem)
{
- (this.FindName("OpenItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
+ LoadMenuFlyoutItemByName("OpenItem");
UnloadMenuFlyoutItemByName("OpenItemWithAppPicker");
UnloadMenuFlyoutItemByName("RunAsAdmin");
UnloadMenuFlyoutItemByName("RunAsAnotherUser");
@@ -497,42 +602,42 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
UnloadMenuFlyoutItemByName("OpenItemWithAppPicker");
UnloadMenuFlyoutItemByName("RunAsAdmin");
UnloadMenuFlyoutItemByName("RunAsAnotherUser");
- (this.FindName("CreateShortcut") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
+ LoadMenuFlyoutItemByName("CreateShortcut");
}
else if (SelectedItem.FileExtension.Equals(".exe", StringComparison.OrdinalIgnoreCase)
|| SelectedItem.FileExtension.Equals(".bat", StringComparison.OrdinalIgnoreCase))
{
- (this.FindName("OpenItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
+ LoadMenuFlyoutItemByName("OpenItem");
UnloadMenuFlyoutItemByName("OpenItemWithAppPicker");
- (this.FindName("RunAsAdmin") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
- (this.FindName("RunAsAnotherUser") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
- (this.FindName("CreateShortcut") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
+ LoadMenuFlyoutItemByName("RunAsAdmin");
+ LoadMenuFlyoutItemByName("RunAsAnotherUser");
+ LoadMenuFlyoutItemByName("CreateShortcut");
}
else if (SelectedItem.FileExtension.Equals(".msi", StringComparison.OrdinalIgnoreCase))
{
UnloadMenuFlyoutItemByName("OpenItem");
UnloadMenuFlyoutItemByName("OpenItemWithAppPicker");
UnloadMenuFlyoutItemByName("RunAsAdmin");
- (this.FindName("RunAsAnotherUser") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
- (this.FindName("CreateShortcut") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
+ LoadMenuFlyoutItemByName("RunAsAnotherUser");
+ LoadMenuFlyoutItemByName("CreateShortcut");
}
else if (SelectedItem.FileExtension.Equals(".appx", StringComparison.OrdinalIgnoreCase)
|| SelectedItem.FileExtension.Equals(".msix", StringComparison.OrdinalIgnoreCase)
|| SelectedItem.FileExtension.Equals(".appxbundle", StringComparison.OrdinalIgnoreCase)
|| SelectedItem.FileExtension.Equals(".msixbundle", StringComparison.OrdinalIgnoreCase))
{
- (this.FindName("OpenItemWithAppPicker") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
+ LoadMenuFlyoutItemByName("OpenItemWithAppPicker");
UnloadMenuFlyoutItemByName("RunAsAdmin");
UnloadMenuFlyoutItemByName("RunAsAnotherUser");
- (this.FindName("CreateShortcut") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
+ LoadMenuFlyoutItemByName("CreateShortcut");
}
else
{
- (this.FindName("OpenItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
- (this.FindName("OpenItemWithAppPicker") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
+ LoadMenuFlyoutItemByName("OpenItem");
+ LoadMenuFlyoutItemByName("OpenItemWithAppPicker");
UnloadMenuFlyoutItemByName("RunAsAdmin");
UnloadMenuFlyoutItemByName("RunAsAnotherUser");
- (this.FindName("CreateShortcut") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
+ LoadMenuFlyoutItemByName("CreateShortcut");
}
}
}
@@ -555,23 +660,20 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
}
else if (SelectedItems.Count == 1)
{
- (this.FindName("SidebarPinItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
- (this.FindName("CreateShortcut") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
- (this.FindName("OpenItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
+ LoadMenuFlyoutItemByName("SidebarPinItem");
+ LoadMenuFlyoutItemByName("CreateShortcut");
+ LoadMenuFlyoutItemByName("OpenItem");
}
else
{
- (this.FindName("SidebarPinItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
+ LoadMenuFlyoutItemByName("SidebarPinItem");
UnloadMenuFlyoutItemByName("CreateShortcut");
}
if (SelectedItems.Count <= 5 && SelectedItems.Count > 0)
{
- (this.FindName("OpenInNewTab") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
- (this.FindName("OpenInNewWindowItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
- //this.FindName("SidebarPinItem");
- //this.FindName("OpenInNewTab");
- //this.FindName("OpenInNewWindowItem");
+ LoadMenuFlyoutItemByName("OpenInNewTab");
+ LoadMenuFlyoutItemByName("OpenInNewWindowItem");
}
else if (SelectedItems.Count > 5)
{
diff --git a/Files/Constants.cs b/Files/Constants.cs
index 5ada351f36e3..dea0723db8f0 100644
--- a/Files/Constants.cs
+++ b/Files/Constants.cs
@@ -18,8 +18,8 @@ public static class GridViewBrowser
}
public static class GenericFileBrowser
- {
+ {
}
}
}
-}
+}
\ No newline at end of file
diff --git a/Files/Controllers/TerminalController.cs b/Files/Controllers/TerminalController.cs
index 91493a8a605f..dffe859b6d18 100644
--- a/Files/Controllers/TerminalController.cs
+++ b/Files/Controllers/TerminalController.cs
@@ -1,4 +1,5 @@
using Files.DataModels;
+using Files.Filesystem;
using Newtonsoft.Json;
using System;
using System.IO;
@@ -11,9 +12,7 @@ public class TerminalController : IJson
{
private string defaultTerminalPath = "ms-appx:///Assets/terminal/terminal.json";
- private StorageFile JsonFile { get; set; }
-
- private StorageFolder Folder { get; set; }
+ private string folderPath => Path.Combine(ApplicationData.Current.LocalFolder.Path, "settings");
public TerminalFileModel Model { get; set; }
@@ -26,45 +25,69 @@ public TerminalController()
private async Task LoadAsync()
{
- Folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("settings", CreationCollisionOption.OpenIfExists);
- try
+ StorageFolder Folder = await FilesystemTasks.Wrap(() => ApplicationData.Current.LocalFolder.CreateFolderAsync("settings", CreationCollisionOption.OpenIfExists).AsTask());
+ if (Folder == null)
{
- JsonFile = await Folder.GetFileAsync(JsonFileName);
+ Model = await GetDefaultTerminalFileModel();
+ return;
}
- catch (FileNotFoundException)
- {
- var defaultFile = StorageFile.GetFileFromApplicationUriAsync(new Uri(defaultTerminalPath));
- JsonFile = await Folder.CreateFileAsync(JsonFileName);
- await FileIO.WriteBufferAsync(JsonFile, await FileIO.ReadBufferAsync(await defaultFile));
+ var JsonFile = await FilesystemTasks.Wrap(() => Folder.GetFileAsync(JsonFileName).AsTask());
+ if (!JsonFile)
+ {
+ if (JsonFile == FilesystemErrorCode.ERROR_NOTFOUND)
+ {
+ Model = await GetDefaultTerminalFileModel();
+ SaveModel();
+ return;
+ }
+ else
+ {
+ Model = await GetDefaultTerminalFileModel();
+ return;
+ }
}
- var content = await FileIO.ReadTextAsync(JsonFile);
-
try
{
+ var content = await FileIO.ReadTextAsync(JsonFile.Result);
Model = JsonConvert.DeserializeObject(content);
if (Model == null)
{
- Model = new TerminalFileModel();
throw new JsonParsingNullException(JsonFileName);
}
}
catch (JsonParsingNullException)
{
- var defaultFile = StorageFile.GetFileFromApplicationUriAsync(new Uri(defaultTerminalPath));
-
- JsonFile = await Folder.CreateFileAsync(JsonFileName, CreationCollisionOption.ReplaceExisting);
- await FileIO.WriteBufferAsync(JsonFile, await FileIO.ReadBufferAsync(await defaultFile));
- var defaultContent = await FileIO.ReadTextAsync(JsonFile);
- Model = JsonConvert.DeserializeObject(defaultContent);
+ Model = await GetDefaultTerminalFileModel();
+ SaveModel();
}
catch (Exception)
{
- var defaultFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(defaultTerminalPath));
- JsonFile = null;
+ Model = await GetDefaultTerminalFileModel();
+ }
+ }
+
+ private async Task GetDefaultTerminalFileModel()
+ {
+ try
+ {
+ StorageFile defaultFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(defaultTerminalPath));
var defaultContent = await FileIO.ReadTextAsync(defaultFile);
- Model = JsonConvert.DeserializeObject(defaultContent);
+ return JsonConvert.DeserializeObject(defaultContent);
+ }
+ catch
+ {
+ var model = new TerminalFileModel();
+ model.Terminals.Add(new Terminal()
+ {
+ Name = "CMD",
+ Path = "cmd.exe",
+ Arguments = "",
+ Icon = ""
+ });
+ model.ResetToDefaultTerminal();
+ return model;
}
}
@@ -102,16 +125,17 @@ public async Task GetInstalledTerminalsAsync()
public void SaveModel()
{
- if (JsonFile == null)
+ try
{
- return;
+ using (var file = File.CreateText(Path.Combine(folderPath, JsonFileName)))
+ {
+ JsonSerializer serializer = new JsonSerializer();
+ serializer.Formatting = Formatting.Indented;
+ serializer.Serialize(file, Model);
+ }
}
-
- using (var file = File.CreateText(Folder.Path + Path.DirectorySeparatorChar + JsonFileName))
+ catch
{
- JsonSerializer serializer = new JsonSerializer();
- serializer.Formatting = Formatting.Indented;
- serializer.Serialize(file, Model);
}
}
}
diff --git a/Files/DataModels/ShellNewEntry.cs b/Files/DataModels/ShellNewEntry.cs
new file mode 100644
index 000000000000..04bcef94d850
--- /dev/null
+++ b/Files/DataModels/ShellNewEntry.cs
@@ -0,0 +1,55 @@
+using Files.Filesystem;
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using Windows.Storage;
+using Windows.Storage.FileProperties;
+
+namespace Files.DataModels
+{
+ public class ShellNewEntry
+ {
+ public string Extension { get; set; }
+ public string Name { get; set; }
+ public string Command { get; set; }
+ public StorageItemThumbnail Icon { get; set; }
+ public byte[] Data { get; set; }
+ public string Template { get; set; }
+
+ public async Task> Create(string filePath, IShellPage associatedInstance)
+ {
+ var parentFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(filePath));
+ if (parentFolder)
+ {
+ return await Create(parentFolder, Path.GetFileName(filePath));
+ }
+ return new FilesystemResult(null, parentFolder.ErrorCode);
+ }
+
+ public async Task> Create(StorageFolder parentFolder, string fileName)
+ {
+ FilesystemResult createdFile = null;
+ if (!fileName.EndsWith(this.Extension))
+ {
+ fileName += this.Extension;
+ }
+ if (Template == null)
+ {
+ createdFile = await FilesystemTasks.Wrap(() => parentFolder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName).AsTask());
+ }
+ else
+ {
+ createdFile = await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Template).AsTask())
+ .OnSuccess(t => t.CopyAsync(parentFolder, fileName, NameCollisionOption.GenerateUniqueName).AsTask());
+ }
+ if (createdFile)
+ {
+ if (this.Data != null)
+ {
+ await FileIO.WriteBytesAsync(createdFile.Result, this.Data);
+ }
+ }
+ return createdFile;
+ }
+ }
+}
diff --git a/Files/Dialogs/AddItemDialog.xaml b/Files/Dialogs/AddItemDialog.xaml
index 934ce02781c5..3aa976f33aaa 100644
--- a/Files/Dialogs/AddItemDialog.xaml
+++ b/Files/Dialogs/AddItemDialog.xaml
@@ -17,42 +17,59 @@
RequestedTheme="{x:Bind local2:ThemeHelper.RootTheme}"
mc:Ignorable="d">
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+ Source="{x:Bind Icon}"
+ Stretch="Uniform" />
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
+
+
\ No newline at end of file
diff --git a/Files/Dialogs/AddItemDialog.xaml.cs b/Files/Dialogs/AddItemDialog.xaml.cs
index 1fa69e0b4699..8fd1b5bac861 100644
--- a/Files/Dialogs/AddItemDialog.xaml.cs
+++ b/Files/Dialogs/AddItemDialog.xaml.cs
@@ -1,12 +1,16 @@
-using Microsoft.Toolkit.Uwp.Extensions;
-using System.Collections.Generic;
+using Files.DataModels;
+using Files.Helpers;
+using Microsoft.Toolkit.Uwp.Extensions;
+using System;
+using System.Collections.ObjectModel;
using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Media.Imaging;
namespace Files.Dialogs
{
public sealed partial class AddItemDialog : ContentDialog
{
- public AddItemType ResultType { get; private set; } = AddItemType.Cancel;
+ public AddItemResult ResultType { get; private set; } = new AddItemResult() { ItemType = AddItemType.Cancel };
public AddItemDialog()
{
@@ -14,9 +18,9 @@ public AddItemDialog()
AddItemsToList();
}
- public List AddItemsList = new List();
+ public ObservableCollection AddItemsList = new ObservableCollection();
- public void AddItemsToList()
+ public async void AddItemsToList()
{
AddItemsList.Clear();
@@ -24,26 +28,48 @@ public void AddItemsToList()
{
Header = "AddDialogListFolderHeader".GetLocalized(),
SubHeader = "AddDialogListFolderSubHeader".GetLocalized(),
- Icon = "\xE838",
+ Glyph = "\xE838",
IsItemEnabled = true,
- ItemType = AddItemType.Folder
+ ItemType = new AddItemResult() { ItemType = AddItemType.Folder }
});
- AddItemsList.Add(new AddListItem
+ var itemTypes = await RegistryHelper.GetNewContextMenuEntries();
+
+ foreach (var itemType in itemTypes)
{
- Header = "AddDialogListTextFileHeader".GetLocalized(),
- SubHeader = "AddDialogListTextFileSubHeader".GetLocalized(),
- Icon = "\xE8A5",
- IsItemEnabled = true,
- ItemType = AddItemType.TextDocument
- });
+ BitmapImage image = null;
+ if (itemType.Icon != null)
+ {
+ image = new BitmapImage();
+ await image.SetSourceAsync(itemType.Icon);
+ }
+
+ AddItemsList.Add(new AddListItem
+ {
+ Header = itemType.Name,
+ SubHeader = itemType.Extension,
+ Glyph = itemType.Icon != null ? null : "\xE8A5",
+ Icon = image,
+ IsItemEnabled = true,
+ ItemType = new AddItemResult()
+ {
+ ItemType = AddItemType.File,
+ ItemInfo = itemType
+ }
+ });
+ }
+
AddItemsList.Add(new AddListItem
{
- Header = "AddDialogListBitmapHeader".GetLocalized(),
- SubHeader = "AddDialogListBitmapSubHeader".GetLocalized(),
- Icon = "\xEB9F",
+ Header = "AddDialogListFileHeader".GetLocalized(),
+ SubHeader = "AddDialogListFileSubHeader".GetLocalized(),
+ Glyph = "\xE8A5",
IsItemEnabled = true,
- ItemType = AddItemType.BitmapImage
+ ItemType = new AddItemResult()
+ {
+ ItemType = AddItemType.File,
+ ItemInfo = new ShellNewEntry()
+ }
});
}
@@ -56,19 +82,24 @@ private void ListView_ItemClick(object sender, ItemClickEventArgs e)
public enum AddItemType
{
- Folder = 0,
- TextDocument = 1,
- BitmapImage = 2,
- CompressedArchive = 3,
- Cancel = 4
+ Folder,
+ File,
+ Cancel
+ }
+
+ public class AddItemResult
+ {
+ public AddItemType ItemType { get; set; }
+ public ShellNewEntry ItemInfo { get; set; }
}
public class AddListItem
{
public string Header { get; set; }
public string SubHeader { get; set; }
- public string Icon { get; set; }
+ public string Glyph { get; set; }
+ public BitmapImage Icon { get; set; }
public bool IsItemEnabled { get; set; }
- public AddItemType ItemType { get; set; }
+ public AddItemResult ItemType { get; set; }
}
}
\ No newline at end of file
diff --git a/Files/Dialogs/ConfirmDeleteDialog.xaml.cs b/Files/Dialogs/ConfirmDeleteDialog.xaml.cs
index 9e365259fcac..6a1c65ddec50 100644
--- a/Files/Dialogs/ConfirmDeleteDialog.xaml.cs
+++ b/Files/Dialogs/ConfirmDeleteDialog.xaml.cs
@@ -1,6 +1,5 @@
using Files.View_Models;
using Microsoft.Toolkit.Uwp.Extensions;
-using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
diff --git a/Files/Dialogs/PropertiesDialog.xaml b/Files/Dialogs/PropertiesDialog.xaml
index 9f89b3b83e8d..e3eb66ac187e 100644
--- a/Files/Dialogs/PropertiesDialog.xaml
+++ b/Files/Dialogs/PropertiesDialog.xaml
@@ -12,7 +12,7 @@
-
+
\ No newline at end of file
diff --git a/Files/Dialogs/PropertySaveError.xaml.cs b/Files/Dialogs/PropertySaveError.xaml.cs
index 7c7afaeea8f4..f9727a01e862 100644
--- a/Files/Dialogs/PropertySaveError.xaml.cs
+++ b/Files/Dialogs/PropertySaveError.xaml.cs
@@ -1,17 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
-using Windows.Foundation;
-using Windows.Foundation.Collections;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Controls.Primitives;
-using Windows.UI.Xaml.Data;
-using Windows.UI.Xaml.Input;
-using Windows.UI.Xaml.Media;
-using Windows.UI.Xaml.Navigation;
+using Windows.UI.Xaml.Controls;
// The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
@@ -34,4 +21,4 @@ private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDia
{
}
}
-}
+}
\ No newline at end of file
diff --git a/Files/Dialogs/RenameDialog.xaml.cs b/Files/Dialogs/RenameDialog.xaml.cs
index 95cc6ad27839..7460bb8dc877 100644
--- a/Files/Dialogs/RenameDialog.xaml.cs
+++ b/Files/Dialogs/RenameDialog.xaml.cs
@@ -1,5 +1,4 @@
using Files.Filesystem;
-using Files.Interacts;
using Windows.System;
using Windows.UI.Xaml.Controls;
diff --git a/Files/Enums/FileOperationType.cs b/Files/Enums/FileOperationType.cs
index db0bbd4cdc4d..d19856a77653 100644
--- a/Files/Enums/FileOperationType.cs
+++ b/Files/Enums/FileOperationType.cs
@@ -48,4 +48,4 @@ public enum FileOperationType : byte
///
Delete = 8
}
-}
+}
\ No newline at end of file
diff --git a/Files/Enums/ReturnResult.cs b/Files/Enums/ReturnResult.cs
index 478e613e6422..587caf560721 100644
--- a/Files/Enums/ReturnResult.cs
+++ b/Files/Enums/ReturnResult.cs
@@ -53,4 +53,4 @@ public enum ReturnResult : byte
///
Cancelled = 8,
}
-}
+}
\ No newline at end of file
diff --git a/Files/Enums/SidebarOpacity.cs b/Files/Enums/SidebarOpacity.cs
index c9559165b82e..1b1426bee001 100644
--- a/Files/Enums/SidebarOpacity.cs
+++ b/Files/Enums/SidebarOpacity.cs
@@ -3,6 +3,6 @@
public enum SidebarOpacity
{
Opaque = 0,
- AcrylicEnabled = 1
+ IsAcrylicDisabled = 1
}
}
\ No newline at end of file
diff --git a/Files/Extensions/EnumerableExtensions.cs b/Files/Extensions/EnumerableExtensions.cs
index d39536401455..bdccefbde391 100644
--- a/Files/Extensions/EnumerableExtensions.cs
+++ b/Files/Extensions/EnumerableExtensions.cs
@@ -13,4 +13,4 @@ internal static class EnumerableExtensions
internal static IEnumerable CreateEnumerable(this T item) =>
new List() { item };
}
-}
+}
\ No newline at end of file
diff --git a/Files/Extensions/LinqExtensions.cs b/Files/Extensions/LinqExtensions.cs
index b718d5b195cf..b8c2c9d152d7 100644
--- a/Files/Extensions/LinqExtensions.cs
+++ b/Files/Extensions/LinqExtensions.cs
@@ -17,4 +17,4 @@ internal static void ForEach(this IEnumerable collection, Action action
action(value);
}
}
-}
+}
\ No newline at end of file
diff --git a/Files/Files.csproj b/Files/Files.csproj
index 73f9227a7149..f70217da4722 100644
--- a/Files/Files.csproj
+++ b/Files/Files.csproj
@@ -10,6 +10,8 @@
Files
Files
en-US
+ Scale|DXFeatureLevel
+ Language=en-US;de-DE;es-ES;fr-FR;he-IL;hi-IN;hu-HU;it-IT;ja-JP;nl-NL;or-IN;pl-PL;pt-BR;ru-RU;ta;tr-TR;uk-UA;zh-Hans;zh-Hant
UAP
10.0.19041.0
10.0.17763.0
@@ -164,6 +166,8 @@
+
+
@@ -178,6 +182,7 @@
RestartDialog.xaml
+
@@ -199,7 +204,6 @@
-
@@ -218,7 +222,6 @@
-
diff --git a/Files/Filesystem/DriveItem.cs b/Files/Filesystem/DriveItem.cs
index 19f2b099feaa..b5c85c637ba4 100644
--- a/Files/Filesystem/DriveItem.cs
+++ b/Files/Filesystem/DriveItem.cs
@@ -109,16 +109,19 @@ public async Task UpdatePropertiesAsync()
var properties = await Root.Properties.RetrievePropertiesAsync(new[] { "System.FreeSpace", "System.Capacity" })
.AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5));
- MaxSpace = ByteSize.FromBytes((ulong)properties["System.Capacity"]);
- FreeSpace = ByteSize.FromBytes((ulong)properties["System.FreeSpace"]);
- SpaceUsed = MaxSpace - FreeSpace;
-
- SpaceText = string.Format(
- "DriveFreeSpaceAndCapacity".GetLocalized(),
- FreeSpace.ToBinaryString().ConvertSizeAbbreviation(),
- MaxSpace.ToBinaryString().ConvertSizeAbbreviation());
+ if (properties["System.Capacity"] != null && properties["System.FreeSpace"] != null)
+ {
+ MaxSpace = ByteSize.FromBytes((ulong)properties["System.Capacity"]);
+ FreeSpace = ByteSize.FromBytes((ulong)properties["System.FreeSpace"]);
+ SpaceUsed = MaxSpace - FreeSpace;
+
+ SpaceText = string.Format(
+ "DriveFreeSpaceAndCapacity".GetLocalized(),
+ FreeSpace.ToBinaryString().ConvertSizeAbbreviation(),
+ MaxSpace.ToBinaryString().ConvertSizeAbbreviation());
+ }
}
- catch (NullReferenceException)
+ catch (Exception)
{
SpaceText = "DriveCapacityUnknown".GetLocalized();
SpaceUsed = ByteSize.FromBytes(0);
diff --git a/Files/Filesystem/Drives.cs b/Files/Filesystem/Drives.cs
index 9ab50d9fe3ff..af59ab17f117 100644
--- a/Files/Filesystem/Drives.cs
+++ b/Files/Filesystem/Drives.cs
@@ -87,7 +87,7 @@ private async void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, obje
{
try
{
- await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
+ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
if (MainPage.SideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == "SidebarDrives".GetLocalized()) == null)
{
@@ -127,7 +127,7 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
private async void MainView_Activated(CoreApplicationView sender, Windows.ApplicationModel.Activation.IActivatedEventArgs args)
{
- await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
+ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
if (MainPage.SideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == "SidebarDrives".GetLocalized()) == null)
{
diff --git a/Files/Filesystem/FilesystemOperations/FilesystemItemType.cs b/Files/Filesystem/FilesystemOperations/FilesystemItemType.cs
index 7d935bb4b6ed..722012b831e3 100644
--- a/Files/Filesystem/FilesystemOperations/FilesystemItemType.cs
+++ b/Files/Filesystem/FilesystemOperations/FilesystemItemType.cs
@@ -20,4 +20,4 @@ public enum FilesystemItemType : byte
[Obsolete("The symlink has no use for now here.")]
Symlink = 2
}
-}
+}
\ No newline at end of file
diff --git a/Files/Filesystem/FilesystemOperations/FilesystemOperations.cs b/Files/Filesystem/FilesystemOperations/FilesystemOperations.cs
index 9145e015a08e..1a5017422912 100644
--- a/Files/Filesystem/FilesystemOperations/FilesystemOperations.cs
+++ b/Files/Filesystem/FilesystemOperations/FilesystemOperations.cs
@@ -32,7 +32,7 @@ public class FilesystemOperations : IFilesystemOperations
private RecycleBinHelpers recycleBinHelpers;
- #endregion
+ #endregion Private Members
#region Constructor
@@ -42,11 +42,11 @@ public FilesystemOperations(IShellPage associatedInstance)
recycleBinHelpers = new RecycleBinHelpers(this.associatedInstance);
}
- #endregion
+ #endregion Constructor
#region IFilesystemOperations
- public async Task CreateAsync(PathWithType source, IProgress errorCode, CancellationToken cancellationToken)
+ public async Task CreateAsync(IStorageItemWithPath source, IProgress errorCode, CancellationToken cancellationToken)
{
try
{
@@ -54,15 +54,23 @@ public async Task CreateAsync(PathWithType source, IProgress CopyAsync(IStorageItem source,
IProgress errorCode,
CancellationToken cancellationToken)
{
- return await CopyAsync(new PathWithType(source.Path,
- source.IsOfType(StorageItemTypes.File) ? FilesystemItemType.File : FilesystemItemType.Directory),
+ return await CopyAsync(source.FromStorageItem(),
destination,
progress,
errorCode,
cancellationToken);
}
- public async Task CopyAsync(PathWithType source,
+ public async Task CopyAsync(IStorageItemWithPath source,
string destination,
IProgress progress,
IProgress errorCode,
@@ -122,13 +129,13 @@ await DialogDisplayHelper.ShowDialogAsync(
}
IStorageItem copiedItem = null;
- long itemSize = await FilesystemHelpers.GetItemSize(await source.Path.ToStorageItem());
+ long itemSize = await FilesystemHelpers.GetItemSize(await source.ToStorageItem(associatedInstance));
bool reportProgress = false; // TODO: The default value is false
if (source.ItemType == FilesystemItemType.Directory)
{
- if (string.IsNullOrWhiteSpace(source.Path) ||
- Path.GetDirectoryName(destination).IsSubPathOf(source.Path)) // We check if user tried to copy anything above the source.ItemPath
+ if (!string.IsNullOrWhiteSpace(source.Path) &&
+ Path.GetDirectoryName(destination).IsSubPathOf(source.Path)) // We check if user tried to copy anything above the source.ItemPath
{
ImpossibleActionResponseTypes responseType = ImpossibleActionResponseTypes.Abort;
@@ -169,21 +176,21 @@ await DialogDisplayHelper.ShowDialogAsync(
progress?.Report((float)(itemSize * 100.0f / itemSize));
}
- FilesystemResult fsSourceFolderResult = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(source.Path));
- FilesystemResult fsDestinationFolderResult = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(destination));
+ StorageFolder fsSourceFolder = (StorageFolder)await source.ToStorageItem(associatedInstance);
+ StorageFolder fsDestinationFolder = (StorageFolder)await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(destination));
- if (fsSourceFolderResult && fsDestinationFolderResult)
+ if (fsSourceFolder != null && fsDestinationFolder != null)
{
FilesystemResult fsCopyResult = await FilesystemTasks.Wrap(async () =>
{
- return await FilesystemHelpers.CloneDirectoryAsync(fsSourceFolderResult.Result, fsDestinationFolderResult.Result, Path.GetFileName(source.Path));
+ return await FilesystemHelpers.CloneDirectoryAsync(fsSourceFolder, fsDestinationFolder, fsSourceFolder.Name);
})
.OnSuccess(t =>
{
if (associatedInstance.FilesystemViewModel.CheckFolderForHiddenAttribute(source.Path))
{
- // The source folder was hidden, apply hidden attribute to destination
- NativeFileOperationsHelper.SetFileAttribute(t.Path, FileAttributes.Hidden);
+ // The source folder was hidden, apply hidden attribute to destination
+ NativeFileOperationsHelper.SetFileAttribute(t.Path, FileAttributes.Hidden);
}
copiedItem = t;
});
@@ -201,7 +208,7 @@ await DialogDisplayHelper.ShowDialogAsync(
if (fsResult)
{
- StorageFile file = (StorageFile)await source.Path.ToStorageItem();
+ StorageFile file = (StorageFile)await source.ToStorageItem(associatedInstance);
FilesystemResult fsResultCopy = new FilesystemResult(null, FilesystemErrorCode.ERROR_GENERIC);
@@ -209,7 +216,7 @@ await DialogDisplayHelper.ShowDialogAsync(
{
fsResultCopy = await FilesystemTasks.Wrap(() =>
{
- return file.CopyAsync(fsResult.Result, Path.GetFileName(source.Path), NameCollisionOption.GenerateUniqueName).AsTask();
+ return file.CopyAsync(fsResult.Result, Path.GetFileName(file.Name), NameCollisionOption.GenerateUniqueName).AsTask();
});
}
@@ -222,7 +229,7 @@ await DialogDisplayHelper.ShowDialogAsync(
// Try again with CopyFileFromApp
if (NativeFileOperationsHelper.CopyFileFromApp(source.Path, destination, true))
{
- copiedItem = await source.Path.ToStorageItem(); // Dangerous - the provided item may be different than output result!
+ copiedItem = await source.ToStorageItem(associatedInstance); // Dangerous - the provided item may be different than output result!
}
else
{
@@ -253,9 +260,7 @@ await DialogDisplayHelper.ShowDialogAsync(
progress?.Report(100.0f);
- var pathWithType = new PathWithType(
- copiedItem != null ? (!string.IsNullOrWhiteSpace(copiedItem.Path) ? copiedItem.Path : destination) : destination,
- source.ItemType);
+ var pathWithType = copiedItem.FromStorageItem(destination, source.ItemType);
return new StorageHistory(FileOperationType.Copy, source, pathWithType);
}
@@ -266,15 +271,14 @@ public async Task MoveAsync(IStorageItem source,
IProgress errorCode,
CancellationToken cancellationToken)
{
- return await MoveAsync(new PathWithType(source.Path,
- source.IsOfType(StorageItemTypes.File) ? FilesystemItemType.File : FilesystemItemType.Directory),
+ return await MoveAsync(source.FromStorageItem(),
destination,
progress,
errorCode,
cancellationToken);
}
- public async Task MoveAsync(PathWithType source,
+ public async Task MoveAsync(IStorageItemWithPath source,
string destination,
IProgress progress,
IProgress errorCode,
@@ -303,15 +307,14 @@ public async Task DeleteAsync(IStorageItem source,
bool permanently,
CancellationToken cancellationToken)
{
- return await DeleteAsync(new PathWithType(source.Path,
- source.IsOfType(StorageItemTypes.File) ? FilesystemItemType.File : FilesystemItemType.Directory),
+ return await DeleteAsync(source.FromStorageItem(),
progress,
errorCode,
permanently,
cancellationToken);
}
- public async Task DeleteAsync(PathWithType source,
+ public async Task DeleteAsync(IStorageItemWithPath source,
IProgress progress,
IProgress errorCode,
bool permanently,
@@ -342,14 +345,15 @@ public async Task DeleteAsync(PathWithType source,
// Try again with fulltrust process
if (associatedInstance.FilesystemViewModel.Connection != null)
{
- AppServiceResponse response = await associatedInstance.FilesystemViewModel.Connection.SendMessageAsync(new ValueSet()
+ AppServiceResponse response = await associatedInstance.FilesystemViewModel.Connection.SendMessageAsync(new ValueSet()
{
{ "Arguments", "FileOperation" },
{ "fileop", "DeleteItem" },
{ "filepath", source.Path },
{ "permanently", permanently }
});
- fsResult = (FilesystemResult)(response.Status == AppServiceResponseStatus.Success);
+ fsResult = (FilesystemResult)(response.Status == AppServiceResponseStatus.Success
+ && response.Message.Get("Success", false));
}
}
else if (fsResult == FilesystemErrorCode.ERROR_INUSE)
@@ -391,7 +395,7 @@ await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(iFilePath)
// Get newest file
ShellFileItem item = nameMatchItems.Where((item) => item.RecycleDate != null).OrderBy((item) => item.RecycleDate).FirstOrDefault();
- return new StorageHistory(FileOperationType.Recycle, source, new PathWithType(item?.RecyclePath, source.ItemType));
+ return new StorageHistory(FileOperationType.Recycle, source, StorageItemHelpers.FromPathAndType(item?.RecyclePath, source.ItemType));
}
return new StorageHistory(FileOperationType.Delete, source, null);
@@ -426,7 +430,7 @@ public async Task RenameAsync(IStorageItem source,
await source.RenameAsync(newName, collision);
errorCode?.Report(FilesystemErrorCode.ERROR_SUCCESS);
- return new StorageHistory(FileOperationType.Rename, new PathWithType(originalSource, itemType), new PathWithType(source.Path, itemType));
+ return new StorageHistory(FileOperationType.Rename, StorageItemHelpers.FromPathAndType(originalSource, itemType), source.FromStorageItem());
}
catch (Exception e)
{
@@ -438,7 +442,7 @@ public async Task RenameAsync(IStorageItem source,
return null;
}
- public async Task RenameAsync(PathWithType source,
+ public async Task RenameAsync(IStorageItemWithPath source,
string newName,
NameCollisionOption collision,
IProgress errorCode,
@@ -456,11 +460,11 @@ public async Task RenameAsync(PathWithType source,
{
try
{
- IStorageItem itemToRename = await source.Path.ToStorageItem();
+ IStorageItem itemToRename = await source.ToStorageItem(associatedInstance);
await itemToRename.RenameAsync(newName, collision);
errorCode?.Report(FilesystemErrorCode.ERROR_SUCCESS);
- return new StorageHistory(FileOperationType.Rename, source, new PathWithType(itemToRename.Path, source.ItemType));
+ return new StorageHistory(FileOperationType.Rename, source, itemToRename.FromStorageItem());
}
catch (Exception e)
{
@@ -472,7 +476,7 @@ public async Task RenameAsync(PathWithType source,
return null;
}
- public async Task RestoreFromTrashAsync(PathWithType source,
+ public async Task RestoreFromTrashAsync(IStorageItemWithPath source,
string destination,
IProgress progress,
IProgress errorCode,
@@ -485,11 +489,11 @@ public async Task RestoreFromTrashAsync(PathWithType source,
{
FilesystemResult sourceFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(source.Path);
FilesystemResult destinationFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(destination));
-
+
fsResult = sourceFolder.ErrorCode | destinationFolder.ErrorCode;
errorCode?.Report(fsResult);
- if (sourceFolder && destinationFolder)
+ if (fsResult)
{
fsResult = await FilesystemTasks.Wrap(() =>
{
@@ -509,7 +513,7 @@ public async Task RestoreFromTrashAsync(PathWithType source,
fsResult = sourceFile.ErrorCode | destinationFolder.ErrorCode;
errorCode?.Report(fsResult);
- if (sourceFile && destinationFolder)
+ if (fsResult)
{
fsResult = await FilesystemTasks.Wrap(() =>
{
@@ -518,13 +522,21 @@ public async Task RestoreFromTrashAsync(PathWithType source,
NameCollisionOption.GenerateUniqueName).AsTask();
});
}
+ else if (fsResult == FilesystemErrorCode.ERROR_UNAUTHORIZED)
+ {
+ // Try again with MoveFileFromApp
+ fsResult = (FilesystemResult)NativeFileOperationsHelper.MoveFileFromApp(source.Path, destination);
+ }
errorCode?.Report(fsResult);
}
- // Recycle bin also stores a file starting with $I for each item
- string iFilePath = Path.Combine(Path.GetDirectoryName(source.Path), Path.GetFileName(source.Path).Replace("$R", "$I"));
- await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(iFilePath)
- .OnSuccess(iFile => iFile.DeleteAsync().AsTask());
+ if (fsResult)
+ {
+ // Recycle bin also stores a file starting with $I for each item
+ string iFilePath = Path.Combine(Path.GetDirectoryName(source.Path), Path.GetFileName(source.Path).Replace("$R", "$I"));
+ await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(iFilePath)
+ .OnSuccess(iFile => iFile.DeleteAsync().AsTask());
+ }
errorCode?.Report(fsResult);
if (fsResult != FilesystemErrorCode.ERROR_SUCCESS)
@@ -543,10 +555,10 @@ await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(iFilePath)
}
}
- return new StorageHistory(FileOperationType.Restore, source, new PathWithType(destination, source.ItemType));
+ return new StorageHistory(FileOperationType.Restore, source, StorageItemHelpers.FromPathAndType(destination, source.ItemType));
}
- #endregion
+ #endregion IFilesystemOperations
#region IDisposable
@@ -559,6 +571,6 @@ public void Dispose()
associatedInstance = null;
}
- #endregion
+ #endregion IDisposable
}
-}
+}
\ No newline at end of file
diff --git a/Files/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs b/Files/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs
index 289fb9b998c3..7240785d7953 100644
--- a/Files/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs
+++ b/Files/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs
@@ -1,4 +1,5 @@
using Files.Dialogs;
+using Files.Enums;
using Files.Filesystem.FilesystemHistory;
using Files.Helpers;
using Files.UserControls;
@@ -7,14 +8,13 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
-using System.Text.RegularExpressions;
-using FileAttributes = System.IO.FileAttributes;
using static Files.Helpers.NativeFindStorageItemHelper;
-using Files.Enums;
+using FileAttributes = System.IO.FileAttributes;
namespace Files.Filesystem
{
@@ -43,9 +43,9 @@ public class FilesystemHelpers : IFilesystemHelpers
"LPT6", "LPT7", "LPT8", "LPT9"
};
- #endregion
+ #endregion Helpers Members
- #endregion
+ #endregion Private Members
#region Constructor
@@ -57,13 +57,13 @@ public FilesystemHelpers(IShellPage associatedInstance, CancellationToken cancel
recycleBinHelpers = new RecycleBinHelpers(this.associatedInstance);
}
- #endregion
+ #endregion Constructor
#region IFilesystemHelpers
#region Create
- public async Task CreateAsync(PathWithType source, bool registerHistory)
+ public async Task CreateAsync(IStorageItemWithPath source, bool registerHistory)
{
FilesystemErrorCode returnCode = FilesystemErrorCode.ERROR_INPROGRESS;
Progress errorCode = new Progress();
@@ -79,14 +79,14 @@ public async Task CreateAsync(PathWithType source, bool registerHi
return returnCode.ToStatus();
}
- #endregion
+ #endregion Create
#region Delete
- public async Task DeleteItemsAsync(IEnumerable source, bool showDialog, bool permanently, bool registerHistory)
+ public async Task DeleteItemsAsync(IEnumerable source, bool showDialog, bool permanently, bool registerHistory)
{
bool deleteFromRecycleBin = false;
- foreach (PathWithType item in source)
+ foreach (IStorageItemWithPath item in source)
{
if (await recycleBinHelpers.IsRecycleBinItem(item.Path))
{
@@ -140,7 +140,7 @@ public async Task DeleteItemsAsync(IEnumerable sourc
var rawStorageHistory = new List();
bool originalPermanently = permanently;
- foreach (PathWithType item in source)
+ foreach (IStorageItemWithPath item in source)
{
if (await recycleBinHelpers.IsRecycleBinItem(item.Path))
{
@@ -175,7 +175,7 @@ public async Task DeleteItemsAsync(IEnumerable sourc
return returnStatus;
}
- public async Task DeleteItemAsync(PathWithType source, bool showDialog, bool permanently, bool registerHistory)
+ public async Task DeleteItemAsync(IStorageItemWithPath source, bool showDialog, bool permanently, bool registerHistory)
{
PostedStatusBanner banner;
bool deleteFromRecycleBin = await recycleBinHelpers.IsRecycleBinItem(source.Path);
@@ -397,9 +397,9 @@ public async Task DeleteItemAsync(IStorageItem source, bool showDi
return returnStatus;
}
- #endregion
+ #endregion Delete
- public async Task RestoreFromTrashAsync(PathWithType source, string destination, bool registerHistory)
+ public async Task RestoreFromTrashAsync(IStorageItemWithPath source, string destination, bool registerHistory)
{
FilesystemErrorCode returnCode = FilesystemErrorCode.ERROR_INPROGRESS;
Progress errorCode = new Progress();
@@ -422,18 +422,26 @@ public async Task PerformOperationTypeAsync(DataPackageOperation o
{
try
{
- switch (operation)
+ if (operation.HasFlag(DataPackageOperation.Copy))
{
- case DataPackageOperation.Copy:
- return await CopyItemsFromClipboard(packageView, destination, registerHistory);
-
- case DataPackageOperation.Move:
- return await MoveItemsFromClipboard(packageView, destination, registerHistory);
-
- case DataPackageOperation.None: // Other
- return await CopyItemsFromClipboard(packageView, destination, registerHistory);
-
- default: return default;
+ return await CopyItemsFromClipboard(packageView, destination, registerHistory);
+ }
+ else if (operation.HasFlag(DataPackageOperation.Move))
+ {
+ return await MoveItemsFromClipboard(packageView, destination, registerHistory);
+ }
+ else if (operation.HasFlag(DataPackageOperation.Link))
+ {
+ // TODO: Support link creation
+ return default;
+ }
+ else if (operation.HasFlag(DataPackageOperation.None))
+ {
+ return await CopyItemsFromClipboard(packageView, destination, registerHistory);
+ }
+ else
+ {
+ return default;
}
}
finally
@@ -446,15 +454,15 @@ public async Task PerformOperationTypeAsync(DataPackageOperation o
public async Task CopyItemsAsync(IEnumerable source, IEnumerable destination, bool registerHistory)
{
- return await CopyItemsAsync(source.Select((item) => new PathWithType(item.Path, item.IsOfType(StorageItemTypes.File) ? FilesystemItemType.File : FilesystemItemType.Directory)).ToList(), destination, registerHistory);
+ return await CopyItemsAsync(source.Select((item) => item.FromStorageItem()).ToList(), destination, registerHistory);
}
public async Task CopyItemAsync(IStorageItem source, string destination, bool registerHistory)
{
- return await CopyItemAsync(new PathWithType(source.Path, source.IsOfType(StorageItemTypes.File) ? FilesystemItemType.File : FilesystemItemType.Directory), destination, registerHistory);
+ return await CopyItemAsync(source.FromStorageItem(), destination, registerHistory);
}
- public async Task CopyItemsAsync(IEnumerable source, IEnumerable destination, bool registerHistory)
+ public async Task CopyItemsAsync(IEnumerable source, IEnumerable destination, bool registerHistory)
{
PostedStatusBanner banner = associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
string.Empty,
@@ -512,7 +520,7 @@ public async Task CopyItemsAsync(IEnumerable source,
return returnStatus;
}
- public async Task CopyItemAsync(PathWithType source, string destination, bool registerHistory)
+ public async Task CopyItemAsync(IStorageItemWithPath source, string destination, bool registerHistory)
{
PostedStatusBanner banner = associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
string.Empty,
@@ -565,7 +573,7 @@ public async Task CopyItemsFromClipboard(DataPackageView packageVi
{
source = await packageView.GetStorageItemsAsync();
}
- catch (Exception ex) when ((uint)ex.HResult == 0x80040064)
+ catch (Exception ex) when ((uint)ex.HResult == 0x80040064 || (uint)ex.HResult == 0x8004006A)
{
return ReturnResult.UnknownException;
}
@@ -582,21 +590,21 @@ public async Task CopyItemsFromClipboard(DataPackageView packageVi
return returnStatus;
}
- #endregion
+ #endregion Copy
#region Move
public async Task MoveItemsAsync(IEnumerable source, IEnumerable destination, bool registerHistory)
{
- return await MoveItemsAsync(source.Select((item) => new PathWithType(item.Path, item.IsOfType(StorageItemTypes.File) ? FilesystemItemType.File : FilesystemItemType.Directory)).ToList(), destination, registerHistory);
+ return await MoveItemsAsync(source.Select((item) => item.FromStorageItem()).ToList(), destination, registerHistory);
}
public async Task MoveItemAsync(IStorageItem source, string destination, bool registerHistory)
{
- return await MoveItemAsync(new PathWithType(source.Path, source.IsOfType(StorageItemTypes.File) ? FilesystemItemType.File : FilesystemItemType.Directory), destination, registerHistory);
+ return await MoveItemAsync(source.FromStorageItem(), destination, registerHistory);
}
- public async Task MoveItemsAsync(IEnumerable source, IEnumerable destination, bool registerHistory)
+ public async Task MoveItemsAsync(IEnumerable source, IEnumerable destination, bool registerHistory)
{
PostedStatusBanner banner = associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
string.Empty,
@@ -654,7 +662,7 @@ public async Task MoveItemsAsync(IEnumerable source,
return returnStatus;
}
- public async Task MoveItemAsync(PathWithType source, string destination, bool registerHistory)
+ public async Task MoveItemAsync(IStorageItemWithPath source, string destination, bool registerHistory)
{
PostedStatusBanner banner = associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
string.Empty,
@@ -724,7 +732,7 @@ public async Task MoveItemsFromClipboard(DataPackageView packageVi
return returnStatus;
}
- #endregion
+ #endregion Move
#region Rename
@@ -744,7 +752,7 @@ public async Task RenameAsync(IStorageItem source, string newName,
return returnCode.ToStatus();
}
- public async Task RenameAsync(PathWithType source, string newName, NameCollisionOption collision, bool registerHistory)
+ public async Task RenameAsync(IStorageItemWithPath source, string newName, NameCollisionOption collision, bool registerHistory)
{
FilesystemErrorCode returnCode = FilesystemErrorCode.ERROR_INPROGRESS;
Progress errorCode = new Progress();
@@ -760,9 +768,9 @@ public async Task RenameAsync(PathWithType source, string newName,
return returnCode.ToStatus();
}
- #endregion
+ #endregion Rename
- #endregion
+ #endregion IFilesystemHelpers
#region Public Helpers
@@ -933,7 +941,7 @@ public static bool ContainsRestrictedFileName(string input)
return false;
}
- #endregion
+ #endregion Public Helpers
#region IDisposable
@@ -948,6 +956,6 @@ public void Dispose()
recycleBinHelpers = null;
}
- #endregion
+ #endregion IDisposable
}
-}
+}
\ No newline at end of file
diff --git a/Files/Filesystem/FilesystemOperations/Helpers/IFilesystemHelpers.cs b/Files/Filesystem/FilesystemOperations/Helpers/IFilesystemHelpers.cs
index 63ccd001941d..f0a36ebdb3e7 100644
--- a/Files/Filesystem/FilesystemOperations/Helpers/IFilesystemHelpers.cs
+++ b/Files/Filesystem/FilesystemOperations/Helpers/IFilesystemHelpers.cs
@@ -1,10 +1,10 @@
-using System;
+using Files.Enums;
+using Files.Filesystem.FilesystemHistory;
+using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
-using Files.Filesystem.FilesystemHistory;
-using Files.Enums;
namespace Files.Filesystem
{
@@ -16,7 +16,7 @@ public interface IFilesystemHelpers : IDisposable
/// FullPath to the item
/// Determines whether is saved
/// of performed operation
- Task CreateAsync(PathWithType source, bool registerHistory);
+ Task CreateAsync(IStorageItemWithPath source, bool registerHistory);
#region Delete
@@ -48,7 +48,7 @@ public interface IFilesystemHelpers : IDisposable
/// Determines whether is be deleted permanently
/// Determines whether is saved
/// of performed operation
- Task DeleteItemsAsync(IEnumerable source, bool showDialog, bool permanently, bool registerHistory);
+ Task DeleteItemsAsync(IEnumerable source, bool showDialog, bool permanently, bool registerHistory);
///
/// Deletes provided
@@ -58,9 +58,9 @@ public interface IFilesystemHelpers : IDisposable
/// Determines whether is be deleted permanently
/// Determines whether is saved
/// of performed operation
- Task DeleteItemAsync(PathWithType source, bool showDialog, bool permanently, bool registerHistory);
+ Task DeleteItemAsync(IStorageItemWithPath source, bool showDialog, bool permanently, bool registerHistory);
- #endregion
+ #endregion Delete
///
/// Restores from the RecycleBin to fullPath
@@ -69,7 +69,7 @@ public interface IFilesystemHelpers : IDisposable
/// The destination fullPath to restore to
/// Determines whether is saved
/// of performed operation
- Task RestoreFromTrashAsync(PathWithType source, string destination, bool registerHistory);
+ Task RestoreFromTrashAsync(IStorageItemWithPath source, string destination, bool registerHistory);
///
/// Performs relevant operation based on
@@ -113,7 +113,7 @@ public interface IFilesystemHelpers : IDisposable
/// The destination fullPath
/// Determines whether is saved
/// of performed operation
- Task CopyItemsAsync(IEnumerable source, IEnumerable destination, bool registerHistory);
+ Task CopyItemsAsync(IEnumerable source, IEnumerable destination, bool registerHistory);
///
/// Copies to fullPath
@@ -122,7 +122,7 @@ public interface IFilesystemHelpers : IDisposable
/// The destination fullPath
/// Determines whether is saved
/// of performed operation
- Task CopyItemAsync(PathWithType source, string destination, bool registerHistory);
+ Task CopyItemAsync(IStorageItemWithPath source, string destination, bool registerHistory);
///
/// Copies items from clipboard to fullPath
@@ -138,7 +138,7 @@ public interface IFilesystemHelpers : IDisposable
/// of performed operation
Task CopyItemsFromClipboard(DataPackageView packageView, string destination, bool registerHistory);
- #endregion
+ #endregion Copy
#region Move
@@ -167,7 +167,7 @@ public interface IFilesystemHelpers : IDisposable
/// The destination fullPath
/// Determines whether is saved
/// of performed operation
- Task MoveItemsAsync(IEnumerable source, IEnumerable destination, bool registerHistory);
+ Task MoveItemsAsync(IEnumerable source, IEnumerable destination, bool registerHistory);
///
/// Moves to fullPath
@@ -176,7 +176,7 @@ public interface IFilesystemHelpers : IDisposable
/// The destination fullPath
/// Determines whether is saved
/// of performed operation
- Task MoveItemAsync(PathWithType source, string destination, bool registerHistory);
+ Task MoveItemAsync(IStorageItemWithPath source, string destination, bool registerHistory);
///
/// Moves items from clipboard to fullPath
@@ -192,7 +192,7 @@ public interface IFilesystemHelpers : IDisposable
/// of performed operation
Task MoveItemsFromClipboard(DataPackageView packageView, string destination, bool registerHistory);
- #endregion
+ #endregion Move
///
/// Renames with
@@ -212,6 +212,6 @@ public interface IFilesystemHelpers : IDisposable
/// Determines what to do if item already exists
/// Determines whether is saved
/// of performed operation
- Task RenameAsync(PathWithType source, string newName, NameCollisionOption collision, bool registerHistory);
+ Task RenameAsync(IStorageItemWithPath source, string newName, NameCollisionOption collision, bool registerHistory);
}
}
\ No newline at end of file
diff --git a/Files/Filesystem/FilesystemOperations/IFilesystemOperations.cs b/Files/Filesystem/FilesystemOperations/IFilesystemOperations.cs
index a1351978db4c..22a24fde0c3b 100644
--- a/Files/Filesystem/FilesystemOperations/IFilesystemOperations.cs
+++ b/Files/Filesystem/FilesystemOperations/IFilesystemOperations.cs
@@ -1,8 +1,8 @@
-using System;
+using Files.Filesystem.FilesystemHistory;
+using System;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
-using Files.Filesystem.FilesystemHistory;
namespace Files.Filesystem
{
@@ -28,7 +28,7 @@ public interface IFilesystemOperations : IDisposable
///
/// Destination: null
///
- Task CreateAsync(PathWithType source, IProgress errorCode, CancellationToken cancellationToken);
+ Task CreateAsync(IStorageItemWithPath source, IProgress errorCode, CancellationToken cancellationToken);
///
/// Copies to fullPath
@@ -64,7 +64,7 @@ Task CopyAsync(IStorageItem source,
///
/// Destination: The item fullPath (as ) the was copied
///
- Task CopyAsync(PathWithType source,
+ Task CopyAsync(IStorageItemWithPath source,
string destination,
IProgress progress,
IProgress errorCode,
@@ -104,7 +104,7 @@ Task MoveAsync(IStorageItem source,
///
/// Destination: The item fullPath (as ) the was moved
///
- Task MoveAsync(PathWithType source,
+ Task MoveAsync(IStorageItemWithPath source,
string destination,
IProgress progress,
IProgress errorCode,
@@ -153,7 +153,7 @@ Task DeleteAsync(IStorageItem source,
///
/// If was false, returns path to recycled item
///
- Task DeleteAsync(PathWithType source,
+ Task DeleteAsync(IStorageItemWithPath source,
IProgress progress,
IProgress errorCode,
bool permanently,
@@ -193,7 +193,7 @@ Task RenameAsync(IStorageItem source,
///
/// Destination: The renamed item fullPath (as )
///
- Task RenameAsync(PathWithType source,
+ Task RenameAsync(IStorageItemWithPath source,
string newName,
NameCollisionOption collision,
IProgress errorCode,
@@ -213,7 +213,7 @@ Task RenameAsync(PathWithType source,
///
/// Destination: The item fullPath (as ) the has been restored
///
- Task RestoreFromTrashAsync(PathWithType source,
+ Task RestoreFromTrashAsync(IStorageItemWithPath source,
string destination,
IProgress progress,
IProgress errorCode,
diff --git a/Files/Filesystem/FilesystemOperations/PathWithType.cs b/Files/Filesystem/FilesystemOperations/PathWithType.cs
deleted file mode 100644
index edeb4553143d..000000000000
--- a/Files/Filesystem/FilesystemOperations/PathWithType.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-using System;
-using Windows.Storage;
-
-namespace Files.Filesystem
-{
- public class PathWithType : IDisposable
- {
- #region Public Properties
-
- public string Path { get; private set; }
-
- public FilesystemItemType ItemType { get; private set; }
-
- #endregion
-
- #region Constructor
-
- public PathWithType(string path, FilesystemItemType itemType)
- {
- Path = path;
- ItemType = itemType;
- }
-
- #endregion
-
- #region Operators
-
- public static explicit operator string(PathWithType pathWithType) => pathWithType.Path;
-
- public static explicit operator FilesystemItemType(PathWithType pathWithType) => pathWithType.ItemType;
-
- public static explicit operator PathWithType(StorageFile storageFile)
- {
- return new PathWithType(storageFile.Path, storageFile.IsOfType(StorageItemTypes.File) ? FilesystemItemType.File : FilesystemItemType.Directory);
- }
-
- public static explicit operator PathWithType(StorageFolder storageFolder)
- {
- return new PathWithType(storageFolder.Path, storageFolder.IsOfType(StorageItemTypes.File) ? FilesystemItemType.File : FilesystemItemType.Directory);
- }
-
- #endregion
-
- #region Override
-
- public override string ToString()
- {
- return Path;
- }
-
- #endregion
-
- #region IDisposable
-
- public void Dispose()
- {
- Path ??= string.Empty;
-
- Path = null;
- }
-
- #endregion
- }
-}
diff --git a/Files/Filesystem/ListedItem.cs b/Files/Filesystem/ListedItem.cs
index 1cb0f6f551f9..85cbf36a47e5 100644
--- a/Files/Filesystem/ListedItem.cs
+++ b/Files/Filesystem/ListedItem.cs
@@ -1,12 +1,8 @@
-using ByteSizeLib;
-using Files.Enums;
-using Files.Helpers;
using Files.Enums;
using Files.Filesystem.Cloud;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Uwp.Extensions;
using System;
-using System.Diagnostics;
using Windows.Storage;
using Windows.UI.Xaml.Media.Imaging;
diff --git a/Files/Filesystem/Search/FolderSearch.cs b/Files/Filesystem/Search/FolderSearch.cs
index 30cb8df204c0..3f4f749ac2b0 100644
--- a/Files/Filesystem/Search/FolderSearch.cs
+++ b/Files/Filesystem/Search/FolderSearch.cs
@@ -1,20 +1,18 @@
-using System;
+using Files.Common;
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
-using System.Linq;
-using System.Text;
+using System.IO;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Search;
using Windows.UI.Xaml.Media.Imaging;
-using Files.Common;
using static Files.Helpers.NativeFindStorageItemHelper;
-using System.IO;
using FileAttributes = System.IO.FileAttributes;
namespace Files.Filesystem.Search
{
- class FolderSearch
+ internal class FolderSearch
{
public static async Task> SearchForUserQueryTextAsync(string userText, string WorkingDirectory, int maxItemCount = 10)
{
@@ -23,7 +21,7 @@ public static async Task> SearchForUserQueryTex
{
FolderDepth = FolderDepth.Deep,
IndexerOption = IndexerOption.OnlyUseIndexerAndOptimizeForIndexedProperties,
- UserSearchFilter = string.IsNullOrWhiteSpace(userText)? null : userText,
+ UserSearchFilter = string.IsNullOrWhiteSpace(userText) ? null : userText,
};
options.SortOrder.Add(new SortEntry()
{
@@ -88,7 +86,6 @@ public static async Task> SearchForUserQueryTex
ItemPropertiesInitialized = true
});
}
-
}
}
if (maxItemCount != 10)
@@ -120,9 +117,9 @@ await Task.Run(() =>
var hasNextFile = false;
do
{
- if (((FileAttributes)findData.dwFileAttributes & FileAttributes.System) != FileAttributes.System)
+ var itemPath = Path.Combine(WorkingDirectory, findData.cFileName);
+ if (((FileAttributes)findData.dwFileAttributes & FileAttributes.System) != FileAttributes.System || !App.AppSettings.AreSystemItemsHidden)
{
- var itemPath = Path.Combine(WorkingDirectory, findData.cFileName);
if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
@@ -170,4 +167,4 @@ await Task.Run(() =>
return returnedItems;
}
}
-}
+}
\ No newline at end of file
diff --git a/Files/Filesystem/StorageFileHelpers/FilesystemResult.cs b/Files/Filesystem/StorageFileHelpers/FilesystemResult.cs
index aff43cc401d6..5774d8985286 100644
--- a/Files/Filesystem/StorageFileHelpers/FilesystemResult.cs
+++ b/Files/Filesystem/StorageFileHelpers/FilesystemResult.cs
@@ -128,14 +128,14 @@ public async static Task Wrap(Func wrapped)
}
}
- public async static Task> OnSuccess(this Task> wrapped, Func> func)
+ public async static Task> OnSuccess(this Task> wrapped, Func> func)
{
var res = await wrapped;
if (res)
{
return await Wrap(() => func(res.Result));
}
- return res;
+ return new FilesystemResult(default, res.ErrorCode);
}
public async static Task OnSuccess(this Task> wrapped, Func func)
diff --git a/Files/Filesystem/StorageFileHelpers/IStorageItemWithPath.cs b/Files/Filesystem/StorageFileHelpers/IStorageItemWithPath.cs
index c48a8d3aca7b..46e508639700 100644
--- a/Files/Filesystem/StorageFileHelpers/IStorageItemWithPath.cs
+++ b/Files/Filesystem/StorageFileHelpers/IStorageItemWithPath.cs
@@ -3,9 +3,10 @@
namespace Files.Filesystem
{
public interface IStorageItemWithPath // TODO: Maybe use here : IStorageItem instead of declaring a variable,
- // and keep the Path property for it to override IStorageItem.Path ?
+ // and keep the Path property for it to override IStorageItem.Path ?
{
public string Path { get; set; }
public IStorageItem Item { get; set; }
+ public FilesystemItemType ItemType { get; }
}
}
\ No newline at end of file
diff --git a/Files/Filesystem/StorageFileHelpers/StorageFileWithPath.cs b/Files/Filesystem/StorageFileHelpers/StorageFileWithPath.cs
index 7f337bce201c..f5397dc1efb3 100644
--- a/Files/Filesystem/StorageFileHelpers/StorageFileWithPath.cs
+++ b/Files/Filesystem/StorageFileHelpers/StorageFileWithPath.cs
@@ -18,6 +18,7 @@ public StorageFile File
public string Path { get; set; }
public IStorageItem Item { get; set; }
+ public FilesystemItemType ItemType => FilesystemItemType.File;
public StorageFileWithPath(StorageFile file)
{
diff --git a/Files/Filesystem/StorageFileHelpers/StorageFolderWithPath.cs b/Files/Filesystem/StorageFileHelpers/StorageFolderWithPath.cs
index 256a25bb0602..63174d5fe842 100644
--- a/Files/Filesystem/StorageFileHelpers/StorageFolderWithPath.cs
+++ b/Files/Filesystem/StorageFileHelpers/StorageFolderWithPath.cs
@@ -18,6 +18,7 @@ public StorageFolder Folder
public string Path { get; set; }
public IStorageItem Item { get; set; }
+ public FilesystemItemType ItemType => FilesystemItemType.Directory;
public StorageFolderWithPath(StorageFolder folder)
{
diff --git a/Files/Filesystem/StorageHistory/Helpers/StorageHistoryHelpers.cs b/Files/Filesystem/StorageHistory/Helpers/StorageHistoryHelpers.cs
index e8e260a9524d..3dcdc714eeea 100644
--- a/Files/Filesystem/StorageHistory/Helpers/StorageHistoryHelpers.cs
+++ b/Files/Filesystem/StorageHistory/Helpers/StorageHistoryHelpers.cs
@@ -1,5 +1,4 @@
using Files.Enums;
-using Files.Helpers;
using System;
using System.Threading.Tasks;
@@ -11,7 +10,7 @@ public class StorageHistoryHelpers : IDisposable
private IStorageHistoryOperations storageHistoryOperations;
- #endregion
+ #endregion Private Members
#region Constructor
@@ -20,7 +19,7 @@ public StorageHistoryHelpers(IStorageHistoryOperations storageHistoryOperations)
this.storageHistoryOperations = storageHistoryOperations;
}
- #endregion
+ #endregion Constructor
#region Undo, Redo
@@ -70,7 +69,7 @@ public async Task TryRedo()
return ReturnResult.Cancelled;
}
- #endregion
+ #endregion Undo, Redo
#region IDisposable
@@ -81,6 +80,6 @@ public void Dispose()
storageHistoryOperations = null;
}
- #endregion
+ #endregion IDisposable
}
-}
+}
\ No newline at end of file
diff --git a/Files/Filesystem/StorageHistory/IStorageHistory.cs b/Files/Filesystem/StorageHistory/IStorageHistory.cs
index 918119e148d5..5ccbb1bd8246 100644
--- a/Files/Filesystem/StorageHistory/IStorageHistory.cs
+++ b/Files/Filesystem/StorageHistory/IStorageHistory.cs
@@ -19,7 +19,7 @@ public interface IStorageHistory : IDisposable
///
/// May contain more that one item
///
- IEnumerable Source { get; }
+ IEnumerable Source { get; }
///
/// Destination file/folder
@@ -29,16 +29,16 @@ public interface IStorageHistory : IDisposable
///
/// May contain more that one item
///
- IEnumerable Destination { get; }
+ IEnumerable Destination { get; }
#region Modify
void Modify(IStorageHistory newHistory);
- void Modify(FileOperationType operationType, IEnumerable source, IEnumerable destination);
+ void Modify(FileOperationType operationType, IEnumerable source, IEnumerable destination);
- void Modify(FileOperationType operationType, PathWithType source, PathWithType destination);
+ void Modify(FileOperationType operationType, IStorageItemWithPath source, IStorageItemWithPath destination);
- #endregion
+ #endregion Modify
}
-}
+}
\ No newline at end of file
diff --git a/Files/Filesystem/StorageHistory/IStorageHistoryOperations.cs b/Files/Filesystem/StorageHistory/IStorageHistoryOperations.cs
index c4db3c19c1a6..270460674d39 100644
--- a/Files/Filesystem/StorageHistory/IStorageHistoryOperations.cs
+++ b/Files/Filesystem/StorageHistory/IStorageHistoryOperations.cs
@@ -20,4 +20,4 @@ public interface IStorageHistoryOperations : IDisposable
///
Task Redo(IStorageHistory history);
}
-}
+}
\ No newline at end of file
diff --git a/Files/Filesystem/StorageHistory/StorageHistory.cs b/Files/Filesystem/StorageHistory/StorageHistory.cs
index 6f98c50d3379..458687d2050c 100644
--- a/Files/Filesystem/StorageHistory/StorageHistory.cs
+++ b/Files/Filesystem/StorageHistory/StorageHistory.cs
@@ -10,29 +10,29 @@ public class StorageHistory : IStorageHistory
public FileOperationType OperationType { get; private set; }
- public IEnumerable Source { get; private set; }
+ public IEnumerable Source { get; private set; }
- public IEnumerable Destination { get; private set; }
+ public IEnumerable Destination { get; private set; }
- #endregion
+ #endregion Public Properties
#region Constructor
- public StorageHistory(FileOperationType operationType, IEnumerable source, IEnumerable destination)
+ public StorageHistory(FileOperationType operationType, IEnumerable source, IEnumerable destination)
{
OperationType = operationType;
Source = source;
Destination = destination;
}
- public StorageHistory(FileOperationType operationType, PathWithType source, PathWithType destination)
+ public StorageHistory(FileOperationType operationType, IStorageItemWithPath source, IStorageItemWithPath destination)
{
OperationType = operationType;
Source = source.CreateEnumerable();
Destination = destination.CreateEnumerable();
}
- #endregion
+ #endregion Constructor
#region Modify
@@ -43,33 +43,30 @@ public void Modify(IStorageHistory newHistory)
Destination = newHistory.Destination;
}
- public void Modify(FileOperationType operationType, IEnumerable source, IEnumerable destination)
+ public void Modify(FileOperationType operationType, IEnumerable source, IEnumerable destination)
{
OperationType = operationType;
Source = source;
Destination = destination;
}
- public void Modify(FileOperationType operationType, PathWithType source, PathWithType destination)
+ public void Modify(FileOperationType operationType, IStorageItemWithPath source, IStorageItemWithPath destination)
{
OperationType = operationType;
Source = source.CreateEnumerable();
Destination = destination.CreateEnumerable();
}
- #endregion
+ #endregion Modify
#region IDisposable
public void Dispose()
{
- Source?.ForEach((item) => item?.Dispose());
- Destination?.ForEach((item) => item?.Dispose());
-
Source = null;
Destination = null;
}
- #endregion
+ #endregion IDisposable
}
-}
+}
\ No newline at end of file
diff --git a/Files/Filesystem/StorageHistory/StorageHistoryOperations.cs b/Files/Filesystem/StorageHistory/StorageHistoryOperations.cs
index 6611e0ad3c3e..b65439abe293 100644
--- a/Files/Filesystem/StorageHistory/StorageHistoryOperations.cs
+++ b/Files/Filesystem/StorageHistory/StorageHistoryOperations.cs
@@ -1,4 +1,6 @@
-using System;
+using Files.Enums;
+using Files.Helpers;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@@ -6,8 +8,6 @@
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
-using Files.Helpers;
-using Files.Enums;
namespace Files.Filesystem.FilesystemHistory
{
@@ -23,7 +23,7 @@ public class StorageHistoryOperations : IStorageHistoryOperations
private readonly CancellationToken cancellationToken;
- #endregion
+ #endregion Private Members
#region Constructor
@@ -35,7 +35,7 @@ public StorageHistoryOperations(IShellPage associatedInstance, CancellationToken
filesystemHelpers = new FilesystemHelpers(associatedInstance, cancellationToken);
}
- #endregion
+ #endregion Constructor
#region IStorageHistoryOperations
@@ -130,13 +130,20 @@ await filesystemOperations.RenameAsync(
cancellationToken));
}
- IStorageHistory newHistory = new StorageHistory(
- FileOperationType.Recycle,
- rawStorageHistory.SelectMany((item) => item?.Source).ToList(),
- rawStorageHistory.SelectMany((item) => item?.Destination).ToList());
+ if (rawStorageHistory.TrueForAll((item) => item != null))
+ {
+ IStorageHistory newHistory = new StorageHistory(
+ FileOperationType.Recycle,
+ rawStorageHistory.SelectMany((item) => item?.Source).ToList(),
+ rawStorageHistory.SelectMany((item) => item?.Destination).ToList());
- // We need to change the recycled item paths (since IDs are different) - for Undo() to work
- App.HistoryWrapper.ModifyCurrentHistory(newHistory);
+ // We need to change the recycled item paths (since IDs are different) - for Undo() to work
+ App.HistoryWrapper.ModifyCurrentHistory(newHistory);
+ }
+ else
+ {
+ App.HistoryWrapper.RemoveHistory(history, true);
+ }
break;
}
@@ -263,7 +270,7 @@ await filesystemOperations.RenameAsync(
if (returnStatus == ReturnResult.IntegrityCheckFailed) // Not found, corrupted
{
- App.HistoryWrapper.RemoveHistory(history);
+ App.HistoryWrapper.RemoveHistory(history, false);
}
break;
@@ -289,13 +296,20 @@ await filesystemOperations.RenameAsync(
cancellationToken));
}
- IStorageHistory newHistory = new StorageHistory(
- FileOperationType.Restore,
- rawStorageHistory.SelectMany((item) => item?.Destination).ToList(),
- rawStorageHistory.SelectMany((item) => item?.Source).ToList());
+ if (rawStorageHistory.TrueForAll((item) => item != null))
+ {
+ IStorageHistory newHistory = new StorageHistory(
+ FileOperationType.Restore,
+ rawStorageHistory.SelectMany((item) => item?.Destination).ToList(),
+ rawStorageHistory.SelectMany((item) => item?.Source).ToList());
- // We need to change the recycled item paths (since IDs are different) - for Redo() to work
- App.HistoryWrapper.ModifyCurrentHistory(newHistory);
+ // We need to change the recycled item paths (since IDs are different) - for Redo() to work
+ App.HistoryWrapper.ModifyCurrentHistory(newHistory);
+ }
+ else
+ {
+ App.HistoryWrapper.RemoveHistory(history, false);
+ }
break;
}
@@ -312,18 +326,19 @@ await filesystemOperations.RenameAsync(
return returnStatus;
}
- #endregion
+ #endregion IStorageHistoryOperations
#region Private Helpers
+ // history.Destination is null with CreateNew
private bool IsHistoryNull(IStorageHistory history) =>
!(history.Source.ToList().TrueForAll((item) => item != null && !string.IsNullOrWhiteSpace(item.Path))
- && history.Destination.ToList().TrueForAll((item) => item != null && !string.IsNullOrWhiteSpace(item.Path)));
+ && (history.Destination == null || history.Destination.ToList().TrueForAll((item) => item != null && !string.IsNullOrWhiteSpace(item.Path))));
- private bool IsHistoryNull(IEnumerable source) =>
+ private bool IsHistoryNull(IEnumerable source) =>
!(source.ToList().TrueForAll((item) => item != null && !string.IsNullOrWhiteSpace(item.Path)));
- #endregion
+ #endregion Private Helpers
#region IDisposable
@@ -338,6 +353,6 @@ public void Dispose()
filesystemHelpers = null;
}
- #endregion
+ #endregion IDisposable
}
-}
+}
\ No newline at end of file
diff --git a/Files/Filesystem/StorageHistory/StorageHistoryWrapper.cs b/Files/Filesystem/StorageHistory/StorageHistoryWrapper.cs
index ad5e710332be..92e0911c2c04 100644
--- a/Files/Filesystem/StorageHistory/StorageHistoryWrapper.cs
+++ b/Files/Filesystem/StorageHistory/StorageHistoryWrapper.cs
@@ -12,17 +12,17 @@ public class StorageHistoryWrapper : IDisposable
private int storageHistoryIndex;
- #endregion
+ #endregion Private Members
#region Constructor
public StorageHistoryWrapper()
{
this.storageHistory = new List();
- this.storageHistoryIndex = 0;
+ this.storageHistoryIndex = -1;
}
- #endregion
+ #endregion Constructor
#region Helpers
@@ -30,32 +30,41 @@ public void AddHistory(IStorageHistory history)
{
if (history != null)
{
- this.storageHistory?.Add(history);
-
- if (this.storageHistory?.Count > 1)
+ this.storageHistoryIndex++;
+ this.storageHistory.Insert(this.storageHistoryIndex, history);
+ // If a history item is added also remove all the redo operations after it
+ for (var idx = this.storageHistory.Count - 1; idx > this.storageHistoryIndex; idx--)
{
- this.storageHistoryIndex++;
+ this.storageHistory.RemoveAt(idx);
}
}
}
- public void RemoveHistory(IStorageHistory history)
+ public void RemoveHistory(IStorageHistory history, bool decreaseIndex)
{
if (history != null)
{
- this.storageHistory?.Remove(history);
- this.storageHistoryIndex--;
+ // If a history item is invalid also remove all the redo operations after it
+ for (var idx = this.storageHistory.Count - 1; idx > this.storageHistoryIndex; idx--)
+ {
+ this.storageHistory.RemoveAt(idx);
+ }
+ if (decreaseIndex)
+ {
+ this.storageHistoryIndex--;
+ }
+ this.storageHistory.Remove(history);
}
}
public void ModifyCurrentHistory(IStorageHistory newHistory)
{
- this.storageHistory?[this.storageHistoryIndex].Modify(newHistory);
+ this.storageHistory[this.storageHistoryIndex].Modify(newHistory);
}
public IStorageHistory GetCurrentHistory()
{
- return this.storageHistory?.ElementAt(this.storageHistoryIndex);
+ return this.storageHistory.ElementAt(this.storageHistoryIndex);
}
public void IncreaseIndex()
@@ -74,18 +83,17 @@ public bool CanUndo() =>
public bool CanRedo() =>
(this.storageHistoryIndex + 1) < this.storageHistory.Count;
- #endregion
+ #endregion Helpers
#region IDisposable
public void Dispose()
{
storageHistory?.ForEach((item) => item?.Dispose());
-
storageHistory?.ForEach((item) => item = null);
storageHistory = null;
}
- #endregion
+ #endregion IDisposable
}
-}
+}
\ No newline at end of file
diff --git a/Files/Helpers/AppUpdater.cs b/Files/Helpers/AppUpdater.cs
new file mode 100644
index 000000000000..b4fc8b505283
--- /dev/null
+++ b/Files/Helpers/AppUpdater.cs
@@ -0,0 +1,84 @@
+using Microsoft.Toolkit.Uwp.Extensions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Windows.Services.Store;
+using Windows.UI.Xaml.Controls;
+
+namespace Files.Helpers
+{
+ internal class AppUpdater
+ {
+ private StoreContext context = null;
+ private IReadOnlyList UpdateList = null;
+
+ public AppUpdater()
+ {
+ context = StoreContext.GetDefault();
+ }
+
+ public async void CheckForUpdatesAsync(bool mandantoryOnly = true)
+ {
+ try
+ {
+ if (context == null)
+ {
+ context = StoreContext.GetDefault();
+ }
+
+ UpdateList = await context.GetAppAndOptionalStorePackageUpdatesAsync();
+
+ if (mandantoryOnly)
+ {
+ UpdateList = (IReadOnlyList)UpdateList.Where(e => e.Mandatory);
+ }
+
+ if (UpdateList.Count > 0)
+ {
+ if (await DownloadUpdatesConsent())
+ {
+ DownloadUpdates();
+ }
+ }
+ }
+ catch (Exception)
+ {
+ }
+ }
+
+ private async Task DownloadUpdatesConsent()
+ {
+ ContentDialog dialog = new ContentDialog
+ {
+ Title = "ConsentDialogTitle".GetLocalized(),
+ Content = "ConsentDialogContent".GetLocalized(),
+ CloseButtonText = "ConsentDialogCloseButtonText".GetLocalized(),
+ PrimaryButtonText = "ConsentDialogPrimaryButtonText".GetLocalized()
+ };
+ ContentDialogResult result = await dialog.ShowAsync();
+
+ if (result == ContentDialogResult.Primary)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ private IAsyncResult DownloadUpdates()
+ {
+ if (UpdateList == null || UpdateList.Count < 1)
+ {
+ return null;
+ }
+
+ if (context == null)
+ {
+ context = StoreContext.GetDefault();
+ }
+
+ IAsyncResult downloadOperation = (IAsyncResult)context.RequestDownloadAndInstallStorePackageUpdatesAsync(UpdateList);
+ return downloadOperation;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Files/Helpers/ArrayHelpers.cs b/Files/Helpers/ArrayHelpers.cs
deleted file mode 100644
index a7905c942a6b..000000000000
--- a/Files/Helpers/ArrayHelpers.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace Files.Helpers
-{
- public class ArrayHelpers
- {
- public static int FitBounds(int index, int length) =>
- index == 0 ? index : (index >= length ? length - 1 : (index < 0 ? 0 : index));
- }
-}
diff --git a/Files/Helpers/Convert/ErrorCodeConverter.cs b/Files/Helpers/Convert/ErrorCodeConverter.cs
index 17f66fd3a731..e66cc26688e8 100644
--- a/Files/Helpers/Convert/ErrorCodeConverter.cs
+++ b/Files/Helpers/Convert/ErrorCodeConverter.cs
@@ -39,9 +39,9 @@ public static ReturnResult ToStatus(this FilesystemErrorCode errorCode)
case FilesystemErrorCode.ERROR_INPROGRESS:
return ReturnResult.InProgress;
- default:
+ default:
return default;
}
}
}
-}
+}
\ No newline at end of file
diff --git a/Files/Helpers/PostBannerHelpers.cs b/Files/Helpers/PostBannerHelpers.cs
index 11d33566363f..d9236e9d2d9e 100644
--- a/Files/Helpers/PostBannerHelpers.cs
+++ b/Files/Helpers/PostBannerHelpers.cs
@@ -64,4 +64,4 @@ public static void PostBanner_Delete(ReturnResult status, FileOperationType oper
}
}
}
-}
+}
\ No newline at end of file
diff --git a/Files/Helpers/RecycleBinHelpers.cs b/Files/Helpers/RecycleBinHelpers.cs
index 61d47a55b56a..1d66cdae4d63 100644
--- a/Files/Helpers/RecycleBinHelpers.cs
+++ b/Files/Helpers/RecycleBinHelpers.cs
@@ -18,7 +18,7 @@ public class RecycleBinHelpers : IDisposable
private AppServiceConnection Connection => associatedInstance?.ServiceConnection;
- #endregion
+ #endregion Private Members
public RecycleBinHelpers(IShellPage associatedInstance)
{
@@ -81,6 +81,6 @@ public void Dispose()
associatedInstance = null;
}
- #endregion
+ #endregion IDisposable
}
-}
+}
\ No newline at end of file
diff --git a/Files/Helpers/RegistryHelper.cs b/Files/Helpers/RegistryHelper.cs
new file mode 100644
index 000000000000..3e16b59f321a
--- /dev/null
+++ b/Files/Helpers/RegistryHelper.cs
@@ -0,0 +1,132 @@
+using Files.DataModels;
+using Files.Filesystem;
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Security;
+using System.Text;
+using System.Threading.Tasks;
+using Windows.Storage;
+
+namespace Files.Helpers
+{
+ public static class RegistryHelper
+ {
+ public static async Task> GetNewContextMenuEntries()
+ {
+ var newMenuItems = new List();
+ foreach (var keyName in Registry.ClassesRoot.GetSubKeyNames()
+ .Where(x => x.StartsWith(".") && !new string[] { ".library-ms", ".url", ".lnk" }.Contains(x)))
+ {
+ using var key = Registry.ClassesRoot.OpenSubKeySafe(keyName);
+ if (key != null)
+ {
+ var ret = await GetShellNewRegistryEntries(key, key);
+ if (ret != null)
+ {
+ newMenuItems.Add(ret);
+ }
+ }
+ }
+ return newMenuItems;
+ }
+
+ public static async Task GetNewContextMenuEntryForType(string extension)
+ {
+ if (string.IsNullOrEmpty(extension)) return null;
+ using var key = Registry.ClassesRoot.OpenSubKeySafe(extension);
+ return key != null ? await GetShellNewRegistryEntries(key, key) : null;
+ }
+
+ private static async Task GetShellNewRegistryEntries(RegistryKey current, RegistryKey root)
+ {
+ foreach (var keyName in current.GetSubKeyNames())
+ {
+ using var key = current.OpenSubKeySafe(keyName);
+ if (key == null)
+ {
+ continue;
+ }
+ if (keyName == "ShellNew")
+ {
+ return await ParseShellNewRegistryEntry(key, root);
+ }
+ else
+ {
+ var ret = await GetShellNewRegistryEntries(key, root);
+ if (ret != null)
+ {
+ return ret;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static async Task ParseShellNewRegistryEntry(RegistryKey key, RegistryKey root)
+ {
+ if (!key.GetValueNames().Contains("NullFile") &&
+ !key.GetValueNames().Contains("ItemName") &&
+ !key.GetValueNames().Contains("FileName"))
+ {
+ return null;
+ }
+
+ var extension = root.Name.Substring(root.Name.LastIndexOf('\\') + 1);
+ var fileName = (string)key.GetValue("FileName");
+ if (!string.IsNullOrEmpty(fileName) && Path.GetExtension(fileName) != extension)
+ {
+ return null;
+ }
+
+ byte[] data = null;
+ var dataObj = key.GetValue("Data");
+ if (dataObj != null)
+ {
+ switch (key.GetValueKind("Data"))
+ {
+ case RegistryValueKind.Binary:
+ data = (byte[])dataObj;
+ break;
+ case RegistryValueKind.String:
+ data = UTF8Encoding.UTF8.GetBytes((string)dataObj);
+ break;
+ }
+ }
+
+ var sampleFile = await FilesystemTasks.Wrap(() => ApplicationData.Current.LocalFolder.CreateFolderAsync("extensions", CreationCollisionOption.OpenIfExists).AsTask())
+ .OnSuccess(t => t.CreateFileAsync("file" + extension, CreationCollisionOption.OpenIfExists).AsTask());
+
+ var displayType = sampleFile ? sampleFile.Result.DisplayType : string.Format("{0} {1}", "file", extension);
+ var thumbnail = sampleFile ? await sampleFile.Result.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.ListView, 24, Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale) : null;
+
+ var entry = new ShellNewEntry()
+ {
+ Extension = extension,
+ Template = fileName,
+ Name = displayType,
+ Command = (string)key.GetValue("Command"),
+ //Name = (string)key.GetValue("ItemName"),
+ //IconPath = (string)key.GetValue("IconPath"),
+ Icon = thumbnail,
+ Data = data
+ };
+
+ return entry;
+ }
+
+ private static RegistryKey OpenSubKeySafe(this RegistryKey root, string keyName)
+ {
+ try
+ {
+ return root.OpenSubKey(keyName);
+ }
+ catch (SecurityException)
+ {
+ return null;
+ }
+ }
+ }
+}
diff --git a/Files/Helpers/StorageItemHelpers.cs b/Files/Helpers/StorageItemHelpers.cs
index 0cb1030612ac..110b5ba197ca 100644
--- a/Files/Helpers/StorageItemHelpers.cs
+++ b/Files/Helpers/StorageItemHelpers.cs
@@ -1,5 +1,4 @@
using Files.Filesystem;
-using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
@@ -12,146 +11,47 @@ namespace Files.Helpers
///
public static class StorageItemHelpers
{
- // TODO: If the TODO of IStorageItemWithPath is implemented, change return type to IStorageItem
- public static async Task ToStorageItem(this string path, StorageFolderWithPath parentFolder = null)
+ public static async Task ToStorageItem(this IStorageItemWithPath item, IShellPage associatedInstance = null)
{
- FilesystemResult fsRootFolderResult = await FilesystemTasks.Wrap(async () =>
+ if (item.Item != null)
{
- return (StorageFolderWithPath)await Path.GetPathRoot(path).ToStorageItemWithPath();
- });
-
- FilesystemResult fsFileResult = await FilesystemTasks.Wrap(() =>
- {
- return StorageFileExtensions.DangerousGetFileFromPathAsync(path, fsRootFolderResult.Result, parentFolder);
- });
-
- if (fsFileResult)
- {
- if (!string.IsNullOrWhiteSpace(fsFileResult.Result.Path))
- {
- return fsFileResult.Result;
- }
- else
- {
- FilesystemResult fsFileWithPathResult = await FilesystemTasks.Wrap(() =>
- {
- return StorageFileExtensions.DangerousGetFileWithPathFromPathAsync(path, fsRootFolderResult);
- });
-
- if (fsFileWithPathResult)
- {
- return null; /* fsFileWithPathResult.Result */ // Could be done if IStorageItemWithPath implemented IStorageItem
- }
- }
- }
-
- FilesystemResult fsFolderResult = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path));
-
- if (fsFolderResult)
- {
- if (!string.IsNullOrWhiteSpace(fsFolderResult.Result.Path))
- {
- return fsFolderResult.Result;
- }
- else
- {
- FilesystemResult fsFolderWithPathResult = await FilesystemTasks.Wrap(() =>
- {
- return StorageFileExtensions.DangerousGetFolderWithPathFromPathAsync(path, fsRootFolderResult);
- });
-
- if (fsFolderWithPathResult)
- {
- return null; /* fsFolderWithPathResult.Result; */ // Could be done if IStorageItemWithPath implemented IStorageItem
- }
- }
- }
-
- return null;
- }
-
- public static async Task ToStorageItemWithPath(this string path, StorageFolderWithPath parentFolder = null)
- {
- StorageFolderWithPath rootFolder = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(path));
-
- FilesystemResult fsFileWithPathResult = await FilesystemTasks.Wrap(() =>
- {
- return StorageFileExtensions.DangerousGetFileWithPathFromPathAsync(path, rootFolder, parentFolder);
- });
-
- if (fsFileWithPathResult)
- {
- return fsFileWithPathResult.Result;
+ return item.Item;
}
-
- FilesystemResult fsFolderWithPathResult = await FilesystemTasks.Wrap(() =>
- {
- return StorageFileExtensions.DangerousGetFolderWithPathFromPathAsync(path, rootFolder);
- });
-
- if (fsFolderWithPathResult)
+ if (!string.IsNullOrEmpty(item.Path))
{
- return fsFolderWithPathResult.Result;
+ return (item.ItemType == FilesystemItemType.File) ?
+ (associatedInstance != null ?
+ (IStorageItem)(StorageFile)await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(item.Path) :
+ (IStorageItem)(StorageFile)await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileFromPathAsync(item.Path))) :
+ (associatedInstance != null ?
+ (IStorageItem)(StorageFolder)await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(item.Path) :
+ (IStorageItem)(StorageFolder)await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(item.Path)));
}
-
return null;
}
- public static async Task IsOfType(this string path, StorageItemTypes type)
+ public static IStorageItemWithPath FromPathAndType(string customPath, FilesystemItemType? itemType)
{
- IStorageItem item = await path.ToStorageItem() is IStorageItem storageItem ? storageItem : null;
- return item?.IsOfType(type);
+ return (itemType == FilesystemItemType.File) ?
+ (IStorageItemWithPath)new StorageFileWithPath(null, customPath) :
+ (IStorageItemWithPath)new StorageFolderWithPath(null, customPath);
}
- public static async Task> ToStorageItemWithPathCollection(this IEnumerable listedItems,
- StorageFolderWithPath parentFolder = null)
+ public static IStorageItemWithPath FromStorageItem(this IStorageItem item, string customPath = null, FilesystemItemType? itemType = null)
{
- List output = new List();
-
- foreach (ListedItem item in listedItems)
+ if (item == null)
{
- output.Add(await item.ItemPath.ToStorageItemWithPath(parentFolder));
+ return FromPathAndType(customPath, itemType);
}
-
- return output;
- }
-
- public static async Task> ToStorageItemWithPathCollection(this IEnumerable paths,
- StorageFolderWithPath parentFolder = null)
- {
- List output = new List();
-
- foreach (string path in paths)
- {
- output.Add(await path.ToStorageItemWithPath(parentFolder));
- }
-
- return output;
- }
-
- public static async Task> ToStorageItemCollection(this IEnumerable paths, StorageFolderWithPath parentFolder = null)
- {
- List output = new List();
-
- foreach (string path in paths)
+ else if (item.IsOfType(StorageItemTypes.File))
{
- output.Add(await path.ToStorageItem(parentFolder));
+ return new StorageFileWithPath(item as StorageFile, string.IsNullOrEmpty(item.Path) ? customPath : item.Path);
}
-
- return output;
- }
-
- public static async Task> ToStorageItemCollection(this IEnumerable listedItems,
- StorageFolderWithPath parentFolder = null)
- {
- List output = new List();
-
- foreach (ListedItem item in listedItems)
+ else if (item.IsOfType(StorageItemTypes.Folder))
{
- output.Add(await item.ItemPath.ToStorageItem(parentFolder));
+ return new StorageFolderWithPath(item as StorageFolder, string.IsNullOrEmpty(item.Path) ? customPath : item.Path);
}
-
- return output;
+ return null;
}
}
-}
+}
\ No newline at end of file
diff --git a/Files/INavigationToolbar.cs b/Files/INavigationToolbar.cs
index 354841387873..debb70d9f4b2 100644
--- a/Files/INavigationToolbar.cs
+++ b/Files/INavigationToolbar.cs
@@ -42,6 +42,7 @@ public interface INavigationToolbar
public event EventHandler UpRequested;
public event EventHandler RefreshRequested;
+
public void ClearSearchBoxQueryText(bool collapseSearchReigon = false);
}
diff --git a/Files/Interacts/Interaction.cs b/Files/Interacts/Interaction.cs
index 54ee764f8ec3..4f73ae735cbb 100644
--- a/Files/Interacts/Interaction.cs
+++ b/Files/Interacts/Interaction.cs
@@ -1,3 +1,4 @@
+using Files.DataModels;
using Files.Dialogs;
using Files.Enums;
using Files.Filesystem;
@@ -531,18 +532,18 @@ private async void OpenSelectedItems(bool displayApplicationPicker)
//Unfortunately this is unsupported | Remarks: https://docs.microsoft.com/en-us/uwp/api/windows.storage.search.queryoptions.sortorder?view=winrt-19041
//case Enums.SortOption.Size:
- //sortEntry.PropertyName = "System.TotalFileSize";
- //queryOptions.SortOrder.Clear();
- //queryOptions.SortOrder.Add(sortEntry);
- //break;
+ //sortEntry.PropertyName = "System.TotalFileSize";
+ //queryOptions.SortOrder.Clear();
+ //queryOptions.SortOrder.Add(sortEntry);
+ //break;
//Unfortunately this is unsupported | Remarks: https://docs.microsoft.com/en-us/uwp/api/windows.storage.search.queryoptions.sortorder?view=winrt-19041
//case Enums.SortOption.FileType:
- //sortEntry.PropertyName = "System.FileExtension";
- //queryOptions.SortOrder.Clear();
- //queryOptions.SortOrder.Add(sortEntry);
- //break;
+ //sortEntry.PropertyName = "System.FileExtension";
+ //queryOptions.SortOrder.Clear();
+ //queryOptions.SortOrder.Add(sortEntry);
+ //break;
//Handle unsupported
default:
@@ -806,7 +807,7 @@ public async void CreateShortcutFromItem_Click(object sender, RoutedEventArgs e)
public async void DeleteItem_Click(object sender, RoutedEventArgs e)
{
await FilesystemHelpers.DeleteItemsAsync(
- AssociatedInstance.ContentPage.SelectedItems.Select((item) => new PathWithType(
+ AssociatedInstance.ContentPage.SelectedItems.Select((item) => StorageItemHelpers.FromPathAndType(
item.ItemPath,
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory)).ToList(),
true, false, true);
@@ -928,7 +929,7 @@ public async void RestoreItem_Click(object sender, RoutedEventArgs e)
foreach (ListedItem listedItem in AssociatedInstance.ContentPage.SelectedItems)
{
FilesystemItemType itemType = (listedItem as RecycleBinItem).PrimaryItemAttribute == StorageItemTypes.Folder ? FilesystemItemType.Directory : FilesystemItemType.File;
- await FilesystemHelpers.RestoreFromTrashAsync(new PathWithType(
+ await FilesystemHelpers.RestoreFromTrashAsync(StorageItemHelpers.FromPathAndType(
(listedItem as RecycleBinItem).ItemPath,
itemType), (listedItem as RecycleBinItem).ItemOriginalPath, true);
}
@@ -1156,7 +1157,7 @@ public async Task PasteItemAsync()
AssociatedInstance.FilesystemViewModel.IsFolderEmptyTextDisplayed = false;
}
- public async void CreateFileFromDialogResultType(AddItemType itemType)
+ public async void CreateFileFromDialogResultType(AddItemType itemType, ShellNewEntry itemInfo)
{
string currentPath = null;
if (AssociatedInstance.ContentPage != null)
@@ -1174,7 +1175,7 @@ public async void CreateFileFromDialogResultType(AddItemType itemType)
// Create file based on dialog result
string userInput = renameDialog.storedRenameInput;
- var folderRes = await AssociatedInstance.FilesystemViewModel.GetFolderFromPathAsync(currentPath);
+ var folderRes = await AssociatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(currentPath);
FilesystemResult created = folderRes;
if (folderRes)
{
@@ -1185,27 +1186,17 @@ public async void CreateFileFromDialogResultType(AddItemType itemType)
created = await FilesystemTasks.Wrap(async () =>
{
return await FilesystemHelpers.CreateAsync(
- new PathWithType(Path.Combine(folderRes.Result.Path, userInput), FilesystemItemType.Directory),
+ StorageItemHelpers.FromPathAndType(Path.Combine(folderRes.Result.Path, userInput), FilesystemItemType.Directory),
true);
});
break;
- case AddItemType.TextDocument:
- userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewTextDocument".GetLocalized();
+ case AddItemType.File:
+ userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : itemInfo?.Name ?? "NewFile".GetLocalized();
created = await FilesystemTasks.Wrap(async () =>
{
return await FilesystemHelpers.CreateAsync(
- new PathWithType(Path.Combine(folderRes.Result.Path, userInput + ".txt"), FilesystemItemType.File),
- true);
- });
- break;
-
- case AddItemType.BitmapImage:
- userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewBitmapImage".GetLocalized();
- created = await FilesystemTasks.Wrap(async () =>
- {
- return await FilesystemHelpers.CreateAsync(
- new PathWithType(Path.Combine(folderRes.Result.Path, userInput + ".bmp"), FilesystemItemType.File),
+ StorageItemHelpers.FromPathAndType(Path.Combine(folderRes.Result.Path, userInput + itemInfo?.Extension), FilesystemItemType.File),
true);
});
break;
@@ -1218,22 +1209,16 @@ public async void CreateFileFromDialogResultType(AddItemType itemType)
}
public RelayCommand CreateNewFolder => new RelayCommand(() => NewFolder());
- public RelayCommand CreateNewTextDocument => new RelayCommand(() => NewTextDocument());
- public RelayCommand CreateNewBitmapImage => new RelayCommand(() => NewBitmapImage());
+ public RelayCommand CreateNewFile => new RelayCommand((itemType) => NewFile(itemType));
private void NewFolder()
{
- CreateFileFromDialogResultType(AddItemType.Folder);
- }
-
- private void NewTextDocument()
- {
- CreateFileFromDialogResultType(AddItemType.TextDocument);
+ CreateFileFromDialogResultType(AddItemType.Folder, null);
}
- private void NewBitmapImage()
+ private void NewFile(ShellNewEntry itemType)
{
- CreateFileFromDialogResultType(AddItemType.BitmapImage);
+ CreateFileFromDialogResultType(AddItemType.File, itemType);
}
public RelayCommand SelectAllContentPageItems => new RelayCommand(() => SelectAllItems());
@@ -1389,4 +1374,4 @@ await DialogDisplayHelper.ShowDialogAsync(
}
}
}
-}
+}
\ No newline at end of file
diff --git a/Files/MultilingualResources/Files.de-DE.xlf b/Files/MultilingualResources/Files.de-DE.xlf
index 0b588adf575b..29cf9b0bfc06 100644
--- a/Files/MultilingualResources/Files.de-DE.xlf
+++ b/Files/MultilingualResources/Files.de-DE.xlf
@@ -226,14 +226,6 @@
Ordner
-
-
- Bitmap Bild
-
-
-
- Textdatei
-
Eigenschaften
@@ -330,8 +322,8 @@
Textdokument
-
-
+
+
Details
@@ -410,14 +402,6 @@
Neuer Ordner
-
-
- Neues Textdokument
-
-
-
- Neues Bitmap Bild
-
Dieser Ordner ist leer.
@@ -1171,14 +1155,6 @@
Abbrechen
-
-
-
-
Layoutmodus
@@ -1899,10 +1867,70 @@
Search results
+
+
+ See who contributed to Files
+
+
+
+ Find out what's new in Files
+
+
+
+ Send the developers an issue report with more information
+
+
+
+ Support us on PayPal
+
List and sort directories alongside files
+
+
+ Details
+
+
+
+ No
+
+
+
+ Do you want to download and install the latest version of Files?
+
+
+
+ Yes
+
+
+
+ Updates Available
+
+
+
+ Hide protected operating system files (Recommended)
+
+
+
+ Hide protected operating system files (Recommended)
+
+
+
+ File
+
+
+
+
+
+ New File
+