Skip to content

Commit

Permalink
feat: Read-Pause function
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Sep 8, 2024
1 parent 01fde65 commit affb3b5
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ function Write-Title {
Write-Host "`n$dashes`n$text`n$dashes" -ForegroundColor Yellow
}

function Read-Pause {
param (
[Parameter(ValueFromPipeline = $true)]
[string]$Message = "Press Enter to exit",
[switch]$NewLine
)

if ($NewLine) { Write-Output "" }
$null = Read-Host $Message
}

enum MsgIcon {
Stop
Question
Expand Down Expand Up @@ -57,4 +68,4 @@ function Read-MessageBox {
}
}

Export-ModuleMember -Function Write-Title, Read-MessageBox
Export-ModuleMember -Function Write-Title, Read-Pause, Read-MessageBox
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#Requires -RunAsAdministrator

$windir = [Environment]::GetFolderPath('Windows')
& "$windir\AtlasModules\initPowerShell.ps1"

Write-Host "`nRestoring default power schemes..." -ForegroundColor Yellow
# This should set the power plan to 'Balanced' by default
powercfg /restoredefaultschemes | Out-Null
Expand Down Expand Up @@ -79,4 +82,4 @@ Remove-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Power\PowerThr
bcdedit /deletevalue disabledynamictick *> $null

# Finish
$null = Read-Host "`nCompleted.`nPress Enter to exit"
Read-Pause "`nCompleted.`nPress Enter to exit"
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ param (
[switch]$Silent
)

$windir = [Environment]::GetFolderPath('Windows')
& "$windir\AtlasModules\initPowerShell.ps1"

if (!$Silent) {
$isLaptop = (Get-CimInstance -Class Win32_ComputerSystem -Property PCSystemType).PCSystemType -eq 2
if ($isLaptop) {
Expand Down Expand Up @@ -54,7 +57,7 @@ powercfg /setacvalueindex scheme_current 54533251-82be-4824-96c1-47b60b740d00 4d
powercfg /setactive scheme_current

Write-Host "Disabling power-saving ACPI devices..." -ForegroundColor Yellow
& "$([Environment]::GetFolderPath('Windows'))\AtlasModules\Scripts\toggleDev.cmd" -Disable '@("ACPI Processor Aggregator", "Microsoft Windows Management Interface for ACPI")' | Out-Null
& "$windir\AtlasModules\Scripts\toggleDev.cmd" -Disable '@("ACPI Processor Aggregator", "Microsoft Windows Management Interface for ACPI")' | Out-Null

Write-Host "Disabling network adapter power-saving..." -ForegroundColor Yellow
$properties = Get-NetAdapter -Physical | Get-NetAdapterAdvancedProperty
Expand Down Expand Up @@ -130,4 +133,4 @@ New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Power\PowerThrott
bcdedit /set disabledynamictick yes | Out-Null

if ($Silent) { exit }
$null = Read-Host "`nCompleted.`nPress Enter to exit"
Read-Pause "`nCompleted.`nPress Enter to exit"
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
$ProgressPreference = 'SilentlyContinue'
function Pause ($message = "Press Enter to exit") { $null = Read-Host $message }

$windir = [Environment]::GetFolderPath('Windows')
& "$windir\AtlasModules\initPowerShell.ps1"

function Write-BulletPoint($message) {
Write-Host " - " -ForegroundColor Green -NoNewline
Write-Host $message
Expand All @@ -11,14 +14,14 @@ function Restart {
Restart-Computer
} else {
Write-Host "`nChanges will apply after next restart." -ForegroundColor Yellow
Pause
Read-Pause
}
}

$packageInstall = "$([Environment]::GetFolderPath('Windows'))\AtlasModules\Scripts\packageInstall.ps1"
$packageInstall = "$windir\AtlasModules\Scripts\packageInstall.ps1"
if (!(Test-Path $packageInstall)) {
Write-Host "Missing package install script, can't continue."
Pause
Read-Pause
exit 1
}

Expand All @@ -29,7 +32,7 @@ try {
} catch {
if (!$?) {
Write-Host "Failed to get packages! $_" -ForegroundColor Red
Pause
Read-Pause
exit 1
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
$ProgressPreference = 'SilentlyContinue'
function Pause ($message = "Press Enter to exit") { $null = Read-Host $message }

$windir = [Environment]::GetFolderPath('Windows')
& "$windir\AtlasModules\initPowerShell.ps1"

function Restart {
Write-Host "`nCompleted!" -ForegroundColor Green
choice /c yn /n /m "Would you like to restart now to apply the changes? [Y/N] "
if ($lastexitcode -eq 1) {
Restart-Computer
} else {
Write-Host "`nChanges will apply after next restart." -ForegroundColor Yellow
Pause
Read-Pause
}
}

$packageInstall = "$([Environment]::GetFolderPath('Windows'))\AtlasModules\Scripts\packageInstall.ps1"
$packageInstall = "$windir\AtlasModules\Scripts\packageInstall.ps1"
if (!(Test-Path $packageInstall)) {
Write-Host "Missing package install script, can't continue."
if (!$args) { Pause }
if (!$args) { Read-Pause }
exit 1
}

Expand All @@ -25,7 +28,7 @@ try {
} catch {
if (!$?) {
Write-Host "Failed to get packages! $_" -ForegroundColor Red
Pause
Read-Pause
exit 1
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/playbook/Executables/AtlasModules/Scripts/newUsers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $title = 'Preparing Atlas user settings...'

if (!(Test-Path $atlasDesktop) -or !(Test-Path $atlasModules)) {
Write-Host "Atlas was about to configure user settings, but its files weren't found. :(" -ForegroundColor Red
$null = Read-Host "Press Enter to exit"
Read-Pause
exit 1
}

Expand Down
14 changes: 5 additions & 9 deletions src/playbook/Executables/AtlasModules/Scripts/packageInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ $safeModeStatus = (Get-CimInstance -Class Win32_ComputerSystem).BootupState -ne
# ======================================================================================================================= #
# FUNCTIONS #
# ======================================================================================================================= #
function Pause ($message = "Press Enter to exit") {
$null = Read-Host $message
}

function Write-BulletPoint($message) {
$message | Foreach-Object {
Write-Host " - " -ForegroundColor Green -NoNewline
Expand Down Expand Up @@ -83,7 +79,7 @@ function Restart {
Restart-Computer
Start-Sleep 2
Write-Host "Something seems to have went wrong restarting automatically, restart manually." -ForegroundColor Red
if (!$NoInteraction) { Pause }
if (!$NoInteraction) { Read-Pause }
exit 9000
}

Expand Down Expand Up @@ -127,7 +123,7 @@ $seperator

function NoRestart {
Write-Host "`nIf any packages installed successfully, they will apply next restart." -ForegroundColor Yellow
Pause
Read-Pause
}

if ($safeModeStatus) {
Expand Down Expand Up @@ -157,7 +153,7 @@ $seperator
Restart
} else {
Write-Host "`nChanges will apply next restart." -ForegroundColor Yellow
Pause
Read-Pause
exit $script:errorLevel
}
}
Expand Down Expand Up @@ -221,7 +217,7 @@ if ($InstallPackages) {

if ($matchedPackages.Count -eq 0) {
Write-Host "[ERROR] The specified CABs ($InstallPackages) to install weren't found." -ForegroundColor Red
if (!$NoInteraction) { Pause }
if (!$NoInteraction) { Read-Pause }
exit 1
}
if ($notMatchedPackages.Count -gt 0) {
Expand Down Expand Up @@ -277,7 +273,7 @@ Please note that if you chose to disable Windows Defender, it may still remain e
# ======================================================================================================================= #
if (!$matchedPackages) {
Write-Host "This will install specified CBS packages online, meaning live on your current install of Windows." -ForegroundColor Yellow
Pause "Press Enter to continue"
Read-Pause "Press Enter to continue"

Write-Host "`n[INFO] Opening file dialog to select CBS package CAB..."
Add-Type -AssemblyName System.Windows.Forms
Expand Down

0 comments on commit affb3b5

Please sign in to comment.