private void CopyImages(List <DataRepExt> images, string destLocation) { E_Decision resMem = E_Decision.None; string tail, futurLink; foreach (DataRepExt pkFile in images) { tail = string.Empty; // On récupère la tail PlatformFolder folder = _ZePlatform.PlatformFolders.First( (x) => x.MediaType.Equals(pkFile.Categorie, StringComparison.OrdinalIgnoreCase)); if (folder != null && pkFile.ALinkToThePath.Contains(folder.FolderPath)) { tail = pkFile.ALinkToThePath.Replace(folder.FolderPath, string.Empty).TrimStart('\\'); futurLink = Path.Combine(destLocation, pkFile.Categorie, tail); } else { futurLink = Path.Combine(destLocation, Path.GetFileName(pkFile.ALinkToThePath)); } SimpleCopyManager(pkFile.ALinkToThePath, ref resMem, futurLink); // Dossier de destination //25/03/2021string destFolder = Path.Combine(_Tree.Children[nameof(SubFolder.Images)].Path, tail1); //string destFolder = Path.Combine(imgsFolder, tail1); //SimpleCopyManager(pkFile.LinkToThePath, destFolder, ref resMem); } }
private void PrepareImages(List <DataRepImg> images, string destLocation) { E_Decision resMem = E_Decision.None; string tail; foreach (DataRepImg pkFile in images) { tail = string.Empty; // On récupère la tail PlatformFolder pFolder = _ZePlatform.PlatformFolders.First( (x) => x.MediaType.Equals(pkFile.Categorie, StringComparison.OrdinalIgnoreCase)); string toReplace = Path.GetFullPath(pFolder.FolderPath, Common.Config.HLaunchBoxPath); if (toReplace != null && pkFile.CurrentPath.Contains(toReplace)) { tail = pkFile.CurrentPath.Replace(toReplace, string.Empty).TrimStart('\\'); pkFile.DestPath = Path.Combine(destLocation, pkFile.Categorie, tail); } else { pkFile.DestPath = Path.Combine(destLocation, Path.GetFileName(pkFile.CurrentPath)); } } }
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> /// Copie les images / Copy the images /// </summary> /// <remarks>To Add Mask see 'Where'</remarks> private void CopyImages(LBGame lbGame, string imgsFolder) { if (!imgsFolder.Contains(_WFolder)) { throw new Exception($"[CreateFolders] Erreur la chaine '{imgsFolder}' ne contient pas '{_WFolder}'"); } //ITrace.WriteLine(prefix: false); Queue <PackFile> lPackFile = new Queue <PackFile>(); // Get All images (To Add mask see at Where) Console.WriteLine($"[CopyImages] Search all images for '{lbGame.Title}'"); foreach (PlatformFolder plfmFolder in _ZePlatform.PlatformFolders) { //filtre sur tout ce qui n'est pas image switch (plfmFolder.MediaType) { case "Manual": case "Music": case "Theme Video": case "Video": continue; } // 2020 - on modify pour certains titres, la recherche string toSearch = lbGame.Title.Replace(':', '_').Replace('\'', '_').Replace("__", "_"); // Liste du contenu des dossiers foreach (var fichier in Directory.EnumerateFiles(plfmFolder.FolderPath, "*.*", SearchOption.AllDirectories)) { string fileName = Path.GetFileName(fichier); if ( !fileName.StartsWith($"{toSearch}-") && !fileName.StartsWith($"{ lbGame.Title}.{ lbGame.Id}-")) { continue; } HeTrace.WriteLine($"\t\t[CopyImages] Found '{fichier}' in '{plfmFolder.FolderPath}'"); PackFile tmp = new PackFile(plfmFolder.MediaType, fichier); lPackFile.Enqueue(tmp); } } // ITrace.WriteLine(prefix: false); E_Decision resMem = E_Decision.None; while (lPackFile.Count != 0) { var pkFile = lPackFile.Dequeue(); // On récupère la tail int pos = pkFile.LinkToThePath.IndexOf(pkFile.Categorie); string tail1 = Path.GetDirectoryName(pkFile.LinkToThePath).Substring(pos); // Dossier de destination //25/03/2021string destFolder = Path.Combine(_Tree.Children[nameof(SubFolder.Images)].Path, tail1); string destFolder = Path.Combine(imgsFolder, tail1); SimpleCopyManager(pkFile.LinkToThePath, destFolder, ref resMem); } }
// --- /// <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)); }