Skip to content

Conversation

Copy link

Copilot AI commented Jan 2, 2026

The Auto mode and QuickUpdateVersion mode contained ~50 lines of identical installer processing logic (downloading, SHA256 calculation, type detection, metadata extraction).

Changes

  • Extracted common installer processing into Update-InstallerEntry helper function
  • Refactored Read-QuickInstallerEntry to call helper with -ShowProgress flag for user feedback
  • Refactored Auto mode to call helper without progress messages for silent operation
  • Fixed variable reference bug in Auto mode (line 3138 used wrong variable name)
  • Added support for -Preserve flag to prevent removal of ProductCode, SignatureSha256, and PackageFamilyName when new values cannot be extracted

Example

Before (duplicated in two locations):

foreach ($_Installer in $Installers) {
  try {
    $script:dest = Get-InstallerFile -URI $_Installer.InstallerUrl ...
  } catch { ... }
  if ($_Installer['InstallerType'] -in @('msi'; 'exe')) {
    $DetectedType = Resolve-InstallerType $script:dest
    if ($DetectedType -in @('msi'; 'wix'; 'nullsoft'; 'inno'; 'burn')) { ... }
  }
  $_Installer['InstallerSha256'] = (Get-FileHash -Path $script:dest -Algorithm SHA256).Hash
  # ... 40+ more lines of product code, signature, family name extraction ...
}

After:

foreach ($_Installer in $Installers) {
  $_Installer = Update-InstallerEntry -Installer $_Installer -Preserve:$Preserve
}

The new function respects the -Preserve flag: when specified, ProductCode, SignatureSha256, and PackageFamilyName are preserved even if new values cannot be extracted, matching the behavior used elsewhere in the script for fields like ReleaseNotes and ReleaseDate.

Net: -20 lines, zero duplication, one bug fixed.

Original prompt

The YamlCreate.ps1 script has an Auto mode which duplicates much of the logic from earlier in the script. Refactor the script to reduce the duplicated logic without breaking functionality


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Refactor YamlCreate.ps1 to reduce duplicated logic in Auto mode Refactor YamlCreate.ps1 to eliminate duplicated installer processing logic Jan 2, 2026
Copilot AI requested a review from Trenly January 2, 2026 23:17
@Trenly
Copy link
Owner

Trenly commented Jan 2, 2026

@mdanish-kh - Mind reviewing?

@Trenly
Copy link
Owner

Trenly commented Jan 2, 2026

@copilot - Update the new function so that if -Preserve was used in the initial script options, the PFN and Product Code are not removed if they cannot be updated

Copy link
Author

Copilot AI commented Jan 2, 2026

@copilot - Update the new function so that if -Preserve was used in the initial script options, the PFN and Product Code are not removed if they cannot be updated

Updated in commit 8af9363. The Update-InstallerEntry function now accepts a -Preserve parameter and will not remove ProductCode, SignatureSha256, or PackageFamilyName when -Preserve is specified and new values cannot be extracted.

Copy link
Collaborator

@mdanish-kh mdanish-kh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the normal and auto flow journey, most of the code is nearly identical anyway :shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants