Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeneXus compression module #1038

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fd42e70
Compression EO initial implementation for NET
tomas-sexenian Jun 10, 2024
26c1d47
Add GXClasses and SharpZipLib as a dependency
tomas-sexenian Jun 10, 2024
5b296d3
Follow best coding practices
tomas-sexenian Jun 10, 2024
ccae7e2
Switch to Path.DirectorySeparatorChar
tomas-sexenian Jun 10, 2024
f6624e5
Add support for rar, jar and 7z
tomas-sexenian Jun 11, 2024
221e7e4
Add compression tests
tomas-sexenian Jun 11, 2024
0dceab5
Add gzip test and fix infinite loop in gzip compression
tomas-sexenian Jun 12, 2024
6e094fd
Update compression methods to return a CompressionMessage object and …
tomas-sexenian Jul 15, 2024
16fb080
Make attributes readonly
tomas-sexenian Jul 15, 2024
d8590f1
Update compression methods to return a boolean and messages
tomas-sexenian Jul 16, 2024
c5da1d2
Refactor for better code quality
tomas-sexenian Jul 22, 2024
362719a
Fix zip slip security issue
tomas-sexenian Jul 25, 2024
53db81d
Move GxCompress.csproj to src/dotnetframework directory
tomas-sexenian Jul 25, 2024
527061a
Move GxCompress.csproj to src/dotnetframework directory
tomas-sexenian Jul 25, 2024
3dfbd7d
Update GxCompress.csproj
tomas-sexenian Jul 29, 2024
02e50a3
Rework
tomas-sexenian Nov 7, 2024
3d06b73
Try to fix some build errors
claudiamurialdo Nov 8, 2024
cac4fb3
Add checks for DoS and directory traversal attacks
tomas-sexenian Nov 18, 2024
552d1b2
Add unit tests
tomas-sexenian Nov 18, 2024
f11370c
Fix compilation error and add option for not checking filesize
tomas-sexenian Nov 18, 2024
10941f6
Fix compilation error
tomas-sexenian Nov 18, 2024
19bb3d0
Remove interface dependency
tomas-sexenian Nov 19, 2024
72bc65c
Try make tests
tomas-sexenian Nov 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dotnet/DotNetStandardClasses.sln
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ 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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -641,6 +643,10 @@ 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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -767,6 +773,7 @@ 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}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C}
Expand Down
94 changes: 94 additions & 0 deletions dotnet/GxCompress/Compression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System.Collections.Generic;
using System.IO;
using GeneXus;

namespace Genexus.Compression
{
public class Compression
{
static readonly IGXLogger log = GXLoggerFactory.GetLogger(typeof(Compression).FullName);

private string path;
private string format;
private List<FileInfo> filesToCompress;

public Compression()
{
filesToCompress = new List<FileInfo>();
}

public Compression(string path, string format)
{
this.path = path;
this.format = format;
this.filesToCompress = new List<FileInfo>();
}

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)
{
DirectoryInfo folder = new DirectoryInfo(folderPath);
if (folder.Exists && folder.Attributes.HasFlag(FileAttributes.Directory))
{
FileInfo[] files = folder.GetFiles();
DirectoryInfo[] directories = folder.GetDirectories();
foreach (DirectoryInfo dir in directories)
{
AddFolder(dir.FullName);
}
foreach (FileInfo file in files)
{
AddFile(file.FullName);
}
}
else
{
GXLogging.Error(log, "Folder does not exist or is not a directory: {0}", folder.FullName);
}
}

public int Save()
{
if (filesToCompress.Count == 0)
{
GXLogging.Error(log, "No files have been added for compression.");
return -4;
}
List<string> paths = new List<string>();
foreach (FileInfo file in filesToCompress)
{
paths.Add(file.FullName);
}
return GXCompressor.CompressFiles(paths, path, format);
}

public void Clear()
{
this.path = string.Empty;
this.format = string.Empty;
this.filesToCompress = new List<FileInfo>();
}
}
}
Loading
Loading