Commit ce44b2ea authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander Trofimov

для Win интерфейс с wchar_t* для остальных ОС с char*

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@59350 954022d7-b5bf-4e40-9824-e11837661b57
parent 77da2a9b
...@@ -10,7 +10,32 @@ ...@@ -10,7 +10,32 @@
namespace ZLibZipUtils namespace ZLibZipUtils
{ {
AVSOfficeCriticalSection criticalSection; AVSOfficeCriticalSection criticalSection;
static zipFile zipOpenHelp(const wchar_t* filename)
{
#ifdef _WIN32
zipFile zf = zipOpen( filename, APPEND_STATUS_CREATE );
#else
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(filename, wcslen(filename), pUtf8, lLen, false);
zipFile zf = zipOpen( (char*)pUtf8, APPEND_STATUS_CREATE );
delete [] pUtf8;
#endif
return zf;
}
static unzFile unzOpenHelp(const wchar_t* filename)
{
#ifdef _WIN32
unzFile uf = unzOpen (filename);
#else
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(filename, wcslen(filename), pUtf8, lLen, false);
unzFile uf = unzOpen( (char*)pUtf8 );
delete [] pUtf8;
#endif
return uf;
}
static std::wstring ascii_to_unicode(const char *src) static std::wstring ascii_to_unicode(const char *src)
{ {
size_t nSize = mbstowcs(0, src, 0); size_t nSize = mbstowcs(0, src, 0);
...@@ -442,7 +467,7 @@ namespace ZLibZipUtils ...@@ -442,7 +467,7 @@ namespace ZLibZipUtils
wstring zipFileName; wstring zipFileName;
wstring szText; wstring szText;
zipFile zf = zipOpen( outputFile, APPEND_STATUS_CREATE ); zipFile zf = zipOpenHelp(outputFile);
zip_fileinfo zi; zip_fileinfo zi;
...@@ -562,7 +587,7 @@ namespace ZLibZipUtils ...@@ -562,7 +587,7 @@ namespace ZLibZipUtils
BYTE* pData = new BYTE[oFile.GetFileSize()]; BYTE* pData = new BYTE[oFile.GetFileSize()];
if(oFile.ReadFile(pData, oFile.GetFileSize(), dwSizeRead)) if(oFile.ReadFile(pData, oFile.GetFileSize(), dwSizeRead))
{ {
zipFile zf = zipOpen( outputFile, APPEND_STATUS_CREATE ); zipFile zf = zipOpenHelp(outputFile);
zip_fileinfo zi; zip_fileinfo zi;
...@@ -670,7 +695,7 @@ namespace ZLibZipUtils ...@@ -670,7 +695,7 @@ namespace ZLibZipUtils
if ( ( zipFile != NULL ) && ( unzipDir != NULL ) ) if ( ( zipFile != NULL ) && ( unzipDir != NULL ) )
{ {
uf = unzOpen (zipFile); uf = unzOpenHelp (zipFile);
} }
if ( uf != NULL ) if ( uf != NULL )
...@@ -770,7 +795,7 @@ namespace ZLibZipUtils ...@@ -770,7 +795,7 @@ namespace ZLibZipUtils
bool isZIP = false; bool isZIP = false;
if (( filename != NULL )) if (( filename != NULL ))
uf = unzOpen( filename ); uf = unzOpenHelp( filename );
if ( uf != NULL ) if ( uf != NULL )
{ {
...@@ -793,7 +818,7 @@ namespace ZLibZipUtils ...@@ -793,7 +818,7 @@ namespace ZLibZipUtils
bool isIn = false; bool isIn = false;
if ( ( zipFile != NULL ) && ( filePathInZip != NULL ) ) if ( ( zipFile != NULL ) && ( filePathInZip != NULL ) )
uf = unzOpen( zipFile ); uf = unzOpenHelp( zipFile );
if ( uf != NULL ) if ( uf != NULL )
{ {
isIn = is_file_in_archive( uf, filePathInZip ); isIn = is_file_in_archive( uf, filePathInZip );
...@@ -814,7 +839,7 @@ namespace ZLibZipUtils ...@@ -814,7 +839,7 @@ namespace ZLibZipUtils
bool isIn = false; bool isIn = false;
if ( ( zipFile != NULL ) && ( filePathInZip != NULL ) ) if ( ( zipFile != NULL ) && ( filePathInZip != NULL ) )
uf = unzOpen( zipFile ); uf = unzOpenHelp( zipFile );
if ( uf != NULL ) if ( uf != NULL )
{ {
...@@ -832,7 +857,7 @@ namespace ZLibZipUtils ...@@ -832,7 +857,7 @@ namespace ZLibZipUtils
{ {
CSLocker locker(criticalSection); CSLocker locker(criticalSection);
unzFile unzip_file_handle = unzOpen(zip_file_path); unzFile unzip_file_handle = unzOpenHelp(zip_file_path);
if ( unzip_file_handle != NULL ) if ( unzip_file_handle != NULL )
{ {
do do
...@@ -861,7 +886,7 @@ namespace ZLibZipUtils ...@@ -861,7 +886,7 @@ namespace ZLibZipUtils
{ {
CSLocker locker(criticalSection); CSLocker locker(criticalSection);
zipFile zip_file_handle = zipOpen(zip_file_path, APPEND_STATUS_CREATE); zipFile zip_file_handle = zipOpenHelp(zip_file_path);
if(NULL != zip_file_handle) if(NULL != zip_file_handle)
{ {
......
...@@ -29,10 +29,17 @@ ...@@ -29,10 +29,17 @@
#define SEEK_SET 0 #define SEEK_SET 0
#endif #endif
#ifdef _WIN32
voidpf ZCALLBACK fopen_file_func OF(( voidpf ZCALLBACK fopen_file_func OF((
voidpf opaque, voidpf opaque,
const wchar_t* filename, const wchar_t* filename,
int mode)); int mode));
#else
voidpf ZCALLBACK fopen_file_func OF((
voidpf opaque,
const char* filename,
int mode));
#endif
uLong ZCALLBACK fread_file_func OF(( uLong ZCALLBACK fread_file_func OF((
voidpf opaque, voidpf opaque,
...@@ -64,13 +71,12 @@ int ZCALLBACK ferror_file_func OF(( ...@@ -64,13 +71,12 @@ int ZCALLBACK ferror_file_func OF((
voidpf opaque, voidpf opaque,
voidpf stream)); voidpf stream));
#ifdef _WIN32
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
voidpf opaque; voidpf opaque;
const wchar_t* filename; const wchar_t* filename;
int mode; int mode;
{ {
#ifdef _WIN32
FILE* file = NULL; FILE* file = NULL;
const wchar_t* mode_fopen = NULL; const wchar_t* mode_fopen = NULL;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
...@@ -85,11 +91,29 @@ voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) ...@@ -85,11 +91,29 @@ voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
if ((filename!=NULL) && (mode_fopen != NULL)) if ((filename!=NULL) && (mode_fopen != NULL))
file = _wfopen(filename, mode_fopen); file = _wfopen(filename, mode_fopen);
return file; return file;
#else
return NULL;
#endif
} }
#else
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
voidpf opaque;
const char* filename;
int mode;
{
FILE* file = NULL;
const char* mode_fopen = NULL;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
mode_fopen = "rb";
else
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
mode_fopen = "r+b";
else
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
mode_fopen = "wb";
if ((filename!=NULL) && (mode_fopen != NULL))
file = fopen(filename, mode_fopen);
return file;
}
#endif
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
voidpf opaque; voidpf opaque;
......
...@@ -35,7 +35,11 @@ ...@@ -35,7 +35,11 @@
extern "C" { extern "C" {
#endif #endif
#ifdef _WIN32
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const wchar_t* filename, int mode));
#else
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
#endif
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
......
...@@ -395,7 +395,11 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) ...@@ -395,7 +395,11 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
of this unzip package. of this unzip package.
*/ */
extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
#ifdef _WIN32
const wchar_t *path; const wchar_t *path;
#else
const char *path;
#endif
zlib_filefunc_def* pzlib_filefunc_def; zlib_filefunc_def* pzlib_filefunc_def;
{ {
unz_s us; unz_s us;
...@@ -498,7 +502,11 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) ...@@ -498,7 +502,11 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
extern unzFile ZEXPORT unzOpen (path) extern unzFile ZEXPORT unzOpen (path)
#ifdef _WIN32
const wchar_t *path; const wchar_t *path;
#else
const char *path;
#endif
{ {
return unzOpen2(path, NULL); return unzOpen2(path, NULL);
} }
......
...@@ -131,8 +131,11 @@ extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, ...@@ -131,8 +131,11 @@ extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
(like 1 on Unix, 2 on Windows) (like 1 on Unix, 2 on Windows)
*/ */
#ifdef _WIN32
extern unzFile ZEXPORT unzOpen OF((const wchar_t *path)); extern unzFile ZEXPORT unzOpen OF((const wchar_t *path));
#else
extern unzFile ZEXPORT unzOpen OF((const char *path));
#endif
/* /*
Open a Zip file. path contain the full pathname (by example, 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 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
...@@ -142,9 +145,13 @@ extern unzFile ZEXPORT unzOpen OF((const wchar_t *path)); ...@@ -142,9 +145,13 @@ extern unzFile ZEXPORT unzOpen OF((const wchar_t *path));
Else, the return value is a unzFile Handle, usable with other function Else, the return value is a unzFile Handle, usable with other function
of this unzip package. of this unzip package.
*/ */
#ifdef _WIN32
extern unzFile ZEXPORT unzOpen2 OF((const wchar_t *path, extern unzFile ZEXPORT unzOpen2 OF((const wchar_t *path,
zlib_filefunc_def* pzlib_filefunc_def)); zlib_filefunc_def* pzlib_filefunc_def));
#else
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
zlib_filefunc_def* pzlib_filefunc_def));
#endif
/* /*
Open a Zip file, like unzOpen, but provide a set of file low level API Open a Zip file, like unzOpen, but provide a set of file low level API
for read/write the zip file (see ioapi.h) for read/write the zip file (see ioapi.h)
......
...@@ -497,7 +497,11 @@ local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream) ...@@ -497,7 +497,11 @@ local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream)
/************************************************************/ /************************************************************/
extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def) extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def)
#ifdef _WIN32
const wchar_t *pathname; const wchar_t *pathname;
#else
const char *pathname;
#endif
int append; int append;
zipcharpc* globalcomment; zipcharpc* globalcomment;
zlib_filefunc_def* pzlib_filefunc_def; zlib_filefunc_def* pzlib_filefunc_def;
...@@ -681,7 +685,11 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc ...@@ -681,7 +685,11 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
} }
extern zipFile ZEXPORT zipOpen (pathname, append) extern zipFile ZEXPORT zipOpen (pathname, append)
#ifdef _WIN32
const wchar_t *pathname; const wchar_t *pathname;
#else
const char *pathname;
#endif
int append; int append;
{ {
return zipOpen2(pathname,append,NULL,NULL); return zipOpen2(pathname,append,NULL,NULL);
......
...@@ -110,8 +110,11 @@ typedef const char* zipcharpc; ...@@ -110,8 +110,11 @@ typedef const char* zipcharpc;
#define APPEND_STATUS_CREATE (0) #define APPEND_STATUS_CREATE (0)
#define APPEND_STATUS_CREATEAFTER (1) #define APPEND_STATUS_CREATEAFTER (1)
#define APPEND_STATUS_ADDINZIP (2) #define APPEND_STATUS_ADDINZIP (2)
#ifdef _WIN32
extern zipFile ZEXPORT zipOpen OF((const wchar_t *pathname, int append)); extern zipFile ZEXPORT zipOpen OF((const wchar_t *pathname, int append));
#else
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
#endif
/* /*
Create a zipfile. Create a zipfile.
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
...@@ -130,11 +133,17 @@ extern zipFile ZEXPORT zipOpen OF((const wchar_t *pathname, int append)); ...@@ -130,11 +133,17 @@ extern zipFile ZEXPORT zipOpen OF((const wchar_t *pathname, int append));
If you want delete file into a zipfile, you must open a zipfile, and create another If you want delete file into a zipfile, you must open a zipfile, and create another
Of couse, you can use RAW reading and writing to copy the file you did not want delte Of couse, you can use RAW reading and writing to copy the file you did not want delte
*/ */
#ifdef _WIN32
extern zipFile ZEXPORT zipOpen2 OF((const wchar_t *pathname, extern zipFile ZEXPORT zipOpen2 OF((const wchar_t *pathname,
int append, int append,
zipcharpc* globalcomment, zipcharpc* globalcomment,
zlib_filefunc_def* pzlib_filefunc_def)); zlib_filefunc_def* pzlib_filefunc_def));
#else
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
int append,
zipcharpc* globalcomment,
zlib_filefunc_def* pzlib_filefunc_def));
#endif
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
const char* filename, const char* filename,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment