Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 18912 → Rev 18913

/trunk/Scribus/scribus/unzip.c
File deleted
Property changes:
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Author Date Id Revision
\ No newline at end of property
Index: trunk/Scribus/scribus/unzip.h
===================================================================
--- trunk/Scribus/scribus/unzip.h (revision 18912)
+++ trunk/Scribus/scribus/unzip.h (nonexistent)
@@ -1,362 +0,0 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-/* unzip.h -- IO for uncompress .zip files using zlib
- Version 1.01, May 8th, 2004
-
- Copyright (C) 1998-2004 Gilles Vollant
-
- This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
- WinZip, InfoZip tools and compatible.
- Encryption and multi volume ZipFile (span) are not supported.
- Old compressions used by old PKZip 1.x are not supported
-
-
- I WAIT FEEDBACK at mail info@winimage.com
- Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
-
- Condition of use and distribution are the same than zlib :
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
-
-*/
-
-/* for more info about .ZIP format, see
- http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
- http://www.info-zip.org/pub/infozip/doc/
- PkWare has also a specification at :
- ftp://ftp.pkware.com/probdesc.zip
-*/
-
-#include "scconfig.h"
-
-#ifndef _unz_H
-#define _unz_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef _ZLIB_H
-#include "zlib.h"
-#endif
-
-#ifndef _ZLIBIOAPI_H
-#include "ioapi.h"
-#endif
-
-#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
-/* like the STRICT of WIN32, we define a pointer that cannot be converted
- from (void*) without cast */
-typedef struct TagunzFile__ { int unused; } unzFile__;
-typedef unzFile__ *unzFile;
-#else
-typedef voidp unzFile;
-#endif
-
-
-#define UNZ_OK (0)
-#define UNZ_END_OF_LIST_OF_FILE (-100)
-#define UNZ_ERRNO (Z_ERRNO)
-#define UNZ_EOF (0)
-#define UNZ_PARAMERROR (-102)
-#define UNZ_BADZIPFILE (-103)
-#define UNZ_INTERNALERROR (-104)
-#define UNZ_CRCERROR (-105)
-
-/* tm_unz contain date/time info */
-typedef struct tm_unz_s
-{
- uInt tm_sec; /* seconds after the minute - [0,59] */
- uInt tm_min; /* minutes after the hour - [0,59] */
- uInt tm_hour; /* hours since midnight - [0,23] */
- uInt tm_mday; /* day of the month - [1,31] */
- uInt tm_mon; /* months since January - [0,11] */
- uInt tm_year; /* years - [1980..2044] */
-} tm_unz;
-
-/* unz_global_info structure contain global data about the ZIPfile
- These data comes from the end of central dir */
-typedef struct unz_global_info_s
-{
- uLong number_entry; /* total number of entries in
- the central dir on this disk */
- uLong size_comment; /* size of the global comment of the zipfile */
-} unz_global_info;
-
-
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_info_s
-{
- uLong version; /* version made by 2 bytes */
- uLong version_needed; /* version needed to extract 2 bytes */
- uLong flag; /* general purpose bit flag 2 bytes */
- uLong compression_method; /* compression method 2 bytes */
- uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
- uLong crc; /* crc-32 4 bytes */
- uLong compressed_size; /* compressed size 4 bytes */
- uLong uncompressed_size; /* uncompressed size 4 bytes */
- uLong size_filename; /* filename length 2 bytes */
- uLong size_file_extra; /* extra field length 2 bytes */
- uLong size_file_comment; /* file comment length 2 bytes */
-
- uLong disk_num_start; /* disk number start 2 bytes */
- uLong internal_fa; /* internal file attributes 2 bytes */
- uLong external_fa; /* external file attributes 4 bytes */
-
- tm_unz tmu_date;
-} unz_file_info;
-
-extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
- const char* fileName2,
- int iCaseSensitivity));
-/*
- Compare two filename (fileName1,fileName2).
- If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
- If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
- or strcasecmp)
- If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
- (like 1 on Unix, 2 on Windows)
-*/
-
-
-extern unzFile ZEXPORT unzOpen OF((const char *path));
-/*
- Open a Zip file. path contain the full pathname (by example,
- on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
- "zlib/zlib113.zip".
- If the zipfile cannot be opened (file don't exist or in not valid), the
- return value is NULL.
- Else, the return value is a unzFile Handle, usable with other function
- of this unzip package.
-*/
-
-extern unzFile ZEXPORT unzOpen2 OF((const char *path,
- zlib_filefunc_def* pzlib_filefunc_def));
-/*
- Open a Zip file, like unzOpen, but provide a set of file low level API
- for read/write the zip file (see ioapi.h)
-*/
-
-extern int ZEXPORT unzClose OF((unzFile file));
-/*
- Close a ZipFile opened with unzipOpen.
- If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
- these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
- return UNZ_OK if there is no problem. */
-
-extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
- unz_global_info *pglobal_info));
-/*
- Write info about the ZipFile in the *pglobal_info structure.
- No preparation of the structure is needed
- return UNZ_OK if there is no problem. */
-
-
-extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
- char *szComment,
- uLong uSizeBuf));
-/*
- Get the global comment string of the ZipFile, in the szComment buffer.
- uSizeBuf is the size of the szComment buffer.
- return the number of byte copied or an error code <0
-*/
-
-
-/***************************************************************************/
-/* Unzip package allow you browse the directory of the zipfile */
-
-extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
-/*
- Set the current file of the zipfile to the first file.
- return UNZ_OK if there is no problem
-*/
-
-extern int ZEXPORT unzGoToNextFile OF((unzFile file));
-/*
- Set the current file of the zipfile to the next file.
- return UNZ_OK if there is no problem
- return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-*/
-
-extern int ZEXPORT unzLocateFile OF((unzFile file,
- const char *szFileName,
- int iCaseSensitivity));
-/*
- Try locate the file szFileName in the zipfile.
- For the iCaseSensitivity signification, see unzStringFileNameCompare
-
- return value :
- UNZ_OK if the file is found. It becomes the current file.
- UNZ_END_OF_LIST_OF_FILE if the file is not found
-*/
-
-
-/* ****************************************** */
-/* Ryan supplied functions */
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_pos_s
-{
- uLong pos_in_zip_directory; /* offset in zip file directory */
- uLong num_of_file; /* # of file */
-} unz_file_pos;
-
-extern int ZEXPORT unzGetFilePos(
- unzFile file,
- unz_file_pos* file_pos);
-
-extern int ZEXPORT unzGoToFilePos(
- unzFile file,
- unz_file_pos* file_pos);
-
-/* ****************************************** */
-
-extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
- unz_file_info *pfile_info,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize));
-/*
- Get Info about the current file
- if pfile_info!=NULL, the *pfile_info structure will contain somes info about
- the current file
- if szFileName!=NULL, the filemane string will be copied in szFileName
- (fileNameBufferSize is the size of the buffer)
- if extraField!=NULL, the extra field information will be copied in extraField
- (extraFieldBufferSize is the size of the buffer).
- This is the Central-header version of the extra field
- if szComment!=NULL, the comment string of the file will be copied in szComment
- (commentBufferSize is the size of the buffer)
-*/
-
-/***************************************************************************/
-/* for reading the content of the current zipfile, you can open it, read data
- from it, and close it (you can close it before reading all the file)
- */
-
-extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
-/*
- Open for reading data the current file in the zipfile.
- If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
- const char* password));
-/*
- Open for reading data the current file in the zipfile.
- password is a crypting password
- If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
- int* method,
- int* level,
- int raw));
-/*
- Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
- if raw==1
- *method will receive method of compression, *level will receive level of
- compression
- note : you can set level parameter as NULL (if you did not want known level,
- but you CANNOT set method parameter as NULL
-*/
-
-extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
- int* method,
- int* level,
- int raw,
- const char* password));
-/*
- Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
- if raw==1
- *method will receive method of compression, *level will receive level of
- compression
- note : you can set level parameter as NULL (if you did not want known level,
- but you CANNOT set method parameter as NULL
-*/
-
-
-extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
-/*
- Close the file in zip opened with unzOpenCurrentFile
- Return UNZ_CRCERROR if all the file was read but the CRC is not good
-*/
-
-extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
- voidp buf,
- unsigned len));
-/*
- Read bytes from the current file (opened by unzOpenCurrentFile)
- buf contain buffer where data must be copied
- len the size of buf.
-
- return the number of byte copied if somes bytes are copied
- return 0 if the end of file was reached
- return <0 with error code if there is an error
- (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-*/
-
-extern z_off_t ZEXPORT unztell OF((unzFile file));
-/*
- Give the current position in uncompressed data
-*/
-
-extern int ZEXPORT unzeof OF((unzFile file));
-/*
- return 1 if the end of file was reached, 0 elsewhere
-*/
-
-extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
- voidp buf,
- unsigned len));
-/*
- Read extra field from the current file (opened by unzOpenCurrentFile)
- This is the local-header version of the extra field (sometimes, there is
- more info in the local-header version than in the central-header)
-
- if buf==NULL, it return the size of the local extra field
-
- if buf!=NULL, len is the size of the buffer, the extra header is copied in
- buf.
- the return value is the number of bytes copied in buf, or (if <0)
- the error code
-*/
-
-/***************************************************************************/
-
-/* Get the current file offset */
-extern uLong ZEXPORT unzGetOffset (unzFile file);
-
-/* Set the current file offset */
-extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _unz_H */
-
-
/trunk/Scribus/scribus/unzip.h
Property changes:
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Author Date Id Revision
\ No newline at end of property
Index: trunk/Scribus/scribus/fileunzip.cpp
===================================================================
--- trunk/Scribus/scribus/fileunzip.cpp (revision 18912)
+++ trunk/Scribus/scribus/fileunzip.cpp (nonexistent)
@@ -1,440 +0,0 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-/***************************************************************************
- * Copyright (C) 2004 by Riku Leino *
- * tsoots@gmail.com *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
- ***************************************************************************/
-
-#include "scconfig.h"
-#include "fileunzip.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#ifndef _MSC_VER
-#include <utime.h>
-#else
-#include <direct.h>
-#include <time.h>
-#include <sys/utime.h>
-#endif
-
-#include <iostream>
-#include "unzip.h"
-#include <zlib.h>
-
-#include <QDir>
-#include <QDebug>
-#include <QByteArray>
-
-#include "scpaths.h"
-#include "util.h"
-
-#define CASESENSITIVITY (0)
-#define WRITEBUFFERSIZE (8192)
-#define MAXFILENAME (256)
-
-int do_extract_currentfile(unzFile uf, QString outfile, const char *password);
-int do_extract_onefile(unzFile uf, const QString& filename, QString outfile, const char *password);
-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);
-
-#if defined(_WIN32) && defined(HAVE_UNICODE)
-zlib_filefunc_def file_api;
-static voidpf ZCALLBACK fopen_filefunc_unicode(voidpf opaque, const char *filename, int mode);
-#define utimbuf _utimbuf
-#endif
-
-FileUnzip::FileUnzip(QString zipFilePath)
-{
- zipFile = zipFilePath;
-}
-
-QString FileUnzip::getFile(QString name)
-{
- QString pwd = QDir::currentPath();
- QTemporaryFile *tempImageFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_zip_XXXXXX.dat");
- if (tempImageFile == NULL)
- return NULL;
- tempImageFile->setAutoRemove(false);
- tempImageFile->open();
- QString fname = getLongPathName(tempImageFile->fileName());
- tempImageFile->close();
- delete tempImageFile;
- tempFileList.append(fname);
- QDir::setCurrent(QDir::tempPath());
- unzFile uf = unzOpenFile(zipFile);
- int ret = do_extract_onefile(uf, name, fname, NULL);
- unzClose(uf);
- QDir::setCurrent(pwd);
- if (ret != 0)
- return NULL;
- else
- return fname;
-}
-
-QString FileUnzip::getFileToPath(QString name, QString path)
-{
- QString pwd = QDir::currentPath();
- QString outDir;
- if (path.isNull())
- outDir = ScPaths::getTempFileDir();
- else
- outDir=path;
- QFile f(outDir);
- QFileInfo fi(f);
- if (!fi.isWritable())
- outDir = ScPaths::getApplicationDataDir();
- QDir::setCurrent(outDir);
- unzFile uf = unzOpenFile(zipFile);
- int ret = do_extract_onefile(uf,name, 0, 1, NULL);
- unzClose(uf);
- QDir::setCurrent(pwd);
- if (ret != 0)
- return NULL;
- else
- return outDir + name;
-}
-
-FileUnzip::~FileUnzip()
-{
- for (int a = 0; a < tempFileList.count(); a++)
- {
- QFile::remove(tempFileList[a]);
- }
-}
-
-FILE* openfile(const QString& filename, const QString& mode)
-{
- FILE* fout = NULL;
-#if defined(_WIN32) && defined(HAVE_UNICODE)
- fout = _wfopen((const wchar_t*) filename.utf16(), (const wchar_t*) mode.utf16());
-#else
- QByteArray fname = filename.toLocal8Bit();
- QByteArray fmode = mode.toLocal8Bit();
- fout = fopen(fname.data(), fmode.data());
-#endif
- return fout;
-}
-
-unzFile unzOpenFile(const QString& filename)
-{
- 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.utf16(), &file_api);
-#else
- QByteArray fname(filename.toLocal8Bit());
- unz = unzOpen(fname.data());
-#endif
- return unz;
-}
-
-#if defined(_WIN32) && defined(HAVE_UNICODE)
-static voidpf ZCALLBACK fopen_filefunc_unicode(voidpf opaque, const char *filename, int mode)
-{
- FILE* file = NULL;
- const wchar_t* mode_fopen = NULL;
- if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
- mode_fopen = L"rb";
- else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
- mode_fopen = L"r+b";
- else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
- mode_fopen = L"wb";
- if (!((filename == NULL) || (mode_fopen == NULL)))
- file = _wfopen((const wchar_t *)filename, mode_fopen);
- return file;
-}
-#endif
-
-int mymkdir(const QString& dirname)
-{
- int ret=0;
-#if defined(_WIN32) && defined(HAVE_UNICODE)
- ret = _wmkdir((const wchar_t*) dirname.utf16());
-#elif defined(_WIN32)
- QByteArray cdir = dirname.toLocal8Bit();
- ret = _mkdir(cdir.data());
-#else
- QByteArray cdir = dirname.toLocal8Bit();
- ret = mkdir (cdir.data(), 0775);
-#endif
- return ret;
-}
-
-int makedir (const QString& newdir)
-{
- 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;
-}
-
-int do_extract_onefile(unzFile uf, const QString& filename, QString outfile, const char *password)
-{
- QByteArray fname = filename.toLocal8Bit();
- if (unzLocateFile(uf,fname.data(),CASESENSITIVITY)!=UNZ_OK)
- return 2;
-
- if (do_extract_currentfile(uf, outfile, password) == UNZ_OK)
- return 0;
- else
- return 1;
-}
-
-int do_extract_currentfile(unzFile uf, QString outfile, const char* password)
-{
- char fn_inzip[256];
- QString filename_inzip;
- QString write_filename;
- int err=UNZ_OK;
- FILE *fout=NULL;
- void* buf;
- uInt size_buf;
- unz_file_info file_info;
- 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;
- filename_inzip = QString::fromLocal8Bit(fn_inzip);
- write_filename = outfile;
- err = unzOpenCurrentFilePassword(uf, password);
- if (err == UNZ_OK)
- {
- 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;
-}
-
-int do_extract_onefile(unzFile uf, const QString& filename, int opt_extract_without_path, int opt_overwrite, const char* password)
-{
-// int err = UNZ_OK;
- QByteArray fname = filename.toLocal8Bit();
- 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;
-}
-
-int do_extract_currentfile(unzFile uf, const int* popt_extract_without_path, int*, const char* password)
-{
- 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 (int 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;
-}
-
-/* change_file_date : change the date/time of a file
- filename : the filename of the file where date/time must be modified
- dosdate : the new date at the MSDos format (4 bytes)
- tmu_date : the SAME new date at the tm_unz format */
-void change_file_date(const QString& filename, uLong, tm_unz tmu_date)
-{
- 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.utf16(), &ut);
-#else
- QByteArray fname = filename.toLocal8Bit();
- utime(fname.data(), &ut);
-#endif
-}
/trunk/Scribus/scribus/fileunzip.cpp
Property changes:
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Author Date Id Revision
\ No newline at end of property
Index: trunk/Scribus/scribus/fileunzip.h
===================================================================
--- trunk/Scribus/scribus/fileunzip.h (revision 18912)
+++ trunk/Scribus/scribus/fileunzip.h (nonexistent)
@@ -1,55 +0,0 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-/***************************************************************************
- * Copyright (C) 2004 by Riku Leino *
- * tsoots@gmail.com *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
- ***************************************************************************/
-
-#ifndef FILEUNZIP_H
-#define FILEUNZIP_H
-
-#include "scconfig.h"
-#include "scribusapi.h"
-#include <QString>
-#include <QTemporaryFile>
-#include <QList>
-
-/**
- * @brief Extract files from a zip archive.
- *
- * FileUnzip can be used to extract a known file from a zip archive.
- * constructor FileUnzip(QString) takes a zip file as a parameter and method
- * getFile(QString) extracts the path to the extracted file.
- */
-class SCRIBUS_API FileUnzip
-{
-private:
- QString zipFile;
- QList<QString> tempFileList;
-public:
- FileUnzip(QString zipFilePath);
- ~FileUnzip();
- QString getFile(QString name);
- QString getFileToPath(QString name, QString path);
-};
-
-#endif
/trunk/Scribus/scribus/fileunzip.h
Property changes:
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Author Date Id Revision
\ No newline at end of property
Index: trunk/Scribus/scribus/CMakeLists.txt
===================================================================
--- trunk/Scribus/scribus/CMakeLists.txt (revision 18912)
+++ trunk/Scribus/scribus/CMakeLists.txt (revision 18913)
@@ -557,7 +557,6 @@
exif.cpp
fileloader.cpp
filesearch.cpp
- fileunzip.cpp
filewatcher.cpp
ui/fontcombo.cpp
fontlistmodel.cpp
@@ -702,7 +701,6 @@
undostack.cpp
undostate.cpp
units.cpp
- unzip.c
updatemanager.cpp
upgradechecker.cpp
urllauncher.cpp
Index: trunk/Scribus/scribus/plugins/gettext/odtim/odtim.cpp
===================================================================
--- trunk/Scribus/scribus/plugins/gettext/odtim/odtim.cpp (revision 18912)
+++ trunk/Scribus/scribus/plugins/gettext/odtim/odtim.cpp (revision 18913)
@@ -31,6 +31,7 @@
#endif
#include <QStringList>
+#include <QTemporaryDir>
#include <scribusstructs.h>
#include "prefsmanager.h"
@@ -37,10 +38,10 @@
#include <prefsfile.h>
#include <prefscontext.h>
#include <prefstable.h>
-#include "fileunzip.h"
#include "stylereader.h"
#include "contentreader.h"
#include "odtdia.h"
+#include "third_party/zip/scribus_zip.h"
QString FileFormatName()
{
@@ -91,20 +92,27 @@
filename = fileName;
writer = w;
writer->setUpdateParagraphStyles(update);
- FileUnzip* fun = new FileUnzip(fileName);
- stylePath = fun->getFile(STYLE);
- contentPath = fun->getFile(CONTENT);
- // Qt4 NULL -> isNull()
- if ((!stylePath.isNull()) && (!contentPath.isNull()))
+ ScZipHandler* fun = new ScZipHandler();
+ if (fun->open(fileName))
{
- QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1);
- docname = docname.left(docname.lastIndexOf("."));
- StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
- sreader->parse(stylePath);
- ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
- creader->parse(contentPath);
- delete sreader;
- delete creader;
+ QTemporaryDir *dir = new QTemporaryDir();
+ QString baseDir = dir->path();
+ fun->extract(STYLE, baseDir);
+ fun->extract(CONTENT, baseDir);
+ stylePath = baseDir + "/" + STYLE;
+ contentPath = baseDir + "/" + CONTENT;
+ if ((!stylePath.isNull()) && (!contentPath.isNull()))
+ {
+ QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1);
+ docname = docname.left(docname.lastIndexOf("."));
+ StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
+ sreader->parse(stylePath);
+ ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
+ creader->parse(contentPath);
+ delete sreader;
+ delete creader;
+ }
+ delete dir;
}
delete fun;
}
/trunk/Scribus/scribus/plugins/gettext/sxwim/sxwim.cpp
26,6 → 26,7
 
#include "sxwim.h"
#include <QStringList>
#include <QTemporaryDir>
 
#ifndef HAVE_XML
#error The sxwim plugin requires libxml to build
35,10 → 36,10
#include <prefsfile.h>
#include <prefscontext.h>
#include <prefstable.h>
#include "fileunzip.h"
#include "stylereader.h"
#include "contentreader.h"
#include "sxwdia.h"
#include "third_party/zip/scribus_zip.h"
 
QString FileFormatName()
{
89,20 → 90,27
filename = fileName;
writer = w;
writer->setUpdateParagraphStyles(update);
FileUnzip* fun = new FileUnzip(fileName);
stylePath = fun->getFile(STYLE);
contentPath = fun->getFile(CONTENT);
// Qt4 NULL -> isNull()
if ((!stylePath.isNull()) && (!contentPath.isNull()))
ScZipHandler* fun = new ScZipHandler();
if (fun->open(fileName))
{
QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1);
docname = docname.left(docname.lastIndexOf("."));
StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
sreader->parse(stylePath);
ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
creader->parse(contentPath);
delete sreader;
delete creader;
QTemporaryDir *dir = new QTemporaryDir();
QString baseDir = dir->path();
fun->extract(STYLE, baseDir);
fun->extract(CONTENT, baseDir);
stylePath = baseDir + "/" + STYLE;
contentPath = baseDir + "/" + CONTENT;
if ((!stylePath.isNull()) && (!contentPath.isNull()))
{
QString docname = filename.right(filename.length() - filename.lastIndexOf("/") - 1);
docname = docname.left(docname.lastIndexOf("."));
StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
sreader->parse(stylePath);
ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
creader->parse(contentPath);
delete sreader;
delete creader;
}
delete dir;
}
delete fun;
}
/trunk/Scribus/scribus/plugins/import/idml/importidml.cpp
105,7 → 105,6
{
QImage tmp;
QByteArray f;
QString designMap;
if ( !QFile::exists(fName) )
return QImage();
QFileInfo fi = QFileInfo(fName);
112,18 → 111,22
QString ext = fi.suffix().toLower();
if (ext == "idml")
{
fun = new FileUnzip(fName);
designMap = fun->getFile("designmap.xml");
fun = new ScZipHandler();
if (!fun->open(fName))
{
delete fun;
return QImage();
}
if (fun->contains("designmap.xml"))
fun->read("designmap.xml", f);
delete fun;
}
else if (ext == "idms")
{
designMap = fName;
fun = NULL;
loadRawText(fName, f);
}
if (!designMap.isNull())
if (!f.isEmpty())
{
loadRawText(designMap, f);
delete fun;
if(!designMapDom.setContent(f))
return QImage();
bool found = false;
220,22 → 223,25
m_Doc->addPage(0);
m_Doc->setGUI(false, ScCore->primaryMainWindow(), 0);
QByteArray f;
QString designMap;
QFileInfo fi = QFileInfo(fNameIn);
QString ext = fi.suffix().toLower();
if (ext == "idml")
{
fun = new FileUnzip(fNameIn);
designMap = fun->getFile("designmap.xml");
fun = new ScZipHandler();
if (!fun->open(fNameIn))
{
delete fun;
return false;
}
if (fun->contains("designmap.xml"))
fun->read("designmap.xml", f);
}
else if (ext == "idms")
{
designMap = fNameIn;
fun = NULL;
loadRawText(fNameIn, f);
}
if (!designMap.isNull())
if (!f.isEmpty())
{
loadRawText(designMap, f);
if(designMapDom.setContent(f))
{
QDomElement docElem = designMapDom.documentElement();
510,22 → 516,25
bool retVal = true;
bool firstSpread = true;
QByteArray f;
QString designMap;
QFileInfo fi = QFileInfo(fn);
QString ext = fi.suffix().toLower();
if (ext == "idml")
{
fun = new FileUnzip(fn);
designMap = fun->getFile("designmap.xml");
fun = new ScZipHandler();
if (!fun->open(fn))
{
delete fun;
return false;
}
if (fun->contains("designmap.xml"))
fun->read("designmap.xml", f);
}
else if (ext == "idms")
{
designMap = fn;
fun = NULL;
loadRawText(fn, f);
}
if (!designMap.isNull())
if (!f.isEmpty())
{
loadRawText(designMap, f);
if(designMapDom.setContent(f))
{
QDomElement docElem = designMapDom.documentElement();
690,7 → 699,7
if (grElem.hasAttribute("src"))
{
QByteArray f2;
loadRawText(fun->getFile(grElem.attribute("src")), f2);
fun->read(grElem.attribute("src"), f2);
if(grMapDom.setContent(f2))
grNode = grMapDom.documentElement();
else
738,7 → 747,7
if (grElem.hasAttribute("src"))
{
QByteArray f2;
loadRawText(fun->getFile(grElem.attribute("src")), f2);
fun->read(grElem.attribute("src"), f2);
if(grMapDom.setContent(f2))
grNode = grMapDom.documentElement();
else
864,7 → 873,7
if (sElem.hasAttribute("src"))
{
QByteArray f2;
loadRawText(fun->getFile(sElem.attribute("src")), f2);
fun->read(sElem.attribute("src"), f2);
if(sMapDom.setContent(f2))
sNode = sMapDom.documentElement();
else
1287,7 → 1296,7
if (prElem.hasAttribute("src"))
{
QByteArray f2;
loadRawText(fun->getFile(prElem.attribute("src")), f2);
fun->read(prElem.attribute("src"), f2);
if(prMapDom.setContent(f2))
prNode = prMapDom.documentElement();
else
1500,7 → 1509,7
if (spElem.hasAttribute("src"))
{
QByteArray f2;
loadRawText(fun->getFile(spElem.attribute("src")), f2);
fun->read(spElem.attribute("src"), f2);
if(spMapDom.setContent(f2))
spNode = spMapDom.documentElement();
else
2690,7 → 2699,7
if (stElem.hasAttribute("src"))
{
QByteArray f2;
loadRawText(fun->getFile(stElem.attribute("src")), f2);
fun->read(stElem.attribute("src"), f2);
if(stMapDom.setContent(f2))
stNode = stMapDom.documentElement();
else
/trunk/Scribus/scribus/plugins/import/idml/importidml.h
16,7 → 16,6
#include "pluginapi.h"
#include "pageitem.h"
#include "sccolor.h"
#include "fileunzip.h"
#include "fpointarray.h"
#include <QList>
#include <QTransform>
27,6 → 26,8
#include <QDomDocument>
#include <QDomElement>
 
#include "third_party/zip/scribus_zip.h"
 
class MultiProgressDialog;
class ScribusDoc;
class Selection;
186,7 → 187,7
QMap<QString, PageItem*> frameTargets;
QMap<QString, ObjectStyle> ObjectStyles;
 
FileUnzip *fun;
ScZipHandler *fun;
 
public slots:
void cancelRequested() { cancel = true; }
/trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp
22,7 → 22,6
 
#include "color.h"
#include "commonstrings.h"
#include "fileunzip.h"
#include "fpointarray.h"
#include "ui/scmwmenumanager.h"
#include "pageitem.h"
47,6 → 46,7
#include "util.h"
#include "util_icon.h"
#include "util_math.h"
#include "third_party/zip/scribus_zip.h"
 
 
using namespace std;
242,26 → 242,26
QByteArray f, f2, f3;
if ( !QFile::exists(fileName) )
return QImage();
FileUnzip* fun = new FileUnzip(fileName);
stylePath = fun->getFile("styles.xml");
contentPath = fun->getFile("content.xml");
metaPath = fun->getFile("meta.xml");
// Qt4 NULL -> isNull()
if ((!stylePath.isNull()) && (!contentPath.isNull()))
ScZipHandler* fun = new ScZipHandler();
if (!fun->open(fileName))
{
HaveMeta = false;
QString docname = fileName.right(fileName.length() - fileName.lastIndexOf("/") - 1);
docname = docname.left(docname.lastIndexOf("."));
loadRawText(stylePath, f);
loadRawText(contentPath, f2);
HaveMeta = false;
if (!metaPath.isEmpty())
{
loadRawText(metaPath, f3);
HaveMeta = inpMeta.setContent(f3);
}
delete fun;
return QImage();
}
if (fun->contains("styles.xml"))
fun->read("styles.xml", f);
if (fun->contains("content.xml"))
fun->read("content.xml", f2);
if (fun->contains("meta.xml"))
fun->read("meta.xml", f3);
delete fun;
HaveMeta = inpMeta.setContent(f3);
QString docname = fileName.right(fileName.length() - fileName.lastIndexOf("/") - 1);
docname = docname.left(docname.lastIndexOf("."));
if (f.isEmpty())
return QImage();
if (f2.isEmpty())
return QImage();
if(!inpStyles.setContent(f))
return QImage();
if(!inpContents.setContent(f2))
365,26 → 365,26
QByteArray f, f2, f3;
if ( !QFile::exists(fileName) )
return false;
FileUnzip* fun = new FileUnzip(fileName);
stylePath = fun->getFile("styles.xml");
contentPath = fun->getFile("content.xml");
metaPath = fun->getFile("meta.xml");
// Qt4 NULL -> isNull()
if ((!stylePath.isNull()) && (!contentPath.isNull()))
ScZipHandler* fun = new ScZipHandler();
if (!fun->open(fileName))
{
HaveMeta = false;
QString docname = fileName.right(fileName.length() - fileName.lastIndexOf("/") - 1);
docname = docname.left(docname.lastIndexOf("."));
loadRawText(stylePath, f);
loadRawText(contentPath, f2);
HaveMeta = false;
if (!metaPath.isEmpty())
{
loadRawText(metaPath, f3);
HaveMeta = inpMeta.setContent(f3);
}
delete fun;
return false;
}
if (fun->contains("styles.xml"))
fun->read("styles.xml", f);
if (fun->contains("content.xml"))
fun->read("content.xml", f2);
if (fun->contains("meta.xml"))
fun->read("meta.xml", f3);
delete fun;
HaveMeta = inpMeta.setContent(f3);
QString docname = fileName.right(fileName.length() - fileName.lastIndexOf("/") - 1);
docname = docname.left(docname.lastIndexOf("."));
if (f.isEmpty())
return false;
if (f2.isEmpty())
return false;
if(!inpStyles.setContent(f))
return false;
if(!inpContents.setContent(f2))
/trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.h
146,9 → 146,6
QDomDocument inpMeta;
QHash<QString,QDomElement*> m_styles, m_draws;
StyleStack m_styleStack;
QString stylePath;
QString contentPath;
QString metaPath;
double CurrX, CurrY, StartX, StartY;
int PathLen;
bool FirstM, WasM, PathClosed, HaveMeta;
/trunk/Scribus/scribus/third_party/zip/scribus_zip.cpp
23,6 → 23,7
#include "unzip.h"
#include "scribus_zip.h"
#include "util.h"
#include "scpaths.h"
 
ScZipHandler::ScZipHandler(bool forWrite)
{
109,6 → 110,29
return retVal;
}
 
bool ScZipHandler::extract(QString name, QString path)
{
bool retVal = false;
if (m_uz != NULL)
{
QString pwd = QDir::currentPath();
QString outDir;
if (path.isNull())
outDir = ScPaths::getTempFileDir();
else
outDir=path;
QFile f(outDir);
QFileInfo fi(f);
if (!fi.isWritable())
outDir = ScPaths::getApplicationDataDir();
QDir::setCurrent(outDir);
UnZip::ErrorCode ec = m_uz->extractFile(name, outDir, UnZip::SkipPaths);
retVal = (ec == UnZip::Ok);
QDir::setCurrent(pwd);
}
return retVal;
}
 
QStringList ScZipHandler::files()
{
QStringList retVal = QStringList();
/trunk/Scribus/scribus/third_party/zip/scribus_zip.h
35,6 → 35,7
bool contains(QString fileName);
bool read(QString fileName, QByteArray &buf);
bool write(QString dirName);
bool extract(QString name, QString path);
QStringList files();
private:
UnZip* m_uz;
/trunk/Scribus/scribus/ui/prefs_spelling.cpp
17,7 → 17,6
 
 
#include "prefs_spelling.h"
#include "fileunzip.h"
#include "langmgr.h"
#include "prefsstructs.h"
#include "scribusdoc.h"
24,6 → 23,7
#include "util_icon.h"
#include "util.h"
#include "util_file.h"
#include "third_party/zip/scribus_zip.h"
 
#include "scribusapp.h"
#include "scpaths.h"
185,13 → 185,17
if (d.filetype=="zip")
{
//qDebug()<<"zip data found"<<filename;
FileUnzip fun(filename);
foreach (QString s, files)
ScZipHandler* fun = new ScZipHandler();
if (fun->open(filename))
{
//qDebug()<<"Unzipping"<<userDictDir+s;
QString data = fun.getFileToPath(s, userDictDir);
allFileList.removeOne(s);
foreach (QString s, files)
{
//qDebug()<<"Unzipping"<<userDictDir+s;
fun->extract(s, userDictDir);
allFileList.removeOne(s);
}
}
delete fun;
}
if (d.filetype=="plain")
{
324,4 → 328,4
return file;
}
return QString();
}
}