public Sound AddSound(SirenOfShameSettings settings, string fileNameAndPath, string fileNameAndExtension) { var existingSound = settings.Sounds.FirstOrDefault(i => i.DisplayName == fileNameAndExtension); if (existingSound != null) DeleteSound(settings, existingSound); var soundsDir = GetSoundsDirAndEnsureExists(); var fileNameAsWav = Path.ChangeExtension(fileNameAndExtension, "wav"); var destinationFileNameAndPath = Path.Combine(soundsDir, fileNameAsWav); CopyOrConvertToWav(fileNameAndPath, destinationFileNameAndPath); Sound sound = new Sound { Location = destinationFileNameAndPath, DisplayName = fileNameAndExtension }; settings.Sounds.Add(sound); settings.Save(); return sound; }
public void Play(Sound sound) { Play(sound.Location); }
private void DeleteSound(Sound sound) { _soundService.DeleteSound(_settings, sound); RefreshSoundList(); }
public void DeleteSound(SirenOfShameSettings settings, Sound sound) { try { settings.Sounds.Remove(sound); settings.Save(); var sosAppDataFolder = SirenOfShameSettings.GetSosAppDataFolder(); var fileIsInOurFolder = sound.Location.StartsWith(sosAppDataFolder); // should be, but we can't assume someone hasn't tampered with the settings file if (fileIsInOurFolder) { File.Delete(sound.Location); } } catch (Exception ex) { _log.Warn("Unable to delete file", ex); } }
private ToolStripMenuItem WindowsAudioPatternMenu(Sound sound, Rule rule, string buildDefinitionId, TriggerType triggerType, string person) { bool patternIsMatch = false; if (rule != null && !string.IsNullOrEmpty(rule.WindowsAudioLocation)) patternIsMatch = sound.Location == rule.WindowsAudioLocation; var menu = new ToolStripMenuItem(sound.DisplayName) { Checked = patternIsMatch, Tag = new RuleDropDownItemTag { AlertType = null, BuildDefinitionId = buildDefinitionId, TriggerPerson = person, TriggerType = triggerType, LedPattern = null, WindowsAudioLocation = sound.Location, AudioPattern = null, Duration = null } }; menu.Click += RuleDropDownItemClick; return menu; }