private void InjectInXMLFile(string gamePath, GameDataCont gdC, string xmlPlatform, string platFormFolder) { //DataPlus defGame = gdC.Applications.FirstOrDefault(x => x.IsSelected); if (gdC.DefaultApp == null) { throw new Exception("No default game chosen"); } // Lecture du fichier TBGame ou EBGame string xmlGame = null; if (File.Exists(Path.Combine(gamePath, "TBGame.xml"))) { xmlGame = Path.Combine(gamePath, "TBGame.xml"); } else if (File.Exists(Path.Combine(gamePath, "EBGame.xml"))) { xmlGame = Path.Combine(gamePath, "EBGame.xml"); } else if (File.Exists(Path.Combine(gamePath, "NBGame.xml"))) { xmlGame = Path.Combine(gamePath, "NBGame.xml"); } // if (xmlGame == null) { throw new Exception("No XML file to inject"); } // Vérification pour voir si le jeu est présent using (XML_Games xmlSrc = new XML_Games(xmlGame)) using (XML_Games xmlPlat = new XML_Games(xmlPlatform)) { bool?remove = false; if (xmlPlat.Exists(GameTag.ID, gdC.DefaultApp.Id)) { remove = IHMStatic.AskDxMBox("Game is already present, remove it ? ", "Question", E_DxButtons.No | E_DxButtons.Yes, gdC.DefaultApp.Name); if (remove != true) { return; } // ----------------- On enlève si désiré xmlPlat.Remove_Game(gdC.DefaultApp.Id); xmlPlat.Remove_AddApps(gdC.DefaultApp.Id); xmlPlat.Remove_CustomF(gdC.DefaultApp.Id); xmlPlat.Remove_AlternateN(gdC.DefaultApp.Id); } // ----------------- Traitement du jeu. XElement xelGame = xmlSrc.GetGameNode(); // --- Modifications // Changement de la plateforme if (xelGame.Element(Tag.Platform) != null) { xelGame.Element(Tag.Platform).Value = gdC.Platform; } // App ModifElement(xelGame, Tag.AppPath, gdC.DefaultApp, true); // Manuel ModifElement(xelGame, GameTag.ManPath, gdC.DefaultManual, true); // Musique ModifElement(xelGame, GameTag.MusPath, gdC.DefaultMusic, false); // Video ModifElement(xelGame, GameTag.VidPath, gdC.DefaultVideo, false); // ThemeVideo ModifElement(xelGame, GameTag.ThVidPath, gdC.DefaultThemeVideo, false); // Changement du RootFolder if (xelGame.Element(GameTag.RootFolder) != null) { xelGame.Element(GameTag.RootFolder).Value = platFormFolder; } // --- Récupération des clones + modification var xelClones = xmlSrc.GetNodes(Tag.AddApp); foreach (XElement clone in xelClones) { var file = gdC.Applications.FirstOrDefault(x => x.Id == clone.Element(CloneTag.Id).Value); if (file != null) { ModifElement(clone, Tag.AppPath, file, true); } } xmlPlat.InjectGame(xelGame); xmlPlat.InjectAddApps(xelClones); // ----------------- Custom Fields if (Config.UseCustomFields) { var xelCFields = xmlSrc.GetNodes(Tag.CustField); xmlPlat.InjectCustomF(xelCFields); } // ----------------- Alternate names var xelANs = xmlSrc.GetNodes(Tag.AltName); xmlPlat.InjectAltName(xelANs); xmlPlat.Root.Save(xmlPlatform); } /* * elem.Value = DxPath.To_RelativeOrNull(Default.LastLBpath, defGame.DestPath); * } * * * // Modification du fichier xml pour l'injection */ void ModifElement <T>(in XElement xelObj, string tag, T elem, bool first) where T : IDataRep { var target = xelObj.Element(tag); var value = elem == null ? string.Empty : DxPath.To_Relative(Config.HLaunchBoxPath, elem.DestPath); // Pour lever le .\ value = value.StartsWith(@".\") ? value.Substring(2) : value; // Vérification if (target == null && first) { xelObj.AddFirst(new XElement(tag, value)); } else if (target == null && !first) { xelObj.Add(new XElement(tag, value)); } else { target.Value = value; } } }