Skip to content
Open
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
10 changes: 6 additions & 4 deletions src/SizeBench.GUI/Windows/SelectSingleBinaryAndPDBControl.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<UserControl x:Class="SizeBench.GUI.Windows.SelectSingleBinaryAndPDBControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignWidth="500">
<Grid>
<Grid AllowDrop="True "
PreviewDragOver="OnDragOver"
PreviewDrop="OnDrop">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
Expand Down
90 changes: 90 additions & 0 deletions src/SizeBench.GUI/Windows/SelectSingleBinaryAndPDBControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;
Expand Down Expand Up @@ -56,4 +57,93 @@ private void btnBinaryPathBrowse_Click(object sender, RoutedEventArgs e)
this._viewModel!.BinaryPath = ofd.FileName;
}
}

private void OnDragOver(object sender, DragEventArgs e)
{
e.Effects = GetDroppedExeAndPdb(e.Data) is null ? DragDropEffects.None : DragDropEffects.Copy;
e.Handled = true;
}

private static (string, string)? GetDroppedExeAndPdb(IDataObject data)
{
if (!data.GetDataPresent(DataFormats.FileDrop))
{
return null;
}

var files = (data.GetData(DataFormats.FileDrop) as string[])!;

if (files.Length is < 0 or > 2)
{
return null;
}

string? exePath = null;
string? pdbPath = null;
foreach (var file in files)
{
if (file.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
{
exePath = file;
}
else if (file.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase))
{
pdbPath = file;
}
}

if (exePath is null && pdbPath is null)
{
return null;
}

if (exePath is not null && pdbPath is not null)
{
return (exePath, pdbPath);
}

if (files.Length != 1)
{
return null;
}

if (exePath is not null)
{
pdbPath = exePath[..^3] + "pdb";
if (File.Exists(pdbPath))
{
return (exePath, pdbPath);
}

return null;
}

if (pdbPath is not null)
{
exePath = pdbPath[..^3] + "exe";
if (File.Exists(exePath))
{
return (exePath, pdbPath);
}
}

return null;
}

private void OnDrop(object sender, DragEventArgs e)
{
var exeAndPdb = GetDroppedExeAndPdb(e.Data);
if (exeAndPdb is null)
{
e.Effects = DragDropEffects.None;
e.Handled = true;
return;
}

var (exePath, pdbPath) = exeAndPdb.Value;
this._viewModel!.PDBPath = pdbPath;
this._viewModel!.BinaryPath = exePath;
e.Effects = DragDropEffects.Copy;
e.Handled = true;
}
}