Skip to content

Instantly share code, notes, and snippets.

@Jamamuuga
Forked from Halkcyon/GW2.cmd
Created February 27, 2019 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jamamuuga/63ddfb44b7ea2fb6e6580ea46b183449 to your computer and use it in GitHub Desktop.
Save Jamamuuga/63ddfb44b7ea2fb6e6580ea46b183449 to your computer and use it in GitHub Desktop.
Automatically update ArcDps and BuildTemplates from deltaconnected for Guild Wars 2
::[CmdletBinding(SupportsShouldProcess)]
::param
::(
::# Update these values to where you have GW2 installed and named
:: [Parameter(Position = 0)]
:: [System.String]
:: $Gw2Path = "$Env:ProgramFiles\Guild Wars 2\Gw2-64.exe",
::
::# This line can be removed if you don't want to pass any arguments
::# It does not get used if you already have a "%APPDATA%\Guild Wars 2\Settings.json" file
::# https://wiki.guildwars2.com/wiki/Command_line_arguments
:: [Parameter(Position = 1)]
:: [System.String[]]
:: $Gw2Arguments = @('/mapLoadinfo', '/bmp', '/autologin', '/fps:60')
::)
::<#
@ECHO OFF
REM https://stackoverflow.com/questions/3759456/create-a-executable-exe-file-from-powershell-script#answer-4629494
REM https://blogs.msdn.microsoft.com/zainala/2008/08/05/using-0-inside-the-batch-file-to-get-the-file-info/
SET "pwsh=%windir%\System32\WindowsPowerShell\v1.0\powershell.exe"
SET "args=-NoProfile -NoLogo -ExecutionPolicy Bypass -Command"
SET "cmd="@(Get-Content -Path '%~f0') -replace '^^::'^|Set-Content -Path '%~dpn0.ps1';. '%~dpn0.ps1' %*""
%pwsh% %args% %cmd%
DEL "%~dpn0.ps1" /Q /F
EXIT 0
::#>
if (Get-Process -Name $(Split-Path -Leaf -Path $Gw2Path) -ErrorAction SilentlyContinue)
{
exit
}
function Start-Gw2()
{
$startProcessParams = @{
'FilePath' = $Gw2Path
}
if (-not $(Test-Path -Path "$Env:AppData\Guild Wars 2\Settings.json") -and $Gw2Arguments)
{
$startProcessParams['ArgumentList'] = $Gw2Arguments
}
Start-Process @startprocessParams
Start-Sleep -Seconds 10
$startProcessParams = @{
'FilePath' = "$(Split-Path -Parent -Path $Gw2Root)\addons\taco\GW2TacO.exe"
'WorkingDirectory' = "$(Split-Path -Parent -Path $Gw2Root)\addons\taco\"
}
Start-Process @startProcessParams
exit
}
$arcPath = "$(Split-Path -Parent -Path $Gw2Path)\bin64\d3d9.dll"
$arcUri = 'https://www.deltaconnected.com/arcdps/x64/d3d9.dll'
$templatesPath = "$(Split-Path -Parent -Path $Gw2Path)\bin64\d3d9_arcdps_buildtemplates.dll"
$templatesUri = 'https://www.deltaconnected.com/arcdps/x64/buildtemplates/d3d9_arcdps_buildtemplates.dll'
try
{
$invokeWebRequestParams = @{
'Uri' = 'https://www.deltaconnected.com/arcdps/x64/d3d9.dll.md5sum'
'UseBasicParsing' = $true
'ErrorAction' = [System.Management.Automation.ActionPreference]::Stop
}
$remoteHash = $(
@($(Invoke-WebRequest @invokeWebRequestParams).RawContent -split "`n").Where{$_}[-1] -split '\s'
)[0]
}
catch
{
"Failed to retrieve checksum for ArcDPS: $PSItem"
$null = $Host.UI.RawUI.ReadKey()
Start-Gw2
}
if ($remoteHash.Length -ne 32)
{
"Bad MD5 checksum from ArcDPS: $remoteHash."
$null = $Host.UI.RawUI.ReadKey()
Start-Gw2
}
#region ArcDPS/BuildTemplates download
if (Test-Path -Path $arcPath)
{
if ($(Get-FileHash -Path $arcPath -Algorithm MD5).Hash -ne $remoteHash)
{
'ArcDPS is out-of-date.'
if (Test-Path -Path "$arcPath.bak")
{
Remove-Item -Path "$arcPath.bak", "$templatesPath.bak" -Force
}
Rename-Item -Path $arcPath -NewName "$arcPath.bak"
Rename-Item -Path $templatesPath -NewName "$templatesPath.bak"
try
{
Invoke-WebRequest -Uri $arcUri -OutFile $arcPath -ErrorAction Stop
Invoke-WebRequest -Uri $templatesUri -OutFile $templatesPath -ErrorAction Stop
}
catch
{
Remove-Item -Path $arcPath, $templatesPath -Force -ErrorAction Ignore
Rename-Item -Path "$arcPath.bak" -NewName $arcPath
Rename-Item -Path "$templatesPath.bak" -NewName $templatesPath
"Failed to update ArcDPS: $PSItem Restored old version."
$null = $Host.UI.RawUI.ReadKey()
Start-Gw2
}
'ArcDPS install complete.'
}
else
{
'ArcDPS is up-to-date.'
}
}
else
{
Invoke-WebRequest -Uri $arcUri -OutFile $arcPath
Invoke-WebRequest -Uri $templatesUri -OutFile $templatesPath
'ArcDPS install complete.'
Start-Sleep -Seconds 1
}
#endregion
Start-Gw2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment