public bool Parse() { if (!File.Exists(filename)) { return(false); } Lines.Clear(); Lines.AddRange(File.ReadAllLines(filename)); foreach (string Line in Lines) { if ((Line.Length > 0) && (Line[0] == '#')) { continue; } if ((!Line.Contains("server") && !Line.Contains("client") && !Line.Contains("mapper")) || string.IsNullOrEmpty(Line)) { continue; } bool Enabled; string Reserved = ""; ScriptApp App; ScriptType Type; int i = 0; char[] del = { ' ', '\t' }; string[] param = Line.Split(del, StringSplitOptions.RemoveEmptyEntries); if (param[0] == "@") { i = 1; Enabled = true; } else { Enabled = false; } string AppStr = param[i]; if (AppStr == "server") { App = ScriptApp.Server; } else if (AppStr == "client") { App = ScriptApp.Client; } else { App = ScriptApp.Mapper; } string TypeStr = param[i + 1]; if (TypeStr == "module") { Type = ScriptType.Module; } else { Type = ScriptType.Bind; } char[] trim = { '\t', '#' }; string Name = param[i + 2].TrimEnd(trim); List <string> Desc = new List <string>(); if (Type == ScriptType.Bind) { Reserved = param[3 + i++]; } ScriptDeclaration script = new ScriptDeclaration(Name, App, Type, Enabled); for (int y = i + 4; y < param.Length; y++) { Desc.Add(param[y].Trim(trim)); } script.Description = String.Join(" ", Desc.ToArray()); script.ReservedPlace = Reserved; Scripts.Add(script); } _IsParsed = true; return(true); }
public bool Parse() { if (!File.Exists(filename)) { return(false); } ScriptApp App = ScriptApp.Server; ScriptType Type = ScriptType.Module; Lines.Clear(); Lines.AddRange(File.ReadAllLines(filename)); foreach (string Line in Lines) { if (string.IsNullOrEmpty(Line?.Trim() ?? string.Empty) || Line.TrimStart(new char[] { ' ', '\t' }).StartsWith("#") || Line.TrimStart(new char[] { ' ', '\t' }).StartsWith(";")) { continue; } if (Line[0] == '[') { if (Line.ToLower().Contains("server")) { App = ScriptApp.Server; } else if (Line.ToLower().Contains("client")) { App = ScriptApp.Server; } else if (Line.ToLower().Contains("mapper")) { App = ScriptApp.Server; } else { return(false); } if (Line.ToLower().Contains("scripts")) { Type = ScriptType.Module; } else if (Line.ToLower().Contains("binds")) { Type = ScriptType.Bind; } else { return(false); } continue; } string[] row = Line.Split('='); string[] parameters = row[1].Split(new char[] { '#', ';' }); string param = String.Join(" ", parameters[0].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)); bool Enabled; string Reserved = ""; Enabled = Type == ScriptType.Bind || param.ToLower() == "load"; string Name = row[0].Trim(new char[] { ' ', '\t' }); List <string> Desc = new List <string>(); if (Type == ScriptType.Bind) { Reserved = param; } ScriptDeclaration script = new ScriptDeclaration(Name, App, Type, Enabled); script.Description = (parameters.Length > 1) ? parameters[1].Trim(new char[] { ' ', '\t' }) : ""; script.ReservedPlace = Reserved; Scripts.Add(script); } _IsParsed = true; return(true); }