winutil icon indicating copy to clipboard operation
winutil copied to clipboard

add undoscript feature + implement it on every tweaks

Open padsalatushal opened this issue 2 years ago • 11 comments

added undoscript feature

padsalatushal avatar May 19 '23 12:05 padsalatushal

.

padsalatushal avatar May 19 '23 12:05 padsalatushal

We would want to update every tweak with an InvokeScript to have an undo script as well. Otherwise we will start seeing error messages.

Also I would try and do something like this instead of putting the undo tweaks inside the beginning section

    if($undo){
        $Values = @{
            Registry = "OriginalValue"
            ScheduledTask = "OriginalState"
            Service = "OriginalType"
            script = "UndoScript"
        }
    }    
    Else{
        $Values = @{
            Registry = "Value"
            ScheduledTask = "State"
            Service = "StartupType"
            script = "InvokeScript"
        }
    }

        if($sync.configs.tweaks.$CheckBox.$script){
            $sync.configs.tweaks.$CheckBox.UndoScript | ForEach-Object {
                $Scriptblock = [scriptblock]::Create($psitem)
                Invoke-WinUtilScript -ScriptBlock $scriptblock -Name $CheckBox
            }
        }

DeveloperDurp avatar May 19 '23 13:05 DeveloperDurp

@DeveloperDurp list of tweaks that have an InvokeScript. I will add undo script for these tweaks.

  • [ ] WPFEssTweaksTele
  • [x] WPFMiscTweaksDisplay
  • [ ] WPFEssTweaksDeBloat
  • [x] WPFEssTweaksStorage
  • [x] WPFEssTweaksRemoveEdge
  • [x] WPFMiscTweaksRightClickMenu
  • [x] WPFEssTweaksRemoveCortana

padsalatushal avatar May 19 '23 13:05 padsalatushal

@ChrisTitusTech this pr is good to merge. WPFEssTweaksTele and WPFEssTweaksDeBloat are both remaining for undo script I will make another pr for that after doing some testing.

padsalatushal avatar May 27 '23 13:05 padsalatushal

Can you cleanup Invoke-WinUtilTweaks.ps1it still has the 2 if statements for InvokeScript and UndoScript and is in the wrong spot in the script.

DeveloperDurp avatar May 27 '23 13:05 DeveloperDurp

Felt this is relevant, undo does not work for the "run OOShutup" option. Search breaks for local installations with winutil.

The interesting part is OOShutup breaking search is inconsistent. I've done a few tests on clean windows 10 installs and most of the time it breaks. Sometimes it does not.

See #569

dreamsyntax avatar May 27 '23 14:05 dreamsyntax

Can you cleanup Invoke-WinUtilTweaks.ps1it still has the 2 if statements for InvokeScript and UndoScript and is in the wrong spot in the script.

can you explain how to implement that? because I tested previous code you share and it didn't work

for each tweak, we have to use like this?

  "WPFMiscTweaksRightClickMenu": {
    "Script": [
      "InvokeScript" : "New-Item -Path \"HKCU:\\Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\" -Name \"InprocServer32\" -force -value \"\" "  
      "UndoScript" : "
      Remove-Item -Path \"HKCU:\\Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\" -Recurse -Confirm:$false -Force
      Write-Host Restart Needed for change
      "
    ] 

padsalatushal avatar May 27 '23 15:05 padsalatushal

Try

function Invoke-WinUtilTweaks {
    <#
    
        .DESCRIPTION
        This function converts all the values from the tweaks.json and routes them to the appropriate function
    
    #>

    param(
        $CheckBox,
        $undo = $false
    )
    if($undo){
        $Values = @{
            Registry = "OriginalValue"
            ScheduledTask = "OriginalState"
            Service = "OriginalType"
            ScriptType = "UndoScript"
        }

    }    
    Else{
        $Values = @{
            Registry = "Value"
            ScheduledTask = "State"
            Service = "StartupType"
            ScriptType = "InvokeScript"
        }
    }
    if($sync.configs.tweaks.$CheckBox.ScheduledTask){
        $sync.configs.tweaks.$CheckBox.ScheduledTask | ForEach-Object {
            Set-WinUtilScheduledTask -Name $psitem.Name -State $psitem.$($values.ScheduledTask)
        }
    }
    if($sync.configs.tweaks.$CheckBox.service){
        $sync.configs.tweaks.$CheckBox.service | ForEach-Object {
            Set-WinUtilService -Name $psitem.Name -StartupType $psitem.$($values.Service)
        }
    }
    if($sync.configs.tweaks.$CheckBox.registry){
        $sync.configs.tweaks.$CheckBox.registry | ForEach-Object {
            Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry)
        }
    }
    if($sync.configs.tweaks.$CheckBox.$($values.ScriptType)){
        $sync.configs.tweaks.$CheckBox.$($values.ScriptType) | ForEach-Object {
            $Scriptblock = [scriptblock]::Create($psitem)
            Invoke-WinUtilScript -ScriptBlock $scriptblock -Name $CheckBox
        }
    }

    if(!$undo){
        if($sync.configs.tweaks.$CheckBox.appx){
            $sync.configs.tweaks.$CheckBox.appx | ForEach-Object {
                Remove-WinUtilAPPX -Name $psitem
            }
        }

    }
}

Edit: had undoscript in the wrong section

DeveloperDurp avatar May 27 '23 16:05 DeveloperDurp

image for me it still not work give lots of error like this

padsalatushal avatar May 27 '23 16:05 padsalatushal

That means one of your config files is broken

DeveloperDurp avatar May 27 '23 16:05 DeveloperDurp

yeah now it works understood the implementation awesome work @DeveloperDurp . Thanks for helping.

padsalatushal avatar May 27 '23 16:05 padsalatushal

@ChrisTitusTech good to merge.

padsalatushal avatar May 31 '23 02:05 padsalatushal

Awesome, Thanks for all the hard work @padsalatushal

ChrisTitusTech avatar May 31 '23 03:05 ChrisTitusTech