-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-pcsx2.ps1
85 lines (72 loc) · 2.48 KB
/
start-pcsx2.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
# Adapted from this file https://github.com/h4570/tyra/blob/master/windows-pcsx2.ps1
# =======================
$CUSTOM_PCSX2_PATH = "D:/PS2DEV/PCSX2/pcsx2-v1.7.4479-windows-64bit-Qt" # "D:/My/Path/To/PCSX2"
# =======================
function GetTargetELFName {
return Get-ChildItem -Path "./src" -Filter "*.elf" -Recurse | Select-Object -ExpandProperty Name
}
function FindPCSX2Directory {
if (-not [string]::IsNullOrEmpty($CUSTOM_PCSX2_PATH)) {
return $CUSTOM_PCSX2_PATH
}
else {
# Try to find in program files
$pcsx2Path = "${Env:ProgramFiles}/PCSX2"
$pcsx2Pathx86 = "${Env:ProgramFiles(x86)}/PCSX2"
if (Test-Path -Path $pcsx2Path) {
return $pcsx2Path
}
elseif (Test-Path -Path $pcsx2Pathx86) {
return $pcsx2Pathx86
}
else {
throw "PCSX2 directory not found!"
return $null
}
}
}
function IsNewQtVersionOfPCSX2 {
param (
[string]$path
)
return Test-Path -Path "$path/qt.conf"
}
function FindPCSX2Executable {
param (
[string]$directory
)
$pcsx2ExePath = Join-Path -Path $directory -ChildPath 'pcsx2.exe'
$pcsx2QtExePath = Join-Path -Path $directory -ChildPath 'pcsx2-qt.exe'
if (Test-Path -Path $pcsx2ExePath) {
return 'pcsx2.exe'
}
elseif (Test-Path -Path $pcsx2QtExePath) {
return 'pcsx2-qt.exe'
}
else {
throw "PCSX2 executable not found in: $directory!"
return $null
}
}
function StartPCSX2 {
$dirPath = FindPCSX2Directory
$noGui = $true
$isNewVersion = IsNewQtVersionOfPCSX2 -path $dirPath
$executableName = FindPCSX2Executable -directory $dirPath
$executableNameWithoutExt = (Split-Path $executableName -Leaf).Split('.')[0]
$targetFileName = "$PWD\dist\$(GetTargetELFName)"
Stop-Process -Name $executableNameWithoutExt -ErrorAction 'SilentlyContinue'
if ($isNewVersion) {
if ($noGui) {
Start-Process -FilePath "$dirPath/$executableName" -ArgumentList "-batch -nogui -fastboot -elf", $targetFileName -NoNewWindow
}
else {
Start-Process -FilePath "$dirPath/$executableName" -ArgumentList "-batch -fastboot -elf", $targetFileName
}
}
else {
# Old version of PCSX2
Start-Process -FilePath "$dirPath/$executableName" -ArgumentList "--elf=$targetFileName"
}
}
StartPCSX2