You are not logged in.
Pages: 1
Всем привет,вопрос такой, хотелось чтоб кто-то показал на этом коде, как сделать чтения файлов с подпапок?
Надеюсь на вашу помощь.
void DllInit() { #ifdef USE_LOG fopen_s(&pLogFile, "vimg.log", "w"); #endif { GetModuleFileName(NULL, cSelfPath, MAX_PATH); if (strrchr(cSelfPath, '\\')) *(char*)(strrchr(cSelfPath, '\\') + 1) = '\0'; char cFilePath[MAX_PATH]; strcpy_s(cFilePath, MAX_PATH, cSelfPath); strcat_s(cFilePath, MAX_PATH, "virtualimg.dat"); FILE* pFile; if (fopen_s(&pFile, cFilePath, "r")) { MessageBox(0, "Failed to open virtualimg.dat.", "Virtual IMG", MB_OK | MB_ICONERROR); ExitProcess(0); } char cType[16]; int iType; char cIMGPath[MAX_PATH]; char cDirPath[MAX_PATH]; while (fscanf_s(pFile, "%s\t%s\t%s", cType, 16, cIMGPath, MAX_PATH, cDirPath, MAX_PATH) == 3) { iType = 0; if (!_stricmp(cType, "MARGE")) iType = 1; if (!_stricmp(cType, "CREATE")) iType = 2; if (!_stricmp(cType, "APPEND")) iType = 3; if (!_stricmp(cType, "IGNORE")) continue; pVirtualIMG = (VirtualIMG*)realloc(pVirtualIMG, sizeof(VirtualIMG) * (iIMGCount + 1)); pVirtualIMG[iIMGCount].iType = iType; strcpy_s(pVirtualIMG[iIMGCount].cIMGPath, MAX_PATH, cIMGPath); strcpy_s(pVirtualIMG[iIMGCount].cDirPath, MAX_PATH, cDirPath); pVirtualIMG[iIMGCount].hIMGFile = 0; pVirtualIMG[iIMGCount].hNewFile = 0; pVirtualIMG[iIMGCount].iIMGFile = 0; pVirtualIMG[iIMGCount].cIMGFile = NULL; if (!pVirtualIMG[iIMGCount].iType) continue; strcpy_s(cIMGPath, MAX_PATH, cSelfPath); strcat_s(cIMGPath, MAX_PATH, pVirtualIMG[iIMGCount].cIMGPath); strcpy_s(cFilePath, MAX_PATH, cIMGPath); strcat_s(cFilePath, MAX_PATH, ".vimg"); pVirtualIMG[iIMGCount].hIMGFile = CreateFile(cIMGPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL); HANDLE hNewIMG; HANDLE hFind; WIN32_FIND_DATA ffd; unsigned long dwCurrentFile = 0x00800000; unsigned long dwVersion; unsigned long dwFileNum; unsigned long dwBuffer[8]; unsigned long dwSize; unsigned long dwIMGFile; hNewIMG = CreateFile(cFilePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_RANDOM_ACCESS, NULL); ReadFile(pVirtualIMG[iIMGCount].hIMGFile, &dwVersion, 0x4, &dwSize, NULL); WriteFile(hNewIMG, &dwVersion, 0x4, &dwSize, NULL); dwFileNum = 0; WriteFile(hNewIMG, &dwFileNum, 0x4, &dwSize, NULL); strcpy_s(cDirPath, MAX_PATH, cSelfPath); strcat_s(cDirPath, MAX_PATH, pVirtualIMG[iIMGCount].cDirPath); strcat_s(cDirPath, MAX_PATH, "*"); pVirtualIMG[iIMGCount].iIMGFile = 0; hFind = FindFirstFile(cDirPath, &ffd); while (FindNextFile(hFind,&ffd)) { if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (!FindNextFile(hFind, &ffd)) break; continue; } dwBuffer[0] = dwCurrentFile; dwBuffer[1] = (ffd.nFileSizeLow >> 11 | ffd.nFileSizeHigh << 21) + 1; //ZeroMemory(&dwBuffer[2], 0x18); strcpy_s((char*)&dwBuffer[2], 0x18, strrchr(ffd.cFileName, '\\') ? strrchr(ffd.cFileName, '\\') + 1 : ffd.cFileName); WriteFile(hNewIMG, dwBuffer, 0x20, &dwSize, NULL); pVirtualIMG[iIMGCount].cIMGFile =(char*)realloc(pVirtualIMG[iIMGCount].cIMGFile, MAX_PATH * (pVirtualIMG[iIMGCount].iIMGFile + 1)); strcpy_s(&pVirtualIMG[iIMGCount].cIMGFile[MAX_PATH * pVirtualIMG[iIMGCount].iIMGFile], MAX_PATH, cSelfPath); strcat_s(&pVirtualIMG[iIMGCount].cIMGFile[MAX_PATH * pVirtualIMG[iIMGCount].iIMGFile], MAX_PATH, pVirtualIMG[iIMGCount].cDirPath); strcat_s(&pVirtualIMG[iIMGCount].cIMGFile[MAX_PATH * pVirtualIMG[iIMGCount].iIMGFile], MAX_PATH, ffd.cFileName); pVirtualIMG[iIMGCount].iIMGFile++; dwFileNum++; dwCurrentFile++; //if (!FindNextFile(hFind, &ffd)) break; } FindClose(hFind); switch (pVirtualIMG[iIMGCount].iType) { case 1: { ReadFile(pVirtualIMG[iIMGCount].hIMGFile, &dwIMGFile, 0x4, &dwSize, NULL); for (unsigned long i = 0; i < dwIMGFile; i++) { ReadFile(pVirtualIMG[iIMGCount].hIMGFile, dwBuffer, 0x20, &dwSize, NULL); for (int j = 0; j < pVirtualIMG[iIMGCount].iIMGFile; j++) if (!_stricmp((const char*)&dwBuffer[2], (strrchr(&pVirtualIMG[iIMGCount].cIMGFile[MAX_PATH * j], '\\')) ? strrchr(&pVirtualIMG[iIMGCount].cIMGFile[MAX_PATH * j], '\\') + 1 : &pVirtualIMG[iIMGCount].cIMGFile[MAX_PATH * j])) { dwBuffer[1] = 0; break; } if (!dwBuffer[1]) continue; WriteFile(hNewIMG, dwBuffer, 0x20, &dwSize, NULL); dwFileNum++; } break; } case 2: { break; } case 3: { ReadFile(pVirtualIMG[iIMGCount].hIMGFile, &dwIMGFile, 0x4, &dwSize, NULL); for (unsigned long i = 0; i < dwIMGFile; i++) { ReadFile(pVirtualIMG[iIMGCount].hIMGFile, dwBuffer, 0x20, &dwSize, NULL); WriteFile(hNewIMG, dwBuffer, 0x20, &dwSize, NULL); dwFileNum++; } break; } } CloseHandle(pVirtualIMG[iIMGCount].hIMGFile); pVirtualIMG[iIMGCount].hIMGFile = CreateFile(cIMGPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED | FILE_FLAG_RANDOM_ACCESS, NULL); SetFilePointer(hNewIMG, 0x4, NULL, FILE_BEGIN); WriteFile(hNewIMG, &dwFileNum, 0x4, &dwSize, NULL); CloseHandle(hNewIMG); iIMGCount++; } }
Pages: 1