Skip to content

Commit 1c45080

Browse files
committed
prepare to call it a release (v0.2)
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
1 parent 7779e1d commit 1c45080

12 files changed

Lines changed: 289 additions & 53 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,4 @@ __pycache__/
261261
*.pyc
262262

263263
# CUSTOM ADDED
264-
ToDo.txt
264+

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ tiny7z is a native C# SevenZip 7zip .7z file format archive reader/writer
1414
- Support LZMA, LZMA2, PPMd decoders.
1515
- Support AES, BCJ and BCJ2 decoder filters.
1616

17+
## Releases
18+
19+
- v0.1 - First release, unofficial, lots of features missing, incomplete test app
20+
- v0.2 - First official release, command-line test app
21+
1722
## Current limitations
1823

1924
*They are plenty unfortunately, but this library is still a huge step forward for compact .7z support in native C#*

tiny7z/Archive/Interfaces.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ UInt64 TotalSize
9191
/// <summary>
9292
/// Extractor proxy interface
9393
/// </summary>
94-
public interface IExtractor
94+
public interface IExtractor : IDisposable
9595
{
9696
/// <summary>
9797
/// List of files contained in the opened archive.
@@ -208,7 +208,7 @@ bool SkipExistingFiles
208208
/// <summary>
209209
/// Compressor proxy interface
210210
/// </summary>
211-
public interface ICompressor
211+
public interface ICompressor : IDisposable
212212
{
213213
/// <summary>
214214
/// List of files in the archive.

tiny7z/Archive/SevenZip/SevenZipCompressor.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ public bool Solid
4141
#endregion Public Properties
4242

4343
#region Public Methods
44+
public void Dispose() // IDisposable
45+
{
46+
if (this.stream != null && this.header != null)
47+
{
48+
Finalize();
49+
}
50+
this.stream = null;
51+
this.header = null;
52+
}
53+
4454
public ICompressor AddDirectory(string inputDirectory, string archiveDirectory = null, bool recursive = true)
4555
{
4656
Trace.TraceInformation($"Adding files from directory `{inputDirectory}`.");
@@ -146,6 +156,9 @@ public ICompressor AddFile(Stream stream, string archiveFileName, DateTime? time
146156

147157
public ICompressor Finalize()
148158
{
159+
if (this.stream == null || this.header == null)
160+
throw new SevenZipException("Compressor object has already been finalized.");
161+
149162
Trace.TraceInformation($"Compressing files.");
150163
Trace.Indent();
151164
try
@@ -189,6 +202,8 @@ public ICompressor Finalize()
189202
Trace.TraceInformation("Done compressing files.");
190203
}
191204

205+
this.stream = null;
206+
this.header = null;
192207
return this;
193208
}
194209
#endregion Public Methods

tiny7z/Archive/SevenZip/SevenZipException.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,27 @@
33

44
namespace pdj.tiny7z.Archive
55
{
6-
/// <summary>
7-
/// Base exception class for error handling
8-
/// </summary>
96
public class SevenZipException : Exception
107
{
118
internal SevenZipException(string message)
129
: base(message)
1310
{
1411
}
1512
}
13+
14+
public class SevenZipFileAlreadyExistsException : SevenZipException
15+
{
16+
internal SevenZipFileAlreadyExistsException(SevenZipArchiveFile file)
17+
: base($"File `{file.Name}` already exists.")
18+
{
19+
}
20+
}
21+
22+
public class SevenZipPasswordRequiredException : SevenZipException
23+
{
24+
internal SevenZipPasswordRequiredException()
25+
: base("No password provided. Encrypted stream requires password.")
26+
{
27+
}
28+
}
1629
}

tiny7z/Archive/SevenZip/SevenZipExtractor.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public bool SkipExistingFiles
5555
#endregion Public Properties
5656

5757
#region Public Methods
58+
public void Dispose() // IDisposable
59+
{
60+
Finalize();
61+
}
62+
5863
public void Dump()
5964
{
6065
// TODO
@@ -288,7 +293,6 @@ public IExtractor Finalize()
288293
{
289294
this.stream = null;
290295
this.header = null;
291-
this._Files = null;
292296
return this;
293297
}
294298
#endregion Public Methods
@@ -369,7 +373,7 @@ private bool preProcessFile(string outputDirectory, SevenZipArchiveFile file)
369373
else
370374
{
371375
if (!SkipExistingFiles)
372-
throw new IOException($"File `{file.Name}` already exists.");
376+
throw new SevenZipFileAlreadyExistsException(file);
373377
result = FeedbackResult.No;
374378
}
375379
}

tiny7z/Archive/SevenZip/SevenZipStreamsExtractor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal SevenZipStreamsExtractor(Stream stream, SevenZipHeader.StreamsInfo stre
2222
public string CryptoGetTextPassword()
2323
{
2424
if (password == null)
25-
throw new SevenZipException("No password provided for encrypted data.");
25+
throw new SevenZipPasswordRequiredException();
2626
return password;
2727
}
2828
#endregion Public Methods (Interfaces)

tiny7z/ToDo.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Tiny7z
2+
3+
## TO DO LIST
4+
5+
- [ ] Allow per-file (or files group) compression settings (solid/non solid)
6+
- [ ] Allow compressing in different coders (LZMA2, etc.)
7+
8+
## DONE
9+
10+
- [x] Replace digests with arrays of CRCs (improved Digests instead)
11+
- [x] When SubStreamsInfo exists, fields have to be properly filled/guessed from other fields
12+
- [x] When writing SubStreamsInfo, I have to undo these guesses to write them
13+
- [x] Add constants for hard-coded values
14+
- [x] Compressed header
15+
- [x] Replace clunky bool vectors with adapted vectors with data used
16+
- [x] Compress one file
17+
- [x] Ensure MultiFileStream.Source cleanup
18+
- [x] Better extract/compress interface
19+
- [x] Add BCJ and BCJ2 filters
20+
- [x] Add multiple coders per folder support for decompression
21+
- [x] Add progress report for compression and decompression
22+
- [x] Add AES password handling to enable decryption
23+
- [x] Fully implement ProgressDelegate calls with file details
24+
- [x] Implement access protection with internal where appropriate
25+
- [x] Ensure no duplicate files when not "preserving directory structure" (handle overwriting per file at least)
26+
- [x] Better tracing

tiny7zTool/FodyWeavers.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
3+
<Costura />
4+
</Weavers>

tiny7zTool/FodyWeavers.xsd

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
4+
<xs:element name="Weavers">
5+
<xs:complexType>
6+
<xs:all>
7+
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
8+
<xs:complexType>
9+
<xs:all>
10+
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
11+
<xs:annotation>
12+
<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>
13+
</xs:annotation>
14+
</xs:element>
15+
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
16+
<xs:annotation>
17+
<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>
18+
</xs:annotation>
19+
</xs:element>
20+
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
21+
<xs:annotation>
22+
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
23+
</xs:annotation>
24+
</xs:element>
25+
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
26+
<xs:annotation>
27+
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
28+
</xs:annotation>
29+
</xs:element>
30+
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
31+
<xs:annotation>
32+
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
33+
</xs:annotation>
34+
</xs:element>
35+
</xs:all>
36+
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
37+
<xs:annotation>
38+
<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>
39+
</xs:annotation>
40+
</xs:attribute>
41+
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
42+
<xs:annotation>
43+
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
44+
</xs:annotation>
45+
</xs:attribute>
46+
<xs:attribute name="DisableCompression" type="xs:boolean">
47+
<xs:annotation>
48+
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
49+
</xs:annotation>
50+
</xs:attribute>
51+
<xs:attribute name="DisableCleanup" type="xs:boolean">
52+
<xs:annotation>
53+
<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>
54+
</xs:annotation>
55+
</xs:attribute>
56+
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
57+
<xs:annotation>
58+
<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>
59+
</xs:annotation>
60+
</xs:attribute>
61+
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
62+
<xs:annotation>
63+
<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>
64+
</xs:annotation>
65+
</xs:attribute>
66+
<xs:attribute name="ExcludeAssemblies" type="xs:string">
67+
<xs:annotation>
68+
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
69+
</xs:annotation>
70+
</xs:attribute>
71+
<xs:attribute name="IncludeAssemblies" type="xs:string">
72+
<xs:annotation>
73+
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
74+
</xs:annotation>
75+
</xs:attribute>
76+
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
77+
<xs:annotation>
78+
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
79+
</xs:annotation>
80+
</xs:attribute>
81+
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
82+
<xs:annotation>
83+
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
84+
</xs:annotation>
85+
</xs:attribute>
86+
<xs:attribute name="PreloadOrder" type="xs:string">
87+
<xs:annotation>
88+
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
89+
</xs:annotation>
90+
</xs:attribute>
91+
</xs:complexType>
92+
</xs:element>
93+
</xs:all>
94+
<xs:attribute name="VerifyAssembly" type="xs:boolean">
95+
<xs:annotation>
96+
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
97+
</xs:annotation>
98+
</xs:attribute>
99+
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
100+
<xs:annotation>
101+
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
102+
</xs:annotation>
103+
</xs:attribute>
104+
<xs:attribute name="GenerateXsd" type="xs:boolean">
105+
<xs:annotation>
106+
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
107+
</xs:annotation>
108+
</xs:attribute>
109+
</xs:complexType>
110+
</xs:element>
111+
</xs:schema>

0 commit comments

Comments
 (0)