Rev 7225 | Rev 7331 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7225 | Rev 7227 | ||
---|---|---|---|
Line 122... | Line 122... | ||
122 | $mov ebx,#read_file_70.func |
122 | $mov ebx,#read_file_70.func |
123 | $int 0x40 |
123 | $int 0x40 |
124 | } |
124 | } |
Line 125... | Line 125... | ||
125 | 125 | ||
126 | :f70 write_file_70; |
126 | :f70 write_file_70; |
127 | :int WriteFile(dword data_size, buffer, file_path) |
127 | :int CreateFile(dword data_size, buffer, file_path) |
128 | { |
128 | { |
129 | write_file_70.func = 2; |
129 | write_file_70.func = 2; |
130 | write_file_70.param1 = 0; |
130 | write_file_70.param1 = 0; |
131 | write_file_70.param2 = 0; |
131 | write_file_70.param2 = 0; |
Line 140... | Line 140... | ||
140 | 140 | ||
141 | //////////////////////////////////////// |
141 | //////////////////////////////////////// |
142 | // WriteInFileThatAlredyExists // |
142 | // WriteInFileThatAlredyExists // |
143 | //////////////////////////////////////// |
143 | //////////////////////////////////////// |
144 | :f70 write_file_offset_70; |
144 | :f70 write_file_offset_70; |
145 | :int WriteFileWithOffset(dword offset, data_size, buffer, file_path) |
145 | :int WriteFile(dword offset, data_size, buffer, file_path) |
146 | { |
146 | { |
147 | write_file_offset_70.func = 3; |
147 | write_file_offset_70.func = 3; |
148 | write_file_offset_70.param1 = offset; |
148 | write_file_offset_70.param1 = offset; |
149 | write_file_offset_70.param2 = 0; |
149 | write_file_offset_70.param2 = 0; |
Line 352... | Line 352... | ||
352 | { |
352 | { |
353 | debugln("Error: CopyFileAtOnce->ReadFile"); |
353 | debugln("Error: CopyFileAtOnce->ReadFile"); |
354 | } |
354 | } |
355 | else |
355 | else |
356 | { |
356 | { |
357 | if (error = WriteFile(size, cbuf, copyTo)) debugln("Error: CopyFileAtOnce->WriteFile"); |
357 | if (error = CreateFile(size, cbuf, copyTo)) debugln("Error: CopyFileAtOnce->CreateFile"); |
358 | } |
358 | } |
359 | free(cbuf); |
359 | free(cbuf); |
360 | return error; |
360 | return error; |
361 | } |
361 | } |
Line 362... | Line 362... | ||
362 | 362 | ||
363 | :int CopyFileByBlocks(dword size, copyFrom, copyTo) |
363 | :int CopyFileByBlocks(dword size, copyFrom, copyTo) |
364 | dword cbuf; |
364 | dword cbuf; |
365 | int error=-1; |
365 | int error=-1; |
366 | dword offpos=0; |
366 | dword offpos=0; |
367 | int block_size=1024*1024*4; //copy by 4 MiBs |
367 | int block_size=1024*1024*4; //copy by 4 MiB |
- | 368 | { |
|
- | 369 | if (GetFreeRAM()>1024*78) { |
|
- | 370 | //Set block size 32 MiB |
|
- | 371 | block_size <<= 3; |
|
368 | { |
372 | } |
369 | cbuf = malloc(block_size); |
373 | cbuf = malloc(block_size); |
- | 374 | if (error = CreateFile(0, 0, copyTo)) |
|
- | 375 | { |
|
- | 376 | debugln("Error: CopyFileByBlocks->CreateFile"); |
|
- | 377 | size = -1; |
|
370 | WriteFile(0, 0, copyTo); //create file |
378 | } |
371 | while(offpos < size) |
379 | while(offpos < size) |
372 | { |
380 | { |
373 | error = ReadFile(offpos, block_size, cbuf, copyFrom); |
381 | error = ReadFile(offpos, block_size, cbuf, copyFrom); |
374 | if (error = 6) { //File ended before last byte was readed |
382 | if (error = 6) { //File ended before last byte was readed |
375 | block_size = EBX; |
383 | block_size = EBX; |
376 | error=0; |
384 | if (block_size+offpos>=size) error=0; |
377 | } |
385 | } |
378 | else |
386 | else |
- | 387 | if (error!=0) { |
|
- | 388 | debugln("Error: CopyFileByBlocks->ReadFile"); |
|
- | 389 | break; |
|
379 | if (error!=0) break; |
390 | } |
- | 391 | if (error = WriteFile(offpos, block_size, cbuf, copyTo)) { |
|
- | 392 | debugln("Error: CopyFileByBlocks->WriteFile"); |
|
- | 393 | break; |
|
380 | if (error = WriteFileWithOffset(offpos, block_size, cbuf, copyTo)) break; |
394 | } |
381 | offpos += block_size; |
395 | offpos += block_size; |
382 | } |
396 | } |
383 | free(cbuf); |
397 | free(cbuf); |
384 | return error; |
398 | return error; |