public static bool Load(string path) { Debug.Assert(null != path); Debug.Assert(string.Empty != path); if (!File.Exists(path)) { UtilSys.MessageBoxInfo("Settings Load: " + path); CreateDefaultSettingsFile(path); UtilSys.Sleep(1000); return(false); } _path = path; _dic.Clear(); List <string> lst = UtilIO.ReadFile(_path); char[] sep = { ' ', '=', ' ' }; string[] stringSeparators = new string[] { " = " }; foreach (string line in lst) { string[] tmp = line.Split(stringSeparators, StringSplitOptions.None); _dic.Add(tmp[0], tmp[1]); } // at this point we have settings loaded // but there is a possibility that new setting keys are not in file, we have to check and fix that string key = string.Empty; string value = string.Empty; foreach (string keyLine in m_Settings) { string[] tmp = keyLine.Split(stringSeparators, StringSplitOptions.None); key = tmp[0]; value = tmp[1]; if (!_dic.ContainsKey(key)) { Add(key, value); } } Save(); return(true); }
public static List <string> LoadServerIPHistory() { if (!File.Exists(_pathServerIPHistory)) { using (StreamWriter SW = File.CreateText(_pathServerIPHistory)) { } } List <string> history = UtilIO.ReadFile(_pathServerIPHistory); return(history); }
public static bool Parse(FrmScripter frmScp, Editor editor) { Debug.Assert(null != frmScp); Debug.Assert(null != editor); _frm = frmScp; _editor = editor; _editor.Variables.Clear(); _editor.Functions.Clear(); CreateDefaultTreeNodes(); CreateTreeNodes(_frm.tvwImported, _editor.Path2File); List <string> lst = new List <string>(_editor.Lines); ParseLines(lst); foreach (string rawline in editor.Lines) { string line = rawline.Trim(); if (line.StartsWith(keyword_import)) { string str = line.Replace(keyword_import, ""); str = str.Trim(); str = str.Substring(1, str.Length - 2); CreateTreeNodes(frmScp.tvwImported, str); lst = UtilIO.ReadFile(Path.Combine(Application.StartupPath, str)); ParseLines(lst); } } foreach (TreeNode node in _nodesFiles) { node.Expand(); } _frm.tvwImported.SelectedNode = _frm.tvwImported.Nodes[0]; return(true); }
// here we simply import other script file into our _lines List at the current position private static void LoadImportScript(string path2Import) { Debug.Assert(null != path2Import); _vm.host.WriteLog("Loading Import Script: " + path2Import); string tmp = path2Import.Trim(); string path = Path.Combine(_vm.host.StartupPath, tmp); if (!File.Exists(path)) { throw new FileNotFoundException("File '" + path + "' does not exist."); } try { List <string> lines = UtilIO.ReadFile(path); if (_bWriteLog) { _vm.host.WriteLog("Loading Import Script: '" + path + "', Lines: " + lines.Count); } _LoadedFiles.Push(path); _LineNumbers.Push(_lineNum); _lineNum = -1; int index = _lines.IndexOf(_raw); _lines.RemoveAt(index); _lines.Insert(index, _ImportEndMark + "[" + path + "]"); for (int i = lines.Count - 1; i > -1; --i) { _lines.Insert(index, lines[i]); } _lines.Insert(index, _ImportBeginMark + "[" + path + "]"); } catch { throw; } }
public static void Load(string path) { List <string> lst = UtilIO.ReadFile(path); items.Clear(); comments.Clear(); if (0 == lst.Count) { return; } if ("v1.1" == lst[0]) { ParseScopedDataFile(lst); return; } ParseVariables(lst); }
public static void Load(string path, Script script) { Debug.Assert(null != path); Debug.Assert(null != script); _script = script; _tokens = new List <string>(); if (_bWriteLog) { _vm.host.WriteLog("\r\n<Parser>"); } try { _lines = UtilIO.ReadFile(path); if (_bWriteLog) { _vm.host.WriteLog("Parser Load File: '" + path + "', Lines: " + _lines.Count); } _LoadedFiles.Push(path); _LineNumbers.Push(0); ProcessLines(); } catch { throw; } if (_bWriteLog) { DumpFinalScriptToLogFile(); _vm.host.WriteLog("</Parser>"); } }