NN.WindowsSetup.psm1

#Region './Private/Add-Cursor.ps1' 0
function Add-Cursor {
    [bool]$runAsAdmin = ([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544"
    if ($runAsAdmin) {
        if (!(Test-Path -Path "$env:SystemRoot\cursors\")) {
            New-Item -Path "$env:SystemRoot\cursors" -ItemType "directory"
        }
        
        Invoke-WebRequest -Uri "http://dl.dropbox.com/s/20hr9j0dkyumrj1/material_design_dark.zip?dl=0" -OutFile "$env:TEMP\material_design_dark.zip"
        Expand-Archive -Force -Path "$env:TEMP\material_design_dark.zip" -DestinationPath "$env:SystemRoot\cursors\"
    } else {
        throw "Function needs to run with administrator privledges."
    }
}
#EndRegion './Private/Add-Cursor.ps1' 14
#Region './Private/Invoke-gsudoCheck.ps1' 0
function Invoke-gsudoCheck {
    try {
        $null = gsudo --version
    }
    catch [System.Management.Automation.CommandNotFoundException] {
        throw "Please run `"Install-gsudo`" before running this command."
    }
}
#EndRegion './Private/Invoke-gsudoCheck.ps1' 9
#Region './Public/Enable-ClipboardHistory.ps1' 0
function Enable-ClipboardHistory {
    if (!(Test-Path -Path "HKCU:\Software\Microsoft\Clipboard")) {
        New-Item -Force -Path "HKCU:\Software\Microsoft\Clipboard"
    }
    New-ItemProperty -Force -Path "HKCU:\Software\Microsoft\Clipboard" -Name "EnableClipboardHistory" -PropertyType "dword" -Value "1"
}
#EndRegion './Public/Enable-ClipboardHistory.ps1' 7
#Region './Public/Enable-gsudoCache.ps1' 0
function Enable-gsudoCache {
    gsudo config CacheMode Auto
}
#EndRegion './Public/Enable-gsudoCache.ps1' 4
#Region './Public/Export-CodeExtensionList.ps1' 0
function Export-CodeExtensionList {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)][string]$Path
    )

    begin {
        try {
            $null = code --version
        }
        catch [System.Management.Automation.CommandNotFoundException] {
            Write-Error "Can't find a VSCode install on this computer." -ErrorAction Stop
        }
    }
    
    process {
        code --list-extensions | Out-File -FilePath $Path
    }
}
#EndRegion './Public/Export-CodeExtensionList.ps1' 20
#Region './Public/Install-Choco.ps1' 0
function Install-Choco {
    try {
        $null = choco --version
    }
    catch [System.Management.Automation.CommandNotFoundException] {
        Invoke-gsudoCheck
        Invoke-gsudo {
            Set-ExecutionPolicy Bypass -Scope Process -Force
            [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
            Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
            Write-Warning "You'll need to restart all terminal applications before using choco."
        }
    }
}
#EndRegion './Public/Install-Choco.ps1' 15
#Region './Public/Install-CodeExtensions.ps1' 0
function Install-CodeExtensions {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)][string]$ExtensionListPath
    )

    begin {
        try {
            $null = code --version
        }
        catch [System.Management.Automation.CommandNotFoundException] {
            Write-Error "Please run `"Install-VSCode`" before running this command." -ErrorAction Stop
        }
    }
    
    process {
        $CodeExtensions = Get-Content -Path $ExtensionListPath
        $CodeExtensions.ForEach({
            code --install-extension $_
        })
    }
}
#EndRegion './Public/Install-CodeExtensions.ps1' 23
#Region './Public/Install-Cursor.ps1' 0
function Install-Cursor {
    Invoke-gsudoCheck
    Invoke-gsudo {
        Add-Cursor
    }

    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(Default)" -Value "material_design_dark"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "AppStarting" -Value "%SystemRoot%\cursors\material_design_dark\work.ani"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Arrow" -Value "%SystemRoot%\cursors\material_design_dark\pointer.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Crosshair" -Value "%SystemRoot%\cursors\material_design_dark\cross.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Hand" -Value "%SystemRoot%\cursors\material_design_dark\link.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Help" -Value "%SystemRoot%\cursors\material_design_dark\help.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "IBeam" -Value "%SystemRoot%\cursors\material_design_dark\text.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "No" -Value "%SystemRoot%\cursors\material_design_dark\unavailiable.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "NWPen" -Value "%SystemRoot%\cursors\material_design_dark\handwriting.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Person" -Value "%SystemRoot%\cursors\material_design_dark\account.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Pin" -Value "%SystemRoot%\cursors\material_design_dark\place.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "SizeAll" -Value "%SystemRoot%\cursors\material_design_dark\move.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "SizeNESW" -Value "%SystemRoot%\cursors\material_design_dark\dgn2.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "SizeNS" -Value "%SystemRoot%\cursors\material_design_dark\vert.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "SizeNWSE" -Value "%SystemRoot%\cursors\material_design_dark\dgn1.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "SizeWE" -Value "%SystemRoot%\cursors\material_design_dark\horz.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "UpArrow" -Value "%SystemRoot%\cursors\material_design_dark\alternate.cur"
    Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Wait" -Value "%SystemRoot%\cursors\material_design_dark\busy.ani"

    if (!(Test-Path "HKCU:\Control Panel\Cursors\Schemes")) {
        New-Item -Force -Path "HKCU:\Control Panel\Cursors\Schemes"
    }
    $null = New-ItemProperty -Force -Path "HKCU:\Control Panel\Cursors\Schemes" -Name "material_design_dark" -PropertyType "String" -Value "C:\Windows\Cursors\material_design_dark\pointer.cur,C:\Windows\Cursors\material_design_dark\help.cur,C:\Windows\Cursors\material_design_dark\work.ani,C:\Windows\Cursors\material_design_dark\busy.ani,C:\Windows\Cursors\material_design_dark\cross.cur,C:\Windows\Cursors\material_design_dark\text.cur,C:\Windows\Cursors\material_design_dark\handwriting.cur,C:\Windows\Cursors\material_design_dark\unavailiable.cur,C:\Windows\Cursors\material_design_dark\vert.cur,C:\Windows\Cursors\material_design_dark\horz.cur,C:\Windows\Cursors\material_design_dark\dgn1.cur,C:\Windows\Cursors\material_design_dark\dgn2.cur,C:\Windows\Cursors\material_design_dark\move.cur,C:\Windows\Cursors\material_design_dark\alternate.cur,C:\Windows\Cursors\material_design_dark\link.cur,C:\Windows\Cursors\material_design_dark\place.cur,C:\Windows\Cursors\material_design_dark\account.cur"
    
    rundll32.exe shell32.dll,Control_RunDLL main.cpl "@0,1" #Open mouse pointer window
}
#EndRegion './Public/Install-Cursor.ps1' 33
#Region './Public/Install-gsudo.ps1' 0
function Install-gsudo {
    try {
        $null = gsudo --version
    }
    catch [System.Management.Automation.CommandNotFoundException] {
        Set-ExecutionPolicy RemoteSigned -scope CurrentUser -Force
        [Net.ServicePointManager]::SecurityProtocol = 'Tls12'
        Invoke-WebRequest -useb https://raw.githubusercontent.com/gerardog/gsudo/master/installgsudo.ps1 | Invoke-Expression
        Write-Warning "You'll need to restart all terminal applications before using gsudo."
    }
}
#EndRegion './Public/Install-gsudo.ps1' 12
#Region './Public/Install-Powercord.ps1' 0
<#
    Prerequisites:
    * Node.js
    * Discord Canary
#>

function Install-Powercord {
    #Install powercord
    Set-Location $env:USERPROFILE
    git clone https://github.com/powercord-org/powercord
    Set-Location .\powercord
    npm i
    npm run plug

    #Download plugins
    Set-Location "$env:USERPROFILE\powercord\src\Powercord\plugins"
    $allplugins = @(
        "https://github.com/notsapinho/powercord-together",
        "https://github.com/Twizzer/relationship-notifier",
        "https://github.com/griefmodz/scrollable-autocomplete",
        "https://github.com/griefmodz/smart-typers",
        "https://github.com/RazerMoon/muteNewGuild",
        "https://github.com/RazerMoon/vcTimer",
        "https://github.com/PandaDriver156/Custom-Volume-Range",
        "https://github.com/redstonekasi/theme-toggler",
        "https://github.com/12944qwerty/report-messages",
        "https://github.com/E-boi/ShowConnections",
        "https://github.com/VenPlugs/PersistFavourites",
        "https://github.com/Juby210/show-all-activities",
        "https://github.com/Juby210/unread-count-badges",
        "https://github.com/Juby210/user-details",
        "https://github.com/A-Trash-Coder/Quick-Channel-Mute",
        "https://github.com/21Joakim/copy-avatar-url",
        "https://github.com/BluSpring/Spotify-No-Pause",
        "https://github.com/jaimeadf/who-reacted",
        "https://github.com/powerfart-plugins/image-tools",
        "https://github.com/Killerjet101/open-in-app.git"
    )

    foreach ($plugin in $allplugins) {
        git clone $plugin
    }

    #Download themes
    Set-Location "$env:USERPROFILE\powercord\src\Powercord\themes"
    $allthemes = @(
        "https://github.com/CorellanStoma/Menu-Icons",
        "https://github.com/Discord-Theme-Addons/refined-user-connections",
        "https://github.com/NYRI4/Discolored",
        "https://github.com/Goku-04/minimal-theme",
        "https://github.com/Discord-Theme-Addons/gradientbuttons-v2",
        "https://github.com/mr-miner1/Better-Badges"
    )

    foreach ($theme in $allthemes) {
        git clone $theme
    }

    Get-Process | Where-Object Name -like "*discord*" | Stop-Process -Force
    Start-Process "$env:LOCALAPPDATA\DiscordCanary\Update.exe" -PassThru "--processStart DiscordCanary.exe"
}
#EndRegion './Public/Install-Powercord.ps1' 61
#Region './Public/Install-RSAT.ps1' 0
function Install-RSAT {
    [CmdletBinding()]
    param (
        [switch]$WUServerBypass
    )

    begin {
        Invoke-gsudoCheck
    }

    process {
        try {
            $null = Get-ADUser -Filter "Name -eq 0"
        }
        catch [System.Management.Automation.CommandNotFoundException] {
            try {
                Invoke-gsudo {
                    Import-Module NN.WindowsSetup
        
                    if ($using:WUServerBypass) {
                        Invoke-WUServerBypass
                    }
                
                    $RSATNames = (Get-WindowsCapability -Name RSAT* -online | Where-Object State -NotLike 'Installed').Name 
                    
                    foreach ($item in $RSATNames) {
                        Get-WindowsCapability -Name $item -Online | Add-WindowsCapability -Online
                    }
                }
            }
            catch [System.Management.Automation.CommandNotFoundException] {
                throw "Please run `"Install-gsudo`" before running this command."
            }
        }
    }
}
#EndRegion './Public/Install-RSAT.ps1' 37
#Region './Public/Install-VSCode.ps1' 0
function Install-VSCode {
    Install-Choco
    choco install -y vscode
    
    Write-Warning "Terminal requires a restart before using the `"code`" command."
}
#todo: check if restart is required
#EndRegion './Public/Install-VSCode.ps1' 8
#Region './Public/Install-WebRDP.ps1' 0
function Install-WebRDP {
    if (!(Test-Path HKCR:)) {
        New-PSDrive -PSProvider "registry" -Root "HKEY_CLASSES_ROOT" -Name "HKCR"
    }
    if (!(Test-Path HKCR:\rdp\DefaultIcon)) {
        New-Item -Force -Path "HKCR:\rdp\DefaultIcon"
    }
    if (!(Test-Path HKCR:\rdp\shell\open\command)) {
        New-Item -Force -Path "HKCR:\rdp\shell\open\command"
    }
    New-ItemProperty -Force -Path "HKCR:\rdp" -PropertyType "String" -Name "(Default)" -Value "URL:Remote Desktop Connection"
    New-ItemProperty -Force -Path "HKCR:\rdp" -PropertyType "String" -Name "URL Protocol"
    New-ItemProperty -Force -Path "HKCR:\rdp\DefaultIcon" -PropertyType "String" -Name "(Default)" -Value "C:\WINDOWS\System32\mstsc.exe"
    New-ItemProperty -Force -Path "HKCR:\rdp\shell\open\command" -PropertyType "String" -Name "(Default)" -Value "powershell.exe $('$URL') = '%1%'; $('$SERVER') = $('$url').replace('rdp://',''); $('$SERVER') = $('$SERVER').replace('/',''); mstsc.exe /v $('$SERVER')"
}
#EndRegion './Public/Install-WebRDP.ps1' 16
#Region './Public/Install-WinReg.ps1' 0
function Install-WinReg {
    Set-ItemProperty -Path "HKCU:\Control Panel\Accessibility\StickyKeys" -Type "String" -Name "Flags" -Value "506" #Disable hotkey for StickyKeys
    Set-ItemProperty -Path "HKCU:\Control Panel\Accessibility\ToggleKeys" -Type "String" -Name "Flags" -Value "59" #Enable ToggleKeys tone
    Set-ItemProperty -Path "HKCU:\Keyboard Layout\Toggle" -Type "String" -Name "Hotkey" -Value "3" #Disable keyboard language switching hotkey
    Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\OperationStatusManager" -Type "dword" -Name "EnthusiastMode" -Value "1" #Show more details in file transfer dialog
}
#EndRegion './Public/Install-WinReg.ps1' 7
#Region './Public/Invoke-JpegExtensionFix.ps1' 0
function Invoke-JpegExtensionFix {
    [CmdletBinding()]
    param ()
    process {
        $null = New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR
        $jpegExtension = (Get-ItemProperty "HKCR:\MIME\Database\Content Type\image/jpeg" -Name Extension).Extension

        if ($jpegExtension -notlike ".jpg") {
            $null = New-ItemProperty -Path "HKCR:\MIME\Database\Content Type\image/jpeg" -Name "Extension" -PropertyType "String" -Value ".jpg" -Force
            Write-Information "Jpeg extension has been changed from `"$jpegExtension`" to `".jpg`""
        } else {
            Write-Information "Jpeg extension is already set to `"$jpegExtension`""
        }
    }
}
#EndRegion './Public/Invoke-JpegExtensionFix.ps1' 16
#Region './Public/Invoke-WUServerBypass.ps1' 0
function Invoke-WUServerBypass {
    #Enable WU
    if (!(Test-Path -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU")) {
        New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Force
    }

    Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -name "DisableDualScan" -value 0
    Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -name "DisableWindowsUpdateAccess" -value 0
    Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -name "SetPolicyDrivenUpdateSourceForDriverUpdates" -value 0
    Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -name "SetPolicyDrivenUpdateSourceForFeatureUpdates" -value 0
    Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -name "SetPolicyDrivenUpdateSourceForOtherUpdates" -value 0
    Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -name "SetPolicyDrivenUpdateSourceForQualityUpdates" -value 0
    Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -name "UseWUServer" -value 0
    Restart-Service wuauserv
}
#EndRegion './Public/Invoke-WUServerBypass.ps1' 16
#Region './Public/Remove-Edge.ps1' 0
function Remove-Edge {
    Start-Process -FilePath "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\**\Installer\setup.exe" -Args "--uninstall --system-level --force-uninstall"
    New-Item -Path "HKLM:\SOFTWARE\Microsoft\EdgeUpdate" -Force
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\EdgeUpdate" -Name "DoNotUpdateToEdgeWithChromium" -Type dword -Value 1
}
#EndRegion './Public/Remove-Edge.ps1' 6
#Region './Public/Remove-XboxGameBar.ps1' 0
function Remove-XboxGameBar {
    #Remove game bar
    Import-Module Appx -UseWindowsPowershell
    Get-AppxPackage -AllUsers *Microsoft.XboxGameOverlay* | Remove-AppxPackage
    Get-AppxPackage -AllUsers *Microsoft.XboxGamingOverlay* | Remove-AppxPackage
    Get-AppxPackage *Microsoft.XboxSpeechToTextOverlay* | Remove-AppxPackage
    New-Item -Path "HKLM:\Software\Policies\Microsoft\Windows\GameDVR"
    New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\GameDVR" -Name AllowGameDVR -Type dword -Value 0
}
#EndRegion './Public/Remove-XboxGameBar.ps1' 10
#Region './Public/Set-DefaultBrowser.ps1' 0
function Set-DefaultBrowser {
    #Set Chrome as default browser
    Invoke-WebRequest -Uri https://kolbi.cz/SetDefaultBrowser.zip -OutFile $env:TEMP\SetDefaultBrowser.zip
    Expand-Archive -LiteralPath $env:TEMP\SetDefaultBrowser.zip -DestinationPath $env:TEMP
    Start-Process $env:TEMP\SetDefaultBrowser\SetDefaultBrowser.exe chrome
    Remove-Item $env:TEMP\SetDefaultBrowser.zip
    Remove-Item -Recurse $env:TEMP\SetDefaultBrowser
}
#EndRegion './Public/Set-DefaultBrowser.ps1' 9
#Region './Public/Set-OldRightClickMenu.ps1' 0
function Set-OldRightClickMenu {
    [CmdletBinding()]
    param (
        
    )

    process {
        $RegistryPath = "HKCU:\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"

        if (!(Test-Path $RegistryPath)) {
            $null = New-Item -Path $RegistryPath -Force
        }
        
        Set-ItemProperty -Path $RegistryPath -Name "(Default)" -Value $null
        Write-Warning -Message "A restart is required to apply the old right-click context menu."
    }
}
#EndRegion './Public/Set-OldRightClickMenu.ps1' 18