diff --git a/SLAM/App.config b/SLAM/App.config index d2ecb32..d6823ae 100644 --- a/SLAM/App.config +++ b/SLAM/App.config @@ -11,7 +11,7 @@ - + C:\Program Files (x86)\Steam\steamapps\ X @@ -19,6 +19,9 @@ + + False + \ No newline at end of file diff --git a/SLAM/Form1.Designer.vb b/SLAM/Form1.Designer.vb index 889fc40..974adf4 100644 --- a/SLAM/Form1.Designer.vb +++ b/SLAM/Form1.Designer.vb @@ -22,24 +22,31 @@ Partial Class Form1 'Do not modify it using the code editor. _ Private Sub InitializeComponent() + Me.components = New System.ComponentModel.Container() Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1)) Me.GameSelector = New System.Windows.Forms.ComboBox() Me.Label1 = New System.Windows.Forms.Label() Me.ImportButton = New System.Windows.Forms.Button() Me.TrackList = New System.Windows.Forms.ListView() - Me.ColumnHeader1 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) - Me.ColumnHeader2 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) - Me.ColumnHeader3 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.LoadedCol = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.TrackCol = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.HotKeyCol = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.TagsCol = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) Me.StartButton = New System.Windows.Forms.Button() Me.ImportDialog = New System.Windows.Forms.OpenFileDialog() Me.ProgressBar1 = New System.Windows.Forms.ProgressBar() Me.WavWorker = New System.ComponentModel.BackgroundWorker() Me.PollRelayWorker = New System.ComponentModel.BackgroundWorker() Me.ChangeDirButton = New System.Windows.Forms.Button() - Me.Label2 = New System.Windows.Forms.Label() - Me.PlayKeyTextBox = New System.Windows.Forms.TextBox() - Me.ChangeDirDialog = New System.Windows.Forms.FolderBrowserDialog() - Me.BackgroundWorker1 = New System.ComponentModel.BackgroundWorker() + Me.TrackContextMenu = New System.Windows.Forms.ContextMenuStrip(Me.components) + Me.ContextDelete = New System.Windows.Forms.ToolStripMenuItem() + Me.GoToToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() + Me.LoadToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() + Me.ContextRefresh = New System.Windows.Forms.ToolStripMenuItem() + Me.RemoveHotkeyToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() + Me.ContextHotKey = New System.Windows.Forms.ToolStripMenuItem() + Me.PlayKeyButton = New System.Windows.Forms.Button() + Me.TrackContextMenu.SuspendLayout() Me.SuspendLayout() ' 'GameSelector @@ -66,7 +73,7 @@ Partial Class Form1 'ImportButton ' Me.ImportButton.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) - Me.ImportButton.Location = New System.Drawing.Point(15, 288) + Me.ImportButton.Location = New System.Drawing.Point(15, 297) Me.ImportButton.Name = "ImportButton" Me.ImportButton.Size = New System.Drawing.Size(75, 23) Me.ImportButton.TabIndex = 3 @@ -79,36 +86,40 @@ Partial Class Form1 Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.TrackList.AutoArrange = False - Me.TrackList.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3}) + Me.TrackList.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.LoadedCol, Me.TrackCol, Me.HotKeyCol, Me.TagsCol}) Me.TrackList.FullRowSelect = True Me.TrackList.HideSelection = False Me.TrackList.ImeMode = System.Windows.Forms.ImeMode.Off Me.TrackList.Location = New System.Drawing.Point(15, 39) Me.TrackList.MultiSelect = False Me.TrackList.Name = "TrackList" - Me.TrackList.Size = New System.Drawing.Size(457, 243) + Me.TrackList.Size = New System.Drawing.Size(457, 252) Me.TrackList.TabIndex = 4 Me.TrackList.UseCompatibleStateImageBehavior = False Me.TrackList.View = System.Windows.Forms.View.Details ' - 'ColumnHeader1 + 'LoadedCol ' - Me.ColumnHeader1.Text = "Loaded" + Me.LoadedCol.Text = "Loaded" ' - 'ColumnHeader2 + 'TrackCol ' - Me.ColumnHeader2.Text = "Track" - Me.ColumnHeader2.Width = 137 + Me.TrackCol.Text = "Track" + Me.TrackCol.Width = 137 ' - 'ColumnHeader3 + 'HotKeyCol ' - Me.ColumnHeader3.Text = "Tags" - Me.ColumnHeader3.Width = 43 + Me.HotKeyCol.Text = "Bind" + ' + 'TagsCol + ' + Me.TagsCol.Text = "Tags" + Me.TagsCol.Width = 43 ' 'StartButton ' Me.StartButton.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) - Me.StartButton.Location = New System.Drawing.Point(96, 288) + Me.StartButton.Location = New System.Drawing.Point(96, 297) Me.StartButton.Name = "StartButton" Me.StartButton.Size = New System.Drawing.Size(75, 23) Me.StartButton.TabIndex = 5 @@ -125,7 +136,7 @@ Partial Class Form1 ' Me.ProgressBar1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) - Me.ProgressBar1.Location = New System.Drawing.Point(15, 317) + Me.ProgressBar1.Location = New System.Drawing.Point(15, 326) Me.ProgressBar1.Name = "ProgressBar1" Me.ProgressBar1.Size = New System.Drawing.Size(457, 23) Me.ProgressBar1.Step = 1 @@ -150,43 +161,64 @@ Partial Class Form1 Me.ChangeDirButton.Text = "Change Dir" Me.ChangeDirButton.UseVisualStyleBackColor = True ' - 'Label2 + 'TrackContextMenu + ' + Me.TrackContextMenu.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ContextDelete, Me.GoToToolStripMenuItem, Me.LoadToolStripMenuItem, Me.ContextRefresh, Me.RemoveHotkeyToolStripMenuItem, Me.ContextHotKey}) + Me.TrackContextMenu.Name = "TrackContextMenu" + Me.TrackContextMenu.Size = New System.Drawing.Size(153, 158) + ' + 'ContextDelete + ' + Me.ContextDelete.Name = "ContextDelete" + Me.ContextDelete.Size = New System.Drawing.Size(158, 22) + Me.ContextDelete.Text = "Delete" + ' + 'GoToToolStripMenuItem + ' + Me.GoToToolStripMenuItem.Name = "GoToToolStripMenuItem" + Me.GoToToolStripMenuItem.Size = New System.Drawing.Size(158, 22) + Me.GoToToolStripMenuItem.Text = "Go To" + ' + 'LoadToolStripMenuItem + ' + Me.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem" + Me.LoadToolStripMenuItem.Size = New System.Drawing.Size(158, 22) + Me.LoadToolStripMenuItem.Text = "Load" + ' + 'ContextRefresh ' - Me.Label2.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) - Me.Label2.AutoSize = True - Me.Label2.Location = New System.Drawing.Point(390, 293) - Me.Label2.Name = "Label2" - Me.Label2.Size = New System.Drawing.Size(51, 13) - Me.Label2.TabIndex = 8 - Me.Label2.Text = "Play Key:" + Me.ContextRefresh.Name = "ContextRefresh" + Me.ContextRefresh.Size = New System.Drawing.Size(158, 22) + Me.ContextRefresh.Text = "Refresh" ' - 'PlayKeyTextBox + 'RemoveHotkeyToolStripMenuItem ' - Me.PlayKeyTextBox.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) - Me.PlayKeyTextBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper - Me.PlayKeyTextBox.Cursor = System.Windows.Forms.Cursors.IBeam - Me.PlayKeyTextBox.Location = New System.Drawing.Point(447, 290) - Me.PlayKeyTextBox.MaxLength = 2 - Me.PlayKeyTextBox.Name = "PlayKeyTextBox" - Me.PlayKeyTextBox.Size = New System.Drawing.Size(25, 20) - Me.PlayKeyTextBox.TabIndex = 9 - Me.PlayKeyTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center + Me.RemoveHotkeyToolStripMenuItem.Name = "RemoveHotkeyToolStripMenuItem" + Me.RemoveHotkeyToolStripMenuItem.Size = New System.Drawing.Size(152, 22) + Me.RemoveHotkeyToolStripMenuItem.Text = "Remove Bind" ' - 'ChangeDirDialog + 'ContextHotKey ' - Me.ChangeDirDialog.Description = "Select your steamapps folder:" - Me.ChangeDirDialog.ShowNewFolderButton = False + Me.ContextHotKey.Name = "ContextHotKey" + Me.ContextHotKey.Size = New System.Drawing.Size(152, 22) + Me.ContextHotKey.Text = "Set Bind" ' - 'BackgroundWorker1 + 'PlayKeyButton ' + Me.PlayKeyButton.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) + Me.PlayKeyButton.Location = New System.Drawing.Point(247, 297) + Me.PlayKeyButton.Name = "PlayKeyButton" + Me.PlayKeyButton.Size = New System.Drawing.Size(225, 23) + Me.PlayKeyButton.TabIndex = 8 + Me.PlayKeyButton.Text = "Play key: {0} (change)" + Me.PlayKeyButton.UseVisualStyleBackColor = True ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(484, 352) - Me.Controls.Add(Me.PlayKeyTextBox) - Me.Controls.Add(Me.Label2) + Me.ClientSize = New System.Drawing.Size(484, 361) + Me.Controls.Add(Me.PlayKeyButton) Me.Controls.Add(Me.ChangeDirButton) Me.Controls.Add(Me.ProgressBar1) Me.Controls.Add(Me.StartButton) @@ -195,9 +227,11 @@ Partial Class Form1 Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.GameSelector) Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) + Me.MinimumSize = New System.Drawing.Size(500, 400) Me.Name = "Form1" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "Source Live Audio Mixer" + Me.TrackContextMenu.ResumeLayout(False) Me.ResumeLayout(False) Me.PerformLayout() @@ -206,18 +240,23 @@ Partial Class Form1 Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents ImportButton As System.Windows.Forms.Button Friend WithEvents TrackList As System.Windows.Forms.ListView - Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader - Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader - Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader + Friend WithEvents LoadedCol As System.Windows.Forms.ColumnHeader + Friend WithEvents TrackCol As System.Windows.Forms.ColumnHeader + Friend WithEvents TagsCol As System.Windows.Forms.ColumnHeader Friend WithEvents StartButton As System.Windows.Forms.Button Friend WithEvents ImportDialog As System.Windows.Forms.OpenFileDialog Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar Friend WithEvents WavWorker As System.ComponentModel.BackgroundWorker Friend WithEvents PollRelayWorker As System.ComponentModel.BackgroundWorker Friend WithEvents ChangeDirButton As System.Windows.Forms.Button - Friend WithEvents Label2 As System.Windows.Forms.Label - Friend WithEvents PlayKeyTextBox As System.Windows.Forms.TextBox - Friend WithEvents ChangeDirDialog As System.Windows.Forms.FolderBrowserDialog - Friend WithEvents BackgroundWorker1 As System.ComponentModel.BackgroundWorker + Friend WithEvents TrackContextMenu As System.Windows.Forms.ContextMenuStrip + Friend WithEvents ContextDelete As System.Windows.Forms.ToolStripMenuItem + Friend WithEvents ContextRefresh As System.Windows.Forms.ToolStripMenuItem + Friend WithEvents ContextHotKey As System.Windows.Forms.ToolStripMenuItem + Friend WithEvents HotKeyCol As System.Windows.Forms.ColumnHeader + Friend WithEvents LoadToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem + Friend WithEvents RemoveHotkeyToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem + Friend WithEvents GoToToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem + Friend WithEvents PlayKeyButton As System.Windows.Forms.Button End Class diff --git a/SLAM/Form1.resx b/SLAM/Form1.resx index 255167b..e4d5e32 100644 --- a/SLAM/Form1.resx +++ b/SLAM/Form1.resx @@ -126,11 +126,8 @@ 247, 17 - - 373, 16 - - - 518, 16 + + 377, 18 diff --git a/SLAM/Form1.vb b/SLAM/Form1.vb index 6d74058..8faa648 100644 --- a/SLAM/Form1.vb +++ b/SLAM/Form1.vb @@ -3,18 +3,23 @@ Imports NAudio.Wave Imports System.IO Imports System.Text.RegularExpressions Imports System.Threading +Imports SLAM.XmlSerialization +Imports System.Net.Http Public Class Form1 + Dim SlamVersion As New Version("1.1.0") + Dim Games As New List(Of SourceGame) Dim SteamappsPath As String = My.Settings.SteamAppsFolder - Public PlayKey As String = My.Settings.PlayKey Dim running As Boolean = False Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load DisableInterface() - PlayKeyTextBox.Text = PlayKey + RefreshPlayKey() + + CheckForUpdate() Dim csgo As New SourceGame csgo.name = "Counter-Strike: Global Offensive" @@ -24,6 +29,13 @@ Public Class Form1 csgo.samplerate = 22050 Games.Add(csgo) + Dim css As New SourceGame + css.name = "Counter-Strike: Source" + css.directory = "common\Counter-Strike Source\" + css.ToCfg = "cstrike\cfg\" + css.libraryname = "css\" + Games.Add(css) + Dim tf2 As New SourceGame tf2.name = "Team Fortress 2" tf2.directory = "common\Team Fortress 2\" @@ -31,18 +43,10 @@ Public Class Form1 tf2.libraryname = "tf2\" Games.Add(tf2) - If String.IsNullOrEmpty(SteamappsPath) Then - If ChangeDirDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then - SteamappsPath = ChangeDirDialog.SelectedPath & "\" - Else - Me.Close() - End If - End If - LoadGames() End Sub - Public Shared Sub WaveCreator(File As String, outputFile As String) + Private Sub WaveCreator(File As String, outputFile As String) Dim reader If Path.GetExtension(File) = ".mp3" Then @@ -70,13 +74,18 @@ Public Class Form1 End Sub Private Sub ImportButton_Click(sender As Object, e As EventArgs) Handles ImportButton.Click - If ImportDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then - ProgressBar1.Maximum = ImportDialog.FileNames.Count + If File.Exists("NAudio.dll") Then + If ImportDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then + ProgressBar1.Maximum = ImportDialog.FileNames.Count - Dim WorkerPassthrough() As Object = {GetCurrentGame(), ImportDialog.FileNames} + Dim WorkerPassthrough() As Object = {GetCurrentGame(), ImportDialog.FileNames} - WavWorker.RunWorkerAsync(WorkerPassthrough) - DisableInterface() + WavWorker.RunWorkerAsync(WorkerPassthrough) + DisableInterface() + End If + + Else + MessageBox.Show("You are missing NAudio.dll! Cannot import without it!", "Missing File", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Sub @@ -150,6 +159,8 @@ Public Class Form1 Next CreateTags(Game) + LoadTrackKeys(Game) + SaveTrackKeys(Game) 'To prune hotkeys from non-existing tracks Else Directory.CreateDirectory(Game.libraryname) @@ -162,13 +173,14 @@ Public Class Form1 Dim Game As SourceGame = GetCurrentGame() For Each Track In Game.tracks - TrackList.Items.Add(New ListViewItem({"False", Track.name, """" & String.Join(""", """, Track.tags) & """"})) + TrackList.Items.Add(New ListViewItem({"False", Track.name, Track.hotkey, """" & String.Join(""", """, Track.tags) & """"})) Next TrackList.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.HeaderSize) TrackList.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent) - TrackList.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent) + TrackList.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.HeaderSize) + TrackList.AutoResizeColumn(3, ColumnHeaderAutoResizeStyle.ColumnContent) End Sub Private Sub StartButton_Click(sender As Object, e As EventArgs) Handles StartButton.Click @@ -176,7 +188,12 @@ Public Class Form1 StopPoll() Else StartPoll() - MsgBox("Don't forget to type ""exec slam"" in colsole!") + If Not My.Settings.NoHint Then + If MessageBox.Show("Don't forget to type ""exec slam"" in console! Click ""Cancel"" if you don't ever want to see this message again.", "SLAM", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.Cancel Then + My.Settings.NoHint = True + My.Settings.Save() + End If + End If End If End Sub @@ -201,6 +218,7 @@ Public Class Form1 Dim GameDir As String = Path.Combine(SteamappsPath, Game.directory) Dim GameCfgFolder As String = Path.Combine(GameDir, Game.ToCfg) + 'slam.cfg Using slam_cfg As StreamWriter = New StreamWriter(GameCfgFolder & "slam.cfg") slam_cfg.WriteLine("alias slam_listtracks ""exec slam_tracklist.cfg""") slam_cfg.WriteLine("alias list slam_listtracks") @@ -210,7 +228,8 @@ Public Class Form1 slam_cfg.WriteLine("alias slam_play_on ""alias slam_play slam_play_off; voice_inputfromfile 1; voice_loopback 1; +voicerecord""") slam_cfg.WriteLine("alias slam_play_off ""-voicerecord; voice_inputfromfile 0; voice_loopback 0; alias slam_play slam_play_on""") slam_cfg.WriteLine("alias slam_updatecfg ""host_writeconfig slam_relay""") - slam_cfg.WriteLine("bind {0} slam_play", PlayKey) + slam_cfg.WriteLine("bind {0} slam_play", My.Settings.PlayKey) + For Each Track In Game.tracks Dim index As String = Game.tracks.IndexOf(Track) slam_cfg.WriteLine("alias {0} ""bind {1} {0}; slam_updatecfg; echo Loaded: {2}""", index + 1, Game.RelayKey, Track.name) @@ -218,10 +237,16 @@ Public Class Form1 For Each TrackTag In Track.tags slam_cfg.WriteLine("alias {0} ""bind {1} {2}; slam_updatecfg; echo Loaded: {3}""", TrackTag, Game.RelayKey, index + 1, Track.name) Next + + If Not String.IsNullOrEmpty(Track.hotkey) Then + slam_cfg.WriteLine("bind {0} ""bind {1} {2}; slam_updatecfg; echo Loaded: {3}""", Track.hotkey, Game.RelayKey, index + 1, Track.name) + End If Next + slam_cfg.WriteLine("voice_enable 1; voice_modenable 1; voice_forcemicrecord 0; voice_fadeouttime 0.0; con_enable 1") End Using + 'slam_tracklist.cfg Using slam_tracklist_cfg As StreamWriter = New StreamWriter(GameCfgFolder & "slam_tracklist.cfg") slam_tracklist_cfg.WriteLine("echo ""You can select tracks either by typing a tag, or their track number.""") slam_tracklist_cfg.WriteLine("echo ""--------------------Tracks--------------------""") @@ -244,7 +269,7 @@ Public Class Form1 If File.Exists(voicefile) Then File.Delete(voicefile) End If - File.Copy(Game.libraryname & TrackName & ".wav", voicefile) + File.Copy(Game.libraryname & TrackName & Game.FileExtension, voicefile) Catch ex As Exception Return False @@ -254,7 +279,7 @@ Public Class Form1 Return True End Function - Public Shared Function recog(ByVal str As String, ByVal reg As String) As String + Private Function recog(ByVal str As String, ByVal reg As String) As String Dim keyd As Match = Regex.Match(str, reg) Return (keyd.Groups(1).ToString) End Function @@ -296,6 +321,7 @@ Public Class Form1 End Sub Private Sub CreateTags(ByVal Game As SourceGame) + Dim BadWords() As String = {"slam", "slam_listtracks", "list", "tracks", "la", "slam_play", "slam_play_on", "slam_play_off", "slam_updatecfg"} Dim NameWords As New Dictionary(Of String, Integer) Dim index As Integer @@ -304,7 +330,7 @@ Public Class Form1 For Each Word In Words - If Not IsNumeric(Word) Then + If Not IsNumeric(Word) And Not BadWords.Contains(Word.ToLower) Then If NameWords.ContainsKey(Word) Then NameWords.Remove(Word) Else @@ -321,60 +347,30 @@ Public Class Form1 Next End Sub - Public Sub EnableInterface() - GameSelector.Enabled = True - TrackList.Enabled = True - ImportButton.Enabled = True - StartButton.Enabled = True - ChangeDirButton.Enabled = True - PlayKeyTextBox.Enabled = True + Private Sub EnableInterface() + For Each Control In Me.Controls + Control.Enabled = True + Next End Sub - Public Sub DisableInterface() - GameSelector.Enabled = False - TrackList.Enabled = False - ImportButton.Enabled = False - StartButton.Enabled = False - ChangeDirButton.Enabled = False - PlayKeyTextBox.Enabled = False - PlayKeyTextBox.Text = PlayKey + Private Sub DisableInterface() + For Each Control In Me.Controls + Control.Enabled = False + Next End Sub - Public Sub DisplayLoaded(ByVal track As Integer) + Private Sub DisplayLoaded(ByVal track As Integer) For i As Integer = 0 To TrackList.Items.Count - 1 TrackList.Items(i).SubItems(0).Text = "False" Next TrackList.Items(track).SubItems(0).Text = "True" End Sub - Private Sub PlayKeyTextBox_Enter(sender As Object, e As EventArgs) Handles PlayKeyTextBox.Enter - BeginInvoke(DirectCast(Sub() PlayKeyTextBox.SelectAll(), Action)) - End Sub - - Private Sub PlayKey_TextChanged(sender As Object, e As EventArgs) Handles PlayKeyTextBox.TextChanged - If String.IsNullOrEmpty(PlayKeyTextBox.Text) Then - PlayKeyTextBox.Text = PlayKey - End If - - If PlayKeyTextBox.Text.Count > 1 Then - PlayKeyTextBox.Text = PlayKeyTextBox.Text.Substring(1) - End If - - PlayKeyTextBox.SelectAll() - PlayKey = PlayKeyTextBox.Text - - My.Settings.PlayKey = PlayKey - My.Settings.Save() - End Sub - Private Sub ChangeDirButton_Click(sender As Object, e As EventArgs) Handles ChangeDirButton.Click - If ChangeDirDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then - SteamappsPath = ChangeDirDialog.SelectedPath & "\" - LoadGames() - End If + ShowFolderSelector() End Sub - Public Sub LoadGames() + Private Sub LoadGames() GameSelector.Items.Clear() For Each Game In Games @@ -404,14 +400,180 @@ Public Class Form1 EnableInterface() Else - MsgBox("There are no games in your steamapps filder. Please click ""Change Dir"" and select a valid steamapps folder.") DisableInterface() ChangeDirButton.Enabled = True + ShowFolderSelector() + End If + + End Sub + + Private Sub ShowFolderSelector() + Dim ChangeDirDialog As New FolderBrowserDialog + ChangeDirDialog.Description = "Select your steamapps folder:" + ChangeDirDialog.ShowNewFolderButton = False + + If ChangeDirDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then + SteamappsPath = ChangeDirDialog.SelectedPath & "\" + LoadGames() + End If + + End Sub + + Private Sub LoadTrackKeys(ByVal Game As SourceGame) + Dim HotKeys As New Dictionary(Of String, String) 'Name, Key + Dim HotkeyFile As String = Path.Combine(Game.libraryname, "HotKeys.xml") + + If File.Exists(HotkeyFile) Then + Dim XmlFile As String + Using reader As StreamReader = New StreamReader(HotkeyFile) + XmlFile = reader.ReadToEnd + End Using + HotKeys = Deserialize(Of Dictionary(Of String, String))(XmlFile) End If + + + For Each Track In Game.tracks + If HotKeys.ContainsKey(Track.name) Then + + Track.hotkey = HotKeys.Item(Track.name) + + End If + Next + End Sub - Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork + Private Sub SaveTrackKeys(ByVal Game As SourceGame) + Dim HotKeys As New Dictionary(Of String, String) 'Name, Key + Dim HotkeyFile As String = Path.Combine(Game.libraryname, "HotKeys.xml") + + For Each Track In Game.tracks + If Not String.IsNullOrEmpty(Track.hotkey) Then + + HotKeys.Add(Track.name, Track.hotkey) + + End If + Next + + If HotKeys.Count > 0 Then + Using writer As StreamWriter = New StreamWriter(HotkeyFile) + writer.Write(Serialize(HotKeys)) + End Using + Else + If File.Exists(HotkeyFile) Then + File.Delete(HotkeyFile) + End If + End If + + End Sub + + Private Sub TrackList_MouseClick(sender As Object, e As MouseEventArgs) Handles TrackList.MouseClick + If e.Button = MouseButtons.Right Then + If TrackList.FocusedItem.Bounds.Contains(e.Location) = True Then + TrackContextMenu.Show(Cursor.Position) + End If + End If + End Sub + + Private Sub ContextRefresh_Click(sender As Object, e As EventArgs) Handles ContextRefresh.Click + ReloadTracks(GetCurrentGame) + RefreshTrackList() + End Sub + + Private Sub ContextDelete_Click(sender As Object, e As EventArgs) Handles ContextDelete.Click + Dim game As SourceGame = GetCurrentGame() + If MessageBox.Show(String.Format("Are you sure you want to delete {0}?", TrackList.SelectedItems(0).SubItems(1).Text), "Delete Track?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then + + Dim FilePath As String = Path.Combine(game.libraryname, TrackList.SelectedItems(0).SubItems(1).Text & game.FileExtension) + + If File.Exists(FilePath) Then + Try + File.Delete(FilePath) + Catch ex As Exception + MsgBox(String.Format("Failed to delete {0}.", FilePath)) + End Try + End If + + End If + + ReloadTracks(GetCurrentGame) + RefreshTrackList() + End Sub + + Private Sub LoadToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadToolStripMenuItem.Click + LoadTrack(GetCurrentGame, TrackList.SelectedItems(0).Index) + DisplayLoaded(TrackList.SelectedItems(0).Index) + End Sub + + Private Sub ContextHotKey_Click(sender As Object, e As EventArgs) Handles ContextHotKey.Click + Dim SelectKeyDialog As New SelectKey + Dim SelectedIndex = TrackList.SelectedItems(0).Index + If SelectKeyDialog.ShowDialog = Windows.Forms.DialogResult.OK Then + + For Each Game In Games.ToList + If Game Is GetCurrentGame() Then + Game.tracks(SelectedIndex).hotkey = SelectKeyDialog.ChosenKey + SaveTrackKeys(GetCurrentGame) + ReloadTracks(GetCurrentGame) + RefreshTrackList() + End If + Next + End If + End Sub + + Private Sub RemoveHotkeyToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RemoveHotkeyToolStripMenuItem.Click + Dim SelectedIndex = TrackList.SelectedItems(0).Index + For Each Game In Games.ToList + If Game Is GetCurrentGame() Then + Game.tracks(SelectedIndex).hotkey = vbNullString + SaveTrackKeys(GetCurrentGame) + ReloadTracks(GetCurrentGame) + RefreshTrackList() + End If + + Next + End Sub + + Private Sub GoToToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles GoToToolStripMenuItem.Click + Dim Games As SourceGame = GetCurrentGame() + Dim FilePath As String = Path.Combine(Games.libraryname, Games.tracks(TrackList.SelectedItems(0).Index).name & Games.FileExtension) + + + Dim Args As String = String.Format("/Select, ""{0}""", FilePath) + Dim pfi As New ProcessStartInfo("Explorer.exe", Args) + + System.Diagnostics.Process.Start(pfi) + End Sub + + Private Async Function CheckForUpdate() As Task + Dim UpdateText As String + + Using client As New HttpClient + Dim UpdateTextTask As Task(Of String) = client.GetStringAsync("http://slam.flankers.net/updates.php") + UpdateText = Await UpdateTextTask + End Using + + Dim NewVersion As Version + Dim UpdateURL As String = UpdateText.Split()(1) + If Version.TryParse(UpdateText.Split()(0), NewVersion) Then + If SlamVersion.CompareTo(NewVersion) < 0 Then + If MessageBox.Show(String.Format("An update ({0}) is available! Click ""OK"" to be taken to the download page.", NewVersion.ToString), "SLAM Update", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then + Process.Start(UpdateURL) + End If + End If + End If + End Function + + Private Sub PlayKeyButton_Click(sender As Object, e As EventArgs) Handles PlayKeyButton.Click + Dim SelectKeyDialog As New SelectKey + If SelectKeyDialog.ShowDialog = Windows.Forms.DialogResult.OK Then + My.Settings.PlayKey = SelectKeyDialog.ChosenKey + My.Settings.Save() + RefreshPlayKey() + End If + End Sub + Private Sub RefreshPlayKey() + PlayKeyButton.Text = String.Format("Play key: {0} (change)", My.Settings.PlayKey) End Sub End Class @@ -433,5 +595,6 @@ Public Class SourceGame Public Class track Public name As String Public tags As New List(Of String) + Public hotkey As String End Class End Class diff --git a/SLAM/My Project/Settings.Designer.vb b/SLAM/My Project/Settings.Designer.vb index 403d12c..fe02b7f 100644 --- a/SLAM/My Project/Settings.Designer.vb +++ b/SLAM/My Project/Settings.Designer.vb @@ -56,7 +56,7 @@ Namespace My _ + Global.System.Configuration.DefaultSettingValueAttribute("C:\Program Files (x86)\Steam\steamapps\")> _ Public Property SteamAppsFolder() As String Get Return CType(Me("SteamAppsFolder"),String) @@ -78,17 +78,29 @@ Namespace My End Set End Property - _ + _ Public Property LastGame() As String Get - Return CType(Me("LastGame"), String) + Return CType(Me("LastGame"),String) End Get - Set(value As String) + Set Me("LastGame") = value End Set End Property + + _ + Public Property NoHint() As Boolean + Get + Return CType(Me("NoHint"),Boolean) + End Get + Set + Me("NoHint") = value + End Set + End Property End Class End Namespace diff --git a/SLAM/My Project/Settings.settings b/SLAM/My Project/Settings.settings index 3b1f452..0d7fd6c 100644 --- a/SLAM/My Project/Settings.settings +++ b/SLAM/My Project/Settings.settings @@ -3,7 +3,7 @@ - + C:\Program Files (x86)\Steam\steamapps\ X @@ -11,5 +11,8 @@ + + False + \ No newline at end of file diff --git a/SLAM/SLAM.vbproj b/SLAM/SLAM.vbproj index ae66cc0..c4aa327 100644 --- a/SLAM/SLAM.vbproj +++ b/SLAM/SLAM.vbproj @@ -12,6 +12,21 @@ 512 WindowsForms v4.5 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -56,6 +71,8 @@ + + @@ -98,6 +115,13 @@ Settings.settings True + + SelectKey.vb + + + Form + + @@ -109,6 +133,9 @@ My.Resources Designer + + SelectKey.vb + @@ -125,6 +152,23 @@ + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SLAM/SelectKey.vb b/SLAM/SelectKey.vb new file mode 100644 index 0000000..0b17550 --- /dev/null +++ b/SLAM/SelectKey.vb @@ -0,0 +1,43 @@ +Public Class SelectKey + + Public ChosenKey As String + Dim WholeList As New List(Of String) + + Private Sub SelectKey_Load(sender As Object, e As EventArgs) Handles MyBase.Load + For Each item In BindKeyBox.Items + WholeList.Add(item.ToString) + Next + End Sub + + Private Sub BindKeyBox_TextChanged(sender As Object, e As EventArgs) Handles BindKeyBox.TextChanged + BindKeyBox.DroppedDown = False + + If String.IsNullOrEmpty(BindKeyBox.Text) Then + BindKeyBox.Items.Clear() + BindKeyBox.Items.AddRange(WholeList.ToArray) + Else + + BindKeyBox.Text = BindKeyBox.Text.ToUpper + BindKeyBox.SelectionStart = BindKeyBox.Text.Length + + If WholeList.Contains(BindKeyBox.Text) Then + BindKeyBox.ForeColor = Color.Green + Else + BindKeyBox.ForeColor = Color.Red + End If + End If + End Sub + + Private Sub SelectButton_Click(sender As Object, e As EventArgs) Handles SelectButton.Click + If WholeList.Contains(BindKeyBox.Text) Then + ChosenKey = BindKeyBox.Text + DialogResult = Windows.Forms.DialogResult.OK + + ElseIf String.IsNullOrEmpty(BindKeyBox.Text) Then + Me.Close() + + Else + MessageBox.Show("That bind key does not exist.", "Key Error", MessageBoxButtons.OK, MessageBoxIcon.Error) + End If + End Sub +End Class \ No newline at end of file diff --git a/SLAM/XmlSerialization.vb b/SLAM/XmlSerialization.vb new file mode 100644 index 0000000..5f364f8 --- /dev/null +++ b/SLAM/XmlSerialization.vb @@ -0,0 +1,26 @@ +Imports System.Xml +Imports System.IO +Imports System.Runtime.Serialization + +Public Class XmlSerialization + + Public Shared Function Serialize(Of T)(obj As T) As String + Dim serializer = New DataContractSerializer(obj.[GetType]()) + Using writer = New StringWriter() + Using stm = New XmlTextWriter(writer) + serializer.WriteObject(stm, obj) + Return writer.ToString() + End Using + End Using + End Function + + Public Shared Function Deserialize(Of T)(serialized As String) As T + Dim serializer = New DataContractSerializer(GetType(T)) + Using reader = New StringReader(serialized) + Using stm = New XmlTextReader(reader) + Return DirectCast(serializer.ReadObject(stm), T) + End Using + End Using + End Function + +End Class