void CWmvSearch::Mount(CArcFile* archive) { SFileInfo file_info; // Get start address file_info.start = archive->GetArcPointer(); archive->Seek(GetHeaderSize(), FILE_CURRENT); // Search the auxiliary header if (!SearchFooter(archive)) return; // Amount of progress advanced by the search bar const u64 search_offset = archive->GetArcPointer() - file_info.start - GetHeaderSize(); // Get file size archive->Seek(23, FILE_CURRENT); archive->Read(&file_info.sizeOrg, 4); file_info.sizeCmp = file_info.sizeOrg; // Get exit address file_info.end = file_info.start + file_info.sizeOrg; // Go to the end of the WMV file archive->Seek(file_info.end, FILE_BEGIN); archive->GetProg()->UpdatePercent(file_info.sizeOrg - search_offset); archive->AddFileInfo(file_info, GetNumFiles(), _T(".wmv")); }
bool WUploadThread::IsLastFile() { int c = GetCurrentNum() + 1; int n = GetNumFiles(); return (c >= n); }
void OnStart( const std::string& RootPath ) { auto FS = make_intrusive<clFileSystem>(); FS->Mount( "" ); FS->Mount( RootPath ); FS->AddAliasMountPoint( RootPath, "assets" ); const char* ArchiveName = "test.zip"; auto File = FS->CreateReader( ArchiveName ); auto Reader = make_intrusive<clArchiveReader>(); if ( !Reader->OpenArchive( File ) ) { LOGI( "Bad archive: %s", ArchiveName ); return; } /// Iterate the files in archive for ( size_t i = 0; i != Reader->GetNumFiles(); i++ ) { LOGI( "File[%i]: %s", i, Reader->GetFileName( i ).c_str() ); const char* Data = reinterpret_cast<const char*>( Reader->GetFileDataIdx( i ) ); LOGI( "Data: %s", std::string( Data, static_cast<size_t>( Reader->GetFileSizeIdx( i ) ) ).c_str() ); } }
void CMpgSearch::Mount(CArcFile* archive) { // Corresponds to CVM LPCTSTR file_extension = (lstrcmpi(archive->GetArcExten(), _T(".cvm")) == 0) ? _T(".sfd") : _T(".mpg"); SFileInfo file_info; // Get start address file_info.start = archive->GetArcPointer(); archive->Seek(GetHeaderSize(), FILE_CURRENT); archive->GetProg()->UpdatePercent(GetHeaderSize()); // Get footer if (!SearchFooter(archive)) return; // Get exit address file_info.end = archive->GetArcPointer(); // Get file size file_info.sizeOrg = file_info.end - file_info.start; file_info.sizeCmp = file_info.sizeOrg; archive->AddFileInfo(file_info, GetNumFiles(), file_extension); }
void CAhxSearch::Mount(CArcFile* archive) { SFileInfo file_info; // Get start address file_info.start = archive->GetArcPointer(); // Get file ssize archive->Seek(GetHeaderSize() + 2, FILE_CURRENT); archive->Read(&file_info.sizeOrg, 4); file_info.sizeOrg = BitUtils::Swap32(file_info.sizeOrg) << 1; archive->GetProg()->UpdatePercent(4); // Search footer if (!SearchFooter(archive)) return; // Get exit address file_info.end = archive->GetArcPointer(); // Get compressedfile size file_info.sizeCmp = file_info.end - file_info.start; archive->AddFileInfo(file_info, GetNumFiles(), _T(".ahx")); }
//----------------------------------------------------------------------------- // Purpose: // Input : index - // Output : char const //----------------------------------------------------------------------------- char const *CLoadDialog::GetFile( int index ) { if ( index < 0 || index >= GetNumFiles() ) { return ""; } return m_FileNames[ index ].fn; }
void CMidSearch::Mount(CArcFile* archive) { SFileInfo file_info; // Get the head position file_info.start = archive->GetArcPointer(); // Get the number of tracks u16 tracks; archive->SeekCur(GetHeaderSize() + 2); archive->ReadU16(&tracks); tracks = BitUtils::Swap16(tracks); archive->SeekCur(2); // Get end positions for (unsigned short cnt = 0; cnt < tracks; cnt++) { std::array<u8, 4> marker; archive->Read(marker.data(), marker.size()); // Invalid MIDI if (std::memcmp(marker.data(), "MTrk", marker.size()) != 0) { return; } // Get track size u32 track_size; archive->ReadU32(&track_size); track_size = BitUtils::Swap32(track_size); // Advance to next track archive->SeekCur(track_size); } file_info.end = archive->GetArcPointer(); // Get file size file_info.size_org = file_info.end - file_info.start; file_info.size_cmp = file_info.size_org; // Update progress bar archive->GetProg()->UpdatePercent(file_info.size_org); archive->AddFileInfo(file_info, GetNumFiles(), _T(".mid")); }
void TimeGridWindCurv::Draw(Rect r, WorldRect view, double refScale, double arrowScale,double arrowDepth, Boolean bDrawArrows, Boolean bDrawGrid, RGBColor arrowColor) { // use for curvilinear WorldPoint wayOffMapPt = {-200*1000000,-200*1000000}; double timeAlpha; Point p; Rect c; Seconds startTime,endTime; Seconds time = model->GetModelTime(); OSErr err = 0; char errmsg[256]; RGBForeColor(&arrowColor); if(bDrawArrows || bDrawGrid) { if (bDrawGrid) // make sure to draw grid even if don't draw arrows { ((TTriGridVel*)fGrid)->DrawCurvGridPts(r,view); //return; } if (bDrawArrows) { // we have to draw the arrows long numVertices,i; LongPointHdl ptsHdl = 0; long timeDataInterval; Boolean loaded; TTriGridVel* triGrid = (TTriGridVel*)fGrid; err = this -> SetInterval(errmsg, model->GetModelTime()); // AH 07/17/2012 if(err) return; loaded = this -> CheckInterval(timeDataInterval, model->GetModelTime()); // AH 07/17/2012 if(!loaded) return; ptsHdl = triGrid -> GetPointsHdl(); if(ptsHdl) numVertices = _GetHandleSize((Handle)ptsHdl)/sizeof(**ptsHdl); else numVertices = 0; // Check for time varying wind if( (GetNumTimesInFile()>1 || GetNumFiles()>1 )&& loaded && !err) { // Calculate the time weight factor startTime = (*fTimeHdl)[fStartData.timeIndex] + fTimeShift; //endTime = (*fTimeHdl)[fEndData.timeIndex] + fTimeShift; //timeAlpha = (endTime - time)/(double)(endTime - startTime); if (fEndData.timeIndex == UNASSIGNEDINDEX && (time > startTime || time < startTime) && fAllowExtrapolationInTime) { timeAlpha = 1; } else { //return false; endTime = (*fTimeHdl)[fEndData.timeIndex] + fTimeShift; timeAlpha = (endTime - time)/(double)(endTime - startTime); } } for(i = 0; i < numVertices; i++) { // get the value at each vertex and draw an arrow LongPoint pt = INDEXH(ptsHdl,i); long ptIndex=-1,iIndex,jIndex; WorldPoint wp,wp2; Point p,p2; VelocityRec velocity = {0.,0.}; Boolean offQuickDrawPlane = false; wp.pLat = pt.v; wp.pLong = pt.h; ptIndex = INDEXH(fVerdatToNetCDFH,i); iIndex = ptIndex/(fNumCols+1); jIndex = ptIndex%(fNumCols+1); if (iIndex>0 && jIndex<fNumCols) ptIndex = (iIndex-1)*(fNumCols)+jIndex; else ptIndex = -1; // for now draw arrow at midpoint of diagonal of gridbox // this will result in drawing some arrows more than once if (GetLatLonFromIndex(iIndex-1,jIndex+1,&wp2)!=-1) // may want to get all four points and interpolate { wp.pLat = (wp.pLat + wp2.pLat)/2.; wp.pLong = (wp.pLong + wp2.pLong)/2.; } p = GetQuickDrawPt(wp.pLong, wp.pLat, &r, &offQuickDrawPlane); // should put velocities in center of grid box // Should check vs fFillValue // Check for constant wind if( (( GetNumTimesInFile()==1 &&!(GetNumFiles()>1) ) || timeAlpha == 1) && ptIndex!=-1) { velocity.u = INDEXH(fStartData.dataHdl,ptIndex).u; velocity.v = INDEXH(fStartData.dataHdl,ptIndex).v; } else if (ptIndex!=-1)// time varying wind { // need to rescale velocities for Navy case, store angle velocity.u = timeAlpha*INDEXH(fStartData.dataHdl,ptIndex).u + (1-timeAlpha)*INDEXH(fEndData.dataHdl,ptIndex).u; velocity.v = timeAlpha*INDEXH(fStartData.dataHdl,ptIndex).v + (1-timeAlpha)*INDEXH(fEndData.dataHdl,ptIndex).v; } if ((velocity.u != 0 || velocity.v != 0) && (velocity.u != fFillValue && velocity.v != fFillValue)) { float inchesX = (velocity.u * refScale) / arrowScale; float inchesY = (velocity.v * refScale) / arrowScale; short pixX = inchesX * PixelsPerInchCurrent(); short pixY = inchesY * PixelsPerInchCurrent(); p2.h = p.h + pixX; p2.v = p.v - pixY; MyMoveTo(p.h, p.v); MyLineTo(p2.h, p2.v); MyDrawArrow(p.h,p.v,p2.h,p2.v); } } } } if (bDrawGrid) fGrid->Draw(r,view,wayOffMapPt,refScale,arrowScale,0.,false,true,arrowColor); RGBForeColor(&colors[BLACK]); }
void TimeGridWindRect::Draw(Rect r, WorldRect view, double refScale, double arrowScale,double arrowDepth, Boolean bDrawArrows, Boolean bDrawGrid, RGBColor arrowColor) { // Use this for regular grid short row, col, pixX, pixY; long dLong, dLat, index, timeDataInterval; float inchesX, inchesY; double timeAlpha; Seconds startTime, endTime, time = model->GetModelTime(); Point p, p2; WorldPoint wp; WorldRect boundsRect, bounds; VelocityRec velocity; Rect c, newGridRect = {0, 0, fNumRows - 1, fNumCols - 1}; // fNumRows, fNumCols members of TimeGridVel Boolean offQuickDrawPlane = false, loaded; char errmsg[256]; OSErr err = 0; TRectGridVel* rectGrid = (TRectGridVel*)fGrid; if (!bDrawArrows && !bDrawGrid) return; bounds = rectGrid->GetBounds(); // need to get the bounds from the grid dLong = (WRectWidth(bounds) / fNumCols) / 2; dLat = (WRectHeight(bounds) / fNumRows) / 2; //RGBForeColor(&colors[PURPLE]); RGBForeColor(&arrowColor); boundsRect = bounds; InsetWRect (&boundsRect, dLong, dLat); if (bDrawArrows) { err = this -> SetInterval(errmsg, model->GetModelTime()); // AH 07/17/2012 if(err && !bDrawGrid) return; // want to show grid even if there's no wind data loaded = this -> CheckInterval(timeDataInterval, model->GetModelTime()); if(!loaded && !bDrawGrid) return; if((GetNumTimesInFile()>1 || GetNumFiles()>1) && loaded && !err) { // Calculate the time weight factor if (GetNumFiles()>1 && fOverLap) startTime = fOverLapStartTime + fTimeShift; else startTime = (*fTimeHdl)[fStartData.timeIndex] + fTimeShift; if (fEndData.timeIndex == UNASSIGNEDINDEX && (time > startTime || time < startTime) && fAllowExtrapolationInTime) { timeAlpha = 1; } else { //return false; endTime = (*fTimeHdl)[fEndData.timeIndex] + fTimeShift; timeAlpha = (endTime - time)/(double)(endTime - startTime); } } } for (row = 0 ; row < fNumRows ; row++) for (col = 0 ; col < fNumCols ; col++) { SetPt(&p, col, row); wp = ScreenToWorldPoint(p, newGridRect, boundsRect); velocity.u = velocity.v = 0.; if (loaded && !err) { index = dynamic_cast<TimeGridWindRect *>(this)->GetVelocityIndex(wp); if (bDrawArrows && index >= 0) { // Check for constant wind pattern if((GetNumTimesInFile()==1 && !(GetNumFiles()>1)) || timeAlpha==1) { velocity.u = INDEXH(fStartData.dataHdl,index).u; velocity.v = INDEXH(fStartData.dataHdl,index).v; } else // time varying wind { velocity.u = timeAlpha*INDEXH(fStartData.dataHdl,index).u + (1-timeAlpha)*INDEXH(fEndData.dataHdl,index).u; velocity.v = timeAlpha*INDEXH(fStartData.dataHdl,index).v + (1-timeAlpha)*INDEXH(fEndData.dataHdl,index).v; } } } p = GetQuickDrawPt(wp.pLong, wp.pLat, &r, &offQuickDrawPlane); MySetRect(&c, p.h - 1, p.v - 1, p.h + 1, p.v + 1); if (bDrawGrid && bDrawArrows && (velocity.u != 0 || velocity.v != 0)) PaintRect(&c); // should check fill_value if (bDrawGrid && !bDrawArrows) PaintRect(&c); // should check fill_value if (bDrawArrows && (velocity.u != 0 || velocity.v != 0)) { inchesX = (velocity.u * refScale) / arrowScale; inchesY = (velocity.v * refScale) / arrowScale; pixX = inchesX * PixelsPerInchCurrent(); pixY = inchesY * PixelsPerInchCurrent(); p2.h = p.h + pixX; p2.v = p.v - pixY; MyMoveTo(p.h, p.v); MyLineTo(p2.h, p2.v); MyDrawArrow(p.h,p.v,p2.h,p2.v); } } RGBForeColor(&colors[BLACK]); }
void CLoadDialog::OnOK() { UpdateData( TRUE ); m_nFlags = DetermineFlags(); // Create list of filenames, if possible CButton *radioByDate = static_cast< CButton * >( GetDlgItem( IDC_LOADBYDATE ) ); if ( radioByDate && radioByDate->GetCheck() == 1 ) { m_FileNames.RemoveAll(); // Use dates to determine filename, otherwise, clicking the "choose files button probably // created a list for us char const *starttime = m_strStartDate; char const *endtime = m_strEndDate; int m1, d1, y1; int m2, d2, y2; if ( SuckTimeFromString( starttime, &m1, &d1, &y1 ) && SuckTimeFromString( endtime, &m2, &d2, &y2 ) ) { struct tm t1; struct tm t2; if ( ComposeDate( &t1, m1, d1, y1 ) && ComposeDate( &t2, m2, d2, y2 ) ) { time_t start = mktime( &t1 ); time_t end = mktime( &t2 ); if ( start > end ) { time_t temp = start; start = end; end = temp; } if ( difftime( end, start ) < FIVE_YEARS ) { // Create file list m_FileNames.RemoveAll(); for ( time_t t = start; t <= (time_t)( end + FSECONDS_PER_DAY ) || m_pStatus->IsInSameDay( t, end ) ; t += (int)FSECONDS_PER_DAY ) { char const *fname = m_pStatus->FileNameForTime( t ); ASSERT( fname ); int i = m_FileNames.AddToTail(); ASSERT( m_FileNames.IsValidIndex( i ) ); FilenameList *entry = &m_FileNames[ i ]; strncpy( entry->fn, fname, sizeof( entry->fn ) ); entry->fn[ sizeof( entry->fn ) - 1 ] = 0; } char sz[ 512 ]; sprintf( sz, "(%i) files in list.", GetNumFiles() ); m_staticNumFiles.SetWindowText( sz ); } } } } CDialog::OnOK(); }
void BackUpFiles() { int num_files = GetNumFiles(DIRECTORY); int i = 0; pthread_t threads[num_files]; struct stat statbuf; DIR *cwd = opendir(DIRECTORY); struct dirent * file; int total_files = 0; while ( (file = readdir(cwd) ) != NULL ) { if(strcmp(file->d_name,".") != 0) if(strcmp(file->d_name,"..") != 0) if(strcmp(file->d_name,".mybackup") != 0) if(strcmp(file->d_name,"multithread_backup.c") != 0) if(strcmp(file->d_name,"a.out") != 0) { total_files++; char* full_dir = DirAppend(DIRECTORY,file->d_name); if(lstat(full_dir, &statbuf) == 0) { if (S_ISDIR(statbuf.st_mode)) { // printf("DIR found: %s\n",file->d_name); struct file_info * backup = (struct file_info *)malloc(sizeof(struct file_info)); backup->name = file->d_name; backup->to = BACKUP_DIRECTORY; backup->from = DirAppend(DIRECTORY,file->d_name); int rc = pthread_create(&threads[i], NULL, Thread_BackupDir, backup); if (rc != 0) { fprintf( stderr, "pthread_create() failed (%d): %s", rc, strerror( rc ) ); exit(EXIT_FAILURE); } i++; } else { struct file_info * backup = (struct file_info *)malloc(sizeof(struct file_info)); backup->name = file->d_name; backup->to = BACKUP_DIRECTORY; backup->from = DirAppend(DIRECTORY,file->d_name); int rc = pthread_create(&threads[i], NULL, Thread_BackupFile, backup); if (rc != 0) { fprintf( stderr, "pthread_create() failed (%d): %s", rc, strerror( rc ) ); exit(EXIT_FAILURE); } i++; //printf("File found: %s\n", file->d_name); } } free(full_dir); } } closedir(cwd); int total_bytes = 0; total_files = i; for(i=0;i<num_files;i++) { int *x; pthread_join(threads[i], (void*)&x); total_bytes += *x; total_files += x[1]; free(x); } printf("Successfully created %d files (%d bytes).\n",total_files,total_bytes ); }
void RestoreFiles() { int num_files = GetNumFiles(BACKUP_DIRECTORY); int i = 0; pthread_t threads[num_files]; struct stat statbuf; DIR *cwd = opendir(BACKUP_DIRECTORY); struct dirent * file; int total_files =0; if(cwd == NULL) { perror("Error, .mybackup does not exist. Backup files before attempting to restore.\n"); exit(EXIT_FAILURE); } while ( (file = readdir(cwd) ) != NULL ) { if(strcmp(file->d_name,".") != 0) if(strcmp(file->d_name,"..") != 0) if(strcmp(file->d_name,".mybackup") != 0) if(strcmp(file->d_name,"multithread_backup.c") != 0) if(strcmp(file->d_name,"a.out") != 0) { char* full_dir = DirAppend(BACKUP_DIRECTORY,file->d_name); if(lstat(full_dir, &statbuf) == 0) { if (S_ISDIR(statbuf.st_mode)) { struct file_info * backup = (struct file_info *)malloc(sizeof(struct file_info)); backup->name = file->d_name; backup->to = DIRECTORY; backup->from = DirAppend(BACKUP_DIRECTORY,file->d_name); int rc = pthread_create(&threads[i], NULL, Thread_RestoreDir, backup); if (rc != 0) { fprintf( stderr, "pthread_create() failed (%d): %s", rc, strerror( rc ) ); exit(EXIT_FAILURE); } i++; printf("Folder found to restore: %s\n",file->d_name ); } else { struct file_info * backup = (struct file_info *)malloc(sizeof(struct file_info)); backup->name = file->d_name; backup->to = DIRECTORY; backup->from = DirAppend(BACKUP_DIRECTORY,file->d_name); int rc = pthread_create(&threads[i], NULL, Thread_RestoreFile, backup); if (rc != 0) { fprintf( stderr, "pthread_create() failed (%d): %s", rc, strerror( rc ) ); exit(EXIT_FAILURE); } i++; } }} } closedir(cwd); int total_bytes = 0; total_files = i; for(i=0;i<num_files;i++) { int *x; pthread_join(threads[i], (void*)&x); total_bytes += *x; total_files+= x[1]; free(x); } printf("Successfully restored %d files (%d bytes).\n",total_files,total_bytes ); }
void * Thread_RestoreDir(void * arg) { unsigned int * num_bytes = (unsigned int *)malloc( sizeof( unsigned int ) *2 ); *num_bytes = 0; struct file_info * info = (struct file_info *)(arg); info->num_files = 0; char* new_dir = DirAppend(info->to,info->name); printf("[thread %u] Restoring %s...\n",(unsigned int)pthread_self(),info->name ); mkdir(new_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); printf("[thread %u] Created %s (or it already existed)\n",(unsigned int)pthread_self(),info->name ); int num_files = GetNumFiles(info->from); int i = 0; pthread_t threads[num_files]; struct stat statbuf; DIR *cwd = opendir(info->from); struct dirent * file; //************************************************************************************************** while ( (file = readdir(cwd) ) != NULL ) { if(strcmp(file->d_name,".") != 0) if(strcmp(file->d_name,"..") != 0) if(strcmp(file->d_name,".mybackup") != 0) if(strcmp(file->d_name,"multithread_backup.c") != 0) if(strcmp(file->d_name,"a.out") != 0) { info->num_files++; char* full_dir = DirAppend(info->from,file->d_name); if(lstat(full_dir, &statbuf) == 0) { if (S_ISDIR(statbuf.st_mode)) { struct file_info * backup = (struct file_info *)malloc(sizeof(struct file_info)); backup->name = file->d_name; backup->to = new_dir; backup->from = DirAppend(info->from,file->d_name); int rc = pthread_create(&threads[i], NULL, Thread_RestoreDir, backup); if (rc != 0) { fprintf( stderr, "pthread_create() failed (%d): %s", rc, strerror( rc ) ); exit(EXIT_FAILURE); } i++; } else { struct file_info * backup = (struct file_info *)malloc(sizeof(struct file_info)); backup->name = file->d_name; backup->to = new_dir; backup->from = DirAppend(info->from,file->d_name); int rc = pthread_create(&threads[i], NULL, Thread_RestoreFile, backup); if (rc != 0) { fprintf( stderr, "pthread_create() failed (%d): %s", rc, strerror( rc ) ); exit(EXIT_FAILURE); } i++; } } free(full_dir); } } closedir(cwd); //************************************************************************************************** num_bytes[1] = i +1; for(i=0;i<num_files;i++) { int *x; pthread_join(threads[i], (void*)&x); *num_bytes += *x; free(x); } pthread_exit(num_bytes); return NULL; }