void readPatchControl() { // Extract the control file FileInfo outFile = new FileInfo(Path.Combine(tempExtractPath, "PatchControl.xml")); FileStream streamOutFile = outFile.OpenWrite(); extractFile(GetEmbeddedFile("AvalonPatch", "EmbeddedPatches.PatchControl.xml"), streamOutFile); // Read the file string elementName = ""; reader = new XmlTextReader(Path.Combine(tempExtractPath, "PatchControl.xml")); reader.MoveToContent(); if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "patches")) { while (reader.Read()) { // Get the minium skin version required if (reader.NodeType == XmlNodeType.Element && reader.Name == "minskinversion") { reader.Read(); minSMPVersion = new Version(reader.Value); } if (reader.NodeType == XmlNodeType.Element && reader.Name == "patch") { patchFile thisPatch = new patchFile(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) elementName = reader.Name; else { if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue)) { switch (elementName) { case "name": thisPatch.patchFileName = reader.Value; break; case "action": thisPatch.patchAction = reader.Value; break; case "location": thisPatch.patchLocation = reader.Value; break; case "version": thisPatch.patchVersion = reader.Value; break; } } } if (reader.NodeType == XmlNodeType.EndElement) { if (reader.Name == "patch") { handlePatch(thisPatch.patchFileName, thisPatch); break; } } } } } reader.Close(); } }
void installZip(patchFile thePatch) { FastZip fz = new FastZip(); fz.ExtractZip(Path.Combine(tempExtractPath, thePatch.patchFileName), Path.Combine(tempExtractPath, Path.GetFileNameWithoutExtension(thePatch.patchFileName)), ""); checkAndCopy(Path.Combine(tempExtractPath, Path.GetFileNameWithoutExtension(thePatch.patchFileName))); }
void handlePatch(string patchName, patchFile pf) { FileInfo outFile = new FileInfo(Path.Combine(tempExtractPath, patchName)); FileStream streamOutFile = outFile.OpenWrite(); extractFile(GetEmbeddedFile("AvalonPatch", "EmbeddedPatches." + patchName), streamOutFile); // Now get the version and fill in the info fillInfo(patchName, pf); }
void installPatch(patchFile thePatch) { try { if (thePatch.patchAction.Contains("install")) { if (thePatch.patchLocation.ToLower().StartsWith("process") || thePatch.patchLocation.ToLower().StartsWith("windows")) { File.Copy(Path.Combine(tempExtractPath, thePatch.patchFileName), Path.Combine(thePatch.destinationPath, thePatch.patchFileName), true); } if (thePatch.patchLocation.ToLower().StartsWith("mediaportal")) { File.Copy(Path.Combine(tempExtractPath, thePatch.patchFileName), Path.Combine(thePatch.destinationPath, thePatch.patchFileName), true); } } } catch (UnauthorizedAccessException ex) { // catch access issues...maybe from UAC // really need to elevate string message = "User Account Control maybe preventing Avalon from updating the required file: "; string message2 = "Its recommended you address the issue and run the patch again."; DialogResult result = MessageBox.Show(string.Format("{0}{1}.\n\n{2}\n\n{3}", message, thePatch.patchFileName, ex.Message, message2), "AvalonPatch", MessageBoxButtons.OK, MessageBoxIcon.Error); // exit now, so we dont update version and prevent user from applying patch again Application.Exit(); } catch (Exception e) { // This is to catch the issue where we are running the patch from SMPMediaPortalRestart // and cannot then update SMPMediaPortalRestart. // Check it is SMPMediaPortalRestart we are trying to update, continue if we are // otherwise show the error and abort update process. if (!thePatch.patchFileName.ToLower().Contains("avalonmediaportalrestart")) { string message = "Exception due update while updating:"; string message2 = "Its recommended you address the issue and run the patch again."; DialogResult result = MessageBox.Show(string.Format("{0}{1}.\n\n{2}\n\n{3}", message, thePatch.patchFileName, e.Message, message2), "AvalonPatch", MessageBoxButtons.OK, MessageBoxIcon.Error); // exit now, so we dont update version and prevent user from applying patch again Application.Exit(); } } if (thePatch.patchAction.ToLower() == "unzip") { installZip(thePatch); } if (thePatch.patchAction.ToLower() == "run") { } }
void fillInfo(string fileName, patchFile pf) { if (pf.patchAction != "unzip") { pf.patchVersion = fileVersion(Path.Combine(tempExtractPath, fileName)); pf.patchSize = fileSize(Path.Combine(tempExtractPath, fileName)); } // if patch file is a plugin if (pf.patchLocation.ToLower().StartsWith("process") || pf.patchLocation.ToLower().StartsWith("windows")) { pf.destinationPath = Path.Combine(SkinInfo.mpPaths.pluginPath, pf.patchLocation); pf.installedVersion = fileVersion(Path.Combine(pf.destinationPath, fileName)); pf.installedSize = fileSize(Path.Combine(pf.destinationPath, fileName)); } if (pf.patchLocation.ToLower().StartsWith("mediaportal")) { pf.destinationPath = SkinInfo.mpPaths.sMPbaseDir; pf.installedVersion = fileVersion(Path.Combine(pf.destinationPath, fileName)); pf.installedSize = fileSize(Path.Combine(pf.destinationPath, fileName)); } if (pf.patchAction == "unzip") pf.installedVersion = skInfo.skinVersion.ToString(); if (pf.installedVersion == "0.0.0.0" && pf.patchAction != "mandatoryinstall") return; patchFiles.Add(pf); ListViewItem item = new ListViewItem(new[] { pf.patchFileName, pf.patchVersion, pf.installedVersion }); item.ImageIndex = 1; Version patchVersion = new Version(pf.patchVersion); Version installedVersion = new Version(pf.installedVersion); if (patchVersion.CompareTo(installedVersion) < 0) { item.ImageIndex = 0; } else if (patchVersion.CompareTo(installedVersion) == 0) { // check filesize...we cant do modified date as embedded resource // streams and writes a new file if (pf.patchSize.CompareTo(pf.installedSize) <= 0) item.ImageIndex = 0; else item.ImageIndex = 1; } else item.ImageIndex = 1; thePatches.Items.Add(item); }