static int CountDroppedFiles( char **ppDroppedItems, int nCount ) { int fileCount = 0; for (int i = 0; i < nCount; ++i ) { fileCount += CountFiles( ppDroppedItems[ i ] ); } return fileCount; }
//Container void ExploreFiles(const Container::Walker& walker) const override { for (uint_t idx = 0, total = CountFiles(); idx < total; ++idx) { const Formats::Chiptune::AY::BlobBuilder::Ptr builder = Formats::Chiptune::AY::CreateFileBuilder(); if (const Formats::Chiptune::Container::Ptr parsed = Formats::Chiptune::AY::Parse(*Delegate, idx, *builder)) { const String subPath = Filename(Text::MULTITRACK_FILENAME_PREFIX, idx).ToString(); const Binary::Container::Ptr subData = builder->Result(); const File file(subPath, subData); walker.OnFile(file); } } }
int CountFiles(CString strFolder, BOOL bSubfolders) { // Declare variables int iCount = 0; CString strFilePath, sPattern; HANDLE hFile; WIN32_FIND_DATA FileInformation; // Get pattern sPattern = strFolder + TEXT("\\*.*"); hFile = ::FindFirstFile(sPattern, &FileInformation); if (hFile != INVALID_HANDLE_VALUE) { do { // Is it something else then current folder? if (FileInformation.cFileName[0] != TEXT('.')) { // Set up path strFilePath = strFolder + TEXT("\\") + FileInformation.cFileName; // Is it a folder? if (FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // Should we search subdirectories too? if (bSubfolders) { // Search subdirectory int iRC = CountFiles(strFilePath, bSubfolders); // Check result of function iCount += iRC; } } else { // Increase counter ++iCount; } } } while (::FindNextFile(hFile, &FileInformation) == TRUE); // Close handle ::FindClose(hFile); } // Return count return iCount; }
static int CountFiles( char *szItem ) { int nCount = 0; WIN32_FIND_DATAA fd; HANDLE hFind = FindFirstFileA( szItem, &fd ); if ( hFind != INVALID_HANDLE_VALUE ) { do { if ( fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ) { // Skip parent directories if (( 0 != strcmp( fd.cFileName, "." )) && ( 0 != strcmp( fd.cFileName, ".." )) ) { char szDirName[MAX_PATH]; strncpy( szDirName, szItem, MAX_PATH - 1); if ( NULL != strstr( szItem, "*.*" )) { size_t offset = strlen( szDirName ) - 3; mir_snprintf(szDirName + offset, SIZEOF( szDirName) - offset, "%s\0", fd.cFileName); } ++nCount; strcat( szDirName, "\\*.*" ); nCount += CountFiles( szDirName ); } } else { ++nCount; } } while( FALSE != FindNextFileA( hFind, &fd )); } return nCount; }
void TProgressThread::CountFiles(LPTSTR sCountPath) { WIN32_FIND_DATA pFILEDATA; HANDLE hFile = FindFirstFile(strcat(sCountPath,"\\*.*"),&pFILEDATA); sCountPath[strlen(sCountPath) - strlen(strstr(sCountPath,"*.*"))] = '\0'; if (hFile!=INVALID_HANDLE_VALUE) { char * chBuf; do { if (strlen(pFILEDATA.cFileName) == 1 && strchr(pFILEDATA.cFileName,'.') !=NULL) if (FindNextFile(hFile,&pFILEDATA) == 0) break; if (strlen(pFILEDATA.cFileName) == 2 && strstr(pFILEDATA.cFileName,"..") !=NULL) if(FindNextFile(hFile,&pFILEDATA) == 0) break; if(pFILEDATA.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { CountFiles(strcat(sCountPath,pFILEDATA.cFileName)); sCountPath[strlen(sCountPath) - strlen(pFILEDATA.cFileName)-1] = '\0'; } else { count++; //TFolderCheck *FoCh = new TFolderCheck(); // Synchronize(TLabelProcess); //FoCh->ccount = 1 ; } } while (FindNextFile(hFile,&pFILEDATA)); } }
void ImageScanThread<DBFS>::run() { RunProlog(); setPriority(QThread::LowPriority); do { // Process all clears before scanning while (ClearsPending()) { m_mutexQueue.lock(); if (m_clearQueue.isEmpty()) break; ClearTask task = m_clearQueue.takeFirst(); m_mutexQueue.unlock(); int devId = task.first; QString action = task.second; LOG(VB_GENERAL, LOG_INFO, QString("Clearing Filesystem: %1 %2").arg(action).arg(devId)); // Clear Db m_dbfs.ClearDb(devId, action); // Pass on to thumb generator now scanning has stopped m_thumb.ClearThumbs(devId, action); } // Scan requested ? if (IsScanning()) { LOG(VB_GENERAL, LOG_INFO, "Starting scan"); // Load known directories and files from the database if (!m_dbfs.ReadAllImages(m_dbFileMap, m_dbDirMap)) // Abort on any Db error break; bool firstScan = m_dbFileMap.isEmpty(); // Pause thumb generator so that scans are fast as possible m_thumb.PauseBackground(true); // Adapter determines list of dirs to scan StringMap paths = m_dbfs.GetScanDirs(); CountFiles(paths.values()); // Now start the actual syncronization m_seenFile.clear(); m_changedImages.clear(); StringMap::const_iterator i = paths.constBegin(); while (i != paths.constEnd() && IsScanning()) { SyncSubTree(QFileInfo(i.value()), GALLERY_DB_ID, i.key(), i.value()); ++i; } // Release thumb generator asap m_thumb.PauseBackground(false); // Adding or updating directories has been completed. // The maps now only contain old directories & files that are not // in the filesystem anymore. Remove them from the database m_dbfs.RemoveFromDB(m_dbDirMap.values()); m_dbfs.RemoveFromDB(m_dbFileMap.values()); // Cleanup thumbnails QStringList mesg(m_thumb.DeleteThumbs(m_dbFileMap.values())); mesg << m_changedImages.join(","); // Cleanup dirs m_dbFileMap.clear(); m_dbDirMap.clear(); m_seenDir.clear(); m_mutexProgress.lock(); // (count == total) signals scan end Broadcast(m_progressTotalCount); // Must reset counts for scan queries m_progressCount = m_progressTotalCount = 0; m_mutexProgress.unlock(); LOG(VB_GENERAL, LOG_INFO, "Finished scan"); // For initial scans pause briefly to give thumb generator a headstart // before being deluged by client requests if (firstScan) msleep(1000); // Notify clients of completion with removed & changed images m_dbfs.Notify("IMAGE_DB_CHANGED", mesg); ChangeState(false); } } while (ClearsPending()); RunEpilog(); }
void Document::read(const OOX::CPath& path, IPPTXEvent* Event) { OOX::CRels rels(path); PPTX::FileMap map; long files = CountFiles(path); if(files == 0) return; m_lPercent = (long)floor(1000000. / files); FileContainer::read(rels, path, map, Event); long percent = Event ? Event->GetPercent() : 0; if(m_bCancelled && percent < 1000000) return; smart_ptr<PPTX::Presentation> _presentation = FileContainer::Get(OOX::Presentation::FileTypes::Presentation).smart_dynamic_cast<PPTX::Presentation>(); if (_presentation.is_init()) { _presentation->commentAuthors = _presentation->Get(OOX::Presentation::FileTypes::CommentAuthors).smart_dynamic_cast<PPTX::Authors>(); if (_presentation->IsExist(OOX::FileTypes::VbaProject)) { _presentation->m_bMacroEnabled = true; _presentation->m_pVbaProject = _presentation->Get(OOX::FileTypes::VbaProject).smart_dynamic_cast<OOX::VbaProject>(); } if (_presentation->IsExist(OOX::FileTypes::JsaProject)) { _presentation->m_pJsaProject = _presentation->Get(OOX::FileTypes::JsaProject).smart_dynamic_cast<OOX::JsaProject>(); } _presentation->comments = _presentation->Get(OOX::Presentation::FileTypes::SlideComments).smart_dynamic_cast<PPTX::Comments>(); } for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::FileTypes::Theme == curType) { smart_ptr<PPTX::Theme> pTheme = pPair->second.smart_dynamic_cast<PPTX::Theme>(); if (pTheme.IsInit()) pTheme->presentation = _presentation; } } for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::Presentation::FileTypes::SlideMaster == curType) { smart_ptr<PPTX::SlideMaster> pointer = pPair->second.smart_dynamic_cast<PPTX::SlideMaster>(); if (pointer.is_init()) pointer->ApplyRels(); } } for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::Presentation::FileTypes::SlideLayout == curType) { smart_ptr<PPTX::SlideLayout> pointer = pPair->second.smart_dynamic_cast<PPTX::SlideLayout>(); if (pointer.is_init()) pointer->ApplyRels(); } } for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::Presentation::FileTypes::Slide == curType) { smart_ptr<PPTX::Slide> pointer = pPair->second.smart_dynamic_cast<PPTX::Slide>(); if (pointer.is_init()) pointer->ApplyRels(); } } for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::Presentation::FileTypes::NotesMaster == curType) { smart_ptr<PPTX::NotesMaster> pointer = pPair->second.smart_dynamic_cast<PPTX::NotesMaster>(); if (pointer.is_init()) pointer->ApplyRels(); } } for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::Presentation::FileTypes::NotesSlide == curType) { smart_ptr<PPTX::NotesSlide> pointer = pPair->second.smart_dynamic_cast<PPTX::NotesSlide>(); if (pointer.is_init()) pointer->ApplyRels(); } } if (Event) Event->Progress(0, 1000000); }
int CreateHelpFile(char* listfile, char* helpfile) { FILE *ifptr, *ofptr; int filecount, i; unsigned csum; ifptr = fopen(listfile, "rb"); if (!ifptr) { printf("Listfile cannot be opened."); return 1; } ofptr = fopen(helpfile, "wb"); if (!ofptr) { fclose(ifptr); printf("Unable to open destination help file."); return 1; } filecount = CountFiles(ifptr); if (filecount == 0) return 0; if ((filecount < 0) || (InitialiseHeader(ofptr, filecount)) || (MoveTextFiles(ifptr, ofptr))) { printf("Error processing listfile.\n"); fclose(ifptr); fclose(ofptr); return 1; } fclose(ifptr); fclose(ofptr); csum = CalculateCheckSum(helpfile); #ifdef VERBOSE printf("Checksum = %X\n", csum); #endif ofptr = fopen(helpfile, "ab"); if (!ofptr) { fclose(ifptr); printf("Unable to open destination help file."); return 1; } fseek(ofptr, 0, SEEK_END); for (i = 0; i < sizeof(unsigned); i++) fputc(*(((char*)(&csum))+i), ofptr); fclose(ofptr); return 0; }
/* Dispatch */ bool pnAuthClient::Dispatch::dispatch(pnSocket* sock) { uint16_t msgId; sock->recv(&msgId, sizeof(uint16_t)); const pnNetMsg* msgDesc = GET_Auth2Cli(msgId); if (msgDesc == NULL) { plDebug::Error("Got invalid message ID (%u)", msgId); return false; } msgparm_t* msgbuf = sock->recvMsg(msgDesc); switch (msgId) { case kAuth2Cli_PingReply: fReceiver->onPingReply(msgbuf[1].fUint, msgbuf[0].fUint); if (msgbuf[2].fUint != 0) plDebug::Debug("Got non-zero payload"); break; case kAuth2Cli_ServerAddr: fReceiver->onServerAddr(msgbuf[0].fUint, NCGetUuid(msgbuf[1])); break; case kAuth2Cli_NotifyNewBuild: fReceiver->onNotifyNewBuild(msgbuf[0].fUint); break; case kAuth2Cli_ClientRegisterReply: fReceiver->onClientRegisterReply(msgbuf[0].fUint); break; case kAuth2Cli_AcctExistsReply: fReceiver->onAcctExistsReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, msgbuf[2].fUint != 0); break; case kAuth2Cli_AcctLoginReply: fReceiver->onAcctLoginReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, NCGetUuid(msgbuf[2]), msgbuf[3].fUint, msgbuf[4].fUint, (const uint32_t*)msgbuf[5].fData); break; // case kAuth2Cli_AcctData: case kAuth2Cli_AcctPlayerInfo: fReceiver->onAcctPlayerInfo(msgbuf[0].fUint, msgbuf[1].fUint, msgbuf[2].fString, msgbuf[3].fString, msgbuf[4].fUint); break; case kAuth2Cli_AcctSetPlayerReply: fReceiver->onAcctSetPlayerReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_AcctCreateReply: fReceiver->onAcctCreateReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, NCGetUuid(msgbuf[2])); break; case kAuth2Cli_AcctChangePasswordReply: fReceiver->onAcctChangePasswordReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_AcctSetRolesReply: fReceiver->onAcctSetRolesReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_AcctSetBillingTypeReply: fReceiver->onAcctSetBillingTypeReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_AcctActivateReply: fReceiver->onAcctActivateReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_AcctCreateFromKeyReply: fReceiver->onAcctCreateFromKeyReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, NCGetUuid(msgbuf[2]), NCGetUuid(msgbuf[3])); break; //case kAuth2Cli_PlayerList: //case kAuth2Cli_PlayerChat: case kAuth2Cli_PlayerCreateReply: fReceiver->onPlayerCreateReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, msgbuf[2].fUint, msgbuf[3].fUint, msgbuf[4].fString, msgbuf[5].fString); break; case kAuth2Cli_PlayerDeleteReply: fReceiver->onPlayerDeleteReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_UpgradeVisitorReply: fReceiver->onUpgradeVisitorReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_SetPlayerBanStatusReply: fReceiver->onSetPlayerBanStatusReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_ChangePlayerNameReply: fReceiver->onChangePlayerNameReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_SendFriendInviteReply: fReceiver->onSendFriendInviteReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; //case kAuth2Cli_FriendNotify: case kAuth2Cli_VaultNodeCreated: fReceiver->onVaultNodeCreated(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, msgbuf[2].fUint); break; case kAuth2Cli_VaultNodeFetched: { ENetError result = (ENetError)msgbuf[1].fUint; pnVaultNode node; if (result == kNetSuccess) node.read(msgbuf[3].fData, msgbuf[2].fUint); fReceiver->onVaultNodeFetched(msgbuf[0].fUint, result, node); } break; case kAuth2Cli_VaultNodeChanged: fReceiver->onVaultNodeChanged(msgbuf[0].fUint, NCGetUuid(msgbuf[1])); break; case kAuth2Cli_VaultNodeDeleted: fReceiver->onVaultNodeDeleted(msgbuf[0].fUint); break; case kAuth2Cli_VaultNodeAdded: fReceiver->onVaultNodeAdded(msgbuf[0].fUint, msgbuf[1].fUint, msgbuf[2].fUint); break; case kAuth2Cli_VaultNodeRemoved: fReceiver->onVaultNodeRemoved(msgbuf[0].fUint, msgbuf[1].fUint); break; case kAuth2Cli_VaultNodeRefsFetched: { size_t numRefs = msgbuf[2].fUint; pnVaultNodeRef* refs = new pnVaultNodeRef[numRefs]; for (size_t i=0; i<numRefs; i++) refs[i].read(msgbuf[3].fData + (i * pnVaultNodeRef::Stride)); fReceiver->onVaultNodeRefsFetched(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, numRefs, refs); delete[] refs; } break; case kAuth2Cli_VaultInitAgeReply: fReceiver->onVaultInitAgeReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, msgbuf[2].fUint, msgbuf[3].fUint); break; case kAuth2Cli_VaultNodeFindReply: fReceiver->onVaultNodeFindReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, msgbuf[2].fUint, (const uint32_t*)msgbuf[3].fData); break; case kAuth2Cli_VaultSaveNodeReply: fReceiver->onVaultSaveNodeReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_VaultAddNodeReply: fReceiver->onVaultAddNodeReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_VaultRemoveNodeReply: fReceiver->onVaultRemoveNodeReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_AgeReply: fReceiver->onAgeReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, msgbuf[2].fUint, NCGetUuid(msgbuf[3]), msgbuf[4].fUint, msgbuf[5].fUint); break; case kAuth2Cli_AgeReplyEx: fReceiver->onAgeReplyEx(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, msgbuf[2].fUint, NCGetUuid(msgbuf[3]), msgbuf[4].fUint, msgbuf[5].fString); break; case kAuth2Cli_FileListReply: { size_t count = CountFiles(msgbuf[2].fUint, msgbuf[3].fString); pnAuthFileItem* files = new pnAuthFileItem[count]; GetFileList(files, msgbuf[2].fUint, msgbuf[3].fString); fReceiver->onFileListReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, count, files); delete[] files; } break; case kAuth2Cli_FileDownloadChunk: fReceiver->onFileDownloadChunk(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, msgbuf[2].fUint, msgbuf[3].fUint, msgbuf[4].fUint, msgbuf[5].fData); fReceiver->sendFileDownloadChunkAck(msgbuf[0].fUint); break; case kAuth2Cli_KickedOff: fReceiver->onKickedOff(msgbuf[0].fUint); break; case kAuth2Cli_PublicAgeList: { size_t ageCount = msgbuf[2].fUint; pnNetAgeInfo* ages = new pnNetAgeInfo[ageCount]; for (size_t i=0; i<ageCount; i++) ages[i].read(msgbuf[3].fData + (i * pnNetAgeInfo::Stride)); fReceiver->onPublicAgeList(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, ageCount, ages); delete[] ages; } break; case kAuth2Cli_ScoreCreateReply: fReceiver->onScoreCreateReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, msgbuf[2].fUint, msgbuf[3].fUint); break; case kAuth2Cli_ScoreDeleteReply: fReceiver->onScoreDeleteReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_ScoreGetScoresReply: { size_t scoreCount = msgbuf[2].fUint; pnNetGameScore* scores = new pnNetGameScore[scoreCount]; const uint8_t* buf = msgbuf[3].fData; for (size_t i=0; i<scoreCount; i++) { scores[i].fScoreId = *(uint32_t*)(buf ); scores[i].fOwnerId = *(uint32_t*)(buf + 4); scores[i].fCreatedTime = *(uint32_t*)(buf + 8); scores[i].fGameType = *(uint32_t*)(buf + 12); scores[i].fValue = *(int32_t* )(buf + 16); size_t strDataSize = *(uint32_t*)(buf + 20); scores[i].fGameName = (const pl_wchar_t*)(buf + 24); buf += 24 + strDataSize; } fReceiver->onScoreGetScoresReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, scoreCount, scores); delete[] scores; } break; case kAuth2Cli_ScoreAddPointsReply: fReceiver->onScoreAddPointsReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_ScoreTransferPointsReply: fReceiver->onScoreTransferPointsReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_ScoreSetPointsReply: fReceiver->onScoreSetPointsReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint); break; case kAuth2Cli_ScoreGetRanksReply: { size_t rankCount = msgbuf[2].fUint; pnNetGameRank* ranks = new pnNetGameRank[rankCount]; const uint8_t* buf = msgbuf[3].fData; for (size_t i=0; i<rankCount; i++) { ranks[i].fRank = *(uint32_t*)(buf ); ranks[i].fScore = *(uint32_t*)(buf + 4); size_t strDataSize = *(uint32_t*)(buf + 8); ranks[i].fName = (const pl_wchar_t*)(buf + 12); buf += 12 + strDataSize; } fReceiver->onScoreGetRanksReply(msgbuf[0].fUint, (ENetError)msgbuf[1].fUint, rankCount, ranks); delete[] ranks; } break; case kAuth2Cli_PropagateBuffer: { hsRAMStream rs(PlasmaVer::pvMoul); rs.copyFrom(msgbuf[2].fData, msgbuf[1].fUint); fReceiver->fResMgr->lock(); plCreatable* pCre = NULL; try { pCre = fReceiver->fResMgr->ReadCreatable(&rs, true, msgbuf[1].fUint); } catch (hsException& ex) { plDebug::Error("Error reading propagated message: %s\n", ex.what()); delete pCre; pCre = NULL; } fReceiver->fResMgr->unlock(); if (pCre != NULL) { fReceiver->onPropagateMessage(pCre); if (fDeleteMsgs) delete pCre; } else { plDebug::Error("Ignored propagated message [%04X]%s", pdUnifiedTypeMap::PlasmaToMapped(msgbuf[0].fUint, PlasmaVer::pvMoul), pdUnifiedTypeMap::ClassName(msgbuf[0].fUint, PlasmaVer::pvMoul)); } } break; } NCFreeMessage(msgbuf, msgDesc); return true; }