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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
| void* export_data(void *arg) {
WIN32_FILE_ATTRIBUTE_DATA attr;
int i = 0, size = 0;
LPVOID buffer;
HANDLE FileDest;
int NbBlocks;
unsigned long nb_ecrit;
char dirnameinput[1024];
char filenameinput[1024];
char destfile[1024];
char filename1[1024];
char filename2[1024];
char filename3[1024];
char filename4[1024];
char filename5[1024];
char filename6[1024];
char filename7[1024];
char filename8[1024];
char commentfilename[1024];
char destcommentfilename[1024];
int nb_of_free_clusters, nb_bytes_per_sector, nb_sectors_per_cluster, nb_free_blocks;
double free_space_first_disk;
double filesize;
unsigned int *ptr;
acquisition->file_well_close = 0;
acquisition->int_field = 0;
continue_acquisition = 1;
strcpy(dirnameinput,command->dirname);
strcpy(filenameinput,command->filename);
#ifdef _DEBUG_CONFIG_
printf("Export message\n");
printf("command->filename : %s\n",filenameinput);
printf("command->dirname : %s\n",dirnameinput);
#endif
strcpy(destfile, dirnameinput);
strcat(destfile, "\\");
strcat(destfile, filenameinput);
strcpy(filename1,PATH_1);
strcat(filename1, "\\");
strcat(filename1, filenameinput);
strcpy(filename2,PATH_2);
strcat(filename2, "\\");
strcat(filename2, filenameinput);
strcat(filename2,"2"); // pour extention .bin2
strcpy(filename3,PATH_3);
strcat(filename3, "\\");
strcat(filename3, filenameinput);
strcat(filename3,"3"); // pour extention .bin3
strcpy(filename4,PATH_4);
strcat(filename4, "\\");
strcat(filename4, filenameinput);
strcat(filename4,"4"); // pour extention .bin4
strcpy(filename5,PATH_5);
strcat(filename5, "\\");
strcat(filename5, filenameinput);
strcat(filename5,"5"); // pour extention .bin5
strcpy(filename6,PATH_6);
strcat(filename6, "\\");
strcat(filename6, filenameinput);
strcat(filename6,"6"); // pour extention .bin6
//oliv
strcpy(filename7,PATH_7);
strcat(filename7, "\\");
strcat(filename7, filenameinput);
strcat(filename7,"7"); // pour extention .bin7
//oliv
strcpy(filename8,PATH_8);
strcat(filename8, "\\");
strcat(filename8, filenameinput);
strcat(filename8,"8"); // pour extention .bin8
#ifdef _DEBUG_CONFIG_
printf("Export data into %s\n", destfile);
printf("Source file1 %s\n", filename1);
printf("Source file2 %s\n", filename2);
printf("Source file3 %s\n", filename3);
printf("Source file4 %s\n", filename4);
printf("Source file5 %s\n", filename5);
printf("Source file6 %s\n", filename6);
//oliv
printf("Source file7 %s\n", filename7);
printf("Source file8 %s\n", filename8);
#endif
FileDest = CreateFile(destfile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
File_F = CreateFile(filename1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
File_G = CreateFile(filename2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
File_H = CreateFile(filename3, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
File_I = CreateFile(filename4, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
File_J = CreateFile(filename5, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
File_K = CreateFile(filename6, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
File_L = CreateFile(filename7, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
File_M = CreateFile(filename8, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
//Taille du fichier source
GetFileAttributesEx(filename1, GetFileExInfoStandard, &attr );
filesize = 4294967296*attr.nFileSizeHigh+attr.nFileSizeLow;
NbBlocks = (int)(filesize/T_BLOCK/2);
#ifdef _DEBUG_CONFIG_
printf("filesize = %f\n",filesize);
printf("NbBlocks = %d\n",NbBlocks);
#endif
// Espace libre sur IDE:
GetDiskFreeSpace(IDE_PATH, &nb_sectors_per_cluster, &nb_bytes_per_sector,&nb_of_free_clusters, NULL);
#ifdef _DEBUG_CONFIG_
printf("nb_sectors_per_cluster = %f\n",(double)nb_sectors_per_cluster);
printf("nb_bytes_per_sector = %f\n",(double)nb_bytes_per_sector);
printf("nb_of_free_clusters = %f\n",(double)nb_of_free_clusters);
#endif
free_space_first_disk = (double)((double)nb_sectors_per_cluster*(double)nb_of_free_clusters*(double)nb_bytes_per_sector);
// nb de blocs libres:
nb_free_blocks = (int)(free_space_first_disk/T_BLOCK/2); // Attention: les blocs réelles font 2*T_BLOCK.
#ifdef _DEBUG_CONFIG_
printf("free_space_first_disk = %f\n",free_space_first_disk);
printf("nb_free_blocks = %d\n",nb_free_blocks);
#endif
// Limitation pour ne pas depasser capacité disc.
if (nb_free_blocks < (NbBlocks*8)) // 4 discs => a remplacer qd 6
NbBlocks = (int)(nb_free_blocks/8); // 4 discs => a remplacer qd 6
#ifdef _DEBUG_CONFIG_
printf("NbBlocks = %d\n",NbBlocks);
#endif
buffer = VirtualAlloc(NULL,T_BLOCK*2,MEM_COMMIT,PAGE_READWRITE);
if (buffer==NULL) goto buffererror;
i=0;
do
{
if( ! ReadFile(File_F, buffer, T_BLOCK*2, &size, NULL)) goto readerror;
[color=red]-> if( ! WriteFile(FileDest, buffer, size, &nb_ecrit, NULL)) goto writeerror;[/color]
if( ! ReadFile(File_G, buffer, T_BLOCK*2, &size, NULL)) goto readerror;
if( ! WriteFile(FileDest, buffer, size, &nb_ecrit, NULL)) goto writeerror;
if( ! ReadFile(File_H, buffer, T_BLOCK*2, &size, NULL)) goto readerror;
if( ! WriteFile(FileDest, buffer, size, &nb_ecrit, NULL)) goto writeerror;
if( ! ReadFile(File_I, buffer, T_BLOCK*2, &size, NULL)) goto readerror;
if( ! WriteFile(FileDest, buffer, size, &nb_ecrit, NULL)) goto writeerror;
if( ! ReadFile(File_J, buffer, T_BLOCK*2, &size, NULL)) goto readerror;
if( ! WriteFile(FileDest, buffer, size, &nb_ecrit, NULL)) goto writeerror;
if( ! ReadFile(File_K, buffer, T_BLOCK*2, &size, NULL)) goto readerror;
if( ! WriteFile(FileDest, buffer, size, &nb_ecrit, NULL)) goto writeerror;
if( ! ReadFile(File_L, buffer, T_BLOCK*2, &size, NULL)) goto readerror;
if( ! WriteFile(FileDest, buffer, size, &nb_ecrit, NULL)) goto writeerror;
if( ! ReadFile(File_M, buffer, T_BLOCK*2, &size, NULL)) goto readerror;
if( ! WriteFile(FileDest, buffer, size, &nb_ecrit, NULL)) goto writeerror;
acquisition->int_field = (int)((double)((double)(i+1)/(double)NbBlocks*100));
#ifdef _DEBUG_CONFIG_
printf("i = %d\n",i);
printf("continue_acquisition = %d\n",continue_acquisition);
printf("NbBlocks = %d\n",NbBlocks);
#endif
i++;
}while((i<NbBlocks)&&(continue_acquisition));
// Export comment file:
strcpy(commentfilename, PATH_1);
strcat(commentfilename,"\\");
strcat(commentfilename,filenameinput);
strcat(commentfilename,".txt");
strcpy(destcommentfilename, dirnameinput);
strcat(destcommentfilename,"\\");
strcat(destcommentfilename,filenameinput);
strcat(destcommentfilename,".txt");
CopyFile(commentfilename,destcommentfilename,0);
continue_acquisition = 0;
goto __ok;
writeerror:
printf("Error on write\n");
goto __ok;
readerror:
printf("Error on read\n");
goto __ok;
buffererror:
printf("Buffer error\n");
__ok:
CloseHandle(FileDest);
CloseHandle(File_F);
CloseHandle(File_G);
CloseHandle(File_H);
CloseHandle(File_I);
CloseHandle(File_J);
CloseHandle(File_K);
//oliv
CloseHandle(File_L);
CloseHandle(File_M);
acquisition->file_well_close = 1;
#ifdef _DEBUG_CONFIG_
printf("test_fich = %d\n",test_fich);
printf("Data successfully exported\n");
#endif
VirtualFree(buffer,T_BLOCK*2,MEM_DECOMMIT);
return NULL;
} |
Partager