mer. 13 août 2014, 18h51
etobis
France
atoutfox.public.association
Copie de gros fichiers avec progression
bonjour à tous (Ceux qui ne sont pas en vacances !)
J'ai besoin de faire une copie de fichier locale avec suivi de la progression.
Sur des gros fichiers (plus de 3go) :
FOPEN/FREAD/FCREATE/FWRITE ne marche pas : Fichier trop gros.
J'ai donc implémenté copyFileEx.
Mais si la copie se passe bien, j'ai tout de même un joli totalSize négatif !
Donc la progression est...défectueuse !
Avez vous une idée ?
Merci d'avance
Eto
PS : Je joins le code du copyfileEx pour les pro du CTOBIN qui sauraient l'adapter à mon problème !!!
Declare INTEGER CopyFileEx in win32api;
STRING lpExistingFileName,;
STRING lpNewFileName,;
LONG lpProgressRoutine,;
STRING lpData,;
INTEGER@ pbCancel,;
INTEGER dwCopyFlags;
cfHook = CreateObject("CopyFileCallback")
bCancel = 0
=CopyFileEx(_from,_to, cfHook.ProcAddress, "Progress :", @bCancel, 0)
Define Class CopyFileCallback as Callback
*!* DWORD CALLBACK CopyProgressRoutine(
*!* __in LARGE_INTEGER TotalFileSize,
*!* __in LARGE_INTEGER TotalBytesTransferred,
*!* __in LARGE_INTEGER StreamSize,
*!* __in LARGE_INTEGER StreamBytesTransferred,
*!* __in DWORD dwStreamNumber,
*!* __in DWORD dwCallbackReason,
*!* __in HANDLE hSourceFile,
*!* __in HANDLE hDestinationFile,
*!* __in_opt LPVOID lpData
*!* )
*********** Total parameters size = 52 Bytes
Procedure Init
Return DoDefault(52)
EndProc
Procedure Callback
Lparameters sParams
local TotalFileSize,; && 8 bytes
TotalBytesTransferred, ; && 8 bytes
StreamSize, ; && 8 bytes
StreamBytesTransferred, ; && 8 bytes
StreamNumber, ; && 4 bytes
CallbackReason, ; && 4 bytes
SourceFile, ; && 4 bytes
DestinationFile, ; && 4 bytes
lpData && 4 bytes
SET STEP ON
TotalFileSize = CToBin(Substr(sParams,1,4),"4RS")+CToBin(Substr(sParams,5,4),"4RS")*0x100000000
TotalBytesTransferred = CToBin(Substr(sParams,9,4),"4RS")+CToBin(Substr(sParams,13,4),"4RS")*0x100000000
StreamSize = CToBin(Substr(sParams,17,4),"4RS")+CToBin(Substr(sParams,21,4),"4RS")*0x100000000
StreamBytesTransferred = CToBin(Substr(sParams,25,4),"4RS")+CToBin(Substr(sParams,29,4),"4RS")*0x100000000
StreamNumber = CToBin(Substr(sParams,33,4),"4RS")
CallbackReason = CToBin(Substr(sParams,37,4),"4RS")
SourceFile = CToBin(Substr(sParams,41,4),"4RS")
DestinationFile = CToBin(Substr(sParams,45,4),"4RS")
lpData = CToBin(Substr(sParams,49,4),"4RS")
Activate screen
If CallbackReason=1
EndIf
&& Sur un gros fichier, StreamSize est négatif et incohérent !
? STR(StreamBytesTransferred)+"/"+STR(StreamSize )
return 0 && PROGRESS_CONTINUE
EndProc
ENDDEFINE
Define Class Callback as Form
oRefForm=null
ProcAddress = 0
hHeap = 0
Procedure Init
Lparameters tnParamSize
&& IF _screen.MASTER_FORM.stop_process
&& RETURN
&& ENDIF
Declare LONG GetModuleHandleA In WIN32API String
Declare LONG GetProcAddress In WIN32API LONG hModule, String procname
Declare LONG HeapAlloc In WIN32API LONG hHeap, LONG dwFlags, LONG dwBytes
Declare LONG HeapCreate In WIN32API LONG dwFlags, LONG dwBytes, LONG dwMaxBytes
#define WM_USERCALLBACK 0x400+700
If Vartype(tnParamSize)#"N"
tnParamSize = 0
EndIf
Local pfnSendMessage,hModule
hModule = GetModuleHandleA("user32.dll")
pfnSendMessage=GetProcAddress(hModule,"SendMessageA")
*Emit code
Local sCode
*Enter
sCode = Chr(0x55) && push ebp
sCode = sCode + Chr(0x89) + Chr(0xE5) && mov ebp, esp
*Read data
If tnParamSize=0
sCode = sCode + Chr(0x68) + BinToC(0,"4rs") && push 0 : lParam - ptr to params
Else
sCode = sCode + Chr(0x89) + Chr(0xE8) && mov eax,ebp
sCode = sCode + Chr(0x83) + Chr(0xC0) + Chr(0x08) && add eax,8
sCode = sCode + Chr(0x50) && push eax : lParam - ptr to params
EndIf
*Push general parameters
sCode = sCode + Chr(0x68) + BinToC(tnParamSize,"4rs") && push wParam - param size
sCode = sCode + Chr(0x68) + BinToC(WM_USERCALLBACK,"4rs") && push nMsg
sCode = sCode + Chr(0x68) + BinToC(this.hWnd,"4rs") && push hWnd
*Send message
sCode = sCode + Chr(0xB8) + BinToC(pfnSendMessage,"4rs") && move eax, procSendMessage
sCode = sCode + Chr(0xFF) + Chr(0xD0) && call eax
*Return
sCode = sCode + Chr(0xC9) && leave
If tnParamSize = 0
sCode = sCode + Chr(0xC3) && ret
Else
sCode = sCode + Chr(0xC2) + BinToC(tnParamSize,"2RS") && ret tnParamSize
EndIf
*Allocate memory for code
#define HEAP_CREATE_ENABLE_EXECUTE 0x00040000
this.hHeap = HeapCreate(HEAP_CREATE_ENABLE_EXECUTE,Len(sCode),Len(sCode))
this.ProcAddress = HeapAlloc(this.hHeap,0,Len(sCode))
*Write emitted code
sys(2600,this.ProcAddress,Len(sCode),sCode)
BindEvent(this.HWnd,WM_USERCALLBACK,this,"CallbackEvent")
EndProc
Procedure CallbackEvent
Lparameters hWnd,uMsg,wParam,lParam
Local sParamData
If m.wParam>0
sParamData=Sys(2600,lParam,wParam)
Else
sParamData = ""
EndIf
Return this.Callback(sParamData)
EndProc
Procedure Callback
Lparameters sParamData
EndProc
Procedure Destroy
UnBindEvents(this)
Declare LONG HeapDestroy In WIN32API LONG hHeap
HeapDestroy(this.hHeap)
EndProc
ENDDEFINE
Permalink : http://www.atoutfox.org/nntp.asp?ID=0000014993