@@ -66,15 +66,15 @@ Public Class DownloadUserControl
66
66
Me .theBackgroundSteamPipe.Kill()
67
67
End If
68
68
69
- ' RemoveHandler Me.OutputPathTextBox.DataBindings("Text").Parse, AddressOf FileManager.ParsePathFileName
69
+ RemoveHandler Me .OutputPathTextBox.DataBindings( "Text" ).Parse, AddressOf FileManager.ParsePathFileName
70
70
71
71
RemoveHandler TheApp.Settings.PropertyChanged, AddressOf AppSettings_PropertyChanged
72
72
73
- ' Me.FreeDownloadOptions()
73
+ Me .FreeDownloadOptions()
74
74
75
- ' Me.FreeOutputPathComboBox()
75
+ Me .FreeOutputPathComboBox()
76
76
77
- ' Me.ItemIdTextBox.DataBindings.Clear()
77
+ Me .ItemIdTextBox.DataBindings.Clear()
78
78
End Sub
79
79
80
80
Private Sub InitOutputPathComboBox()
@@ -100,13 +100,15 @@ Public Class DownloadUserControl
100
100
Me .PrependTitleCheckBox.DataBindings.Add( "Checked" , TheApp.Settings, "DownloadPrependItemTitleIsChecked" , False , DataSourceUpdateMode.OnPropertyChanged)
101
101
Me .AppendDateTimeCheckBox.DataBindings.Add( "Checked" , TheApp.Settings, "DownloadAppendItemUpdateDateTimeIsChecked" , False , DataSourceUpdateMode.OnPropertyChanged)
102
102
Me .ReplaceSpacesWithUnderscoresCheckBox.DataBindings.Add( "Checked" , TheApp.Settings, "DownloadReplaceSpacesWithUnderscoresIsChecked" , False , DataSourceUpdateMode.OnPropertyChanged)
103
+ Me .ConvertToExpectedFileOrFolderCheckBox.DataBindings.Add( "Checked" , TheApp.Settings, "DownloadConvertToExpectedFileOrFolderCheckBoxIsChecked" , False , DataSourceUpdateMode.OnPropertyChanged)
103
104
End Sub
104
105
105
106
Private Sub FreeDownloadOptions()
106
107
Me .UseIdCheckBox.DataBindings.Clear()
107
108
Me .PrependTitleCheckBox.DataBindings.Clear()
108
109
Me .AppendDateTimeCheckBox.DataBindings.Clear()
109
110
Me .ReplaceSpacesWithUnderscoresCheckBox.DataBindings.Clear()
111
+ Me .ConvertToExpectedFileOrFolderCheckBox.DataBindings.Clear()
110
112
End Sub
111
113
112
114
# End Region
@@ -180,12 +182,13 @@ Public Class DownloadUserControl
180
182
End Sub
181
183
182
184
Private Sub WebClient_DownloadFileCompleted( ByVal sender As Object , ByVal e As AsyncCompletedEventArgs)
185
+ Dim pathFileName As String = CType (e.UserState, String )
186
+
183
187
If e.Cancelled Then
184
188
Me .LogTextBox.AppendText( "Download cancelled." + vbCrLf)
185
189
Me .DownloadProgressBar.Text = ""
186
190
Me .DownloadProgressBar.Value = 0
187
191
188
- Dim pathFileName As String = CType (e.UserState, String )
189
192
If File.Exists(pathFileName) Then
190
193
Try
191
194
File.Delete(pathFileName)
@@ -194,15 +197,9 @@ Public Class DownloadUserControl
194
197
End Try
195
198
End If
196
199
Else
197
- Dim pathFileName As String = CType (e.UserState, String )
198
200
If File.Exists(pathFileName) Then
199
- Me .ProcessFileAfterDownload(pathFileName)
200
- If File.Exists(pathFileName) Then
201
- Me .LogTextBox.AppendText( "Download complete." + vbCrLf + "Downloaded file: """ + pathFileName + """" + vbCrLf)
202
- Me .DownloadedItemTextBox.Text = pathFileName
203
- Else
204
- Me .LogTextBox.AppendText( "Download failed." + vbCrLf)
205
- End If
201
+ Me .LogTextBox.AppendText( "Download complete." + vbCrLf + "Downloaded file: """ + pathFileName + """" + vbCrLf)
202
+ Me .DownloadedItemTextBox.Text = pathFileName
206
203
Else
207
204
Me .LogTextBox.AppendText( "Download failed." + vbCrLf)
208
205
End If
@@ -214,6 +211,10 @@ Public Class DownloadUserControl
214
211
215
212
Me .DownloadButton.Enabled = True
216
213
Me .CancelDownloadButton.Enabled = False
214
+
215
+ If Not e.Cancelled AndAlso File.Exists(pathFileName) Then
216
+ Me .ProcessFileAfterDownload(pathFileName)
217
+ End If
217
218
End Sub
218
219
219
220
Private Sub DownloadItem_ProgressChanged( ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs)
@@ -260,9 +261,9 @@ Public Class DownloadUserControl
260
261
261
262
File.WriteAllBytes(outputPathFileName, outputInfo.ContentFile)
262
263
If File.Exists(outputPathFileName) Then
263
- Me .ProcessFileAfterDownload(outputPathFileName)
264
264
Me .LogTextBox.AppendText( "Download complete." + vbCrLf + "Downloaded file: """ + outputPathFileName + """" + vbCrLf)
265
265
Me .DownloadedItemTextBox.Text = outputPathFileName
266
+ Me .ProcessFileAfterDownload(outputPathFileName)
266
267
Else
267
268
Me .LogTextBox.AppendText( "Download failed." + vbCrLf)
268
269
End If
@@ -525,36 +526,32 @@ Public Class DownloadUserControl
525
526
Dim jss As JavaScriptSerializer = New JavaScriptSerializer()
526
527
Dim root As SteamRemoteStorage_PublishedFileDetails_Json = jss.Deserialize( Of SteamRemoteStorage_PublishedFileDetails_Json)(responseFromServer)
527
528
Dim file_url As String = root.response.publishedfiledetails( 0 ).file_url
528
- If file_url Is Nothing OrElse file_url = "" Then
529
- appID = CUInt(root.response.publishedfiledetails( 0 ).consumer_app_id)
530
- Else
529
+ If file_url IsNot Nothing AndAlso file_url <> "" Then
531
530
itemLink = file_url
532
531
533
- appID = CUInt(root.response.publishedfiledetails( 0 ).consumer_app_id)
534
- Me .theAppIdText = appID.ToString()
535
- Me .theSteamAppInfo = Nothing
536
- Try
537
- If TheApp.Settings.PublishSteamAppUserInfos.Count > 0 Then
538
- 'NOTE: Use this temp var because appID as a ByRef var can not be used in a lambda expression used in next line.
539
- Dim steamAppID As New Steamworks.AppId_t(appID)
540
- Me .theSteamAppInfo = TheApp.SteamAppInfos.First( Function (info) info.ID = steamAppID)
541
- End If
542
- Catch ex As Exception
543
- Dim debug As Integer = 4242
544
- End Try
545
- If Me .theSteamAppInfo Is Nothing Then
546
- 'NOTE: Value was not found, so unable to download.
547
- appID = 0
548
- End If
549
-
550
532
Me .theItemTitle = root.response.publishedfiledetails( 0 ).title
551
533
Dim fileName As String = root.response.publishedfiledetails( 0 ).filename
552
534
Me .theItemContentPathFileName = fileName
553
535
Me .theItemIdText = root.response.publishedfiledetails( 0 ).publishedfileid
554
536
Me .theItemTimeUpdatedText = root.response.publishedfiledetails( 0 ).time_updated.ToString()
555
537
End If
556
- Catch ex As Exception
557
- Dim debug As Integer = 4242
538
+
539
+ appID = CUInt(root.response.publishedfiledetails( 0 ).consumer_app_id)
540
+ Me .theAppIdText = appID.ToString()
541
+ Me .theSteamAppInfo = Nothing
542
+ Try
543
+ If TheApp.Settings.PublishSteamAppUserInfos.Count > 0 Then
544
+ 'NOTE: Use this temp var because appID as a ByRef var can not be used in a lambda expression used in next line.
545
+ Dim steamAppID As New Steamworks.AppId_t(appID)
546
+ Me .theSteamAppInfo = TheApp.SteamAppInfos.First( Function (info) info.ID = steamAppID)
547
+ End If
548
+ Catch ex As Exception
549
+ Dim debug As Integer = 4242
550
+ End Try
551
+ If Me .theSteamAppInfo Is Nothing Then
552
+ 'NOTE: Value was not found, so unable to download.
553
+ appID = 0
554
+ End If
558
555
Finally
559
556
If reader IsNot Nothing Then
560
557
reader.Close()
@@ -703,20 +700,60 @@ Public Class DownloadUserControl
703
700
End Sub
704
701
705
702
Private Sub ProcessFileAfterDownload( ByRef pathFileName As String )
706
- If Me .theSteamAppInfo IsNot Nothing Then
703
+ If Me .theSteamAppInfo IsNot Nothing AndAlso TheApp.Settings.DownloadConvertToExpectedFileOrFolderCheckBoxIsChecked Then
707
704
Try
708
- pathFileName = Me .theSteamAppInfo.ProcessFileAfterDownload(pathFileName)
705
+ Me .DownloadButton.Enabled = False
706
+ Me .CancelDownloadButton.Enabled = True
707
+
708
+ Me .theProcessAfterDownloadWorker = New BackgroundWorkerEx()
709
+ Me .theProcessAfterDownloadWorker.WorkerSupportsCancellation = True
710
+ Me .theProcessAfterDownloadWorker.WorkerReportsProgress = True
711
+ AddHandler Me .theProcessAfterDownloadWorker.DoWork, AddressOf ProcessAfterDownloadWorker_DoWork
712
+ AddHandler Me .theProcessAfterDownloadWorker.ProgressChanged, AddressOf ProcessAfterDownloadWorker_ProgressChanged
713
+ AddHandler Me .theProcessAfterDownloadWorker.RunWorkerCompleted, AddressOf ProcessAfterDownloadWorker_RunWorkerCompleted
714
+ Me .theProcessAfterDownloadWorker.RunWorkerAsync(pathFileName)
709
715
Catch ex As Exception
710
716
Me .LogTextBox.AppendText( "ERROR: " + ex.Message + vbCrLf)
711
717
End Try
712
718
End If
713
719
End Sub
714
720
721
+ 'NOTE: This is run in a background thread.
722
+ Private Sub ProcessAfterDownloadWorker_DoWork( ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
723
+ e.Result = Me .theSteamAppInfo.ProcessFileAfterDownload( CType (e.Argument, String ), Me .theProcessAfterDownloadWorker)
724
+ End Sub
725
+
726
+ Private Sub ProcessAfterDownloadWorker_ProgressChanged( ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs)
727
+ If e.ProgressPercentage = 0 Then
728
+ Me .LogTextBox.AppendText( CStr (e.UserState))
729
+ 'ElseIf e.ProgressPercentage = 1 Then
730
+ ' Me.LogTextBox.AppendText(vbTab + CStr(e.UserState))
731
+ End If
732
+ End Sub
733
+
734
+ Private Sub ProcessAfterDownloadWorker_RunWorkerCompleted( ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs)
735
+ If e.Cancelled Then
736
+ Else
737
+ Dim pathFileName As String = CType (e.Result, String )
738
+ Me .LogTextBox.AppendText( "Final file: """ + pathFileName + """" + vbCrLf)
739
+ Me .DownloadedItemTextBox.Text = pathFileName
740
+ End If
741
+
742
+ RemoveHandler Me .theProcessAfterDownloadWorker.DoWork, AddressOf ProcessAfterDownloadWorker_DoWork
743
+ RemoveHandler Me .theProcessAfterDownloadWorker.ProgressChanged, AddressOf ProcessAfterDownloadWorker_ProgressChanged
744
+ RemoveHandler Me .theProcessAfterDownloadWorker.RunWorkerCompleted, AddressOf ProcessAfterDownloadWorker_RunWorkerCompleted
745
+ Me .theProcessAfterDownloadWorker = Nothing
746
+
747
+ Me .DownloadButton.Enabled = True
748
+ Me .CancelDownloadButton.Enabled = False
749
+ End Sub
750
+
715
751
# End Region
716
752
717
753
# Region "Data"
718
754
719
755
Private theWebClient As WebClient
756
+ Private theProcessAfterDownloadWorker As BackgroundWorkerEx
720
757
Private theAppIdText As String
721
758
Private theSteamAppInfo As SteamAppInfoBase
722
759
0 commit comments