public ActionQueueTriggerConfig(ActionQueueTrigger actionQueueTrigger) { _actionQueueTrigger = actionQueueTrigger; InitializeComponent(); NotificationDelayInput.Value = (decimal)GeneralHelper.ConstrainValue<double>(_actionQueueTrigger.NotificationDelay, 0, 1000); _initComplete = true; }
public bool Execute() { var oldSoundTriggersPath = Path.Combine(AssistantEngine.DataDir, "Modules", "SoundNotify"); if (!Directory.Exists(oldSoundTriggersPath)) { return false; } _oldSoundTriggersPath = oldSoundTriggersPath; var newTriggersPath = _moduleTriggers.ModuleDataDir; var queueModFile = Path.Combine(oldSoundTriggersPath, "QueueSoundMod.txt"); if (File.Exists(queueModFile)) { try { var file = new FileInfo(queueModFile); file.CopyTo(Path.Combine(newTriggersPath, "QueueSoundMod.txt"), true); } catch (Exception exception) { Logger.LogError("error while trying to copy queue sound modding file: " + queueModFile, this, exception); } } //var activeChars = new List<string>(); var moduleSettingsFile = Path.Combine(oldSoundTriggersPath, "settings.xml"); if (File.Exists(moduleSettingsFile)) { try { string xml = File.ReadAllText(moduleSettingsFile); xml = GetRidOfThisSillyNamespace(xml); XDocument doc = XDocument.Parse(xml); //activeChars = doc.Root // .Element("ActiveCharacterNames") // .Elements("Elements") // .Select(element => element.Value) // .ToList(); _moduleTriggers.Settings.Value.GlobalVolume = XmlConvert.ToSingle(doc.Root.Element("globalVolume").Value); _moduleTriggers.Settings.Value.GlobalMute = XmlConvert.ToBoolean(doc.Root.Element("GlobalMute").Value); } catch (Exception exception) { Logger.LogError("error while trying to import old global soundnotify settings: " + moduleSettingsFile, this, exception); } } string[] allExistingPlayers = Directory.GetDirectories(oldSoundTriggersPath); foreach (var playerDir in allExistingPlayers) { var playerName = new FileInfo(playerDir).Name; var manager = new TriggerManager(_moduleTriggers, playerName, newTriggersPath); var playlistFile = Path.Combine(playerDir, "playlist.txt"); if (File.Exists(playlistFile)) { var parser = new FileParser(playlistFile); IEnumerable<TriggerData> triggerDatas = parser.GetData(); foreach (var triggerData in triggerDatas) { try { ITrigger trigger; if (triggerData.IsRegex || triggerData.Condition.Contains('*')) { trigger = CreateRegexTrigger(triggerData); } else { trigger = CreateSimpleTrigger(triggerData); } manager.Settings.Value.AddTrigger(trigger); } catch (Exception exception) { Logger.LogError("Failed to create new trigger from parsed soundtrigger playlist!", this, exception); } } } var settingsFile = Path.Combine(playerDir, "settings.xml"); if (File.Exists(settingsFile)) { try { string xml = File.ReadAllText(settingsFile); xml = GetRidOfThisSillyNamespace(xml); XDocument doc = XDocument.Parse(xml); double delay = XmlConvert.ToDouble((doc.Root.Element("QueueDefDelay").Value)); bool soundEnabled = XmlConvert.ToBoolean(doc.Root.Element("QueueSoundEnabled").Value); var soundNameElem = doc.Root.Element("QueueSoundName"); string soundName = soundNameElem == null ? string.Empty : soundNameElem.Value; var trigger = new ActionQueueTrigger { NotificationDelay = delay, Active = soundEnabled }; trigger.AddNotifier(new SoundNotifier(soundName)); manager.Settings.Value.Muted = XmlConvert.ToBoolean(doc.Root.Element("Muted").Value); manager.Settings.Value.AddTrigger(trigger); } catch (Exception exception) { Logger.LogError("error while parsing old soundnotify settings!", this, exception); } } _moduleTriggers.AddManager(manager); } return true; }