From 7a7ce6e8fe1a35f6ccf54882b5c27becde736d8f Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Thu, 21 Jan 2021 13:52:03 -0600 Subject: [PATCH] Version 0.7 as marked by the folder name. --- SoundBoard.v11.suo | Bin 46080 -> 47104 bytes SoundBoard/Properties/AssemblyInfo.cs | 4 +- SoundBoard/aboutForm.Designer.cs | 2 +- SoundBoard/mainForm.Designer.cs | 73 ++---- SoundBoard/mainForm.cs | 331 ++++++++++++++++++-------- SoundBoard/mainForm.resx | 3 + 6 files changed, 252 insertions(+), 161 deletions(-) diff --git a/SoundBoard.v11.suo b/SoundBoard.v11.suo index aec83defd014ceb38ceaf3e0bfc6dcb91d74572f..69c10cb8835b09edfcdfc266980b776abc92d54d 100644 GIT binary patch delta 4647 zcmZp8!PM}9X@U)-@J3sGCcY1%b;%DiFEGk7FfcHvPOf6AVw^nrE0aGHAH(DaDhiVg znD`jGCzmq&^YAh-Fz_=lF#P}j|NrERVk*2{3=9lBAZ-i`4C0d+S)?U77#JA-f#m=H z|1ZM8z#z)NzyQ+rZ(^Xdfg}S1g9HNu13Lo)0~Z4WgBSw?12@z>kRCP$1_nJSUx9&v zVR8eD2`k7n=gEew;*&411PFRTrG21u;ABHqVbxG54`c`khcPfPgflQOL@+QgL^3ci zM1kB1GGk&w!z890z6Q<>th>1`GAc4KFdR^sT*X$!ScmTA+R3HNe!O76BKtYA24oi0 z&mg-%Sdf8%;qU+d|3Pl$L~{#B45S8x!6EVg|9@!)1_l8J1_mhx1_n83pt3;R$0Ezh zz`!7cWC$M;+ZLioVe%dh9Yt#f1_m2wc-t{BFxWFNFgP$UFgP+WFgP(VFnB@~v*>z5 zP4I=%ehdr@{tOHZ0SpWbK~S+^1_p)@P*8z1G4g=Oi3u%^O$-bS%?u0-El_*f7#JAZ z85kHkpnQ<8V0a<}14ADJ14BOp1H%NU{G`o)d3Q5T67ZP(NJS2mlqQ$(gm8c&9;6GD zh$esG@t=H{$#8NBZvc}rJjqS|!YklG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47i3DkTn1Y8RKMEY3oHR8Np2^P_yaZ z#=!NA6B9fpJIMA-?vXVC>11GlTd>IlpA(HHt>ytc;)64&#Q?Gm$q^XM40K1p8zeC8 e$PE%1kn12OGB98mH9>7N_SOoxu7|W%7#IM1c$ydh diff --git a/SoundBoard/Properties/AssemblyInfo.cs b/SoundBoard/Properties/AssemblyInfo.cs index 5a9a118..a468d8c 100644 --- a/SoundBoard/Properties/AssemblyInfo.cs +++ b/SoundBoard/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.5.0.0")] -[assembly: AssemblyFileVersion("0.5.0.0")] +[assembly: AssemblyVersion("0.7.0.0")] +[assembly: AssemblyFileVersion("0.7.0.0")] diff --git a/SoundBoard/aboutForm.Designer.cs b/SoundBoard/aboutForm.Designer.cs index 96729ae..be6708c 100644 --- a/SoundBoard/aboutForm.Designer.cs +++ b/SoundBoard/aboutForm.Designer.cs @@ -58,7 +58,7 @@ this.applicationVersionLabel.Name = "applicationVersionLabel"; this.applicationVersionLabel.Size = new System.Drawing.Size(194, 60); this.applicationVersionLabel.TabIndex = 1; - this.applicationVersionLabel.Text = "YouTube Soundboard \r\n\r\nVersion 0.5.0.0\r\n"; + this.applicationVersionLabel.Text = "YouTube Soundboard \r\n\r\nVersion 0.7.0.0\r\n"; // // asdfLabel // diff --git a/SoundBoard/mainForm.Designer.cs b/SoundBoard/mainForm.Designer.cs index 8988dbe..56562fc 100644 --- a/SoundBoard/mainForm.Designer.cs +++ b/SoundBoard/mainForm.Designer.cs @@ -39,17 +39,12 @@ this.mainMenuHelp = new System.Windows.Forms.ToolStripMenuItem(); this.mainMenuHelpAbout = new System.Windows.Forms.ToolStripMenuItem(); this.randomIterationNumericUpDown = new System.Windows.Forms.NumericUpDown(); - this.asdfMovieTabPage = new System.Windows.Forms.TabPage(); - this.asdfMovieListBox = new System.Windows.Forms.ListBox(); - this.gamerPoopTabPage = new System.Windows.Forms.TabPage(); - this.gamerPoopListBox = new System.Windows.Forms.ListBox(); this.soundboardTabControl = new System.Windows.Forms.TabControl(); this.loopSelectedSoundCheckBox = new System.Windows.Forms.CheckBox(); + this.fileSystemWatcherMain = new System.IO.FileSystemWatcher(); this.mainMenu.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.randomIterationNumericUpDown)).BeginInit(); - this.asdfMovieTabPage.SuspendLayout(); - this.gamerPoopTabPage.SuspendLayout(); - this.soundboardTabControl.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcherMain)).BeginInit(); this.SuspendLayout(); // // btnRandom @@ -109,8 +104,9 @@ // this.mainMenuPlayAll.CheckOnClick = true; this.mainMenuPlayAll.Name = "mainMenuPlayAll"; - this.mainMenuPlayAll.Size = new System.Drawing.Size(113, 22); + this.mainMenuPlayAll.Size = new System.Drawing.Size(152, 22); this.mainMenuPlayAll.Text = "Play &All"; + this.mainMenuPlayAll.Click += new System.EventHandler(this.mainMenuPlayAll_Click); // // mainMenuHelp // @@ -138,61 +134,20 @@ this.randomIterationNumericUpDown.Name = "randomIterationNumericUpDown"; this.randomIterationNumericUpDown.Size = new System.Drawing.Size(58, 20); this.randomIterationNumericUpDown.TabIndex = 4; + this.randomIterationNumericUpDown.TabStop = false; this.randomIterationNumericUpDown.Value = new decimal(new int[] { 1, 0, 0, 0}); // - // asdfMovieTabPage - // - this.asdfMovieTabPage.Controls.Add(this.asdfMovieListBox); - this.asdfMovieTabPage.Location = new System.Drawing.Point(4, 22); - this.asdfMovieTabPage.Name = "asdfMovieTabPage"; - this.asdfMovieTabPage.Padding = new System.Windows.Forms.Padding(3); - this.asdfMovieTabPage.Size = new System.Drawing.Size(410, 480); - this.asdfMovieTabPage.TabIndex = 1; - this.asdfMovieTabPage.Text = "ASDF Movie"; - this.asdfMovieTabPage.UseVisualStyleBackColor = true; - // - // asdfMovieListBox - // - this.asdfMovieListBox.FormattingEnabled = true; - this.asdfMovieListBox.Location = new System.Drawing.Point(-4, -2); - this.asdfMovieListBox.Margin = new System.Windows.Forms.Padding(0); - this.asdfMovieListBox.Name = "asdfMovieListBox"; - this.asdfMovieListBox.Size = new System.Drawing.Size(418, 485); - this.asdfMovieListBox.TabIndex = 0; - // - // gamerPoopTabPage - // - this.gamerPoopTabPage.Controls.Add(this.gamerPoopListBox); - this.gamerPoopTabPage.Location = new System.Drawing.Point(4, 22); - this.gamerPoopTabPage.Name = "gamerPoopTabPage"; - this.gamerPoopTabPage.Padding = new System.Windows.Forms.Padding(3); - this.gamerPoopTabPage.Size = new System.Drawing.Size(410, 480); - this.gamerPoopTabPage.TabIndex = 0; - this.gamerPoopTabPage.Text = "Gamer Poop"; - this.gamerPoopTabPage.UseVisualStyleBackColor = true; - // - // gamerPoopListBox - // - this.gamerPoopListBox.FormattingEnabled = true; - this.gamerPoopListBox.Location = new System.Drawing.Point(-4, -2); - this.gamerPoopListBox.Margin = new System.Windows.Forms.Padding(0); - this.gamerPoopListBox.Name = "gamerPoopListBox"; - this.gamerPoopListBox.Size = new System.Drawing.Size(418, 485); - this.gamerPoopListBox.TabIndex = 0; - // // soundboardTabControl // - this.soundboardTabControl.Controls.Add(this.gamerPoopTabPage); - this.soundboardTabControl.Controls.Add(this.asdfMovieTabPage); this.soundboardTabControl.Location = new System.Drawing.Point(7, 27); this.soundboardTabControl.Name = "soundboardTabControl"; this.soundboardTabControl.SelectedIndex = 0; this.soundboardTabControl.Size = new System.Drawing.Size(418, 506); - this.soundboardTabControl.TabIndex = 2; + this.soundboardTabControl.TabIndex = 0; // // loopSelectedSoundCheckBox // @@ -200,11 +155,16 @@ this.loopSelectedSoundCheckBox.Location = new System.Drawing.Point(158, 549); this.loopSelectedSoundCheckBox.Name = "loopSelectedSoundCheckBox"; this.loopSelectedSoundCheckBox.Size = new System.Drawing.Size(129, 17); - this.loopSelectedSoundCheckBox.TabIndex = 5; + this.loopSelectedSoundCheckBox.TabIndex = 3; this.loopSelectedSoundCheckBox.Text = "Loop Selected Sound"; this.loopSelectedSoundCheckBox.UseVisualStyleBackColor = true; this.loopSelectedSoundCheckBox.CheckedChanged += new System.EventHandler(this.loopSelectedSoundCheckBox_CheckedChanged); // + // fileSystemWatcherMain + // + this.fileSystemWatcherMain.EnableRaisingEvents = true; + this.fileSystemWatcherMain.SynchronizingObject = this; + // // formMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -224,9 +184,7 @@ this.mainMenu.ResumeLayout(false); this.mainMenu.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.randomIterationNumericUpDown)).EndInit(); - this.asdfMovieTabPage.ResumeLayout(false); - this.gamerPoopTabPage.ResumeLayout(false); - this.soundboardTabControl.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcherMain)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -242,14 +200,11 @@ private System.Windows.Forms.ToolStripMenuItem randSettingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem mainMenuPlayAll; private System.Windows.Forms.ToolStripMenuItem mainMenuFileShowOnDisk; - private System.Windows.Forms.TabPage asdfMovieTabPage; - private System.Windows.Forms.ListBox asdfMovieListBox; - private System.Windows.Forms.TabPage gamerPoopTabPage; - private System.Windows.Forms.ListBox gamerPoopListBox; private System.Windows.Forms.TabControl soundboardTabControl; private System.Windows.Forms.ToolStripMenuItem mainMenuHelp; private System.Windows.Forms.ToolStripMenuItem mainMenuHelpAbout; private System.Windows.Forms.CheckBox loopSelectedSoundCheckBox; + private System.IO.FileSystemWatcher fileSystemWatcherMain; } } diff --git a/SoundBoard/mainForm.cs b/SoundBoard/mainForm.cs index a7b7c2f..c45a72a 100644 --- a/SoundBoard/mainForm.cs +++ b/SoundBoard/mainForm.cs @@ -18,67 +18,205 @@ namespace SoundBoard public SoundPlayer player = new SoundPlayer(); public Random randomNum = new Random(); - bool willLoopSound = false; + public ListBox listBoxEntity = new ListBox(); + public string _workingDirectory; + public string[] _soundFiles; + public string[] _soundDirectories; + public bool willLoopSound = false; public formMain() { InitializeComponent(); - //create event handlers for onClick events in the ListBoxes - gamerPoopListBox.MouseClick += new MouseEventHandler(soundListBox_OnLeftClick); - asdfMovieListBox.MouseClick += new MouseEventHandler(soundListBox_OnLeftClick); - } - - private void soundListBox_OnLeftClick(object sender, MouseEventArgs e) - { - if (soundboardTabControl.SelectedIndex == 0) - { - string fullPath = Path.GetFullPath("gamer_poop/") + gamerPoopListBox.SelectedItem + ".wav"; - player.SoundLocation = fullPath; - player.Load(); - if (willLoopSound) - { - player.PlayLooping(); - } - else - { - player.Play(); - } - } - else if (soundboardTabControl.SelectedIndex == 1) - { - string fullPath = Path.GetFullPath("asdfmovie/") + asdfMovieListBox.SelectedItem + ".wav"; - player.SoundLocation = fullPath; - player.Load(); - if (willLoopSound) - { - player.PlayLooping(); - } - else - { - player.Play(); - } - } } private void formMain_Load(object sender, EventArgs e) { - string[] soundFiles; - soundFiles = Directory.GetFiles(Path.GetFullPath("gamer_poop/")); - foreach (string str in soundFiles) + _workingDirectory = Path.GetDirectoryName(Application.ExecutablePath); + _soundFiles = Directory.GetFiles(_workingDirectory); + foreach (string sound in _soundFiles) { - this.gamerPoopListBox.Items.Add(Path.GetFileNameWithoutExtension(str)); + CreateUITabs("Working Directory", _workingDirectory); } - soundFiles = Directory.GetFiles(Path.GetFullPath("asdfmovie/")); - foreach (string str in soundFiles) + + _soundDirectories = Directory.GetDirectories(_workingDirectory); + foreach (string sounds in _soundDirectories) { - asdfMovieListBox.Items.Add(Path.GetFileNameWithoutExtension(str)); + CreateUITabs(Path.GetFileName(sounds), sounds); + } + fileSystemWatcherMain.Path = _workingDirectory; + fileSystemWatcherMain.IncludeSubdirectories = true; + fileSystemWatcherMain.Created += new FileSystemEventHandler(fileSystemUpdateDetected); //file or folder created + fileSystemWatcherMain.Deleted += new FileSystemEventHandler(fileSystemUpdateDetected); //file or folder moved or deleted + fileSystemWatcherMain.Renamed += new RenamedEventHandler(fileSystemUpdateDetected); //for any file changes like file extension changes + soundboardTabControl.SelectedIndexChanged += new EventHandler(CheckForDisabledListBox); //disables ore enables the Show on Disk file menu object + listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0]; + if (listBoxEntity.Enabled == true) + { + listBoxEntity.SelectedIndex = 0; + } + } + + private void fileSystemUpdateDetected(object sender, FileSystemEventArgs e) + { + //perform the UI refresh operation + RefreshUIControls(); + } + + private void CheckForDisabledListBox(object sender, EventArgs e) + { + ListBox listBoxEntity = new ListBox(); + try + { + listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0]; + } + catch (Exception spam) + { + return; + } + + if (listBoxEntity.Enabled == false) + { + mainMenuFileShowOnDisk.Enabled = false; + } + else + { + listBoxEntity.SelectedIndex = 0; + mainMenuFileShowOnDisk.Enabled = true; + } + } + + private void RefreshUIControls() + { + _workingDirectory = Path.GetDirectoryName(Application.ExecutablePath); + _soundDirectories = Directory.GetDirectories(_workingDirectory); + + soundboardTabControl.Controls.Clear(); + + foreach (string sounds in _soundFiles) + { + CreateUITabs("Working Directory", _workingDirectory); + } + foreach (string files in _soundDirectories) + { + CreateUITabs(Path.GetFileName(files), files); + } + } + + private void CreateUITabs(string tabName, string directoryPath) + { + //add tabs dynamically + int soundControlHeight = soundboardTabControl.Height; + int soundControlWidth = soundboardTabControl.Width; + string[] directoryFiles; //files in the target directory + TabPage tab = new TabPage(); + ListBox localListBox = new ListBox(); + + if (soundboardTabControl.Controls.ContainsKey(tabName.Replace(" ", "") + "Tab")) + { + + } + else + { + tab.Text = tabName; //display the folder's full name to the user + tab.Name = tabName.Replace(" ", "") + "Tab"; //create a legal name for the tab's (name) property + tab.Height = soundControlHeight - 20; + tab.Height = soundControlWidth; + soundboardTabControl.Controls.Add(tab); + + localListBox.Height = soundControlHeight - 20; + localListBox.Width = soundControlWidth - 7; + localListBox.Name = tabName.Replace(" ", "") + "ListBox"; + tab.Controls.Add(localListBox); + localListBox.Click += new EventHandler((sender, e) => ListBoxOnLeftClick(sender, e, localListBox)); //create event handler for the lsit box and pass the object in + } + + directoryFiles = Directory.GetFiles(Path.GetFullPath(directoryPath)); + + foreach (string files in directoryFiles) + { + switch (Path.GetExtension(files))//check to make sure the file is a sound file + { + case ".wav": + case ".mp3": + localListBox.Items.Add(Path.GetFileNameWithoutExtension(files)); + break; + default: + break; + } + } + if (localListBox.Items.Count == 0) + { + localListBox.Items.Add("No sound files found in the " + tabName + " directory."); + localListBox.Enabled = false; + if (soundboardTabControl.SelectedIndex == 0) + { + mainMenuFileShowOnDisk.Enabled = false; + } + } + } + + private void ListBoxOnLeftClick(object sender, EventArgs e, ListBox list) + { + //check to make sure something is actually selected + if (list.SelectedItem == null) + { + return; + } + //get the file's location on disk, double back if it's not a .wav file + string fileLocation; + if (soundboardTabControl.SelectedIndex == 0) + { + fileLocation = _workingDirectory + "\\" + list.SelectedItem.ToString() + ".wav"; + if (!File.Exists(fileLocation)) + { + fileLocation = _workingDirectory + "\\" + list.SelectedItem.ToString() + ".mp3"; + } + } + else + { + fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + list.SelectedItem.ToString() + ".wav"; + if (!File.Exists(fileLocation)) + { + fileLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + list.SelectedItem.ToString() + ".mp3"; + } + } + if (File.Exists(fileLocation))//check for the file's existance + { + player.SoundLocation = fileLocation; + player.Load(); + //try playing the sound file + try + { + if (willLoopSound) + { + player.PlayLooping(); + } + else + { + player.Play(); + } + } + catch (InvalidOperationException Ex) + { + MessageBox.Show("The file '" + list.SelectedItem.ToString() + "' couldn't be played.", "Invalid Sound File"); + } + } + else + { + MessageBox.Show("The file '" + list.SelectedItem.ToString() + "' couldn't be found.", "File Not Found"); } } private void btnRandom_Click(object sender, EventArgs e) { int iterations = (int)randomIterationNumericUpDown.Value; - string fullPath; + listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0]; + + if (listBoxEntity.Enabled == false) + { + //the ListBox is disabled and therefore contains no sounds, so return + return; + } //disable the Random Button and the NumericUpDown box btnRandom.Enabled = false; randomIterationNumericUpDown.Enabled = false; @@ -95,30 +233,43 @@ namespace SoundBoard for (int i = 0; i < iterations; i++) { - int tempRandomNumber; - if (soundboardTabControl.SelectedIndex == 0) { - tempRandomNumber = randomNum.Next(gamerPoopListBox.Items.Count - 1); - gamerPoopListBox.SelectedIndex = tempRandomNumber; - fullPath = Path.GetFullPath("gamer_poop/") + gamerPoopListBox.SelectedItem + ".wav"; - player.SoundLocation = fullPath; - player.Load(); - player.PlaySync(); - } - else if (soundboardTabControl.SelectedIndex == 1) - { - tempRandomNumber = randomNum.Next(asdfMovieListBox.Items.Count - 1); - asdfMovieListBox.SelectedIndex = tempRandomNumber; - fullPath = Path.GetFullPath("asdfmovie/") + asdfMovieListBox.SelectedItem + ".wav"; - player.SoundLocation = fullPath; + listBoxEntity.SelectedIndex = randomNum.Next(listBoxEntity.Items.Count); + if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav")) + { + player.SoundLocation = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"; + } + else if (File.Exists(_workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3")) + { + player.SoundLocation = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"; + } + else + { + MessageBox.Show("The file '" + listBoxEntity.SelectedItem.ToString() + "' couldn't be found.", "File Not Found"); + return; + } player.Load(); player.PlaySync(); } else { - MessageBox.Show("The " + soundboardTabControl.SelectedTab.Text + " tab has no sounds to play.", "No Waves Here"); - return; + listBoxEntity.SelectedIndex = randomNum.Next(listBoxEntity.Items.Count); + if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav")) + { + player.SoundLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"; + } + else if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3")) + { + player.SoundLocation = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"; + } + else + { + MessageBox.Show("The file '" + listBoxEntity.SelectedItem.ToString() + "' couldn't be found.", "File Not Found"); + return; + } + player.Load(); + player.PlaySync(); } } //renable the controls @@ -142,58 +293,33 @@ namespace SoundBoard private void playRandomSoundBothColumns(int iterations) { - int tempRandomNumber = 0; - int incrementor = 0; - string soundPath; - - while (incrementor < iterations) - { - Random rand = new Random(); - tempRandomNumber = rand.Next(0, 200); - if (tempRandomNumber <= 100) - { - soundboardTabControl.SelectedIndex = 0; - tempRandomNumber = randomNum.Next(gamerPoopListBox.Items.Count - 1); - gamerPoopListBox.SelectedIndex = tempRandomNumber; - soundPath = Path.GetFullPath("gamer_poop/") + gamerPoopListBox.SelectedItem + ".wav"; - player.SoundLocation = soundPath; - player.Load(); - player.PlaySync(); - } - else - { - soundboardTabControl.SelectedIndex = 1; - tempRandomNumber = randomNum.Next(asdfMovieListBox.Items.Count - 1); - asdfMovieListBox.SelectedIndex = tempRandomNumber; - soundPath = Path.GetFullPath("asdfmovie/") + asdfMovieListBox.SelectedItem + ".wav"; - player.SoundLocation = soundPath; - player.Load(); - player.PlaySync(); - } - incrementor++; - } + } private void mainMenuFileShowOnDisk_Click(object sender, EventArgs e) { string filePath; string arg; + listBoxEntity = (ListBox)soundboardTabControl.SelectedTab.Controls[0]; if (soundboardTabControl.SelectedIndex == 0) { - filePath = Path.GetFullPath("gamer_poop/") + gamerPoopListBox.SelectedItem + ".wav"; - arg = "/select, " + '"' + filePath + '"'; - Process.Start("explorer.exe", arg); - } - else if (soundboardTabControl.SelectedIndex == 1) - { - filePath = Path.GetFullPath("asdfmovie/") + asdfMovieListBox.SelectedItem + ".wav"; + filePath = _workingDirectory + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"; arg = "/select, " + '"' + filePath + '"'; Process.Start("explorer.exe", arg); } else { - MessageBox.Show("Unable to open files in this tab.", "Error"); + filePath = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".wav"; + if (File.Exists(filePath)) + { + Process.Start("explorer.exe", "/select, " + '"' + filePath + '"'); + } + else if (File.Exists(_workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3")) + { + filePath = _workingDirectory + "\\" + soundboardTabControl.SelectedTab.Text + "\\" + listBoxEntity.SelectedItem.ToString() + ".mp3"; + Process.Start("explorer.exe", "/select, " + '"' + filePath + '"'); + } } } @@ -201,11 +327,18 @@ namespace SoundBoard { aboutForm aboutDialogForm = new aboutForm(); aboutDialogForm.ShowDialog(); + aboutDialogForm.Dispose(); } private void mainMenuFileExit_Click(object sender, EventArgs e) { Close(); } + + private void mainMenuPlayAll_Click(object sender, EventArgs e) + { + MessageBox.Show("Under construction", "To Be Added", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + mainMenuPlayAll.Checked = false; + } } } diff --git a/SoundBoard/mainForm.resx b/SoundBoard/mainForm.resx index 1877780..e3e9191 100644 --- a/SoundBoard/mainForm.resx +++ b/SoundBoard/mainForm.resx @@ -120,6 +120,9 @@ 17, 17 + + 127, 17 + 43