Skip to content

Commit

Permalink
Ignore BCU itself when mouse-dragging to target an application (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
Klocman authored May 10, 2024
1 parent 59761ba commit 3ef2333
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions source/BulkCrapUninstaller/Forms/Helpers/TargetWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ Apache License Version 2.0
*/

using BulkCrapUninstaller.Controls;
using BulkCrapUninstaller.Properties;
using Klocman.Extensions;
using Klocman.Forms.Tools;
using Klocman.Tools;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using BulkCrapUninstaller.Properties;

namespace BulkCrapUninstaller.Forms
{
Expand Down Expand Up @@ -50,7 +51,7 @@ protected virtual void OnDirectoriesSelected(DirectoriesSelectedEventArgs e)
Close();
DirectoriesSelected?.Invoke(this, e);
}

private void WindowTargeter1OnPickingStarted(object sender, EventArgs e)
{
_setMainWindowVisible(false);
Expand All @@ -62,7 +63,18 @@ private void WindowTargeterWindowSelected(object sender, Klocman.Subsystems.Wind

try
{
var parentDirectory = new FileInfo(e.TargetWindow.GetRunningProcess().MainModule?.FileName ?? throw new InvalidOperationException("Process has no MainModule")).Directory;
var fileName = e.TargetWindow.GetRunningProcess().MainModule?.FileName;
if (fileName == null)
throw new InvalidOperationException("Process has no MainModule");

var parentDirectory = new FileInfo(fileName).Directory;
if (parentDirectory == null)
throw new InvalidOperationException("Failed to get MainModule Directory");

// Ignore targeting BCU itself
if (PathTools.SubPathIsInsideBasePath(Program.AssemblyLocation.FullName, fileName, true))
return;

OnDirectoriesSelected(new DirectoriesSelectedEventArgs(parentDirectory.ToEnumerable().ToList()));
}
catch (Exception exception)
Expand Down

0 comments on commit 3ef2333

Please sign in to comment.