-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateAll.cmd
176 lines (143 loc) · 6.12 KB
/
UpdateAll.cmd
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
REM <#
@echo off
copy UpdateAll.cmd UpdateAll.ps1 >NUL
PowerShell.exe -ExecutionPolicy Unrestricted -NoProfile -Command "&{Set-Alias REM Write-Host; .\UpdateAll.ps1}"
del UpdateAll.ps1
exit
REM #>
# Lines starting with a '#' are comments for readability and will not be executed
# This is based off of the code from https://gist.github.com/OneFaced/764f9c5c7bef1c49a31d928c223bcb24
# It checks for updates to arc dps and also the mechanics plugin at the uri below
# comments included for readability
# ======================== Guild Wars 2 Path (Change if needed) ========================================================
$GW2Path = "$env:ProgramFiles\Guild Wars 2\"
$gw = 'Gw2-64'
# ======================== Links to files needed ========================================================
$arcMD5 = 'https://www.deltaconnected.com/arcdps/x64/d3d9.dll.md5sum'
$arcD3 = 'https://www.deltaconnected.com/arcdps/x64/d3d9.dll'
$buildTemplates = 'https://www.deltaconnected.com/arcdps/x64/buildtemplates/d3d9_arcdps_buildtemplates.dll'
$mechanicsD3 = 'http://martionlabs.com/wp-content/uploads/d3d9_arcdps_mechanics.dll'
$mechanicsMD5 = 'http://martionlabs.com/wp-content/uploads/d3d9_arcdps_mechanics.dll.md5sum'
# ======================== Downloads main arc dps ========================================================
function DownloadArcDps
{
Write-Verbose 'Downloading ArcDps'
$arcD3Response = Invoke-WebRequest -Uri $arcD3
Set-Content -Path "$($GW2Path)\bin64\d3d9.dll" -Encoding Byte -Value $arcD3Response.Content
$btResponse = Invoke-WebRequest -Uri $buildTemplates
Set-Content -Path "$($GW2Path)\bin64\d3d9_arcdps_buildtemplates.dll" -Encoding Byte -Value $btResponse.Content
Write-Verbose 'Completed ArcDps install'
}
# ======================== Downloads mechanics plugin ========================================================
function DownloadArcMechanics
{
Write-Verbose 'Downloading ArcMechanics'
$mechanicsD3Response = Invoke-WebRequest -Uri $mechanicsD3
Set-Content -Path "$($GW2Path)\bin64\d3d9_arcdps_mechanics.dll" -Encoding Byte -Value $mechanicsD3Response.Content
Write-Verbose 'Completed ArcMechanics install'
}
# ======================== Checks main arc file for updates ========================================================
function CheckArcUpdates
{
if((Get-Process $gw -ErrorAction 0).Count -gt 0)
{
Exit
}
# checks if the file exists in the directory
$arcD3Exists = Test-Path "$($GW2Path)\bin64\d3d9.dll"
# if it does exist, check if the version is the most recent
if($arcD3Exists)
{
# gets the hash of the version in the GW2 directory
$currentArcD3 = Get-FileHash "$($GW2Path)\bin64\d3d9.dll" -Algorithm MD5
# attempts to get a response from the MD5
try
{
$arcMD5Response = Invoke-WebRequest -Uri $arcMD5
}
# exits if it cant download the MD5
catch
{
Write-Verbose 'Failed to download Arc Dps MD5 sum'
Exit
}
# if we get a response, check if the hash matches the one we currently have, if they dont match, it is out of date
if(!$currentArcD3.Hash.Equals(($arcMD5Response.ToString().Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)[0]),
[System.StringComparison]::InvariantCultureIgnoreCase))
{
Write-Verbose 'Arc Dps is out of date'
# copying the current arc dps to a old.bak file for backup
Copy-Item "$($GW2Path)\bin64\d3d9.dll" -Destination "$($GW2Path)\bin64\d3d9_old.bak" -Force
# makes an attempt to copy the build templates file as well
try
{
Copy-Item "$($GW2Path)\bin64\d3d9_arcdps_buildtemplates.dll" -Destination "$($GW2Path)\bin64\d3d9_arcdps_buildtemplates_old.bak" -Force
}
catch {}
# calls the function to download the newest version
DownloadArcDps
}
# The hashes match, you currently have the most recent version
else
{
Write-Verbose 'Arc Dps is up to date'
}
}
# the file does not exist in the directory, downloading a new copy now
else
{
DownloadArcDps
}
}
# ======================== Checks mechanics plugin for updates ========================================================
function CheckMechanicsUpdates
{
if((Get-Process $gw -ErrorAction 0).Count -gt 0)
{
Exit
}
# checks if the file exists in the directory
$mechanicsD3Exists = Test-Path "$($GW2Path)\bin64\d3d9_arcdps_mechanics.dll"
# if it does exist, check if the version is the most recent
if($mechanicsD3Exists)
{
# gets the hash of the version in the GW2 directory
$currentMechanicsD3 = Get-FileHash "$($GW2Path)\bin64\d3d9_arcdps_mechanics.dll" -Algorithm MD5
# attempts to get a response from the MD5
try
{
$mechanicsMD5Response = Invoke-WebRequest -Uri $mechanicsMD5
}
# exits if it cant download the MD5
catch
{
Write-Verbose 'Failed to download Arc Mechanics MD5 sum'
Exit
}
# if we get a response, check if the hash matches the one we currently have, if they dont match, it is out of date
if(!$currentMechanicsD3.Hash.Equals(($mechanicsMD5Response.ToString().Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)[0]),
[System.StringComparison]::InvariantCultureIgnoreCase))
{
Write-Verbose 'Arc Mechanics is out of date'
# copying the current arc Mechanics to a old.bak file for backup
Copy-Item "$($GW2Path)\bin64\d3d9_arcdps_mechanics.dll" -Destination "$($GW2Path)\bin64\d3d9_arcdps_mechanics_old.bak" -Force
# calls the function to download the newest version
DownloadArcMechanics
}
# The hashes match, you currently have the most recent version
else
{
Write-Verbose 'Arc Mechanics is up to date'
}
}
# the file does not exist in the directory, downloading a new copy now
else
{
DownloadArcMechanics
}
}
# ======================== Function Calls and launches GW2 ========================================================
CheckArcUpdates
CheckMechanicsUpdates
Write-Verbose 'Launching Guild Wars 2'
Start-Process -FilePath "$($GW2Path)\$($gw).exe"