/// <summary> /// Show the dialog. /// </summary> /// <param name="owner">owner form</param> /// <param name="list">instance of SyncPathList</param> /// <returns>DialogResult</returns> public DialogResult ShowDialog(IWin32Window owner, SyncPathList list) { pathList = list; // copy items from ArrayList to ListView lvPaths.Items.Clear(); foreach (PathPair pp in pathList) { ListViewItem newItem = new ListViewItem(new string[] { pp.Source, pp.Destination }); lvPaths.Items.Add(newItem); } return base.ShowDialog(owner); }
/// <summary> /// Load settings from the given file. /// </summary> /// <param name="fileName">file to load settings from</param> /// <param name="syncPathList">list with paths to synchronize</param> public void LoadJob(string fileName, SyncPathList syncPathList) { XmlDocument doc = new XmlDocument(); doc.Load(fileName); syncPathList.Clear(); ContextMenu.Clear(); bool contextMenuRead = false; ContextDblClickIdx = -1; foreach (XmlNode node in doc.ChildNodes) { if ((node.NodeType == XmlNodeType.Element) && (node.Name == "InZync")) { if (node.HasChildNodes) { foreach (XmlNode param in node.ChildNodes) { if (param.NodeType == XmlNodeType.Element) { // read paths to synchronize if (param.Name == "SourcePaths") { foreach (XmlNode pathNode in param.ChildNodes) { if (pathNode.Name == "Path") { PathPair pp = new PathPair(); XmlAttribute attr = pathNode.Attributes["source"]; if (attr != null) { pp.Source = attr.Value; attr = pathNode.Attributes["destination"]; if (attr != null) { pp.Destination = attr.Value; syncPathList.Add(pp); } } } } } if (param.Name == "ShowLog") { ShowLogWindow = bool.Parse(param.InnerText); } if (param.Name == "SaveLog") { SaveLog = bool.Parse(param.InnerText); } if (param.Name == "AppendLog") { AppendLog = bool.Parse(param.InnerText); } if (param.Name == "LogFile") { LogFile = param.InnerText; } if (param.Name == "ReadOnly") { RemoveReadOnlyFlag = bool.Parse(param.InnerText); } if (param.Name == "DirectoriesLikeFiles") { DirectoriesLikeFiles = bool.Parse(param.InnerText); } if (param.Name == "SubDirectories") { SubDirectories = bool.Parse(param.InnerText); } if (param.Name == "HiddenFiles") { ProcessHiddenFiles = bool.Parse(param.InnerText); } if (param.Name == "SystemFiles") { ProcessSystemFiles = bool.Parse(param.InnerText); } if (param.Name == "TerminateApp") { TerminateApp = bool.Parse(param.InnerText); } if (param.Name == "RunSilent") { RunSilent = bool.Parse(param.InnerText); } if (param.Name == "Extensions") { ExtensionList = param.InnerText; } if (param.Name == "ExcludedExtensions") { ExcludedExtensionList = param.InnerText; } if (param.Name == "SourceNewer") { SourceNewer = Int32.Parse(param.InnerText); } if (param.Name == "SourceMissing") { SourceMissing = Int32.Parse(param.InnerText); } if (param.Name == "DestNewer") { DestNewer = Int32.Parse(param.InnerText); } if (param.Name == "DestMissing") { DestMissing = Int32.Parse(param.InnerText); } if (param.Name == "BackupMode") { BackupMode = bool.Parse(param.InnerText); } if (param.Name == "Template") { Template = Int32.Parse(param.InnerText); } if (param.Name == "ShowOnlyDifferentFiles") { ShowOnlyDifferentFiles = bool.Parse(param.InnerText); } // read context menu entries if (param.Name == "ContextMenuEntries") { contextMenuRead = true; foreach (XmlNode pathNode in param.ChildNodes) { if (pathNode.Name == "ContextMenuEntry") { XmlAttribute attr = pathNode.Attributes["caption"]; if (attr != null) { string cme = attr.Value; attr = pathNode.Attributes["file"]; if (attr != null) { cme += "\t" + attr.Value; ContextMenu.Add(cme); if (pathNode.Attributes["DblClick"] != null) { ContextDblClickIdx = ContextMenu.Count - 1; } } } } } } } } } } } if (!contextMenuRead) { SetContextMenuDefaults(ContextMenu); } }
/// <summary> /// Save settings into the given file. /// </summary> /// <param name="fileName">file to save settings to</param> /// <param name="syncPathList">list with paths to synchronize</param> public void SaveJob(string fileName, SyncPathList syncPathList) { XmlAttribute attr; XmlElement root; XmlNode node; XmlDocument doc = new XmlDocument(); XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, "", ""); doc.AppendChild(xmlnode); root = doc.CreateElement("InZync"); // save paths to synchronize node = doc.CreateElement("SourcePaths"); foreach (PathPair pp in syncPathList) { XmlNode pathNode = doc.CreateElement("Path"); attr = doc.CreateAttribute("source"); attr.Value = pp.Source; pathNode.Attributes.Append(attr); attr = doc.CreateAttribute("destination"); attr.Value = pp.Destination; pathNode.Attributes.Append(attr); node.AppendChild(pathNode); } root.AppendChild(node); node = doc.CreateElement("ShowLog"); node.InnerText = ShowLogWindow.ToString(); root.AppendChild(node); node = doc.CreateElement("SaveLog"); node.InnerText = SaveLog.ToString(); root.AppendChild(node); node = doc.CreateElement("AppendLog"); node.InnerText = AppendLog.ToString(); root.AppendChild(node); node = doc.CreateElement("LogFile"); node.InnerText = LogFile; root.AppendChild(node); node = doc.CreateElement("ReadOnly"); node.InnerText = RemoveReadOnlyFlag.ToString(); root.AppendChild(node); node = doc.CreateElement("DirectoriesLikeFiles"); node.InnerText = DirectoriesLikeFiles.ToString(); root.AppendChild(node); node = doc.CreateElement("SubDirectories"); node.InnerText = SubDirectories.ToString(); root.AppendChild(node); node = doc.CreateElement("HiddenFiles"); node.InnerText = ProcessHiddenFiles.ToString(); root.AppendChild(node); node = doc.CreateElement("SystemFiles"); node.InnerText = ProcessSystemFiles.ToString(); root.AppendChild(node); node = doc.CreateElement("TerminateApp"); node.InnerText = TerminateApp.ToString(); root.AppendChild(node); node = doc.CreateElement("RunSilent"); node.InnerText = RunSilent.ToString(); root.AppendChild(node); node = doc.CreateElement("Extensions"); node.InnerText = ExtensionList; root.AppendChild(node); node = doc.CreateElement("ExcludedExtensions"); node.InnerText = ExcludedExtensionList; root.AppendChild(node); node = doc.CreateElement("SourceNewer"); node.InnerText = SourceNewer.ToString(); root.AppendChild(node); node = doc.CreateElement("SourceMissing"); node.InnerText = SourceMissing.ToString(); root.AppendChild(node); node = doc.CreateElement("DestNewer"); node.InnerText = DestNewer.ToString(); root.AppendChild(node); node = doc.CreateElement("DestMissing"); node.InnerText = DestMissing.ToString(); root.AppendChild(node); node = doc.CreateElement("BackupMode"); node.InnerText = BackupMode.ToString(); root.AppendChild(node); node = doc.CreateElement("Template"); node.InnerText = Template.ToString(); root.AppendChild(node); node = doc.CreateElement("ShowOnlyDifferentFiles"); node.InnerText = ShowOnlyDifferentFiles.ToString(); root.AppendChild(node); // save context menu entries node = doc.CreateElement("ContextMenuEntries"); for (int i = 0; i < ContextMenu.Count; i++) { string[] cme = ContextMenu[i].Split('\t'); XmlNode pathNode = doc.CreateElement("ContextMenuEntry"); attr = doc.CreateAttribute("caption"); attr.Value = cme[0]; pathNode.Attributes.Append(attr); attr = doc.CreateAttribute("file"); attr.Value = cme[1]; pathNode.Attributes.Append(attr); if (i == ContextDblClickIdx) { attr = doc.CreateAttribute("DblClick"); //attr.Value = cme[1]; pathNode.Attributes.Append(attr); } node.AppendChild(pathNode); } root.AppendChild(node); doc.AppendChild(root); doc.Save(fileName); }