?? ztssplit v1.11.asm
字號:
popad
ret
.ENDIF
mov hSourceFile, eax
;文件太小(比指定的分割大小)
invoke GetFileSize, hSourceFile, NULL
.IF eax<blocksize
invoke CloseHandle, hSourceFile
invoke MessageBox, hMainWnd, addr strError03, addr AppName, MB_OK or MB_ICONERROR
popad
ret
.ENDIF
;計算文件名(包括擴展名)
mov esi, lpfile
lea edi, filetitle
invoke StrLen, lpfile
add esi, eax
xor ecx, ecx
labelTest:
cmp BYTE ptr [esi], '\'
je labelExit
dec esi
inc ecx
jmp labelTest
labelExit:
inc esi
dec ecx
rep movsd
invoke lstrcpy, addr sourcefilename, addr filetitle ;保存文件名到 sourcefilename 中
;計算文件名(不包括擴展名)
lea esi, filetitle
mov ebx, esi
invoke StrLen, addr filetitle
add ebx, eax
labelLoop:
cmp BYTE ptr [esi], '.'
je labelQuit
inc esi
cmp esi, ebx
je labelQuit
jmp labelLoop
labelQuit:
mov BYTE ptr [esi], '.'
mov BYTE ptr [esi+1], 0
;mrg 文件的擴展名
lea esi, fileExt
mov BYTE ptr [esi], 'm'
mov BYTE ptr [esi+1], 'r'
mov BYTE ptr [esi+2], 'g'
mov BYTE ptr [esi+3], 0
;計算 mrg 文件的文件名(包括路徑)
invoke lstrcpy, addr filename, lpfolder
invoke lstrcat, addr filename, addr filetitle
invoke lstrcat, addr filename, addr fileExt
invoke CreateFile, addr filename, GENERIC_WRITE or GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL
.IF eax==INVALID_HANDLE_VALUE
invoke MessageBox, hMainWnd, addr strError02, addr AppName, MB_OK or MB_ICONERROR
popad
ret
.ENDIF
mov hMrgFile, eax
;寫入版本信息
invoke StrLen, addr strCopyright
mov ebx, eax
invoke WriteFile, hMrgFile, addr strCopyright, ebx, addr ActualReaded, NULL
;初始化一些數據
mov number, -1
mov eax, blocksize
mov BufCount, eax
mov hDestFile,0
invoke ReadFile, hSourceFile, addr buffer, 1024, addr ActualReaded, NULL
mov eax, ActualReaded
.WHILE eax!=0 ;文件沒到末尾就繼續讀
;當一個分割文件寫完后創建一個新的分割文件來寫
mov eax, BufCount
.IF eax==blocksize
.IF hDestFile != 0
invoke CloseHandle, hDestFile
.ENDIF
;計算分割文件的擴展名
inc number
invoke wsprintf, addr fileExt, addr format1, number
invoke lstrcpy, addr filename, lpfolder
invoke lstrcat, addr filename, addr filetitle
invoke lstrcat, addr filename, addr fileExt
invoke CreateFile, addr filename, GENERIC_WRITE or GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL
.IF eax==INVALID_HANDLE_VALUE
invoke MessageBox, hMainWnd, addr strError02, addr AppName, MB_OK or MB_ICONERROR
popad
ret
.ENDIF
mov hDestFile, eax
mov BufCount, 0 ;每次新創建的分割文件,寫入的大小為零
.ENDIF
;寫入數據
mov ebx, ActualReaded
invoke WriteFile, hDestFile, addr buffer, ebx, addr ActualReaded, NULL
add BufCount, ebx ;寫入的大小遞增
;根據已經讀出的大小和需要分割文件的大小來設置進度條
invoke GetFileSize, hSourceFile, NULL
mov ebx, eax
mov eax, number
inc eax
mul blocksize
mov ecx, 100
mul ecx
div ebx
invoke SendMessage, hProgress, PBM_SETPOS, eax, 0
;讀出數據
invoke ReadFile, hSourceFile, addr buffer, 1024, addr ActualReaded, NULL
mov eax, ActualReaded
.ENDW
;把分割文件的個數和原文件名(包括擴展名)寫入 mrg 文件中
inc number
invoke wsprintf, addr fileExt, addr format1, number
invoke WriteFile, hMrgFile, addr fileExt, 3, addr ActualReaded, NULL
invoke StrLen, addr sourcefilename
mov ebx, eax
invoke WriteFile, hMrgFile, addr sourcefilename, ebx, addr ActualReaded, NULL
invoke CloseHandle, hMrgFile
invoke CloseHandle, hDestFile
invoke CloseHandle, hSourceFile
popad
ret
Split endp
;=================================
; 合并過程
; 參數:待合并文件,存放目錄
;=================================
Merge proc lpfile:DWORD, lpfolder:DWORD
local hSourceFile, hDestFile:DWORD
local buffer[1024]:BYTE ;緩沖區
local srcFolder[MAX_PATH]:BYTE ;分割文件所在目錄
local filetitle[128]:BYTE ;文件名(不包括擴展名)
local fileExt[10]:BYTE ;擴展名
local filename[128]:BYTE ;文件名(包括路徑和擴展名)
local nfile,ntotal:DWORD ;分割文件的個數
local number:DWORD ;用來計算擴展名
local ActualReaded:DWORD ;實際讀出的字節
pushad
;沒指定需要分割的文件
mov esi, lpfile
mov al, byte ptr [esi]
.IF al == 0
invoke MessageBox, hMainWnd, addr strError05, addr AppName, MB_OK or MB_ICONERROR
popad
ret
.ENDIF
;沒指定分割后文件存放的目錄
mov esi, lpfolder
mov al, byte ptr [esi]
.IF al == 0
invoke MessageBox, hMainWnd, addr strError06, addr AppName, MB_OK or MB_ICONERROR
popad
ret
.ENDIF
;打開 mrg 文件
invoke CreateFile, lpfile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL
.IF eax==INVALID_HANDLE_VALUE
invoke MessageBox, hMainWnd, addr strError01, addr AppName, MB_OK or MB_ICONERROR
popad
ret
.ENDIF
mov hSourceFile, eax
;讀出版本信息,比較是否為合法的文件
invoke StrLen, addr strCopyright
mov ebx, eax
invoke ReadFile, hSourceFile, addr buffer, ebx, addr ActualReaded, NULL
invoke lstrcmp, addr buffer, addr strCopyright
.IF eax!=0
invoke CloseHandle, hSourceFile
invoke MessageBox, hMainWnd, addr strError07, addr AppName, MB_OK or MB_ICONERROR
popad
ret
.ENDIF
;讀出分割文件的個數,保存在 nfile 中
invoke ReadFile, hSourceFile, addr buffer, 3, addr ActualReaded, NULL
lea esi, buffer
xor eax, eax
mov al, byte ptr [esi]
sub al, 48
mov ebx, 100
mul ebx
mov nfile, eax
xor eax, eax
mov al, byte ptr [esi+1]
sub al, 48
mov ebx, 10
mul ebx
add nfile, eax
xor eax, eax
mov al, byte ptr [esi+2]
sub al, 48
add nfile, eax
mov eax, nfile
mov ntotal, eax
shl eax,16
invoke SendMessage,hProgress,PBM_SETRANGE,0,eax
;讀出合并后的文件名(包括擴展名)
invoke RtlZeroMemory, addr buffer, 1024
invoke GetFileSize, hSourceFile, NULL
mov ebx, eax
invoke StrLen, addr strCopyright
sub ebx, eax
invoke ReadFile, hSourceFile, addr buffer, ebx, addr ActualReaded, NULL
invoke lstrcpy, addr filename, lpfolder
invoke lstrcat, addr filename, addr buffer
;創建文件準備寫
invoke CreateFile, addr filename, GENERIC_WRITE or GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL
.IF eax==INVALID_HANDLE_VALUE
invoke MessageBox, hMainWnd, addr strError02, addr AppName, MB_OK or MB_ICONERROR
popad
ret
.ENDIF
mov hDestFile, eax
;取得分割文件所在的目錄
invoke GetFolder, addr srcFolder, lpfile
;計算文件名(不包括擴展名)
invoke lstrcpy, addr filetitle, addr buffer
lea esi, filetitle
mov ebx, esi
invoke StrLen, addr filetitle
add ebx, eax
labelLoop:
cmp BYTE ptr [esi], '.'
je labelQuit
inc esi
cmp esi, ebx
je labelQuit
jmp labelLoop
labelQuit:
mov BYTE ptr [esi], '.'
mov BYTE ptr [esi+1], 0
mov number, -1
.WHILE nfile ;用分割文件的個數來控制循環
invoke CloseHandle, hSourceFile
;計算擴展名,然后得出文件名(包括路徑和擴展名)
inc number
invoke wsprintf, addr fileExt, addr format1, number
invoke lstrcpy, addr filename, addr srcFolder
invoke lstrcat, addr filename, addr filetitle
invoke lstrcat, addr filename, addr fileExt
;打開文件準備讀
invoke CreateFile, addr filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL
.IF eax==INVALID_HANDLE_VALUE
invoke MessageBox, hMainWnd, addr strError01, addr AppName, MB_OK or MB_ICONERROR
popad
ret
.ENDIF
mov hSourceFile, eax
invoke ReadFile, hSourceFile, addr buffer, 1024, addr ActualReaded, NULL
mov eax, ActualReaded
.WHILE eax ;循環讀,一直到文件末尾
mov ebx, eax
invoke WriteFile, hDestFile, addr buffer, ebx, addr ActualReaded, NULL
invoke ReadFile, hSourceFile, addr buffer, 1024, addr ActualReaded, NULL
mov eax, ActualReaded
.ENDW
dec nfile
mov eax, ntotal
sub eax, nfile
invoke SendMessage, hProgress, PBM_SETPOS, eax, 0
.ENDW
invoke CloseHandle, hDestFile
invoke CloseHandle, hSourceFile
popad
ret
Merge endp
end start
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -