/// <summary> /// GaGa implementation. /// </summary> /// <param name="streamsFilePath"> /// Path for the streams file to use. /// </param> public GaGa(String streamsFilePath) { // streams file and loader: streamsFile = new StreamsFile(streamsFilePath, "GaGa.Resources.streams.ini"); menuLoader = new StreamsMenuLoader(streamsFile); // gui components: container = new Container(); notifyIcon = new NotifyIcon(container); notifyIcon.Visible = true; MenuRecreate(); // error items: errorOpenItem = new MenuItem("Error opening streams file (click for details)", OnErrorOpenItemClick); errorReadItem = new MenuItem("Error reading streams file (click for details)", OnErrorReadItemClick); // constant items: editItem = new MenuItem("Edit streams file", OnEditItemClick); exitItem = new MenuItem("Exit", OnExitItemClick); // playing: player = new Player(notifyIcon); }
/// <summary> /// Can read or recreate a streams file, monitor changes, /// and add all the sections and items to a context menu. /// </summary> /// <param name="file">Streams file to read from.</param> public StreamsMenuLoader(StreamsFile file) { this.file = file; reader = new StreamsFileReader(); lastUpdated = null; }
/// <summary> /// Raised by StreamsFileReader on a reading error. /// </summary> /// <param name="message">Error message.</param> /// <param name="file">Streams file that triggered the error.</param> /// <param name="line">Line text for the incorrect line.</param> /// <param name="linenumber">Line where the error happened.</param> public StreamsFileReadError(String message, StreamsFile file, String line, Int32 linenumber) : base(message) { File = file; Line = line; LineNumber = linenumber; }
/// <summary> /// An INIReader that reads lines from a streams file /// adding sections and key=value pairs to a context menu /// as submenus and clickable items. /// </summary> public StreamsFileReader() { file = null; menu = null; onClick = null; currentMenuItems = null; seenSubmenues = new Dictionary<String, MenuItem>(); currentLineNumber = 0; currentLine = String.Empty; }
/// <summary> /// Read a streams file adding submenus items to a context menu. /// </summary> /// <param name="file">Streams file to read lines from.</param> /// <param name="menu">Target context menu.</param> /// <param name="onClick">Click event to attach to menu items.</param> public void Read(StreamsFile file, ContextMenu menu, EventHandler onClick) { this.file = file; this.menu = menu; this.onClick = onClick; // start at root: currentMenuItems = menu.MenuItems; try { foreach (String line in file.ReadLines()) { currentLineNumber++; currentLine = line; ReadLine(line); } } finally { ResetState(); } }
/// <summary> /// Clear internal state. /// </summary> private void ResetState() { file = null; menu = null; onClick = null; currentMenuItems = null; seenSubmenues.Clear(); currentLineNumber = 0; currentLine = String.Empty; }