public Form1() { InitializeComponent(); InitializeBackGroundWorker(); cfgArgCtrl = new ConfigArgumentControl(cfgLabelPanel, cfgSplitContainer.Panel2, cbPreCase, tbPreCase, cbPostCase, tbPostCase); this.Icon = Properties.Resources.SeeFlaw; this.Text = "SeeFlaw"; //Cursor.Current = new Cursor("MyWait.cur"); string startFile = ""; if (Environment.GetCommandLineArgs().Count() > 1) { startFile = Environment.GetCommandLineArgs()[Environment.GetCommandLineArgs().Count()-1]; if (!System.IO.File.Exists(startFile)) { MessageBox.Show("No such file " + startFile); startFile = ""; } } if (startFile != "") { OpenFile(startFile); } else { CreateTreeNode("first", false); } runTreeView.ImageList = NodeColors.GetColorList(); //Cursor.Current = Cursors.Default; }
public static List<RootNode> OpenFileInternal(ConfigArgumentControl cfgArgCtrl) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "xml files (*.xml)|*.xml"; dialog.InitialDirectory = System.IO.Directory.GetCurrentDirectory(); dialog.Title = "Name of config file"; if (dialog.ShowDialog() == DialogResult.OK && dialog.FileName != "") { return OpenFile(cfgArgCtrl, dialog.FileName); } return new List<RootNode>(); }
public static List<RootNode> OpenFile(ConfigArgumentControl cfgArgCtrl, string fileName) { if (fileName != null) { if (!fileName.EndsWith(".xml")) { MessageBox.Show("File must be of type xml!"); return OpenFileInternal(cfgArgCtrl); } return OpenFileInternal(cfgArgCtrl, fileName); } else { return OpenFileInternal(cfgArgCtrl); } }
public static List<RootNode> OpenFileInternal(ConfigArgumentControl cfgArgCtrl, string fileName) { List<RootNode> resultList = new List<RootNode>(); XmlDocument doc = new XmlDocument(); doc.Load(fileName); XmlNode rootElement = doc.FirstChild; if (rootElement == null || rootElement.Name != "seeflawgui") { MessageBox.Show("Xmlfile does not start with a seeflawgui node"); return resultList; } cfgArgCtrl.RemoveAllArguments(); XmlNode configElement = GetElementByName(rootElement, "config"); if (configElement != null) { foreach (XmlAttribute attr in configElement.Attributes) { cfgArgCtrl.AddArgument(attr.Name, attr.Value); } } foreach (XmlNode treeNode in rootElement.ChildNodes) { if (treeNode.Name == "tree") { XmlAttribute dirAttr = GetAttributeByName(treeNode, "dir"); if (dirAttr != null) { if (System.IO.Directory.Exists(dirAttr.Value)) { RootNode rootNode = CreateRootDirectory(dirAttr.Value); if (rootNode != null) { resultList.Add(rootNode); } } else { System.Console.WriteLine("No such directory exist " + dirAttr.Value); } } else { XmlAttribute nameAttr = GetAttributeByName(treeNode, "name"); { if (nameAttr != null) { RootNode rootNode = new RootNode(nameAttr.Value); foreach (XmlNode childNode in treeNode.ChildNodes) { RootNode child = BuildTree(childNode); if (child != null) { rootNode.Nodes.Add(child); } } resultList.Add(rootNode); } } } } } return resultList; }
public static void SaveFile(ConfigArgumentControl cfgArgCtrl, TreeView tree) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "xml files (*.xml)|*.xml"; dialog.InitialDirectory = System.IO.Directory.GetCurrentDirectory(); dialog.Title = "Name for config file"; if (dialog.ShowDialog() == DialogResult.OK && dialog.FileName != "") { XmlDocument doc = new XmlDocument(); XmlElement rootElement = doc.CreateElement("seeflawgui"); doc.AppendChild(rootElement); XmlElement configElement = doc.CreateElement("config"); rootElement.AppendChild(configElement); Dictionary<string, string> argDic = cfgArgCtrl.GetConfigArguments(); foreach (string key in argDic.Keys) { string value = ""; argDic.TryGetValue(key, out value); configElement.SetAttribute(key, value); } foreach (RootNode rootNode in tree.Nodes) { rootElement.AppendChild(rootNode.ToXml(doc)); } doc.Save(dialog.FileName); } }