protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pHootAuditorStruct, DoWorkEventArgs e) { HootAuditorStruct hootAuditorStruct = (HootAuditorStruct)pHootAuditorStruct; if (Path.GetExtension(pPath).ToUpper().Equals(FILE_EXTENSION_XML)) { TreeNode rootNode = new TreeNode(Path.GetFileNameWithoutExtension(pPath)); Dictionary <string, HootRomCheckStruct[]> archiveContents = new Dictionary <string, HootRomCheckStruct[]>(); try { gamelist hootGames = new gamelist(); XmlSerializer serializer = new XmlSerializer(typeof(gamelist)); using (FileStream xmlFs = File.OpenRead(pPath)) { using (XmlTextReader textReader = new XmlTextReader(xmlFs)) { hootGames = (gamelist)serializer.Deserialize(textReader); } } string gameArchiveFileName; TreeNode gameNode; TreeNode romNode; ArrayList archiveContentsStructs; string romNameUpperCase; string romTypeUpperCase; bool romFoundInDictionary; bool romFoundInArchives; HootRomCheckStruct newRom; foreach (game g in hootGames.Items) { gameArchiveFileName = g.romlist.archive + ".zip"; gameNode = new TreeNode(String.Format("{0} ({1})]", gameArchiveFileName, g.name)); if (archiveContents.ContainsKey(gameArchiveFileName)) { archiveContentsStructs = new ArrayList(archiveContents[gameArchiveFileName]); } else { archiveContentsStructs = new ArrayList(); } foreach (rom r in g.romlist.rom) { romNameUpperCase = r.Value.ToUpper(); romTypeUpperCase = r.type.ToUpper(); if (!romTypeUpperCase.Equals(ROM_TYPE_SHELL) && !romTypeUpperCase.Equals(ROM_TYPE_DEVICE) && !romTypeUpperCase.Equals(ROM_TYPE_BINARY) && !romTypeUpperCase.Equals(ROM_TYPE_CONIN)) { // Check if Rom is in Dictionary romFoundInDictionary = false; romFoundInArchives = false; foreach (HootRomCheckStruct h in archiveContentsStructs) { if (h.RomName.ToUpper().Equals(romNameUpperCase)) { romFoundInDictionary = true; romFoundInArchives = h.IsPresent; break; } } if (!romFoundInDictionary) { // Add Rom to Dictionary newRom = new HootRomCheckStruct(r.Value, false); archiveContentsStructs.Add(newRom); } } } // Scan for all roms archiveContents[gameArchiveFileName] = (HootRomCheckStruct[])archiveContentsStructs.ToArray(typeof(HootRomCheckStruct)); this.checkIfRomsArePresent(hootAuditorStruct.SetArchivePaths, ref archiveContents, gameArchiveFileName, hootAuditorStruct.IncludeSubDirectories); foreach (HootRomCheckStruct romCheckStruct in archiveContents[gameArchiveFileName]) { romNode = new TreeNode(romCheckStruct.RomName); gameNode.Nodes.Add(romNode); if (!romCheckStruct.IsPresent) { romNode.ForeColor = HOOT_MISSING_FILE_COLOR; gameNode.ForeColor = HOOT_MISSING_FILE_COLOR; rootNode.ForeColor = HOOT_MISSING_FILE_COLOR; } } rootNode.Nodes.Add(gameNode); } this.progressStruct.Clear(); this.progressStruct.FileName = pPath; this.progressStruct.NewNode = rootNode; ReportProgress(this.progress, this.progressStruct); } catch (Exception ex) { this.progressStruct.Clear(); this.progressStruct.ErrorMessage = String.Format("Error processing <{0}>. Error received: ", pPath) + ex.Message; ReportProgress(this.Progress, this.progressStruct); } } }
static void Main(string[] args) { gamelist hootGames; game[] vermouthGames; ArrayList vermouthGameList = new ArrayList(); option midioutMixOption; ArrayList optionsList; XmlSerializer serializer; string xmlSourceFolder = Path.GetFullPath(args[0]); // get files string[] xmlSourceFiles = Directory.GetFiles(xmlSourceFolder, "*.xml"); hootGames = new gamelist(); serializer = new XmlSerializer(typeof(gamelist)); midioutMixOption = new option(); midioutMixOption.name = "midiout_mix"; midioutMixOption.value = "0x80"; // loop over xml files foreach (string xmlSourceFile in xmlSourceFiles) { // get game list from file using (FileStream xmlFs = File.OpenRead(xmlSourceFile)) { using (XmlTextReader textReader = new XmlTextReader(xmlFs)) { hootGames = (gamelist)serializer.Deserialize(textReader); } } // loop over the games foreach (game g in hootGames.Items) { if (g.options != null && g.options.option != null) { optionsList = new ArrayList(g.options.option); // check for 'midiout' option; foreach (option o in optionsList) { // midiout_type: 4 (GS), 8 (GM) if (o.name.Equals("midiout_type") && (o.value.Equals("4") || o.value.Equals("8"))) { // convert to vermouth type o.value = "6"; // add midiout_mix optionsList.Add(midioutMixOption); // replace existing options g.options.option = (option[])optionsList.ToArray(typeof(option)); // update title g.name += " (Vermouth, Gravis Ultrasound simulation)"; // add to vermouth game list vermouthGameList.Add(g); break; } } } } } int x = 1; // write output file if (vermouthGameList.Count > 0) { vermouthGames = (game[])vermouthGameList.ToArray(typeof(game)); XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = System.Text.Encoding.UTF8; settings.Indent = true; settings.IndentChars = "\t"; settings.NewLineChars = Environment.NewLine; settings.ConformanceLevel = ConformanceLevel.Document; // Use to suppress namespace attributes XmlSerializerNamespaces namespaceSerializer = new XmlSerializerNamespaces(); namespaceSerializer.Add("", ""); string outputPath = Path.Combine(Path.GetDirectoryName((Application.ExecutablePath)), XML_OUTPUT_NAME); serializer = new XmlSerializer(vermouthGames.GetType()); using (XmlWriter xmlWriter = XmlTextWriter.Create(outputPath, settings)) { serializer.Serialize(xmlWriter, vermouthGames, namespaceSerializer); } } }