/// <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); } }
public object Run(int timeSleep = 10) { try { /* * * log.AddCaller(this); * HeTrace.AddLogger("LaunchBox", log); */ //UpdateStatus += (x, y) => HeTrace.WriteLine(y, this); // Redirige les signaux //RedirectSignals(); // Récupération des infos de la plateforme UpdateStatus?.Invoke(this, "Get infos from platform"); /* * Normalement on peut virer * XML_Functions xf = new XML_Functions(); * xf.ReadFile(Common.PlatformsFile); * * Machine = xf.ScrapPlatform(PlatformName);*/ Machine = XML_Platforms.GetPlatformPaths(Common.PlatformsFile, PlatformName); if (Machine.PlatformFolders.Count < 1) { UpdateStatus?.Invoke(this, "Error: this machine has no path"); return(false); } // Backup datas MachineXMLFile = Path.Combine(PS.Default.LastLBpath, PS.Default.dPlatforms, $"{PlatformName}.xml"); BackupPlatformFile(MachineXMLFile); UpdateStatus?.Invoke(this, $"Backup of '{MachineXMLFile}'"); // Initialisation des dossiers cible // Memo solution la plus simple, fixant des limites et normalement évolutive string root = Path.GetDirectoryName(Path.GetDirectoryName(Machine.FolderPath)); TGamesP = Path.Combine(Machine.FolderPath); UpdateStatus?.Invoke(this, $"Target Game path: {TGamesP}"); TCheatsCodesP = Path.Combine(root, "Cheat Codes", PlatformName); UpdateStatus?.Invoke(this, $"Target Cheats path: {TCheatsCodesP}"); TImagesP = Path.GetDirectoryName(Machine.PlatformFolders.First((x) => x.MediaType.Contains("Box", StringComparison.OrdinalIgnoreCase)).FolderPath); UpdateStatus?.Invoke(this, $"Target Images path: {TImagesP}"); TManualsP = Machine.PlatformFolders.First((x) => x.MediaType == "Manual").FolderPath; UpdateStatus?.Invoke(this, $"Target Manuals path: {TManualsP}"); TMusicsP = Machine.PlatformFolders.First((x) => x.MediaType == "Music").FolderPath; UpdateStatus?.Invoke(this, $"Target Musics path: {TMusicsP}"); TVideosP = Machine.PlatformFolders.First((x) => x.MediaType == "Video").FolderPath; UpdateStatus?.Invoke(this, $"Target Videos path: {TVideosP}"); // int i = 0; //MaximumProgressT?.Invoke(this, Games.Count()); //MaximumProgress?.Invoke(this, 100); foreach (FileObj game in Games) { UpdateProgressT?.Invoke(this, i); UpdateStatus?.Invoke(this, $"Work on: {game.Nom}"); string gameName = Path.GetFileNameWithoutExtension(game.Nom); string tmpPath = Path.Combine(Config.WorkingFolder, Path.GetFileNameWithoutExtension(game.Nom)); // Décompresser if (Path.GetExtension(game.Path).Equals(".zip", StringComparison.OrdinalIgnoreCase)) { ZipDecompression.UnCompressArchive(game.Path, tmpPath, CancelToken); } if (CancelToken.IsCancellationRequested) { UpdateStatus?.Invoke(this, "Stopped by user"); return(false); } // todo 7zip // Chargement des données du jeu string xmlFile = Path.Combine(tmpPath, "EBGame.xml"); LBGame lbGame = XML_Games.Scrap_LBGame(xmlFile); List <AdditionalApplication> clones = XML_Games.ListAddApps(xmlFile); //05/04/2021 LBGame lbGame = XML_Games.Scrap_GameLB(Path.Combine(tmpPath, "EBGame.xml"), "LaunchBox_Backup", PS.Default.wCustomFields); UpdateStatus?.Invoke(this, $"Game info xml loaded: {lbGame.Title}"); // Modification des chemins dans le jeu Modify_Paths(lbGame, clones); // Modification de la platforme du jeu UpdateStatus?.Invoke(this, $"Altération of platform {lbGame.Platform} => {PlatformName}"); lbGame.Platform = PlatformName; // Copier Copy_LBManager(lbGame, tmpPath); /*// Platform modification * if (PS.Default.ChangePlatform) * XMLBackup.Change_Platform(Path.Combine(destPath, "EBGame.xml"), machine);*/ // Retrait du jeu si présence bool?replace = false; if (XML_Custom.TestPresence(MachineXMLFile, "Game", nameof(lbGame.Id).ToUpper(), lbGame.Id)) { replace = AskDxMBox("Game is Already present", "Question", E_DxButtons.Yes | E_DxButtons.No, lbGame.Title); } if (replace == true) { XML_Games.Remove_Game(lbGame.Id, MachineXMLFile); } // Injection XML_Games.InjectGame(lbGame, MachineXMLFile); XML_Games.InjectAddApps(clones, MachineXMLFile); if (PS.Default.wCustomFields) { //var r = XML_Games.ListCustomFields(xmlFile, "CustomField"); XML_Games.Trans_CustomF(xmlFile, MachineXMLFile); } UpdateStatus?.Invoke(this, $"Injection in xml Launchbox's files"); //XMLBackup.Copy_EBGame(gameName, Path.Combine(tmpPath, "EBGame.xml"), MachineXMLFile); // Effacer le dossier temporaire Delete(tmpPath); UpdateStatus?.Invoke(this, "Game Finished"); UpdateProgress?.Invoke(this, 100); i++; } UpdateStatus?.Invoke(this, "Task Finished"); HeTrace.RemoveLogger("LaunchBoxAdapt"); UpdateProgressT?.Invoke(this, 100); return(true); } catch (Exception exc) { HeTrace.WriteLine(exc.Message); return(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 object Run(int timeSleep = 10) { bool backupDone = false; /*// Tracing * MeSimpleLog log = new MeSimpleLog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Common.Logs, $"{DateTime.Now.ToFileTime()}.log")) * { * LogLevel = 1, * FuncPrefix = EPrefix.Horodating, * }; * log.AddCaller(this); * HeTrace.AddLogger("LaunchBox", log);*/ // UpdateStatus += (x, y) => HeTrace.WriteLine(y, this); // Redirige les signaux //RedirectSignals(); // int i = 0; foreach (FileObj game in Games) { UpdateProgressT?.Invoke(this, i); UpdateStatus?.Invoke(this, $"Work on: {game.Nom}"); string gameName = Path.GetFileNameWithoutExtension(game.Nom); string tmpPath = Path.Combine(Config.WorkingFolder, Path.GetFileNameWithoutExtension(game.Nom)); // Décompresser if (Path.GetExtension(game.Path).Equals(".zip", StringComparison.OrdinalIgnoreCase)) { ZipDecompression.UnCompressArchive(game.Path, tmpPath, CancelToken); } if (CancelToken.IsCancellationRequested) { UpdateStatus?.Invoke(this, "Stopped by user"); return(false); } // Chargement des données du jeu string xmlFile = Path.Combine(tmpPath, "EBGame.xml"); LBGame lbGame = XML_Games.Scrap_LBGame(xmlFile); List <AdditionalApplication> clones = XML_Games.ListAddApps(xmlFile); UpdateStatus?.Invoke(this, $"Game info xml loaded: {lbGame.Title}"); // Vérification de la présence du fichier xml de la plateforme string machineXMLFile = Path.Combine(PS.Default.LastLBpath, PS.Default.dPlatforms, $"{lbGame.Platform}.xml"); if (!File.Exists(machineXMLFile)) { UpdateStatus?.Invoke(this, $"Creation of xml file: '{machineXMLFile}'"); XML_Games.NewPlatform(machineXMLFile); } // Backup datas if (!backupDone) { BackupPlatformFile(machineXMLFile); UpdateStatus?.Invoke(this, $"Backup of '{machineXMLFile}'"); backupDone = true; } // Initialisation des dossiers TGamesP = Path.GetDirectoryName(lbGame.ApplicationPath); UpdateStatus?.Invoke(this, $"Target Game path: {TGamesP}"); /*TCheatsCodesP = Path.Combine(root, "Cheat Codes", lbGame.Platform); * UpdateStatus?.Invoke($"Target Cheats path: {TCheatsCodesP}"); * * TImagesP = Path.Combine(root, "Images", lbGame.Platform); * UpdateStatus?.Invoke($"Target Images path: {TImagesP}");*/ TManualsP = Path.GetDirectoryName(lbGame.ManualPath); UpdateStatus?.Invoke(this, $"Target Manuals path: {TManualsP}"); TMusicsP = Path.GetDirectoryName(lbGame.MusicPath); UpdateStatus?.Invoke(this, $"Target Musics path: {TMusicsP}"); TVideosP = Path.GetDirectoryName(lbGame.VideoPath); UpdateStatus?.Invoke(this, $"Target Videos path: {TVideosP}"); // Modification des chemins dans le jeu Modify_Paths(lbGame); // Copy des jeux Copy_Manager(lbGame, tmpPath); // Retrait du jeu si présence bool?replace = false; if (XML_Custom.TestPresence(machineXMLFile, "Game", nameof(lbGame.Id).ToUpper(), lbGame.Id)) { replace = AskDxMBox("Game is Already present", "Question", E_DxButtons.Yes | E_DxButtons.No, lbGame.Title); } if (replace == true) { XML_Games.Remove_Game(lbGame.Id, machineXMLFile); } // Injection XML_Games.InjectGame(lbGame, machineXMLFile); XML_Games.InjectAddApps(clones, machineXMLFile); if (PS.Default.wCustomFields) { //var r = XML_Games.ListCustomFields(xmlFile, "CustomField"); XML_Games.Trans_CustomF(xmlFile, machineXMLFile); } UpdateStatus?.Invoke(this, $"Injection in xml Launchbox's files"); //XMLBackup.Copy_EBGame(gameName, Path.Combine(tmpPath, "EBGame.xml"), MachineXMLFile); // Effacer le dossier temporaire Delete(tmpPath); //i++; UpdateProgress?.Invoke(this, 100); UpdateStatus?.Invoke(this, "Game Finished"); } UpdateStatus?.Invoke(this, "Task Finished"); HeTrace.RemoveLogger("LaunchBoxEB"); UpdateProgressT?.Invoke(this, 100); return(true); }