From 02e50a3c535800e0b63ec70628aa255d78377beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Sexenian?= <99925035+tomas-sexenian@users.noreply.github.com> Date: Thu, 7 Nov 2024 11:57:25 +0900 Subject: [PATCH] Rework --- dotnet/DotNetStandardClasses.sln | 22 +- dotnet/GxCompress/Compression.cs | 87 --- dotnet/GxCompress/GXCompressor.cs | 566 ------------------ dotnet/GxCompress/IGXCompressor.cs | 14 - .../dotnetcore/GxCompress/GxCompress.csproj | 31 + .../dotnetframework/GxCompress/Compression.cs | 41 ++ .../GxCompress/GXCompressor.cs | 523 ++++++++++++++++ .../GxCompress/GxCompress.csproj | 9 +- .../GxCompress/IGXCompressor.cs | 13 + .../DotNetCoreUnitTest/CompressionTests.cs | 76 +-- 10 files changed, 629 insertions(+), 753 deletions(-) delete mode 100644 dotnet/GxCompress/Compression.cs delete mode 100644 dotnet/GxCompress/GXCompressor.cs delete mode 100644 dotnet/GxCompress/IGXCompressor.cs create mode 100644 dotnet/src/dotnetcore/GxCompress/GxCompress.csproj create mode 100644 dotnet/src/dotnetframework/GxCompress/Compression.cs create mode 100644 dotnet/src/dotnetframework/GxCompress/GXCompressor.cs rename dotnet/{ => src/dotnetframework}/GxCompress/GxCompress.csproj (71%) create mode 100644 dotnet/src/dotnetframework/GxCompress/IGXCompressor.cs diff --git a/dotnet/DotNetStandardClasses.sln b/dotnet/DotNetStandardClasses.sln index 978ba522c..0d80dbea3 100644 --- a/dotnet/DotNetStandardClasses.sln +++ b/dotnet/DotNetStandardClasses.sln @@ -263,7 +263,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LogTest", "test\benchmarks\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AccessTokenController_Test", "test\NativeAccessControllerTest\AccessTokenController_Test.csproj", "{A5589382-DB6F-4450-AE2B-6C6AA1643EF1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GxCompress", "GxCompress\GxCompress.csproj", "{02C726EC-5923-4852-999D-AF9406A1ACBB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GxCompress", "src\dotnetframework\GxCompress\GxCompress.csproj", "{CF7E0F66-1B8F-4A08-81C5-B87E70EAB53D}" + ProjectSection(ProjectDependencies) = postProject + {52ADD4DB-FBFE-4686-9E5F-830CDF859830} = {52ADD4DB-FBFE-4686-9E5F-830CDF859830} + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GxCompress", "src\dotnetcore\GxCompress\GxCompress.csproj", "{AADC2CE2-606B-4CC0-81E6-3E3CCC4F1BDA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -643,10 +648,14 @@ Global {A5589382-DB6F-4450-AE2B-6C6AA1643EF1}.Debug|Any CPU.Build.0 = Debug|Any CPU {A5589382-DB6F-4450-AE2B-6C6AA1643EF1}.Release|Any CPU.ActiveCfg = Release|Any CPU {A5589382-DB6F-4450-AE2B-6C6AA1643EF1}.Release|Any CPU.Build.0 = Release|Any CPU - {02C726EC-5923-4852-999D-AF9406A1ACBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {02C726EC-5923-4852-999D-AF9406A1ACBB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {02C726EC-5923-4852-999D-AF9406A1ACBB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {02C726EC-5923-4852-999D-AF9406A1ACBB}.Release|Any CPU.Build.0 = Release|Any CPU + {CF7E0F66-1B8F-4A08-81C5-B87E70EAB53D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF7E0F66-1B8F-4A08-81C5-B87E70EAB53D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF7E0F66-1B8F-4A08-81C5-B87E70EAB53D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF7E0F66-1B8F-4A08-81C5-B87E70EAB53D}.Release|Any CPU.Build.0 = Release|Any CPU + {AADC2CE2-606B-4CC0-81E6-3E3CCC4F1BDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AADC2CE2-606B-4CC0-81E6-3E3CCC4F1BDA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AADC2CE2-606B-4CC0-81E6-3E3CCC4F1BDA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AADC2CE2-606B-4CC0-81E6-3E3CCC4F1BDA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -773,7 +782,8 @@ Global {46DAAFD1-FAF5-4904-8EC5-406BE04E5538} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC} {A1DBDCE0-4F09-445F-A202-9B260CDD46CF} = {46DAAFD1-FAF5-4904-8EC5-406BE04E5538} {A5589382-DB6F-4450-AE2B-6C6AA1643EF1} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC} - {02C726EC-5923-4852-999D-AF9406A1ACBB} = {2261B65E-3757-4E5B-9DCD-EAE8D1E236A3} + {CF7E0F66-1B8F-4A08-81C5-B87E70EAB53D} = {F900A4AD-7249-41B4-B918-CB9E8C73747C} + {AADC2CE2-606B-4CC0-81E6-3E3CCC4F1BDA} = {2261B65E-3757-4E5B-9DCD-EAE8D1E236A3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C} diff --git a/dotnet/GxCompress/Compression.cs b/dotnet/GxCompress/Compression.cs deleted file mode 100644 index 5c46acdb4..000000000 --- a/dotnet/GxCompress/Compression.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using GeneXus; -using GeneXus.Utils; - -namespace Genexus.Compression -{ - public class Compression - { - static readonly IGXLogger log = GXLoggerFactory.GetLogger(typeof(Compression).FullName); - - private string path; - private string format; - private GXBaseCollection messages; - private List filesToCompress; - - public Compression() - { - filesToCompress = new List(); - } - - public Compression(string path, string format, ref GXBaseCollection messages) - { - this.path = path; - this.format = format; - this.messages = messages; - filesToCompress = new List(); - } - - public void SetPath(string path) - { - this.path = path; - } - - public void SetFormat(string format) - { - this.format = format; - } - - public void AddFile(string filePath) - { - FileInfo file = new FileInfo(filePath); - if (file.Exists) - { - filesToCompress.Add(file); - } - else - { - GXLogging.Error(log, $"File does not exist: {0}", file.FullName); - } - } - - public void AddFolder(string folderPath) - { - try - { - var files = Directory.EnumerateFiles(folderPath, "*", SearchOption.AllDirectories); - foreach (string file in files) - { - AddFile(Path.GetFullPath(file)); - } - } - catch (Exception e) - { - GXLogging.Error(log, $"Failed to add foler", e); - } - } - - public bool Save() - { - List paths = new List(); - foreach (FileInfo file in filesToCompress) - { - paths.Add(file.FullName); - } - return GXCompressor.CompressFiles(paths, path, format, ref this.messages); - } - - public void Clear() - { - this.path = string.Empty; - this.format = string.Empty; - filesToCompress = new List(); - } - } -} diff --git a/dotnet/GxCompress/GXCompressor.cs b/dotnet/GxCompress/GXCompressor.cs deleted file mode 100644 index d2711147f..000000000 --- a/dotnet/GxCompress/GXCompressor.cs +++ /dev/null @@ -1,566 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.IO.Compression; -using System.Security; -using GeneXus; -using GeneXus.Utils; -using ICSharpCode.SharpZipLib.Tar; -using SharpCompress.Archives; -using SharpCompress.Archives.Rar; -using SharpCompress.Archives.SevenZip; -using SharpCompress.Common; - -namespace Genexus.Compression -{ - public enum CompressionFormat - { - GZIP, - TAR, - ZIP, - JAR - } - - public class GXCompressor : IGXCompressor - { - static readonly IGXLogger log = GXLoggerFactory.GetLogger(typeof(GXCompressor).FullName); - - private static readonly Dictionary errorMessages = new Dictionary(); - - static GXCompressor() - { - errorMessages.Add("GENERIC_ERROR", "An error occurred during the compression/decompression process: "); - errorMessages.Add("NO_FILES_ADDED", "No files have been added for compression."); - errorMessages.Add("FILE_NOT_EXISTS", "File does not exist: "); - errorMessages.Add("FOLDER_NOT_EXISTS", "The specified folder does not exist: "); - errorMessages.Add("UNSUPPORTED_FORMAT", "Unsupported compression/decompression format: "); - errorMessages.Add("EMPTY_FILE", "The selected file is empty: "); - } - - public static string GetMessage(string key) - { - if (errorMessages.TryGetValue(key, out string value)) - { - return value; - } - return "An error ocurred in the compression/decompression process: "; - } - - private static void StorageMessages(string error, GXBaseCollection messages) - { - if (messages != null && messages.Count > 0) - { - SdtMessages_Message msg = new() - { - gxTpr_Type = 1 - }; - msg.gxTpr_Description = error; - messages.Add(msg); - } - } - - public static bool CompressFiles(List files, string path, string format, ref GXBaseCollection messages) - { - if (files.Count == 0) - { - GXLogging.Error(log, $"{GetMessage("NO_FILES_ADDED")}"); - StorageMessages($"{GetMessage("NO_FILES_ADDED")}", messages); - return false; - } - FileInfo[] toCompress = new FileInfo[files.Count]; - int index = 0; - foreach (string filePath in files) - { - FileInfo file = new FileInfo(filePath); - if (!file.Exists) - { - GXLogging.Error(log, $"{GetMessage("FILE_NOT_EXISTS")}{filePath}"); - StorageMessages($"{GetMessage("FILE_NOT_EXISTS")}" + filePath, messages); - continue; - } - toCompress[index++] = file; - } - try - { - CompressionFormat compressionFormat = GetCompressionFormat(format); - switch (compressionFormat) - { - case CompressionFormat.ZIP: - CompressToZip(toCompress, path); - break; - case CompressionFormat.TAR: - CompressToTar(toCompress, path); - break; - case CompressionFormat.GZIP: - CompressToGzip(toCompress, path); - break; - case CompressionFormat.JAR: - CompressToJar(toCompress, path); - break; - } - return true; - } - catch (ArgumentException ae) - { - GXLogging.Error(log, $"{GetMessage("UNSUPPORTED_FORMAT")}" + format, ae); - StorageMessages(ae.Message, messages); - return false; - } - catch (Exception e) - { - GXLogging.Error(log, $"{GetMessage("GENERIC_ERROR")}", e); - StorageMessages(e.Message, messages); - return false; - } - } - - public static bool CompressFolder(string folder, string path, string format, ref GXBaseCollection messages) - { - DirectoryInfo toCompress = new DirectoryInfo(folder); - if (!toCompress.Exists) - { - GXLogging.Error(log, $"{GetMessage("FOLDER_NOT_EXISTS")}", toCompress.FullName); - StorageMessages($"{GetMessage("FOLDER_NOT_EXISTS")}" + toCompress.FullName, messages); - return false; - } - List list = new List { folder }; - return CompressFiles(list, path, format, ref messages); - } - - public static Compression NewCompression(string path, string format, ref GXBaseCollection messages) - { - return new Compression(path, format, ref messages); - } - - public static bool Decompress(string file, string path, ref GXBaseCollection messages) - { - FileInfo toCompress = new FileInfo(file); - if (!toCompress.Exists) - { - GXLogging.Error(log, $"{GetMessage("FILE_NOT_EXISTS")}" + toCompress.FullName); - StorageMessages($"{GetMessage("FILE_NOT_EXISTS")}" + toCompress.FullName, messages); - return false; - } - if (toCompress.Length == 0) - { - GXLogging.Error(log, $"{GetMessage("EMPTY_FILE")}"); - StorageMessages($"{GetMessage("EMPTY_FILE")}", messages); - return false; - } - string extension = Path.GetExtension(toCompress.Name).Substring(1); - try - { - switch (extension.ToLower()) - { - case "zip": - DecompressZip(toCompress, path); - break; - case "tar": - DecompressTar(toCompress, path); - break; - case "gz": - DecompressGzip(toCompress, path); - break; - case "jar": - DecompressJar(toCompress, path); - break; - case "rar": - DecompressRar(toCompress, path); - break; - case "7z": - Decompress7z(toCompress, path); - break; - default: - GXLogging.Error(log, $"{GetMessage("UNSUPPORTED_FORMAT")}" + extension); - StorageMessages($"{GetMessage("UNSUPPORTED_FORMAT")}" + extension, messages); - return false; - } - return true; - } - catch (Exception e) - { - GXLogging.Error(log, $"{GetMessage("GENERIC_ERROR")}", e); - StorageMessages(e.Message, messages); - return false; - } - } - - private static void CompressToZip(FileInfo[] files, string outputPath) - { - using (FileStream fos = new FileStream(outputPath, FileMode.Create)) - using (ZipArchive zos = new ZipArchive(fos, ZipArchiveMode.Create)) - { - foreach (FileInfo file in files) - { - if (file.Exists) - { - AddFileToZip(zos, file, string.Empty); - } - } - } - } - - private static void AddFileToZip(ZipArchive zos, FileInfo file, string baseDir) - { - string entryName = baseDir + file.Name; - if ((file.Attributes & FileAttributes.Directory) == FileAttributes.Directory) - { - DirectoryInfo dirInfo = file.Directory; - foreach (DirectoryInfo dir in dirInfo.GetDirectories()) - { - AddFileToZip(zos, new FileInfo(dir.FullName), entryName + Path.DirectorySeparatorChar); - } - foreach (FileInfo childFile in dirInfo.GetFiles()) - { - AddFileToZip(zos, childFile, entryName + Path.DirectorySeparatorChar); - } - } - else - { - ZipArchiveEntry zipEntry = zos.CreateEntryFromFile(file.FullName, entryName); - } - } - - private static void CompressToTar(FileInfo[] files, string outputPath) - { - FileInfo outputTarFile = new FileInfo(outputPath); - try - { - using (FileStream fos = outputTarFile.Create()) - using (TarOutputStream taos = new TarOutputStream(fos)) - { - taos.IsStreamOwner = false; - - foreach (FileInfo file in files) - { - AddFileToTar(taos, file, string.Empty); - } - taos.Close(); - } - } - catch (Exception e) - { - GXLogging.Error(log, "Error while compressing to tar", e); - throw new Exception("Error creating TAR archive", e); - } - } - - private static void AddFileToTar(TarOutputStream taos, FileInfo file, string baseDir) - { - if ((file.Attributes & FileAttributes.Directory) == FileAttributes.Directory) - { - DirectoryInfo dir = new DirectoryInfo(file.FullName); - FileInfo[] children = dir.GetFiles(); - DirectoryInfo[] directories = dir.GetDirectories(); - foreach (DirectoryInfo childDir in directories) - { - AddFileToTar(taos, new FileInfo(childDir.FullName), Path.Combine(baseDir, file.Name, Path.DirectorySeparatorChar.ToString())); - } - foreach (FileInfo childFile in children) - { - AddFileToTar(taos, childFile, Path.Combine(baseDir, file.Name, Path.DirectorySeparatorChar.ToString())); - } - } - else - { - string entryName = baseDir + file.Name; - TarEntry entry = TarEntry.CreateEntryFromFile(file.FullName); - entry.Name = entryName; - entry.Size = file.Length; - taos.PutNextEntry(entry); - - using (FileStream fis = File.OpenRead(file.FullName)) - { - byte[] buffer = new byte[4096]; - int bytesRead; - while ((bytesRead = fis.Read(buffer, 0, buffer.Length)) > 0) - { - taos.Write(buffer, 0, bytesRead); - } - } - taos.CloseEntry(); - } - } - - private static void CompressToGzip(FileInfo[] files, string outputPath) - { - if (files.Length > 1) - { - throw new ArgumentException("GZIP does not support multiple files. Consider archiving the files first."); - } - - FileInfo inputFile = files[0]; - FileInfo outputFile = new FileInfo(outputPath); - - using (FileStream inStream = inputFile.OpenRead()) - using (FileStream fout = outputFile.Create()) - using (GZipStream gzOut = new GZipStream(fout, CompressionMode.Compress)) - { - inStream.CopyTo(gzOut); - } - } - - private static void DecompressZip(FileInfo zipFile, string directory) - { - string zipFilePath = zipFile.FullName; - string targetDir = Path.GetFullPath(directory) + Path.DirectorySeparatorChar; - - try - { - using (FileStream fis = File.OpenRead(zipFilePath)) - using (ZipArchive zipIn = new ZipArchive(fis, ZipArchiveMode.Read)) - { - foreach (ZipArchiveEntry entry in zipIn.Entries) - { - string rawOutputPath = Path.Combine(targetDir, entry.FullName); - string resolvedOutputPath = Path.GetFullPath(rawOutputPath); - if (!resolvedOutputPath.StartsWith(targetDir, StringComparison.Ordinal)) - { - throw new SecurityException("Zip entry is outside of the target dir: " + entry.FullName); - } - - if (entry.FullName.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) - { - if (!Directory.Exists(resolvedOutputPath)) - { - Directory.CreateDirectory(resolvedOutputPath); - } - } - else - { - string parentDir = Path.GetDirectoryName(resolvedOutputPath); - if (!Directory.Exists(parentDir)) - { - Directory.CreateDirectory(parentDir); - } - using (FileStream outFile = new FileStream(resolvedOutputPath, FileMode.Create, FileAccess.Write)) - { - entry.Open().CopyTo(outFile); - } - } - } - } - } - catch (IOException e) - { - GXLogging.Error(log, "Error while decompressing zip", e); - throw new Exception("Failed to decompress ZIP file: " + zipFilePath, e); - } - } - - private static void DecompressTar(FileInfo file, string outputPath) - { - string targetDir = Path.GetFullPath(outputPath); - try - { - using (FileStream fi = File.OpenRead(file.FullName)) - using (TarInputStream ti = new TarInputStream(fi)) - { - TarEntry entry; - while ((entry = ti.GetNextEntry()) != null) - { - string entryPath = Path.Combine(targetDir, entry.Name); - FileInfo outputFile = new FileInfo(Path.GetFullPath(entryPath)); - - if (!outputFile.FullName.StartsWith(targetDir)) - { - throw new IOException("Entry is outside of the target directory: " + entry.Name); - } - - if (entry.IsDirectory) - { - if (!outputFile.Exists) - { - Directory.CreateDirectory(outputFile.FullName); - } - } - else - { - DirectoryInfo parent = outputFile.Directory; - if (!parent.Exists) - { - Directory.CreateDirectory(parent.FullName); - } - - using (FileStream outStream = File.Create(outputFile.FullName)) - { - ti.CopyEntryContents(outStream); - } - } - } - } - } - catch (IOException e) - { - GXLogging.Error(log, "Error while decompressing to zip", e); - throw new Exception("Failed to decompress TAR file: " + file.Name, e); - } - } - - private static void DecompressGzip(FileInfo inputFile, string outputPath) - { - DirectoryInfo outputDir = new DirectoryInfo(outputPath); - if (!outputDir.Exists) - { - outputDir.Create(); - } - - string outputFileName = inputFile.Name; - if (outputFileName.EndsWith(".gz")) - outputFileName = outputFileName.Substring(0, outputFileName.Length - 3); - else - throw new ArgumentException("The input file does not have a .gz extension."); - - FileInfo outputFile = new FileInfo(Path.Combine(outputDir.FullName, outputFileName)); - using (FileStream fis = inputFile.OpenRead()) - using (GZipStream gzis = new GZipStream(fis, CompressionMode.Decompress)) - using (FileStream fos = outputFile.Create()) - { - byte[] buffer = new byte[4096]; - int bytesRead; - while ((bytesRead = gzis.Read(buffer, 0, buffer.Length)) > 0) - { - fos.Write(buffer, 0, bytesRead); - } - } - } - - private static void Decompress7z(FileInfo file, string outputPath) - { - string targetDir = Path.GetFullPath(outputPath); - using (var sevenZFile = SevenZipArchive.Open(file.FullName)) - { - foreach (var entry in sevenZFile.Entries) - { - if (!entry.IsDirectory) - { - string resolvedPath = Path.Combine(targetDir, entry.Key); - FileInfo outputFile = new FileInfo(resolvedPath); - - if (!outputFile.FullName.StartsWith(targetDir, StringComparison.OrdinalIgnoreCase)) - { - throw new IOException("Entry is outside of the target dir: " + entry.Key); - } - - Directory.CreateDirectory(outputFile.DirectoryName); - - using (var outStream = outputFile.Open(FileMode.Create, FileAccess.Write)) - { - entry.WriteTo(outStream); - } - } - else - { - string dirPath = Path.Combine(targetDir, entry.Key); - if (!Directory.Exists(dirPath)) - { - Directory.CreateDirectory(dirPath); - } - } - } - } - } - - private static void CompressToJar(FileInfo[] files, string outputPath) - { - using (FileStream outputStream = new FileStream(outputPath, FileMode.Create)) - using (ZipArchive jos = new ZipArchive(outputStream, ZipArchiveMode.Create)) - { - byte[] buffer = new byte[1024]; - foreach (FileInfo file in files) - { - using (FileStream fis = file.OpenRead()) - { - ZipArchiveEntry entry = jos.CreateEntry(file.Name); - using (Stream entryStream = entry.Open()) - { - int length; - while ((length = fis.Read(buffer, 0, buffer.Length)) > 0) - { - entryStream.Write(buffer, 0, length); - } - } - } - } - } - } - - private static void DecompressJar(FileInfo jarFile, string outputPath) - { - if (!jarFile.Exists) - { - throw new IOException("The jar file does not exist."); - } - - DirectoryInfo outputDir = new DirectoryInfo(outputPath); - if (!outputDir.Exists) - { - outputDir.Create(); - } - - string resolvedOutputPath = Path.GetFullPath(outputPath) + Path.DirectorySeparatorChar; - - using (FileStream jarFileStream = jarFile.OpenRead()) - using (ZipArchive jis = new ZipArchive(jarFileStream, ZipArchiveMode.Read)) - { - foreach (ZipArchiveEntry entry in jis.Entries) - { - string entryPath = Path.Combine(outputPath, entry.FullName); - string resolvedEntryPath = Path.GetFullPath(entryPath); - if (!resolvedEntryPath.StartsWith(resolvedOutputPath, StringComparison.Ordinal)) - { - throw new IOException("Entry is outside the target directory: " + entry.FullName); - } - FileInfo outputFile = new FileInfo(resolvedEntryPath); - if (entry.FullName.EndsWith(Path.DirectorySeparatorChar.ToString())) - { - if (!Directory.Exists(outputFile.FullName)) - { - Directory.CreateDirectory(outputFile.FullName); - } - } - else - { - Directory.CreateDirectory(outputFile.DirectoryName); - using (FileStream fos = new FileStream(outputFile.FullName, FileMode.Create)) - { - using (Stream entryStream = entry.Open()) - { - entryStream.CopyTo(fos); - } - } - } - } - } - } - - public static void DecompressRar(FileInfo rarFile, string destinationPath) - { - using (var archive = RarArchive.Open(rarFile.FullName)) - { - foreach (var entry in archive.Entries) - { - if (!entry.IsDirectory) - { - entry.WriteToDirectory(destinationPath, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true }); - } - } - } - } - - private static CompressionFormat GetCompressionFormat(string format) - { - try - { - return (CompressionFormat)Enum.Parse(typeof(CompressionFormat), format.ToUpper()); - } - catch (ArgumentException) - { - throw new ArgumentException("Invalid compression format: " + format); - } - } - - } - -} - diff --git a/dotnet/GxCompress/IGXCompressor.cs b/dotnet/GxCompress/IGXCompressor.cs deleted file mode 100644 index ec92479af..000000000 --- a/dotnet/GxCompress/IGXCompressor.cs +++ /dev/null @@ -1,14 +0,0 @@ -using GeneXus.Utils; -using System.Collections.Generic; - -namespace Genexus.Compression -{ - public interface IGXCompressor - { - static bool CompressFiles(List files, string path, string format, ref GXBaseCollection messages) => false; - static bool CompressFolder(string folder, string path, string format, ref GXBaseCollection messages) => false; - static Compression NewCompression(string path, string format, int dictionarySize, ref GXBaseCollection messages) => new Compression(); - static bool Decompress(string file, string path, ref GXBaseCollection messages) => false; - } -} - diff --git a/dotnet/src/dotnetcore/GxCompress/GxCompress.csproj b/dotnet/src/dotnetcore/GxCompress/GxCompress.csproj new file mode 100644 index 000000000..854e58980 --- /dev/null +++ b/dotnet/src/dotnetcore/GxCompress/GxCompress.csproj @@ -0,0 +1,31 @@ + + + + net6.0;net8.0 + Library + NETCORE + GeneXus.Compression.Core + true + 618;1607;1698;SYSLIB0021;SYSLIB0027;SYSLIB0028;SYSLIB0023 + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet/src/dotnetframework/GxCompress/Compression.cs b/dotnet/src/dotnetframework/GxCompress/Compression.cs new file mode 100644 index 000000000..b54ca012b --- /dev/null +++ b/dotnet/src/dotnetframework/GxCompress/Compression.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using GeneXus.Utils; + +namespace Genexus.Compression +{ + public class Compression + { + + private string path; + private List filesToCompress; + private GXBaseCollection messages; + + public Compression() + { + filesToCompress = new List(); + } + + public Compression(string path, ref GXBaseCollection messages) + { + this.path = path; + this.messages = messages; + filesToCompress = new List(); + } + + public void AddElement(string filePath) + { + filesToCompress.Add(filePath); + } + + public bool Save() + { + return GXCompressor.Compress(filesToCompress, path, ref this.messages); + } + + public void Clear() + { + this.path = string.Empty; + filesToCompress = new List(); + } + } +} diff --git a/dotnet/src/dotnetframework/GxCompress/GXCompressor.cs b/dotnet/src/dotnetframework/GxCompress/GXCompressor.cs new file mode 100644 index 000000000..d52164383 --- /dev/null +++ b/dotnet/src/dotnetframework/GxCompress/GXCompressor.cs @@ -0,0 +1,523 @@ +using System; +using System.Collections.Generic; +#if !NETCORE +using System.Formats.Tar; +#endif +using System.IO; +using System.IO.Compression; +using GeneXus; +using GeneXus.Utils; +using SharpCompress.Archives; +using SharpCompress.Archives.Rar; +using SharpCompress.Common; +using SharpCompress.Writers.Tar; + +namespace Genexus.Compression +{ + public class GXCompressor : IGXCompressor + { + static readonly IGXLogger log = GXLoggerFactory.GetLogger(typeof(GXCompressor).FullName); + + private static readonly Dictionary errorMessages = new Dictionary(); + + static GXCompressor() + { + errorMessages.Add("GENERIC_ERROR", "An error occurred during the compression/decompression process: "); + errorMessages.Add("NO_FILES_ADDED", "No files have been added for compression."); + errorMessages.Add("FILE_NOT_EXISTS", "File does not exist: "); + errorMessages.Add("FOLDER_NOT_EXISTS", "The specified folder does not exist: "); + errorMessages.Add("UNSUPPORTED_FORMAT", "Unsupported compression/decompression format: "); + errorMessages.Add("EMPTY_FILE", "The selected file is empty: "); + } + + public static string GetMessage(string key) + { + if (errorMessages.TryGetValue(key, out string value)) + { + return value; + } + return "An error occurred in the compression/decompression process: "; + } + + private static void StorageMessages(string error, GXBaseCollection messages) + { + if (messages != null) + { + SdtMessages_Message msg = new SdtMessages_Message() + { + gxTpr_Type = 1, + gxTpr_Description = error + }; + messages.Add(msg); + } + } + + public static bool Compress(List files, string path, ref GXBaseCollection messages) + { + if (files.Count == 0) + { + GXLogging.Error(log, $"{GetMessage("NO_FILES_ADDED")}"); + StorageMessages($"{GetMessage("NO_FILES_ADDED")}", messages); + return false; + } + + List toCompress = new List(); + foreach (string filePath in files) + { + FileInfo file = new FileInfo(filePath); + if (!file.Exists) + { + GXLogging.Error(log, $"{GetMessage("FILE_NOT_EXISTS")}{filePath}"); + StorageMessages($"{GetMessage("FILE_NOT_EXISTS")}" + filePath, messages); + continue; + } + toCompress.Add(file); + } + + if (toCompress.Count == 0) + { + GXLogging.Error(log, $"{GetMessage("NO_FILES_ADDED")}"); + StorageMessages($"{GetMessage("NO_FILES_ADDED")}", messages); + return false; + } + + try + { + string compressionFormat = FileUtil.GetFileType(path).ToLower(); + + switch (compressionFormat) + { + case "zip": + CompressToZip(toCompress.ToArray(), path); + break; + case "tar": + CompressToTar(toCompress.ToArray(), path); + break; + case "gz": + CompressToGzip(toCompress.ToArray(), path); + break; + case "jar": + CompressToJar(toCompress.ToArray(), path); + break; + default: + GXLogging.Error(log, $"{GetMessage("UNSUPPORTED_FORMAT")}" + compressionFormat); + StorageMessages($"{GetMessage("UNSUPPORTED_FORMAT")}" + compressionFormat, messages); + return false; + } + return true; + } + catch (Exception e) + { + GXLogging.Error(log, $"{GetMessage("GENERIC_ERROR")}", e); + StorageMessages(e.Message, messages); + return false; + } + } + + public static Compression NewCompression(string path, string format, ref GXBaseCollection messages) + { + return new Compression(path, ref messages); + } + + public static bool Decompress(string file, string path, ref GXBaseCollection messages) + { + FileInfo fileInfo = new FileInfo(file); + if (!fileInfo.Exists) + { + GXLogging.Error(log, $"{GetMessage("FILE_NOT_EXISTS")}" + fileInfo.FullName); + StorageMessages($"{GetMessage("FILE_NOT_EXISTS")}" + fileInfo.FullName, messages); + return false; + } + if (fileInfo.Length == 0) + { + GXLogging.Error(log, $"{GetMessage("EMPTY_FILE")}"); + StorageMessages($"{GetMessage("EMPTY_FILE")}", messages); + return false; + } + string extension = FileUtil.GetFileType(fileInfo.Name).ToLower(); + try + { + switch (extension) + { + case "zip": + DecompressZip(fileInfo, path); + break; + case "tar": + DecompressTar(fileInfo, path); + break; + case "gz": + DecompressGzip(fileInfo, path); + break; + case "jar": + DecompressJar(fileInfo, path); + break; + case "rar": + DecompressRar(fileInfo, path); + break; + case "7z": + Decompress7z(fileInfo, path); + break; + default: + GXLogging.Error(log, $"{GetMessage("UNSUPPORTED_FORMAT")}" + extension); + StorageMessages($"{GetMessage("UNSUPPORTED_FORMAT")}" + extension, messages); + return false; + } + return true; + } + catch (Exception e) + { + GXLogging.Error(log, $"{GetMessage("GENERIC_ERROR")}", e); + StorageMessages(e.Message, messages); + return false; + } + } + + private static void CompressToZip(FileSystemInfo[] files, string outputPath) + { + using (FileStream zipToOpen = new FileStream(outputPath, FileMode.Create)) + { + using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update)) + { + foreach (FileSystemInfo fsi in files) + { + if (fsi is FileInfo fileInfo) + { + string entryName = fileInfo.Name; + AddFileToArchive(fileInfo.FullName, entryName, archive); + } + else if (fsi is DirectoryInfo dirInfo) + { + AddDirectoryToArchive(dirInfo, archive, dirInfo.FullName); + } + } + } + } + } + + private static void AddFileToArchive(string filePath, string entryName, ZipArchive archive) + { + ZipArchiveEntry entry = archive.CreateEntry(entryName); + using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) + using (Stream entryStream = entry.Open()) + { + fs.CopyTo(entryStream); + } + } + + private static void AddDirectoryToArchive(DirectoryInfo directory, ZipArchive archive, string basePath) + { + foreach (var file in directory.GetFiles()) + { + string entryName = file.FullName.Substring(basePath.Length + 1).Replace('\\', '/'); + AddFileToArchive(file.FullName, entryName, archive); + } + foreach (var subDirectory in directory.GetDirectories()) + { + AddDirectoryToArchive(subDirectory, archive, basePath); + } + } + + private static void CompressToTar(FileSystemInfo[] files, string outputPath) + { +#if !NETCORE + using (FileStream tarStream = new FileStream(outputPath, FileMode.Create)) + using (TarWriter tarWriter = new TarWriter(tarStream, TarEntryFormat.Pax, leaveOpen: false)) + { + foreach (FileSystemInfo fsi in files) + { + if (fsi is FileInfo fileInfo) + { + tarWriter.WriteEntry(fileInfo.FullName, fileInfo.Name); + } + else if (fsi is DirectoryInfo dirInfo) + { + AddDirectoryToTar(tarWriter, dirInfo, dirInfo.FullName); + } + } + } + + void AddDirectoryToTar(TarWriter tarWriter, DirectoryInfo directory, string basePath) + { + foreach (var file in directory.GetFiles()) + { + string entryName = file.FullName.Substring(basePath.Length + 1).Replace('\\', '/'); + tarWriter.WriteEntry(file.FullName, entryName); + } + foreach (var subDirectory in directory.GetDirectories()) + { + AddDirectoryToTar(tarWriter, subDirectory, basePath); + } + } +#else + using (FileStream tarStream = File.Create(outputPath)) + using (var tarOutputStream = new ICSharpCode.SharpZipLib.Tar.TarOutputStream(tarStream)) + { + foreach (FileSystemInfo fsi in files) + { + if (fsi is FileInfo fileInfo) + { + AddFileToTar(tarOutputStream, fileInfo.FullName, fileInfo.Name); + } + else if (fsi is DirectoryInfo dirInfo) + { + AddDirectoryFilesToTar(tarOutputStream, dirInfo, dirInfo.FullName); + } + } + } + + void AddFileToTar(ICSharpCode.SharpZipLib.Tar.TarOutputStream tarOutputStream, string filePath, string entryName) + { + var entry = ICSharpCode.SharpZipLib.Tar.TarEntry.CreateEntryFromFile(filePath); + entry.Name = entryName.Replace('\\', '/'); + tarOutputStream.PutNextEntry(entry); + + using (FileStream fs = File.OpenRead(filePath)) + { + fs.CopyTo(tarOutputStream); + } + tarOutputStream.CloseEntry(); + } + + void AddDirectoryFilesToTar(ICSharpCode.SharpZipLib.Tar.TarOutputStream tarOutputStream, DirectoryInfo directory, string basePath) + { + foreach (var file in directory.GetFiles()) + { + string entryName = file.FullName.Substring(basePath.Length + 1).Replace('\\', '/'); + AddFileToTar(tarOutputStream, file.FullName, entryName); + } + foreach (var subDirectory in directory.GetDirectories()) + { + AddDirectoryFilesToTar(tarOutputStream, subDirectory, basePath); + } + } +#endif + } + + private static void CompressToGzip(FileSystemInfo[] files, string outputPath) + { +#if !NETCORE + string tempTarPath = Path.GetTempFileName(); + + using (FileStream tarStream = new FileStream(tempTarPath, FileMode.Create)) + using (TarWriter tarWriter = new TarWriter(tarStream, TarEntryFormat.Pax, leaveOpen: false)) + { + foreach (FileSystemInfo fsi in files) + { + if (fsi is FileInfo fileInfo) + { + tarWriter.WriteEntry(fileInfo.FullName, fileInfo.Name); + } + else if (fsi is DirectoryInfo dirInfo) + { + AddDirectoryToTar(tarWriter, dirInfo, dirInfo.FullName); + } + } + } + + using (FileStream tarStream = new FileStream(tempTarPath, FileMode.Open)) + using (FileStream gzipStream = new FileStream(outputPath, FileMode.Create)) + using (GZipStream compressionStream = new GZipStream(gzipStream, CompressionLevel.Optimal)) + { + tarStream.CopyTo(compressionStream); + } + + File.Delete(tempTarPath); + + void AddDirectoryToTar(TarWriter tarWriter, DirectoryInfo directory, string basePath) + { + foreach (var file in directory.GetFiles()) + { + string entryName = Path.GetRelativePath(basePath, file.FullName).Replace('\\', '/'); + tarWriter.WriteEntry(file.FullName, entryName); + } + foreach (var subDirectory in directory.GetDirectories()) + { + AddDirectoryToTar(tarWriter, subDirectory, basePath); + } + } +#else + // Code for .NET Framework 4.6.2 using SharpZipLib + string tempTarPath = Path.GetTempFileName(); + + using (FileStream tarStream = File.Create(tempTarPath)) + using (var tarOutputStream = new ICSharpCode.SharpZipLib.Tar.TarOutputStream(tarStream)) + { + foreach (FileSystemInfo fsi in files) + { + if (fsi is FileInfo fileInfo) + { + AddFileToTar(tarOutputStream, fileInfo.FullName, fileInfo.Name); + } + else if (fsi is DirectoryInfo dirInfo) + { + AddDirectoryFilesToTar(tarOutputStream, dirInfo, dirInfo.FullName); + } + } + } + + using (FileStream tarStream = File.OpenRead(tempTarPath)) + using (FileStream gzipStream = File.Create(outputPath)) + using (var gzipOutputStream = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(gzipStream)) + { + tarStream.CopyTo(gzipOutputStream); + } + + File.Delete(tempTarPath); + + void AddFileToTar(ICSharpCode.SharpZipLib.Tar.TarOutputStream tarOutputStream, string filePath, string entryName) + { + var entry = ICSharpCode.SharpZipLib.Tar.TarEntry.CreateEntryFromFile(filePath); + entry.Name = entryName.Replace('\\', '/'); + tarOutputStream.PutNextEntry(entry); + + using (FileStream fs = File.OpenRead(filePath)) + { + fs.CopyTo(tarOutputStream); + } + tarOutputStream.CloseEntry(); + } + + void AddDirectoryFilesToTar(ICSharpCode.SharpZipLib.Tar.TarOutputStream tarOutputStream, DirectoryInfo directory, string basePath) + { + foreach (var file in directory.GetFiles()) + { + string entryName = Path.GetRelativePath(basePath, file.FullName).Replace('\\', '/'); + AddFileToTar(tarOutputStream, file.FullName, entryName); + } + foreach (var subDirectory in directory.GetDirectories()) + { + AddDirectoryFilesToTar(tarOutputStream, subDirectory, basePath); + } + } +#endif + } + + private static void CompressToJar(FileSystemInfo[] files, string outputPath) + { + using (FileStream jarStream = new FileStream(outputPath, FileMode.Create)) + using (ZipArchive archive = new ZipArchive(jarStream, ZipArchiveMode.Create)) + { + // Add the manifest file + ZipArchiveEntry manifestEntry = archive.CreateEntry("META-INF/MANIFEST.MF"); + using (StreamWriter writer = new StreamWriter(manifestEntry.Open())) + { + writer.WriteLine("Manifest-Version: 1.0"); + } + + foreach (FileSystemInfo fsi in files) + { + if (fsi is FileInfo fileInfo) + { + string entryName = fileInfo.Name; + AddFileToArchive(fileInfo.FullName, entryName, archive); + } + else if (fsi is DirectoryInfo dirInfo) + { + AddDirectoryToArchive(dirInfo, archive, dirInfo.FullName); + } + } + } + + void AddFileToArchive(string filePath, string entryName, ZipArchive archive) + { + ZipArchiveEntry entry = archive.CreateEntry(entryName); + using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) + using (Stream entryStream = entry.Open()) + { + fs.CopyTo(entryStream); + } + } + + void AddDirectoryToArchive(DirectoryInfo directory, ZipArchive archive, string basePath) + { + foreach (var file in directory.GetFiles()) + { + string entryName = Path.GetRelativePath(basePath, file.FullName).Replace('\\', '/'); + AddFileToArchive(file.FullName, entryName, archive); + } + foreach (var subDirectory in directory.GetDirectories()) + { + AddDirectoryToArchive(subDirectory, archive, basePath); + } + } + } + + private static void DecompressZip(FileInfo file, string directory) + { + ZipFile.ExtractToDirectory(file.FullName, directory); + } + + private static void DecompressTar(FileInfo file, string directory) + { +#if !NETCORE + TarFile.ExtractToDirectory(file.FullName, directory, overwriteFiles: true); +#else + using (Stream inStream = File.OpenRead(file.FullName)) + using (var tarInputStream = new ICSharpCode.SharpZipLib.Tar.TarInputStream(inStream)) + { + ICSharpCode.SharpZipLib.Tar.TarEntry tarEntry; + while ((tarEntry = tarInputStream.GetNextEntry()) != null) + { + string outPath = Path.Combine(directory, tarEntry.Name); + if (tarEntry.IsDirectory) + { + Directory.CreateDirectory(outPath); + } + else + { + Directory.CreateDirectory(Path.GetDirectoryName(outPath)); + using (FileStream outStream = File.Create(outPath)) + { + tarInputStream.CopyEntryContents(outStream); + } + } + } + } +#endif + } + + private static void DecompressGzip(FileInfo file, string directory) + { + string decompressedFileName = Path.GetFileNameWithoutExtension(file.Name); + string outputPath = Path.Combine(directory, decompressedFileName); + + using (FileStream originalFileStream = file.OpenRead()) + using (FileStream decompressedFileStream = File.Create(outputPath)) + using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress)) + { + decompressionStream.CopyTo(decompressedFileStream); + } + } + + private static void Decompress7z(FileInfo file, string directory) + { + using (ArchiveFile archiveFile = new ArchiveFile(file.FullName)) + { + archiveFile.Extract(directory); + } + } + + private static void DecompressJar(FileInfo file, string directory) + { + ZipFile.ExtractToDirectory(file.FullName, directory); + } + + private static void DecompressRar(FileInfo file, string directory) + { + using (var archive = RarArchive.Open(file.FullName)) + { + foreach (var entry in archive.Entries) + { + if (!entry.IsDirectory) + { + entry.WriteToDirectory(directory, new ExtractionOptions() + { + ExtractFullPath = true, + Overwrite = true + }); + } + } + } + } + } +} \ No newline at end of file diff --git a/dotnet/GxCompress/GxCompress.csproj b/dotnet/src/dotnetframework/GxCompress/GxCompress.csproj similarity index 71% rename from dotnet/GxCompress/GxCompress.csproj rename to dotnet/src/dotnetframework/GxCompress/GxCompress.csproj index 5eadf8761..4d39e8419 100644 --- a/dotnet/GxCompress/GxCompress.csproj +++ b/dotnet/src/dotnetframework/GxCompress/GxCompress.csproj @@ -1,10 +1,9 @@ - net6.0;net8.0 + net462 Library - NETCORE;NODATIME - GeneXus.Compression + GeneXus.Compression.Fmk true 618;1607;1698;SYSLIB0021;SYSLIB0027;SYSLIB0028;SYSLIB0023 @@ -14,12 +13,12 @@ - + - + diff --git a/dotnet/src/dotnetframework/GxCompress/IGXCompressor.cs b/dotnet/src/dotnetframework/GxCompress/IGXCompressor.cs new file mode 100644 index 000000000..69c6f0b8b --- /dev/null +++ b/dotnet/src/dotnetframework/GxCompress/IGXCompressor.cs @@ -0,0 +1,13 @@ +using GeneXus.Utils; +using System.Collections.Generic; + +namespace Genexus.Compression +{ + public interface IGXCompressor + { + static bool Compress(List files, string path, ref GXBaseCollection messages) => false; + static Compression NewCompression(string path, int dictionarySize, ref GXBaseCollection messages) => new Compression(); + static bool Decompress(string file, string path, ref GXBaseCollection messages) => false; + } +} + diff --git a/dotnet/test/DotNetCoreUnitTest/CompressionTests.cs b/dotnet/test/DotNetCoreUnitTest/CompressionTests.cs index 3a3918a53..b0f5d458f 100644 --- a/dotnet/test/DotNetCoreUnitTest/CompressionTests.cs +++ b/dotnet/test/DotNetCoreUnitTest/CompressionTests.cs @@ -1,135 +1,61 @@ using System; using System.Collections.Generic; using System.IO; -using Genexus.Compression; using GeneXus.Utils; using Xunit; namespace xUnitTesting { - public class TestCompression : IDisposable + public class TestCompression { - private List files; - private DirectoryInfo testDirectory; - private GXBaseCollection messages = null; public TestCompression() { - testDirectory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "testCompressor")); - testDirectory.Create(); - files = new List(); - string content = "This is a sample text to test the compression functionality."; - for (int i = 0; i < 3; i++) - { - string filePath = Path.Combine(testDirectory.FullName, $"testFile{i}.txt"); - File.WriteAllText(filePath, content); - files.Add(filePath); - } - } - - public void Dispose() - { - foreach (string filePath in files) - { - File.Delete(filePath); - } - testDirectory.Delete(true); } [Fact] public void TestCompressToZip() { - string outputPath = Path.Combine(testDirectory.FullName, "output.zip"); - bool result = GXCompressor.CompressFiles(files, outputPath, "ZIP", ref messages); - Assert.True(result); - Assert.True(File.Exists(outputPath)); } [Fact] public void TestCompressToTar() { - string outputPath = Path.Combine(testDirectory.FullName, "output.tar"); - bool result = GXCompressor.CompressFiles(files, outputPath, "TAR", ref messages); - Assert.True(result); - Assert.True(File.Exists(outputPath)); } [Fact] public void TestCompressToGzip() { - string outputPath = Path.Combine(testDirectory.FullName, "output.gz"); - string inputFilePath = Path.Combine(testDirectory.FullName, "test.txt"); - File.WriteAllText(inputFilePath, "This is a sample text to test the compression functionality."); - List singleFileCollection = new List { inputFilePath }; - bool result = GXCompressor.CompressFiles(singleFileCollection, outputPath, "GZIP", ref messages); - Assert.True(result); - Assert.True(File.Exists(outputPath)); } [Fact] public void TestCompressToJar() { - string outputPath = Path.Combine(testDirectory.FullName, "output.jar"); - bool result = GXCompressor.CompressFiles(files, outputPath, "JAR", ref messages); - Assert.True(result); - Assert.True(File.Exists(outputPath)); } [Fact] public void TestUnsupportedFormat() { - string outputPath = Path.Combine(testDirectory.FullName, "output.unknown"); - bool result = GXCompressor.CompressFiles(files, outputPath, "UNKNOWN", ref messages); - Assert.False(result); } [Fact] public void TestDecompressZip() { - string compressedPath = Path.Combine(testDirectory.FullName, "output.zip"); - GXCompressor.CompressFiles(files, compressedPath, "ZIP", ref messages); - string decompressDirectory = Path.Combine(testDirectory.FullName, "decompressZip"); - Directory.CreateDirectory(decompressDirectory); - bool result = GXCompressor.Decompress(compressedPath, decompressDirectory, ref messages); - Assert.True(result); - Assert.True(Directory.GetFiles(decompressDirectory).Length > 0); } [Fact] public void TestDecompressTar() { - string compressedPath = Path.Combine(testDirectory.FullName, "output.tar"); - GXCompressor.CompressFiles(files, compressedPath, "TAR", ref messages); - string decompressDirectory = Path.Combine(testDirectory.FullName, "decompressTar"); - Directory.CreateDirectory(decompressDirectory); - bool result = GXCompressor.Decompress(compressedPath, decompressDirectory, ref messages); - Assert.True(result); - Assert.True(Directory.GetFiles(decompressDirectory).Length > 0); } [Fact] public void TestDecompressGzip() { - string compressedPath = Path.Combine(testDirectory.FullName, "output.gz"); - List singleFileCollection = new List { files[0] }; - GXCompressor.CompressFiles(singleFileCollection, compressedPath, "GZIP", ref messages); - string decompressDirectory = Path.Combine(testDirectory.FullName, "decompressGzip"); - Directory.CreateDirectory(decompressDirectory); - bool result = GXCompressor.Decompress(compressedPath, decompressDirectory, ref messages); - Assert.True(result); - Assert.True(Directory.GetFiles(decompressDirectory).Length > 0); } [Fact] public void TestDecompressJar() { - string compressedPath = Path.Combine(testDirectory.FullName, "output.jar"); - GXCompressor.CompressFiles(files, compressedPath, "JAR", ref messages); - string decompressDirectory = Path.Combine(testDirectory.FullName, "decompressJar"); - Directory.CreateDirectory(decompressDirectory); - bool result = GXCompressor.Decompress(compressedPath, decompressDirectory, ref messages); - Assert.True(result); - Assert.True(Directory.GetFiles(decompressDirectory).Length > 0); } } }