using System.Text; using System.Xml; using System.IO; namespace BetterPatchFileCreator.Code { public class PatchConfig { public long _v; public string Name { get; set; } public string Description { get; set; } public long Version { get { return _v; } set { _v = value; }} public string ClientPath { get; set; } public string XmlPath { get; set; } public string PatchFilePath { get; set; } public string DeployConfig { get; set; } public string GetBasePath() { string path = Path.Combine(DataProvider.BasePath, this.Name); return path; } public string GetXmlPath() { string path = Path.Combine(GetBasePath(), "xml"); return path; } public string GetDataPath() { string path = Path.Combine(GetBasePath(), "data"); return path; } public string GetXmlFilePath() { string path = Path.Combine(GetXmlPath(), GetXmlFileName()); return path; } public string GetDataFilePath() { string path = Path.Combine(GetDataPath(), GetDataFileName()); return path; } public string GetXmlFileName() { StringBuilder builder = GetFileNameBase(); builder.Append(".xml"); return builder.ToString(); } public string GetDataFileName() { StringBuilder builder = GetFileNameBase(); builder.Append(".spf"); return builder.ToString(); } private StringBuilder GetFileNameBase() { StringBuilder builder = new StringBuilder(); builder.Append(this.Name) .Append('-') .Append(this.Version); return builder; } public void ReadFromXmlNode(XmlNode node) { foreach (XmlAttribute xmlAttribute in node.Attributes) { ParseXmlAttribute(xmlAttribute); } } public XmlNode ToXmlNode(XmlDocument doc) { XmlNode node = doc.CreateNode(XmlNodeType.Element, "PatchConfig", ""); XmlAttribute tmp; tmp = doc.CreateAttribute("Name"); tmp.InnerText = this.Name; node.Attributes.Append(tmp); tmp = doc.CreateAttribute("Description"); tmp.InnerText = this.Description; node.Attributes.Append(tmp); tmp = doc.CreateAttribute("Version"); tmp.InnerText = this.Version.ToString(); node.Attributes.Append(tmp); tmp = doc.CreateAttribute("ClientPath"); tmp.InnerText = this.ClientPath; node.Attributes.Append(tmp); tmp = doc.CreateAttribute("XmlPath"); tmp.InnerText = this.XmlPath; node.Attributes.Append(tmp); tmp = doc.CreateAttribute("PatchFilePath"); tmp.InnerText = this.PatchFilePath; node.Attributes.Append(tmp); tmp = doc.CreateAttribute("DeployConfig"); tmp.InnerText = this.DeployConfig; node.Attributes.Append(tmp); return node; } private void ParseXmlAttribute(XmlAttribute attr) { switch (attr.Name) { case "Name": this.Name = attr.InnerText; break; case "Description": this.Description = attr.InnerText; break; case "Version": this.Version = long.Parse(attr.InnerText); break; case "ClientPath": this.ClientPath = attr.InnerText; break; case "XmlPath": this.XmlPath = attr.InnerText; break; case "PatchFilePath": this.PatchFilePath = attr.InnerText; break; case "DeployConfig": this.DeployConfig = attr.InnerText; break; default: break; } } } }