Skip to content

Commit 2e43a1a

Browse files
authored
Fix: Fixed an issue with dropping multiple items onto executable files (#14067)
1 parent 9e5b053 commit 2e43a1a

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

src/Files.App/Helpers/Environment/SoftwareHelpers.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Microsoft.Win32;
5+
using System.IO;
56

67
namespace Files.App.Helpers
78
{
@@ -30,6 +31,32 @@ public static bool IsVSInstalled()
3031
return true;
3132
}
3233

34+
public static bool IsPythonInstalled()
35+
{
36+
try
37+
{
38+
ProcessStartInfo psi = new ProcessStartInfo();
39+
psi.FileName = "python";
40+
psi.Arguments = "--version";
41+
psi.RedirectStandardOutput = true;
42+
psi.UseShellExecute = false;
43+
psi.CreateNoWindow = true;
44+
45+
using (Process process = Process.Start(psi))
46+
{
47+
using (StreamReader reader = process.StandardOutput)
48+
{
49+
string result = reader.ReadToEnd();
50+
return result.Contains("Python");
51+
}
52+
}
53+
}
54+
catch
55+
{
56+
return false;
57+
}
58+
}
59+
3360
private static bool ContainsName(RegistryKey? key, string find)
3461
{
3562
if (key is null)

src/Files.App/Helpers/Navigation/NavigationHelpers.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -321,42 +321,15 @@ public static async Task OpenSelectedItemsAsync(IShellPage associatedInstance, b
321321
}
322322
}
323323

324-
public static async Task OpenItemsWithExecutableAsync(IShellPage associatedInstance, IEnumerable<IStorageItemWithPath> items, string executable)
324+
public static async Task OpenItemsWithExecutableAsync(IShellPage associatedInstance, IEnumerable<IStorageItemWithPath> items, string executablePath)
325325
{
326326
// Don't open files and folders inside recycle bin
327327
if (associatedInstance.FilesystemViewModel.WorkingDirectory.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal) ||
328328
associatedInstance.SlimContentPage is null)
329-
{
330329
return;
331-
}
332-
333-
foreach (var item in items)
334-
{
335-
try
336-
{
337-
await OpenPath(executable, associatedInstance, FilesystemItemType.File, false, false, args: $"\"{item.Path}\"");
338-
}
339-
catch (Exception e)
340-
{
341-
// This is to try and figure out the root cause of AppCenter error #985932119u
342-
App.Logger.LogWarning(e, e.Message);
343-
}
344-
}
345-
}
346330

347-
public static async Task OpenItemsWithPythonAsync(IShellPage associatedInstance, IEnumerable<IStorageItemWithPath> items, string pythonScriptPath)
348-
{
349-
// Don't open files and folders inside recycle bin
350-
if (associatedInstance.FilesystemViewModel.WorkingDirectory.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal) ||
351-
associatedInstance.SlimContentPage is null)
352-
{
353-
return;
354-
}
355-
356-
foreach (var item in items)
357-
{
358-
await Win32Helpers.InvokeWin32ComponentAsync(pythonScriptPath, associatedInstance, arguments: $"\"{item.Path}\"");
359-
}
331+
var arguments = string.Join(" ", items.Select(item => $"\"{item.Path}\""));
332+
await Win32Helpers.InvokeWin32ComponentAsync(executablePath, associatedInstance, arguments);
360333
}
361334

362335
/// <summary>

src/Files.App/Utils/Storage/Operations/FilesystemHelpers.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,14 @@ public async Task<ReturnResult> PerformOperationTypeAsync(
255255
else if (operation.HasFlag(DataPackageOperation.Link))
256256
{
257257
// Open with piggybacks off of the link operation, since there isn't one for it
258-
if (isTargetExecutable)
258+
if (isTargetExecutable || isTargetPythonFile)
259259
{
260260
var items = await GetDraggedStorageItems(packageView);
261+
if (isTargetPythonFile && !SoftwareHelpers.IsPythonInstalled())
262+
return ReturnResult.Cancelled;
261263
NavigationHelpers.OpenItemsWithExecutableAsync(associatedInstance, items, destination);
262264
return ReturnResult.Success;
263265
}
264-
else if (isTargetPythonFile)
265-
{
266-
var items = await GetDraggedStorageItems(packageView);
267-
NavigationHelpers.OpenItemsWithPythonAsync(associatedInstance, items, destination);
268-
return ReturnResult.Success;
269-
}
270266
else
271267
{
272268
return await CreateShortcutFromClipboard(packageView, destination, showDialog, registerHistory);

src/Files.App/Views/Layouts/BaseLayoutPage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,9 @@ protected void InitializeDrag(UIElement container, ListedItem item)
12591259
return;
12601260

12611261
UninitializeDrag(container);
1262-
if ((item.PrimaryItemAttribute == StorageItemTypes.Folder && !RecycleBinHelpers.IsPathUnderRecycleBin(item.ItemPath)) || item.IsExecutable || item.IsPythonFile)
1262+
if ((item.PrimaryItemAttribute == StorageItemTypes.Folder && !RecycleBinHelpers.IsPathUnderRecycleBin(item.ItemPath))
1263+
|| item.IsExecutable
1264+
|| item.IsPythonFile)
12631265
{
12641266
container.AllowDrop = true;
12651267
container.AddHandler(UIElement.DragOverEvent, Item_DragOverEventHandler, true);

0 commit comments

Comments
 (0)