diff --git a/.vscode/configurations/windows-docker/tasks.json b/.vscode/configurations/windows-docker/tasks.json index 3e94ea5..f968c06 100644 --- a/.vscode/configurations/windows-docker/tasks.json +++ b/.vscode/configurations/windows-docker/tasks.json @@ -42,7 +42,7 @@ "options": { "cwd": "${config:buildDirectory}" }, - "command": "./run.ps1" + "command": "Start-Job { ./run.ps1 } | Receive-Job -Wait" }, { "type": "shell", diff --git a/template/windows-pcsx2.ps1 b/template/windows-pcsx2.ps1 index 98f87fe..6543a59 100644 --- a/template/windows-pcsx2.ps1 +++ b/template/windows-pcsx2.ps1 @@ -1,12 +1,76 @@ -$PCSX2_PATH = "${Env:ProgramFiles(x86)}/PCSX2" -$PCSX2_EXE = 'pcsx2.exe' +# ======================= +$CUSTOM_PCSX2_PATH = "" # "D:/My/Path/To/PCSX2" +# ======================= function GetTargetELFName { return (Select-String -Path './Makefile' -Pattern "[^ ]*.elf").Matches.Value } +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 RunPCSX2 { - $PCSX2_EXE_WITHOUT_EXT = (Split-Path $PCSX2_EXE -Leaf).Split('.')[0] - Stop-Process -Name $PCSX2_EXE_WITHOUT_EXT -ErrorAction 'SilentlyContinue' - Start-Process -FilePath "$PCSX2_PATH/$PCSX2_EXE" -ArgumentList "--elf=$PWD/bin/$(GetTargetELFName)" -} \ No newline at end of file + $dirPath = FindPCSX2Directory + $isNewVersion = IsNewQtVersionOfPCSX2 -path $dirPath + $executableName = FindPCSX2Executable -directory $dirPath + $executableNameWithoutExt = (Split-Path $executableName -Leaf).Split('.')[0] + $targetFileName = "$PWD/bin/$(GetTargetELFName)" + + Stop-Process -Name $executableNameWithoutExt -ErrorAction 'SilentlyContinue' + + if ($isNewVersion) { + Start-Process -FilePath "$dirPath/$executableName" -ArgumentList "-elf", $targetFileName + } + else { # Old version of PCSX2 + Start-Process -FilePath "$dirPath/$executableName" -ArgumentList "--elf=$targetFileName" + } +} + +RunPCSX2 \ No newline at end of file diff --git a/windows-pcsx2.ps1 b/windows-pcsx2.ps1 index 98f87fe..6543a59 100644 --- a/windows-pcsx2.ps1 +++ b/windows-pcsx2.ps1 @@ -1,12 +1,76 @@ -$PCSX2_PATH = "${Env:ProgramFiles(x86)}/PCSX2" -$PCSX2_EXE = 'pcsx2.exe' +# ======================= +$CUSTOM_PCSX2_PATH = "" # "D:/My/Path/To/PCSX2" +# ======================= function GetTargetELFName { return (Select-String -Path './Makefile' -Pattern "[^ ]*.elf").Matches.Value } +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 RunPCSX2 { - $PCSX2_EXE_WITHOUT_EXT = (Split-Path $PCSX2_EXE -Leaf).Split('.')[0] - Stop-Process -Name $PCSX2_EXE_WITHOUT_EXT -ErrorAction 'SilentlyContinue' - Start-Process -FilePath "$PCSX2_PATH/$PCSX2_EXE" -ArgumentList "--elf=$PWD/bin/$(GetTargetELFName)" -} \ No newline at end of file + $dirPath = FindPCSX2Directory + $isNewVersion = IsNewQtVersionOfPCSX2 -path $dirPath + $executableName = FindPCSX2Executable -directory $dirPath + $executableNameWithoutExt = (Split-Path $executableName -Leaf).Split('.')[0] + $targetFileName = "$PWD/bin/$(GetTargetELFName)" + + Stop-Process -Name $executableNameWithoutExt -ErrorAction 'SilentlyContinue' + + if ($isNewVersion) { + Start-Process -FilePath "$dirPath/$executableName" -ArgumentList "-elf", $targetFileName + } + else { # Old version of PCSX2 + Start-Process -FilePath "$dirPath/$executableName" -ArgumentList "--elf=$targetFileName" + } +} + +RunPCSX2 \ No newline at end of file