diff --git a/ersc-script.ps1 b/ersc-script.ps1 index 5f343b6..7d86b59 100644 --- a/ersc-script.ps1 +++ b/ersc-script.ps1 @@ -1,8 +1,54 @@ $ErrorActionPreference = 'Stop' $apiUrl = 'https://api.github.com/repos/LukeYui/EldenRingSeamlessCoopRelease/releases/latest' -$release = Invoke-RestMethod -Uri $apiUrl -Headers @{ 'User-Agent' = 'PowerShell' } -$scDownloadUrl = $release.assets[0].browser_download_url +$scDownloadUrl = $null +$localPath = $null + +$input = Read-Host "Do you want to use the official Github-Repository [d] to download the mod or use an already downloaded .zip? [l] [D/l]" + +if ($input -match '^(l|local)$') { + Write-Host "Searching Downloads folder..." + + $downloads = Join-Path $HOME 'Downloads' + + $localPath = Get-ChildItem -Path $downloads -Filter 'Seamless*.zip' -File -ErrorAction SilentlyContinue | + Select-Object -First 1 -ExpandProperty FullName + + if ($localPath -and (Test-Path $localPath)) { + Write-Host "File found at $localPath" + } + else { + Write-Host "File not found in $downloads" + + $input = Read-Host "Please specify the path to your local .zip archive" + + if ([string]::IsNullOrWhiteSpace($input) -or $input -eq 'null') { + throw "Empty path provided" + } + elseif (Test-Path $input -PathType Leaf) { + $localPath = $input + Write-Host "File found at $localPath" + } + elseif (Test-Path $input -PathType Container) { + $localPath = Get-ChildItem -Path $input -Filter 'Seamless*.zip' -File -Recurse -ErrorAction SilentlyContinue | + Select-Object -First 1 -ExpandProperty FullName + + if ($localPath) { + Write-Host "File found at $localPath" + } + else { + throw "File not found at $input" + } + } + else { + throw "Invalid path provided" + } + } +} +else { + $release = Invoke-RestMethod -Uri $apiUrl -Headers @{ 'User-Agent' = 'PowerShell' } + $scDownloadUrl = $release.assets[0].browser_download_url +} function Get-EldenRingGameDir { $steamPaths = @( @@ -12,44 +58,64 @@ function Get-EldenRingGameDir { ) foreach ($path in $steamPaths) { - if (Test-Path (Join-Path $path 'eldenring.exe')) { return $path } + if (Test-Path (Join-Path $path 'eldenring.exe')) { + $input = Read-Host "Is this your Elden Ring Game folder? $path [Y/n]" + + if ($input -notmatch '^(n|no)$') { + return $path + } + } } $drives = Get-PSDrive -PSProvider FileSystem | Select-Object -ExpandProperty Root + foreach ($drive in $drives) { + Write-Host "Searching at $drive" + $hit = Get-ChildItem -Path $drive -Filter 'eldenring.exe' -Recurse -File -ErrorAction SilentlyContinue | Where-Object { $_.FullName -match '\\Elden Ring\\Game\\eldenring\.exe$' } | Select-Object -First 1 - if ($hit) { return $hit.DirectoryName } + + if ($hit) { + $input = Read-Host "Is this your Elden Ring Game folder? $($hit.DirectoryName) [Y/n]" + + if ($input -notmatch '^(n|no)$') { + return $hit.DirectoryName + } + } } return $null } +Write-Host "Searching for Elden Ring game folder" + $eldenringDir = Get-EldenRingGameDir if (-not $eldenringDir) { - $eldenringDir = Read-Host "Could not auto-detect your Elden Ring Game folder. Enter the full Game folder path" + $eldenringDir = Read-Host "Please provide your Elden Ring Directory Path" + if (-not (Test-Path (Join-Path $eldenringDir 'eldenring.exe'))) { throw "Incorrect Elden Ring directory. 'eldenring.exe' not found at provided path." } -} else { - $input = Read-Host "Is this your Elden Ring Game folder? $eldenringDir [Y/n]" - if ($input -match '^(n|no)$') { - $eldenringDir = Read-Host "Please provide your Elden Ring Game folder path" - if (-not (Test-Path (Join-Path $eldenringDir 'eldenring.exe'))) { - throw "Incorrect Elden Ring directory. 'eldenring.exe' not found at provided path." - } - } + + Write-Host "Correct Elden Ring directory" } $tempDir = Join-Path $PWD 'ersc-download' New-Item -ItemType Directory -Path $tempDir -Force | Out-Null -Write-Host "Downloading Seamless Coop" -Write-Host "Download URL: $scDownloadUrl" $zipPath = Join-Path $tempDir 'ersc.zip' -Invoke-WebRequest -Uri $scDownloadUrl -OutFile $zipPath + +if (-not $scDownloadUrl -and $localPath) { + Write-Host "Copying .zip" + Copy-Item $localPath $zipPath -Force +} +else { + Write-Host "Downloading Seamless Coop" + Write-Host "Download URL: $scDownloadUrl" + Invoke-WebRequest -Uri $scDownloadUrl -OutFile $zipPath +} Write-Host "Extracting downloaded files" Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force @@ -59,9 +125,13 @@ $launcherPath = Join-Path $eldenringDir 'ersc_launcher.exe' if (Test-Path $launcherPath) { $input = Read-Host "Override existing Seamless Coop settings? This resets your Seamless Coop settings, including multiplayer password [Y/n]" + if ($input -match '^(n|no)$') { $settings = Join-Path $seamlessDir 'ersc_settings.ini' - if (Test-Path $settings) { Remove-Item $settings -Force } + + if (Test-Path $settings) { + Remove-Item $settings -Force + } } }