//---------------------------------------------------------------------------
// Служебные функции для SimpleUnzip
//---------------------------------------------------------------------------
int WINAPI DummyPrint(LPSTR, unsigned long) {return 0;}
int WINAPI DummyReplace(LPSTR) {return 0;}
int WINAPI DummyPassword(LPSTR, int, LPCSTR, LPCSTR) {return 0;}
void WINAPI DummyMessage(unsigned long, unsigned long, unsigned,
unsigned, unsigned, unsigned, unsigned, unsigned,
char, LPSTR, LPSTR, unsigned long, char) {}
//---------------------------------------------------------------------------
// Распаковывает zip-архив a_zip в каталог a_dir, заменяя существующие файлы
//---------------------------------------------------------------------------
typedef int (WINAPI * FSINGLEENTRYUNZIP)( int, char **, int, char **,
LPDCL, LPUSERFUNCTIONS );
bool SimpleUnzip( const QString& a_zip, const QString& a_dir )
{
const QString noZip = ru( "Обработка архивов zip невозможна." );
const QString errCap = ru("Ошибка");
const TCHAR* UNZ_DLL_NAME = TEXT("unzip32.dll");
TCHAR szFullPath[_MAX_PATH];
TCHAR* ptr;
if ( SearchPathW( 0, UNZ_DLL_NAME, 0,
sizeof(szFullPath) / sizeof(szFullPath[ 0 ]),
szFullPath, &ptr ) == 0 )
{
mbE( errCap, ru("Не найдена библиотека unzip32.dll.\n" + noZip ) );
return false;
}
HMODULE hUnzipDll = LoadLibraryW( UNZ_DLL_NAME );
if ( hUnzipDll == 0 )
{
mbE( errCap, ru("Не удалось загрузить библиотеку unzip32.dll.\n" + noZip ) );
return false;
}
FSINGLEENTRYUNZIP pWiz_SingleEntryUnzip = (FSINGLEENTRYUNZIP)GetProcAddress(
hUnzipDll, "Wiz_SingleEntryUnzip" );
if ( pWiz_SingleEntryUnzip == 0 )
{
FreeLibrary( hUnzipDll );
mbE( errCap, ru("Неправильная библиотека unzip32.dll.\n" + noZip ) );
return false;
}
LPDCL lpDCL = new DCL;
LPUSERFUNCTIONS lpUserFunctions = new USERFUNCTIONS;
lpUserFunctions->password = DummyPassword;
lpUserFunctions->print = DummyPrint;
lpUserFunctions->replace = DummyReplace;
lpUserFunctions->SendApplicationMessage = DummyMessage;
lpUserFunctions->sound = 0;
lpUserFunctions->ServCallBk = 0;
//set up the flags to be passed into the dll.
lpDCL->ExtractOnlyNewer = 0; // Do not extract only newer
lpDCL->SpaceToUnderscore = 0;
lpDCL->PromptToOverwrite = 0; // "Overwrite all" selected, no query mode
lpDCL->fQuiet = 2; // 0 = all messages, 1 = fewer messages, 2 = no messages
lpDCL->ncflag = 0; // Write to stdout if true
lpDCL->ntflag = 0; // Do not test zip file
lpDCL->nvflag = 0; // Do not give a verbose listing
lpDCL->nfflag = 0; // Do not freshen existing files only
lpDCL->nzflag = 0; // display a zip file comment if true
lpDCL->ndflag = 1; // Recreate directories != 0, skip "../" if < 2
lpDCL->noflag = 1; // Over-write all files
lpDCL->naflag = 0; // Do not convert CR to CRLF
lpDCL->nZIflag = 0;// Do not get ZipInfo
lpDCL->C_flag = 1; // Do not be case insensitive
lpDCL->fPrivilege = 0; // 1 => restore ACLs in user mode,
// 2 => try to use privileges for restoring ACLs
QCString zip = a_zip.local8Bit();
QCString dir = a_dir.local8Bit();
lpDCL->lpszZipFN = const_cast<CHAR*>(static_cast<const char*>(zip));
if ( a_dir.isEmpty() )
lpDCL->lpszExtractDir = 0;
else
lpDCL->lpszExtractDir = const_cast<CHAR*>(static_cast<const char*>(dir));
// qDebug( "zip=%s, dir=%s", lpDCL->lpszZipFN, lpDCL->lpszExtractDir );
int res = pWiz_SingleEntryUnzip( 0, 0, 0, 0, lpDCL, lpUserFunctions );
// qDebug( "unzip retcode=%d", res );
bool rc = res == 0;
delete lpDCL;
delete lpUserFunctions;
FreeLibrary( hUnzipDll );
return rc;
}