Archived Forum Post

Index of archived forum posts

Question:

Chilkat+OpenZIP self-extracting error

Aug 28 '13 at 18:19

So, I'm learning C++ and decided to try this out http://www.chilkatforum.com/questions/2354/how-to-write-a-self-extractor-for-the-windows-os . I made some minor changes in the code. The first program (which joins zip and exe) works fine, but when I try to run and unpack it, this happens:

ChilkatLog:
  OpenZip:
    DllDate: Aug 15 2013
    ChilkatVersion: 9.4.1.42
    UnlockPrefix: myUnlockCode
    Username: COMPUTERNAME:Myusername
    Architecture: Little Endian; 32-bit
    Language: Visual C++ 10.0
    VerboseLogging: 0
    hcCurDate: Wed, 28 Aug 2013 21:37:28 +0400
    hcExpire: 11/2013
    zipPath: C:\program.exe
    oemCodePage: 866
    numCentralDirEntries: 6
    szCentralDir: 557
    posCentralDir: 282294
    Did not find central file header signature.
    index: 0
    filePos: 282294
    Failed.
  --OpenZip
--ChilkatLog

What am I doing wrong? Thanks in advance :) This is the program that joins .zip and .exe together:

    #include <windows.h>
    #include <ckbytedata.h>
    #include <ckfileaccess.h>

    // This program appends a .zip to the end of a .exe
    // The .exe must be a multiple of 4 bytes in length.  If it is not, null bytes are
    // appended to make the size a multiple of 4.
    int main(int argc, char* argv[])
        {
        const char *exeFile = "C:/program.exe";

    CkFileAccess fac;
        int exeSize = fac.FileSize(exeFile);
        int nZeros = 4 - (exeSize % 4);
        if (nZeros < 4)
            {
            CkByteData zeros;
            zeros.appendCharN(0,nZeros);
            // Append the zeros to the .exe
            zeros.appendFile(exeFile);
            }

    // Append the .zip to the .exe
        CkByteData zipData;
        zipData.loadFile("c:/archive.zip");
        zipData.appendFile(exeFile);

    return 0;
    }

This is the program which extracts the archive attached to it:

    #include <windows.h>
    #include <direct.h>
    #include <stdio.h>
    #include <CkZip.h>

    int selfExtract(void)
    {
        char myExePath[1024];
        GetModuleFileName(0,myExePath,1024);

        CkZip zip;

        bool success = zip.UnlockComponent("myUnlockCode");
        if (!success)
        {
        printf("%s\n",zip.lastErrorText());
        return 1;
        }

        success = zip.OpenZip(myExePath);
        if (!success)
        {
        printf("%s\n",zip.lastErrorText());
        return 1;
        }

        _mkdir("C:/extract");
        int numUnzipped = zip.Unzip("C:/extract");
        if (numUnzipped < 0)
        {
        printf("%s\n",zip.lastErrorText());
        return 1;
        }

        zip.CloseZip();

        return 0;
     }

    int main(int argc, char* argv[])
    {
        return selfExtract();
    }

Answer

I'm suspecting this is a problem introduced with v9.4.1. Try the v9.4.0 build here:

http://www.chilkatsoft.com/download/chilkat-9.4.0-x86-vc10.zip

I'll test v9.4.1 and will fix the problem, assuming my hunch is correct.