// --- private void CopyFiles(GameDataCont gdC, Folder tree) { HashCopy objCopy = new HashCopy(); objCopy.AskToUser += PackMe_IHM.Ask4_FileConflict2; HeTrace.WriteLine("[CopyFiles] All files except images"); // Fusion des fichiers sauf les images List <DataTrans> Fichiers = new List <DataTrans>(); Fichiers.AddRange(gdC.Applications); Fichiers.AddRange(gdC.CheatCodes); Fichiers.AddRange(gdC.Manuals); Fichiers.AddRange(gdC.Musics); Fichiers.AddRange(gdC.Videos); PackMe_IHM.DoubleProgress(objCopy, "Copy", (test) => test = objCopy.CopySevNVerif(Fichiers), (test) => test = objCopy.CopySevNVerif(gdC.Images)); //copyObj.CopySNVerif(Fichiers); }
internal void SimpleCopyManager(string fileSrc, ref E_Decision previousDec, string destFile) { if (CancelToken.IsCancellationRequested) { throw new OperationCanceledException("Operation stopped"); } if (!destFile.Contains(_WFolder)) { throw new Exception($"[CreateFolders] Erreur la chaine '{destFile}' ne contient pas '{_WFolder}'"); } // Création des dossiers string destFolder = Path.GetDirectoryName(destFile); if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } //string destFile = Path.Combine(destFolder, Path.GetFileName(fileSrc)); E_Decision?conflictDec = previousDec; bool overwrite = false; if (File.Exists(destFile)) { HeTrace.Write($"[CopyHandler] Destination file exists... ", this); if (conflictDec == E_Decision.None) { conflictDec = PackMe_IHM.Ask4_FileConflict(fileSrc, destFile, E_DxConfB.OverWrite | E_DxConfB.Pass | E_DxConfB.Trash); // Mémorisation pour les futurs conflits switch (conflictDec) { case E_Decision.PassAll: case E_Decision.OverWriteAll: case E_Decision.TrashAll: previousDec = conflictDec == null ? E_Decision.None : (E_Decision)conflictDec; break; } } HeTrace.EndLine(conflictDec.ToString(), this); switch (conflictDec) { case E_Decision.Pass: case E_Decision.PassAll: SetStatus(this, new StateArg($"Pass: {fileSrc}", CancelFlag)); return; case E_Decision.OverWrite: case E_Decision.OverWriteAll: SetStatus(this, new StateArg($"OverWrite: {destFile}", CancelFlag)); overwrite = true; break; case E_Decision.Trash: case E_Decision.TrashAll: SetStatus(this, new StateArg($"Trash: {destFile}", CancelFlag)); OpDFiles.Trash(destFile); break; } } // --- Copie SetStatus(this, new StateArg($"Copy {fileSrc}", CancelFlag)); SetProgress(this, new ProgressArg(0, 1, CancelFlag)); FilesFunc.Copy(fileSrc, destFile, overwrite); SetProgress(this, new ProgressArg(1, 1, CancelFlag)); // --- Vérification des sommes this.SetStatus(this, new StateArg($"Copy verification", CancelFlag)); //this.SetMaximum(this, 100); //bool? res = _ObjectFiles.VerifByHash_Sync(fileSrc, destFile, () => MD5.Create()); //var res = _ObjectFiles.DeepVerif(fileSrc, destFile, () => MD5.Create()); this.SetStatus(this, new StateArg($"Check verif: {res}", CancelFlag)); //this.UpdateProgress?.Invoke(100); }
/// <summary> /// /// </summary> /// <param name="gamePath"></param> /// <param name="title">Titre du jeu</param> private void Compress_7ZipMode(string gamePath) { var archiveLink = Path.Combine(_SystemPath, $"{Path.GetFileName(gamePath)}.7z"); if (File.Exists(archiveLink)) { var Length = DxLocalTransf.Tools.FileSizeFormatter.Convert(new FileInfo(archiveLink).Length); var resConflict = SafeBoxes.Ask4_DestConflict ( LanguageManager.Instance.Lang.File_Ex, archiveLink, Length, E_DxConfB.OverWrite | E_DxConfB.Trash ); switch (resConflict) { case E_Decision.OverWriteAll: case E_Decision.OverWrite: File.Delete(archiveLink); break; case E_Decision.Trash: case E_Decision.TrashAll: OpDFiles.Trash(archiveLink); break; } } SevenZipCompression sevZippy = new SevenZipCompression(_SystemPath) { IsPaused = this.IsPaused, TokenSource = this.TokenSource }; sevZippy.UpdateStatus += (x, y) => HeTrace.WriteLine(y.Message); var res = (bool?)PackMe_IHM.ZipCompressFolder(sevZippy, () => sevZippy.CompressFolder( gamePath, Path.GetFileName(gamePath), Config.SevZipLvlCompression), "Compression 7z"); if (res != true) { return; } #region Création du fichier MD5 if (Config.CreateMD5) { Gen_PlusCalculator calculator = Gen_PlusCalculator.Create(CancelToken); string sum = string.Empty; PackMe_IHM.LaunchOpProgress(calculator, () => sum = calculator.Calcul(sevZippy.ArchiveLink, () => MD5.Create()), "Calcul de somme"); HashCalc.Files.ClassicParser.Write(sevZippy.ArchiveLink, sum, HashType.md5, overwrite: true); } else { HeTrace.WriteLine($"[Run] MD5 disabled", this); } #endregion }
// --- /// <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)); }