QByteArray uncompress( const QByteArray& data ) { if ( data.size()>2 && (data.at(0) != gz_magic_0 || data.at(1) != gz_magic_1) ) { qWarning( "gz: data to be uncompressed doesn't look like gzip format" ); } return uncompress_( reinterpret_cast<const uchar*>( data.constData() ), data.size() ); }
KDvoid AssetsManager::update ( KDvoid ) { // 1. Urls of package and version should be valid; // 2. Package should be a zip file. if ( m_sVersionFileUrl.size ( ) == 0 || m_sPackageUrl.size ( ) == 0 || std::string::npos == m_sPackageUrl.find ( ".zip" ) ) { CCLOG ( "no version file url, or no package url, or the package is not a zip file" ); return; } // Check if there is a new version. if ( !checkUpdate ( ) ) { return; } // Is package already downloaded? std::string sDownloadedVersion = CCUserDefault::sharedUserDefault ( )->getStringForKey ( KEY_OF_DOWNLOADED_VERSION ); if ( sDownloadedVersion != m_sVersion ) { if ( !downLoad ( ) ) { return; } // Record downloaded version. CCUserDefault::sharedUserDefault ( )->setStringForKey ( KEY_OF_DOWNLOADED_VERSION, m_sVersion.c_str ( ) ); CCUserDefault::sharedUserDefault ( )->flush ( ); } // Uncompress zip file. if ( !uncompress_ ( ) ) { return; } // Record new version code. CCUserDefault::sharedUserDefault ( )->setStringForKey ( KEY_OF_VERSION, m_sVersion.c_str ( ) ); // Unrecord downloaded version code. CCUserDefault::sharedUserDefault ( )->setStringForKey ( KEY_OF_DOWNLOADED_VERSION, "" ); CCUserDefault::sharedUserDefault ( )->flush ( ); // Set resource search path. setSearchPath ( ); // Delete unloaded zip file. std::string sZipfileName = m_sStoragePath + TEMP_PACKAGE_FILE_NAME; if ( kdRemove ( sZipfileName.c_str ( ) ) != 0 ) { CCLOG ( "can not remove downloaded zip file" ); } }