/// <summary> /// Compresses the specified type. /// </summary> /// <param name="fileInfo">The file information.</param> /// <param name="type">The type.</param> /// <param name="destinationPath">The destination path.</param> /// <param name="compressedFileInfo">The compressed file information.</param> /// <returns>True if successful</returns> public static bool Compress(this FileInfo fileInfo, CompressionType type, string destinationPath, out CompressedElement compressedFileInfo) { bool success; ICompression compression; switch (type) { case CompressionType.GZip: compression = new GZipCompression(); success = compression.CompressFolder(fileInfo.FullName, destinationPath, out compressedFileInfo); break; case CompressionType.ZipArchive: compression = new ZipArchiveCompression(); success = compression.CompressFolder(fileInfo.FullName, destinationPath, out compressedFileInfo); break; default: compression = new ZipCompression(); success = compression.CompressFolder(fileInfo.FullName, destinationPath, out compressedFileInfo); break; } return(success); }
/// <summary> /// Compresses the specified type. /// </summary> /// <param name="directory">The directory.</param> /// <param name="type">The type.</param> /// <param name="destinationPath">The destination path.</param> /// <param name="compressedFileInfo">The compressed file information.</param> /// <param name="name">The name.</param> /// <returns>True if succeeded</returns> public static bool Compress(this DirectoryInfo directory, CompressionType type, string destinationPath, out CompressedElement compressedFileInfo, string name = "") { bool success; ICompression compression; switch (type) { case CompressionType.GZip: compression = new GZipCompression(); success = compression.CompressFolder(directory.FullName, destinationPath, out compressedFileInfo); break; case CompressionType.ZipArchive: compression = new ZipArchiveCompression(); success = compression.CompressFolder(directory.FullName, destinationPath, out compressedFileInfo); break; default: compression = new ZipCompression(); success = compression.CompressFolder(directory.FullName, destinationPath, out compressedFileInfo); break; } return success; }
/* * * /// <summary> * /// Créer des dossiers à la verticale dans un répertoire, ajoute au dictionnaire * /// </summary> * /// <param name="basePath">Starting Directory</param> * /// <param name="folders"></param> * void CreateVFolders(Folder basePath, string tail) * { * string[] arrTail = tail.Split('\\'); * * string path = basePath.Path; // 22/10/2020 * foreach (string name in arrTail) * { * path = Path.Combine(path, name); * * HeTrace.WriteLine($"[CreateFolders] Creation of the folder: '{path}'"); * * // Creation * Directory.CreateDirectory(path); * } * * * }*/ #endregion tree #region Compression & Hash /// <summary> /// /// </summary> /// <param name="gamePath"></param> /// <param name="title">Tite du jeu</param> private void Compress_ZipMode(string gamePath) { var archiveLink = Path.Combine(_SystemPath, $"{Path.GetFileName(gamePath)}.zip"); 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; } } ZipCompression zippy = new ZipCompression(_SystemPath) { IsPaused = this.IsPaused, TokenSource = this.TokenSource, }; /* * zippy.UpdateProgressT += this.SetProgress; * zippy.UpdateStatus += this.SetStatus; * zippy.MaximumProgressT += this.SetMaximum;*/ zippy.UpdateStatus += (x, y) => HeTrace.WriteLine(y.Message); var res = PackMe_IHM.ZipCompressFolder(zippy, () => zippy.CompressFolder( gamePath, Path.GetFileName(gamePath), Config.ZipLvlCompression), "Compression Zip"); //ZipCompression.CompressFolder(gamePath, Path.Combine(_SystemPath, shGame.ExploitableFileName), PS.Default.c7zCompLvl); 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(zippy.ArchiveLink, () => MD5.Create()), "Calcul de somme"); HashCalc.Files.ClassicParser.Write(zippy.ArchiveLink, sum, HashType.md5, overwrite: true); } else { HeTrace.WriteLine($"[Run] MD5 disabled", this); } #endregion }