Skip to content

Commit

Permalink
prepare to call it a release (v0.2)
Browse files Browse the repository at this point in the history
add IDisposable interfaces to Extractor and Compressor
add a couple sanity checks
add a couple custom exceptions
add password to command-line app
add Fody Costura nuget package to command-line app
  • Loading branch information
daPhie79 committed Mar 24, 2019
1 parent 7779e1d commit 1c45080
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,4 @@ __pycache__/
*.pyc

# CUSTOM ADDED
ToDo.txt

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ tiny7z is a native C# SevenZip 7zip .7z file format archive reader/writer
- Support LZMA, LZMA2, PPMd decoders.
- Support AES, BCJ and BCJ2 decoder filters.

## Releases

- v0.1 - First release, unofficial, lots of features missing, incomplete test app
- v0.2 - First official release, command-line test app

## Current limitations

*They are plenty unfortunately, but this library is still a huge step forward for compact .7z support in native C#*
Expand Down
4 changes: 2 additions & 2 deletions tiny7z/Archive/Interfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ UInt64 TotalSize
/// <summary>
/// Extractor proxy interface
/// </summary>
public interface IExtractor
public interface IExtractor : IDisposable
{
/// <summary>
/// List of files contained in the opened archive.
Expand Down Expand Up @@ -208,7 +208,7 @@ bool SkipExistingFiles
/// <summary>
/// Compressor proxy interface
/// </summary>
public interface ICompressor
public interface ICompressor : IDisposable
{
/// <summary>
/// List of files in the archive.
Expand Down
15 changes: 15 additions & 0 deletions tiny7z/Archive/SevenZip/SevenZipCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public bool Solid
#endregion Public Properties

#region Public Methods
public void Dispose() // IDisposable
{
if (this.stream != null && this.header != null)
{
Finalize();
}
this.stream = null;
this.header = null;
}

public ICompressor AddDirectory(string inputDirectory, string archiveDirectory = null, bool recursive = true)
{
Trace.TraceInformation($"Adding files from directory `{inputDirectory}`.");
Expand Down Expand Up @@ -146,6 +156,9 @@ public ICompressor AddFile(Stream stream, string archiveFileName, DateTime? time

public ICompressor Finalize()
{
if (this.stream == null || this.header == null)
throw new SevenZipException("Compressor object has already been finalized.");

Trace.TraceInformation($"Compressing files.");
Trace.Indent();
try
Expand Down Expand Up @@ -189,6 +202,8 @@ public ICompressor Finalize()
Trace.TraceInformation("Done compressing files.");
}

this.stream = null;
this.header = null;
return this;
}
#endregion Public Methods
Expand Down
19 changes: 16 additions & 3 deletions tiny7z/Archive/SevenZip/SevenZipException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@

namespace pdj.tiny7z.Archive
{
/// <summary>
/// Base exception class for error handling
/// </summary>
public class SevenZipException : Exception
{
internal SevenZipException(string message)
: base(message)
{
}
}

public class SevenZipFileAlreadyExistsException : SevenZipException
{
internal SevenZipFileAlreadyExistsException(SevenZipArchiveFile file)
: base($"File `{file.Name}` already exists.")
{
}
}

public class SevenZipPasswordRequiredException : SevenZipException
{
internal SevenZipPasswordRequiredException()
: base("No password provided. Encrypted stream requires password.")
{
}
}
}
8 changes: 6 additions & 2 deletions tiny7z/Archive/SevenZip/SevenZipExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public bool SkipExistingFiles
#endregion Public Properties

#region Public Methods
public void Dispose() // IDisposable
{
Finalize();
}

public void Dump()
{
// TODO
Expand Down Expand Up @@ -288,7 +293,6 @@ public IExtractor Finalize()
{
this.stream = null;
this.header = null;
this._Files = null;
return this;
}
#endregion Public Methods
Expand Down Expand Up @@ -369,7 +373,7 @@ private bool preProcessFile(string outputDirectory, SevenZipArchiveFile file)
else
{
if (!SkipExistingFiles)
throw new IOException($"File `{file.Name}` already exists.");
throw new SevenZipFileAlreadyExistsException(file);
result = FeedbackResult.No;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tiny7z/Archive/SevenZip/SevenZipStreamsExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal SevenZipStreamsExtractor(Stream stream, SevenZipHeader.StreamsInfo stre
public string CryptoGetTextPassword()
{
if (password == null)
throw new SevenZipException("No password provided for encrypted data.");
throw new SevenZipPasswordRequiredException();
return password;
}
#endregion Public Methods (Interfaces)
Expand Down
26 changes: 26 additions & 0 deletions tiny7z/ToDo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Tiny7z

## TO DO LIST

- [ ] Allow per-file (or files group) compression settings (solid/non solid)
- [ ] Allow compressing in different coders (LZMA2, etc.)

## DONE

- [x] Replace digests with arrays of CRCs (improved Digests instead)
- [x] When SubStreamsInfo exists, fields have to be properly filled/guessed from other fields
- [x] When writing SubStreamsInfo, I have to undo these guesses to write them
- [x] Add constants for hard-coded values
- [x] Compressed header
- [x] Replace clunky bool vectors with adapted vectors with data used
- [x] Compress one file
- [x] Ensure MultiFileStream.Source cleanup
- [x] Better extract/compress interface
- [x] Add BCJ and BCJ2 filters
- [x] Add multiple coders per folder support for decompression
- [x] Add progress report for compression and decompression
- [x] Add AES password handling to enable decryption
- [x] Fully implement ProgressDelegate calls with file details
- [x] Implement access protection with internal where appropriate
- [x] Ensure no duplicate files when not "preserving directory structure" (handle overwriting per file at least)
- [x] Better tracing
4 changes: 4 additions & 0 deletions tiny7zTool/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>
111 changes: 111 additions & 0 deletions tiny7zTool/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCompression" type="xs:boolean">
<xs:annotation>
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCleanup" type="xs:boolean">
<xs:annotation>
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
Loading

0 comments on commit 1c45080

Please sign in to comment.