/// <summary> /// Fills the list of categories with the folders found /// in the given module path. /// @Throws PSGuiException /// </summary> public void UpdateScriptCategoriesList() { string[] categoryList; try { categoryList = Directory.GetDirectories(modulePath); foreach (string category in categoryList) { _scriptCategories.Add(new ScriptCategory(category, modulePathLength)); } } catch (System.Exception e) { PsGuiException.WriteErrorToFile(e.ToString()); PsGuiException.WriteErrorToScreen("No script directory found!"); PsGuiException.CloseApp(); } }
/// <summary> /// Reads the selected powershell script and calls the functions /// responsible to parse and store the information. Adds /// all the gathered information to the ScriptVariables collection. /// </summary> /// <param name="script"></param> public void ReadSelectedScript(string scriptPath) { string[] lines = System.IO.File.ReadAllLines(scriptPath); string scriptHeaderEndTag = "#>"; int lineNum = 0; int lastHeaderLine = 1; // Must match number of meta data lines try { foreach (string line in lines) { // If header is completely parsed if (line.Equals(scriptHeaderEndTag)) { break; } // If script meta data (description...) if (lineNum <= lastHeaderLine) { ReadScriptHeader(lineNum, line); } // Else if input variables to script else { ReadScriptVariables(line); } lineNum++; } } catch (Exception e) { PsGuiException.WriteErrorToFile(e.ToString()); PsGuiException.WriteErrorToScreen("The header in the Powershell-script is improperly formated.\r\n\r\nClosing PsGui."); PsGuiException.CloseApp(); } AddScriptArgumentsToMainCollection(); }