-
Notifications
You must be signed in to change notification settings - Fork 0
/
sc.ps1
177 lines (155 loc) · 6.38 KB
/
sc.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Star Citizen Launcher
# Beta v0.1
# Use at your own risk!
# See LICENSE file for MIT licensing
# Description:
# This will manage processes, manage services, set primary monitor, and launch Star Citizen
# Then it will monitor for the StarCitizen.exe and Launcher and
# relaunch any processes and services
Write-Host "Star Citizen Launcher"
Write-Host "---------------------"
# Set the current path of the script
$scriptdir = $PSScriptRoot
Write-Host "Scriptdir is " $scriptdir
# Load config file
# rename sc-config-example.ps1 to sc-config.ps1 and configure settings
$basefile = (Get-Item $PSCommandPath ).BaseName
$configfile = "$basefile-config.ps1"
if (Test-Path -Path $configfile -PathType Leaf) {
Write-Host "Configfile is: " $configfile
. $PSScriptRoot\$configfile
}
else {
Write-Host "ERROR:"
Write-Host "$configfile not found."
Write-Host "Copy sc-config-example.ps1 to sc-config.ps1 and"
Write-Host "edit appropriate settings"
exit 1
}
# Functions
Function StopProcess {
param (
$ProcessName
)
try {
Write-Host "Stopping $ProcessName"
$ProcessRunning = Get-Process $ProcessName -ErrorAction SilentlyContinue
if ($ProcessRunning) {
Stop-Process -Name $ProcessName
}
}
catch {
Write-Host "$ProcessName not found"
}
}
function StartProg {
param ($ProgName, $ProgPath, $ProgDir, $ProgArgs)
Write-Host "ProgPath: $ProgPath"
If ($ProgName) {$ProgRunning = Get-Process $ProgName -ErrorAction SilentlyContinue}
# If the ProgName process is not running the launch
# If $ProgName is nul it will always launch
if (!$ProgRunning) {
# If the path to the ProgPath exists then start the program
If (Test-Path -Path $ProgPath -PathType Leaf) {
Write-Host "Starting $ProgName..."
If (!$ProgArgs) {Start-Process -FilePath $ProgPath -WorkingDirectory $ProgDir}
If ($ProgArgs) {Start-Process -FilePath $ProgPath -WorkingDirectory $ProgDir -ArgumentList $ProgArgs}
}
else {
Write-Host "Error: Path does not exist"
Write-Host "ProgPath:" $ProgPath
return 1
}
Start-Sleep 2
}
}
function SetPrimaryMonitor {
# Set second monitor as primary if more than 1 display
# This uses the free utility MultiMonitor
# https://www.nirsoft.net/utils/multi_monitor_tool.html
# Depending on your configuration your external monitor may not be "Display2".
# It could be almost any number. Use the utility to see which number you should use below.
# It works best if you find the Monitor ID using MultiMonitorTool
# Example:
# My Scepter external monitor's Monitor ID is
# MONITOR\SPT2401\{4d36e96e-e325-11ce-bfc1-08002be10318}\0006
# This GUID is consistent no matter what stupid Display number Windows assigns
param ($DisplayNum)
$monitors = @(Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams | where-object { $_.Active }).Length
Write-Host "There are" $monitors "display(s)"
If ((Get-Command ".\MultiMonitorTool.exe" -ErrorAction SilentlyContinue) -eq $null)
{
Write-Host "ERROR: "
Write-Host "Unable to find MultiMonitorTool.exe in your PATH"
Write-Host "Please download MultiMonitorTool from"
Write-Host " https://www.nirsoft.net/utils/multi_monitor_tool.html"
Write-Host ""
exit 1
}
# Only do this if more than one monitor is detected
If ($monitors -gt 1) {
Write-Host "Multiple Displays - Switching primary montitor"
Start-Process "MultiMonitorTool.exe" -ArgumentList "/SetPrimary $DisplayNum" -WorkingDirectory "$PSScriptRoot"
Write-Host ""
}
}
function MinimizeApps {
$a = New-Object -ComObject Shell.Application
$a.MinimizeAll()
Start-Sleep 2
}
# End Functions
MinimizeApps
# Stop Processes Before Launch of Star Citizen
# Edit StopProcessList in sc-config.ps1
Write-Host "Stopping Procceses..."
foreach ($process in $StopProcessList) {
StopProcess $process
}
# Clear Star Citizen Cache $SCPath\StarCitizen\LIVE\USER\Client\0\shaders\cache
#Remove-Item "$env:localappdata\Star Citizen\*" -Recurse
# Set the Primary monitor if more than 1 monitor is connected
SetPrimaryMonitor -DisplayNum $PrimaryMonitor
# Hide taskbar
&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=3;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}
# Start Programs
# StartProg -ProgName $ProgListNode.ProgName -ProgPath $ProgListNode.ProgPath -ProgDir $ProgListNode.ProgDir -ProgArgs $ProgListNode.ProgArgs
Write-Host "Starting Programs..."
foreach ( $ProgListNode in $ProgList ) {
StartProg -ProgName $ProgListNode.ProgName -ProgPath $ProgListNode.ProgPath -ProgDir $ProgListNode.ProgDir -ProgArgs $ProgListNode.ProgArgs
}
# Shutdown stuff with elevated user
# Stop Services
Write-host "Launching: PowerShell.exe" $stopservicescmd
Start-Process PowerShell.exe $stopservicescmd
# Wait for RSI Launcher and StarCitizen to be closed then start things back up again.
#Wait-Process -Name "RSI Launcher"
# Wait for RSI Launcher to be closed then start things back up again.
$launcherprocess = (Get-Process -Name "RSI Launcher" -ErrorAction SilentlyContinue)
try {
Write-Host "Waiting for RSI Launcher to close"
Get-Process $launcherprocess.ProcessName | Wait-Process
Write-Host "$launcherprocess no longer running"
}
catch {
Write-Host "RSI Launcher is not running"
}
finally {
Write-Host "RSI Launcher is not running"
}
# $PostStopList After RSI Launcher is closed
Write-Host "Stopping Programs after closing RSI Launcher..."
foreach ($process in $PostStopList) {
StopProcess $process
}
# Set first monitor as primary
SetPrimaryMonitor -DisplayNum 1
# Startup Select Background Programs again
Write-Host "Starting Programs after closing RSI Launcher Programs..."
foreach ( $ProgListNode in $PostProgList ) {
StartProg -ProgName $ProgListNode.ProgName -ProgPath $ProgListNode.ProgPath -ProgDir $ProgListNode.ProgDir -ProgArgs $ProgListNode.ProgArgs
}
# Show Taskbar
&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=2;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}
Write-host "Closing Star Citizen Launch"