Пример #1
0
        public SoundFile randomFile()
        {
            Random    rnd      = new Random();
            SoundFile randFile = new SoundFile();

            SoundBoard.TryGetValue(rnd.Next(0, SoundBoard.Count), out randFile);


            return(randFile);
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbLocation.Text))
            {
                MessageBox.Show("Location is empty");
                return;
            }

            if (SettingsForm.addingEditingLoadXMLFile && string.IsNullOrWhiteSpace(tbKeys.Text))
            {
                MessageBox.Show("No keys entered");
                return;
            }

            string[] soundLocs    = null;
            string   errorMessage = "";

            if (!SettingsForm.addingEditingLoadXMLFile)
            {
                if (!SettingsForm.addingEditingLoadXMLFile && Helper.soundLocsArrayFromString(tbLocation.Text, out soundLocs, out errorMessage))
                {
                    if (soundLocs.Any(x => string.IsNullOrWhiteSpace(x) || !File.Exists(x)))
                    {
                        MessageBox.Show("The file/one of the files does not exist");

                        this.Close();

                        return;
                    }
                }

                if (soundLocs == null)
                {
                    MessageBox.Show(errorMessage);
                    return;
                }
            }

            Keys[] keysArr;

            if (!Helper.keysArrayFromString(tbKeys.Text, out keysArr, out errorMessage))
            {
                keysArr = new Keys[] { }
            }
            ;


            if (SettingsForm.addingEditingLoadXMLFile)
            {
                if (editIndex != -1)
                {
                    settingsForm.lvKeysLocs.Items[editIndex].Text             = tbKeys.Text;
                    settingsForm.lvKeysLocs.Items[editIndex].SubItems[1].Text = tbLocation.Text;

                    settingsForm.loadJSONFilesList[editIndex].Keys         = keysArr;
                    settingsForm.loadJSONFilesList[editIndex].JSONLocation = tbLocation.Text;
                }
                else
                {
                    var item = new ListViewItem(tbKeys.Text);
                    item.SubItems.Add(tbLocation.Text);

                    settingsForm.lvKeysLocs.Items.Add(item);

                    settingsForm.loadJSONFilesList.Add(new JSONSettings.LoadJSONFile(keysArr, tbLocation.Text));
                }
            }
            else
            {
                if (editIndex > -1)
                {
                    ///
                    /// Fix editing sound file (changing sound file)
                    /// -- change filename with associated selected key
                    ///

                    //SoundFile sf = new SoundFile();
                    SoundFile tempSF = new SoundFile();
                    string    eM;
                    mainForm.soundFileData.TryGetValue(editIndex, out tempSF);
                    //mainForm.allSounds.TryGetValue(editIndex, out tempSF);
                    if (tbKeys.Text.Contains('+'))
                    {
                        var tempStr = tbKeys.Text.Split('+');
                        tempSF.keys = Helper.stringArrayToKeysArray(tempStr);
                        //tempSF.keys = Helper.keysArrayFromString(tbKeys.Text, out keys, out eM);
                        var tempArr       = Helper.keysArrayToStringArray(tempSF.keys);
                        var keySoundsText = "";
                        foreach (string item in tempArr)
                        {
                            if (item != tempArr[tempArr.Length - 1])
                            {
                                keySoundsText += item;
                                keySoundsText += "+";
                            }
                            else
                            {
                                keySoundsText += item;
                            }
                        }
                        tempSF.filePath = tbLocation.Text;
                        tempSF.hotKey   = keySoundsText;

                        mainForm.lvKeySounds.Items[editIndex].Text             = tempSF.hotKey;
                        mainForm.lvKeySounds.Items[editIndex].SubItems[1].Text = tempSF.filePath;
                    }
                    else
                    {
                        //Enum.TryParse(tbKeys.Text, out tempHK);
                        //mainForm.lvKeySounds.Items[editIndex].Text = Helper.stringToKey(tbKeys.Text).ToString();
                        tempSF.hotKey     = tbKeys.Text;
                        tempSF.pressedKey = Helper.stringToKey(tbKeys.Text);
                        tempSF.keys       = new Keys[] { tempSF.pressedKey };
                        tempSF.filePath   = tbLocation.Text;
                        mainForm.lvKeySounds.Items[editIndex].Text             = tbKeys.Text;
                        mainForm.lvKeySounds.Items[editIndex].SubItems[1].Text = tbLocation.Text;


                        //Helper.keysArrayFromString(tempSF.hotKey, out keys, out eM);
                        //tempSF.pressedKey = keys[1];
                    }

                    //mainForm.keysSounds[editIndex] = new XMLSettings.KeysSounds(keysArr, soundLocs);
                }
                else
                {
                    SoundFile sf = helperAddFile(tbKeys.Text, tbLocation.Text);
                }

                mainForm.chHotkey.Width   = -2;
                mainForm.chFileName.Width = -2;
            }

            this.Close();
        }
        private SoundFile helperAddFile(string hotkeyStr, string fileName)
        {
            SoundFile returningSF = new SoundFile();

            if (fileName.Contains(';'))
            {
                string[] temp  = fileName.Split(';');
                int      count = 0;

                foreach (string file in temp)
                {
                    returningSF          = new SoundFile();
                    returningSF.filePath = file;
                    //Enum.TryParse(tbKeys.Text, out tempHK);
                    returningSF.hotKey    = hotkeyStr;
                    returningSF.playCount = 0;
                    if (hotkeyStr.Contains('+'))
                    {
                        var tempStr = hotkeyStr.Split('+');
                        returningSF.keys = Helper.stringArrayToKeysArray(tempStr);
                        //tempSF.keys = Helper.keysArrayFromString(tbKeys.Text, out keys, out eM);
                    }
                    else
                    {
                        returningSF.filePath  = file;
                        returningSF.playCount = 0;

                        returningSF.pressedKey = Helper.stringToKey(hotkeyStr);
                        returningSF.keys       = new Keys[] { returningSF.pressedKey };
                    }
                    ListViewItem item = new ListViewItem();
                    item.Text = returningSF.hotKey;
                    item.SubItems.Add(returningSF.filePath);
                    mainForm.lvKeySounds.Items.Add(item);
                    mainForm.soundFileData.Add(mainForm.soundFileData.Count, returningSF);
                    mainForm.allSounds.Add(mainForm.allSounds.Count, returningSF);
                    count++;
                }
            }
            else
            {
                if (hotkeyStr.Contains('+'))
                {
                    var tempStr = hotkeyStr.Split('+');
                    returningSF.keys = Helper.stringArrayToKeysArray(tempStr);
                    //tempSF.keys = Helper.keysArrayFromString(tbKeys.Text, out keys, out eM);
                }

                else
                {
                    returningSF.keys = new Keys[] { returningSF.pressedKey }
                };


                returningSF.filePath   = fileName;
                returningSF.playCount  = 0;
                returningSF.pressedKey = Helper.stringToKey(hotkeyStr);


                //Enum.TryParse(tbKeys.Text, out tempHK);
                returningSF.hotKey = hotkeyStr;
                mainForm.soundFileData.Add(mainForm.soundFileData.Count, returningSF);
                mainForm.allSounds.Add(mainForm.allSounds.Count, returningSF);

                var newItem = new ListViewItem(hotkeyStr);
                newItem.SubItems.Add(fileName);

                mainForm.lvKeySounds.Items.Add(newItem);
            }
            return(returningSF);
        }