Creating a ZIP Extractor

I want to create a zip extractor for the plugins that I create for asp.net sites. I want the client to be able to run the extractor, and the files are placed in the correct folders that I specify. Are there any tools for this? I'm not sure how to do this, thanks

+3
source share
2 answers

DotNetZip is a library that allows managed code applications to read or write zip files. One thing he lets you do is create a self-extracting archive (SFX).

In C #, the code for creating an SFX archive with DotNetZip is as follows:

using (ZipFile zip1 = new ZipFile())
{
    // zip up a directory
    zip1.AddDirectory("C:\\project1\\datafiles", "data");
    zip1.Comment = "This will be embedded into a self-extracting exe";
    zip1.AddEntry("Readme.txt", "This is content for a 'Readme' file that will appear in the zip.");
    zip1.SaveSelfExtractor("archive.exe", SelfExtractorFlavor.WinFormsApplication);
}

, ZIP . - . ( 7 , )

EXE .NET Framework 2.0 , .

SFX/EXE Zip , WinZip Zip, Windows Explorer " ".

SFX ,

  • WinZip AES - , .
  • ZIP64 .
  • Unicode, ~ ASCII.
  • , ..

DotNetZip SFX: WinForms. WinForms - . , :

alt text

( ).


SFX, :

  • ( , )
  • execute on unpack. .
  • Win32 SFX EXE
  • , , ,% USERPROFILE%.
  • "" , , , , , WinForms. , - SFX .

SFX DotNetZip.


SFX, UI + . , WPF . : , SFX, - EXE (WinForms, WPF ) , , , Zip , VB :

Public Shared Function Main(ByVal args As String()) As Integer
    Dim sfxStub As String = "my-sfx-stub.exe"
    Dim outputFile As String = "my-sfx-archive.exe"
    Dim directoryToZip As String = "c:\directory\to\ZIP"
    Dim buffer As Byte() = New Byte(4000){}
    Dim n As Integer = 1
    Using output As System.IO.Stream = File.Open(outputFile, FileMode.Create)
        '' copy the contents of the sfx stub to the output stream
        Using input As System.IO.Stream = File.Open(sfxStub, FileMode.Open)
            While n <> 0
                n = input.Read(buffer, 0, buffer.Length)
                If n <> 0 Then
                    output.Write(buffer, 0, n)
                End If
            End While
        End Using
        '' now save the zip file to the same stream
        Using zp As New ZipFile
            zp.AddFiles(Directory.GetFiles(directoryToZip), False, "")
            zp.Save(output)
        End Using
    End Using
End Function

, , EXE , ZIP . EXE , . my-sfx-stub.exe :

Dim a As Assembly = Assembly.GetExecutingAssembly
Try
    '' read myself as a zip file
    Using zip As ZipFile = ZipFile.Read(a.Location)
        Dim entry As ZipEntry
        For Each entry in zip
            '' extract here, or add to a listBox, etc. 
            '' listBox1.Items.Add(entry.FileName)
        Next
    End Using
Catch
    MessageBox.Show("-No embedded zip file.-")
End Try

SFX, , DotNetZip DLL. EXE , DLL, ILMerge DLL- DotNetZip AssemblyResolver .

, DotNetZip.

+10

Source: https://habr.com/ru/post/1720298/


All Articles