private void xMLToolStripMenuItem2_Click(object sender, EventArgs e) { if (MainPanel.DataTree.SelectedNode == null ||(!(MainPanel.DataTree.SelectedNode.Tag is WzDirectory) && !(MainPanel.DataTree.SelectedNode.Tag is WzFile) && !(MainPanel.DataTree.SelectedNode.Tag is IPropertyContainer))) return; WzFile wzFile = ((IWzObject)MainPanel.DataTree.SelectedNode.Tag).WzFileParent; if (!(wzFile is WzFile)) return; OpenFileDialog dialog = new OpenFileDialog() { Title = "Select the XML files", Filter = "eXtended Markup Language (*.xml)|*.xml", Multiselect = true }; if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; WzXmlDeserializer deserializer = new WzXmlDeserializer(true, WzTool.GetIvByMapleVersion(wzFile.MapleVersion)); yesToAll = false; noToAll = false; threadDone = false; runningThread = new Thread(new ParameterizedThreadStart(WzImporterThread)); runningThread.Start(new object[] { deserializer, dialog.FileNames, MainPanel.DataTree.SelectedNode, null }); new Thread(new ParameterizedThreadStart(ProgressBarThread)).Start(deserializer); }
protected void downloadLatestVersion() { //oldversion_newversion.txt string updateFile = verificationSignature.WzVersion.ToString() + "_" + latestWZVersion.ToString() + ".txt"; //Download and prepare the XML list for parsing. List<string> XMLsToUpdate = mergeFiles(); List<Tuple<string, string>> XMLListing = new List<Tuple<string, string>>(); WzXmlDeserializer xmlParser = new WzXmlDeserializer(true, new byte[] { 0, 0, 0, 0 }); List<string> wzFilesNeedingPatch = new List<string>(); updateLabel("(2/6) Receiving the update patch list."); //Removed the display here since it doesn't play well with merged files //splits the update log into <WzFile, WzNode> foreach (string XMLLine in XMLsToUpdate) { //Check for which files actually need patching first foreach (string wzName in wzFiles) { if (!wzFilesNeedingPatch.Contains(wzName) && XMLLine.Contains(wzName)) { wzFilesNeedingPatch.Add(wzName); } } string[] splitted = XMLLine.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (!XMLListing.Contains(new Tuple<string, string>(splitted[0], splitted[1]))) { XMLListing.Add(new Tuple<string, string>(splitted[0], splitted[1])); } } //open the WZ files for patching foreach (string wzName in wzFilesNeedingPatch) { WzFile tmp = new WzFile(wzName, WzMapleVersion.BMS); tmp.ParseWzFile(); allWzFiles.Add(tmp); } //Parse XML's and add the nodes to the WZ files. int counter = 0; foreach (WzFile wzFile in allWzFiles) //foreach (Tuple<string, string> XMLFile in XMLListing) { updateLabel("(3/6) Applying: " + wzFile.Name + " (Downloading and applying patch files)"); foreach (Tuple<string, string> XMLFile in XMLListing) //foreach (WzFile wzFile in allWzFiles) { if (wzFile.Name == XMLFile.Item1) { counter += 1; string xmlContent = ""; try { xmlContent = readEntireWebFile(updateServer + @"wz/" + XMLFile.Item1 + "/" + XMLFile.Item2); } catch (Exception) { //Throw "Unable to connect to the update server" if unable to read any file from update server. setStateWrapper(12); backgroundWorker.ReportProgress(100); } try { WzImage imageToAdd = (WzImage)xmlParser.ParseXML(xmlContent)[0]; AddWzImage(wzFile, XMLFile.Item2, imageToAdd); int percentage = (int)((double)counter * 100) / XMLListing.Count; backgroundWorker.ReportProgress(percentage); } catch (Exception e) { Console.WriteLine("Error on XML ("+ XMLFile.Item2 + ") " + e.ToString()); } } } WzPatcher.applyPatches(wzFile); } //Done patching, save in temporary dir if (Directory.Exists(temporaryDirectory)) { Directory.Delete(temporaryDirectory, true); Directory.CreateDirectory(temporaryDirectory); } else { Directory.CreateDirectory(temporaryDirectory); } updateLabel("(4/6) Adding custom content."); backgroundWorker.ReportProgress(0); WzFile CharacterWz = null; WzFile MapWz = null; WzFile UIWz = null; foreach (WzFile wzfile in allWzFiles) { if(wzfile.Name == "Character.wz") CharacterWz = wzfile; if(wzfile.Name == "Map.wz") MapWz = wzfile; if (wzfile.Name == "UI.wz") UIWz = wzfile; } if (!verificationSignature.UIAdded) { if (MapWz == null) { MapWz = new WzFile("Map.wz", WzMapleVersion.BMS); MapWz.ParseWzFile(); allWzFiles.Add(MapWz); } AddCustomImages(MapWz, backgroundWorker); verificationSignature.UIAdded = true; backgroundWorker.ReportProgress(75); } if (!verificationSignature.EssenceAdded) { if (UIWz == null) { UIWz = new WzFile("UI.wz", WzMapleVersion.BMS); UIWz.ParseWzFile(); allWzFiles.Add(UIWz); } AddCustomImages(UIWz, backgroundWorker); verificationSignature.EssenceAdded = true; backgroundWorker.ReportProgress(100); } backgroundWorker.ReportProgress(100); //Generate the new signature wzSignature newSignature = verificationSignature; newSignature.LauncherVersion = currentLauncherVersion; newSignature.WzVersion = (ushort)latestWZVersion; counter = 0; backgroundWorker.ReportProgress(0); foreach (WzFile wzFile in allWzFiles) { counter += 1; updateLabel("(5/6) Creating: " + wzFile.Name + " (Saving files to disk)"); wzFile.SaveToDisk(temporaryDirectory + wzFile.Name); wzFile.Dispose(); int percentage = (int)((double)counter * 100) / allWzFiles.Count; backgroundWorker.ReportProgress(percentage); } counter = 0; backgroundWorker.ReportProgress(0); //Done patching, copy the patched files over to the game installation. foreach (FileInfo wzFile in new DirectoryInfo(temporaryDirectory).GetFiles()) { counter += 1; updateLabel("(6/6) Finalizing: " + wzFile.Name + " (Replacing files with patched files)"); File.Delete(Directory.GetCurrentDirectory() + "\\" + wzFile.Name); File.Copy(wzFile.FullName, Directory.GetCurrentDirectory() + "\\" + wzFile.Name); int percentage = (int)((double)counter * 100) / (new DirectoryInfo(temporaryDirectory).GetFiles().Length); backgroundWorker.ReportProgress(percentage); } allWzFiles.Clear(); foreach (string wzName in wzFiles) { allWzFiles.Add(new WzFile(wzName, WzMapleVersion.BMS)); } //Sign each WZ file foreach (WzFile wzFile in allWzFiles) { try { string wzPath = wzFile.FilePath; BinaryReader wzReaderStream = new BinaryReader(new FileStream(wzPath, FileMode.Open)); bool needsNewSignature = wzSignature.isSignedWzFile(wzReaderStream); wzReaderStream.Close(); BinaryWriter wzWriterStream = new BinaryWriter(new FileStream(wzPath, FileMode.Open)); newSignature.writeSignature(wzWriterStream, !needsNewSignature); wzWriterStream.Flush(); wzWriterStream.Close(); } catch (Exception) { updateLabel("Please close any program using " + wzFiles[0] + "."); setStateWrapper(3); backgroundWorker.ReportProgress(100); //throw new Exception("Please close any program using " + wzFiles[0] + "."); } } Directory.Delete(temporaryDirectory, true); updateLabel("The patch is done."); backgroundWorker.ReportProgress(100); setStateWrapper(2); }