From 28a260bdfc1bd138b9457c55e712388c04ebbef3 Mon Sep 17 00:00:00 2001 From: MikeMaximus Date: Thu, 8 Mar 2018 16:02:58 -0600 Subject: [PATCH] Added the ability to launch other processes when a game is detected --- GBM/Classes/clsGameProcess.vb | 22 ++ GBM/Classes/clsProcess.vb | 53 +++ GBM/Forms/frmChooseGame.vb | 6 +- GBM/Forms/frmGameManager.Designer.vb | 28 +- GBM/Forms/frmGameManager.vb | 80 ++-- GBM/Forms/frmGameProcesses.Designer.vb | 142 +++++++ GBM/Forms/frmGameProcesses.resx | 120 ++++++ GBM/Forms/frmGameProcesses.vb | 247 ++++++++++++ GBM/Forms/frmMain.Designer.vb | 24 +- GBM/Forms/frmMain.vb | 118 +++++- GBM/Forms/frmProcessManager.Designer.vb | 241 ++++++++++++ GBM/Forms/frmProcessManager.resx | 120 ++++++ GBM/Forms/frmProcessManager.vb | 371 ++++++++++++++++++ GBM/Game Backup Monitor.vbproj | 24 +- GBM/Managers/mgrGameProcesses.vb | 163 ++++++++ GBM/Managers/mgrMonitorList.vb | 22 +- GBM/Managers/mgrProcess.vb | 152 +++++++ ...mgrProcesses.vb => mgrProcessDetection.vb} | 2 +- GBM/Managers/mgrSQLite.vb | 10 + GBM/My Project/Resources.Designer.vb | 270 +++++++++++++ GBM/My Project/Resources.resx | 90 +++++ GBM/readme.txt | 10 + 22 files changed, 2254 insertions(+), 61 deletions(-) create mode 100644 GBM/Classes/clsGameProcess.vb create mode 100644 GBM/Classes/clsProcess.vb create mode 100644 GBM/Forms/frmGameProcesses.Designer.vb create mode 100644 GBM/Forms/frmGameProcesses.resx create mode 100644 GBM/Forms/frmGameProcesses.vb create mode 100644 GBM/Forms/frmProcessManager.Designer.vb create mode 100644 GBM/Forms/frmProcessManager.resx create mode 100644 GBM/Forms/frmProcessManager.vb create mode 100644 GBM/Managers/mgrGameProcesses.vb create mode 100644 GBM/Managers/mgrProcess.vb rename GBM/Managers/{mgrProcesses.vb => mgrProcessDetection.vb} (99%) diff --git a/GBM/Classes/clsGameProcess.vb b/GBM/Classes/clsGameProcess.vb new file mode 100644 index 0000000..ef33eb9 --- /dev/null +++ b/GBM/Classes/clsGameProcess.vb @@ -0,0 +1,22 @@ +Public Class clsGameProcess + Private sProcessID As String + Private sMonitorID As String + + Public Property ProcessID As String + Get + Return sProcessID + End Get + Set(value As String) + sProcessID = value + End Set + End Property + + Public Property MonitorID As String + Get + Return sMonitorID + End Get + Set(value As String) + sMonitorID = value + End Set + End Property +End Class diff --git a/GBM/Classes/clsProcess.vb b/GBM/Classes/clsProcess.vb new file mode 100644 index 0000000..bae66d1 --- /dev/null +++ b/GBM/Classes/clsProcess.vb @@ -0,0 +1,53 @@ + +Public Class clsProcess + Private sProcessID As String = Guid.NewGuid.ToString + Private sName As String = String.Empty + Private sPath As String = String.Empty + Private sArgs As String = String.Empty + Private bKill As Boolean = True + + Public Property ID As String + Get + Return sProcessID + End Get + Set(value As String) + sProcessID = value + End Set + End Property + + Public Property Name As String + Get + Return sName + End Get + Set(value As String) + sName = value + End Set + End Property + + Public Property Path As String + Get + Return sPath + End Get + Set(value As String) + sPath = value + End Set + End Property + + Public Property Args As String + Get + Return sArgs + End Get + Set(value As String) + sArgs = value + End Set + End Property + + Public Property Kill As Boolean + Get + Return bKill + End Get + Set(value As Boolean) + bKill = value + End Set + End Property +End Class diff --git a/GBM/Forms/frmChooseGame.vb b/GBM/Forms/frmChooseGame.vb index f79125e..ef6f040 100644 --- a/GBM/Forms/frmChooseGame.vb +++ b/GBM/Forms/frmChooseGame.vb @@ -2,16 +2,16 @@ Public Class frmChooseGame - Private oProcess As mgrProcesses + Private oProcess As mgrProcessDetection Private oGame As clsGame Private oGamesHash As New Hashtable Private bGameSelected As Boolean = False - Property Process As mgrProcesses + Property Process As mgrProcessDetection Get Return oProcess End Get - Set(value As mgrProcesses) + Set(value As mgrProcessDetection) oProcess = value End Set End Property diff --git a/GBM/Forms/frmGameManager.Designer.vb b/GBM/Forms/frmGameManager.Designer.vb index b2c2604..7d28f4d 100644 --- a/GBM/Forms/frmGameManager.Designer.vb +++ b/GBM/Forms/frmGameManager.Designer.vb @@ -28,6 +28,7 @@ Partial Class frmGameManager Me.btnBackup = New System.Windows.Forms.Button() Me.btnClose = New System.Windows.Forms.Button() Me.grpConfig = New System.Windows.Forms.GroupBox() + Me.btnGameID = New System.Windows.Forms.Button() Me.chkRegEx = New System.Windows.Forms.CheckBox() Me.lblComments = New System.Windows.Forms.Label() Me.txtComments = New System.Windows.Forms.TextBox() @@ -101,7 +102,7 @@ Partial Class frmGameManager Me.cmsDeleteBackup = New System.Windows.Forms.ContextMenuStrip(Me.components) Me.cmsDeleteOne = New System.Windows.Forms.ToolStripMenuItem() Me.cmsDeleteAll = New System.Windows.Forms.ToolStripMenuItem() - Me.btnGameID = New System.Windows.Forms.Button() + Me.btnProcesses = New System.Windows.Forms.Button() Me.grpConfig.SuspendLayout() CType(Me.nudLimit, System.ComponentModel.ISupportInitialize).BeginInit() Me.grpExtra.SuspendLayout() @@ -190,6 +191,15 @@ Partial Class frmGameManager Me.grpConfig.TabStop = False Me.grpConfig.Text = "Configuration" ' + 'btnGameID + ' + Me.btnGameID.Location = New System.Drawing.Point(402, 17) + Me.btnGameID.Name = "btnGameID" + Me.btnGameID.Size = New System.Drawing.Size(117, 23) + Me.btnGameID.TabIndex = 2 + Me.btnGameID.Text = "&Game ID..." + Me.btnGameID.UseVisualStyleBackColor = True + ' 'chkRegEx ' Me.chkRegEx.AutoSize = True @@ -875,20 +885,21 @@ Partial Class frmGameManager Me.cmsDeleteAll.Size = New System.Drawing.Size(114, 22) Me.cmsDeleteAll.Text = "&All Files" ' - 'btnGameID + 'btnProcesses ' - Me.btnGameID.Location = New System.Drawing.Point(402, 17) - Me.btnGameID.Name = "btnGameID" - Me.btnGameID.Size = New System.Drawing.Size(117, 23) - Me.btnGameID.TabIndex = 2 - Me.btnGameID.Text = "&Game ID..." - Me.btnGameID.UseVisualStyleBackColor = True + Me.btnProcesses.Location = New System.Drawing.Point(454, 437) + Me.btnProcesses.Name = "btnProcesses" + Me.btnProcesses.Size = New System.Drawing.Size(75, 23) + Me.btnProcesses.TabIndex = 20 + Me.btnProcesses.Text = "Processes..." + Me.btnProcesses.UseVisualStyleBackColor = True ' 'frmGameManager ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(784, 661) + Me.Controls.Add(Me.btnProcesses) Me.Controls.Add(Me.lblQuickFilter) Me.Controls.Add(Me.txtQuickFilter) Me.Controls.Add(Me.btnExport) @@ -1012,4 +1023,5 @@ Partial Class frmGameManager Friend WithEvents txtComments As TextBox Friend WithEvents chkRegEx As CheckBox Friend WithEvents btnGameID As Button + Friend WithEvents btnProcesses As Button End Class diff --git a/GBM/Forms/frmGameManager.vb b/GBM/Forms/frmGameManager.vb index f1fb9c2..1f97e83 100644 --- a/GBM/Forms/frmGameManager.vb +++ b/GBM/Forms/frmGameManager.vb @@ -10,6 +10,7 @@ Public Class frmGameManager Private oCurrentBackupItem As clsBackup Private oCurrentGame As clsGame Private oTagsToSave As New List(Of KeyValuePair(Of String, String)) + Private oProcessesToSave As New List(Of KeyValuePair(Of String, String)) Private bDisableExternalFunctions As Boolean = False Private bTriggerBackup As Boolean = False Private bTriggerRestore As Boolean = False @@ -35,7 +36,6 @@ Public Class frmGameManager Add = 3 Disabled = 4 MultiSelect = 5 - ViewTemp = 6 End Enum Private eCurrentMode As eModes = eModes.Disabled @@ -581,6 +581,36 @@ Public Class frmGameManager End If End Sub + Private Sub OpenProcesses() + Dim frm As New frmGameProcesses + Dim oApp As clsGame + Dim sMonitorIDS As New List(Of String) + + If eCurrentMode = eModes.Add Then + 'Use a dummy ID + sMonitorIDS.Add(Guid.NewGuid.ToString) + frm.GameName = txtName.Text + frm.NewMode = True + frm.ProcessList = oProcessesToSave + Else + For Each oData In lstGames.SelectedItems + oApp = DirectCast(GameData(oData.Key), clsGame) + sMonitorIDS.Add(oApp.ID) + Next + frm.GameName = CurrentGame.Name + frm.NewMode = False + End If + + frm.IDList = sMonitorIDS + frm.ShowDialog() + + If eCurrentMode = eModes.Add Then + oProcessesToSave = frm.ProcessList + Else + ModeChange() + End If + End Sub + Private Sub OpenTags() Dim frm As New frmGameTags Dim oApp As clsGame @@ -917,6 +947,7 @@ Public Class frmGameManager chkEnabled.Checked = True chkMonitorOnly.Checked = False btnTags.Enabled = True + btnProcesses.Enabled = True lblTags.Text = String.Empty lblTags.Visible = True btnInclude.Text = frmGameManager_btnInclude @@ -944,6 +975,7 @@ Public Class frmGameManager btnOpenBackupFile.Enabled = False btnOpenRestorePath.Enabled = False btnTags.Enabled = True + btnProcesses.Enabled = True lblTags.Visible = True btnImport.Enabled = False btnExport.Enabled = False @@ -963,31 +995,10 @@ Public Class frmGameManager btnDelete.Enabled = True btnBackup.Enabled = True btnTags.Enabled = True + btnProcesses.Enabled = True lblTags.Visible = True btnImport.Enabled = True btnExport.Enabled = True - Case eModes.ViewTemp - grpFilter.Enabled = True - lstGames.Enabled = True - lblQuickFilter.Enabled = True - txtQuickFilter.Enabled = True - grpConfig.Enabled = False - chkEnabled.Enabled = False - chkMonitorOnly.Enabled = False - grpExtra.Enabled = False - grpStats.Enabled = True - btnSave.Enabled = False - btnCancel.Enabled = False - btnAdd.Enabled = True - btnDelete.Enabled = False - btnBackup.Enabled = False - btnOpenRestorePath.Enabled = False - btnTags.Enabled = False - lblTags.Visible = False - btnInclude.Text = frmGameManager_btnInclude - btnExclude.Text = frmGameManager_btnExclude - btnImport.Enabled = True - btnExport.Enabled = True Case eModes.Disabled grpFilter.Enabled = True lstGames.Enabled = True @@ -1010,6 +1021,7 @@ Public Class frmGameManager btnRestore.Enabled = False btnMarkAsRestored.Enabled = False btnTags.Enabled = False + btnProcesses.Enabled = False lblTags.Visible = False btnInclude.Text = frmGameManager_btnInclude btnExclude.Text = frmGameManager_btnExclude @@ -1041,6 +1053,7 @@ Public Class frmGameManager btnRestore.Enabled = True btnMarkAsRestored.Enabled = True btnTags.Enabled = True + btnProcesses.Enabled = True lblTags.Visible = False btnImport.Enabled = True btnExport.Enabled = True @@ -1150,6 +1163,22 @@ Public Class frmGameManager End If End Sub + Private Sub SaveProcesses(ByVal sID As String) + Dim oGameProcess As clsGameProcess + Dim oGameProcesses As List(Of clsGameProcess) + + If oProcessesToSave.Count > 0 Then + oGameProcesses = New List(Of clsGameProcess) + For Each kp As KeyValuePair(Of String, String) In oProcessesToSave + oGameProcess = New clsGameProcess + oGameProcess.MonitorID = sID + oGameProcess.ProcessID = kp.Key + oGameProcesses.Add(oGameProcess) + Next + mgrGameProcesses.DoGameProcessAddBatch(oGameProcesses) + End If + End Sub + Private Sub SaveTags(ByVal sID As String) Dim oGameTag As clsGameTag Dim oGameTags As List(Of clsGameTag) @@ -1210,6 +1239,7 @@ Public Class frmGameManager bSuccess = True mgrMonitorList.DoListAdd(oApp) SaveTags(oApp.ID) + SaveProcesses(oApp.ID) eCurrentMode = eModes.View End If Case eModes.Edit @@ -1696,6 +1726,10 @@ Public Class frmGameManager OpenTags() End Sub + Private Sub btnProcesses_Click(sender As Object, e As EventArgs) Handles btnProcesses.Click + OpenProcesses() + End Sub + Private Sub btnDeleteBackup_Click(sender As Object, e As EventArgs) Handles btnDeleteBackup.Click If cboRemoteBackup.Items.Count > 1 Then cmsDeleteBackup.Show(btnDeleteBackup, New Drawing.Point(btnDeleteBackup.Size.Width - Math.Floor(btnDeleteBackup.Size.Width * 0.1), btnDeleteBackup.Size.Height - Math.Floor(btnDeleteBackup.Size.Height * 0.5)), ToolStripDropDownDirection.AboveRight) diff --git a/GBM/Forms/frmGameProcesses.Designer.vb b/GBM/Forms/frmGameProcesses.Designer.vb new file mode 100644 index 0000000..090fc0e --- /dev/null +++ b/GBM/Forms/frmGameProcesses.Designer.vb @@ -0,0 +1,142 @@ + _ +Partial Class frmGameProcesses + Inherits System.Windows.Forms.Form + + 'Form overrides dispose to clean up the component list. + _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + 'Required by the Windows Form Designer + Private components As System.ComponentModel.IContainer + + 'NOTE: The following procedure is required by the Windows Form Designer + 'It can be modified using the Windows Form Designer. + 'Do not modify it using the code editor. + _ + Private Sub InitializeComponent() + Me.btnOpenProcesses = New System.Windows.Forms.Button() + Me.btnClose = New System.Windows.Forms.Button() + Me.lblGameProcesses = New System.Windows.Forms.Label() + Me.lblProcesses = New System.Windows.Forms.Label() + Me.btnRemove = New System.Windows.Forms.Button() + Me.btnAdd = New System.Windows.Forms.Button() + Me.lstGameProcesses = New System.Windows.Forms.ListBox() + Me.lstProcesses = New System.Windows.Forms.ListBox() + Me.SuspendLayout() + ' + 'btnOpenProcesses + ' + Me.btnOpenProcesses.Location = New System.Drawing.Point(12, 229) + Me.btnOpenProcesses.Name = "btnOpenProcesses" + Me.btnOpenProcesses.Size = New System.Drawing.Size(110, 23) + Me.btnOpenProcesses.TabIndex = 12 + Me.btnOpenProcesses.Text = "&Process Manager..." + Me.btnOpenProcesses.UseVisualStyleBackColor = True + ' + 'btnClose + ' + Me.btnClose.Location = New System.Drawing.Point(297, 229) + Me.btnClose.Name = "btnClose" + Me.btnClose.Size = New System.Drawing.Size(75, 23) + Me.btnClose.TabIndex = 13 + Me.btnClose.Text = "&Close" + Me.btnClose.UseVisualStyleBackColor = True + ' + 'lblGameProcesses + ' + Me.lblGameProcesses.AutoSize = True + Me.lblGameProcesses.Location = New System.Drawing.Point(251, 8) + Me.lblGameProcesses.Name = "lblGameProcesses" + Me.lblGameProcesses.Size = New System.Drawing.Size(93, 13) + Me.lblGameProcesses.TabIndex = 6 + Me.lblGameProcesses.Text = "Current Processes" + ' + 'lblProcesses + ' + Me.lblProcesses.AutoSize = True + Me.lblProcesses.Location = New System.Drawing.Point(36, 8) + Me.lblProcesses.Name = "lblProcesses" + Me.lblProcesses.Size = New System.Drawing.Size(102, 13) + Me.lblProcesses.TabIndex = 7 + Me.lblProcesses.Text = "Available Processes" + ' + 'btnRemove + ' + Me.btnRemove.Location = New System.Drawing.Point(168, 114) + Me.btnRemove.Name = "btnRemove" + Me.btnRemove.Size = New System.Drawing.Size(48, 23) + Me.btnRemove.TabIndex = 10 + Me.btnRemove.Text = "<" + Me.btnRemove.UseVisualStyleBackColor = True + ' + 'btnAdd + ' + Me.btnAdd.Location = New System.Drawing.Point(168, 85) + Me.btnAdd.Name = "btnAdd" + Me.btnAdd.Size = New System.Drawing.Size(48, 23) + Me.btnAdd.TabIndex = 9 + Me.btnAdd.Text = ">" + Me.btnAdd.UseVisualStyleBackColor = True + ' + 'lstGameProcesses + ' + Me.lstGameProcesses.FormattingEnabled = True + Me.lstGameProcesses.Location = New System.Drawing.Point(222, 24) + Me.lstGameProcesses.Name = "lstGameProcesses" + Me.lstGameProcesses.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended + Me.lstGameProcesses.Size = New System.Drawing.Size(150, 199) + Me.lstGameProcesses.Sorted = True + Me.lstGameProcesses.TabIndex = 11 + ' + 'lstProcesses + ' + Me.lstProcesses.FormattingEnabled = True + Me.lstProcesses.Location = New System.Drawing.Point(12, 24) + Me.lstProcesses.Name = "lstProcesses" + Me.lstProcesses.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended + Me.lstProcesses.Size = New System.Drawing.Size(150, 199) + Me.lstProcesses.Sorted = True + Me.lstProcesses.TabIndex = 8 + ' + 'frmGameProcesses + ' + Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) + Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.ClientSize = New System.Drawing.Size(384, 261) + Me.Controls.Add(Me.btnOpenProcesses) + Me.Controls.Add(Me.btnClose) + Me.Controls.Add(Me.lblGameProcesses) + Me.Controls.Add(Me.lblProcesses) + Me.Controls.Add(Me.btnRemove) + Me.Controls.Add(Me.btnAdd) + Me.Controls.Add(Me.lstGameProcesses) + Me.Controls.Add(Me.lstProcesses) + Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle + Me.MaximizeBox = False + Me.MinimizeBox = False + Me.Name = "frmGameProcesses" + Me.ShowIcon = False + Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen + Me.Text = "Edit Processes" + Me.ResumeLayout(False) + Me.PerformLayout() + + End Sub + + Friend WithEvents btnOpenProcesses As Button + Friend WithEvents btnClose As Button + Friend WithEvents lblGameProcesses As Label + Friend WithEvents lblProcesses As Label + Friend WithEvents btnRemove As Button + Friend WithEvents btnAdd As Button + Friend WithEvents lstGameProcesses As ListBox + Friend WithEvents lstProcesses As ListBox +End Class diff --git a/GBM/Forms/frmGameProcesses.resx b/GBM/Forms/frmGameProcesses.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/GBM/Forms/frmGameProcesses.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GBM/Forms/frmGameProcesses.vb b/GBM/Forms/frmGameProcesses.vb new file mode 100644 index 0000000..b621990 --- /dev/null +++ b/GBM/Forms/frmGameProcesses.vb @@ -0,0 +1,247 @@ +Imports GBM.My.Resources + +Public Class frmGameProcesses + Private sMonitorIDs As List(Of String) + Private sGameName As String = String.Empty + Private bNewMode As Boolean = False + Private oProcessList As List(Of KeyValuePair(Of String, String)) + + Public Property IDList As List(Of String) + Get + Return sMonitorIDs + End Get + Set(value As List(Of String)) + sMonitorIDs = value + End Set + End Property + + Public Property GameName As String + Get + Return sGameName + End Get + Set(value As String) + sGameName = value + End Set + End Property + + Public Property NewMode As Boolean + Get + Return bNewMode + End Get + Set(value As Boolean) + bNewMode = value + End Set + End Property + + Public Property ProcessList As List(Of KeyValuePair(Of String, String)) + Get + Return oProcessList + End Get + Set(value As List(Of KeyValuePair(Of String, String))) + oProcessList = value + End Set + End Property + + Private Sub AddProcess() + Dim oData As KeyValuePair(Of String, String) + Dim oProcesss As List(Of KeyValuePair(Of String, String)) + Dim oGameProcess As clsGameProcess + Dim oGameProcesses As List(Of clsGameProcess) + + If lstProcesses.SelectedItems.Count = 1 Then + oData = lstProcesses.SelectedItems(0) + + oGameProcesses = New List(Of clsGameProcess) + For Each sID As String In IDList + oGameProcess = New clsGameProcess + oGameProcess.MonitorID = sID + oGameProcess.ProcessID = oData.Key + oGameProcesses.Add(oGameProcess) + Next + + If Not bNewMode Then mgrGameProcesses.DoGameProcessAddBatch(oGameProcesses) + + lstGameProcesses.Items.Add(oData) + lstProcesses.Items.Remove(oData) + ElseIf lstProcesses.SelectedItems.Count > 1 Then + oProcesss = New List(Of KeyValuePair(Of String, String)) + + For Each oData In lstProcesses.SelectedItems + oProcesss.Add(oData) + Next + + For Each kp As KeyValuePair(Of String, String) In oProcesss + oGameProcesses = New List(Of clsGameProcess) + For Each sID As String In IDList + oGameProcess = New clsGameProcess + oGameProcess.MonitorID = sID + oGameProcess.ProcessID = kp.Key + oGameProcesses.Add(oGameProcess) + Next + + If Not bNewMode Then mgrGameProcesses.DoGameProcessAddBatch(oGameProcesses) + + lstGameProcesses.Items.Add(kp) + lstProcesses.Items.Remove(kp) + Next + End If + + End Sub + + Private Sub RemoveProcess() + Dim oData As KeyValuePair(Of String, String) + Dim oProcesses As List(Of KeyValuePair(Of String, String)) + Dim oGameProcess As clsGameProcess + Dim oGameProcesses As List(Of clsGameProcess) + + If lstGameProcesses.SelectedItems.Count = 1 Then + oData = lstGameProcesses.SelectedItems(0) + + oGameProcesses = New List(Of clsGameProcess) + For Each sID As String In IDList + oGameProcess = New clsGameProcess + oGameProcess.MonitorID = sID + oGameProcess.ProcessID = oData.Key + oGameProcesses.Add(oGameProcess) + Next + + If Not bNewMode Then mgrGameProcesses.DoGameProcessDelete(oGameProcesses) + + lstGameProcesses.Items.Remove(oData) + lstProcesses.Items.Add(oData) + ElseIf lstGameProcesses.SelectedItems.Count > 1 Then + oProcesses = New List(Of KeyValuePair(Of String, String)) + + For Each oData In lstGameProcesses.SelectedItems + oProcesses.Add(oData) + Next + + For Each kp As KeyValuePair(Of String, String) In oProcesses + oGameProcesses = New List(Of clsGameProcess) + For Each sID As String In IDList + oGameProcess = New clsGameProcess + oGameProcess.MonitorID = sID + oGameProcess.ProcessID = kp.Key + oGameProcesses.Add(oGameProcess) + Next + + If Not bNewMode Then mgrGameProcesses.DoGameProcessDelete(oGameProcesses) + + lstGameProcesses.Items.Remove(kp) + lstProcesses.Items.Add(kp) + Next + End If + + End Sub + + Private Sub LoadData() + Dim hshProcesses As Hashtable + Dim hshGameProcesses As Hashtable + Dim oProcess As clsProcess + Dim oData As KeyValuePair(Of String, String) + + 'Load Processes + hshProcesses = mgrProcess.ReadProcesses() + + 'Handle Lists + lstProcesses.Items.Clear() + lstGameProcesses.Items.Clear() + + lstProcesses.ValueMember = "Key" + lstProcesses.DisplayMember = "Value" + lstGameProcesses.ValueMember = "Key" + lstGameProcesses.DisplayMember = "Value" + + If bNewMode Then + For Each kp As KeyValuePair(Of String, String) In oProcessList + 'We need to be sure the tags still exist if the "Process Manager" form was used + If hshProcesses.ContainsKey(kp.Value) Then + lstGameProcesses.Items.Add(kp) + End If + Next + + For Each kp As KeyValuePair(Of String, String) In oProcessList + If hshProcesses.ContainsKey(kp.Value) Then + hshProcesses.Remove(kp.Value) + End If + Next + Else + hshGameProcesses = mgrGameProcesses.GetProcessesByGameMulti(IDList) + + For Each de As DictionaryEntry In hshGameProcesses + oProcess = DirectCast(de.Value, clsProcess) + If hshProcesses.ContainsKey(oProcess.Name) Then + hshProcesses.Remove(oProcess.Name) + End If + Next + + For Each de As DictionaryEntry In hshGameProcesses + oProcess = DirectCast(de.Value, clsProcess) + oData = New KeyValuePair(Of String, String)(oProcess.ID, oProcess.Name) + lstGameProcesses.Items.Add(oData) + Next + End If + + For Each de As DictionaryEntry In hshProcesses + oProcess = DirectCast(de.Value, clsProcess) + oData = New KeyValuePair(Of String, String)(oProcess.ID, oProcess.Name) + lstProcesses.Items.Add(oData) + Next + + End Sub + + Private Sub BuildProcessList() + Dim oData As KeyValuePair(Of String, String) + oProcessList.Clear() + For Each oData In lstGameProcesses.Items + oProcessList.Add(oData) + Next + End Sub + + Private Sub OpenProcessManager() + Dim frm As New frmProcessManager + frm.ShowDialog() + LoadData() + End Sub + + Private Sub SetForm() + 'Set Form Name + If IDList.Count > 1 Then + Me.Text = frmGameProcesses_FormNameMulti + Else + Me.Text = mgrCommon.FormatString(frmGameProcesses_FormNameSingle, GameName) + End If + + 'Set Form Text + btnOpenProcesses.Text = frmGameProcesses_btnOpenProcesses + btnClose.Text = frmGameProcesses_btnClose + lblGameProcesses.Text = frmGameProcesses_lblGameProccesses + lblProcesses.Text = frmGameProcesses_lblProcesses + btnRemove.Text = frmGameProcesses_btnRemove + btnAdd.Text = frmGameProcesses_btnAdd + + End Sub + + Private Sub frmGameProcesses_Load(sender As Object, e As EventArgs) Handles MyBase.Load + LoadData() + SetForm() + End Sub + + Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click + If bNewMode Then BuildProcessList() + Me.Close() + End Sub + + Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click + AddProcess() + End Sub + + Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click + RemoveProcess() + End Sub + + Private Sub btnOpenProcesses_Click(sender As Object, e As EventArgs) Handles btnOpenProcesses.Click + If bNewMode Then BuildProcessList() + OpenProcessManager() + End Sub +End Class \ No newline at end of file diff --git a/GBM/Forms/frmMain.Designer.vb b/GBM/Forms/frmMain.Designer.vb index 83816fb..d95579d 100644 --- a/GBM/Forms/frmMain.Designer.vb +++ b/GBM/Forms/frmMain.Designer.vb @@ -36,6 +36,7 @@ Partial Class frmMain Me.gMonTraySetupGameManager = New System.Windows.Forms.ToolStripMenuItem() Me.gMonTraySetupCustomVariables = New System.Windows.Forms.ToolStripMenuItem() Me.gMonTraySetupTags = New System.Windows.Forms.ToolStripMenuItem() + Me.gMonTraySetupProcessManager = New System.Windows.Forms.ToolStripMenuItem() Me.gMonTrayTools = New System.Windows.Forms.ToolStripMenuItem() Me.gMonTrayToolsCompact = New System.Windows.Forms.ToolStripMenuItem() Me.gMonTrayToolsLog = New System.Windows.Forms.ToolStripMenuItem() @@ -65,6 +66,7 @@ Partial Class frmMain Me.gMonSetupAddWizard = New System.Windows.Forms.ToolStripMenuItem() Me.gMonSetupCustomVariables = New System.Windows.Forms.ToolStripMenuItem() Me.gMonSetupTags = New System.Windows.Forms.ToolStripMenuItem() + Me.gMonSetupProcessManager = New System.Windows.Forms.ToolStripMenuItem() Me.gMonTools = New System.Windows.Forms.ToolStripMenuItem() Me.gMonToolsCompact = New System.Windows.Forms.ToolStripMenuItem() Me.gMonToolsLog = New System.Windows.Forms.ToolStripMenuItem() @@ -143,7 +145,7 @@ Partial Class frmMain ' 'gMonTraySetup ' - Me.gMonTraySetup.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.gMonTraySetupAddWizard, Me.gMonTraySetupGameManager, Me.gMonTraySetupCustomVariables, Me.gMonTraySetupTags}) + Me.gMonTraySetup.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.gMonTraySetupAddWizard, Me.gMonTraySetupGameManager, Me.gMonTraySetupCustomVariables, Me.gMonTraySetupTags, Me.gMonTraySetupProcessManager}) Me.gMonTraySetup.Name = "gMonTraySetup" Me.gMonTraySetup.Size = New System.Drawing.Size(161, 22) Me.gMonTraySetup.Text = "&Setup" @@ -172,6 +174,12 @@ Partial Class frmMain Me.gMonTraySetupTags.Size = New System.Drawing.Size(201, 22) Me.gMonTraySetupTags.Text = "&Tags..." ' + 'gMonTraySetupProcessManager + ' + Me.gMonTraySetupProcessManager.Name = "gMonTraySetupProcessManager" + Me.gMonTraySetupProcessManager.Size = New System.Drawing.Size(201, 22) + Me.gMonTraySetupProcessManager.Text = "Process &Manager..." + ' 'gMonTrayTools ' Me.gMonTrayTools.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.gMonTrayToolsCompact, Me.gMonTrayToolsLog, Me.gMonTrayToolsSessions, Me.gMonTrayToolsSyncGameID}) @@ -342,7 +350,7 @@ Partial Class frmMain ' 'gMonSetup ' - Me.gMonSetup.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.gMonSetupGameManager, Me.gMonSetupAddWizard, Me.gMonSetupCustomVariables, Me.gMonSetupTags}) + Me.gMonSetup.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.gMonSetupGameManager, Me.gMonSetupAddWizard, Me.gMonSetupCustomVariables, Me.gMonSetupTags, Me.gMonSetupProcessManager}) Me.gMonSetup.Name = "gMonSetup" Me.gMonSetup.Size = New System.Drawing.Size(49, 20) Me.gMonSetup.Text = "&Setup" @@ -371,6 +379,12 @@ Partial Class frmMain Me.gMonSetupTags.Size = New System.Drawing.Size(201, 22) Me.gMonSetupTags.Text = "&Tags..." ' + 'gMonSetupProcessManager + ' + Me.gMonSetupProcessManager.Name = "gMonSetupProcessManager" + Me.gMonSetupProcessManager.Size = New System.Drawing.Size(201, 22) + Me.gMonSetupProcessManager.Text = "Process &Manager..." + ' 'gMonTools ' Me.gMonTools.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.gMonToolsCompact, Me.gMonToolsLog, Me.gMonToolsSessions, Me.gMonToolsSyncGameID}) @@ -419,13 +433,13 @@ Partial Class frmMain 'gMonToolsSyncGameIDOfficial ' Me.gMonToolsSyncGameIDOfficial.Name = "gMonToolsSyncGameIDOfficial" - Me.gMonToolsSyncGameIDOfficial.Size = New System.Drawing.Size(152, 22) + Me.gMonToolsSyncGameIDOfficial.Size = New System.Drawing.Size(142, 22) Me.gMonToolsSyncGameIDOfficial.Text = "&Official List..." ' 'gMonToolsSyncGameIDFile ' Me.gMonToolsSyncGameIDFile.Name = "gMonToolsSyncGameIDFile" - Me.gMonToolsSyncGameIDFile.Size = New System.Drawing.Size(152, 22) + Me.gMonToolsSyncGameIDFile.Size = New System.Drawing.Size(142, 22) Me.gMonToolsSyncGameIDFile.Text = "&File..." ' 'gMonHelp @@ -671,4 +685,6 @@ Partial Class frmMain Friend WithEvents gMonTrayToolsSyncGameID As ToolStripMenuItem Friend WithEvents gMonTrayToolsSyncGameIDOfficial As ToolStripMenuItem Friend WithEvents gMonTrayToolsSyncGameIDFile As ToolStripMenuItem + Friend WithEvents gMonTraySetupProcessManager As ToolStripMenuItem + Friend WithEvents gMonSetupProcessManager As ToolStripMenuItem End Class diff --git a/GBM/Forms/frmMain.vb b/GBM/Forms/frmMain.vb index f4784eb..77628f7 100644 --- a/GBM/Forms/frmMain.vb +++ b/GBM/Forms/frmMain.vb @@ -40,6 +40,7 @@ Public Class frmMain Private sPriorCompany As String Private sPriorVersion As String Private iRestoreTimeOut As Integer + Private oChildProcesses As New Hashtable Private wState As FormWindowState = FormWindowState.Normal 'Developer Debug Flags @@ -52,7 +53,7 @@ Public Class frmMain WithEvents tmRestoreCheck As New System.Timers.Timer WithEvents tmFileWatcherQueue As New System.Timers.Timer - Public WithEvents oProcess As New mgrProcesses + Public WithEvents oProcess As New mgrProcessDetection Public WithEvents oBackup As New mgrBackup Public WithEvents oRestore As New mgrRestore Public hshScanList As Hashtable @@ -844,6 +845,13 @@ Public Class frmMain ResumeScan() End Sub + Private Sub OpenProcessManager() + Dim frm As New frmProcessManager + PauseScan() + frm.ShowDialog() + ResumeScan() + End Sub + Private Sub OpenGameManager(Optional ByVal bPendingRestores As Boolean = False) Dim frm As New frmGameManager PauseScan() @@ -1381,6 +1389,7 @@ Public Class frmMain gMonSetupAddWizard.Text = frmMain_gMonSetupAddWizard gMonSetupCustomVariables.Text = frmMain_gMonSetupCustomVariables gMonSetupTags.Text = frmMain_gMonSetupTags + gMonSetupProcessManager.Text = frmMain_gMonSetupProcessManager gMonTools.Text = frmMain_gMonTools gMonToolsCompact.Text = frmMain_gMonToolsCompact gMonToolsLog.Text = frmMain_gMonToolsLog @@ -1405,6 +1414,7 @@ Public Class frmMain gMonTraySetupAddWizard.Text = frmMain_gMonSetupAddWizard gMonTraySetupCustomVariables.Text = frmMain_gMonSetupCustomVariables gMonTraySetupTags.Text = frmMain_gMonSetupTags + gMonTraySetupProcessManager.Text = frmMain_gMonSetupProcessManager gMonTrayTools.Text = frmMain_gMonTools gMonTrayToolsCompact.Text = frmMain_gMonToolsCompact gMonTrayToolsLog.Text = frmMain_gMonToolsLog @@ -1439,6 +1449,60 @@ Public Class frmMain ResetGameInfo() End Sub + Private Function BuildChildProcesses() As Integer + Dim oCurrentProcess As clsProcess + Dim oProcessList As Hashtable + Dim prsChild As Process + + oChildProcesses.Clear() + + oProcessList = mgrGameProcesses.GetProcessesByGame(oProcess.GameInfo.ID) + + If oProcessList.Count > 0 Then + For Each oCurrentProcess In oProcessList.Values + prsChild = New Process + prsChild.StartInfo.Arguments = oCurrentProcess.Args + prsChild.StartInfo.FileName = oCurrentProcess.Path + prsChild.StartInfo.UseShellExecute = False + prsChild.StartInfo.RedirectStandardOutput = True + prsChild.StartInfo.CreateNoWindow = True + oChildProcesses.Add(oCurrentProcess, prsChild) + Next + End If + + Return oChildProcesses.Count + End Function + + Private Sub StartChildProcesses() + Dim prsChild As Process + + Try + For Each prsChild In oChildProcesses.Values + prsChild.Start() + Next + Catch ex As Exception + UpdateLog(mgrCommon.FormatString(frmMain_ErrorStartChildProcess, oProcess.GameInfo.CroppedName), True, ToolTipIcon.Error) + UpdateLog(mgrCommon.FormatString(App_GenericError, ex.Message), False,, False) + End Try + End Sub + + Private Sub EndChildProcesses() + Dim oCurrentProcess As clsProcess + Dim prsChild As Process + + Try + For Each de As DictionaryEntry In oChildProcesses + oCurrentProcess = DirectCast(de.Key, clsProcess) + prsChild = DirectCast(de.Value, Process) + prsChild.Kill() + Next + + Catch ex As Exception + UpdateLog(mgrCommon.FormatString(frmMain_ErrorEndChildProcess, oProcess.GameInfo.CroppedName), True, ToolTipIcon.Error) + UpdateLog(mgrCommon.FormatString(App_GenericError, ex.Message), False,, False) + End Try + End Sub + 'Functions that control the scanning for games Private Sub StartScan() tmScanTimer.Interval = 5000 @@ -1684,6 +1748,10 @@ Public Class frmMain OpenTags() End Sub + Private Sub gMonSetupProcessManager_Click(sender As Object, e As EventArgs) Handles gMonSetupProcessManager.Click, gMonTraySetupProcessManager.Click + OpenProcessManager() + End Sub + Private Sub gMonHelpAbout_Click(sender As Object, e As EventArgs) Handles gMonHelpAbout.Click OpenAbout() End Sub @@ -1712,6 +1780,14 @@ Public Class frmMain OpenSessions() End Sub + Private Sub gMonToolsSyncGameIDOfficial_Click(sender As Object, e As EventArgs) Handles gMonToolsSyncGameIDOfficial.Click, gMonTrayToolsSyncGameIDOfficial.Click + SyncGameIDs(True) + End Sub + + Private Sub gMonToolsSyncGameIDFile_Click(sender As Object, e As EventArgs) Handles gMonToolsSyncGameIDFile.Click, gMonTrayToolsSyncGameIDFile.Click + SyncGameIDs(False) + End Sub + Private Sub gMonNotification_Click(sender As Object, e As EventArgs) Handles gMonNotification.Click, gMonTrayNotification.Click gMonNotification.Visible = False gMonTrayNotification.Visible = False @@ -1810,18 +1886,23 @@ Public Class frmMain If bContinue = True Then CheckForSavedDuplicate() If oProcess.Duplicate Then - UpdateLog(frmMain_MultipleGamesDetected, oSettings.ShowDetectionToolTips) - UpdateStatus(frmMain_MultipleGamesDetected) - SetGameInfo(True) - Else - UpdateLog(mgrCommon.FormatString(frmMain_GameDetected, oProcess.GameInfo.Name), oSettings.ShowDetectionToolTips) - UpdateStatus(mgrCommon.FormatString(frmMain_GameDetected, oProcess.GameInfo.CroppedName)) - SetGameInfo() - End If - oProcess.StartTime = Now - bwMonitor.RunWorkerAsync() + UpdateLog(frmMain_MultipleGamesDetected, oSettings.ShowDetectionToolTips) + UpdateStatus(frmMain_MultipleGamesDetected) + SetGameInfo(True) Else - StopScan() + UpdateLog(mgrCommon.FormatString(frmMain_GameDetected, oProcess.GameInfo.Name), oSettings.ShowDetectionToolTips) + UpdateStatus(mgrCommon.FormatString(frmMain_GameDetected, oProcess.GameInfo.CroppedName)) + SetGameInfo() + End If + + If BuildChildProcesses() > 0 Then + StartChildProcesses() + End If + + oProcess.StartTime = Now + bwMonitor.RunWorkerAsync() + Else + StopScan() End If End If End Sub @@ -1843,6 +1924,11 @@ Public Class frmMain Private Sub bwMain_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bwMonitor.RunWorkerCompleted Dim bContinue As Boolean = True + + If oChildProcesses.Count > 0 Then + EndChildProcesses() + End If + oProcess.EndTime = Now If Not bCancelledByUser Then @@ -1948,12 +2034,4 @@ Public Class frmMain 'Move focus to first label lblGameTitle.Focus() End Sub - - Private Sub gMonToolsSyncGameIDOfficial_Click(sender As Object, e As EventArgs) Handles gMonToolsSyncGameIDOfficial.Click, gMonTrayToolsSyncGameIDOfficial.Click - SyncGameIDs(True) - End Sub - - Private Sub gMonToolsSyncGameIDFile_Click(sender As Object, e As EventArgs) Handles gMonToolsSyncGameIDFile.Click, gMonTrayToolsSyncGameIDFile.Click - SyncGameIDs(False) - End Sub End Class \ No newline at end of file diff --git a/GBM/Forms/frmProcessManager.Designer.vb b/GBM/Forms/frmProcessManager.Designer.vb new file mode 100644 index 0000000..c461335 --- /dev/null +++ b/GBM/Forms/frmProcessManager.Designer.vb @@ -0,0 +1,241 @@ + _ +Partial Class frmProcessManager + Inherits System.Windows.Forms.Form + + 'Form overrides dispose to clean up the component list. + _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + 'Required by the Windows Form Designer + Private components As System.ComponentModel.IContainer + + 'NOTE: The following procedure is required by the Windows Form Designer + 'It can be modified using the Windows Form Designer. + 'Do not modify it using the code editor. + _ + Private Sub InitializeComponent() + Me.grpProcess = New System.Windows.Forms.GroupBox() + Me.txtArguments = New System.Windows.Forms.TextBox() + Me.lblArguments = New System.Windows.Forms.Label() + Me.btnProcessBrowse = New System.Windows.Forms.Button() + Me.txtName = New System.Windows.Forms.TextBox() + Me.txtPath = New System.Windows.Forms.TextBox() + Me.lblProcess = New System.Windows.Forms.Label() + Me.lblName = New System.Windows.Forms.Label() + Me.btnClose = New System.Windows.Forms.Button() + Me.btnDelete = New System.Windows.Forms.Button() + Me.btnAdd = New System.Windows.Forms.Button() + Me.lstProcesses = New System.Windows.Forms.ListBox() + Me.txtID = New System.Windows.Forms.TextBox() + Me.btnCancel = New System.Windows.Forms.Button() + Me.btnSave = New System.Windows.Forms.Button() + Me.chkKillProcess = New System.Windows.Forms.CheckBox() + Me.grpProcess.SuspendLayout() + Me.SuspendLayout() + ' + 'grpProcess + ' + Me.grpProcess.Controls.Add(Me.chkKillProcess) + Me.grpProcess.Controls.Add(Me.txtArguments) + Me.grpProcess.Controls.Add(Me.lblArguments) + Me.grpProcess.Controls.Add(Me.btnProcessBrowse) + Me.grpProcess.Controls.Add(Me.txtName) + Me.grpProcess.Controls.Add(Me.txtPath) + Me.grpProcess.Controls.Add(Me.lblProcess) + Me.grpProcess.Controls.Add(Me.lblName) + Me.grpProcess.Location = New System.Drawing.Point(238, 12) + Me.grpProcess.Name = "grpProcess" + Me.grpProcess.Size = New System.Drawing.Size(334, 120) + Me.grpProcess.TabIndex = 11 + Me.grpProcess.TabStop = False + Me.grpProcess.Text = "Configuration" + ' + 'txtArguments + ' + Me.txtArguments.Location = New System.Drawing.Point(72, 70) + Me.txtArguments.Name = "txtArguments" + Me.txtArguments.Size = New System.Drawing.Size(256, 20) + Me.txtArguments.TabIndex = 5 + ' + 'lblArguments + ' + Me.lblArguments.AutoSize = True + Me.lblArguments.Location = New System.Drawing.Point(6, 73) + Me.lblArguments.Name = "lblArguments" + Me.lblArguments.Size = New System.Drawing.Size(60, 13) + Me.lblArguments.TabIndex = 4 + Me.lblArguments.Text = "Arguments:" + ' + 'btnProcessBrowse + ' + Me.btnProcessBrowse.Location = New System.Drawing.Point(298, 45) + Me.btnProcessBrowse.Name = "btnProcessBrowse" + Me.btnProcessBrowse.Size = New System.Drawing.Size(30, 20) + Me.btnProcessBrowse.TabIndex = 3 + Me.btnProcessBrowse.Text = "..." + Me.btnProcessBrowse.UseVisualStyleBackColor = True + ' + 'txtName + ' + Me.txtName.Location = New System.Drawing.Point(72, 19) + Me.txtName.Name = "txtName" + Me.txtName.Size = New System.Drawing.Size(256, 20) + Me.txtName.TabIndex = 1 + ' + 'txtPath + ' + Me.txtPath.Location = New System.Drawing.Point(72, 45) + Me.txtPath.Name = "txtPath" + Me.txtPath.Size = New System.Drawing.Size(220, 20) + Me.txtPath.TabIndex = 2 + ' + 'lblProcess + ' + Me.lblProcess.AutoSize = True + Me.lblProcess.Location = New System.Drawing.Point(6, 48) + Me.lblProcess.Name = "lblProcess" + Me.lblProcess.Size = New System.Drawing.Size(48, 13) + Me.lblProcess.TabIndex = 1 + Me.lblProcess.Text = "Process:" + ' + 'lblName + ' + Me.lblName.AutoSize = True + Me.lblName.Location = New System.Drawing.Point(6, 22) + Me.lblName.Name = "lblName" + Me.lblName.Size = New System.Drawing.Size(38, 13) + Me.lblName.TabIndex = 0 + Me.lblName.Text = "Name:" + ' + 'btnClose + ' + Me.btnClose.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) + Me.btnClose.Location = New System.Drawing.Point(497, 226) + Me.btnClose.Name = "btnClose" + Me.btnClose.Size = New System.Drawing.Size(75, 23) + Me.btnClose.TabIndex = 14 + Me.btnClose.Text = "C&lose" + Me.btnClose.UseVisualStyleBackColor = True + ' + 'btnDelete + ' + Me.btnDelete.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) + Me.btnDelete.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.btnDelete.Location = New System.Drawing.Point(48, 226) + Me.btnDelete.Name = "btnDelete" + Me.btnDelete.Size = New System.Drawing.Size(30, 23) + Me.btnDelete.TabIndex = 10 + Me.btnDelete.Text = "-" + Me.btnDelete.UseVisualStyleBackColor = True + ' + 'btnAdd + ' + Me.btnAdd.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) + Me.btnAdd.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.btnAdd.Location = New System.Drawing.Point(12, 226) + Me.btnAdd.Name = "btnAdd" + Me.btnAdd.Size = New System.Drawing.Size(30, 23) + Me.btnAdd.TabIndex = 9 + Me.btnAdd.Text = "+" + Me.btnAdd.UseVisualStyleBackColor = True + ' + 'lstProcesses + ' + Me.lstProcesses.FormattingEnabled = True + Me.lstProcesses.Location = New System.Drawing.Point(12, 12) + Me.lstProcesses.Name = "lstProcesses" + Me.lstProcesses.Size = New System.Drawing.Size(220, 212) + Me.lstProcesses.Sorted = True + Me.lstProcesses.TabIndex = 7 + ' + 'txtID + ' + Me.txtID.Enabled = False + Me.txtID.Location = New System.Drawing.Point(374, 150) + Me.txtID.Name = "txtID" + Me.txtID.Size = New System.Drawing.Size(33, 20) + Me.txtID.TabIndex = 8 + Me.txtID.TabStop = False + Me.txtID.Visible = False + ' + 'btnCancel + ' + Me.btnCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) + Me.btnCancel.Location = New System.Drawing.Point(494, 149) + Me.btnCancel.Name = "btnCancel" + Me.btnCancel.Size = New System.Drawing.Size(75, 23) + Me.btnCancel.TabIndex = 13 + Me.btnCancel.Text = "&Cancel" + Me.btnCancel.UseVisualStyleBackColor = True + ' + 'btnSave + ' + Me.btnSave.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) + Me.btnSave.Location = New System.Drawing.Point(413, 149) + Me.btnSave.Name = "btnSave" + Me.btnSave.Size = New System.Drawing.Size(75, 23) + Me.btnSave.TabIndex = 12 + Me.btnSave.Text = "&Save" + Me.btnSave.UseVisualStyleBackColor = True + ' + 'chkKillProcess + ' + Me.chkKillProcess.AutoSize = True + Me.chkKillProcess.Location = New System.Drawing.Point(72, 96) + Me.chkKillProcess.Name = "chkKillProcess" + Me.chkKillProcess.Size = New System.Drawing.Size(184, 17) + Me.chkKillProcess.TabIndex = 6 + Me.chkKillProcess.Text = "Kill process when game is closed." + Me.chkKillProcess.UseVisualStyleBackColor = True + ' + 'frmProcessManager + ' + Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) + Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.ClientSize = New System.Drawing.Size(584, 261) + Me.Controls.Add(Me.grpProcess) + Me.Controls.Add(Me.btnClose) + Me.Controls.Add(Me.btnDelete) + Me.Controls.Add(Me.btnAdd) + Me.Controls.Add(Me.lstProcesses) + Me.Controls.Add(Me.txtID) + Me.Controls.Add(Me.btnCancel) + Me.Controls.Add(Me.btnSave) + Me.MaximizeBox = False + Me.MinimizeBox = False + Me.Name = "frmProcessManager" + Me.ShowIcon = False + Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen + Me.Text = "Process Manager" + Me.grpProcess.ResumeLayout(False) + Me.grpProcess.PerformLayout() + Me.ResumeLayout(False) + Me.PerformLayout() + + End Sub + + Friend WithEvents grpProcess As GroupBox + Friend WithEvents txtArguments As TextBox + Friend WithEvents lblArguments As Label + Friend WithEvents btnProcessBrowse As Button + Friend WithEvents txtName As TextBox + Friend WithEvents txtPath As TextBox + Friend WithEvents lblProcess As Label + Friend WithEvents lblName As Label + Friend WithEvents btnClose As Button + Friend WithEvents btnDelete As Button + Friend WithEvents btnAdd As Button + Friend WithEvents lstProcesses As ListBox + Friend WithEvents txtID As TextBox + Friend WithEvents btnCancel As Button + Friend WithEvents btnSave As Button + Friend WithEvents chkKillProcess As CheckBox +End Class diff --git a/GBM/Forms/frmProcessManager.resx b/GBM/Forms/frmProcessManager.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/GBM/Forms/frmProcessManager.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GBM/Forms/frmProcessManager.vb b/GBM/Forms/frmProcessManager.vb new file mode 100644 index 0000000..cc56904 --- /dev/null +++ b/GBM/Forms/frmProcessManager.vb @@ -0,0 +1,371 @@ +Imports GBM.My.Resources +Imports System.IO + +Public Class frmProcessManager + Dim hshProcessData As Hashtable + Private bIsDirty As Boolean = False + Private bIsLoading As Boolean = False + Private oCurrentProcess As clsProcess + + Private Property IsDirty As Boolean + Get + Return bIsDirty + End Get + Set(value As Boolean) + bIsDirty = value + End Set + End Property + + Private Property IsLoading As Boolean + Get + Return bIsLoading + End Get + Set(value As Boolean) + bIsLoading = value + End Set + End Property + + Private Enum eModes As Integer + View = 1 + Edit = 2 + Add = 3 + Disabled = 4 + End Enum + + Private eCurrentMode As eModes = eModes.Disabled + + Private Property ProcessData As Hashtable + Get + Return hshProcessData + End Get + Set(value As Hashtable) + hshProcessData = value + End Set + End Property + + Private Sub ProcessBrowse() + Dim sDefaultFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + Dim sCurrentPath As String = txtPath.Text + Dim sNewPath As String + + If sCurrentPath <> String.Empty Then + sCurrentPath = Path.GetDirectoryName(txtPath.Text) + If Directory.Exists(sCurrentPath) Then + sDefaultFolder = sCurrentPath + End If + End If + + sNewPath = mgrCommon.OpenFileBrowser("PM_Process", frmProcessManager_ChooseProcess, "exe", + frmProcessManager_Executable, sDefaultFolder, False, True) + + If sNewPath <> String.Empty Then + txtPath.Text = sNewPath + End If + + End Sub + + Private Sub LoadData() + ProcessData = mgrProcess.ReadProcesses + lstProcesses.Items.Clear() + FormatAndFillList() + End Sub + + Private Function HandleDirty() As MsgBoxResult + Dim oResult As MsgBoxResult + + oResult = mgrCommon.ShowMessage(App_ConfirmDirty, MsgBoxStyle.YesNoCancel) + + Select Case oResult + Case MsgBoxResult.Yes + IsDirty = False + Case MsgBoxResult.No + IsDirty = False + Case MsgBoxResult.Cancel + 'No Change + End Select + + Return oResult + + End Function + + Private Sub FormatAndFillList() + IsLoading = True + + For Each oProcess As clsProcess In ProcessData.Values + lstProcesses.Items.Add(oProcess.Name) + Next + + IsLoading = False + End Sub + + Private Sub FillData() + IsLoading = True + + oCurrentProcess = DirectCast(ProcessData(lstProcesses.SelectedItems(0).ToString), clsProcess) + + txtID.Text = oCurrentProcess.ID + txtName.Text = oCurrentProcess.Name + txtPath.Text = oCurrentProcess.Path + txtArguments.Text = oCurrentProcess.Args + chkKillProcess.Checked = oCurrentProcess.Kill + + IsLoading = False + End Sub + + Private Sub DirtyCheck_ValueChanged(sender As Object, e As EventArgs) + If Not IsLoading Then + IsDirty = True + If Not eCurrentMode = eModes.Add Then EditProcess() + End If + End Sub + + Private Sub AssignDirtyHandlers(ByVal oCtls As GroupBox.ControlCollection) + For Each ctl As Control In oCtls + If TypeOf ctl Is TextBox Then + AddHandler DirectCast(ctl, TextBox).TextChanged, AddressOf DirtyCheck_ValueChanged + End If + Next + End Sub + + Private Sub WipeControls(ByVal oCtls As GroupBox.ControlCollection) + For Each ctl As Control In oCtls + If TypeOf ctl Is TextBox Then + DirectCast(ctl, TextBox).Text = String.Empty + End If + Next + txtID.Text = String.Empty + End Sub + + Private Sub ModeChange() + IsLoading = True + + Select Case eCurrentMode + Case eModes.Add + grpProcess.Enabled = True + WipeControls(grpProcess.Controls) + btnSave.Enabled = True + btnCancel.Enabled = True + btnAdd.Enabled = False + btnDelete.Enabled = False + lstProcesses.Enabled = False + chkKillProcess.Checked = True + Case eModes.Edit + lstProcesses.Enabled = False + grpProcess.Enabled = True + btnSave.Enabled = True + btnCancel.Enabled = True + btnAdd.Enabled = False + btnDelete.Enabled = False + Case eModes.View + lstProcesses.Enabled = True + grpProcess.Enabled = True + btnSave.Enabled = False + btnCancel.Enabled = False + btnAdd.Enabled = True + btnDelete.Enabled = True + Case eModes.Disabled + lstProcesses.Enabled = True + WipeControls(grpProcess.Controls) + grpProcess.Enabled = False + btnSave.Enabled = False + btnCancel.Enabled = False + btnAdd.Enabled = True + btnDelete.Enabled = True + End Select + + IsLoading = False + End Sub + + Private Sub EditProcess() + eCurrentMode = eModes.Edit + ModeChange() + End Sub + + Private Sub AddProcess() + eCurrentMode = eModes.Add + ModeChange() + txtName.Focus() + End Sub + + Private Sub CancelEdit() + If bIsDirty Then + Select Case HandleDirty() + Case MsgBoxResult.Yes + SaveProcess() + Case MsgBoxResult.No + If lstProcesses.SelectedItems.Count > 0 Then + eCurrentMode = eModes.View + ModeChange() + FillData() + lstProcesses.Focus() + Else + eCurrentMode = eModes.Disabled + ModeChange() + End If + Case MsgBoxResult.Cancel + 'Do Nothing + End Select + Else + If lstProcesses.SelectedItems.Count > 0 Then + eCurrentMode = eModes.View + ModeChange() + FillData() + lstProcesses.Focus() + Else + eCurrentMode = eModes.Disabled + ModeChange() + End If + End If + End Sub + + Private Sub SaveProcess() + Dim oProcess As New clsProcess + Dim bSuccess As Boolean = False + + If txtID.Text <> String.Empty Then + oProcess.ID = txtID.Text + End If + oProcess.Name = txtName.Text + oProcess.Path = txtPath.Text + oProcess.Args = txtArguments.Text + oProcess.Kill = chkKillProcess.Checked + + Select Case eCurrentMode + Case eModes.Add + If CoreValidatation(oProcess) Then + bSuccess = True + mgrProcess.DoProcessAdd(oProcess) + eCurrentMode = eModes.View + End If + Case eModes.Edit + If CoreValidatation(oProcess) Then + bSuccess = True + mgrProcess.DoProcessUpdate(oProcess) + eCurrentMode = eModes.View + End If + End Select + + If bSuccess Then + IsDirty = False + LoadData() + ModeChange() + If eCurrentMode = eModes.View Then lstProcesses.SelectedIndex = lstProcesses.Items.IndexOf(oProcess.Name) + End If + End Sub + + Private Sub DeleteProcess() + Dim oProcess As clsProcess + + If lstProcesses.SelectedItems.Count > 0 Then + oProcess = DirectCast(ProcessData(lstProcesses.SelectedItems(0).ToString), clsProcess) + + If mgrCommon.ShowMessage(frmProcessManager_ConfirmDelete, oProcess.Name, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then + mgrProcess.DoProcessDelete(oProcess.ID) + LoadData() + eCurrentMode = eModes.Disabled + ModeChange() + End If + End If + End Sub + + Private Sub SwitchProcess() + If lstProcesses.SelectedItems.Count > 0 Then + eCurrentMode = eModes.View + FillData() + ModeChange() + End If + End Sub + + Private Function CoreValidatation(ByVal oProcess As clsProcess) As Boolean + If txtName.Text.Trim = String.Empty Then + mgrCommon.ShowMessage(frmProcessManager_ErrorValidName, MsgBoxStyle.Exclamation) + txtName.Focus() + Return False + End If + + If txtPath.Text.Trim = String.Empty Then + mgrCommon.ShowMessage(frmProcessManager_ErrorValidPath, MsgBoxStyle.Exclamation) + txtPath.Focus() + Return False + Else + If Not File.Exists(txtPath.Text.Trim) Then + mgrCommon.ShowMessage(frmProcessManager_ErrorPathNotFound, MsgBoxStyle.Exclamation) + txtPath.Focus() + Return False + End If + End If + + If mgrProcess.DoCheckDuplicate(oProcess.Name, oProcess.ID) Then + mgrCommon.ShowMessage(frmProcessManager_ErrorDupe, MsgBoxStyle.Exclamation) + txtName.Focus() + Return False + End If + + Return True + End Function + + Private Sub SetForm() + 'Set Form Name + Me.Text = frmProcessManager_FormName + + 'Set Form Text + btnCancel.Text = frmProcessManager_btnCancel + btnSave.Text = frmProcessManager_btnSave + grpProcess.Text = frmProcessManager_grpProcess + btnProcessBrowse.Text = frmProcessManager_btnProcessBrowse + lblProcess.Text = frmProcessManager_lblPath + lblName.Text = frmProcessManager_lblName + btnClose.Text = frmProcessManager_btnClose + btnDelete.Text = frmProcessManager_btnDelete + btnAdd.Text = frmProcessManager_btnAdd + chkKillProcess.Text = frmProcessManager_chkKillProcess + End Sub + + Private Sub frmProcessManager_Load(sender As Object, e As EventArgs) Handles MyBase.Load + SetForm() + LoadData() + ModeChange() + AssignDirtyHandlers(grpProcess.Controls) + End Sub + + Private Sub lstProcesses_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstProcesses.SelectedIndexChanged + SwitchProcess() + End Sub + + Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click + AddProcess() + End Sub + + Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click + DeleteProcess() + End Sub + + Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click + SaveProcess() + End Sub + + Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click + CancelEdit() + End Sub + + Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click + Me.Close() + End Sub + + Private Sub btnPathBrowse_Click(sender As Object, e As EventArgs) Handles btnProcessBrowse.Click + ProcessBrowse() + End Sub + + Private Sub frmProcessManager_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing + If bIsDirty Then + Select Case HandleDirty() + Case MsgBoxResult.Yes + SaveProcess() + Case MsgBoxResult.No + 'Do Nothing + Case MsgBoxResult.Cancel + e.Cancel = True + End Select + End If + End Sub +End Class \ No newline at end of file diff --git a/GBM/Game Backup Monitor.vbproj b/GBM/Game Backup Monitor.vbproj index 88a2cc1..703c302 100644 --- a/GBM/Game Backup Monitor.vbproj +++ b/GBM/Game Backup Monitor.vbproj @@ -122,6 +122,8 @@ + + @@ -159,6 +161,12 @@ Form + + frmGameProcesses.vb + + + Form + frmGameTags.vb @@ -171,6 +179,12 @@ Form + + frmProcessManager.vb + + + Form + frmSessionExport.vb @@ -232,6 +246,8 @@ Form + + @@ -247,7 +263,7 @@ - + True @@ -277,12 +293,18 @@ frmFileFolderSearch.vb + + frmGameProcesses.vb + frmGameTags.vb frmIncludeExclude.vb + + frmProcessManager.vb + frmSessionExport.vb diff --git a/GBM/Managers/mgrGameProcesses.vb b/GBM/Managers/mgrGameProcesses.vb new file mode 100644 index 0000000..9e1565a --- /dev/null +++ b/GBM/Managers/mgrGameProcesses.vb @@ -0,0 +1,163 @@ +Public Class mgrGameProcesses + + Public Shared Sub DoGameProcessAdd(ByVal oGameProcess As clsGameProcess) + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim sSQL As String + Dim hshParams As New Hashtable + + sSQL = "INSERT INTO gameprocesses VALUES (@ProcessID, @MonitorID)" + hshParams.Add("ProcessID", oGameProcess.ProcessID) + hshParams.Add("MonitorID", oGameProcess.MonitorID) + oDatabase.RunParamQuery(sSQL, hshParams) + End Sub + + Public Shared Sub DoGameProcessAddBatch(ByVal oGameProcesss As List(Of clsGameProcess)) + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim sSQL As String + Dim hshParams As Hashtable + Dim oParamList As New List(Of Hashtable) + + sSQL = "INSERT INTO gameprocesses VALUES (@ProcessID, @MonitorID);" + + For Each oGameProcess As clsGameProcess In oGameProcesss + hshParams = New Hashtable + hshParams.Add("ProcessID", oGameProcess.ProcessID) + hshParams.Add("MonitorID", oGameProcess.MonitorID) + oParamList.Add(hshParams) + Next + + oDatabase.RunMassParamQuery(sSQL, oParamList) + End Sub + + Public Shared Sub DoGameProcessDelete(ByVal oGameProcesss As List(Of clsGameProcess)) + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim sSQL As String + Dim hshParams As Hashtable + Dim oParamList As New List(Of Hashtable) + + sSQL = "DELETE FROM gameprocesses " + sSQL &= "WHERE ProcessID = @ProcessID AND MonitorID = @MonitorID;" + + For Each oGameProcess As clsGameProcess In oGameProcesss + hshParams = New Hashtable + hshParams.Add("ProcessID", oGameProcess.ProcessID) + hshParams.Add("MonitorID", oGameProcess.MonitorID) + oParamList.Add(hshParams) + Next + + oDatabase.RunMassParamQuery(sSQL, oParamList) + End Sub + + Public Shared Sub DoGameProcessDeleteByGame(ByVal sMonitorID As String) + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim sSQL As String + Dim hshParams As New Hashtable + + sSQL = "DELETE FROM gameprocesses " + sSQL &= "WHERE MonitorID = @ID;" + + hshParams.Add("ID", sMonitorID) + + oDatabase.RunParamQuery(sSQL, hshParams) + End Sub + + + Public Shared Sub DoGameProcessDeleteByProcess(ByVal sProcessID As String) + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim sSQL As String + Dim hshParams As New Hashtable + + sSQL = "DELETE FROM gameprocesses " + sSQL &= "WHERE ProcessID = @ID;" + + hshParams.Add("ID", sProcessID) + + oDatabase.RunParamQuery(sSQL, hshParams) + + End Sub + + Public Shared Function GetProcessesByGame(ByVal sMonitorID As String) As Hashtable + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim oData As DataSet + Dim sSQL As String + Dim hshList As New Hashtable + Dim hshParams As New Hashtable + Dim oProcess As clsProcess + + sSQL = "SELECT ProcessID, processes.Name, processes.Path, processes.Args, processes.Kill FROM gameprocesses NATURAL JOIN processes WHERE MonitorID = @ID" + + hshParams.Add("ID", sMonitorID) + + oData = oDatabase.ReadParamData(sSQL, hshParams) + + For Each dr As DataRow In oData.Tables(0).Rows + oProcess = New clsProcess + oProcess.ID = CStr(dr("ProcessID")) + oProcess.Name = CStr(dr("Name")) + oProcess.Path = CStr(dr("Path")) + If Not IsDBNull(dr("Args")) Then oProcess.Args = CStr(dr("Args")) + oProcess.Kill = CBool(dr("Kill")) + + hshList.Add(oProcess.ID, oProcess) + Next + + Return hshList + End Function + + Public Shared Function GetProcessesByGameMulti(ByVal sMonitorIDs As List(Of String)) As Hashtable + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim oData As DataSet + Dim sSQL As String + Dim hshList As New Hashtable + Dim hshParams As New Hashtable + Dim oProcess As clsProcess + Dim iCounter As Integer + + sSQL = "SELECT DISTINCT ProcessID, processes.Name, processes.Path, processes.Args, processes.Kill FROM gameprocesses NATURAL JOIN processes WHERE MonitorID IN (" + + For Each s As String In sMonitorIDs + sSQL &= "@MonitorID" & iCounter & "," + hshParams.Add("MonitorID" & iCounter, s) + iCounter += 1 + Next + + sSQL = sSQL.TrimEnd(",") + sSQL &= ")" + + oData = oDatabase.ReadParamData(sSQL, hshParams) + + For Each dr As DataRow In oData.Tables(0).Rows + oProcess = New clsProcess + oProcess.ID = CStr(dr("ProcessID")) + oProcess.Name = CStr(dr("Name")) + oProcess.Path = CStr(dr("Path")) + If Not IsDBNull(dr("Args")) Then oProcess.Args = CStr(dr("Args")) + oProcess.Kill = CBool(dr("Kill")) + hshList.Add(oProcess.ID, oProcess) + Next + + Return hshList + End Function + + Public Shared Function ReadGameProcesss() As Hashtable + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim oData As DataSet + Dim sSQL As String + Dim sCompoundKey As String + Dim hshList As New Hashtable + Dim oGameProcess As clsGameProcess + + sSQL = "SELECT * from gameprocesses" + oData = oDatabase.ReadParamData(sSQL, New Hashtable) + + For Each dr As DataRow In oData.Tables(0).Rows + oGameProcess = New clsGameProcess + oGameProcess.ProcessID = CStr(dr("ProcessID")) + oGameProcess.MonitorID = CStr(dr("MonitorID")) + sCompoundKey = oGameProcess.ProcessID & ":" & oGameProcess.MonitorID + hshList.Add(sCompoundKey, oGameProcess) + Next + + Return hshList + End Function +End Class diff --git a/GBM/Managers/mgrMonitorList.vb b/GBM/Managers/mgrMonitorList.vb index eb17a5b..f944788 100644 --- a/GBM/Managers/mgrMonitorList.vb +++ b/GBM/Managers/mgrMonitorList.vb @@ -152,7 +152,11 @@ Public Class mgrMonitorList sSQL &= "Hours=@Hours, Version=@Version, Company=@Company, Enabled=@Enabled, MonitorOnly=@MonitorOnly, BackupLimit=@BackupLimit, " sSQL &= "CleanFolder=@CleanFolder, Parameter=@Parameter, Comments=@Comments, IsRegEx=@IsRegEx WHERE MonitorID=@QueryID;" sSQL &= "UPDATE gametags SET MonitorID=@ID WHERE MonitorID=@QueryID;" - sSQL &= "UPDATE sessions SET MonitorID=@ID WHERE MonitorID=@QueryID;" + + If iSelectDB = mgrSQLite.Database.Local Then + sSQL &= "UPDATE gameprocesses SET MonitorID=@ID WHERE MonitorID=@QueryID;" + sSQL &= "UPDATE sessions SET MonitorID=@ID WHERE MonitorID=@QueryID;" + End If 'Parameters hshParams = SetCoreParameters(oGame) @@ -200,6 +204,8 @@ Public Class mgrMonitorList sSQL &= "DELETE FROM gametags " sSQL &= "WHERE MonitorID = @MonitorID;" If iSelectDB = mgrSQLite.Database.Local Then + sSQL &= "DELETE FROM gameprocesses " + sSQL &= "WHERE MonitorID = @MonitorID;" sSQL &= "DELETE FROM sessions " sSQL &= "WHERE MonitorID = @MonitorID;" End If @@ -243,6 +249,18 @@ Public Class mgrMonitorList sSQL &= ");" If iSelectDB = mgrSQLite.Database.Local Then + sSQL &= "DELETE FROM gameprocesses " + sSQL &= "WHERE MonitorID IN (" + + For Each s As String In sMonitorIDs + sSQL &= "@MonitorID" & iCounter & "," + hshParams.Add("MonitorID" & iCounter, s) + iCounter += 1 + Next + + sSQL = sSQL.TrimEnd(",") + sSQL &= ");" + sSQL &= "DELETE FROM sessions " sSQL &= "WHERE MonitorID IN (" @@ -456,6 +474,8 @@ Public Class mgrMonitorList sSQL &= "DELETE FROM gametags " sSQL &= "WHERE MonitorID = @MonitorID;" If iSelectDB = mgrSQLite.Database.Local Then + sSQL &= "DELETE FROM gameprocesses " + sSQL &= "WHERE MonitorID = @MonitorID;" sSQL &= "DELETE FROM sessions " sSQL &= "WHERE MonitorID = @MonitorID;" End If diff --git a/GBM/Managers/mgrProcess.vb b/GBM/Managers/mgrProcess.vb new file mode 100644 index 0000000..db62916 --- /dev/null +++ b/GBM/Managers/mgrProcess.vb @@ -0,0 +1,152 @@ +Public Class mgrProcess + + Private Shared Function MapToObject(ByVal dr As DataRow) As clsProcess + Dim oProcess As New clsProcess + + oProcess.ID = CStr(dr("ProcessID")) + oProcess.Name = CStr(dr("Name")) + oProcess.Path = CStr(dr("Path")) + If Not IsDBNull(dr("Args")) Then oProcess.Args = CStr(dr("Args")) + oProcess.Kill = CBool(dr("Kill")) + + Return oProcess + End Function + + Private Shared Function SetCoreParameters(ByVal oProcess As clsProcess) As Hashtable + Dim hshParams As New Hashtable + + hshParams.Add("ProcessID", oProcess.ID) + hshParams.Add("Name", oProcess.Name) + hshParams.Add("Path", oProcess.Path) + hshParams.Add("Args", oProcess.Args) + hshParams.Add("Kill", oProcess.Kill) + + Return hshParams + End Function + + Public Shared Sub DoProcessAdd(ByVal oProcess As clsProcess) + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim sSQL As String + Dim hshParams As Hashtable + + sSQL = "INSERT INTO processes VALUES (@ProcessID, @Name, @Path, @Args, @Kill)" + hshParams = SetCoreParameters(oProcess) + oDatabase.RunParamQuery(sSQL, hshParams) + End Sub + + Public Shared Sub DoProcessUpdate(ByVal oProcess As clsProcess) + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim sSQL As String + Dim hshParams As Hashtable + + sSQL = "UPDATE processes SET Name=@Name, Path=@Path, Args=@Args, Kill=@Kill " + sSQL &= "WHERE ProcessID = @ProcessID" + + hshParams = SetCoreParameters(oProcess) + + oDatabase.RunParamQuery(sSQL, hshParams) + + End Sub + + Public Shared Sub DoProcessDelete(ByVal sProcessID As String) + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim sSQL As String + Dim hshParams As New Hashtable + + sSQL = "DELETE FROM gameprocesses " + sSQL &= "WHERE ProcessID = @ProcessID;" + sSQL &= "DELETE FROM processes " + sSQL &= "WHERE ProcessID = @ProcessID;" + + hshParams.Add("ProcessID", sProcessID) + + oDatabase.RunParamQuery(sSQL, hshParams) + + End Sub + + Public Shared Function DoProcessGetbyID(ByVal sProcessID As String) As clsProcess + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim sSQL As String + Dim oData As DataSet + Dim oProcess As New clsProcess + Dim hshParams As New Hashtable + + sSQL = "SELECT * FROM processes " + sSQL &= "WHERE ProcessID = @ProcessID" + + hshParams.Add("ProcessID", sProcessID) + + oData = oDatabase.ReadParamData(sSQL, hshParams) + + For Each dr As DataRow In oData.Tables(0).Rows + oProcess = MapToObject(dr) + Next + + Return oProcess + End Function + + Public Shared Function DoProcessGetbyName(ByVal sProcessName As String) As clsProcess + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim sSQL As String + Dim oData As DataSet + Dim oProcess As New clsProcess + Dim hshParams As New Hashtable + + sSQL = "SELECT * FROM processes " + sSQL &= "WHERE Name = @Name" + + hshParams.Add("Name", sProcessName) + + oData = oDatabase.ReadParamData(sSQL, hshParams) + + For Each dr As DataRow In oData.Tables(0).Rows + oProcess = MapToObject(dr) + Next + + Return oProcess + End Function + + Public Shared Function DoCheckDuplicate(ByVal sName As String, Optional ByVal sExcludeID As String = "") As Boolean + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim sSQL As String + Dim oData As DataSet + Dim hshParams As New Hashtable + + sSQL = "SELECT * FROM processes " + sSQL &= "WHERE Name = @Name" + + hshParams.Add("Name", sName) + + If sExcludeID <> String.Empty Then + sSQL &= " AND ProcessID <> @ProcessID" + hshParams.Add("ProcessID", sExcludeID) + End If + + oData = oDatabase.ReadParamData(sSQL, hshParams) + + If oData.Tables(0).Rows.Count > 0 Then + Return True + Else + Return False + End If + End Function + + Public Shared Function ReadProcesses() As Hashtable + Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim oData As DataSet + Dim sSQL As String + Dim hshList As New Hashtable + Dim oProcess As clsProcess + + sSQL = "SELECT * from processes" + oData = oDatabase.ReadParamData(sSQL, New Hashtable) + + For Each dr As DataRow In oData.Tables(0).Rows + oProcess = MapToObject(dr) + hshList.Add(oProcess.Name, oProcess) + Next + + Return hshList + End Function + +End Class diff --git a/GBM/Managers/mgrProcesses.vb b/GBM/Managers/mgrProcessDetection.vb similarity index 99% rename from GBM/Managers/mgrProcesses.vb rename to GBM/Managers/mgrProcessDetection.vb index 7d4d230..cfc4216 100644 --- a/GBM/Managers/mgrProcesses.vb +++ b/GBM/Managers/mgrProcessDetection.vb @@ -2,7 +2,7 @@ Imports System.Management Imports System.Text.RegularExpressions -Public Class mgrProcesses +Public Class mgrProcessDetection Private prsFoundProcess As Process Private dStartTime As DateTime = Now, dEndTime As DateTime = Now diff --git a/GBM/Managers/mgrSQLite.vb b/GBM/Managers/mgrSQLite.vb index 667b692..ef1a751 100644 --- a/GBM/Managers/mgrSQLite.vb +++ b/GBM/Managers/mgrSQLite.vb @@ -102,6 +102,12 @@ Public Class mgrSQLite 'Add Tables (Sessions) sSql &= "CREATE TABLE sessions (MonitorID TEXT NOT NULL, Start INTEGER NOT NULL, End INTEGER NOT NULL, PRIMARY KEY(MonitorID, Start));" + 'Add Tables (Processes) + sSql &= "CREATE TABLE processes (ProcessID TEXT NOT NULL PRIMARY KEY, Name Text NOT NULL, Path TEXT NOT NULL, Args TEXT, Kill BOOLEAN NOT NULL);" + + 'Add Tables (Game Processes) + sSql &= "CREATE TABLE gameprocesses (ProcessID TEXT NOT NULL, MonitorID TEXT NOT NULL, PRIMARY KEY(ProcessID, MonitorID));" + 'Set Version sSql &= "PRAGMA user_version=" & mgrCommon.AppVersion @@ -767,6 +773,10 @@ Public Class mgrSQLite 'Backup DB before starting BackupDB("v108") + 'Add Tables + sSQL = "CREATE TABLE processes (ProcessID TEXT NOT NULL PRIMARY KEY, Name Text NOT NULL, Path TEXT NOT NULL, Args TEXT, Kill BOOLEAN NOT NULL);" + sSQL &= "CREATE TABLE gameprocesses (ProcessID TEXT NOT NULL, MonitorID TEXT NOT NULL, PRIMARY KEY(ProcessID, MonitorID));" + 'Overhaul Tables sSQL = "CREATE TABLE settings_new (SettingsID INTEGER NOT NULL PRIMARY KEY, MonitorOnStartup BOOLEAN NOT NULL, StartToTray BOOLEAN NOT NULL, ShowDetectionToolTips BOOLEAN NOT NULL, " & "DisableConfirmation BOOLEAN NOT NULL, CreateSubFolder BOOLEAN NOT NULL, ShowOverwriteWarning BOOLEAN NOT NULL, RestoreOnLaunch BOOLEAN NOT NULL, " & diff --git a/GBM/My Project/Resources.Designer.vb b/GBM/My Project/Resources.Designer.vb index d1f6800..b659a16 100644 --- a/GBM/My Project/Resources.Designer.vb +++ b/GBM/My Project/Resources.Designer.vb @@ -105,6 +105,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to Error: [PARAM]. + ''' + Friend ReadOnly Property App_GenericError() As String + Get + Return ResourceManager.GetString("App_GenericError", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to 7-Zip (7za.exe) is invalid and has been prevented from running.. ''' @@ -2382,6 +2391,78 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to >. + ''' + Friend ReadOnly Property frmGameProcesses_btnAdd() As String + Get + Return ResourceManager.GetString("frmGameProcesses_btnAdd", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to &Close. + ''' + Friend ReadOnly Property frmGameProcesses_btnClose() As String + Get + Return ResourceManager.GetString("frmGameProcesses_btnClose", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Process &Manager.... + ''' + Friend ReadOnly Property frmGameProcesses_btnOpenProcesses() As String + Get + Return ResourceManager.GetString("frmGameProcesses_btnOpenProcesses", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to <. + ''' + Friend ReadOnly Property frmGameProcesses_btnRemove() As String + Get + Return ResourceManager.GetString("frmGameProcesses_btnRemove", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Edit Processes for Multiple Games. + ''' + Friend ReadOnly Property frmGameProcesses_FormNameMulti() As String + Get + Return ResourceManager.GetString("frmGameProcesses_FormNameMulti", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Edit Processes for [PARAM]. + ''' + Friend ReadOnly Property frmGameProcesses_FormNameSingle() As String + Get + Return ResourceManager.GetString("frmGameProcesses_FormNameSingle", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Current Processes. + ''' + Friend ReadOnly Property frmGameProcesses_lblGameProccesses() As String + Get + Return ResourceManager.GetString("frmGameProcesses_lblGameProccesses", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Available Processes. + ''' + Friend ReadOnly Property frmGameProcesses_lblProcesses() As String + Get + Return ResourceManager.GetString("frmGameProcesses_lblProcesses", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to >. ''' @@ -2994,6 +3075,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to An error occured when attempting to end a process associated with [PARAM].. + ''' + Friend ReadOnly Property frmMain_ErrorEndChildProcess() As String + Get + Return ResourceManager.GetString("frmMain_ErrorEndChildProcess", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to An unexpected error occured while initializing GBM.[BR][BR][PARAM][BR][BR]Do you wish to continue anyway? (Not Recommended). ''' @@ -3066,6 +3156,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to An error occured when attempting to start a process associated with [PARAM].. + ''' + Friend ReadOnly Property frmMain_ErrorStartChildProcess() As String + Get + Return ResourceManager.GetString("frmMain_ErrorStartChildProcess", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to [PARAM] (Executable Path). ''' @@ -3264,6 +3363,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to Process &Manager.... + ''' + Friend ReadOnly Property frmMain_gMonSetupProcessManager() As String + Get + Return ResourceManager.GetString("frmMain_gMonSetupProcessManager", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to &Tags.... ''' @@ -3723,6 +3831,168 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to +. + ''' + Friend ReadOnly Property frmProcessManager_btnAdd() As String + Get + Return ResourceManager.GetString("frmProcessManager_btnAdd", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to &Cancel. + ''' + Friend ReadOnly Property frmProcessManager_btnCancel() As String + Get + Return ResourceManager.GetString("frmProcessManager_btnCancel", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to C&lose. + ''' + Friend ReadOnly Property frmProcessManager_btnClose() As String + Get + Return ResourceManager.GetString("frmProcessManager_btnClose", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to -. + ''' + Friend ReadOnly Property frmProcessManager_btnDelete() As String + Get + Return ResourceManager.GetString("frmProcessManager_btnDelete", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to .... + ''' + Friend ReadOnly Property frmProcessManager_btnProcessBrowse() As String + Get + Return ResourceManager.GetString("frmProcessManager_btnProcessBrowse", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to &Save. + ''' + Friend ReadOnly Property frmProcessManager_btnSave() As String + Get + Return ResourceManager.GetString("frmProcessManager_btnSave", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Kill process when game is closed.. + ''' + Friend ReadOnly Property frmProcessManager_chkKillProcess() As String + Get + Return ResourceManager.GetString("frmProcessManager_chkKillProcess", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Choose a file that starts the process. + ''' + Friend ReadOnly Property frmProcessManager_ChooseProcess() As String + Get + Return ResourceManager.GetString("frmProcessManager_ChooseProcess", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Are you sure you want to delete [PARAM]? This cannot be undone.. + ''' + Friend ReadOnly Property frmProcessManager_ConfirmDelete() As String + Get + Return ResourceManager.GetString("frmProcessManager_ConfirmDelete", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to A process with this name already exists.. + ''' + Friend ReadOnly Property frmProcessManager_ErrorDupe() As String + Get + Return ResourceManager.GetString("frmProcessManager_ErrorDupe", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to The process does not exist.. + ''' + Friend ReadOnly Property frmProcessManager_ErrorPathNotFound() As String + Get + Return ResourceManager.GetString("frmProcessManager_ErrorPathNotFound", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to You must enter a valid name for this process.. + ''' + Friend ReadOnly Property frmProcessManager_ErrorValidName() As String + Get + Return ResourceManager.GetString("frmProcessManager_ErrorValidName", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to You must choose a valid process.. + ''' + Friend ReadOnly Property frmProcessManager_ErrorValidPath() As String + Get + Return ResourceManager.GetString("frmProcessManager_ErrorValidPath", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Executable. + ''' + Friend ReadOnly Property frmProcessManager_Executable() As String + Get + Return ResourceManager.GetString("frmProcessManager_Executable", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Process Manager. + ''' + Friend ReadOnly Property frmProcessManager_FormName() As String + Get + Return ResourceManager.GetString("frmProcessManager_FormName", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Configuration. + ''' + Friend ReadOnly Property frmProcessManager_grpProcess() As String + Get + Return ResourceManager.GetString("frmProcessManager_grpProcess", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Name:. + ''' + Friend ReadOnly Property frmProcessManager_lblName() As String + Get + Return ResourceManager.GetString("frmProcessManager_lblName", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Path:. + ''' + Friend ReadOnly Property frmProcessManager_lblPath() As String + Get + Return ResourceManager.GetString("frmProcessManager_lblPath", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to &Cancel. ''' diff --git a/GBM/My Project/Resources.resx b/GBM/My Project/Resources.resx index 5f53281..ffdbbd1 100644 --- a/GBM/My Project/Resources.resx +++ b/GBM/My Project/Resources.resx @@ -2068,4 +2068,94 @@ Backup GBM data files on launch + + An error occured when attempting to end a process associated with [PARAM]. + + + An error occured when attempting to start a process associated with [PARAM]. + + + + + + + &Cancel + + + C&lose + + + - + + + ... + + + &Save + + + Are you sure you want to delete [PARAM]? This cannot be undone. + + + A process with this name already exists. + + + The process does not exist. + + + You must enter a valid name for this process. + + + You must choose a valid process. + + + Process Manager + + + Configuration + + + Name: + + + Path: + + + Process &Manager... + + + Choose a file that starts the process + + + Executable + + + Kill process when game is closed. + + + > + + + &Close + + + Process &Manager... + + + < + + + Edit Processes for Multiple Games + + + Edit Processes for [PARAM] + + + Current Processes + + + Available Processes + + + Error: [PARAM] + \ No newline at end of file diff --git a/GBM/readme.txt b/GBM/readme.txt index 0753b4d..dc452b6 100644 --- a/GBM/readme.txt +++ b/GBM/readme.txt @@ -22,6 +22,12 @@ All Platforms: - When a game is deleted via Game Manager (or sync), all backup manifest entries for that particular game are now deleted. The backup files themselves are not. - The Game Manager now syncs changes to the remote database immediately, instead of only when closed. - Feature Changes + - Added the ability to start another process (or multiple process) whenever a game is detected. (Thanks for the suggestion Naliel Supremo) + - This is useful to automatically start utilities, such as custom control schemes or overlays, for specific games. + - The "Process Manager" allows you to manage any programs you'd like to launch. + - The "Processes..." button on the Game Manager allows you to assign processes to any selected game. + - A process can be set to end when the game is closed. + - Processes and related settings are specific to the local machine only. They are not synced to the backup folder and are not part of the import/export. - Added "Backup GBM data files on launch" to the settings. A long overdue feature, this will backup both the remote and local databases (as gbm.s3db.launch.bak) each time GBM starts. - This new setting is enabled by default. - Only one backup is kept, the prior one will be overwritten. @@ -57,6 +63,7 @@ Known Issues: - If one or more Game IDs are changed on one computer and these changes are synced to another PC sharing the same backup folder: - The local session data on that PC for the changed game(s) will be lost. + - Any processes assigned to the changed games(s) on that PC will be lost. - The local backup manifest data for the changed game(s) on that PC will be reset. GBM will see any backups for the changed game(s) as new and will handle them accordingly. - Backup files made prior to v1.1.0 are not being renamed or removed when a new backup is created. - This is due to file name now being generated by the Game ID and not the name. @@ -65,5 +72,8 @@ Known Issues: - Configurations on the official game list are no longer fully compatible with older GBM versions. - Technically they will work. But any game imported with a special character in it's name, such as a colon, will not create backup files correctly. - These characters can be manually removed from the game name after importing, then the configurations will function properly. +- The error "The requested operation requires elevation" occurs when GBM tries to launch a process associated with a game. + - This means the process you're trying to launch with GBM requires administrator privilege. + - Click the blue "user" icon on the bottom left of the GBM window to quickly switch to administrator mode. The entire version history of GBM releases is available at http://mikemaximus.github.io/gbm-web/versionhistory.html \ No newline at end of file