// --- /// <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)); }