@@ -335,9 +335,12 @@ function Approve-NewTextFileContent {
335335 begin {
336336
337337 # ensure content path exists, create if missing
338- $contentPath = GenXdev.FileSystem\Expand-Path $ContentPath - CreateFile
338+ $contentPath = GenXdev.FileSystem\Expand-Path $ContentPath `
339+ - CreateFile
339340
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} " )
341344 }
342345
343346
@@ -346,17 +349,23 @@ function Approve-NewTextFileContent {
346349 # check initial file existence for tracking deletion
347350 $existed = [System.IO.File ]::Exists($contentPath )
348351
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} " )
350355
351356 # 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() +
353359 [System.IO.Path ]::GetExtension($contentPath )) `
354360 - CreateDirectory
355361
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} " )
357365
358366 # 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
360369
361370 # launch winmerge for interactive comparison
362371 $null = GenXdev.AI\Invoke-WinMerge `
@@ -366,26 +375,39 @@ function Approve-NewTextFileContent {
366375
367376 # prepare result tracking object
368377 $result = @ {
378+
369379 approved = [System.IO.File ]::Exists($contentPath )
370380 }
371381
372382 if ($result.approved ) {
373383
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
376388 $changed = $content.Trim () -ne $NewContent.Trim ()
377389
390+ # track if content was accepted without changes
378391 $result.approvedAsIs = -not $changed
379392
380393 if ($changed ) {
394+
395+ # store the user-modified content
381396 $result.savedContent = $content
382397 }
383398 }
384399 elseif ($existed ) {
400+
401+ # track if user deleted the existing file
385402 $result.userDeletedFile = $true
386403 }
387404
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+
389411 return $result
390412 }
391413
0 commit comments