/// <summary> /// On récupère les informations principales, dont les chemins (EBGame, TBGame) /// </summary> /// <param name="gamePath"></param> /// <param name="file"></param> /// <returns></returns> /// <remarks> /// Si les chemins sont vides, on conserve quand même pas de tri /// </remarks> private GamePaths GetMainsInfo(string gamePath, string file) { string xmlFile = Path.Combine(gamePath, file); GamePaths gpX = null; using (XML_Games xelGames = new XML_Games(xmlFile)) { var xelG = xelGames.GetGameNode(); gpX = GamePaths.CreateBasic(xelG); gpX.Complete(xelGames.GetNodes(Tag.AddApp, Tag.GameId, gpX.Id)); // Essaie de récupération des paths foreach (var app in gpX.Applications) { app.CurrentPath = SimuRelativePath(gpX.Platform, app.CurrentPath); } // --- gpX.ManualPath = SimuRelativePath(gpX.Platform, gpX.ManualPath); gpX.MusicPath = SimuRelativePath(gpX.Platform, gpX.MusicPath); gpX.VideoPath = SimuRelativePath(gpX.Platform, gpX.VideoPath); gpX.ThemeVideoPath = SimuRelativePath(gpX.Platform, gpX.ThemeVideoPath); } return(gpX); }
/// <summary> /// Travaille sur le fichier de sortie pour injecter /// </summary> /// <param name="xmlPlateforme"></param> /// <param name="baseGame"></param> private void WorkOnGamesFile(string xmlPlateforme, XElement verbatimGame, string xmlSrcFile, BasicGame baseGame) { // Travail sur le fichier de plateforme using (XML_Games xGame = new XML_Games(xmlPlateforme)) { bool?replace = false; if (xGame.Exists("ID", baseGame.Id)) { replace = AskDxMBox("Game is Already present, replace it (or duplicate) ?", "Question", E_DxButtons.Yes | E_DxButtons.No, baseGame.Title); } if (replace == true) { UpdateStatus?.Invoke(this, $"Removing game: {baseGame.Title}"); xGame.RemoveByChild(Cst.Game, Cst.Id, baseGame.Id); UpdateStatus?.Invoke(this, $"Removing AdditionnalApps: {baseGame.Title}"); xGame.RemoveByChild(Cst.AddApp, Cst.GameId, baseGame.Id); UpdateStatus?.Invoke(this, $"Removing CustomFields: {baseGame.Title}"); xGame.RemoveByChild(Cst.CustField, Cst.GameId, baseGame.Id); UpdateStatus?.Invoke(this, $"Removing AlternateNames"); xGame.RemoveByChild(Cst.AltName, Cst.GameId, baseGame.Id); } // Injection UpdateStatus?.Invoke(this, $"Inject game"); xGame.InjectGame(verbatimGame); UpdateStatus?.Invoke(this, $"Inject additionnal applications"); xGame.InjectAddApps(XML_Games.GetNodes(xmlSrcFile, Cst.AddApp)); UpdateStatus?.Invoke(this, $"Inject custom fields"); xGame.InjectCustomF(XML_Games.GetNodes(xmlSrcFile, Cst.CustField)); /*XML_Games.InjectAddApps(clones, machineXMLFile); * if (PS.Default.wCustomFields) * { * //var r = XML_Games.ListCustomFields(xmlFile, "CustomField"); * XML_Games.Trans_CustomF(xmlFile, machineXMLFile); * }*/ //XML_Games.Remove_Game(lbGame.Id, machineXMLFile); } }
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; } } }