public void ApplyPatch(Patch patch) { lock (fileSystemSync) { if (Version != patch.FromVersion) { throw new ArgumentException(string.Format("Cannot upgrade from version '{0}' using patch for version '{1}'", Version, patch.FromVersion)); } IsModified = true; foreach (var instruction in patch.Instructions) { instruction.Apply(patch.PatchDataRoot, ApplicationRoot); } WriteVersion(patch.ToVersion); Version = patch.ToVersion; } }
private static Patch InitializeFrom(string patchDataRoot) { var config = new XmlDocument(); config.Load(Path.Combine(patchDataRoot, "nocap.xml")); var patch = new Patch(patchDataRoot); ParsePatchConfig(patch, config); return patch; }
private static void ParsePatchConfig(Patch patch, XmlDocument config) { var configRoot = config.DocumentElement; patch.Instructions = new ReadOnlyCollection<IPatchInstruction>( configRoot.SelectNodes("Instructions/*").OfType<XmlElement>().Select(ParseInstruction).ToArray() ); patch.FromVersion = configRoot.SelectSingleNode("From").InnerText; patch.ToVersion = configRoot.SelectSingleNode("To").InnerText; }