forked from Marshallx/Launch-Base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmUpdates.frm
396 lines (386 loc) · 16.9 KB
/
frmUpdates.frm
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmUpdates
BorderStyle = 1 'Fixed Single
Caption = "YR Launch Base: Check For Updates"
ClientHeight = 4770
ClientLeft = 45
ClientTop = 330
ClientWidth = 8985
Icon = "frmUpdates.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4770
ScaleWidth = 8985
StartUpPosition = 2 'CenterScreen
Begin MSComctlLib.ListView listUpdates
Height = 2295
Left = 120
TabIndex = 1
Top = 1200
Width = 8775
_ExtentX = 15478
_ExtentY = 4048
View = 3
LabelEdit = 1
LabelWrap = 0 'False
HideSelection = 0 'False
FullRowSelect = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 0
End
Begin VB.CommandButton cmdCancel
Caption = "Cancel Update Check"
Height = 375
Left = 2880
TabIndex = 3
Top = 4320
Width = 3255
End
Begin VB.CommandButton cmdDownload
Caption = "Download and Install Selected Update"
Height = 375
Left = 2880
TabIndex = 2
Top = 3960
Width = 3255
End
Begin VB.Frame Frame1
Caption = "Update Check Progress"
Height = 975
Left = 120
TabIndex = 0
Top = 120
Width = 8775
End
Begin VB.CommandButton cmdChangeLog
Caption = "View Change Log for Selected Update"
Height = 375
Left = 2880
TabIndex = 4
Top = 3600
Width = 3255
End
Begin MSComctlLib.ProgressBar pbarDownload
Height = 375
Left = 2880
TabIndex = 7
Top = 3960
Width = 3255
_ExtentX = 5741
_ExtentY = 661
_Version = 393216
Appearance = 1
Scrolling = 1
End
Begin VB.Label lblDownloadPercent
Alignment = 1 'Right Justify
Caption = "(0%)"
Height = 255
Left = 5640
TabIndex = 6
Top = 3720
Visible = 0 'False
Width = 495
End
Begin VB.Label lblDownloadAmount
Alignment = 1 'Right Justify
Caption = "0 / 0"
Height = 255
Left = 120
TabIndex = 5
Top = 3720
Visible = 0 'False
Width = 5415
End
End
Attribute VB_Name = "frmUpdates"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Downloading As Boolean
Dim Checking As Boolean
Dim SelfConnect As Boolean
Public CancelDownload As Boolean
Dim UpdateCount As Integer
Dim UpdateDownloadURL() As String
Dim UpdateChangelogURL() As String
Dim UpdateDownloadSize() As Long
Dim UpdateModPath() As String
Dim DownloadSize As Long
Dim ShuttingDown As Boolean
Public Sub CheckForUpdates()
Dim Counter As Integer
Dim RModPath As String
Dim RName As String
Dim RVersion As String
Dim RType As Integer
Dim RTypeStr As String
Dim RFolder As String
Dim RUpdateCheckURL As String
Dim LocalURL As String
Dim PreviousVersion As String
Dim LatestVersion As String
Dim UpdateDownloadURL As String
Dim UpdateDownloadSize As Long
Dim DownloadURL As String
Dim DownloadSize As Long
Dim ChangeLogURL As String
Dim DownloadError As Boolean
Dim ErrVars(0) As Variant
If Not frmMain.CL_noexcept Then On Error GoTo LocalErr
UpdateCount = 0
lblCheckProgress.Caption = "Initializing update check..."
Call listUpdates.ListItems.Clear
listUpdates.Enabled = False
pbarUpdates.Max = frmMain.ModCount + 1
pbarUpdates.Value = 0
cmdDownload.Enabled = False
cmdChangeLog.Enabled = False
cmdCancel.Caption = "Cancel Update Check"
frmUpdates.Refresh
If FreeDiskSpace(GetDriveFromPath(App.Path)) < frmMain.SafetySpace Then
Call frmMain.WriteLogEntry("Insufficient free space to download update check files. Update check aborted.")
Call MsgBox("Not enough free space to download update check files. Update check aborted.", vbOKOnly + vbInformation, App.Title)
Call cmdCancel_Click
Else
If Not Connected Then
lblCheckProgress.Caption = "Establishing Internet connection for update check..."
Call frmMain.WriteLogEntry("Establishing Internet connection for update check.")
frmUpdates.Enabled = False
Call Connect(frmUpdates.hwnd)
SelfConnect = True
frmUpdates.Enabled = True
frmUpdates.SetFocus
Else
SelfConnect = False
End If
If Not Connected Then
SelfConnect = False
Call frmMain.WriteLogEntry("Failed to establish Internet connection. Update check aborted.")
Call MsgBox("The Check For Updates facility requires an internet connection." & vbCrLf & "Please check your connection settings and try again.", vbOKOnly + vbInformation, App.Title)
Call cmdCancel_Click
Else
Checking = True
Call frmMain.WriteLogEntry("Checking for updates.")
CancelDownload = False
For Counter = 0 To frmMain.ModCount
Call frmMain.GetModUpdateDetails(Counter, RModPath, RName, RVersion, RType, RTypeStr, RFolder, RUpdateCheckURL)
If Len(RUpdateCheckURL) <> 0 And Len(RName) <> 0 Then
lblCheckProgress.Caption = "Checking for updates to " & RName & "..."
frmUpdates.Refresh
LocalURL = JoinPath(RFolder, GetFileName(RUpdateCheckURL))
DownloadError = Not CopyURLToFile(RUpdateCheckURL, LocalURL, Me)
If DownloadError Or CancelDownload Then
If FileExists(LocalURL) Then Call Kill(LocalURL)
If CancelDownload Then Exit Sub
Else
If FileExists(LocalURL) Then
Call FlushINI(LocalURL)
PreviousVersion = ReadINIStr("Update", "UpdateableVersion", LocalURL)
LatestVersion = ReadINIStr("Update", "LatestVersion", LocalURL)
ChangeLogURL = ReadINIStr("Update", "ChangeLogURL", LocalURL)
UpdateDownloadURL = ReadINIStr("Update", "UpdateDownloadURL", LocalURL)
UpdateDownloadSize = Val(ReadINIStr("Update", "UpdateDownloadSize", LocalURL, "0"))
DownloadURL = ReadINIStr("Update", "FullDownloadURL", LocalURL)
DownloadSize = Val(ReadINIStr("Update", "FullDownloadSize", LocalURL, "0"))
Call Kill(LocalURL)
If CompareVersions(RVersion, "=", PreviousVersion) And Len(UpdateDownloadURL) <> 0 Then
DownloadURL = UpdateDownloadURL
DownloadSize = UpdateDownloadSize
End If
If Len(LatestVersion) <> 0 And (CompareVersions(RVersion, "<", LatestVersion)) Then Call AddGridRow(RModPath, RTypeStr, RName, RVersion, LatestVersion, DownloadSize, DownloadURL, ChangeLogURL)
End If
End If
End If
pbarUpdates.Value = pbarUpdates.Value + 1
frmUpdates.Refresh
Next Counter
Select Case UpdateCount
Case 0
lblCheckProgress.Caption = "Update check complete. No updates available."
Call frmMain.WriteLogEntry("Update check complete. No updates available.")
Case Else
lblCheckProgress.Caption = "Update check complete. " & PadNum(UpdateCount) & " updates available."
Call frmMain.WriteLogEntry("Update check complete. " & PadNum(UpdateCount) & " updates available.")
listUpdates.ListItems.Item(1).Selected = True
cmdDownload.Enabled = True
Call listUpdates_ItemClick(listUpdates.ListItems.Item(1))
End Select
cmdCancel.Caption = "Back to Launch Menu"
Checking = False
End If
End If
listUpdates.Enabled = True
Exit Sub
LocalErr:
Call frmMain.GlobalErr("CheckForUpdates", ErrVars())
End Sub
Public Sub DownloadProgress(ByVal TotalBytesRead As Long)
If DownloadSize <> 0 Then
If TotalBytesRead > DownloadSize Then
pbarDownload.Value = 100
Else
pbarDownload.Value = (TotalBytesRead / DownloadSize) * 100
End If
lblDownloadAmount.Caption = "Download Progress: " & SizeToString(TotalBytesRead, False) & " / " & SizeToString(DownloadSize)
lblDownloadPercent.Caption = "(" & (Int((TotalBytesRead / DownloadSize) * 100)) & "%)"
Me.Refresh
End If
DoEvents
End Sub
Private Sub AddGridRow(ByVal RModPath As String, ByVal RTypeStr As String, ByVal RName As String, ByVal RVersion As String, ByVal LatestVersion As String, ByVal DownloadSize As Long, ByVal DownloadURL As String, ByVal ChangeLogURL As String)
Call listUpdates.ListItems.Add(, , RName)
listUpdates.ListItems(listUpdates.ListItems.Count).SubItems(1) = RTypeStr
listUpdates.ListItems(listUpdates.ListItems.Count).SubItems(2) = RVersion
listUpdates.ListItems(listUpdates.ListItems.Count).SubItems(3) = LatestVersion
listUpdates.ListItems(listUpdates.ListItems.Count).SubItems(4) = SizeToString(DownloadSize)
UpdateCount = UpdateCount + 1
ReDim Preserve UpdateDownloadURL(UpdateCount)
ReDim Preserve UpdateModPath(UpdateCount)
ReDim Preserve UpdateDownloadSize(UpdateCount)
ReDim Preserve UpdateChangelogURL(UpdateCount)
UpdateDownloadURL(UpdateCount) = DownloadURL
UpdateModPath(UpdateCount) = RModPath
UpdateDownloadSize(UpdateCount) = DownloadSize
UpdateChangelogURL(UpdateCount) = ChangeLogURL
End Sub
Private Sub cmdCancel_Click()
pbarDownload.Visible = False
cmdDownload.Visible = True
cmdChangeLog.Visible = True
lblDownloadAmount.Visible = False
lblDownloadPercent.Visible = False
If Checking Then
Checking = False
CancelDownload = True
Call frmMain.WriteLogEntry("Update check cancelled by user.")
Unload Me
Else
If Downloading Then
Downloading = False
CancelDownload = True
Else
Unload Me
End If
End If
End Sub
Private Sub cmdDownload_Click()
Dim mbResult As VbMsgBoxResult
Dim LocalURL As String
Dim DownloadURL As String
Dim DownloadError As Boolean
Dim ErrVars(0) As Variant
If Not frmMain.CL_noexcept Then On Error GoTo LocalErr
DownloadURL = UpdateDownloadURL(listUpdates.SelectedItem.Index)
LocalURL = JoinPath(UpdateModPath(listUpdates.SelectedItem.Index), GetFileName(DownloadURL))
If FreeDiskSpace(GetDriveFromPath(LocalURL)) < (frmMain.SafetySpace + UpdateDownloadSize(listUpdates.SelectedItem.Index)) Then
Call frmMain.WriteLogEntry("Insufficient free space to download " & DownloadURL & " to " & LocalURL)
Call MsgBox("Insufficient free space to download " & DownloadURL & " to " & LocalURL, vbOKOnly + vbInformation, App.Title)
Else
Downloading = True
cmdDownload.Visible = False
cmdChangeLog.Visible = False
pbarDownload.Value = 0
pbarDownload.Visible = True
frmUpdates.Refresh
listUpdates.Enabled = False
Call frmMain.WriteLogEntry("Downloading " & Quote(DownloadURL) & " to " & Quote(LocalURL))
cmdCancel.Caption = "Cancel Download"
lblDownloadAmount.Visible = True
lblDownloadPercent.Visible = True
CancelDownload = False
DownloadSize = UpdateDownloadSize(listUpdates.SelectedItem.Index)
Call DownloadProgress(0)
DownloadError = Not CopyURLToFile(DownloadURL, LocalURL, Me)
Downloading = False
If CancelDownload Or DownloadError Then
If FileExists(LocalURL) Then Call Kill(LocalURL)
pbarDownload.Value = 0
pbarDownload.Visible = False
cmdDownload.Visible = True
cmdChangeLog.Visible = True
lblDownloadAmount.Visible = False
lblDownloadPercent.Visible = False
cmdCancel.Caption = "Back to Launch Menu"
listUpdates.Enabled = True
If CancelDownload Then
Call frmMain.WriteLogEntry("Download cancelled by user.")
Else
Call frmMain.WriteLogEntry("Download error.")
Call MsgBox("An error occurred downloading the setup program for this mod." & vbCrLf & "The remote file may not exist or your firewall may be blocking the download.", vbOKOnly, App.Title)
End If
Else
If FileExists(LocalURL) Then
If GetFileSize(LocalURL) < UpdateDownloadSize(listUpdates.SelectedItem.Index) Then
Call frmMain.WriteLogEntry("Error downloading " & Quote(DownloadURL) & ". " & Quote(LocalURL) & " has not been saved!")
Call Kill(LocalURL)
Call MsgBox("Error downloading " & Quote(DownloadURL) & vbCrLf & Quote(LocalURL) & " has not been saved!", vbOKOnly + vbExclamation, App.Title)
Call cmdCancel_Click
Else
Call frmMain.WriteLogEntry("Download complete. Executing " & Quote(LocalURL))
mbResult = MsgBox("Launch Base will now close so that " & listUpdates.SelectedItem.Text & " can be updated.", vbOKCancel + vbInformation, App.Title)
If mbResult = vbOK Then
Call frmMain.Shutdown(True)
If SelfConnect Then
If MsgBox("Disconnect Internet connection now?", vbYesNo + vbQuestion, App.Title) = vbYes Then
Call frmMain.WriteLogEntry("Disconnecting Internet connection.")
Call Disconnect
End If
End If
ShuttingDown = True
Call Shell(Quote(LocalURL), vbNormal)
Unload Me
Exit Sub
Else
Call cmdCancel_Click
End If
End If
Else
Call frmMain.WriteLogEntry("Error downloading " & Quote(DownloadURL) & ". " & Quote(LocalURL) & " has not been saved!")
Call MsgBox("Error downloading " & Quote(DownloadURL) & vbCrLf & Quote(LocalURL) & " has not been saved!", vbOKOnly + vbExclamation, App.Title)
Call cmdCancel_Click
End If
End If
End If
Exit Sub
LocalErr:
Call frmMain.GlobalErr("cmdDownload_Click", ErrVars())
End Sub
Private Sub Form_Load()
UpdateCount = 0
Call listUpdates.ColumnHeaders.Add(, , "Name", 3930)
Call listUpdates.ColumnHeaders.Add(, , "Type", 885)
Call listUpdates.ColumnHeaders.Add(, , "Your Version", 1200)
Call listUpdates.ColumnHeaders.Add(, , "Latest Version", 1200)
Call listUpdates.ColumnHeaders.Add(, , "Download Size", 1260)
Downloading = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If Checking Or Downloading Then
Cancel = 1
Call cmdCancel_Click
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not ShuttingDown Then
If SelfConnect Then
If MsgBox("Disconnect Internet connection now?", vbYesNo + vbQuestion, App.Title) = vbYes Then
Call frmMain.WriteLogEntry("Disconnecting Internet connection.")
Call Disconnect
End If
End If
frmMain.Show
frmMain.SetFocus
End If
End Sub
Private Sub listUpdates_ItemClick(ByVal Item As MSComctlLib.ListItem)
cmdChangeLog.Enabled = (Len(UpdateChangelogURL(listUpdates.SelectedItem.Index)) <> 0)
End Sub