Skip to content

Commit

Permalink
Merge branch 'download_gma'
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeqMacaw committed Oct 27, 2019
2 parents bc1d95a + 3704c1a commit 8da7e1a
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 42 deletions.
20 changes: 17 additions & 3 deletions Crowbar/Core/- Application/AppSettings.vb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ Public Class AppSettings
End Set
End Property

Public Property DownloadConvertToExpectedFileOrFolderCheckBoxIsChecked() As Boolean
Get
Return Me.theDownloadConvertToExpectedFileOrFolderCheckBoxIsChecked
End Get
Set(ByVal value As Boolean)
If Me.theDownloadConvertToExpectedFileOrFolderCheckBoxIsChecked <> value Then
Me.theDownloadConvertToExpectedFileOrFolderCheckBoxIsChecked = value
NotifyPropertyChanged("DownloadConvertToExpectedFileOrFolderCheckBoxIsChecked")
End If
End Set
End Property

Public Property UnpackPackagePathFolderOrFileName() As String
Get
Return Me.theUnpackPackagePathFolderOrFileName
Expand Down Expand Up @@ -1193,10 +1205,10 @@ Public Class AppSettings

Public Property OptionsAutoOpenVpkFileOption() As ActionType
Get
Return Me.theOptionsAutoOpenvpkFileOption
Return Me.theOptionsAutoOpenVpkFileOption
End Get
Set(ByVal value As ActionType)
Me.theOptionsAutoOpenvpkFileOption = value
Me.theOptionsAutoOpenVpkFileOption = value
NotifyPropertyChanged("OptionsAutoOpenVpkFileOption")
End Set
End Property
Expand Down Expand Up @@ -1503,6 +1515,7 @@ Public Class AppSettings
Me.DownloadPrependItemTitleIsChecked = True
Me.DownloadAppendItemUpdateDateTimeIsChecked = True
Me.DownloadReplaceSpacesWithUnderscoresIsChecked = True
Me.DownloadConvertToExpectedFileOrFolderCheckBoxIsChecked = True
End Sub

Public Sub SetDefaultUnpackOutputSubfolderName()
Expand Down Expand Up @@ -1672,6 +1685,7 @@ Public Class AppSettings
Private theDownloadPrependItemTitleIsChecked As Boolean
Private theDownloadAppendItemUpdateDateTimeIsChecked As Boolean
Private theDownloadReplaceSpacesWithUnderscoresIsChecked As Boolean
Private theDownloadConvertToExpectedFileOrFolderCheckBoxIsChecked As Boolean

' Unpack tab

Expand Down Expand Up @@ -1804,7 +1818,7 @@ Public Class AppSettings
' Publish tab

Private thePublishGameSelectedIndex As Integer
Private thePublishSteamAppUserInfos As BindingListExAutoSort(Of SteamAppUserInfo)
Private thePublishSteamAppUserInfos As BindingListExAutoSort(Of SteamAppUserInfo)
Private thePublishSearchField As PublishSearchFieldOptions
Private thePublishSearchText As String
'Private thePublishDragDroppedContentPath As String
Expand Down
41 changes: 41 additions & 0 deletions Crowbar/Core/SteamAppInfos/GarrysModSteamAppInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,47 @@ Public Class GarrysModSteamAppInfo
Me.TagsControlType = GetType(GarrysModTagsUserControl)
End Sub

Public Overrides Function ProcessFileAfterDownload(ByVal givenPathFileName As String, ByVal bw As BackgroundWorkerEx) As String
Dim processedPathFileName As String = Path.ChangeExtension(givenPathFileName, ".gma")

bw.ReportProgress(0, "Decompressing downloaded Garry's Mod workshop file into a GMA file." + vbCrLf)
Dim lzmaExeProcess As New Process()
Try
lzmaExeProcess.StartInfo.UseShellExecute = False
'NOTE: From Microsoft website:
' On Windows Vista and earlier versions of the Windows operating system,
' the length of the arguments added to the length of the full path to the process must be less than 2080.
' On Windows 7 and later versions, the length must be less than 32699.
'FROM BAT file: lzma.exe d %1 "%~n1.gma"
lzmaExeProcess.StartInfo.FileName = TheApp.LzmaExePathFileName
lzmaExeProcess.StartInfo.Arguments = "d """ + givenPathFileName + """ """ + processedPathFileName + """"
#If DEBUG Then
lzmaExeProcess.StartInfo.CreateNoWindow = False
#Else
lzmaExeProcess.StartInfo.CreateNoWindow = True
#End If
lzmaExeProcess.Start()
lzmaExeProcess.WaitForExit()
lzmaExeProcess.Close()
Catch ex As Exception
Throw New System.Exception("Crowbar tried to decompress the file """ + givenPathFileName + """ to """ + processedPathFileName + """ but Windows gave this message: " + ex.Message)
Finally
lzmaExeProcess.Close()
bw.ReportProgress(0, "Decompress done." + vbCrLf)
End Try

Try
If File.Exists(givenPathFileName) Then
File.Delete(givenPathFileName)
bw.ReportProgress(0, "Deleted: """ + givenPathFileName + """" + vbCrLf)
End If
Catch ex As Exception
bw.ReportProgress(0, "Crowbar tried to delete the file """ + givenPathFileName + """ but Windows gave this message: " + ex.Message)
End Try

Return processedPathFileName
End Function

Public Overrides Function ProcessFileBeforeUpload(ByVal item As WorkshopItem, ByVal bw As BackgroundWorkerEx) As String
Dim processedPathFileName As String = item.ContentPathFolderOrFileName
Me.theBackgroundWorker = bw
Expand Down
2 changes: 1 addition & 1 deletion Crowbar/Core/SteamAppInfos/SteamAppInfoBase.vb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Public Class SteamAppInfoBase
Me.ContentFileExtensionsAndDescriptions = New SortedList(Of String, String)()
End Sub

Public Overridable Function ProcessFileAfterDownload(ByVal givenPathFileName As String) As String
Public Overridable Function ProcessFileAfterDownload(ByVal givenPathFileName As String, ByVal bw As BackgroundWorkerEx) As String
Dim processedPathFileName As String = givenPathFileName
Return processedPathFileName
End Function
Expand Down
17 changes: 17 additions & 0 deletions Crowbar/Widgets/Main Tabs/DownloadUserControl.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Crowbar/Widgets/Main Tabs/DownloadUserControl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
113 changes: 75 additions & 38 deletions Crowbar/Widgets/Main Tabs/DownloadUserControl.vb
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ Public Class DownloadUserControl
Me.theBackgroundSteamPipe.Kill()
End If

'RemoveHandler Me.OutputPathTextBox.DataBindings("Text").Parse, AddressOf FileManager.ParsePathFileName
RemoveHandler Me.OutputPathTextBox.DataBindings("Text").Parse, AddressOf FileManager.ParsePathFileName

RemoveHandler TheApp.Settings.PropertyChanged, AddressOf AppSettings_PropertyChanged

'Me.FreeDownloadOptions()
Me.FreeDownloadOptions()

'Me.FreeOutputPathComboBox()
Me.FreeOutputPathComboBox()

'Me.ItemIdTextBox.DataBindings.Clear()
Me.ItemIdTextBox.DataBindings.Clear()
End Sub

Private Sub InitOutputPathComboBox()
Expand All @@ -100,13 +100,15 @@ Public Class DownloadUserControl
Me.PrependTitleCheckBox.DataBindings.Add("Checked", TheApp.Settings, "DownloadPrependItemTitleIsChecked", False, DataSourceUpdateMode.OnPropertyChanged)
Me.AppendDateTimeCheckBox.DataBindings.Add("Checked", TheApp.Settings, "DownloadAppendItemUpdateDateTimeIsChecked", False, DataSourceUpdateMode.OnPropertyChanged)
Me.ReplaceSpacesWithUnderscoresCheckBox.DataBindings.Add("Checked", TheApp.Settings, "DownloadReplaceSpacesWithUnderscoresIsChecked", False, DataSourceUpdateMode.OnPropertyChanged)
Me.ConvertToExpectedFileOrFolderCheckBox.DataBindings.Add("Checked", TheApp.Settings, "DownloadConvertToExpectedFileOrFolderCheckBoxIsChecked", False, DataSourceUpdateMode.OnPropertyChanged)
End Sub

Private Sub FreeDownloadOptions()
Me.UseIdCheckBox.DataBindings.Clear()
Me.PrependTitleCheckBox.DataBindings.Clear()
Me.AppendDateTimeCheckBox.DataBindings.Clear()
Me.ReplaceSpacesWithUnderscoresCheckBox.DataBindings.Clear()
Me.ConvertToExpectedFileOrFolderCheckBox.DataBindings.Clear()
End Sub

#End Region
Expand Down Expand Up @@ -180,12 +182,13 @@ Public Class DownloadUserControl
End Sub

Private Sub WebClient_DownloadFileCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
Dim pathFileName As String = CType(e.UserState, String)

If e.Cancelled Then
Me.LogTextBox.AppendText("Download cancelled." + vbCrLf)
Me.DownloadProgressBar.Text = ""
Me.DownloadProgressBar.Value = 0

Dim pathFileName As String = CType(e.UserState, String)
If File.Exists(pathFileName) Then
Try
File.Delete(pathFileName)
Expand All @@ -194,15 +197,9 @@ Public Class DownloadUserControl
End Try
End If
Else
Dim pathFileName As String = CType(e.UserState, String)
If File.Exists(pathFileName) Then
Me.ProcessFileAfterDownload(pathFileName)
If File.Exists(pathFileName) Then
Me.LogTextBox.AppendText("Download complete." + vbCrLf + "Downloaded file: """ + pathFileName + """" + vbCrLf)
Me.DownloadedItemTextBox.Text = pathFileName
Else
Me.LogTextBox.AppendText("Download failed." + vbCrLf)
End If
Me.LogTextBox.AppendText("Download complete." + vbCrLf + "Downloaded file: """ + pathFileName + """" + vbCrLf)
Me.DownloadedItemTextBox.Text = pathFileName
Else
Me.LogTextBox.AppendText("Download failed." + vbCrLf)
End If
Expand All @@ -214,6 +211,10 @@ Public Class DownloadUserControl

Me.DownloadButton.Enabled = True
Me.CancelDownloadButton.Enabled = False

If Not e.Cancelled AndAlso File.Exists(pathFileName) Then
Me.ProcessFileAfterDownload(pathFileName)
End If
End Sub

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

File.WriteAllBytes(outputPathFileName, outputInfo.ContentFile)
If File.Exists(outputPathFileName) Then
Me.ProcessFileAfterDownload(outputPathFileName)
Me.LogTextBox.AppendText("Download complete." + vbCrLf + "Downloaded file: """ + outputPathFileName + """" + vbCrLf)
Me.DownloadedItemTextBox.Text = outputPathFileName
Me.ProcessFileAfterDownload(outputPathFileName)
Else
Me.LogTextBox.AppendText("Download failed." + vbCrLf)
End If
Expand Down Expand Up @@ -525,36 +526,32 @@ Public Class DownloadUserControl
Dim jss As JavaScriptSerializer = New JavaScriptSerializer()
Dim root As SteamRemoteStorage_PublishedFileDetails_Json = jss.Deserialize(Of SteamRemoteStorage_PublishedFileDetails_Json)(responseFromServer)
Dim file_url As String = root.response.publishedfiledetails(0).file_url
If file_url Is Nothing OrElse file_url = "" Then
appID = CUInt(root.response.publishedfiledetails(0).consumer_app_id)
Else
If file_url IsNot Nothing AndAlso file_url <> "" Then
itemLink = file_url

appID = CUInt(root.response.publishedfiledetails(0).consumer_app_id)
Me.theAppIdText = appID.ToString()
Me.theSteamAppInfo = Nothing
Try
If TheApp.Settings.PublishSteamAppUserInfos.Count > 0 Then
'NOTE: Use this temp var because appID as a ByRef var can not be used in a lambda expression used in next line.
Dim steamAppID As New Steamworks.AppId_t(appID)
Me.theSteamAppInfo = TheApp.SteamAppInfos.First(Function(info) info.ID = steamAppID)
End If
Catch ex As Exception
Dim debug As Integer = 4242
End Try
If Me.theSteamAppInfo Is Nothing Then
'NOTE: Value was not found, so unable to download.
appID = 0
End If

Me.theItemTitle = root.response.publishedfiledetails(0).title
Dim fileName As String = root.response.publishedfiledetails(0).filename
Me.theItemContentPathFileName = fileName
Me.theItemIdText = root.response.publishedfiledetails(0).publishedfileid
Me.theItemTimeUpdatedText = root.response.publishedfiledetails(0).time_updated.ToString()
End If
Catch ex As Exception
Dim debug As Integer = 4242

appID = CUInt(root.response.publishedfiledetails(0).consumer_app_id)
Me.theAppIdText = appID.ToString()
Me.theSteamAppInfo = Nothing
Try
If TheApp.Settings.PublishSteamAppUserInfos.Count > 0 Then
'NOTE: Use this temp var because appID as a ByRef var can not be used in a lambda expression used in next line.
Dim steamAppID As New Steamworks.AppId_t(appID)
Me.theSteamAppInfo = TheApp.SteamAppInfos.First(Function(info) info.ID = steamAppID)
End If
Catch ex As Exception
Dim debug As Integer = 4242
End Try
If Me.theSteamAppInfo Is Nothing Then
'NOTE: Value was not found, so unable to download.
appID = 0
End If
Finally
If reader IsNot Nothing Then
reader.Close()
Expand Down Expand Up @@ -703,20 +700,60 @@ Public Class DownloadUserControl
End Sub

Private Sub ProcessFileAfterDownload(ByRef pathFileName As String)
If Me.theSteamAppInfo IsNot Nothing Then
If Me.theSteamAppInfo IsNot Nothing AndAlso TheApp.Settings.DownloadConvertToExpectedFileOrFolderCheckBoxIsChecked Then
Try
pathFileName = Me.theSteamAppInfo.ProcessFileAfterDownload(pathFileName)
Me.DownloadButton.Enabled = False
Me.CancelDownloadButton.Enabled = True

Me.theProcessAfterDownloadWorker = New BackgroundWorkerEx()
Me.theProcessAfterDownloadWorker.WorkerSupportsCancellation = True
Me.theProcessAfterDownloadWorker.WorkerReportsProgress = True
AddHandler Me.theProcessAfterDownloadWorker.DoWork, AddressOf ProcessAfterDownloadWorker_DoWork
AddHandler Me.theProcessAfterDownloadWorker.ProgressChanged, AddressOf ProcessAfterDownloadWorker_ProgressChanged
AddHandler Me.theProcessAfterDownloadWorker.RunWorkerCompleted, AddressOf ProcessAfterDownloadWorker_RunWorkerCompleted
Me.theProcessAfterDownloadWorker.RunWorkerAsync(pathFileName)
Catch ex As Exception
Me.LogTextBox.AppendText("ERROR: " + ex.Message + vbCrLf)
End Try
End If
End Sub

'NOTE: This is run in a background thread.
Private Sub ProcessAfterDownloadWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
e.Result = Me.theSteamAppInfo.ProcessFileAfterDownload(CType(e.Argument, String), Me.theProcessAfterDownloadWorker)
End Sub

Private Sub ProcessAfterDownloadWorker_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs)
If e.ProgressPercentage = 0 Then
Me.LogTextBox.AppendText(CStr(e.UserState))
'ElseIf e.ProgressPercentage = 1 Then
' Me.LogTextBox.AppendText(vbTab + CStr(e.UserState))
End If
End Sub

Private Sub ProcessAfterDownloadWorker_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs)
If e.Cancelled Then
Else
Dim pathFileName As String = CType(e.Result, String)
Me.LogTextBox.AppendText("Final file: """ + pathFileName + """" + vbCrLf)
Me.DownloadedItemTextBox.Text = pathFileName
End If

RemoveHandler Me.theProcessAfterDownloadWorker.DoWork, AddressOf ProcessAfterDownloadWorker_DoWork
RemoveHandler Me.theProcessAfterDownloadWorker.ProgressChanged, AddressOf ProcessAfterDownloadWorker_ProgressChanged
RemoveHandler Me.theProcessAfterDownloadWorker.RunWorkerCompleted, AddressOf ProcessAfterDownloadWorker_RunWorkerCompleted
Me.theProcessAfterDownloadWorker = Nothing

Me.DownloadButton.Enabled = True
Me.CancelDownloadButton.Enabled = False
End Sub

#End Region

#Region "Data"

Private theWebClient As WebClient
Private theProcessAfterDownloadWorker As BackgroundWorkerEx
Private theAppIdText As String
Private theSteamAppInfo As SteamAppInfoBase

Expand Down

0 comments on commit 8da7e1a

Please sign in to comment.