Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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: 10 additions & 0 deletions src/DiffEngine/DiffTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace DiffEngine
public static class DiffTools
{
static Dictionary<string, ResolvedTool> ExtensionLookup = new();
static Dictionary<string, ResolvedTool> PathLookup = new();
static List<ResolvedTool> resolved = new();

public static IEnumerable<ResolvedTool> Resolved
Expand Down Expand Up @@ -178,6 +179,7 @@ static void AddResolvedToolAtStart(ResolvedTool resolvedTool)
var cleanedExtension = Extensions.GetExtension(extension);
ExtensionLookup[cleanedExtension] = resolvedTool;
}
PathLookup[resolvedTool.ExePath] = resolvedTool;
}

static DiffTools()
Expand All @@ -198,6 +200,7 @@ static void InitTools(bool resultFoundInEnvVar, IEnumerable<DiffTool> tools)
{
var custom = resolved.Where(x => x.Tool == null).ToList();
ExtensionLookup.Clear();
PathLookup.Clear();
resolved.Clear();

foreach (var tool in ToolsOrder.Sort(resultFoundInEnvVar, tools).Reverse())
Expand Down Expand Up @@ -234,6 +237,13 @@ public static void UseOrder(in bool throwForNoTool, params DiffTool[] order)
InitTools(throwForNoTool, order);
}

public static bool TryFindByPath(
string path,
[NotNullWhen(true)] out ResolvedTool? tool)
{
return PathLookup.TryGetValue(path, out tool);
}

public static bool TryFind(
string extension,
[NotNullWhen(true)] out ResolvedTool? tool)
Expand Down
3 changes: 1 addition & 2 deletions src/DiffEngine/ResolvedTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public string BuildCommand(string tempFile, string targetFile)
return $"\"{ExePath}\" {GetArguments(tempFile, targetFile)}";
}

string GetArguments(string tempFile, string targetFile)
public string GetArguments(string tempFile, string targetFile)
{
if (TargetPosition.TargetOnLeft)
{
Expand All @@ -38,7 +38,6 @@ string GetArguments(string tempFile, string targetFile)
return TargetRightArguments(tempFile, targetFile);
}


internal ResolvedTool(string name,
DiffTool? tool,
string exePath,
Expand Down
8 changes: 4 additions & 4 deletions src/DiffEngineTray/TrackedMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

class TrackedMove
{
public TrackedMove(
string temp,
public TrackedMove(string temp,
string target,
string? exe,
string? arguments,
bool canKill,
Process? process,
string? group)
string? group,
string extension)
{
Temp = temp;
Target = target;
Exe = exe;
Arguments = arguments;
Name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(target));
Extension = Path.GetExtension(target).TrimStart('.');
Extension = extension;
CanKill = canKill;
Process = process;
Group = group;
Expand Down
56 changes: 48 additions & 8 deletions src/DiffEngineTray/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using DiffEngine;
using Serilog;

class Tracker :
Expand Down Expand Up @@ -116,10 +117,18 @@ public TrackedMove AddMove(
ProcessEx.TryGet(processId.Value, out process);
}

Log.Information("MoveAdded. Target:{target}, CanKill:{canKill}, Process:{process}, Command:{command}", targetFile, canKill, processId, $"{exeFile} {arguments}");
var move = BuildTrackedMove(temp, exe, arguments, canKill, target, process);

var solution = SolutionDirectoryFinder.Find(target);
return BuildTrackedMove(temp, exe, arguments, canKill, target, process, solution);
if (exeFile == null)
{
Log.Information("MoveAdded. Target:{target}, CanKill:{canKill}, Process:{process}", targetFile, move.CanKill, processId);
}
else
{
Log.Information("MoveAdded. Target:{target}, CanKill:{canKill}, Process:{process}, Command:{command}", targetFile, move.CanKill, processId, $"{exeFile} {arguments}");
}

return move;
},
updateValueFactory: (target, existing) =>
{
Expand All @@ -134,16 +143,47 @@ public TrackedMove AddMove(
ProcessEx.TryGet(processId.Value, out process);
}

Log.Information("MoveUpdated. Target:{target}, CanKill:{canKill}, Process:{process}, Command:{command}", targetFile, canKill, processId, $"{exeFile} {arguments}");
var move = BuildTrackedMove(temp, exe, arguments, canKill, target, process);

if (exeFile == null)
{
Log.Information("MoveUpdated. Target:{target}, CanKill:{canKill}, Process:{process}", targetFile, move.CanKill, processId);
}
else
{
Log.Information("MoveUpdated. Target:{target}, CanKill:{canKill}, Process:{process}, Command:{command}", targetFile, move.CanKill, processId, $"{exeFile} {arguments}");
}

var solution = SolutionDirectoryFinder.Find(target);
return BuildTrackedMove(temp, exe, arguments, canKill, target, process, solution);
return move;
});
}

static TrackedMove BuildTrackedMove(string temp, string? exe, string? arguments, bool canKill, string target, Process? process, string? solution)
static TrackedMove BuildTrackedMove(string temp, string? exe, string? arguments, bool? canKill, string target, Process? process)
{
return new(temp, target, exe, arguments, canKill, process, solution);
var solution = SolutionDirectoryFinder.Find(target);
var extension = Path.GetExtension(target).TrimStart('.');
if (exe == null)
{
if(DiffTools.TryFind(extension, out var tool))
{
arguments = tool.GetArguments(temp, target);
exe = tool.ExePath;
canKill = !tool.IsMdi;
}
}
else if (canKill == null)
{
if (DiffTools.TryFindByPath(exe, out var tool))
{
canKill = !tool.IsMdi;
}
else
{
canKill = false;
}
}

return new(temp, target, exe, arguments, canKill.GetValueOrDefault(false), process, solution, extension);
}

public TrackedDelete AddDelete(string file)
Expand Down