Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding ICSharp sharp zip library. It's loaded as a resource at runtime

  • Loading branch information...
commit 4215402b5d49a01444831df68bab66c3587ecd22 1 parent 8363956
@philc authored
View
7 InstallPad.csproj
@@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -65,7 +66,7 @@
<DependentUpon>AppListErrorDialog.cs</DependentUpon>
</Compile>
<Compile Include="src\ControlList.cs">
- <SubType>UserControl</SubType>
+ <SubType>Component</SubType>
</Compile>
<Compile Include="src\ControlList.Designer.cs">
<DependentUpon>ControlList.cs</DependentUpon>
@@ -144,11 +145,15 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="src\RemoteVersionChecker.cs" />
+ <Compile Include="src\Zip.cs" />
</ItemGroup>
<ItemGroup>
<None Include="data\program logo.jpg" />
<None Include="data\program logo border.jpg" />
</ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="lib\ICSharpCode.SharpZipLib.dll" />
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
BIN  lib/ICSharpCode.SharpZipLib.dll
Binary file not shown
View
11 src/Program.cs
@@ -12,7 +12,8 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
-
+using System.IO;
+using System.Reflection;
namespace InstallPad
{
/// <summary>
@@ -24,15 +25,21 @@ static class Program
/// The main entry point for the application.
/// </summary>
[STAThread]
- static void Main(string [] args)
+ static void Main(string[] args)
{
+
+ //View("hey.zip");
+ Zip.Instance.ExtractZip(
+ @"C:\test\anthem.zip", @"c:\test\");
ProcessArguments(args);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new InstallPad());
}
+
private static void ProcessArguments(string[] args)
{
+
if (args.Length <= 0)
return;
View
109 src/Zip.cs
@@ -0,0 +1,109 @@
+//
+// Author: Phil Crosby
+//
+
+// Copyright (C) 2006 Phil Crosby
+// Permission is granted to use, copy, modify, and merge copies
+// of this software for personal use. Permission is not granted
+// to use or change this software for commercial use or commercial
+// redistribution. Permission is not granted to use, modify or
+// distribute this software internally within a corporation.
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using System.Reflection;
+namespace InstallPad
+{
+ /// <summary>
+ /// Zip utilities. Access through Zip.Instance
+ /// </summary>
+ class Zip
+ {
+ //
+ private static string ASSEMBLY_RESOURCE_STRING = "InstallPad.lib.ICSharpCode.SharpZipLib.dll";
+
+ // Reflected types
+ private Assembly zipAssembly = null;
+ Type fastZipType = null;
+ object fastZipInstance;
+
+ private static Zip instance=null;
+
+ /// <summary>
+ /// Singleton
+ /// </summary>
+ public static Zip Instance
+ {
+ get
+ {
+ if (instance == null)
+ instance = new Zip();
+ return instance;
+ }
+ }
+
+ private Zip()
+ {
+ // Load types
+ this.zipAssembly = LoadAssemblyFromResource(ASSEMBLY_RESOURCE_STRING);
+
+ fastZipType = zipAssembly.GetType("ICSharpCode.SharpZipLib.Zip.FastZip");
+ fastZipInstance = Activator.CreateInstance(fastZipType);
+ }
+
+ public void ExtractZip(string zipFile, string extractTo)
+ {
+ // Signature of what we're calling
+ /*
+ * public void ExtractZip(
+ * string zipFileName,
+ * string targetDirectory,
+ * string fileFilter)
+ */
+
+ try
+ {
+ fastZipType.InvokeMember("ExtractZip", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance,
+ null, fastZipInstance, new object[]{
+ zipFile,extractTo,""});
+ }
+ catch (Exception e)
+ {
+ // do a swtich statement on the inner exception, to handle e.g. file not found
+ }
+ }
+
+ /// <summary>
+ /// Loads an assembly from a resource string.
+ /// </summary>
+ /// <param name="assemblyResourceString"></param>
+ /// <returns></returns>
+ private static Assembly LoadAssemblyFromResource(string assemblyResourceString)
+ {
+ Assembly a;
+ Type fastZip;
+ using (Stream stream = Assembly.GetExecutingAssembly().
+ GetManifestResourceStream(assemblyResourceString))
+ {
+ // get the length
+ int length = (int)stream.Length;
+
+ // set up the buffer
+ byte[] buffer = new byte[length];
+
+ // move the contents of the stream to the buffer
+ stream.Read(buffer, 0, length);
+
+ // load the resource bytes into an assembly
+ a = Assembly.Load(buffer);
+
+ // get a specific type out of the assembly to use
+ fastZip = a.GetType("ICSharpCode.SharpZipLib.Zip.FastZip");
+ }
+ return a;
+ }
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.