mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
win_regedit: fixed up diff output to be more representative of type (#28974)
* win_regedit: fixed up diff output to be more representative of type * added diff fix for creation of key and prop in one go
This commit is contained in:
parent
4a577bd67f
commit
91e7c3ec81
3 changed files with 41 additions and 484 deletions
|
@ -138,6 +138,27 @@ Function Compare-RegistryProperties($existing, $new) {
|
|||
return $mismatch
|
||||
}
|
||||
|
||||
Function Get-DiffValueString($type, $value) {
|
||||
$enum = [Microsoft.Win32.RegistryValueKind]
|
||||
if ($type -in @($enum::Binary, $enum::None)) {
|
||||
$hex_values = @()
|
||||
foreach ($dec_value in $value) {
|
||||
$hex_values += "0x$("{0:x2}" -f $dec_value)"
|
||||
}
|
||||
$diff_value = "$($type):[$($hex_values -join ", ")]"
|
||||
} elseif ($type -eq $enum::DWord) {
|
||||
$diff_value = "$($type):0x$("{0:x8}" -f $value)"
|
||||
} elseif ($type -eq $enum::QWord) {
|
||||
$diff_value = "$($type):0x$("{0:x16}" -f $value)"
|
||||
} elseif ($type -eq $enum::MultiString) {
|
||||
$diff_value = "$($type):[$($value -join ", ")]"
|
||||
} else {
|
||||
$diff_value = "$($type):$value"
|
||||
}
|
||||
|
||||
return $diff_value
|
||||
}
|
||||
|
||||
# convert property names "" to $null as "" refers to (Default)
|
||||
if ($name -eq "") {
|
||||
$name = $null
|
||||
|
@ -268,10 +289,16 @@ if ($state -eq "present") {
|
|||
$result.changed = $true
|
||||
|
||||
if ($diff_mode) {
|
||||
$result.diff.prepared += @"
|
||||
[$path]
|
||||
-"$name" = "$existing_type`:$existing_data"
|
||||
+"$name" = "$type`:$data"
|
||||
if ($result.diff.prepared) {
|
||||
$key_prefix = "+"
|
||||
} else {
|
||||
$key_prefix = ""
|
||||
}
|
||||
|
||||
$result.diff.prepared = @"
|
||||
$key_prefix[$path]
|
||||
-"$name" = "$(Get-DiffValueString -type $existing_type -value $existing_data)"
|
||||
+"$name" = "$(Get-DiffValueString -type $type -value $data)"
|
||||
"@
|
||||
}
|
||||
}
|
||||
|
@ -286,9 +313,15 @@ if ($state -eq "present") {
|
|||
}
|
||||
$result.changed = $true
|
||||
if ($diff_mode) {
|
||||
$result.diff.prepared += @"
|
||||
[$path]
|
||||
+"$name" = "$type`:$data"
|
||||
if ($result.diff.prepared) {
|
||||
$key_prefix = "+"
|
||||
} else {
|
||||
$key_prefix = ""
|
||||
}
|
||||
|
||||
$result.diff.prepared = @"
|
||||
$key_prefix[$path]
|
||||
+"$name" = "$(Get-DiffValueString -type $type -value $data)"
|
||||
"@
|
||||
}
|
||||
}
|
||||
|
@ -328,7 +361,7 @@ if ($state -eq "present") {
|
|||
if ($diff_mode) {
|
||||
$result.diff.prepared += @"
|
||||
[$path]
|
||||
-"$name" = "$existing_type`:$existing_data"
|
||||
-"$name" = "$(Get-DiffValueString -type $existing_type -value $existing_data)"
|
||||
"@
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue