protected void BuildMenu(bool addActionDescriptionOutput) { if (ActionOptions.Count == 0) { Console.WriteLine("Cant build the menu - Actions dictionary is empty"); return; } StringBuilder tempMenu = new StringBuilder(); tempMenu.AppendLine($"-------- {MenuName.ToUpper()} --------"); tempMenu.AppendLine(); tempMenu.AppendLine($"---{MainOutput}---"); tempMenu.AppendLine(); foreach (T option in ActionOptions.Keys) { string line = option.ToString(); if (addActionDescriptionOutput) { line += " - " + ActionOptions[option].actionDescriptionOutput; } tempMenu.AppendLine(line); } tempMenu.AppendLine("=================================="); MenuDisplay = tempMenu; }
private void HandleMenus(RMSQLiteConnection DB) { AddToLog("Importing menus"); // Get menu names List <string> MenuNames = new List <string>(); SQL = "SELECT DISTINCT MenuName FROM MenuTbl WHERE MenuName <> 'GLOBAL' ORDER BY MenuName"; DB.ExecuteReader(SQL); while (DB.Reader.Read()) { MenuNames.Add(DB.Reader["MenuName"].ToString()); } DB.Reader.Close(); // Erase old menus foreach (string MenuName in MenuNames) { string FileName = StringUtils.PathCombine(ProcessUtils.StartupPath, "menus", MenuName.ToLower().Replace(" ", "_") + ".ini"); if (File.Exists(FileName)) { FileUtils.FileDelete(FileName); } } // Add hotkeys to menus SQL = "SELECT * FROM MenuTbl ORDER BY MenuName, HotKey"; DB.ExecuteReader(SQL); while (DB.Reader.Read()) { string HotKey = DB.Reader["HotKey"].ToString(); string Name = DB.Reader["Description"].ToString(); string Action = CommandToAction(DB.Reader["Command"].ToString()); string Parameters = DB.Reader["Parameters"].ToString(); string RequiredAccess = DB.Reader["RequiredAccess"].ToString(); // Modify parameters, for those that need it if (Action == "ChangeMenu") { Parameters = Parameters.Replace(" ", "_"); } else if (Action == "RunDoor") { Parameters = GetSafeDoorFileName(Name); } if (Action == DB.Reader["Command"].ToString()) { AddToLog(" - Ignoring command that no longer exists (" + Action + ")"); } else { List <string> MenuNamesToUpdate = new List <string>(); if (DB.Reader["MenuName"].ToString().ToUpper() == "GLOBAL") { foreach (string MenuName in MenuNames) { // Don't add the global CHANGE_MENU commands to the menu we're wanting to change to // i.e. Don't add a CHANGE_MENU MAIN to the MAIN menu if ((Action != "ChangeMenu") || (Parameters.ToUpper() != MenuName.ToUpper())) { MenuNamesToUpdate.Add(MenuName); } } } else { MenuNamesToUpdate.Add(DB.Reader["MenuName"].ToString()); } foreach (string MenuNameToUpdate in MenuNamesToUpdate) { using (IniFile Ini = new IniFile(StringUtils.PathCombine(ProcessUtils.StartupPath, "menus", MenuNameToUpdate.ToLower().Replace(" ", "_") + ".ini"))) { Ini.WriteString(HotKey, "Name", Name); Ini.WriteString(HotKey, "Action", Action); Ini.WriteString(HotKey, "Parameters", Parameters); Ini.WriteString(HotKey, "RequiredAccess", RequiredAccess); AddToLog(" - Added Menu = " + MenuNameToUpdate); AddToLog(" HotKey = " + HotKey); AddToLog(" Name = " + Name); AddToLog(" Action = " + Action); AddToLog(" Parameters = " + Parameters); AddToLog(" RequiredAccess = " + RequiredAccess); } } } } DB.Reader.Close(); // RecordID, MenuName, HotKey, Description, Command, Parameters, RequiredAccess AddToLog(""); }