1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| void CSetup_PervasiveDlg::myCopieFichiers(char * rep, char* str, int tailleTotale, long tailleCourante)
{
WIN32_FIND_DATA FindFileData;
char path[MAX_PATH];
char strP[MAX_PATH];
strcpy(path,rep);
strcat(path,"\\*.*");
HANDLE hFind = FindFirstFile(path, &FindFileData);
if (hFind==INVALID_HANDLE_VALUE) {
return;
}
if (strcmp(FindFileData.cFileName,".")!=0 && strcmp(FindFileData.cFileName,"..")!=0)
{
strcpy(path,rep);
strcat(path,"\\");
strcat(path,FindFileData.cFileName);
strcpy(strP, str);
strcat(strP, "\\");
strcat(strP, FindFileData.cFileName);
CreateDirectory(strP, NULL);
myCopieFichiers(path, strP, tailleTotale, tailleCourante);
}
DWORD a = 0;
while (a != ERROR_NO_MORE_FILES)
{
if (!FindNextFile(hFind, &FindFileData))
a = GetLastError();
else
{
if (strcmp(FindFileData.cFileName,".")!=0 && strcmp(FindFileData.cFileName,"..")!=0)
{
strcpy(path,rep);
strcat(path,"\\");
strcat(path,FindFileData.cFileName);
strcpy(strP, str);
strcat(strP, "\\");
strcat(strP, FindFileData.cFileName);
if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){
CreateDirectory(strP, NULL);
myCopieFichiers(path, strP, tailleTotale, tailleCourante);
}
else
{
CString str;
CFile cfo, cfoCopi;
DWORD nRet = 4096, totalRead = 0, fileSize = (FindFileData.nFileSizeHigh * ((long)MAXDWORD+1) + FindFileData.nFileSizeLow);
char pBuffer[4096];
cfo.Open(path, CFile::modeRead, NULL);
CFileException ex;
cfoCopi.Open(strP, CFile::modeCreate | CFile::shareExclusive | CFile::modeWrite, NULL);
str.Format("Copie du fichier %s en cours . . .", FindFileData.cFileName);
SetDlgItemText(IDC_ETAT2, str);
while (nRet == 4096) {
nRet = cfo.Read(pBuffer, 4096);
cfoCopi.Write(pBuffer, nRet);
totalRead += nRet;
cPd2->SetPos(totalRead*100/fileSize);
if (CheckCancelButton()) {
cfo.Close(); cfoCopi.Close();
exit(0);
}
}
cfo.Close(); cfoCopi.Close();
tailleCourante += totalRead;
Trace << tailleCourante << "\t\t" << totalRead << endl;
cPd->SetPos(tailleCourante*100/tailleTotale);
}
}
}
}
FindClose(hFind);
} |
Partager