Skip to content

Commit 8da7e1a

Browse files
committed
Merge branch 'download_gma'
2 parents bc1d95a + 3704c1a commit 8da7e1a

File tree

6 files changed

+154
-42
lines changed

6 files changed

+154
-42
lines changed

Crowbar/Core/- Application/AppSettings.vb

+17-3
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,18 @@ Public Class AppSettings
296296
End Set
297297
End Property
298298

299+
Public Property DownloadConvertToExpectedFileOrFolderCheckBoxIsChecked() As Boolean
300+
Get
301+
Return Me.theDownloadConvertToExpectedFileOrFolderCheckBoxIsChecked
302+
End Get
303+
Set(ByVal value As Boolean)
304+
If Me.theDownloadConvertToExpectedFileOrFolderCheckBoxIsChecked <> value Then
305+
Me.theDownloadConvertToExpectedFileOrFolderCheckBoxIsChecked = value
306+
NotifyPropertyChanged("DownloadConvertToExpectedFileOrFolderCheckBoxIsChecked")
307+
End If
308+
End Set
309+
End Property
310+
299311
Public Property UnpackPackagePathFolderOrFileName() As String
300312
Get
301313
Return Me.theUnpackPackagePathFolderOrFileName
@@ -1193,10 +1205,10 @@ Public Class AppSettings
11931205

11941206
Public Property OptionsAutoOpenVpkFileOption() As ActionType
11951207
Get
1196-
Return Me.theOptionsAutoOpenvpkFileOption
1208+
Return Me.theOptionsAutoOpenVpkFileOption
11971209
End Get
11981210
Set(ByVal value As ActionType)
1199-
Me.theOptionsAutoOpenvpkFileOption = value
1211+
Me.theOptionsAutoOpenVpkFileOption = value
12001212
NotifyPropertyChanged("OptionsAutoOpenVpkFileOption")
12011213
End Set
12021214
End Property
@@ -1503,6 +1515,7 @@ Public Class AppSettings
15031515
Me.DownloadPrependItemTitleIsChecked = True
15041516
Me.DownloadAppendItemUpdateDateTimeIsChecked = True
15051517
Me.DownloadReplaceSpacesWithUnderscoresIsChecked = True
1518+
Me.DownloadConvertToExpectedFileOrFolderCheckBoxIsChecked = True
15061519
End Sub
15071520

15081521
Public Sub SetDefaultUnpackOutputSubfolderName()
@@ -1672,6 +1685,7 @@ Public Class AppSettings
16721685
Private theDownloadPrependItemTitleIsChecked As Boolean
16731686
Private theDownloadAppendItemUpdateDateTimeIsChecked As Boolean
16741687
Private theDownloadReplaceSpacesWithUnderscoresIsChecked As Boolean
1688+
Private theDownloadConvertToExpectedFileOrFolderCheckBoxIsChecked As Boolean
16751689

16761690
' Unpack tab
16771691

@@ -1804,7 +1818,7 @@ Public Class AppSettings
18041818
' Publish tab
18051819

18061820
Private thePublishGameSelectedIndex As Integer
1807-
Private thePublishSteamAppUserInfos As BindingListExAutoSort(Of SteamAppUserInfo)
1821+
Private thePublishSteamAppUserInfos As BindingListExAutoSort(Of SteamAppUserInfo)
18081822
Private thePublishSearchField As PublishSearchFieldOptions
18091823
Private thePublishSearchText As String
18101824
'Private thePublishDragDroppedContentPath As String

Crowbar/Core/SteamAppInfos/GarrysModSteamAppInfo.vb

+41
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,47 @@ Public Class GarrysModSteamAppInfo
1717
Me.TagsControlType = GetType(GarrysModTagsUserControl)
1818
End Sub
1919

20+
Public Overrides Function ProcessFileAfterDownload(ByVal givenPathFileName As String, ByVal bw As BackgroundWorkerEx) As String
21+
Dim processedPathFileName As String = Path.ChangeExtension(givenPathFileName, ".gma")
22+
23+
bw.ReportProgress(0, "Decompressing downloaded Garry's Mod workshop file into a GMA file." + vbCrLf)
24+
Dim lzmaExeProcess As New Process()
25+
Try
26+
lzmaExeProcess.StartInfo.UseShellExecute = False
27+
'NOTE: From Microsoft website:
28+
' On Windows Vista and earlier versions of the Windows operating system,
29+
' the length of the arguments added to the length of the full path to the process must be less than 2080.
30+
' On Windows 7 and later versions, the length must be less than 32699.
31+
'FROM BAT file: lzma.exe d %1 "%~n1.gma"
32+
lzmaExeProcess.StartInfo.FileName = TheApp.LzmaExePathFileName
33+
lzmaExeProcess.StartInfo.Arguments = "d """ + givenPathFileName + """ """ + processedPathFileName + """"
34+
#If DEBUG Then
35+
lzmaExeProcess.StartInfo.CreateNoWindow = False
36+
#Else
37+
lzmaExeProcess.StartInfo.CreateNoWindow = True
38+
#End If
39+
lzmaExeProcess.Start()
40+
lzmaExeProcess.WaitForExit()
41+
lzmaExeProcess.Close()
42+
Catch ex As Exception
43+
Throw New System.Exception("Crowbar tried to decompress the file """ + givenPathFileName + """ to """ + processedPathFileName + """ but Windows gave this message: " + ex.Message)
44+
Finally
45+
lzmaExeProcess.Close()
46+
bw.ReportProgress(0, "Decompress done." + vbCrLf)
47+
End Try
48+
49+
Try
50+
If File.Exists(givenPathFileName) Then
51+
File.Delete(givenPathFileName)
52+
bw.ReportProgress(0, "Deleted: """ + givenPathFileName + """" + vbCrLf)
53+
End If
54+
Catch ex As Exception
55+
bw.ReportProgress(0, "Crowbar tried to delete the file """ + givenPathFileName + """ but Windows gave this message: " + ex.Message)
56+
End Try
57+
58+
Return processedPathFileName
59+
End Function
60+
2061
Public Overrides Function ProcessFileBeforeUpload(ByVal item As WorkshopItem, ByVal bw As BackgroundWorkerEx) As String
2162
Dim processedPathFileName As String = item.ContentPathFolderOrFileName
2263
Me.theBackgroundWorker = bw

Crowbar/Core/SteamAppInfos/SteamAppInfoBase.vb

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Public Class SteamAppInfoBase
7373
Me.ContentFileExtensionsAndDescriptions = New SortedList(Of String, String)()
7474
End Sub
7575

76-
Public Overridable Function ProcessFileAfterDownload(ByVal givenPathFileName As String) As String
76+
Public Overridable Function ProcessFileAfterDownload(ByVal givenPathFileName As String, ByVal bw As BackgroundWorkerEx) As String
7777
Dim processedPathFileName As String = givenPathFileName
7878
Return processedPathFileName
7979
End Function

Crowbar/Widgets/Main Tabs/DownloadUserControl.Designer.vb

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Crowbar/Widgets/Main Tabs/DownloadUserControl.resx

+3
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,7 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<metadata name="ToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121+
<value>17, 17</value>
122+
</metadata>
120123
</root>

Crowbar/Widgets/Main Tabs/DownloadUserControl.vb

+75-38
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ Public Class DownloadUserControl
6666
Me.theBackgroundSteamPipe.Kill()
6767
End If
6868

69-
'RemoveHandler Me.OutputPathTextBox.DataBindings("Text").Parse, AddressOf FileManager.ParsePathFileName
69+
RemoveHandler Me.OutputPathTextBox.DataBindings("Text").Parse, AddressOf FileManager.ParsePathFileName
7070

7171
RemoveHandler TheApp.Settings.PropertyChanged, AddressOf AppSettings_PropertyChanged
7272

73-
'Me.FreeDownloadOptions()
73+
Me.FreeDownloadOptions()
7474

75-
'Me.FreeOutputPathComboBox()
75+
Me.FreeOutputPathComboBox()
7676

77-
'Me.ItemIdTextBox.DataBindings.Clear()
77+
Me.ItemIdTextBox.DataBindings.Clear()
7878
End Sub
7979

8080
Private Sub InitOutputPathComboBox()
@@ -100,13 +100,15 @@ Public Class DownloadUserControl
100100
Me.PrependTitleCheckBox.DataBindings.Add("Checked", TheApp.Settings, "DownloadPrependItemTitleIsChecked", False, DataSourceUpdateMode.OnPropertyChanged)
101101
Me.AppendDateTimeCheckBox.DataBindings.Add("Checked", TheApp.Settings, "DownloadAppendItemUpdateDateTimeIsChecked", False, DataSourceUpdateMode.OnPropertyChanged)
102102
Me.ReplaceSpacesWithUnderscoresCheckBox.DataBindings.Add("Checked", TheApp.Settings, "DownloadReplaceSpacesWithUnderscoresIsChecked", False, DataSourceUpdateMode.OnPropertyChanged)
103+
Me.ConvertToExpectedFileOrFolderCheckBox.DataBindings.Add("Checked", TheApp.Settings, "DownloadConvertToExpectedFileOrFolderCheckBoxIsChecked", False, DataSourceUpdateMode.OnPropertyChanged)
103104
End Sub
104105

105106
Private Sub FreeDownloadOptions()
106107
Me.UseIdCheckBox.DataBindings.Clear()
107108
Me.PrependTitleCheckBox.DataBindings.Clear()
108109
Me.AppendDateTimeCheckBox.DataBindings.Clear()
109110
Me.ReplaceSpacesWithUnderscoresCheckBox.DataBindings.Clear()
111+
Me.ConvertToExpectedFileOrFolderCheckBox.DataBindings.Clear()
110112
End Sub
111113

112114
#End Region
@@ -180,12 +182,13 @@ Public Class DownloadUserControl
180182
End Sub
181183

182184
Private Sub WebClient_DownloadFileCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
185+
Dim pathFileName As String = CType(e.UserState, String)
186+
183187
If e.Cancelled Then
184188
Me.LogTextBox.AppendText("Download cancelled." + vbCrLf)
185189
Me.DownloadProgressBar.Text = ""
186190
Me.DownloadProgressBar.Value = 0
187191

188-
Dim pathFileName As String = CType(e.UserState, String)
189192
If File.Exists(pathFileName) Then
190193
Try
191194
File.Delete(pathFileName)
@@ -194,15 +197,9 @@ Public Class DownloadUserControl
194197
End Try
195198
End If
196199
Else
197-
Dim pathFileName As String = CType(e.UserState, String)
198200
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
206203
Else
207204
Me.LogTextBox.AppendText("Download failed." + vbCrLf)
208205
End If
@@ -214,6 +211,10 @@ Public Class DownloadUserControl
214211

215212
Me.DownloadButton.Enabled = True
216213
Me.CancelDownloadButton.Enabled = False
214+
215+
If Not e.Cancelled AndAlso File.Exists(pathFileName) Then
216+
Me.ProcessFileAfterDownload(pathFileName)
217+
End If
217218
End Sub
218219

219220
Private Sub DownloadItem_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs)
@@ -260,9 +261,9 @@ Public Class DownloadUserControl
260261

261262
File.WriteAllBytes(outputPathFileName, outputInfo.ContentFile)
262263
If File.Exists(outputPathFileName) Then
263-
Me.ProcessFileAfterDownload(outputPathFileName)
264264
Me.LogTextBox.AppendText("Download complete." + vbCrLf + "Downloaded file: """ + outputPathFileName + """" + vbCrLf)
265265
Me.DownloadedItemTextBox.Text = outputPathFileName
266+
Me.ProcessFileAfterDownload(outputPathFileName)
266267
Else
267268
Me.LogTextBox.AppendText("Download failed." + vbCrLf)
268269
End If
@@ -525,36 +526,32 @@ Public Class DownloadUserControl
525526
Dim jss As JavaScriptSerializer = New JavaScriptSerializer()
526527
Dim root As SteamRemoteStorage_PublishedFileDetails_Json = jss.Deserialize(Of SteamRemoteStorage_PublishedFileDetails_Json)(responseFromServer)
527528
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
531530
itemLink = file_url
532531

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-
550532
Me.theItemTitle = root.response.publishedfiledetails(0).title
551533
Dim fileName As String = root.response.publishedfiledetails(0).filename
552534
Me.theItemContentPathFileName = fileName
553535
Me.theItemIdText = root.response.publishedfiledetails(0).publishedfileid
554536
Me.theItemTimeUpdatedText = root.response.publishedfiledetails(0).time_updated.ToString()
555537
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
558555
Finally
559556
If reader IsNot Nothing Then
560557
reader.Close()
@@ -703,20 +700,60 @@ Public Class DownloadUserControl
703700
End Sub
704701

705702
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
707704
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)
709715
Catch ex As Exception
710716
Me.LogTextBox.AppendText("ERROR: " + ex.Message + vbCrLf)
711717
End Try
712718
End If
713719
End Sub
714720

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+
715751
#End Region
716752

717753
#Region "Data"
718754

719755
Private theWebClient As WebClient
756+
Private theProcessAfterDownloadWorker As BackgroundWorkerEx
720757
Private theAppIdText As String
721758
Private theSteamAppInfo As SteamAppInfoBase
722759

0 commit comments

Comments
 (0)