fix: Remove unused code

- Remove Write-Mandatory method (Use Write-Status instead)
- Fixed a bug where the daily upgrade couldn't be done after closing the script via the window.
main
Plínio Larrubia 2 years ago committed by Plínio Larrubia
parent a52e4c5c8d
commit 002241a6cd
No known key found for this signature in database
GPG Key ID: 057B0A87CB137C69

@ -138,8 +138,8 @@ Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force; ls -Recurse *.ps*1 |
- Help improve the Security of Windows while maintaining performance; ([`optimize-security.ps1`](./src/scripts/optimize-security.ps1))
- Remove OneDrive completely from the System, re-install is possible via Win Store; ([`remove-onedrive.ps1`](./src/scripts/remove-onedrive.ps1))
- Disable/Enable Windows Features specially for Gaming/Productivity; ([`optimize-windows-features.ps1`](./src/scripts/optimize-windows-features.ps1))
- Install WSL Preview (Only works for Windows 11): ([`win11-wsl-preview-install.ps1`](./src/scripts/win11-wsl-preview-install.ps1))
- In the End it Locks Script's Usage Permission. ([`set-script-policy.psm1`](./src/lib/set-script-policy.psm1))
- Install WSL Preview (Only works for Windows 11); ([`win11-wsl-preview-install.ps1`](./src/scripts/win11-wsl-preview-install.ps1))
- In the End it only locks Local Machine script execution. ([`set-script-policy.psm1`](./src/lib/set-script-policy.psm1))
</details>

@ -12,7 +12,7 @@ function Request-FileDownload {
Write-Verbose "[?] I'm at: $PWD"
If (!(Test-Path "$PSScriptRoot\..\tmp")) {
Write-Mandatory "$PSScriptRoot\..\tmp doesn't exist, creating folder..."
Write-Status -Symbol "@" -Status "$PSScriptRoot\..\tmp doesn't exist, creating folder..."
mkdir "$PSScriptRoot\..\tmp" | Out-Null
}
@ -20,7 +20,7 @@ function Request-FileDownload {
If ($OutputFolder) {
If (!(Test-Path "$PSScriptRoot\..\tmp\$OutputFolder")) {
Write-Mandatory "$PSScriptRoot\..\tmp\$OutputFolder doesn't exist, creating folder..."
Write-Status -Symbol "@" -Status "$PSScriptRoot\..\tmp\$OutputFolder doesn't exist, creating folder..."
mkdir "$PSScriptRoot\..\tmp\$OutputFolder"
}
$FileLocation = "$PSScriptRoot\..\tmp\$OutputFolder\$OutputFile"
@ -28,8 +28,8 @@ function Request-FileDownload {
Import-Module BitsTransfer
Write-Host
Write-Mandatory "Downloading from: '$FileURI' as '$OutputFile'"
Write-Mandatory "On: '$FileLocation'"
Write-Status -Symbol "@" -Status "Downloading from: '$FileURI' as '$OutputFile'"
Write-Status -Symbol "@" -Status "On: '$FileLocation'"
Start-BitsTransfer -Dynamic -RetryTimeout 60 -TransferType Download -Source $FileURI -Destination $FileLocation
return $FileLocation

@ -113,7 +113,7 @@ function Get-SystemSpec() {
[String] $Separator = '|'
)
Write-Mandatory "Loading system specs..."
Write-Status -Symbol "@" -Status "Loading system specs..."
# Adapted From: https://www.delftstack.com/howto/powershell/find-windows-version-in-powershell/#using-the-wmi-class-with-get-wmiobject-cmdlet-in-powershell-to-get-the-windows-version
$WinVer = (Get-CimInstance -class Win32_OperatingSystem).Caption -replace 'Microsoft ', ''
$DisplayVersion = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").DisplayVersion

@ -3,7 +3,7 @@ Import-Module -DisableNameChecking $PSScriptRoot\..\lib\"title-templates.psm1"
function Set-GUILayout() {
[CmdletBinding()] param ()
Write-Mandatory "Loading GUI Layout..."
Write-Status -Symbol "@" -Status "Loading GUI Layout..."
# Loading System Libs
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

@ -3,19 +3,15 @@ Import-Module -DisableNameChecking $PSScriptRoot\..\lib\"title-templates.psm1"
function Unlock-ScriptUsage() {
[CmdletBinding()] param ()
Write-Mandatory "Receiving permissions to run scripts..."
Set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force
Write-Status -Symbol "@" -Status "Receiving permissions to run scripts as Current User..."
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
Get-ExecutionPolicy -List | Out-Null
}
function Block-ScriptUsage() {
[CmdletBinding()] param ()
Write-Mandatory "Denying permissions to run scripts..."
Write-Status -Symbol "@" -Status "Denying permissions to run scripts as LocalMachine..."
Set-ExecutionPolicy Restricted -Scope LocalMachine -Force
Set-ExecutionPolicy Restricted -Scope CurrentUser -Force
Get-ExecutionPolicy -List | Out-Null
}
<#

@ -30,16 +30,6 @@ function Write-Caption() {
Write-Host "$Text" -ForegroundColor White -BackgroundColor Black
}
function Write-Mandatory() {
[CmdletBinding()]
param (
[String] $Text = "No Text"
)
Write-Host "[@] " -NoNewline -ForegroundColor Blue -BackgroundColor Black
Write-Host "$Text" -ForegroundColor White -BackgroundColor Black
}
function Write-Status() {
[CmdletBinding()]
param (
@ -114,7 +104,6 @@ Example:
Write-Title -Text "Text" # Used to print Tweak introduction
Write-Section -Text "Text" # Used to print Tweak Section
Write-Caption -Text "Text" # Used to print Tweak Category
Write-Mandatory -Text "Text" # Used to print mandatory configuration
$Private:Counter = Write-TitleCounter -Text "Text" -Counter $Counter -MaxLenght 100 # Used to print when working with collections # No need to iterate $Counter before, as long it's private
$Private:Counter = Write-TitleCounter -Text "Text" -Counter $Counter -MaxLenght 100 # Used to print when working with collections # No need to iterate $Counter before, as long it's private
Write-ScriptLogo # Used at the start of the Script

@ -1,14 +0,0 @@
function Wait-TimeInSecond() {
[CmdletBinding()]
param (
[Int] $Time = 3,
[String] $Msg = "Exiting in"
)
$Time..0 | ForEach-Object { Start-Sleep -Seconds 1 ; "$Msg $_ seconds..." }
}
<#
Example:
Wait-TimeInSecond -Time 5 -Msg "This is closing in"
#>

@ -40,7 +40,7 @@ function Install-PackageManager() {
# Self-reminder, this part stay out of the Try-Catch block
If ($UpdateScriptBlock) {
# Adapted from: https://blogs.technet.microsoft.com/heyscriptingguy/2013/11/23/using-scheduled-tasks-and-scheduled-jobs-in-powershell/
Write-Mandatory "Creating a daily task to automatically upgrade $PackageManagerFullName packages at $Time."
Write-Status -Symbol "@" -Status "Creating a daily task to automatically upgrade $PackageManagerFullName packages at $Time."
$JobName = "$PackageManagerFullName Daily Upgrade"
$ScheduledJob = @{
Name = $JobName
@ -50,14 +50,14 @@ function Install-PackageManager() {
}
If (Get-ScheduledJob -Name $JobName -ErrorAction SilentlyContinue) {
Write-Mandatory "ScheduledJob: $JobName FOUND!"
Write-Mandatory "Re-Creating with the command:"
Write-Status -Symbol "@" -Status "ScheduledJob: $JobName FOUND!"
Write-Status -Symbol "@" -Status "Re-Creating with the command:"
Write-Host " { $("$UpdateScriptBlock".Trim(' ')) }`n" -ForegroundColor Cyan
Unregister-ScheduledJob -Name $JobName
Register-ScheduledJob @ScheduledJob | Out-Null
}
Else {
Write-Mandatory "Creating Scheduled Job with the command:"
Write-Status -Symbol "@" -Status "Creating Scheduled Job with the command:"
Write-Host " { $("$UpdateScriptBlock".Trim(' ')) }`n" -ForegroundColor Cyan
Register-ScheduledJob @ScheduledJob | Out-Null
}

@ -15,7 +15,7 @@ function WSLPreviewInstall() {
Write-Status -Symbol "-" -Type $TweakType -Status "Uninstalling WSL from Optional Features ..."
Get-WindowsOptionalFeature -Online -FeatureName "Microsoft-Windows-Subsystem-Linux" | Where-Object State -Like "Enabled" | Disable-WindowsOptionalFeature -Online -NoRestart
Write-Mandatory "Updating WSL (if possible) ..."
Write-Status -Symbol "@" -Status "Updating WSL (if possible) ..."
wsl --update
}
Catch {

@ -147,9 +147,9 @@ function Set-GPGKey() {
Write-Host "Then: [your passphrase again] [ENTER]." -ForegroundColor Cyan
gpg --full-generate-key
Write-Mandatory "If you want to delete unwanted keys, this is just for reference"
Write-Mandatory 'gpg --delete-secret-keys $(git config --global user.name)'
Write-Mandatory 'gpg --delete-keys $(git config --global user.name)'
Write-Status -Symbol "@" -Status "If you want to delete unwanted keys, this is just for reference"
Write-Status -Symbol "@" -Status 'gpg --delete-secret-keys $(git config --global user.name)'
Write-Status -Symbol "@" -Status 'gpg --delete-keys $(git config --global user.name)'
Write-Host "Copying all files to $GnuPGPath"
Copy-Item -Path "$GnuPGGeneratePath/*" -Destination "$GnuPGPath/" -Recurse

@ -32,7 +32,7 @@ function WSLwithGraphicsInstall() {
Start-Process -FilePath $WSLgOutput -ArgumentList "/passive" -Wait
Remove-Item -Path $WSLgOutput
Write-Mandatory "Updating WSL (if possible)..."
Write-Status -Symbol "@" -Status "Updating WSL (if possible)..."
wsl --update
}
Else {

Loading…
Cancel
Save