⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ztssplit v1.11.asm

📁 一个文件分割器软件
💻 ASM
📖 第 1 页 / 共 3 页
字号:
                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 + -