hit counter for tumblr
Real Time Web Analytics

purefractalsolutions.com

pfszipxp simple archiver

Updated: 2011-10-07 15:17:27
If you found mistake, simply select it
and press Control+Enter

PFSZIPXP is a simple archiver utility, that demonstrates usage of Windows ZIPFLDR.DLL.

Overview

Sometimes we need to make zip archive programmatically, fast, "on the knee", without using any third-party libraries. Under Windows XP or later, we can do it using native system libraries. Detailed description of this method presented here. In this note we present simple archiver, PFSZIPXP.EXE, based on that technology. Command line syntax is similar as that is in popular archivers, and listed below.
[-]
Usage: pfszip <command> archive.zip [files]
<command>
a: Add files to archive
u: Update files to archive
Currently, only add files to archive and update files in archive are implemented, but we are planning to add more functionality later.

Source code of executable main module listed below.
[-]
#if !defined(_INC_STDIO) && !defined(_STDIO_H_) && !defined(_STDIO_H)
    #include <stdio.h>
#endif

#if !defined(_INC_STDLIB) && !defined(_STDLIB_H_) && !defined(_STDLIB_H)
    #include <stdlib.h>
#endif

#if !defined(_VECTOR_) && !defined(_STLP_VECTOR) && !defined(__STD_VECTOR__) && !defined(_CPP_VECTOR) && !defined(_GLIBCXX_VECTOR)
    #include <vector>
#endif

#if !defined(_STRING_) && !defined(_STLP_STRING) && !defined(__STD_STRING) && !defined(_CPP_STRING) && !defined(_GLIBCXX_STRING)
    #include <string>
#endif


#include "../clbsav/apizip.h"

void printHelp()
{
 printf( "Usage: pfszip <command> archive.zip [files]\n" );
 printf( "<command>\n" );
 printf( "a: Add files to archive\n" );
 printf( "u: Update files to archive\n" );
/*
 Not currently implemented
 printf( "e: Extract files from archive (without using directory names)\n" );
 printf( "l: List contents of archive\n" );
 printf( "x: eXtract files with full paths\n" );
  u: Update files to archive
*/
 //printf( "\n" );
}

#define PFSZIPXP_CMD_NONE        0
#define PFSZIPXP_CMD_ADD         1
#define PFSZIPXP_CMD_UPDATE      2

::std::string                     archiveName;
::std::vector< ::std::string >    fileToBeZipped; // or unzipped
int                               cmd = PFSZIPXP_CMD_NONE;

#define ERREXIT(msg,code) do { fprintf( stderr, "%s\n", msg ); printHelp(); return code; } while(0)

struct CPrintProgress
{
const char *prefix;
CPrintProgress(const char *p) : prefix(p) {}
bool operator()( const std::string &filename ) const 
{
 printf("%s: %s\n", prefix, filename.c_str());
 return true;
}
};

struct CPrintError
{
const char *prefix;
CPrintError(const char *p) : prefix(p) {}
bool operator()( const std::string &filename ) const 
{
 printf("! %s '%s' error\n", prefix, filename.c_str());
 return true;
}
};


int main(int argc, char* argv[])
   {
    int argi=1;
    if (argi>=argc) ERREXIT("no command specified", 2);

    const char *pOpt = argv[argi++];

    switch(*pOpt)
       {
        case 'a': cmd = PFSZIPXP_CMD_ADD;
                break;
        case 'u': cmd = PFSZIPXP_CMD_UPDATE;
                break;
        default :
                ERREXIT("unknown command", 3);
       }

    if (argi>=argc) ERREXIT("no archive file name specified", 2);
    archiveName = argv[argi++];

    for(; argi!=argc; ++argi)
       {
        const char *pOpt = argv[argi];
        if (*pOpt=='-' || *pOpt=='/') 
           {
            ++pOpt;
            /*
            if (*pOpt=='a')
               {
                cmd = PFSZIPXP_CMD_ADD;
               }
            */
            /*
            else if (*pOpt=='z')
               {
                createZip = true;
               }
            */
           }
        else
           {
            fileToBeZipped.push_back(pOpt);
           }
       }


    switch(cmd)
       {
        case PFSZIPXP_CMD_ADD:  
        case PFSZIPXP_CMD_UPDATE:
                if (fileToBeZipped.empty())
                   ERREXIT("no files to be archived taken", 2);
                addFilesToZipFolder(archiveName, fileToBeZipped, cmd==PFSZIPXP_CMD_ADD, CPrintProgress("Adding"), CPrintError("Adding") );
                break;
       }
    
    return 0;
   }



List of the files to download
Name Last modified Size Hash MD5/SHA1
pfszipxp.exe 2011-09-30 172.0 KB 7a83c6fdce5ae63aee3160b8c08a1cee / 54428495c0afbf5c7d05f912cad3c6d10d70df34
pfszipxp.zip 2011-09-30 85.7 KB 78f71b8a8e01a4fe65fe220dda14f5a9 / 14c7d38a350faba421fef84e9d565e85ad554db3