From 3911cf963fc017834cf2363b03ce4ce01f53f201 Mon Sep 17 00:00:00 2001 From: MikeMaximus Date: Fri, 3 Jun 2022 13:56:21 -0600 Subject: [PATCH] Added process\parameter to ludusavi import --- .../YAML Serialize Classes/Ludusavi.vb | 6 +- GBM/Forms/frmAdvancedImport.vb | 21 ++++-- GBM/Managers/mgrLudusavi.vb | 64 ++++++++++++++++++- 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/GBM/Classes/YAML Serialize Classes/Ludusavi.vb b/GBM/Classes/YAML Serialize Classes/Ludusavi.vb index 38cfc49..ea1a383 100644 --- a/GBM/Classes/YAML Serialize Classes/Ludusavi.vb +++ b/GBM/Classes/YAML Serialize Classes/Ludusavi.vb @@ -75,15 +75,15 @@ Public Class LudusaviPath End Class Public Class LudusaviLaunch - Private oWhen As List(Of LudusaviWhen) + Private oWhen As LudusaviWhen() Private sArguments As String Private sWorkingDir As String - Property [when] As List(Of LudusaviWhen) + Property [when] As LudusaviWhen() Get Return oWhen End Get - Set(value As List(Of LudusaviWhen)) + Set(value As LudusaviWhen()) oWhen = value End Set End Property diff --git a/GBM/Forms/frmAdvancedImport.vb b/GBM/Forms/frmAdvancedImport.vb index ff6e5c6..495e387 100644 --- a/GBM/Forms/frmAdvancedImport.vb +++ b/GBM/Forms/frmAdvancedImport.vb @@ -149,6 +149,7 @@ Public Class frmAdvancedImport Private Sub LoadData(Optional ByVal sFilter As String = "", Optional ByVal bSelectedOnly As Boolean = False) Dim oApp As clsGame Dim oListViewItem As ListViewItem + Dim sProcess As String Dim sTags As String Dim bAddItem As Boolean @@ -174,10 +175,16 @@ Public Class frmAdvancedImport Next sTags = sTags.TrimEnd(New Char() {",", " "}) + If oApp.Parameter <> String.Empty Then + sProcess = oApp.ProcessName & " (" & oApp.Parameter & ")" + Else + sProcess = oApp.ProcessName + End If + If bClassicMode Then - oListViewItem = New ListViewItem(New String() {oApp.Name, oApp.ProcessName, oApp.Path, oApp.FileType, sTags}) + oListViewItem = New ListViewItem(New String() {oApp.Name, sProcess, oApp.Path, oApp.FileType, sTags}) Else - oListViewItem = New ListViewItem(New String() {oApp.Name, oApp.Path, oApp.FileType, oApp.OS.ToString, sTags}) + oListViewItem = New ListViewItem(New String() {oApp.Name, sProcess, oApp.Path, oApp.FileType, oApp.OS.ToString, sTags}) End If oListViewItem.Tag = oApp.ID @@ -241,11 +248,12 @@ Public Class frmAdvancedImport lstGames.Columns(3).Width = Math.Round(lstGames.Size.Width * 0.13) lstGames.Columns(4).Width = Math.Round(lstGames.Size.Width * 0.09) Else - lstGames.Columns(0).Width = Math.Round(lstGames.Size.Width * 0.36) - lstGames.Columns(1).Width = Math.Round(lstGames.Size.Width * 0.29) - lstGames.Columns(2).Width = Math.Round(lstGames.Size.Width * 0.13) - lstGames.Columns(3).Width = Math.Round(lstGames.Size.Width * 0.09) + lstGames.Columns(0).Width = Math.Round(lstGames.Size.Width * 0.3) + lstGames.Columns(1).Width = Math.Round(lstGames.Size.Width * 0.15) + lstGames.Columns(2).Width = Math.Round(lstGames.Size.Width * 0.2) + lstGames.Columns(3).Width = Math.Round(lstGames.Size.Width * 0.13) lstGames.Columns(4).Width = Math.Round(lstGames.Size.Width * 0.09) + lstGames.Columns(5).Width = Math.Round(lstGames.Size.Width * 0.09) End If lstGames.EndUpdate() End If @@ -287,6 +295,7 @@ Public Class frmAdvancedImport lstGames.Columns.Add(frmAdvancedImport_ColumnTags) Else lstGames.Columns.Add(frmAdvancedImport_ColumnName) + lstGames.Columns.Add(frmAdvancedImport_ColumnProcess) lstGames.Columns.Add(frmAdvancedImport_ColumnPath) lstGames.Columns.Add(frmAdvancedImport_ColumnInclude) lstGames.Columns.Add(frmAdvancedImport_ColumnOs) diff --git a/GBM/Managers/mgrLudusavi.vb b/GBM/Managers/mgrLudusavi.vb index fa7e636..490d5ea 100644 --- a/GBM/Managers/mgrLudusavi.vb +++ b/GBM/Managers/mgrLudusavi.vb @@ -37,6 +37,26 @@ Public Class mgrLudusavi Return True End Function + Private Shared Function IsValidProcess(ByVal sProcess As String) As Boolean + Dim sExt As String() = {".bat", ".sh"} + Dim sName As String() = {"launch", "start_protected_game", "dowser"} + Dim s As String + + For Each s In sExt + If sProcess.ToLower.EndsWith(s) Then + Return False + End If + Next + + For Each s In sName + If sProcess.ToLower.Contains(s) Then + Return False + End If + Next + + Return True + End Function + Private Shared Function HasStorePath(ByVal sPath As String) As Boolean Return sPath.Contains("") End Function @@ -184,6 +204,39 @@ Public Class mgrLudusavi oGame.ImportTags.Add(New Tag("Ludusavi")) End Sub + Private Shared Sub HandleLaunch(ByRef oGame As clsGame, ByRef oLudusaviLaunchData As Dictionary(Of String, List(Of LudusaviLaunch)), ByVal sOS As String) + Dim oLudusaviLaunchPair As KeyValuePair(Of String, List(Of LudusaviLaunch)) + Dim oLudusaviLaunch As LudusaviLaunch + Dim sProcess As String = String.Empty + Dim sArguments As String = String.Empty + + If Not oLudusaviLaunchData Is Nothing Then + For Each oLudusaviLaunchPair In oLudusaviLaunchData + For Each oLudusaviLaunch In oLudusaviLaunchPair.Value + If (oLudusaviLaunch.when(0).os Is Nothing Or oLudusaviLaunch.when(0).os = sOS) And (oLudusaviLaunch.when(0).bit = 0 Or oLudusaviLaunch.when(0).bit = 64) Then + sProcess = mgrPath.ValidatePath(oLudusaviLaunchPair.Key.Replace("/", String.Empty)) + If IsValidProcess(sProcess) Then + If sProcess.ToLower.EndsWith(".exe") Then + sProcess = Path.GetFileNameWithoutExtension(sProcess) + Else + sProcess = Path.GetFileName(sProcess) + End If + If Not oLudusaviLaunch.arguments Is Nothing Then + If oLudusaviLaunch.when(0).os = sOS Or oLudusaviLaunch.when(0).os Is Nothing Then + sArguments = oLudusaviLaunch.arguments + End If + End If + Exit For + End If + End If + Next + Next + End If + + oGame.ProcessName = sProcess + oGame.Parameter = sArguments + End Sub + Private Shared Function DetectSupportedStorePaths() As List(Of String) Dim oStores As New List(Of String) @@ -300,8 +353,12 @@ Public Class mgrLudusavi End If HandleTags(oLudusaviPath.tags, w.store, oGame) + If Not (t = TagTypes.config.ToString And oLudusaviPath.tags.Length = 1) Then + HandleLaunch(oGame, oLudusaviGame.launch, w.os) + End If + oConfigurations.Add(oGame) - End If + End If Next End If End If @@ -326,6 +383,9 @@ Public Class mgrLudusavi oGame.OS = clsGame.eOS.Windows HandleTags(oLudusaviPath.tags, Nothing, oGame) + If Not (t = TagTypes.config.ToString And oLudusaviPath.tags.Length = 1) Then + HandleLaunch(oGame, oLudusaviGame.launch, OsTypes.windows.ToString) + End If oConfigurations.Add(oGame) End If Next @@ -387,7 +447,7 @@ Public Class mgrLudusavi Return True Catch ex As Exception - mgrCommon.ShowMessage(mgrLudusavi_ErrorReading, ex.InnerException.Message, MsgBoxStyle.Critical) + mgrCommon.ShowMessage(mgrLudusavi_ErrorReading, ex.Message, MsgBoxStyle.Critical) Return False Finally Cursor.Current = Cursors.Default