Skip to content

Commit f203cf5

Browse files
committed
Samples Cleanup
* Rename directories that each project is in * Create sample program for checksums
1 parent 4816184 commit f203cf5

25 files changed

Lines changed: 428 additions & 123 deletions

ICSharpCode.SharpZipLib.Samples/Samples.sln

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,24 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreateZipFile", "cs\CreateZ
3737
EndProject
3838
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FastZip", "cs\FastZip\FastZip.csproj", "{61BE8DBC-149A-4564-B891-9EEA4A09ED12}"
3939
EndProject
40-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cmd_BZip2", "cs\minibzip2\Cmd_BZip2.csproj", "{7520CE0B-F1D4-4148-8427-BB03669D7672}"
41-
EndProject
42-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cmd_GZip", "cs\minigzip\Cmd_GZip.csproj", "{301EF496-ED72-4448-A98E-A60D6BF6E0AE}"
43-
EndProject
4440
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sz", "cs\sz\sz.csproj", "{CE0CEA62-CC91-4D17-BC57-A5FCACCA6A1F}"
4541
EndProject
46-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tar", "cs\tar\Tar.csproj", "{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0}"
47-
EndProject
4842
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "zf", "cs\zf\zf.csproj", "{90E83588-261C-45A3-964F-4B707357D437}"
4943
EndProject
50-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cmd_ZipInfo", "cs\zipfiletest\Cmd_ZipInfo.csproj", "{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02}"
51-
EndProject
5244
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "unzipfile", "cs\unzipfile\unzipfile.csproj", "{DE6AA83B-1EFA-41B0-85D9-49DA1B0202BC}"
5345
EndProject
5446
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "viewzipfile", "cs\viewzipfile\viewzipfile.csproj", "{F356B460-0DEA-4F7D-9CD8-7475B9BEC1F7}"
5547
EndProject
48+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cmd_BZip2", "cs\Cmd_BZip2\Cmd_BZip2.csproj", "{7520CE0B-F1D4-4148-8427-BB03669D7672}"
49+
EndProject
50+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cmd_GZip", "cs\Cmd_GZip\Cmd_GZip.csproj", "{301EF496-ED72-4448-A98E-A60D6BF6E0AE}"
51+
EndProject
52+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cmd_Tar", "cs\Cmd_Tar\Cmd_Tar.csproj", "{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0}"
53+
EndProject
54+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cmd_ZipInfo", "cs\Cmd_ZipInfo\Cmd_ZipInfo.csproj", "{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02}"
55+
EndProject
56+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cmd_Checksum", "cs\Cmd_Checksum\Cmd_Checksum.csproj", "{82724A84-3399-4C27-91D2-2B2629B9E3F6}"
57+
EndProject
5658
Global
5759
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5860
Debug|Any CPU = Debug|Any CPU
@@ -93,30 +95,14 @@ Global
9395
{61BE8DBC-149A-4564-B891-9EEA4A09ED12}.Debug|Any CPU.Build.0 = Debug|Any CPU
9496
{61BE8DBC-149A-4564-B891-9EEA4A09ED12}.Release|Any CPU.ActiveCfg = Release|Any CPU
9597
{61BE8DBC-149A-4564-B891-9EEA4A09ED12}.Release|Any CPU.Build.0 = Release|Any CPU
96-
{7520CE0B-F1D4-4148-8427-BB03669D7672}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
97-
{7520CE0B-F1D4-4148-8427-BB03669D7672}.Debug|Any CPU.Build.0 = Debug|Any CPU
98-
{7520CE0B-F1D4-4148-8427-BB03669D7672}.Release|Any CPU.ActiveCfg = Release|Any CPU
99-
{7520CE0B-F1D4-4148-8427-BB03669D7672}.Release|Any CPU.Build.0 = Release|Any CPU
100-
{301EF496-ED72-4448-A98E-A60D6BF6E0AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
101-
{301EF496-ED72-4448-A98E-A60D6BF6E0AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
102-
{301EF496-ED72-4448-A98E-A60D6BF6E0AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
103-
{301EF496-ED72-4448-A98E-A60D6BF6E0AE}.Release|Any CPU.Build.0 = Release|Any CPU
10498
{CE0CEA62-CC91-4D17-BC57-A5FCACCA6A1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10599
{CE0CEA62-CC91-4D17-BC57-A5FCACCA6A1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
106100
{CE0CEA62-CC91-4D17-BC57-A5FCACCA6A1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
107101
{CE0CEA62-CC91-4D17-BC57-A5FCACCA6A1F}.Release|Any CPU.Build.0 = Release|Any CPU
108-
{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
109-
{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
110-
{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
111-
{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0}.Release|Any CPU.Build.0 = Release|Any CPU
112102
{90E83588-261C-45A3-964F-4B707357D437}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
113103
{90E83588-261C-45A3-964F-4B707357D437}.Debug|Any CPU.Build.0 = Debug|Any CPU
114104
{90E83588-261C-45A3-964F-4B707357D437}.Release|Any CPU.ActiveCfg = Release|Any CPU
115105
{90E83588-261C-45A3-964F-4B707357D437}.Release|Any CPU.Build.0 = Release|Any CPU
116-
{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
117-
{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02}.Debug|Any CPU.Build.0 = Debug|Any CPU
118-
{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02}.Release|Any CPU.ActiveCfg = Release|Any CPU
119-
{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02}.Release|Any CPU.Build.0 = Release|Any CPU
120106
{DE6AA83B-1EFA-41B0-85D9-49DA1B0202BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
121107
{DE6AA83B-1EFA-41B0-85D9-49DA1B0202BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
122108
{DE6AA83B-1EFA-41B0-85D9-49DA1B0202BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -125,6 +111,26 @@ Global
125111
{F356B460-0DEA-4F7D-9CD8-7475B9BEC1F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
126112
{F356B460-0DEA-4F7D-9CD8-7475B9BEC1F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
127113
{F356B460-0DEA-4F7D-9CD8-7475B9BEC1F7}.Release|Any CPU.Build.0 = Release|Any CPU
114+
{7520CE0B-F1D4-4148-8427-BB03669D7672}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
115+
{7520CE0B-F1D4-4148-8427-BB03669D7672}.Debug|Any CPU.Build.0 = Debug|Any CPU
116+
{7520CE0B-F1D4-4148-8427-BB03669D7672}.Release|Any CPU.ActiveCfg = Release|Any CPU
117+
{7520CE0B-F1D4-4148-8427-BB03669D7672}.Release|Any CPU.Build.0 = Release|Any CPU
118+
{301EF496-ED72-4448-A98E-A60D6BF6E0AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
119+
{301EF496-ED72-4448-A98E-A60D6BF6E0AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
120+
{301EF496-ED72-4448-A98E-A60D6BF6E0AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
121+
{301EF496-ED72-4448-A98E-A60D6BF6E0AE}.Release|Any CPU.Build.0 = Release|Any CPU
122+
{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
123+
{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
124+
{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
125+
{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0}.Release|Any CPU.Build.0 = Release|Any CPU
126+
{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
127+
{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02}.Debug|Any CPU.Build.0 = Debug|Any CPU
128+
{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02}.Release|Any CPU.ActiveCfg = Release|Any CPU
129+
{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02}.Release|Any CPU.Build.0 = Release|Any CPU
130+
{82724A84-3399-4C27-91D2-2B2629B9E3F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
131+
{82724A84-3399-4C27-91D2-2B2629B9E3F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
132+
{82724A84-3399-4C27-91D2-2B2629B9E3F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
133+
{82724A84-3399-4C27-91D2-2B2629B9E3F6}.Release|Any CPU.Build.0 = Release|Any CPU
128134
EndGlobalSection
129135
GlobalSection(SolutionProperties) = preSolution
130136
HideSolutionNode = FALSE
@@ -137,13 +143,14 @@ Global
137143
{2B42AA12-DD23-4EB8-A1CD-5D0F4B772895} = {F2D07126-17F2-4EBE-910D-B3838DA7C6D3}
138144
{DF63551E-BB6C-4A8D-9B01-DB94F721E74A} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
139145
{61BE8DBC-149A-4564-B891-9EEA4A09ED12} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
140-
{7520CE0B-F1D4-4148-8427-BB03669D7672} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
141-
{301EF496-ED72-4448-A98E-A60D6BF6E0AE} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
142146
{CE0CEA62-CC91-4D17-BC57-A5FCACCA6A1F} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
143-
{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
144147
{90E83588-261C-45A3-964F-4B707357D437} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
145-
{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
146148
{DE6AA83B-1EFA-41B0-85D9-49DA1B0202BC} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
147149
{F356B460-0DEA-4F7D-9CD8-7475B9BEC1F7} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
150+
{7520CE0B-F1D4-4148-8427-BB03669D7672} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
151+
{301EF496-ED72-4448-A98E-A60D6BF6E0AE} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
152+
{12C2AD0C-B815-426D-AFF1-7787C2DCA0F0} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
153+
{4C2CF0B1-FA7B-4FB6-83BA-24A9549AAB02} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
154+
{82724A84-3399-4C27-91D2-2B2629B9E3F6} = {07E37AC9-4F01-4D1D-B5CB-6524CA36D22A}
148155
EndGlobalSection
149156
EndGlobal

ICSharpCode.SharpZipLib.Samples/cs/minibzip2/AssemblyInfo.cs renamed to ICSharpCode.SharpZipLib.Samples/cs/Cmd_BZip2/AssemblyInfo.cs

File renamed without changes.

ICSharpCode.SharpZipLib.Samples/cs/minibzip2/Cmd_BZip2.cs renamed to ICSharpCode.SharpZipLib.Samples/cs/Cmd_BZip2/Cmd_BZip2.cs

File renamed without changes.

ICSharpCode.SharpZipLib.Samples/cs/minibzip2/Cmd_BZip2.csproj renamed to ICSharpCode.SharpZipLib.Samples/cs/Cmd_BZip2/Cmd_BZip2.csproj

File renamed without changes.

ICSharpCode.SharpZipLib.Samples/cs/minibzip2/app.config renamed to ICSharpCode.SharpZipLib.Samples/cs/Cmd_BZip2/app.config

File renamed without changes.

ICSharpCode.SharpZipLib.Samples/cs/minibzip2/readme.txt renamed to ICSharpCode.SharpZipLib.Samples/cs/Cmd_BZip2/readme.txt

File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Reflection;
2+
3+
[assembly: AssemblyTitle("Cmd_Crc")]
4+
[assembly: AssemblyDescription("file checksum generator")]
5+
[assembly: AssemblyCulture("")]
6+
7+
[assembly: AssemblyDelaySign(false)]
8+
[assembly: AssemblyKeyFile("")]
9+
[assembly: AssemblyKeyName("")]
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
// SharpZipLib samples
2+
// Copyright © 2000-2016 AlphaSierraPapa for the SharpZipLib Team
3+
// All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without modification, are
6+
// permitted provided that the following conditions are met:
7+
//
8+
// - Redistributions of source code must retain the above copyright notice, this list
9+
// of conditions and the following disclaimer.
10+
//
11+
// - Redistributions in binary form must reproduce the above copyright notice, this list
12+
// of conditions and the following disclaimer in the documentation and/or other materials
13+
// provided with the distribution.
14+
//
15+
// - Neither the name of the SharpDevelop team nor the names of its contributors may be used to
16+
// endorse or promote products derived from this software without specific prior written
17+
// permission.
18+
//
19+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &AS IS& AND ANY EXPRESS
20+
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21+
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25+
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26+
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
using System;
29+
using System.IO;
30+
31+
using ICSharpCode.SharpZipLib.Checksums;
32+
33+
class Cmd_Crc
34+
{
35+
static void ShowHelp()
36+
{
37+
Console.Error.WriteLine("Compress or uncompress FILEs (by default, compress FILES in-place).");
38+
Console.Error.WriteLine("Version {0} using SharpZipLib {1}",
39+
typeof(Cmd_Crc).Assembly.GetName().Version,
40+
typeof(IChecksum).Assembly.GetName().Version);
41+
Console.Error.WriteLine("");
42+
Console.Error.WriteLine("Mandatory arguments to long options are mandatory for short options too.");
43+
Console.Error.WriteLine("");
44+
Console.Error.WriteLine(" -a, --adler decompress");
45+
Console.Error.WriteLine(" -b, --bzip2 give this help");
46+
Console.Error.WriteLine(" -c, --crc32 compress");
47+
Console.Error.WriteLine(" -1, --fast compress faster");
48+
Console.Error.WriteLine(" -9, --best compress better");
49+
}
50+
51+
#region Command parsing
52+
enum Command
53+
{
54+
Nothing,
55+
Help,
56+
Adler,
57+
BZip2,
58+
Crc32,
59+
Stop
60+
}
61+
62+
class ArgumentParser
63+
{
64+
public ArgumentParser(string[] args)
65+
{
66+
foreach (string argument in args) {
67+
switch (argument) {
68+
case "-?": // for backwards compatibility
69+
case "-h":
70+
case "--help":
71+
SetCommand(Command.Help);
72+
break;
73+
case "--adler32":
74+
SetCommand(Command.Adler);
75+
break;
76+
case "--bzip2":
77+
SetCommand(Command.BZip2);
78+
break;
79+
case "--crc32":
80+
SetCommand(Command.Crc32);
81+
break;
82+
default:
83+
if (argument[0] == '-') {
84+
Console.Error.WriteLine("Unknown argument {0}", argument);
85+
command_ = Command.Stop;
86+
} else if (file_ == null) {
87+
file_ = argument;
88+
89+
if (!System.IO.File.Exists(file_)) {
90+
Console.Error.WriteLine("File not found '{0}'", file_);
91+
command_ = Command.Stop;
92+
}
93+
} else {
94+
Console.Error.WriteLine("File has already been specified");
95+
command_ = Command.Stop;
96+
}
97+
break;
98+
}
99+
}
100+
101+
if (command_ == Command.Nothing) {
102+
if (file_ == null) {
103+
command_ = Command.Help;
104+
} else {
105+
command_ = Command.Crc32;
106+
}
107+
}
108+
}
109+
110+
void SetCommand(Command command)
111+
{
112+
if ((command_ != Command.Nothing) && (command_ != Command.Stop)) {
113+
Console.Error.WriteLine("Command already specified");
114+
command_ = Command.Stop;
115+
} else {
116+
command_ = command;
117+
}
118+
}
119+
120+
public string Source
121+
{
122+
get { return file_; }
123+
}
124+
125+
public Command Command
126+
{
127+
get { return command_; }
128+
}
129+
130+
#region Instance Fields
131+
Command command_ = Command.Nothing;
132+
string file_;
133+
#endregion
134+
}
135+
#endregion
136+
137+
138+
public static int Main(string[] args)
139+
{
140+
if (args.Length == 0) {
141+
ShowHelp();
142+
return 1;
143+
}
144+
145+
if (!File.Exists(args[0])) {
146+
Console.Error.WriteLine("Cannot find file {0}", args[0]);
147+
ShowHelp();
148+
return 1;
149+
}
150+
151+
var parser = new ArgumentParser(args);
152+
153+
using (FileStream checksumStream = File.OpenRead(args[0])) {
154+
155+
byte[] buffer = new byte[4096];
156+
int bytesRead;
157+
158+
switch (parser.Command) {
159+
case Command.Help:
160+
ShowHelp();
161+
break;
162+
163+
case Command.Crc32:
164+
var currentCrc = new Crc32();
165+
while ((bytesRead = checksumStream.Read(buffer, 0, buffer.Length)) > 0) {
166+
currentCrc.Update(buffer, 0, bytesRead);
167+
}
168+
Console.WriteLine("CRC32 for {0} is 0x{1:X2}", args[0], currentCrc.Value);
169+
break;
170+
171+
case Command.Adler:
172+
var currentAdler = new Adler32();
173+
while ((bytesRead = checksumStream.Read(buffer, 0, buffer.Length)) > 0) {
174+
currentAdler.Update(buffer, 0, bytesRead);
175+
}
176+
break;
177+
}
178+
}
179+
return 0;
180+
}
181+
}
182+

0 commit comments

Comments
 (0)