public static void InjectPlatform() { HeTrace.WriteLine("Platform injection..."); string backupFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Common.BackUp); string platformsFile = Path.Combine(Config.HLaunchBoxPath, Config.PlatformsFile); string newPFile = IHMStatic.GetAFile(Config.LastTargetPath, LanguageManager.Instance.Lang.S_XmlPlatform, "xml"); if (string.IsNullOrEmpty(newPFile)) { HeTrace.WriteLine("Platform file is null !"); return; } HeTrace.WriteLine($"Platform selected is '{newPFile}'"); using (XML_Platforms srcPlatform = new XML_Platforms(newPFile)) using (XML_Platforms lbPlatformes = new XML_Platforms(platformsFile)) { string machineName = srcPlatform.Root.Element(Tag.Platform).Element(Tag.Name)?.Value; var samePlats = from platform in lbPlatformes.Root.Elements(Tag.Platform) where ((string)platform.Element(Tag.Name).Value).Equals(machineName, StringComparison.OrdinalIgnoreCase) select platform; bool?write = true; // On demande pour REMPLACER la machine si elle existe déjà if (samePlats.Count() > 0) { write &= IHMStatic.AskDxMBox( "Platform is Already present, replace it ?", "Question", E_DxButtons.Yes | E_DxButtons.No, machineName); } if (write == false) { return; } // Backup du fichier de la plateforme; Tool.BackupFile(platformsFile, backupFolder); // On efface si nécessaire. lbPlatformes.RemoveElemByChild(Tag.Platform, Tag.Name, machineName); lbPlatformes.RemoveElemByChild(Tag.PlatformFolder, Tag.Platform, machineName); lbPlatformes.Save(platformsFile); // Injection de la plateforme lbPlatformes.InjectPlatform(srcPlatform.Root.Element(Tag.Platform)); // Injection des dossiers lbPlatformes.InjectPlatFolders(srcPlatform.Root.Elements(Tag.PlatformFolder)); // Sauvegarde lbPlatformes.Save(platformsFile); } HeTrace.WriteLine("Platform injection, done"); }
internal bool MakeDPG(string gamePath, ArchiveMode mode, string archiveLink) { GamePaths gpX = null; // Lecture des fichiers if (File.Exists(Path.Combine(gamePath, "DPGame.json"))) { HeTrace.WriteLine("DPG Found"); gpX = GamePaths.ReadFromJson(Path.Combine(gamePath, "DPGame.json")); } else if (File.Exists(Path.Combine(gamePath, "EBGame.xml"))) { HeTrace.WriteLine("DPG Missing, work with EBGame"); gpX = GetMainsInfo(gamePath, "EBGame.xml"); } else if (File.Exists(Path.Combine(gamePath, "TBGame.xml"))) { HeTrace.WriteLine("DPG Missing, work with TBGame"); gpX = GetMainsInfo(gamePath, "TBGame.xml"); } else if (File.Exists(Path.Combine(gamePath, "NBGame.xml"))) { HeTrace.WriteLine("DPG Missing, work with NBGame"); gpX = GetMainsInfo(gamePath, "NBGame.xml"); } if (gpX == null) { throw new Exception("Impossible to continue, no data file available"); } GameDataCont gpC = (GameDataCont)gpX; GameDataCompletion(gpC, mode, archiveLink); if (gpC.Applications.Count <= 0) { throw new Exception("No game to inject"); } // Affichage IHMStatic.ShowDPG(gpC, gpX, gamePath); // Sauvegarde gpX.WriteToJson(Path.Combine(gamePath, "DPGame.json")); HeTrace.WriteLine("DPG Done"); return(true); }
// --- public bool CheckIfInjectionNeeded(string machineName) { // --- Lecture du fichier source string platformsFile = Path.Combine(Config.HLaunchBoxPath, Config.PlatformsFile); bool?write = true; bool?resPres = XML_Custom.TestPresence(platformsFile, Tag.Platform, Tag.Name, machineName); // On demande pour REMPLACER la machine si elle existe déjà if (resPres == true) { write = IHMStatic.AskDxMBox( "Platform is Already present, replace it ?", "Question", E_DxButtons.Yes | E_DxButtons.No, machineName); } return(write ?? false); }
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; } } }
public GameDataCont InjectGame(string gamePath) { HeTrace.WriteLine("Dpg Step"); string dpgFile = Path.Combine(gamePath, "DPGame.json"); // Check if DPG file exists if (!File.Exists(dpgFile)) { DPGMakerCore dpgMaker = new DPGMakerCore(); dpgMaker.MakeDPG_Folder(gamePath); } GamePaths gpX = GamePaths.ReadFromJson(dpgFile); HeTrace.WriteLine($"Platform Step for '{gpX.Platform}'"); string platformsFile = Path.Combine(Config.HLaunchBoxPath, Config.PlatformsFile); bool CheckIfInjectionNeeded = !XML_Custom.TestPresence(platformsFile, Tag.Platform, Tag.Name, gpX.Platform); if (CheckIfInjectionNeeded) { HeTrace.WriteLine($"Backup of platforms file"); // Backup du fichier de la plateforme; BackupFile(platformsFile, _BackupFolder); string newPFile = IHMStatic.GetAFile(Config.LastTargetPath, $"Platform '{gpX.Platform}' doesn't exist. Select the xml file to inject for this platform", "xml"); if (string.IsNullOrEmpty(newPFile)) { throw new Exception("File for injection is not filled"); } // Vérification que c'est la bonne plateforme if (!XML_Custom.TestPresence(newPFile, Tag.Platform, Tag.Name, gpX.Platform)) { throw new Exception("File doesn't contain the good platform"); } HeTrace.WriteLine($"Injecting {gpX.Platform} in platforms file for {gpX.Platform}"); InjectPlatform(gpX.Platform, newPFile); } ContPlatFolders zePlatform = XML_Platforms.GetPlatformPaths(platformsFile, gpX.Platform); HeTrace.WriteLine("Preparing files"); // Préparation des fichiers GameDataCont gdC = PrepareGDC(gamePath, gpX); // Manipulation des fichiers AssignTargets(gdC, gamePath, zePlatform); // --- Lecture de la plateforme string machineXMLFile = Path.Combine(Config.HLaunchBoxPath, Config.PlatformsFolder, $"{gpX.Platform}.xml"); if (!File.Exists(machineXMLFile)) { XML_Games.NewPlatform(machineXMLFile); } // Backup platform file BackupFile(machineXMLFile, _BackupFolder); HeTrace.WriteLine($"Backup of '{machineXMLFile}'"); InjectInXMLFile(gamePath, gdC, machineXMLFile, zePlatform.FolderPath); HeTrace.WriteLine($"Game injected: {gdC.Title}"); return(gdC); }