Skip to content

Commit a832c2a

Browse files
committed
fix(tweaks): replace 3 broken implementations with real code
DiskCleanup: cleanup-reduce-recycle-bin-size had a broken PS script (embedded comment broke execution, wrong NukeOnDelete approach). Replaced with WMI Win32_Volume iteration that sets MaxCapacity per drive to 5% (ApplyAction) or 10% (RemoveAction), with real DetectAction. UserAccount: uac-enforce-password-complexity ApplyAction was applying Windows default security template (entire policy reset) instead of only setting PasswordComplexity=1. DetectAction read stdout from secedit /export instead of the output file. RemoveAction was a no-op. Fixed to write a minimal INF via PowerShell and call secedit for both apply and remove; DetectAction now reads and deletes the exported file. SsdOptimization: ssd-enable-write-caching ApplyAction called Set-StorageSetting -NewDiskPolicy OnlineAll (storage subsystem policy, not disk write caching). Replaced with Get-PhysicalDisk | Set-PhysicalDisk -WriteCacheEnabled for proper per-disk write cache toggle, with matching RemoveAction and DetectAction. Total: 7,349 tweaks, 122 categories, 3,230 tests (0 failures)
1 parent a4a0fb5 commit a832c2a

3 files changed

Lines changed: 84 additions & 16 deletions

File tree

src/RegiLattice.Core/Tweaks/DiskCleanup.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,40 @@ internal static class DiskCleanup
272272
Tags = ["cleanup", "disk", "recycle-bin"],
273273
ApplyAction = _ =>
274274
ShellRunner.RunPowerShell(
275-
"$shell = New-Object -ComObject Shell.Application; "
276-
+ "$rb = $shell.Namespace(10); "
277-
+ "# Note: Recycle Bin size is stored per-drive in the registry "
278-
+ "Set-ItemProperty 'HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\BitBucket\\Volume' -Name 'NukeOnDelete' -Value 0 -ErrorAction SilentlyContinue"
275+
"Get-WmiObject Win32_Volume -Filter \"DriveType=3\" -ErrorAction SilentlyContinue "
276+
+ "| Where-Object DriveLetter "
277+
+ "| ForEach-Object { "
278+
+ "$id = $_.DeviceID.TrimEnd('\\').Split('{')[1].TrimEnd('}').ToUpper(); "
279+
+ "$mb = [math]::Round($_.Capacity / 1048576 * 0.05); "
280+
+ "$p = \"HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\BitBucket\\Volume\\$id\"; "
281+
+ "if (!(Test-Path $p)) { New-Item $p -Force | Out-Null }; "
282+
+ "Set-ItemProperty $p -Name MaxCapacity -Value $mb -ErrorAction SilentlyContinue }"
279283
),
280-
RemoveAction = _ => { },
281-
DetectAction = () => false,
284+
RemoveAction = _ =>
285+
ShellRunner.RunPowerShell(
286+
"Get-WmiObject Win32_Volume -Filter \"DriveType=3\" -ErrorAction SilentlyContinue "
287+
+ "| Where-Object DriveLetter "
288+
+ "| ForEach-Object { "
289+
+ "$id = $_.DeviceID.TrimEnd('\\').Split('{')[1].TrimEnd('}').ToUpper(); "
290+
+ "$mb = [math]::Round($_.Capacity / 1048576 * 0.10); "
291+
+ "$p = \"HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\BitBucket\\Volume\\$id\"; "
292+
+ "if (!(Test-Path $p)) { New-Item $p -Force | Out-Null }; "
293+
+ "Set-ItemProperty $p -Name MaxCapacity -Value $mb -ErrorAction SilentlyContinue }"
294+
),
295+
DetectAction = () =>
296+
{
297+
var (_, stdout, _) = ShellRunner.RunPowerShell(
298+
"$v = Get-WmiObject Win32_Volume -Filter \"DriveType=3\" -ErrorAction SilentlyContinue "
299+
+ "| Where-Object DriveLetter | Select-Object -First 1; "
300+
+ "if (!$v) { $false; return }; "
301+
+ "$id = $v.DeviceID.TrimEnd('\\').Split('{')[1].TrimEnd('}').ToUpper(); "
302+
+ "$fivePct = [math]::Round($v.Capacity / 1048576 * 0.05); "
303+
+ "$p = \"HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\BitBucket\\Volume\\$id\"; "
304+
+ "$cur = (Get-ItemProperty -Path $p -Name MaxCapacity -ErrorAction SilentlyContinue)?.MaxCapacity; "
305+
+ "(($cur -ne $null) -and ($cur -le [math]::Round($fivePct * 1.1)))"
306+
);
307+
return stdout.Trim().Equals("True", StringComparison.OrdinalIgnoreCase);
308+
},
282309
},
283310
// ── Sprint 41 additions ────────────────────────────────────────────
284311

src/RegiLattice.Core/Tweaks/SsdOptimization.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,26 @@ internal static class SsdOptimization
8585
SideEffects = "Risk of data loss on sudden power failure without UPS.",
8686
ApplyAction = _ =>
8787
ShellRunner.RunPowerShell(
88-
"Get-Disk | Where-Object { $_.BusType -ne 'USB' } | ForEach-Object { "
89-
+ "Set-StorageSetting -NewDiskPolicy OnlineAll -ErrorAction SilentlyContinue }"
88+
"Get-PhysicalDisk | Where-Object { $_.BusType -ne 'USB' } "
89+
+ "| ForEach-Object { "
90+
+ "try { Set-PhysicalDisk -UniqueId $_.UniqueId -WriteCacheEnabled $true -ErrorAction Stop } "
91+
+ "catch { } }"
9092
),
91-
RemoveAction = _ => { },
92-
DetectAction = () => false,
93+
RemoveAction = _ =>
94+
ShellRunner.RunPowerShell(
95+
"Get-PhysicalDisk | Where-Object { $_.BusType -ne 'USB' } "
96+
+ "| ForEach-Object { "
97+
+ "try { Set-PhysicalDisk -UniqueId $_.UniqueId -WriteCacheEnabled $false -ErrorAction Stop } "
98+
+ "catch { } }"
99+
),
100+
DetectAction = () =>
101+
{
102+
var (_, stdout, _) = ShellRunner.RunPowerShell(
103+
"$d = Get-PhysicalDisk | Where-Object { $_.BusType -ne 'USB' } | Select-Object -First 1; "
104+
+ "if (!$d) { $false } else { $d.WriteCacheEnabled -eq $true }"
105+
);
106+
return stdout.Trim().Equals("True", StringComparison.OrdinalIgnoreCase);
107+
},
93108
},
94109
new TweakDef
95110
{

src/RegiLattice.Core/Tweaks/UserAccount.cs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,42 @@ internal static class UserAccount
211211
ApplyAction = dryRun =>
212212
{
213213
if (!dryRun)
214-
ShellRunner.Run(
215-
"secedit",
216-
["/configure", "/db", "secedit.sdb", "/cfg", "%windir%\\inf\\defltbase.inf", "/areas", "SECURITYPOLICY", "/quiet"]
214+
ShellRunner.RunPowerShell(
215+
"$nl = [System.Environment]::NewLine; "
216+
+ "$inf = \"[Unicode]${nl}Unicode=yes${nl}[System Access]${nl}PasswordComplexity = 1${nl}\"; "
217+
+ "$path = \"$env:TEMP\\rl_pwcomplex_on.inf\"; "
218+
+ "[System.IO.File]::WriteAllText($path, $inf, [System.Text.Encoding]::Unicode); "
219+
+ "secedit /configure /db \"$env:TEMP\\secpol.sdb\" /cfg $path /areas SECURITYPOLICY /quiet; "
220+
+ "Remove-Item $path -ErrorAction SilentlyContinue"
221+
);
222+
},
223+
RemoveAction = dryRun =>
224+
{
225+
if (!dryRun)
226+
ShellRunner.RunPowerShell(
227+
"$nl = [System.Environment]::NewLine; "
228+
+ "$inf = \"[Unicode]${nl}Unicode=yes${nl}[System Access]${nl}PasswordComplexity = 0${nl}\"; "
229+
+ "$path = \"$env:TEMP\\rl_pwcomplex_off.inf\"; "
230+
+ "[System.IO.File]::WriteAllText($path, $inf, [System.Text.Encoding]::Unicode); "
231+
+ "secedit /configure /db \"$env:TEMP\\secpol.sdb\" /cfg $path /areas SECURITYPOLICY /quiet; "
232+
+ "Remove-Item $path -ErrorAction SilentlyContinue"
217233
);
218234
},
219-
RemoveAction = _ => { },
220235
DetectAction = () =>
221236
{
222-
var (_, stdout, _) = ShellRunner.Run("secedit", ["/export", "/cfg", "%temp%\\rl_secedit.cfg", "/quiet"]);
223-
return stdout.Contains("PasswordComplexity = 1", StringComparison.OrdinalIgnoreCase);
237+
var cfgPath = Path.Combine(Path.GetTempPath(), "rl_secedit_export.cfg");
238+
ShellRunner.Run("secedit", ["/export", "/cfg", cfgPath, "/quiet"]);
239+
if (!File.Exists(cfgPath))
240+
return false;
241+
try
242+
{
243+
var content = File.ReadAllText(cfgPath, System.Text.Encoding.Unicode);
244+
return content.Contains("PasswordComplexity = 1", StringComparison.OrdinalIgnoreCase);
245+
}
246+
finally
247+
{
248+
File.Delete(cfgPath);
249+
}
224250
},
225251
},
226252
new TweakDef

0 commit comments

Comments
 (0)