Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 108 additions & 3 deletions Files.Launcher/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Files.Common;
using Newtonsoft.Json;
using NLog;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand All @@ -10,13 +11,13 @@
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Vanara.PInvoke;
using Vanara.Windows.Shell;
using Windows.ApplicationModel;
using Windows.ApplicationModel.AppService;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation.Collections;
using Windows.Storage;
using Vanara.PInvoke;
using NLog;

namespace FilesFullTrust
{
Expand Down Expand Up @@ -245,6 +246,10 @@ private static async Task parseArguments(AppServiceRequestReceivedEventArgs args
}
break;

case "FileOperation":
await parseFileOperation(args);
break;

default:
if (args.Request.Message.ContainsKey("Application"))
{
Expand All @@ -260,6 +265,106 @@ private static async Task parseArguments(AppServiceRequestReceivedEventArgs args
}
}

private static async Task parseFileOperation(AppServiceRequestReceivedEventArgs args)
{
var fileOp = (string)args.Request.Message["fileop"];

switch (fileOp)
{
case "Clipboard":
await Win32API.StartSTATask(() =>
{
System.Windows.Forms.Clipboard.Clear();
var fileToCopy = (string)args.Request.Message["filepath"];
var operation = (DataPackageOperation)(int)args.Request.Message["operation"];
var fileList = new System.Collections.Specialized.StringCollection();
fileList.AddRange(fileToCopy.Split('|'));
if (operation == DataPackageOperation.Copy)
{
System.Windows.Forms.Clipboard.SetFileDropList(fileList);
}
else if (operation == DataPackageOperation.Move)
{
byte[] moveEffect = new byte[] { 2, 0, 0, 0 };
MemoryStream dropEffect = new MemoryStream();
dropEffect.Write(moveEffect, 0, moveEffect.Length);
var data = new System.Windows.Forms.DataObject();
data.SetFileDropList(fileList);
data.SetData("Preferred DropEffect", dropEffect);
System.Windows.Forms.Clipboard.SetDataObject(data, true);
}
return true;
});
break;
case "MoveToBin":
var fileToDeletePath = (string)args.Request.Message["filepath"];
using (var op = new ShellFileOperations())
{
op.Options = ShellFileOperations.OperationFlags.AllowUndo | ShellFileOperations.OperationFlags.NoUI;
using var shi = new ShellItem(fileToDeletePath);
op.QueueDeleteOperation(shi);
op.PerformOperations();
}
//ShellFileOperations.Delete(fileToDeletePath, ShellFileOperations.OperationFlags.AllowUndo | ShellFileOperations.OperationFlags.NoUI);
break;
case "ParseLink":
var linkPath = (string)args.Request.Message["filepath"];
if (linkPath.EndsWith(".lnk"))
{
using var link = new ShellLink(linkPath, LinkResolution.NoUIWithMsgPump, null, TimeSpan.FromMilliseconds(100));
await args.Request.SendResponseAsync(new ValueSet() {
{ "TargetPath", link.TargetPath },
{ "Arguments", link.Arguments },
{ "WorkingDirectory", link.WorkingDirectory },
{ "RunAsAdmin", link.RunAsAdministrator },
{ "IsFolder", !string.IsNullOrEmpty(link.TargetPath) && link.Target.IsFolder },
});
}
else if (linkPath.EndsWith(".url"))
{
var linkUrl = await Win32API.StartSTATask(() =>
{
var ipf = new Url.IUniformResourceLocator();
(ipf as System.Runtime.InteropServices.ComTypes.IPersistFile).Load(linkPath, 0);
ipf.GetUrl(out var retVal);
return retVal;
});
await args.Request.SendResponseAsync(new ValueSet() {
{ "TargetPath", linkUrl },
{ "Arguments", null },
{ "WorkingDirectory", null },
{ "RunAsAdmin", false },
{ "IsFolder", false }
});
}
break;
case "CreateLink":
case "UpdateLink":
var linkSavePath = (string)args.Request.Message["filepath"];
var targetPath = (string)args.Request.Message["targetpath"];
if (linkSavePath.EndsWith(".lnk"))
{
var arguments = (string)args.Request.Message["arguments"];
var workingDirectory = (string)args.Request.Message["workingdir"];
var runAsAdmin = (bool)args.Request.Message["runasadmin"];
using var newLink = new ShellLink(targetPath, arguments, workingDirectory);
newLink.RunAsAdministrator = runAsAdmin;
newLink.SaveAs(linkSavePath); // Overwrite if exists
}
else if (linkSavePath.EndsWith(".url"))
{
await Win32API.StartSTATask(() =>
{
var ipf = new Url.IUniformResourceLocator();
ipf.SetUrl(targetPath, Url.IURL_SETURL_FLAGS.IURL_SETURL_FL_GUESS_PROTOCOL);
(ipf as System.Runtime.InteropServices.ComTypes.IPersistFile).Save(linkSavePath, false); // Overwrite if exists
return true;
});
}
break;
}
}

private static async Task parseRecycleBinAction(AppServiceRequestReceivedEventArgs args, string action)
{
switch (action)
Expand Down Expand Up @@ -395,7 +500,7 @@ private static async void HandleApplicationLaunch(string application, AppService
{
await Win32API.StartSTATask(() =>
{
var split = application.Split(';').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => GetMtpPath(x));
var split = application.Split('|').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => GetMtpPath(x));
if (split.Count() == 1)
{
Process.Start(split.First());
Expand Down
Binary file modified Files/Assets/Custom Glyphs/Custom-Glyphs.ttf
Binary file not shown.
55 changes: 46 additions & 9 deletions Files/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,22 @@ public void RightClickItemContextMenu_Opening(object sender, object e)

if (!string.IsNullOrEmpty(selectedDataItem.FileExtension))
{
if (SelectedItem.FileExtension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
if (SelectedItem.IsShortcutItem)
{
(this.FindName("OpenItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
UnloadMenuFlyoutItemByName("OpenItemWithAppPicker");
UnloadMenuFlyoutItemByName("UnzipItem");
UnloadMenuFlyoutItemByName("RunAsAdmin");
UnloadMenuFlyoutItemByName("RunAsAnotherUser");
UnloadMenuFlyoutItemByName("CreateShortcut");
}
else if (SelectedItem.FileExtension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
{
UnloadMenuFlyoutItemByName("OpenItem");
UnloadMenuFlyoutItemByName("OpenItemWithAppPicker");
UnloadMenuFlyoutItemByName("RunAsAdmin");
UnloadMenuFlyoutItemByName("RunAsAnotherUser");
(this.FindName("CreateShortcut") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
(this.FindName("UnzipItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
}
else if (SelectedItem.FileExtension.Equals(".exe", StringComparison.OrdinalIgnoreCase)
Expand All @@ -358,6 +368,7 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
UnloadMenuFlyoutItemByName("UnzipItem");
(this.FindName("RunAsAdmin") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
(this.FindName("RunAsAnotherUser") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
(this.FindName("CreateShortcut") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
}
else if (SelectedItem.FileExtension.Equals(".appx", StringComparison.OrdinalIgnoreCase)
|| SelectedItem.FileExtension.Equals(".msix", StringComparison.OrdinalIgnoreCase)
Expand All @@ -368,6 +379,7 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
UnloadMenuFlyoutItemByName("UnzipItem");
UnloadMenuFlyoutItemByName("RunAsAdmin");
UnloadMenuFlyoutItemByName("RunAsAnotherUser");
(this.FindName("CreateShortcut") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
}
else
{
Expand All @@ -378,6 +390,7 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
UnloadMenuFlyoutItemByName("UnzipItem");
UnloadMenuFlyoutItemByName("RunAsAdmin");
UnloadMenuFlyoutItemByName("RunAsAnotherUser");
(this.FindName("CreateShortcut") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
}
}
}
Expand All @@ -386,16 +399,33 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
UnloadMenuFlyoutItemByName("OpenItem");
UnloadMenuFlyoutItemByName("OpenItemWithAppPicker");
UnloadMenuFlyoutItemByName("UnzipItem");
UnloadMenuFlyoutItemByName("CreateShortcut");
}
}
else // All are Folders
else // All are folders or shortcuts to folders
{
UnloadMenuFlyoutItemByName("OpenItem");
UnloadMenuFlyoutItemByName("OpenItemWithAppPicker");

if (selectedFileSystemItems.Count <= 5 && selectedFileSystemItems.Count > 0)
if (selectedFileSystemItems.Any(x => x.IsShortcutItem))
{
UnloadMenuFlyoutItemByName("SidebarPinItem");
UnloadMenuFlyoutItemByName("CreateShortcut");
}
else if (selectedFileSystemItems.Count == 1)
{
(this.FindName("SidebarPinItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
//this.FindName("SidebarPinItem");
(this.FindName("CreateShortcut") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
}
else
{
(this.FindName("SidebarPinItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
UnloadMenuFlyoutItemByName("CreateShortcut");
}

if (selectedFileSystemItems.Count <= 5 && selectedFileSystemItems.Count > 0)
{
(this.FindName("OpenInNewTab") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
(this.FindName("OpenInNewWindowItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
//this.FindName("SidebarPinItem");
Expand All @@ -405,8 +435,6 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
}
else if (selectedFileSystemItems.Count > 5)
{
(this.FindName("SidebarPinItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
//this.FindName("SidebarPinItem");
UnloadMenuFlyoutItemByName("OpenInNewTab");
UnloadMenuFlyoutItemByName("OpenInNewWindowItem");
UnloadMenuFlyoutItemByName("UnzipItem");
Expand Down Expand Up @@ -484,12 +512,22 @@ protected async void List_Drop(object sender, DragEventArgs e)
protected async void Item_DragStarting(object sender, DragStartingEventArgs e)
{
List<IStorageItem> selectedStorageItems = new List<IStorageItem>();

foreach (ListedItem item in App.CurrentInstance.ContentPage.SelectedItems)
{
if (item.PrimaryItemAttribute == StorageItemTypes.File)
if (item is ShortcutItem)
{
// Can't drag shortcut items
continue;
}
else if (item.PrimaryItemAttribute == StorageItemTypes.File)
{
selectedStorageItems.Add(await ItemViewModel.GetFileFromPathAsync(item.ItemPath));
}
else if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
{
selectedStorageItems.Add(await ItemViewModel.GetFolderFromPathAsync(item.ItemPath));
}
}

if (selectedStorageItems.Count == 0)
Expand Down Expand Up @@ -540,8 +578,7 @@ protected async void Item_Drop(object sender, DragEventArgs e)

e.Handled = true;
ListedItem rowItem = GetItemFromElement(sender);
await App.CurrentInstance.InteractionOperations.PasteItems(e.DataView, rowItem.ItemPath, e.AcceptedOperation);

await App.CurrentInstance.InteractionOperations.PasteItems(e.DataView, (rowItem as ShortcutItem)?.TargetPath ?? rowItem.ItemPath, e.AcceptedOperation);
deferral.Complete();
}

Expand Down Expand Up @@ -600,4 +637,4 @@ public void BaseLayout_PointerWheelChanged(object sender, PointerRoutedEventArgs
}
}
}
}
}
4 changes: 3 additions & 1 deletion Files/Dialogs/AddItemDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Xaml.Controls;

Expand Down Expand Up @@ -53,7 +54,8 @@ public static async void CreateFile(AddItemType fileType)
{
currentPath = TabInstance.FilesystemViewModel.WorkingDirectory;
}
StorageFolder folderToCreateItem = await Filesystem.ItemViewModel.GetFolderFromPathAsync(currentPath);
var folderWithPath = await Filesystem.ItemViewModel.GetFolderWithPathFromPathAsync(currentPath);
StorageFolder folderToCreateItem = folderWithPath.Folder;
RenameDialog renameDialog = new RenameDialog();

var renameResult = await renameDialog.ShowAsync();
Expand Down
14 changes: 14 additions & 0 deletions Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@
<DependentUpon>Properties.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Views\Pages\PropertiesGeneral.xaml.cs">
<DependentUpon>PropertiesGeneral.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Pages\PropertiesShortcut.xaml.cs">
<DependentUpon>PropertiesShortcut.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Pages\Search.xaml.cs">
<DependentUpon>Search.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -507,6 +513,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Pages\PropertiesGeneral.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Pages\PropertiesShortcut.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Pages\Search.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Loading