void Explorer_rebuildRoms (const t_fslist * filenames) { t_fslist * nnode = (t_fslist *) filenames; t_fslist * tmpnode = NULL; WiiStatus.nRoms = 0; while(nnode->fnext != NULL){ //cuenta numero de roms if(nnode->gfile.location == 0) { tmpnode = nnode->fnext; if(tmpnode->fnext == NULL){ FileList_Init(nnode); free(tmpnode); return; }else{ memcpy(nnode, tmpnode, sizeof(t_fslist)); free(tmpnode); } } nnode = nnode->fnext; //TODO: AÑADIR SOLO ROM+ SI location != 0 :) WiiStatus.nRoms++; } }
/* * Inserta el juego en gamelist ordenado segun nombre. */ bool _FileList_InsertGame (const t_fslist * nfile) { t_fslist * pnode = &gamelist; int result; while ( pnode->fnext != NULL) { if( (strncmp(nfile->gfile.filename, pnode->gfile.filename, 256) != 0) ) { result = strncmp(nfile->game.title, pnode->game.title, 128); if(result == 0){ if ((nfile->gfile.location == SU_SD) && ((pnode->gfile.location == SU_NONE) || (pnode->gfile.location == SU_HTTP) )) { memcpy(&pnode->gfile, &nfile->gfile, sizeof(t_WiiRom)); return true; } break; } if(result < 0) break; }else if(nfile->gfile.location == SU_SD) { if((pnode->gfile.location == SU_NONE) || (pnode->gfile.location == SU_HTTP) ) pnode->gfile.location = SU_SD; return true; } pnode = pnode->fnext; } t_fslist * newnode = NULL; //creamos newnode = malloc(sizeof(t_fslist)); if(newnode == NULL) return false; if( pnode->fnext != NULL) { //copiamos los datos memcpy(newnode, pnode, sizeof(t_fslist)); }else FileList_Init (newnode); //copiamos los datos del nuevo memcpy(pnode, nfile, sizeof(t_fslist)); pnode->fnext = newnode; return true; }
bool Explorer_dirRead ( void ) { DIR_ITER *pdir = NULL; int ngames = 0; char filename[1024]; struct stat statbuf; t_fslist pnode; if(!WiiStatus.Dev_Fat) return false; pdir=diropen(current_path); if (!pdir){ printf ("opendir() failure; terminating\n"); return false; } while(dirnext(pdir,filename,&statbuf) == 0){ if(S_ISDIR(statbuf.st_mode)) continue; if(strlen(current_path) + strlen(filename) >= 1024){ continue; //path demasiado largo, saltamos } lowercase (filename, false); if ( memcmp((char*) &filename[(strlen(filename)-4)], ".zip", 4) != 0) continue; if(!_FileList_UpdateFile(filename, SU_SD)) { FileList_Init(&pnode); //cleaning node _nfoRead(&pnode.game, filename); strcpy(pnode.gfile.filename, filename); pnode.gfile.location = SU_SD; if(_FileList_InsertGame(&pnode)) // TODO: HACER FLUSH PARA EVITAR CUELGUES? ngames++; //to use in debug mode } } dirclose(pdir); return true; }
void _FileList_Swap(t_fslist * pre, t_fslist * current) { t_fslist temp; FileList_Init(&temp); memcpy(&temp, pre, sizeof(t_fslist)); memcpy(pre, current, sizeof(t_fslist)); //pointers pre->fnext = temp.fnext; temp.fnext = current->fnext; memcpy(current, &temp, sizeof(t_fslist)); }
int main(int argc, char **argv) { parse_cmd_line(argc, argv); FileList *filelist = (FileList *)malloc(sizeof(FileList)); FileList_Init(filelist); GetFileListInPaths(DIRPATHS, filelist); IdentFileList *ifiles; IdenticalFile_Init(&ifiles); GetIdenticalFile(filelist, ifiles); if (OPTIONS & OPT_HASH) PrintIdenticalFileHash(ifiles); else PrintIdenticalFile(ifiles); }
int __stdcall isCopyFile( FileCopyCallback_t callback, wchar_t *PathOut, wchar_t *PathIn, BOOL bInnerFolders ) { wchar_t TempDir[ _MAX_PATH ] = {0}; __int64 mCopySize = 0; FILE *mFileOut; // Из FILE *mFileIn; // В int PolKilo = 1024 * 512; wchar_t *TempBuf; size_t result; mCopy = TRUE; FileList = ( FileList_t * )FileList_Init(); TempBuf = ( wchar_t * )malloc( PolKilo ); SizePathOut = wcslen( PathOut ); mbInnerFolders = bInnerFolders; wcscpy( mPathOut, PathOut ); // Ищем файлы SECURITY_ATTRIBUTES sa; ZeroMemory (&sa, sizeof(sa)); sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; hEvent = CreateEvent (&sa, false, false, NULL); hThread = CreateThread (&sa, NULL, SearchThread, NULL, NULL, &thID); WaitWithMessageLoop( &hEvent ); CloseHandle( hEvent ); CloseHandle( hThread ); if( !mCopy ) { free( TempBuf ); FileList_Free( FileList ); return 0; } FileList->AllSize = FileList->AllSize / 1024 ; callback( "allsize", ( int )FileList->AllSize, "" ); // Создаем папку CreateDirectoryTree( PathIn ); // Создаем подпапки for( int i = 0; i < FileList->NumDir; ++i ) { wsprintf( TempDir, L"%s\\%s", PathIn, FileList->mPath[ i ] ); CreateDirectoryTree( TempDir ); } for( int z = 0; z < FileList->NumFiles; ++z ) { if( !mCopy ) break; // Создаем файл в "конечной" папке if( bInnerFolders ) wsprintf( TempDir, L"%s\\%s", PathIn, FileList->Files[ z ] + SizePathOut - 1 ); else wsprintf( TempDir, L"%s\\%s", PathIn, GetFileName( FileList->Files[ z ] ) ); mFileIn = _wfopen( TempDir, L"wb" ); if( mFileIn == NULL ) break; callback( "filename", 0, convertUnicode( FileList->Files[ z ] ) ); // Открываем исходный файл mFileOut = _wfopen( FileList->Files[ z ], L"rb" ); if( mFileIn == NULL ) break; while( !feof( mFileOut ) && mCopy ) { result = fread( TempBuf, 1, PolKilo, mFileOut ); if( ferror( mFileOut ) ) { ErrorExit( L"fread" ); fclose( mFileOut ); fclose( mFileIn ); continue; } mCopySize += result; fwrite( TempBuf, 1, result, mFileIn ); if( ferror( mFileIn ) ) { ErrorExit( L"fread" ); fclose( mFileOut ); fclose( mFileIn ); continue; } callback( "write", mCopySize / 1024, "" ); } fclose( mFileOut ); fclose( mFileIn ); } free( TempBuf ); FileList_Free( FileList ); return 1; }