Skip to content
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

Ignore BCU itself when mouse-dragging to target an application #610

Merged
merged 1 commit into from
May 10, 2024
Merged
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
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
Loading