private void ManageDefaultFiles(LBGame lbGame, string gamePath, Folder tree) { GamePaths gp = (GamePaths)lbGame; gp.ApplicationPath = ManageRomPath(lbGame.ApplicationPath, tree.Children[Common.Games]); gp.ManualPath = ManageDefaultFile(lbGame.ManualPath, tree.Children[Common.Manuals], "Manual"); gp.MusicPath = ManageDefaultFile(lbGame.MusicPath, tree.Children[Common.Musics], "Music"); //gp.VideoPath = ManageDefaultFile(lbGame.VideoPath, tree.Children[Common.Videos]); //gp.ThemeVideoPath = ManageDefaultFile(lbGame.ThemeVideoPath, tree.Children[Common.]); gp.WriteToJson(Path.Combine(gamePath, "DPGame.json")); }
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); }
// --- /// <summary> /// Travail pour un jeu /// </summary> /// <param name="shGame"></param> public void PackMe(ShortGame shGame) { TempDecision = MemorizedDecision; // Verif if (shGame == null || string.IsNullOrEmpty(shGame.Id)) { HeTrace.WriteLine("Game property: null"); return; } // Dossiers string gamePath = Path.Combine(_SystemPath, $"{shGame.ExploitableFileName}"); // New Working Folder //Compress_ZipMode(gamePath, shGame.Title); // Compress_7ZipMode(gamePath, shGame.Title); // Contrôle de collisions pour les dossiers if (Directory.Exists(gamePath)) { HeTrace.WriteLine($"Directory Exists '{gamePath}'", this); // Demande à l'utilisateur si aucune précédente if (MemorizedDecision == E_Decision.None) { Application.Current.Dispatcher?.Invoke(() => TempDecision = MBDecision.ShowDial(null, gamePath, LanguageManager.Instance.Lang.Folder_Ex, E_DxConfB.Trash | E_DxConfB.OverWrite)); switch (TempDecision) { /* // Gestion des stops * case E_Decision.Stop: * HeTrace.WriteLine("Stopped by user", this); * HeTrace.RemoveLogger("game"); * return; * case E_Decision.StopAll: * HeTrace.WriteLine("Stopped by user", this); * HeTrace.RemoveLogger("game"); * throw new OperationCanceledException("Stopped by user"); */ case E_Decision.OverWriteAll: case E_Decision.TrashAll: MemorizedDecision = TempDecision; break; } switch (TempDecision) { case E_Decision.Trash: case E_Decision.TrashAll: HeTrace.WriteLine($"Trash existing folder: '{gamePath}'", this); OpFolders.Trash(@gamePath); break; } } } // --- On part du principe que tout peut être overwritté à partir de là. // Construction de la structure var tree = MakeStructure(gamePath); // --- #region Original Backup Game - Before all modifications if (Config.CreateTBGame) { XML_Games.TrueBackup(_XMLPlatformFile, shGame.Id, gamePath); } else { HeTrace.WriteLine("[Run] Original Backup Game disabled"); } #endregion #region Backup without paths XML_Games.NPBackup(_XMLPlatformFile, shGame.Id, gamePath); #endregion // Récupération du jeu LBGame lbGame = XML_Games.Scrap_LBGame <LBGame>(_XMLPlatformFile, "ID", shGame.Id); // Récupération des clones HeTrace.WriteLine("Alarms about not managed field are not important except if it's about a path containing datas"); HeTrace.WriteLine("EBGames and TBGames don't use a class they copy directly from xml to xml"); #region Creation of the Infos.xml (on ne récupère que ce que l'on veut) if (Config.CreateInfos) { // --- Get game from Launchbox (on a besoin que jusqu'au game info) XML_Custom.Make_InfoGame(gamePath, lbGame); } else { HeTrace.WriteLine("[Run] Make info disabled", this); } #endregion // --- Récupération des fichiers GameDataCont gdC = new GameDataCont(lbGame.Title, lbGame.Platform); GetFiles(lbGame, gdC); if (PackMe_IHM.LaunchBoxCore_Prev(gamePath, _ZePlatform, gdC) != true) { throw new Exception("Stopped by user"); } // --- Prepare files; PrepareList(gdC.Applications, tree, Config.KeepGameStruct, "Game"); PrepareList(gdC.CheatCodes, tree, Config.KeepCheatStruct, "CheatCode"); PrepareList(gdC.Manuals, tree, Config.KeepManualStruct, "Manual"); PrepareList(gdC.Musics, tree, Config.KeepMusicStruct, "Music"); PrepareList(gdC.Videos, tree, true, "Video"); PrepareImages(gdC.Images, tree.Children[Common.Images].Path); // --- Copie des fichiers CopyFiles(gdC, tree); // --- Récapitulatif permettant de rajouter ou lever des fichiers au pack if (PackMe_IHM.LaunchBoxCore_Recap(gamePath, _ZePlatform, gdC) != true) { throw new Exception("Stopped by user"); } // --- GamePaths --- GamePaths gpX = MakeGamePaths(lbGame, gdC, tree); #region Serialization / improved backup of Launchbox datas (with found medias missing) /* - En théorie on est toujours sur du relative path * - On a fait un assign sur les dossiers spécifiques * - On va récupérer la structure exacte sans aucune interprétation et modifier ce que l'on veut * - Les Paths */ if (Config.CreateEBGame) { Make_EnhanceBackup(gdC, lbGame, gamePath); } else { HeTrace.WriteLine($"[Run] Enhanced Backup Game disabled", this); } #endregion // --- Création d'un fichier conservant les fichiers par défaut définis par l'utilisateur en vue de réutilisation plus tard gpX.WriteToJson(Path.Combine(gamePath, "DPGame.json")); // --- On complète l'arborescence FoncSchem.MakeListFolder(tree.Children[Common.Manuals]); FoncSchem.MakeListFolder(tree.Children[Common.Images]); FoncSchem.MakeListFolder(tree.Children[Common.Musics]); FoncSchem.MakeListFolder(tree.Children[Common.Videos]); #region Save Struct if (Config.CreateTreeV) { FoncSchem.MakeStruct(tree, gamePath); } else { HeTrace.WriteLine($"[Run] Save Struct disabled", this); } #endregion #region 2020 choix du nom string name = PackMe_IHM.AskName(shGame.ExploitableFileName, _SystemPath); // Changement de nom du dossier <= Pour le moment ça ne fait que vérifier s'il peut écrire //si un dossier a le même nom ça ne pourra pas le renommer ushort i = 0; string destFolder = Path.Combine(_SystemPath, name); if (!gamePath.Equals(destFolder)) { while (i < 10) { try { Directory.Move(gamePath, destFolder); HeTrace.WriteLine("Folder successfully renamed"); // Attribution du résultat gamePath = destFolder; // Sortie break; } catch (IOException ioe) { HeTrace.WriteLine($"Try {i}: {ioe}"); Thread.Sleep(10); i++; } } } gamePath = destFolder; #endregion #region Compression // Zip if (Config.ZipCompression) { Compress_ZipMode(gamePath); } else { HeTrace.WriteLine($"[Run] Zip Compression disabled", this); } // 7zip if (Config.SevZipCompression) { Compress_7ZipMode(gamePath); } else { HeTrace.WriteLine($"[Run] 7Zip Compression disabled", this); } #endregion #region suppression du dossier de travail if (SafeBoxes.Dispatch_Mbox(this, "Would you want to ERASE the temp folder", "Erase", E_DxButtons.No | E_DxButtons.Yes, optMessage: shGame.ExploitableFileName) == true) { // Erase the temp folder try { Directory.SetCurrentDirectory(_WFolder); Directory.Delete(gamePath, true); HeTrace.WriteLine($"[Run] folder {gamePath} erased", this); } catch (Exception exc) { HeTrace.WriteLine($"[Run] Error when Erasing temp folder {gamePath}\n{exc.Message }", this); } } #endregion SetStatus(this, new StateArg($"Finished: {lbGame.Title}", CancelFlag)); }