// ======================================================================================================= // // ============================================ UI COMMANDS ============================================== // // ======================================================================================================= // void ImageLoader::keep_image(int i) { BingImage* image = m_todaysImages->get(i); QString path = image->filePath(); // 20 is the length of any file name (10 characters for the date, 6 for the market, 4 for the extension) QStringRef fileNameNoPath(&path, path.length() - 20, 16); QStringRef currentFolder(&path, 0, path.length() - 20); if (currentFolder == SettingsHandler::TempImagesFolder) { QString destinationPath = SettingsHandler::ImagesFolder + fileNameNoPath.toString() + SettingsHandler::ImageExtension; int n = 0; while (QFile::exists(destinationPath)) destinationPath = SettingsHandler::ImagesFolder + fileNameNoPath.toString() + "_" + QString::number(n++) + SettingsHandler::ImageExtension; if (!QFile::rename(path, destinationPath)) { emit problems("Could not move the image to the main folder! It will be removed upon quitting the program if you don't manually move it"); return; } image->set_filePath(destinationPath); m_todaysImages->remove(i); m_allImages->prepend(image); } }
VError VArchiveStream::Proceed() { bool userAbort = false; VError result = VE_OK; //Iterate over our various list and check for duplicates /* ACI0077162, Jul 11th 2012, O.R.: add some calls to the progress callback here in order to allow user feedback, in case of lengthy process (e.g. many files/folders to add)*/ if (fCallBack) { fCallBack(CB_OpenProgressUndetermined,0,0,userAbort); } VectorOfPaths::iterator folderIterator = fFolderPathList.begin(); VectorOfVString::iterator folderInfoIterator = fFolderExtra.begin(); xbox_assert(fFolderPathList.size() == fFolderExtra.size()); for ( uLONG i = 0; i < fFolderPathList.size() && result == VE_OK && !userAbort; i++ ) { const VFilePath& folderPath = fFolderPathList[i];//(*folderIterator); const VFilePath& sourceFolderPath = fSourceFolderForFolders[i];//(*folderIterator); const VString& folderExtraInfo = folderInfoIterator[i];//(*folderInfoIterator); VFolder currentFolder(folderPath); result = _AddOneFolder(currentFolder,sourceFolderPath,folderExtraInfo); } if ( fStream && result == VE_OK && !userAbort) { result = fStream->OpenWriting(); if ( result == VE_OK ) { sLONG8 offset; sLONG8 fileSize; sLONG8 byteCount; uLONG8 totalByteCount = 0; uLONG8 partialByteCount = 0; /* put the backup file signature */ fStream->PutLong('FPBK'); /* put the current version of the file */ fStream->PutByte(4); /* put the number of file stored in this archive */ sLONG8 storedObjCount = (sLONG8)fFileList.size(); storedObjCount += (sLONG8)fFileDescList.size(); fStream->PutLong8(storedObjCount /*(sLONG8)(fFileList.size()+fFileDescList.size())*/); /* put the header of the file listing */ fStream->PutLong('LIST'); for ( uLONG i = 0; i < fFileDescList.size() && result == VE_OK && !userAbort; i++ ) { result = _WriteCatalog(fFileDescList[i]->GetParentVFile(),fSourceFolderForFileDescs[i],fFileDescExtra[i],totalByteCount); if ( fCallBack ) { fCallBack(CB_UpdateProgress,0,0,userAbort); } } for ( uLONG i = 0; i < fFileList.size() && result == VE_OK && !userAbort; i++ ) { result = _WriteCatalog(fFileList[i],fSourceFolderForFiles[i],fFileExtra[i],totalByteCount); if ( fCallBack ) { fCallBack(CB_UpdateProgress,0,0,userAbort); } } //ACI0077162, Jul 11th 2012, O.R.: Close unbound session and open a bounded one for file processing if ( fCallBack ) { fCallBack(CB_CloseProgress,0,0,userAbort); fCallBack(CB_OpenProgress,partialByteCount,totalByteCount,userAbort); } VSize bufferSize = 1024*1024; char *buffer = new char[bufferSize]; /* writing file descriptor that we have to the archive files */ /* nota : filedesc passed to the archivestream is considered as data fork */ //ACI0077162, Jul 11th 2012, O.R.: _WriteFile() in charge of calling progress CB to give reactivity to upper layers for( VectorOfVFileDesc::iterator i = fFileDescList.begin() ; result == VE_OK && i != fFileDescList.end() && !userAbort ; ++i) { StErrorContextInstaller errors( false); result = fStream->PutLong('Fdat'); if ( result == VE_OK ) { result = (*i)->SetPos(0); if ( result == VE_OK ) result = _WriteFile( (*i), buffer, bufferSize, partialByteCount, totalByteCount ); } if ( result == VE_OK ) result = fStream->PutLong('Frez'); if ( result == VE_OK ) result = fStream->PutLong8(0); } for( VectorOfVFile::iterator i = fFileList.begin() ; result == VE_OK && i != fFileList.end() && !userAbort ; ++i ) { StErrorContextInstaller errors( false); VFileDesc *fileDesc = NULL; result = fStream->PutLong('Fdat'); if ( result == VE_OK ) { result = (*i)->Open(FA_READ,&fileDesc); if ( fileDesc ) { result = _WriteFile( fileDesc, buffer, bufferSize, partialByteCount, totalByteCount ); delete fileDesc; fileDesc = NULL; } else { result = fStream->PutLong8(0); } } if ( result == VE_OK ) result = fStream->PutLong('Frez'); if ( result == VE_OK ) { #if VERSIONMAC result = (*i)->Open(FA_READ,&fileDesc,FO_OpenResourceFork); if ( fileDesc ) { result = _WriteFile( fileDesc, buffer, bufferSize, partialByteCount, totalByteCount ); delete fileDesc; fileDesc = NULL; } else #endif { result = fStream->PutLong8(0); } } } delete[] buffer; fStream->CloseWriting(); } } //ACI0077162, Jul 11th 2012, O.R.: close remaining session (either unbounded one for check files or bounded one for processing files) if ( fCallBack ) fCallBack(CB_CloseProgress,0,0,userAbort); if (userAbort) { result = XBOX::VE_STREAM_USER_ABORTED; } return result; }