@@ -335,9 +335,12 @@ function Approve-NewTextFileContent {
335
335
begin {
336
336
337
337
# ensure content path exists, create if missing
338
- $contentPath = GenXdev.FileSystem\Expand-Path $ContentPath - CreateFile
338
+ $contentPath = GenXdev.FileSystem\Expand-Path $ContentPath `
339
+ - CreateFile
339
340
340
- Microsoft.PowerShell.Utility\Write-Verbose " Target file path: $contentPath "
341
+ # log the target file path for debugging
342
+ Microsoft.PowerShell.Utility\Write-Verbose (
343
+ " Target file path: ${contentPath} " )
341
344
}
342
345
343
346
@@ -346,17 +349,23 @@ function Approve-NewTextFileContent {
346
349
# check initial file existence for tracking deletion
347
350
$existed = [System.IO.File ]::Exists($contentPath )
348
351
349
- Microsoft.PowerShell.Utility\Write-Verbose " File existed before comparison: $existed "
352
+ # log initial file existence state
353
+ Microsoft.PowerShell.Utility\Write-Verbose (
354
+ " File existed before comparison: ${existed} " )
350
355
351
356
# create temporary file with matching extension for comparison
352
- $tempFile = GenXdev.FileSystem\Expand-Path ([System.IO.Path ]::GetTempFileName() +
357
+ $tempFile = GenXdev.FileSystem\Expand-Path (
358
+ [System.IO.Path ]::GetTempFileName() +
353
359
[System.IO.Path ]::GetExtension($contentPath )) `
354
360
- CreateDirectory
355
361
356
- Microsoft.PowerShell.Utility\Write-Verbose " Created temp comparison file: $tempFile "
362
+ # log temporary file creation
363
+ Microsoft.PowerShell.Utility\Write-Verbose (
364
+ " Created temp comparison file: ${tempFile} " )
357
365
358
366
# write proposed content to temp file
359
- $NewContent | Microsoft.PowerShell.Utility\Out-File $tempFile - Force
367
+ $NewContent |
368
+ Microsoft.PowerShell.Utility\Out-File $tempFile - Force
360
369
361
370
# launch winmerge for interactive comparison
362
371
$null = GenXdev.AI\Invoke-WinMerge `
@@ -366,26 +375,39 @@ function Approve-NewTextFileContent {
366
375
367
376
# prepare result tracking object
368
377
$result = @ {
378
+
369
379
approved = [System.IO.File ]::Exists($contentPath )
370
380
}
371
381
372
382
if ($result.approved ) {
373
383
374
- # check if content was modified during comparison
375
- $content = Microsoft.PowerShell.Management\Get-Content - LiteralPath $contentPath - Raw
384
+ # read file content to check for modifications
385
+ $content = [System.IO.File ]::ReadAllText($contentPath )
386
+
387
+ # compare original and modified content
376
388
$changed = $content.Trim () -ne $NewContent.Trim ()
377
389
390
+ # track if content was accepted without changes
378
391
$result.approvedAsIs = -not $changed
379
392
380
393
if ($changed ) {
394
+
395
+ # store the user-modified content
381
396
$result.savedContent = $content
382
397
}
383
398
}
384
399
elseif ($existed ) {
400
+
401
+ # track if user deleted the existing file
385
402
$result.userDeletedFile = $true
386
403
}
387
404
388
- Microsoft.PowerShell.Utility\Write-Verbose " Comparison result: $ ( $result | Microsoft.PowerShell.Utility\ConvertTo-Json ) "
405
+ # log the comparison result
406
+ Microsoft.PowerShell.Utility\Write-Verbose (
407
+ " Comparison result: $ (
408
+ $result |
409
+ Microsoft.PowerShell.Utility\ConvertTo-Json ) " )
410
+
389
411
return $result
390
412
}
391
413
0 commit comments