Skip to content

Modify context menu options for executable and installer files #1155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
27 changes: 25 additions & 2 deletions Files.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,30 @@ private static void HandleApplicationLaunch(string application, AppServiceReques
process.StartInfo.FileName = application;
// Show window if workingDirectory (opening terminal)
process.StartInfo.CreateNoWindow = string.IsNullOrEmpty(workingDirectory);
process.StartInfo.Arguments = arguments;
if (arguments == "runas")
{
process.StartInfo.UseShellExecute = true;
process.StartInfo.Verb = "runas";
if (Path.GetExtension(application).ToLower() == ".msi")
{
process.StartInfo.FileName = "msiexec.exe";
process.StartInfo.Arguments = $"/a \"{application}\"";
}
}
else if (arguments == "runasuser")
{
process.StartInfo.UseShellExecute = true;
process.StartInfo.Verb = "runasuser";
if (Path.GetExtension(application).ToLower() == ".msi")
{
process.StartInfo.FileName = "msiexec.exe";
process.StartInfo.Arguments = $"/i \"{application}\"";
}
}
else
{
process.StartInfo.Arguments = arguments;
}
process.StartInfo.WorkingDirectory = workingDirectory;
process.Start();
}
Expand Down Expand Up @@ -420,4 +443,4 @@ private static void Connection_ServiceClosed(AppServiceConnection sender, AppSer
appServiceExit.Set();
}
}
}
}
5 changes: 4 additions & 1 deletion Files.sln
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Global
{533F9E86-EE0A-4FCB-B70C-F29532C1B787}.Release|x86.ActiveCfg = Release|x86
{533F9E86-EE0A-4FCB-B70C-F29532C1B787}.Release|x86.Build.0 = Release|x86
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|Any CPU.ActiveCfg = Debug|x86
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|Any CPU.Build.0 = Debug|x86
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|ARM.ActiveCfg = Debug|ARM
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|ARM.Build.0 = Debug|ARM
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|ARM.Deploy.0 = Debug|ARM
Expand All @@ -58,7 +59,6 @@ Global
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|ARM64.Deploy.0 = Debug|ARM64
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|x64.ActiveCfg = Debug|x64
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|x64.Build.0 = Debug|x64
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|x64.Deploy.0 = Debug|x64
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|x86.ActiveCfg = Debug|x86
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|x86.Build.0 = Debug|x86
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Debug|x86.Deploy.0 = Debug|x86
Expand All @@ -76,6 +76,8 @@ Global
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Release|x86.Build.0 = Release|x86
{64C30C4E-A69A-411C-9F78-776E7AAD583C}.Release|x86.Deploy.0 = Release|x86
{3B15596C-3DB9-4B58-B4C8-442D06A8C130}.Debug|Any CPU.ActiveCfg = Debug|x86
{3B15596C-3DB9-4B58-B4C8-442D06A8C130}.Debug|Any CPU.Build.0 = Debug|x86
{3B15596C-3DB9-4B58-B4C8-442D06A8C130}.Debug|Any CPU.Deploy.0 = Debug|x86
{3B15596C-3DB9-4B58-B4C8-442D06A8C130}.Debug|ARM.ActiveCfg = Debug|ARM
{3B15596C-3DB9-4B58-B4C8-442D06A8C130}.Debug|ARM.Build.0 = Debug|ARM
{3B15596C-3DB9-4B58-B4C8-442D06A8C130}.Debug|ARM.Deploy.0 = Debug|ARM
Expand Down Expand Up @@ -142,6 +144,7 @@ Global
{0533133F-2559-4B53-A0FD-0970BC0E312E}.Release|x86.ActiveCfg = Release|Any CPU
{0533133F-2559-4B53-A0FD-0970BC0E312E}.Release|x86.Build.0 = Release|Any CPU
{D4E6A3AB-DF72-44A4-9ACB-C8A222656A20}.Debug|Any CPU.ActiveCfg = Debug|Win32
{D4E6A3AB-DF72-44A4-9ACB-C8A222656A20}.Debug|Any CPU.Build.0 = Debug|Win32
{D4E6A3AB-DF72-44A4-9ACB-C8A222656A20}.Debug|ARM.ActiveCfg = Debug|ARM
{D4E6A3AB-DF72-44A4-9ACB-C8A222656A20}.Debug|ARM.Build.0 = Debug|ARM
{D4E6A3AB-DF72-44A4-9ACB-C8A222656A20}.Debug|ARM64.ActiveCfg = Debug|ARM64
Expand Down
33 changes: 29 additions & 4 deletions Files/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public void RightClickContextMenu_Opening(object sender, object e)
}
}

public void RightClickItemContextMenu_Opening(object sender, object e)
public async void RightClickItemContextMenu_Opening(object sender, object e)
{

SetShellContextmenu();
Expand All @@ -355,20 +355,45 @@ public void RightClickItemContextMenu_Opening(object sender, object e)

if (!string.IsNullOrEmpty(selectedDataItem.FileExtension))
{
if (selectedDataItem.FileExtension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
if (SelectedItem.FileExtension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
{
UnloadMenuFlyoutItemByName("OpenItem");
UnloadMenuFlyoutItemByName("OpenItemWithAppPicker");
UnloadMenuFlyoutItemByName("RunAsAdmin");
UnloadMenuFlyoutItemByName("RunAsAnotherUser");
(this.FindName("UnzipItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
//this.FindName("UnzipItem");
}
else if (!selectedDataItem.FileExtension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
else if (SelectedItem.FileExtension.Equals(".exe", StringComparison.OrdinalIgnoreCase)
|| SelectedItem.FileExtension.Equals(".msi", StringComparison.OrdinalIgnoreCase)
|| SelectedItem.FileExtension.Equals(".bat", StringComparison.OrdinalIgnoreCase))
{
(this.FindName("OpenItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
//this.FindName("OpenItem");

UnloadMenuFlyoutItemByName("OpenItemWithAppPicker");
UnloadMenuFlyoutItemByName("UnzipItem");
(this.FindName("RunAsAdmin") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
(this.FindName("RunAsAnotherUser") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
}
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;
UnloadMenuFlyoutItemByName("UnzipItem");
UnloadMenuFlyoutItemByName("RunAsAdmin");
UnloadMenuFlyoutItemByName("RunAsAnotherUser");
}
else
{
(this.FindName("OpenItem") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
//this.FindName("OpenItem");

(this.FindName("OpenItemWithAppPicker") as MenuFlyoutItemBase).Visibility = Visibility.Visible;
UnloadMenuFlyoutItemByName("UnzipItem");
UnloadMenuFlyoutItemByName("RunAsAdmin");
UnloadMenuFlyoutItemByName("RunAsAnotherUser");
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,14 @@
<Name>Files.MessageRelay</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Commands\" />
</ItemGroup>
<ItemGroup>
<SDKReference Include="WindowsDesktop, Version=10.0.19041.0">
<Name>Windows Desktop Extensions for the UWP</Name>
</SDKReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Commands\" />
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
Expand Down
36 changes: 31 additions & 5 deletions Files/Interacts/Interaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using static Files.Dialogs.ConfirmDeleteDialog;
using Windows.Security.Credentials.UI;

namespace Files.Interacts
{
Expand Down Expand Up @@ -174,19 +175,27 @@ public void GetPath_Click(object sender, RoutedEventArgs e)
}
}

public static async Task InvokeWin32Component(string applicationPath, string arguments = null)
public static async Task InvokeWin32Component(string applicationPath, string arguments = null, bool runAsAdmin = false)
{
await InvokeWin32Components(new List<string>() { applicationPath }, arguments);
await InvokeWin32Components(new List<string>() { applicationPath }, arguments, runAsAdmin);
}

public static async Task InvokeWin32Components(List<string> applicationPaths, string arguments = null)
public static async Task InvokeWin32Components(List<string> applicationPaths, string arguments = null, bool runAsAdmin = false)
{
Debug.WriteLine("Launching EXE in FullTrustProcess");
if (App.Connection != null)
{
var value = new ValueSet();
value.Add("Application", applicationPaths.FirstOrDefault());
if (runAsAdmin)
{
value.Add("Arguments", "runas");
}
else
{
value.Add("Arguments", arguments);
}
value.Add("ApplicationList", JsonConvert.SerializeObject(applicationPaths));
value.Add("Arguments", arguments);
await App.Connection.SendMessageAsync(value);
}
}
Expand Down Expand Up @@ -264,6 +273,23 @@ public static TEnum GetEnum<TEnum>(string text) where TEnum : struct
return (TEnum)Enum.Parse(typeof(TEnum), text);
}

public async void RunAsAdmin_Click()
{
await InvokeWin32Component(CurrentInstance.ContentPage.SelectedItem.ItemPath, null, true);
}

public async void RunAsAnotherUser_Click()
{
if (CurrentInstance.FilesystemViewModel.WorkingDirectory.StartsWith(AppSettings.RecycleBinPath))
{
// Do not open files and folders inside the recycle bin
return;
}

var clickedOnItem = CurrentInstance.ContentPage.SelectedItem;
await InvokeWin32Component(clickedOnItem.ItemPath, "runasuser", false);
}

public void OpenItem_Click(object sender, RoutedEventArgs e)
{
OpenSelectedItems(false);
Expand Down Expand Up @@ -1276,4 +1302,4 @@ public async Task<string> GetHashForFile(ListedItem fileItem, string nameOfAlg,
return CryptographicBuffer.EncodeToHexString(hash.GetValueAndReset()).ToLower();
}
}
}
}
8 changes: 8 additions & 0 deletions Files/MultilingualResources/Files.de-DE.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,14 @@
<source>{0:#,##0} Files, {1:#,##0} Folders</source>
<target state="new">{0:#,##0} Files, {1:#,##0} Folders</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAdmin.Text" translate="yes" xml:space="preserve">
<source>Run as administrator</source>
<target state="new">Run as administrator</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAnotherUser.Text" translate="yes" xml:space="preserve">
<source>Run as another user</source>
<target state="new">Run as another user</target>
</trans-unit>
<trans-unit id="PropertiesDriveItemTypesEquals" translate="yes" xml:space="preserve">
<source>All type of {0}</source>
<target state="new">All type of {0}</target>
Expand Down
8 changes: 8 additions & 0 deletions Files/MultilingualResources/Files.es-ES.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,14 @@
<source>{0:#,##0} Files, {1:#,##0} Folders</source>
<target state="new">{0:#,##0} Files, {1:#,##0} Folders</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAdmin.Text" translate="yes" xml:space="preserve">
<source>Run as administrator</source>
<target state="new">Run as administrator</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAnotherUser.Text" translate="yes" xml:space="preserve">
<source>Run as another user</source>
<target state="new">Run as another user</target>
</trans-unit>
<trans-unit id="PropertiesDriveItemTypesEquals" translate="yes" xml:space="preserve">
<source>All type of {0}</source>
<target state="new">All type of {0}</target>
Expand Down
8 changes: 8 additions & 0 deletions Files/MultilingualResources/Files.fr-FR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,14 @@
<source>{0:#,##0} Files, {1:#,##0} Folders</source>
<target state="new">{0:#,##0} Files, {1:#,##0} Folders</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAdmin.Text" translate="yes" xml:space="preserve">
<source>Run as administrator</source>
<target state="new">Run as administrator</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAnotherUser.Text" translate="yes" xml:space="preserve">
<source>Run as another user</source>
<target state="new">Run as another user</target>
</trans-unit>
<trans-unit id="PropertiesDriveItemTypesEquals" translate="yes" xml:space="preserve">
<source>All type of {0}</source>
<target state="new">All type of {0}</target>
Expand Down
8 changes: 8 additions & 0 deletions Files/MultilingualResources/Files.it-IT.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,14 @@
<source>{0:#,##0} Files, {1:#,##0} Folders</source>
<target state="new">{0:#,##0} Files, {1:#,##0} Folders</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAdmin.Text" translate="yes" xml:space="preserve">
<source>Run as administrator</source>
<target state="new">Run as administrator</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAnotherUser.Text" translate="yes" xml:space="preserve">
<source>Run as another user</source>
<target state="new">Run as another user</target>
</trans-unit>
<trans-unit id="PropertiesDriveItemTypesEquals" translate="yes" xml:space="preserve">
<source>All type of {0}</source>
<target state="new">All type of {0}</target>
Expand Down
10 changes: 9 additions & 1 deletion Files/MultilingualResources/Files.ja-JP.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,14 @@
<source>{0:#,##0} Files, {1:#,##0} Folders</source>
<target state="new">{0:#,##0} Files, {1:#,##0} Folders</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAdmin.Text" translate="yes" xml:space="preserve">
<source>Run as administrator</source>
<target state="new">Run as administrator</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAnotherUser.Text" translate="yes" xml:space="preserve">
<source>Run as another user</source>
<target state="new">Run as another user</target>
</trans-unit>
<trans-unit id="PropertiesDriveItemTypesEquals" translate="yes" xml:space="preserve">
<source>All type of {0}</source>
<target state="new">All type of {0}</target>
Expand Down Expand Up @@ -894,4 +902,4 @@
</group>
</body>
</file>
</xliff>
</xliff>
8 changes: 8 additions & 0 deletions Files/MultilingualResources/Files.nl-NL.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,14 @@
<source>{0:#,##0} Files, {1:#,##0} Folders</source>
<target state="new">{0:#,##0} Files, {1:#,##0} Folders</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAdmin.Text" translate="yes" xml:space="preserve">
<source>Run as administrator</source>
<target state="new">Run as administrator</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAnotherUser.Text" translate="yes" xml:space="preserve">
<source>Run as another user</source>
<target state="new">Run as another user</target>
</trans-unit>
<trans-unit id="PropertiesDriveItemTypesEquals" translate="yes" xml:space="preserve">
<source>All type of {0}</source>
<target state="new">All type of {0}</target>
Expand Down
8 changes: 8 additions & 0 deletions Files/MultilingualResources/Files.pl-PL.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,14 @@
<source>{0:#,##0} Files, {1:#,##0} Folders</source>
<target state="new">{0:#,##0} Files, {1:#,##0} Folders</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAdmin.Text" translate="yes" xml:space="preserve">
<source>Run as administrator</source>
<target state="new">Run as administrator</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAnotherUser.Text" translate="yes" xml:space="preserve">
<source>Run as another user</source>
<target state="new">Run as another user</target>
</trans-unit>
<trans-unit id="PropertiesDriveItemTypesEquals" translate="yes" xml:space="preserve">
<source>All type of {0}</source>
<target state="new">All type of {0}</target>
Expand Down
8 changes: 8 additions & 0 deletions Files/MultilingualResources/Files.ru-RU.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,14 @@
<source>{0:#,##0} Files, {1:#,##0} Folders</source>
<target state="translated">{0:#,##0} Файлов, {1:#,##0} Папок</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAdmin.Text" translate="yes" xml:space="preserve">
<source>Run as administrator</source>
<target state="new">Run as administrator</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAnotherUser.Text" translate="yes" xml:space="preserve">
<source>Run as another user</source>
<target state="new">Run as another user</target>
</trans-unit>
<trans-unit id="PropertiesDriveItemTypesEquals" translate="yes" xml:space="preserve">
<source>All type of {0}</source>
<target state="translated">Все типа {0}</target>
Expand Down
8 changes: 8 additions & 0 deletions Files/MultilingualResources/Files.ta.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,14 @@
<source>{0:#,##0} Files, {1:#,##0} Folders</source>
<target state="new">{0:#,##0} Files, {1:#,##0} Folders</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAdmin.Text" translate="yes" xml:space="preserve">
<source>Run as administrator</source>
<target state="new">Run as administrator</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAnotherUser.Text" translate="yes" xml:space="preserve">
<source>Run as another user</source>
<target state="new">Run as another user</target>
</trans-unit>
<trans-unit id="PropertiesDriveItemTypesEquals" translate="yes" xml:space="preserve">
<source>All type of {0}</source>
<target state="new">All type of {0}</target>
Expand Down
8 changes: 8 additions & 0 deletions Files/MultilingualResources/Files.tr-TR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,14 @@
<source>{0:#,##0} Files, {1:#,##0} Folders</source>
<target state="new">{0:#,##0} Files, {1:#,##0} Folders</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAdmin.Text" translate="yes" xml:space="preserve">
<source>Run as administrator</source>
<target state="new">Run as administrator</target>
</trans-unit>
<trans-unit id="BaseLayoutContextFlyoutRunAsAnotherUser.Text" translate="yes" xml:space="preserve">
<source>Run as another user</source>
<target state="new">Run as another user</target>
</trans-unit>
<trans-unit id="PropertiesDriveItemTypesEquals" translate="yes" xml:space="preserve">
<source>All type of {0}</source>
<target state="new">All type of {0}</target>
Expand Down
Loading