Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Defines | Functions
fileunzip.cpp File Reference
#include "scconfig.h"
#include "fileunzip.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <utime.h>
#include <iostream>
#include "unzip.h"
#include <qdir.h>
#include "scpaths.h"

Go to the source code of this file.

Defines

#define CASESENSITIVITY   (0)
#define WRITEBUFFERSIZE   (8192)
#define MAXFILENAME   (256)

Functions

int do_extract_currentfile (unzFile uf, const int *popt_extract_without_path, int *popt_overwrite, const char *password)
int do_extract_onefile (unzFile uf, const QString &filename, int opt_extract_without_path, int opt_overwrite, const char *password)
FILE * openfile (const QString &filename, const QString &mode)
unzFile unzOpenFile (const QString &filename)
int mymkdir (const QString &dirname)
int makedir (const QString &newdir)
void change_file_date (const QString &filename, uLong dosdate, tm_unz tmu_date)

Define Documentation

#define CASESENSITIVITY   (0)

Definition at line 60 of file fileunzip.cpp.

#define MAXFILENAME   (256)

Definition at line 62 of file fileunzip.cpp.

#define WRITEBUFFERSIZE   (8192)

Definition at line 61 of file fileunzip.cpp.


Function Documentation

void change_file_date ( const QString &  filename,
uLong  dosdate,
tm_unz  tmu_date 
)

Definition at line 315 of file fileunzip.cpp.

{
       struct utimbuf ut;
       struct tm newdate;
       newdate.tm_sec = tmu_date.tm_sec;
       newdate.tm_min=tmu_date.tm_min;
       newdate.tm_hour=tmu_date.tm_hour;
       newdate.tm_mday=tmu_date.tm_mday;
       newdate.tm_mon=tmu_date.tm_mon;
       if (tmu_date.tm_year > 1900)
              newdate.tm_year=tmu_date.tm_year - 1900;
       else
              newdate.tm_year=tmu_date.tm_year ;
       newdate.tm_isdst=-1;

       ut.actime=ut.modtime=mktime(&newdate);
#if defined(_WIN32) && defined(HAVE_UNICODE)
       _wutime((const wchar_t*) filename.ucs2(), &ut);
#else
       QCString fname = filename.local8Bit();
       utime(fname.data(), &ut);
#endif
}

Here is the caller graph for this function:

int do_extract_currentfile ( unzFile  uf,
const int popt_extract_without_path,
int popt_overwrite,
const char *  password 
)

Definition at line 214 of file fileunzip.cpp.

{
       char  fn_inzip[256];
       QString filename_inzip;
       QString filename_withoutpath;
       int err=UNZ_OK;
       FILE *fout=NULL;
       void* buf;
       uInt size_buf;

       unz_file_info file_info;
       //uLong ratio=0;
       err = unzGetCurrentFileInfo(uf,&file_info,fn_inzip,sizeof(fn_inzip),NULL,0,NULL,0);

       if (err!=UNZ_OK)
              return err;

       size_buf = WRITEBUFFERSIZE;
       buf = (void*)malloc(size_buf);
       if (buf==NULL)
              return UNZ_INTERNALERROR;

       QChar p;
//     uint cIndex = 0;
       filename_inzip = QString::fromLocal8Bit(fn_inzip); 
       filename_withoutpath = filename_inzip;
       for (uint i = 0; i < filename_inzip.length(); i++)
       {
              p = filename_inzip[i];
              if( (p == '/') || (p =='\\'))
                     filename_withoutpath = filename_inzip.mid(i+1);
       }

       if (filename_withoutpath.isEmpty())
       {
              if ((*popt_extract_without_path)==0)
                     mymkdir(filename_inzip);
       }
       else
    {
              QString write_filename;
              int skip=0;

              if ((*popt_extract_without_path)==0)
                     write_filename = filename_inzip;
              else
                     write_filename = filename_withoutpath;
              
              err = unzOpenCurrentFilePassword(uf,password);

              if ((skip==0) && (err==UNZ_OK))
              {
                     fout = openfile(write_filename, "wb");
            /* some zipfile don't contain directory alone before file */
                     if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
                                                        (filename_withoutpath != filename_inzip))
                     {
                            uint len = filename_inzip.length() - filename_withoutpath.length() - 1;
                            QString write_dir = filename_inzip.left(len);
                            makedir(write_dir);
                            fout = openfile(write_filename, "wb");
                     }
              }

              if (fout!=NULL)
              {
                     do
                     {
                            err = unzReadCurrentFile(uf,buf,size_buf);
                            if (err<0)
                                   break;
                            if (err>0)
                                   if (fwrite(buf,err,1,fout)!=1)
                                   {
                                          err=UNZ_ERRNO;
                                          break;
                                   }
                     }
                     while (err>0);
                     if (fout)
                            fclose(fout);

                     if (err==0)
                            change_file_date(write_filename,file_info.dosDate,
                                                               file_info.tmu_date);
              }

              if (err==UNZ_OK)
                     err = unzCloseCurrentFile (uf);
              else
                     unzCloseCurrentFile(uf); /* don't lose the error */
       }

       free(buf);
       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int do_extract_onefile ( unzFile  uf,
const QString &  filename,
int  opt_extract_without_path,
int  opt_overwrite,
const char *  password 
)

Definition at line 199 of file fileunzip.cpp.

{
//    int err = UNZ_OK;
       QCString fname = filename.local8Bit();
    if (unzLocateFile(uf,fname.data(),CASESENSITIVITY)!=UNZ_OK)
        return 2;

    if (do_extract_currentfile(uf,&opt_extract_without_path,
                                      &opt_overwrite,
                                      password) == UNZ_OK)
        return 0;
    else
        return 1;
}

Here is the call graph for this function:

int makedir ( const QString &  newdir)

Definition at line 166 of file fileunzip.cpp.

{
       QChar p;
       QString buffer;
       int len = newdir.length();
       
       if (len <= 0)
              return 0;
       buffer = newdir;

       if (buffer.endsWith("/") || buffer.endsWith("\\"))
              buffer.left(len - 1);

       if (mymkdir(buffer) == 0)
              return 1;

       uint cIndex = 1;
       p = buffer[1];
       while (1)
       {
              QString tmpBuf;
              while(!p.isNull() && p != '\\' && p != '/')
                     p = buffer[cIndex++];
              tmpBuf = buffer.left(cIndex - 1);
              if ((mymkdir(tmpBuf) == -1) && (errno == ENOENT))
                     return 0;
              if (p.isNull())
                     break;
              p = buffer[++cIndex];
       }
       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mymkdir ( const QString &  dirname)

Definition at line 151 of file fileunzip.cpp.

{
    int ret=0;
#if defined(_WIN32) && defined(HAVE_UNICODE)
       ret = _wmkdir((const wchar_t*) dirname.ucs2());
#elif defined(_WIN32)
       QCString cdir = dirname.local8Bit();
    ret = _mkdir(cdir.data());
#else
       QCString cdir = dirname.local8Bit();
    ret = mkdir (cdir.data(), 0775);
#endif
    return ret;
}

Here is the caller graph for this function:

FILE * openfile ( const QString &  filename,
const QString &  mode 
)

Definition at line 107 of file fileunzip.cpp.

{
       FILE* fout = NULL;
#if defined(_WIN32) && defined(HAVE_UNICODE)
       fout = _wfopen((const wchar_t*) filename.ucs2(), (const wchar_t*) mode.ucs2());
#else
       QCString fname = filename.local8Bit();
       QCString fmode  = mode.local8Bit();
    fout = fopen(fname.data(), fmode.data());
#endif
       return fout;
}

Here is the caller graph for this function:

unzFile unzOpenFile ( const QString &  filename)

Definition at line 120 of file fileunzip.cpp.

{
       unzFile unz;
#if defined(_WIN32) && defined(HAVE_UNICODE)
       fill_fopen_filefunc(&file_api);
       file_api.zopen_file = fopen_filefunc_unicode;
       unz = unzOpen2((const char*)filename.ucs2(), &file_api); 
#else
       QCString fname(filename.local8Bit());
       unz = unzOpen(fname.data()); 
#endif
       return unz;
}

Here is the call graph for this function: