Added support for LZip.

This commit is contained in:
2017-06-06 22:50:45 +01:00
parent 01461176f3
commit 379d29ca02
8 changed files with 93 additions and 12 deletions

View File

@@ -31,6 +31,7 @@ namespace osrepodbmgr.Core
{
GZip,
BZip2,
LZMA
LZMA,
LZip
}
}

View File

@@ -1,3 +1,14 @@
2017-06-06 Natalia Portillo <claunia@claunia.com>
* AlgoEnum.cs:
* packages.config:
* Workers/Clamd.cs:
* Workers/Files.cs:
* Workers/VirusTotal.cs:
* Workers/Compression.cs:
* osrepodbmgr.Core.csproj:
Added support for LZip.
2017-05-21 Natalia Portillo <claunia@claunia.com>
* Workers/Files.cs:

View File

@@ -120,6 +120,17 @@ namespace osrepodbmgr.Core
file.Sha256 + ".lzma");
algorithm = AlgoEnum.LZMA;
}
else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz")))
{
repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz");
algorithm = AlgoEnum.LZip;
}
else
{
if(Failed != null)
@@ -133,16 +144,21 @@ namespace osrepodbmgr.Core
if(Settings.Current.ClamdIsLocal)
{
// clamd supports gzip and bzip2 but not lzma
if(algorithm == AlgoEnum.LZMA)
if(algorithm == AlgoEnum.LZMA || algorithm == AlgoEnum.LZip)
{
string tmpFile = Path.Combine(Settings.Current.TemporaryFolder, Path.GetTempFileName());
FileStream outFs = new FileStream(tmpFile, FileMode.Create, FileAccess.Write);
FileStream inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read);
byte[] properties = new byte[5];
inFs.Read(properties, 0, 5);
inFs.Seek(8, SeekOrigin.Current);
zStream = new LzmaStream(properties, inFs, inFs.Length - 13, file.Length);
if(algorithm == AlgoEnum.LZMA)
{
byte[] properties = new byte[5];
inFs.Read(properties, 0, 5);
inFs.Seek(8, SeekOrigin.Current);
zStream = new LzmaStream(properties, inFs, inFs.Length - 13, file.Length);
}
else
zStream = new LZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
if(UpdateProgress != null)
UpdateProgress("Uncompressing file...", null, 0, 0);
@@ -210,7 +226,9 @@ namespace osrepodbmgr.Core
inFs.Read(properties, 0, 5);
inFs.Seek(8, SeekOrigin.Current);
zStream = new LzmaStream(properties, inFs, inFs.Length - 13, file.Length);
break;
case AlgoEnum.LZip:
zStream = new LZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
break;
}

View File

@@ -186,6 +186,9 @@ namespace osrepodbmgr.Core
case AlgoEnum.LZMA:
extension = ".lzma";
break;
case AlgoEnum.LZip:
extension = ".lz";
break;
}
#if DEBUG
@@ -220,6 +223,9 @@ namespace osrepodbmgr.Core
outFs.Write(((LzmaStream)zStream).Properties, 0, ((LzmaStream)zStream).Properties.Length);
outFs.Write(BitConverter.GetBytes(inFs.Length), 0, 8);
break;
case AlgoEnum.LZip:
zStream = new LZipStream(outFs, SharpCompress.Compressors.CompressionMode.Compress);
break;
}
byte[] buffer = new byte[bufferSize];
@@ -745,6 +751,17 @@ namespace osrepodbmgr.Core
file.Sha256 + ".lzma");
algorithm = AlgoEnum.LZMA;
}
else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz")))
{
repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz");
algorithm = AlgoEnum.LZip;
}
else
throw new ArgumentException(string.Format("Cannot find file with hash {0} in the repository", file.Sha256));
@@ -764,6 +781,9 @@ namespace osrepodbmgr.Core
inFs.Seek(8, SeekOrigin.Current);
zStream = new LzmaStream(properties, inFs, inFs.Length - 13, file.Length);
break;
case AlgoEnum.LZip:
zStream = new LZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
break;
}
return zStream;

View File

@@ -704,6 +704,17 @@ namespace osrepodbmgr.Core
file.Sha256 + ".lzma");
algorithm = AlgoEnum.LZMA;
}
else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz")))
{
repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz");
algorithm = AlgoEnum.LZip;
}
else
{
if(Failed != null)
@@ -728,6 +739,9 @@ namespace osrepodbmgr.Core
inFs.Seek(8, SeekOrigin.Current);
zStream = new LzmaStream(properties, inFs);
break;
case AlgoEnum.LZip:
zStream = new LZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
break;
}
byte[] buffer = new byte[bufferSize];

View File

@@ -214,6 +214,17 @@ namespace osrepodbmgr.Core
file.Sha256 + ".lzma");
algorithm = AlgoEnum.LZMA;
}
else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz")))
{
repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(),
file.Sha256[1].ToString(), file.Sha256[2].ToString(),
file.Sha256[3].ToString(), file.Sha256[4].ToString(),
file.Sha256 + ".lz");
algorithm = AlgoEnum.LZip;
}
else
{
if(Failed != null)
@@ -241,6 +252,9 @@ namespace osrepodbmgr.Core
inFs.Seek(8, SeekOrigin.Current);
zStream = new LzmaStream(properties, inFs, inFs.Length - 13, file.Length);
break;
case AlgoEnum.LZip:
zStream = new LZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress);
break;
}
ScanResult sResult = null;

View File

@@ -38,9 +38,6 @@
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Data" />
<Reference Include="SharpCompress">
<HintPath>..\packages\SharpCompress.0.15.2\lib\net45\SharpCompress.dll</HintPath>
</Reference>
<Reference Include="nClam">
<HintPath>..\packages\nClam.3.0.0\lib\net45\nClam.dll</HintPath>
</Reference>
@@ -52,6 +49,9 @@
<Reference Include="plist-cil">
<HintPath>..\packages\plist-cil.1.16.0\lib\net45\plist-cil.dll</HintPath>
</Reference>
<Reference Include="SharpCompress">
<HintPath>..\packages\SharpCompress.0.17.0\lib\net45\SharpCompress.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -126,7 +126,10 @@
<MonoDevelop>
<Properties>
<Policies>
<DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedHierarchical" ResourceNamePolicy="MSBuild" />
<DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedHierarchical" ResourceNamePolicy="MSBuild">
<inheritsSet />
<inheritsScope />
</DotNetNamingPolicy>
</Policies>
</Properties>
</MonoDevelop>

View File

@@ -4,7 +4,7 @@
<package id="nClam" version="3.0.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
<package id="plist-cil" version="1.16.0" targetFramework="net45" />
<package id="SharpCompress" version="0.15.2" targetFramework="net45" />
<package id="SharpCompress" version="0.17.0" targetFramework="net45" />
<package id="System.Data.SQLite.Core" version="1.0.105.0" targetFramework="net45" />
<package id="System.Dynamic.Runtime" version="4.3.0" targetFramework="net45" />
<package id="System.Net.Http" version="4.3.1" targetFramework="net45" />