Skip to content

Commit

Permalink
prevent null pointer exceptions (npe)
Browse files Browse the repository at this point in the history
closes #144
  • Loading branch information
rgl committed Jul 10, 2024
1 parent 999534b commit 27a4abb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Configure your packer template to require a [release version of the plugin](http
packer {
required_plugins {
windows-update = {
version = "0.16.0"
version = "0.16.1"
source = "github.com/rgl/windows-update"
}
}
Expand Down
10 changes: 7 additions & 3 deletions update/windows-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,12 @@ while ($true) {
$rebootRequired = $false
for ($i = 0; $i -lt $searchResult.Updates.Count; ++$i) {
$update = $searchResult.Updates.Item($i)
$updateDate = $update.LastDeploymentChangeTime.ToString('yyyy-MM-dd')
$updateSize = ($update.MaxDownloadSize/1024/1024).ToString('0.##')
if (!$update) {
continue
}
$updateMaxDownloadSize = try { [int64]$update.MaxDownloadSize } catch { [int64]0 }
$updateDate = try { $update.LastDeploymentChangeTime.ToString('yyyy-MM-dd') } catch { '1970-01-01' }
$updateSize = ($updateMaxDownloadSize/1024/1024).ToString('0.##')
$updateTitle = $update.Title
$updateSummary = "Windows update ($updateDate; $updateSize MB): $updateTitle"

Expand All @@ -210,7 +214,7 @@ for ($i = 0; $i -lt $searchResult.Updates.Count; ++$i) {

$update.AcceptEula() | Out-Null

$updatesToDownloadSize += $update.MaxDownloadSize
$updatesToDownloadSize += $updateMaxDownloadSize
$updatesToDownload.Add($update) | Out-Null

$updatesToInstall.Add($update) | Out-Null
Expand Down

0 comments on commit 27a4abb

Please sign in to comment.