support del reg
This commit is contained in:
@@ -38,7 +38,10 @@ foreach ($line in $lines) {
|
||||
|
||||
# 匹配 [HKEY_...] 路径
|
||||
if ($line.StartsWith("[") -and $line.EndsWith("]")) {
|
||||
$fullPath = $line.Substring(1, $line.Length - 2)
|
||||
# 检查是否是删除整个 Key 的语法:[-HKEY_...]
|
||||
$isDeleteKey = $line.StartsWith("[-")
|
||||
$fullPath = if ($isDeleteKey) { $line.Substring(2, $line.Length - 3) } else { $line.Substring(1, $line.Length - 2) }
|
||||
|
||||
$root = ""
|
||||
$basePath = ""
|
||||
|
||||
@@ -51,11 +54,12 @@ foreach ($line in $lines) {
|
||||
}
|
||||
|
||||
if ($root -ne "") {
|
||||
# 使用 [ordered] 确保 JSON 键位顺序
|
||||
$currentBatch = [ordered]@{
|
||||
type = "registry_batch"
|
||||
root = $root
|
||||
base_path = $basePath
|
||||
# 如果是删除整个 Key,我们可以在这里记录或者扩展 schema
|
||||
# 但目前我们先处理 Value 删除
|
||||
values = [ordered]@{}
|
||||
}
|
||||
$results += $currentBatch
|
||||
@@ -67,10 +71,14 @@ foreach ($line in $lines) {
|
||||
if ($line -match '^"(.+)"\s*=\s*(.+)$') {
|
||||
$name = $Matches[1]
|
||||
$rawVal = $Matches[2]
|
||||
$vType = "String"
|
||||
$vType = ""
|
||||
$data = $null
|
||||
|
||||
if ($rawVal.StartsWith("dword:")) {
|
||||
if ($rawVal -eq "-") {
|
||||
# 处理删除 Value 的逻辑: "Key"=-
|
||||
$vType = "Delete"
|
||||
$data = $null
|
||||
} elseif ($rawVal.StartsWith("dword:")) {
|
||||
$vType = "Dword"
|
||||
$hex = $rawVal.Substring(6)
|
||||
$data = [Convert]::ToInt32($hex, 16)
|
||||
@@ -91,7 +99,7 @@ foreach ($line in $lines) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($null -ne $currentBatch -and $null -ne $data) {
|
||||
if ($null -ne $currentBatch -and $vType -ne "") {
|
||||
$currentBatch.values[$name] = [ordered]@{
|
||||
v_type = $vType
|
||||
data = $data
|
||||
@@ -104,7 +112,6 @@ if ($results.Count -eq 0) {
|
||||
Write-Warning "未在文件中识别到有效的注册表项。"
|
||||
}
|
||||
|
||||
# 转换为格式化的 JSON
|
||||
$jsonOutput = ConvertTo-Json $results -Depth 10
|
||||
[System.IO.File]::WriteAllText($OutputPath, $jsonOutput, [System.Text.Encoding]::UTF8)
|
||||
|
||||
|
||||
@@ -230,10 +230,13 @@ async fn execute_post_install(handle: &AppHandle, log_id: &str, steps: Vec<PostI
|
||||
"ExpandString" => {
|
||||
key.set_value(&name, &val.data.as_str().unwrap_or_default())
|
||||
},
|
||||
"Delete" => {
|
||||
key.delete_value(&name)
|
||||
},
|
||||
_ => Err(std::io::Error::new(std::io::ErrorKind::Other, "Unsupported type")),
|
||||
};
|
||||
if let Err(e) = res {
|
||||
emit_log(handle, log_id, "Registry Error", &format!("Failed to set {}: {}", name, e), "error");
|
||||
emit_log(handle, log_id, "Registry Error", &format!("Failed to apply {}: {}", name, e), "error");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user