News:

Download Pelles C here: http://www.pellesc.se

Main Menu

LiteZip tests

Started by TimoVJL, Yesterday at 08:53:52 PM

Previous topic - Next topic

TimoVJL

LiteZip 2008 version tests with static libraries.

Check this too
https://www.wischik.com/lu/programmer/zip_utils.html
May the source be with you

Vortex

#1
Hi Timo,

Thanks for the static libraries. With the help of ChatGPT, here is an unzip sample :

// Dependencies required to build the project
// LiteUnzip.h and LiteUnzip.lib from LiteUnzip_WS2.zip
// https://forum.pellesc.de/index.php?msg=42339
// Sample code by ChatGPT

#include <windows.h>
#include <stdio.h>
#include "LiteUnzip.h"

int main(void)
{
    HUNZIP hz;
    ZIPENTRY ze;
    DWORD numitems, i;

    // Open ZIP
    if (UnzipOpenFileA(&hz, "test.zip", 0) != 0)
    {
        printf("Cannot open ZIP file\n");
        return 1;
    }

    // Get number of items
    ze.Index = (DWORD)-1;
    if (UnzipGetItemA(hz, &ze) != 0)
    {
        printf("Cannot get ZIP info\n");
        UnzipClose(hz);
        return 1;
    }

    numitems = ze.Index;
    printf("Files in archive: %lu\n", numitems);

    // Extract loop
    for (i = 0; i < numitems; i++)
    {
        ze.Index = i;

        if (UnzipGetItemA(hz, &ze) != 0)
        {
            printf("Error reading item %lu\n", i);
            continue;
        }

        printf("Extracting: %s\n", ze.Name);

        if (UnzipItemToFileA(hz, ze.Name, &ze) != 0)
        {
            printf("Failed to extract %s\n", ze.Name);
        }
    }

    UnzipClose(hz);
    return 0;
}
Code it... That's all...

Vortex

Here is a zip sample :

// Source code by ChatGPT

#include <windows.h>
#include <stdio.h>
#include "LiteZip.h"

void AddFolder(HZIP hz, const char *basePath, const char *relPath)
{
    char search[MAX_PATH];
    WIN32_FIND_DATAA fd;
    HANDLE hFind;

    sprintf(search, "%s\\%s\\*", basePath, relPath);

    hFind = FindFirstFileA(search, &fd);
    if (hFind == INVALID_HANDLE_VALUE)
        return;

    do
    {
        if (strcmp(fd.cFileName, ".") == 0 ||
            strcmp(fd.cFileName, "..") == 0)
            continue;

        char fullPath[MAX_PATH];
        char zipPath[MAX_PATH];

        sprintf(fullPath, "%s\\%s\\%s", basePath, relPath, fd.cFileName);

        if (relPath[0])
            sprintf(zipPath, "%s\\%s", relPath, fd.cFileName);
        else
            sprintf(zipPath, "%s", fd.cFileName);

        if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            AddFolder(hz, basePath, zipPath);
        }
        else
        {
            printf("Adding: %s\n", zipPath);
            ZipAddFileA(hz, zipPath, fullPath);
        }

    } while (FindNextFileA(hFind, &fd));

    FindClose(hFind);
}

int main(void)
{
    HZIP hz;

    if (ZipCreateFileA(&hz, "archive.zip", 0) != 0)
    {
        printf("Cannot create ZIP\n");
        return 1;
    }

    AddFolder(hz, "C:\\testfolder", "");

    ZipClose(hz);
    printf("Done.\n");
    return 0;
}
Code it... That's all...