66using System . Linq ;
77using System . Threading ;
88using System . Threading . Tasks ;
9+ using DiffEngine ;
910using Serilog ;
1011
1112class Tracker :
@@ -116,10 +117,18 @@ public TrackedMove AddMove(
116117 ProcessEx . TryGet ( processId . Value , out process ) ;
117118 }
118119
119- Log . Information ( "MoveAdded. Target:{target}, CanKill:{canKill}, Process:{process}, Command:{command}" , targetFile , canKill , processId , $ " { exeFile } { arguments } " ) ;
120+ var move = BuildTrackedMove ( temp , exe , arguments , canKill , target , process ) ;
120121
121- var solution = SolutionDirectoryFinder . Find ( target ) ;
122- return BuildTrackedMove ( temp , exe , arguments , canKill , target , process , solution ) ;
122+ if ( exeFile == null )
123+ {
124+ Log . Information ( "MoveAdded. Target:{target}, CanKill:{canKill}, Process:{process}" , targetFile , move . CanKill , processId ) ;
125+ }
126+ else
127+ {
128+ Log . Information ( "MoveAdded. Target:{target}, CanKill:{canKill}, Process:{process}, Command:{command}" , targetFile , move . CanKill , processId , $ "{ exeFile } { arguments } ") ;
129+ }
130+
131+ return move ;
123132 } ,
124133 updateValueFactory : ( target , existing ) =>
125134 {
@@ -134,16 +143,47 @@ public TrackedMove AddMove(
134143 ProcessEx . TryGet ( processId . Value , out process ) ;
135144 }
136145
137- Log . Information ( "MoveUpdated. Target:{target}, CanKill:{canKill}, Process:{process}, Command:{command}" , targetFile , canKill , processId , $ "{ exeFile } { arguments } ") ;
146+ var move = BuildTrackedMove ( temp , exe , arguments , canKill , target , process ) ;
147+
148+ if ( exeFile == null )
149+ {
150+ Log . Information ( "MoveUpdated. Target:{target}, CanKill:{canKill}, Process:{process}" , targetFile , move . CanKill , processId ) ;
151+ }
152+ else
153+ {
154+ Log . Information ( "MoveUpdated. Target:{target}, CanKill:{canKill}, Process:{process}, Command:{command}" , targetFile , move . CanKill , processId , $ "{ exeFile } { arguments } ") ;
155+ }
138156
139- var solution = SolutionDirectoryFinder . Find ( target ) ;
140- return BuildTrackedMove ( temp , exe , arguments , canKill , target , process , solution ) ;
157+ return move ;
141158 } ) ;
142159 }
143160
144- static TrackedMove BuildTrackedMove ( string temp , string ? exe , string ? arguments , bool canKill , string target , Process ? process , string ? solution )
161+ static TrackedMove BuildTrackedMove ( string temp , string ? exe , string ? arguments , bool ? canKill , string target , Process ? process )
145162 {
146- return new ( temp , target , exe , arguments , canKill , process , solution ) ;
163+ var solution = SolutionDirectoryFinder . Find ( target ) ;
164+ var extension = Path . GetExtension ( target ) . TrimStart ( '.' ) ;
165+ if ( exe == null )
166+ {
167+ if ( DiffTools . TryFind ( extension , out var tool ) )
168+ {
169+ arguments = tool . GetArguments ( temp , target ) ;
170+ exe = tool . ExePath ;
171+ canKill = ! tool . IsMdi ;
172+ }
173+ }
174+ else if ( canKill == null )
175+ {
176+ if ( DiffTools . TryFindByPath ( exe , out var tool ) )
177+ {
178+ canKill = ! tool . IsMdi ;
179+ }
180+ else
181+ {
182+ canKill = false ;
183+ }
184+ }
185+
186+ return new ( temp , target , exe , arguments , canKill . GetValueOrDefault ( false ) , process , solution , extension ) ;
147187 }
148188
149189 public TrackedDelete AddDelete ( string file )
0 commit comments