From c230847cc0832d86132fb40a6ea5c1e75e6ab812 Mon Sep 17 00:00:00 2001 From: Julian Freeman Date: Sat, 4 Apr 2026 15:54:40 -0400 Subject: [PATCH] support del reg --- scripts/convert-reg.ps1 | 19 +++++++++++++------ src-tauri/src/lib.rs | 5 ++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/scripts/convert-reg.ps1 b/scripts/convert-reg.ps1 index 1d0bc7e..7120923 100644 --- a/scripts/convert-reg.ps1 +++ b/scripts/convert-reg.ps1 @@ -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) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index ce604ca..95806c6 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -230,10 +230,13 @@ async fn execute_post_install(handle: &AppHandle, log_id: &str, steps: Vec { 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"); } } },