void User::AddFriendGuardedMacros(User&) { ::Loki::ScopeGuard invariantGuard = ::Loki::MakeObjGuard( *this, &User::CheckIfValid, __FUNCTION__, __LINE__ ); (void)invariantGuard; LOKI_ON_BLOCK_EXIT_OBJ(friends_, &UserCont::pop_back); (void) LOKI_ANONYMOUS_VARIABLE(scopeGuard); // GCC 4.2 Bug #if defined(__GNUC__) #define GCC_VERSION (__GNUC__ * 10 + __GNUC_MINOR__ * 1) #endif #if !defined(__GNUC__) || (GCC_VERSION < 42) || (GCC_VERSION > 42) LOKI_ON_BLOCK_EXIT(Decrement, Loki::ByRef(fCount)); (void) LOKI_ANONYMOUS_VARIABLE(scopeGuard); #endif }
bool ReleaseDialog::ZipAddFile(zipFile zf, QString lpszFileNameInZip, QString lpszFilePath, QString password, bool bUtf8) { zip_fileinfo FileInfo; ZeroMemory(&FileInfo, sizeof(FileInfo)); QTextCodec *codec = QTextCodec::codecForName("GBK"); QByteArray nameInZip = codec->fromUnicode(lpszFileNameInZip); ///gbk // QByteArray nameInZip = lpszFileNameInZip.toLocal8Bit(); ///utf-8 QByteArray pwd = password.toLocal8Bit(); if (bUtf8) { if (zipOpenNewFileInZip4(zf, nameInZip.data(), &FileInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 9, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, pwd.data(), 0, 0, ZIP_GPBF_LANGUAGE_ENCODING_FLAG) != ZIP_OK) { return FALSE; } } else { // QTextCodec *codec = QTextCodec::codecForName("GBK"); // QByteArray nameInZip = codec->fromUnicode(lpszFileNameInZip); if (zipOpenNewFileInZip(zf, nameInZip.data(), &FileInfo, NULL, 0, pwd.data(), 0, NULL, Z_DEFLATED, 9) != ZIP_OK) { return FALSE; } } LOKI_ON_BLOCK_EXIT(zipCloseFileInZip, zf); const qint64 BUFFER_SIZE = 4096; char *buffer = new char[BUFFER_SIZE]; QFile file(lpszFilePath); if(!file.open(QIODevice::ReadOnly)) return false; QDataStream in(&file); in.setVersion(QDataStream::Qt_5_4); qint64 size = file.size(); bar->setHidden(false); bar->setRange(0, size); bar->setValue(0); qint64 readCount = 0; qint64 index = size; qint64 total = 0; while (index > 0) { qint64 dwSizeToRead = index > BUFFER_SIZE ? BUFFER_SIZE : (size-total); memset(buffer,0,sizeof(char)*BUFFER_SIZE); readCount = in.readRawData(buffer, dwSizeToRead); if (zipWriteInFileInZip(zf, buffer, readCount)) { return FALSE; } total += readCount; index -= readCount; file.seek(total); bar->setValue(total); } bar->setHidden(true); delete []buffer; file.close(); return TRUE; }
void GifEncoder::encode() { RGBator rgb(data, width, height, buf_type); int color_map_size = 256; ColorMapObject *output_color_map = GifMakeMapObject(256, ext_web_safe_palette); LOKI_ON_BLOCK_EXIT(GifFreeMapObject, output_color_map); if (!output_color_map) throw "MakeMapObject in GifEncoder::encode failed"; GifByteType *gif_buf = (GifByteType *)malloc(sizeof(GifByteType)*width*height); LOKI_ON_BLOCK_EXIT(free, gif_buf); if (!gif_buf) throw "malloc in GifEncoder::encode failed"; if (web_safe_quantize(width, height, rgb.red, rgb.green, rgb.blue, gif_buf) == GIF_ERROR) throw "web_safe_quantize in GifEncoder::encode failed"; /* if (QuantizeBuffer(width, height, &color_map_size, rgb.red, rgb.green, rgb.blue, gif_buf, output_color_map->Colors) == GIF_ERROR) { throw "QuantizeBuffer in GifEncoder::encode failed"; } */ int nError; GifFileType *gif_file = EGifOpen(&gif, gif_writer, &nError); LOKI_ON_BLOCK_EXIT(EGifCloseFile, gif_file); if (!gif_file) throw "EGifOpen in GifEncoder::encode failed"; if (EGifPutScreenDesc(gif_file, width, height, color_map_size, 0, output_color_map) == GIF_ERROR) { throw "EGifPutScreenDesc in GifEncoder::encode failed"; } if (transparency_color.color_present) { int i = find_color_index(output_color_map, color_map_size, transparency_color); if (i) { char extension[] = { 1, // enable transparency 0, 0, // no time delay i // transparency color index }; EGifPutExtension(gif_file, GRAPHICS_EXT_FUNC_CODE, 4, extension); } } if (EGifPutImageDesc(gif_file, 0, 0, width, height, FALSE, NULL) == GIF_ERROR) { throw "EGifPutImageDesc in GifEncoder::encode failed"; } GifByteType *gif_bufp = gif_buf; for (int i = 0; i < height; i++) { if (EGifPutLine(gif_file, gif_bufp, width) == GIF_ERROR) throw "EGifPutLine in GifEncoder::encode failed"; gif_bufp += width; } }