Jump to content

[Solved] Perform Multi-Task


Trong
 Share

Recommended Posts

Eg script:

#RequireAdmin
Chọn tham gia ("KhayAutoPause", 0)
Lựa chọn ("MustDeclareVars", 1)
#inc loại <WinAPISys.au3>
#inc loại <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#inc loại <GUIListBox.au3>
#include <GuiListView.au3>
#inc loại <Crypt.au3>

#Khu vực
Toàn cầu $ hHUI = GUICreate ("AutoIT Hash Caculator", 791, 640, 652, 117, -1, BitOR ($ WS_EX_ACCEPTFILES, $ WS_EX_WINDOWEDGE))
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
GUICtrlCreateLabel ("Nhiệm vụ 1:", 18, 384, 40, 17)
Toàn cầu $ Task1_Label_Status_1 = GUICtrlCreateLabel ("DREADY", 73, 384, 55, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task1_Label_Status_2 = GUICtrlCreateLabel ("Tính CRC32", 140, 384, 130, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task1_Label_Status_3 = GUICtrlCreateLabel ("", 277, 384, 500, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
GUICtrlCreateLabel ("Nhiệm vụ 2:", 18, 416, 40, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task2_Label_Status_1 = GUICtrlCreateLabel ("SYN SÀNG", 73, 416, 55, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task2_Label_Status_2 = GUICtrlCreateLabel ("Tính MD2", 140, 416, 130, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task2_Label_Status_3 = GUICtrlCreateLabel ("", 277, 416, 500, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
GUICtrlCreateLabel ("Nhiệm vụ 3:", 18, 445, 40, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task3_Label_Status_1 = GUICtrlCreateLabel ("SYN SÀNG", 73, 445, 55, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task3_Label_Status_2 = GUICtrlCreateLabel ("Tính MD4", 140, 445, 130, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task3_Label_Status_3 = GUICtrlCreateLabel ("", 277, 445, 500, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
GUICtrlCreateLabel ("Nhiệm vụ 4:", 18, 473, 40, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task4_Label_Status_1 = GUICtrlCreateLabel ("SYN SÀNG", 73, 473, 55, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task4_Label_Status_2 = GUICtrlCreateLabel ("Tính MD5", 140, 473, 130, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task4_Label_Status_3 = GUICtrlCreateLabel ("", 277, 473, 500, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
GUICtrlCreateLabel ("Nhiệm vụ 5:", 18, 503, 40, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task5_Label_Status_1 = GUICtrlCreateLabel ("SYN SÀNG", 73, 503, 55, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task5_Label_Status_2 = GUICtrlCreateLabel ("Tính toán SHA1", 140, 503, 130, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task5_Label_Status_3 = GUICtrlCreateLabel ("", 277, 503, 500, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
GUICtrlCreateLabel ("Nhiệm vụ 6:", 18, 530, 40, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task6_Label_Status_1 = GUICtrlCreateLabel ("SYN SÀNG", 73, 530, 55, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task6_Label_Status_2 = GUICtrlCreateLabel ("Tính toán SHA256", 140, 530, 130, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task6_Label_Status_3 = GUICtrlCreateLabel ("", 277, 530, 500, 17)
GUICtrlCreateLabel ("Nhiệm vụ 7:", 18, 556, 40, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task7_Label_Status_1 = GUICtrlCreateLabel ("SYN SÀNG", 73, 556, 55, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task7_Label_Status_2 = GUICtrlCreateLabel ("Tính toán SHA384", 140, 556, 130, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task7_Label_Status_3 = GUICtrlCreateLabel ("", 277, 556, 500, 17)
GUICtrlCreateLabel ("Nhiệm vụ 8:", 18, 581, 40, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task8_Label_Status_1 = GUICtrlCreateLabel ("SYN SÀNG", 73, 581, 55, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task8_Label_Status_2 = GUICtrlCreateLabel ("Tính toán SHA512", 140, 581, 130, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Task8_Label_Status_3 = GUICtrlCreateLabel ("", 277, 581, 500, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
GUICtrlCreateLabel ("Số lượng tác vụ đang chạy:", 16, 352, 122, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Label_T Nhiệm_Rucky = GUICtrlCreateLabel ("0", 160, 352, 10, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
GUICtrlCreateLabel ("Số lượng tệp đã hoàn thành:", 200, 352, 129, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Label_Number_Files_Completed = GUICtrlCreateLabel ("0", 336, 352, 42, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
GUICtrlCreateLabel ("Trong tổng số tệp cần xử lý:", 400, 352, 117, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Label_Number_Files_Total = GUICtrlCreateLabel ("0", 520, 352, 72, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Nút1_Start = GUICtrlCreateButton ("Bắt đầu tính toán", 512, 8, 123, 33)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Nút2_STOP = GUICtrlCreateButton ("STOP", 656, 8, 51, 33)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Nút3_CLEAR = GUICtrlCreateButton ("RAR RÀNG", 720, 8, 51, 33)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Button4_Select_Files = GUICtrlCreateButton ("Chọn tệp ...", 608, 344, 171, 25)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Group_ListFile = GUICtrlCreategroup ("Kéo và thả tệp tại đây (hộp này)", 8, 40, 769, 297, BitOR ($ GUI_SS_DEFAULT_GROUP, $ BS_CENTER))
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ idListview = GUICtrlCreateListView ("NUM | STATUS | FILE | CRC32 | MD2 | MD4 | MD5 | SHA1 | SHA256 | SHA384 | SHA512", 24, 72, 745, 253)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
GUICtrlCreategroup ("", -99, -99, 1, 1)
Hộp kiểm $ toàn cầu1_CRC32 = GUICtrlCreateCheckbox ("CRC32", 16, 16, 50, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED + $ GUI_CHECKED)
Hộp kiểm $ toàn cầu2_MD2 = GUICtrlCreateCheckbox ("MD2", 72, 16, 50, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Hộp kiểm toàn cầu $ 3_MD4 = GUICtrlCreateCheckbox ("MD4", 128, 16, 50, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Hộp kiểm $ toàn cầu4_MD5 = GUICtrlCreateCheckbox ("MD5", 184, 16, 50, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED + $ GUI_CHECKED)
Hộp kiểm $ toàn cầu5_SHA1 = GUICtrlCreateCheckbox ("SHA1", 240, 16, 52, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED + $ GUI_CHECKED)
Hộp kiểm $ toàn cầu6_SHA256 = GUICtrlCreateCheckbox ("SHA256", 296, 16, 60, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED + $ GUI_CHECKED)
Hộp kiểm $ toàn cầu7_SHA384 = GUICtrlCreateCheckbox ("SHA384", 360, 16, 65, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Hộp kiểm $ toàn cầu8_SHA256 = GUICtrlCreateCheckbox ("SHA256", 440, 16, 73, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)
Toàn cầu $ Label_Status = GUICtrlCreateLabel ("Dòng trạng thái: Tất cả hành động đã hoàn tất, sẵn sàng cho yêu cầu tiếp theo!", 16, 608, 757, 17)
GUICtrlSetState (-1, $ GUI_DROPACCEPTED)

GUISetState (@SW_SHOW)
#EndRegion
_WinAPI_ChangeWindowMessageFilterEx ($ hHUI, $ WM_DROPFILES, $ MSGFLT_ALLOW); Kéo và thả trên quản trị viên
_WinAPI_ChangeWindowMessageFilterEx ($ hHUI, $ WM_COPYDATA, $ MSGFLT_ALLOW); Kéo và thả trên quản trị viên
_WinAPI_ChangeWindowMessageFilterEx ($ hHUI, $ WM_COPYGLOBALDATA, $ MSGFLT_ALLOW); Kéo và thả trên quản trị viên

Toàn cầu $ nMsg, $ __ aDropFiles
GUIRegisterMsg ($ WM_DROPFILES, "WM_DROPFILES")

; GUI KIỂM TRA DỮ LIỆU BẮT ĐẦU
; ~ GUICtrlCreateListViewItem ( "1 | OnProcess | C: \ Mikie Hara \ Shizuka Nakamura \ Buruma Aoi \ Satomi Suzuki \ Ai Sayama \ Nao \ Aki Hoshino.MP4 | F7331A65 ||| CCD6116BB67F24905F2B128FBE2B97BA | 74BC97D15B9B22649C228BC77D26C7D5011B52B0 | EFE6985D1A93D5CDE9E7F5F68AC52AF894B9FC59B3E24B8F635153D526FC940C ||", $ idListview)
; ~ GUICtrlCreateListViewItem ( "2 | OnProcess | C: \ Mai Nishida \ Suzuka Ishikawa \ Ameri Ichinose \ Uta Kohaku \ Các Cà \ Noriko Ashiya \ Rina Koike.ts | FFFFFFFF ||| 9F647B59874D8D10CE6F1102D5519C1A | B63F61838E6A93572A0519FF2D0846BCBE6DF370 | 2774B7FF1108FF9513D6ED1F7F58EFCB0FA30F161246FF2F8E751732560E0902 ||", $ idListview )
; ~ GUICtrlCreateListViewItem ( "3 | OnProcess | D: \ Megu Fujiura \ Rola Takizawa \ Maria Ozawa \ Ria Sakurai \ Shion Utsunomiya \ Emiri Suzuhara.mkv | 26E70099 ||| 2AB25EC471E53FBF3F241A5D3C51E138 | 2AA856E6DA6C991094335F64F45138592C451DDF | B0CFCE9490B987EC4359472853BC5007BD345D69475636508E0EB94327CD6669 ||", $ idListview)
; ~ GUICtrlCreateListViewItem ( "4 | OnProcess | E: \ Saori Hara \ Ameri Ichinose \ Akiho Yoshizawa \ Tsubasa Amami \ Risa Tachibana \ Tina Yuzuki.mp4 | 95.693.338 ||| CCC322F4B18222858715E22A085659AC | 220EB673D4AED9F1652C1CE3D2731CD96A8138F2 | 044263A3BA067F0967D311782916088BDB723CCC4E15E87FF4B2973E037E593E ||", $ idListview)
; ~ GUICtrlCreateListViewItem ("5 | OnProcess | F: \ Kotone-amamiya \ Erika Momotani \ Jun Aizawa \ Arisa kanno \ Yura Sakura \ Sana Anjyu (Hina Kurumi) .ts | CD5BC9F1 |
; ~ GUICtrlCreateListViewItem ("6 | OnProcess | G: \ Sora Aoi \ Shiori Kamisaki \ Takizawa Laura \ Rina Ishihara \ Rin Higurashi \ Aino Kishi \ Yui Hatano.mkv ||||||||", id
; ~ GUICtrlCreateListViewItem ("7 | OnProcess | H: \ Asuka Ichinose \ Anri Sugihara \ Ai Shinozaki \ Hiyo Nishizuku \ Riku Minato \ Kirara Asuka \ Necoco.MP4 ||||||||", id
; ~ GUICtrlCreateListViewItem ("8 | OnProcess | I: \ Hina Maeda \ Maki Hojo \ Yuma Asami \ Jessica Kizaki \ Kokomi Naruse \ Kana Yume \ Mihiro Taniguchi.TS ||||||||", $ idList
; GUI KIỂM TRA DỮ LIỆU

Trong khi 1
    $ nMsg = GUIGetMsg ()
    Chuyển đổi $ nMsg

        Vỏ $ GUI_EVENT_DROPPED
            Nếu ($ __ aDropFiles [0]> 0) Sau đó
                Với $ i = 1 đến $ __ aDropFiles [0]
                    ConsoleWrite ($ __ aDropFiles [$ i] & @CRLF)
                    GUICtrlCreateListViewItem ($ i & "|" & "WAIT |" & $ __ aDropFiles [$ i] & "||||||||", $ idListview)
                Kế tiếp
            Hết

        Trường hợp $ Nút1_Start

        Vỏ $ Nút2_STOP

        Vỏ $ Nút3_CLEAR

        Trường hợp $ Nút4_Select_Files

        Vỏ $ GUI_EVENT_CLOSE
            Lối ra

    Kết thúc
VÒI

Func _HashFile ($ sFilePath, $ iAlgID, $ s Index = 0)

; ~ $ CALG_MD2 0x00008001; Thuật toán băm 128 bit
; ~ $ CALG_MD4 0x00008002; Thuật toán băm 128 bit
; ~ $ CALG_MD5 0x00008003; Thuật toán băm 128 bit
; ~ $ CALG_SHA1 0x00008004; Thuật toán băm 160 bit
; ~ $ CALG_SHA_256 0x0000800c; Thuật toán băm 256-bit
; ~ $ CALG_SHA_384 0x0000800d; Thuật toán băm 384-bit
; ~ $ CALG_SHA_512 0x0000800e; Thuật toán băm 512-bit
    $ SFileSize = FileGetSize ($ sFilePath)
    $ ITimeInit cục bộ = TimerInit ()
    $ DHash = _Crypt_HashFile ($ sFilePath, $ iAlgID)
    $ ITimerDiff = TimerDiff ($ iTimeInit) cục bộ

EndFunc; ==> _ HashFile


Func _FormatElapsedTime ($ Input_Seconds = 0)
    Nếu $ Input_Seconds <1 thì trả về 0
    $ Input_Seconds = $ Input_Seconds / 1000
    $ ElapsedMessage = '', $ Input = $ Input_Seconds, $ Minutes, $ Hour, $ Days
    Chuyển $ Input_Seconds
        Trường hợp 0 đến 59
            $ ElapsedMessage & = Round ($ Input, 3) & 'giây.'
        Trường hợp 60 đến 3599
            $ Phút = Int ($ Đầu vào / 60)
            $ Input - = ($ Phút * 60)
            $ ElapsedMessage & = $ Phút & 'phút,'
            $ ElapsedMessage & = Int ($ Input) & 'giây.'
        Vỏ 3600 đến 86399
            $ Giờ = Int ($ Đầu vào / 3600)
            $ Đầu vào - = ($ Giờ * 3600)
            $ ElapsedMessage & = $ Giờ & 'giờ,'
            $ Phút = Int ($ Đầu vào / 60)
            $ Input - = ($ Phút * 60)
            $ ElapsedMessage & = $ Phút & 'phút,'
            $ ElapsedMessage & = Int ($ Input) & 'giây.'
        Trường hợp khác
            $ Ngày = Int ($ Đầu vào / 86400)
            $ Đầu vào - = ($ Ngày * 86400)
            $ ElapsedMessage & = $ Ngày & 'ngày,'
            $ Giờ = Int ($ Đầu vào / 3600)
            $ Đầu vào - = ($ Giờ * 3600)
            $ ElapsedMessage & = $ Giờ & 'giờ,'
            $ Phút = Int ($ Đầu vào / 60)
            $ Input - = ($ Phút * 60)
            $ ElapsedMessage & = $ Phút & 'phút,'
            $ ElapsedMessage & = Int ($ Input) & 'giây.'
    Kết thúc
    Trả lại $ ElapsedMessage
EndFunc; ==> _ FormatElapsedTime

Func _ByteSuffix ($ iBytes, $ iRound = 2); Bởi Spiff59
    $ A, $ aArray [9] = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
    Trong khi $ iBytes> 1023
        $ a + = 1
        $ iBytes / = 1024
    VÒI
    Vòng quay lại ($ iBytes, $ iRound) & $ aArray [$ a]
EndFunc; ==> _ ByteSuffix

Func WM_DROPFILES ($ hWnd, $ iMsg, $ iwParam, $ ilParam)
    #forceref $ hWnd, $ ilParam
    Chuyển đổi $ iMsg
        Vỏ $ WM_DROPFILES
            $ AReturn = _WinAPI_DragQueryFileEx ($ iwParam) cục bộ
            Nếu IsArray ($ aReturn) Sau đó
                $ __ aDropFiles = $ aReturn
            Khác
                $ AError [1] = [0] cục bộ
                $ __ aDropFiles = $ aError
            Hết
    Kết thúc
    Trả lại $ GUI_RUNDEFMSG
EndFunc; ==> WM_DROPFILES

I want somthing like:

EG.png

Cảm ơn

Edited by VIP
Solved by Chimp

Regards,
 

Link to comment
Share on other sites

Sorry I can't offer code, but perhaps I can offer some information, apologies if this repeats what you have already figured out:

I'm not aware that any of the algorithms you are looking at can be conventionally calculated in a parallel environment for a single file. Exceptions being a non-conventional version of md5 which is not portable (sorry can't remember the details) and a possible technique to split the file process and the checksum process into two threads (sounds impossible within AutoIt).

So lets assume you are splitting the job by a file with one checksum operation per thread. So you now have a job queue that looks something like this:

File A - CRC32 
File A - SHA5
File B - CRC32
File C - SHA5

Each one of these in a separate thread. So all you need to do is build a very basic job queuing system for however many cores you have available e.g. an array that you keep taking the last job from would do.

The way this is most likely to disappoint is the volume of file data you are trying to load into memory at the same time, it will probably choke on the I/O.

Depending on your algorithms, file sizes and hardware, there may be options to deliberately delay launching the separate processes or controlling running processes to stagger the I/O access versus CPU time.

I've not done any parallel work with AutoIt, but a quick search turned up these options

Choose a core to launch on
https://www.autoitscript.com/forum/topic/70395-running-a-process-on-a-specific-core/

Communicate between processes
https://www.autoitscript.com/forum/topic/179457-interprocess-communication-help/

You may not even need inter-processor comms as you could just use a flat file of jobs that all your processes pick up tasks from (delete the task from the list once collected). Obviously, care with file locking. Personally, I'm so lazy I would just skip the whole parallel coding side and run the application 6 times and manually load each one up with a subset of jobs.

I hope that gives some ideas anyway.

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

On 9/27/2019 at 12:48 AM, VIP said:

Any help or suggestions are welcome, thanks for reading.

an udf I wrote some time ago may be handy for your goal.
That udf allows you to run many separate tasks and collect results when are ready.
a needed condition for the tasks is that those must be run detached from the main scipt and must allow I/O streams redirection.

now, if your tasks are executed by autoit functions instead of external executables, you can still adopt a solution like this: create an "external" autoit script that accepts command line parameters, and returns results back to the caller (a sort of foreign AutoIt function callable from the main script, but runned detached). In this way you can run more instances of that function at a time  and collect results while available.
Here is how:
from the main script use a statement similar to this

$hPid = Run(@AutoItExe & ' Ext_Func.au3 Param1 ' & $Param2 & ' $Param3', "", @SW_HIDE, 0x2) ; (0x2) -> $STDOUT_CHILD  = Provide a handle to the child's STDOUT stream

where Ext_Func.au3 is the external script followed by parameters separated by spaces.
In the external script you get parameters by the  $CmdLine[] variable and you send results to the caller using the Consolewrite function.

(this is performed automatically if you use the MultiTask.udf)

Since an example is better than many words (especially if talked by a non-native speaker), here it is:
to calculate some of the "hash" you need I've used this nice function by @Danyfirex  and I've adapted it a bit so to be an "external" function.

Quote

WARNING
since the processing of the hash is quite "memory hungry" and intensive for the CPU, if you try to process several large files at the same time, you could risk sending the CPU overloaded and running out of memory with a consequent computer stuck.
To test the performance of your PC, start by dropping some small files so to check the CPU / memory load gradually.

Save this function as hash_hmac.au3 in the folder along with your main script.

; by Danyfirex
; see here: https://www.autoitscript.com/forum/topic/191500-hash-hmac/

If $CmdLine[0] < 3 Then Exit

; Read parameters
Local $sXkey = $CmdLine[1] ; Key
Local $sFile = $CmdLine[2] ; File Path
Local $sHash = $CmdLine[3] ; hash algorithm

If Not FileExists($sFile) Then Exit
If Not StringInStr("|SHA512|SHA256|SHA1|SHA384|MD5|RIPEMD160|", '|' & $sHash & '|') Then Exit

Local $hFile = FileOpen($sFile, 16) ;  16 -> $FO_BINARY (16) = Force binary mode
Local $oHMAC = ObjCreate("System.Security.Cryptography.HMAC" & $sHash)
$oHMAC.key = Binary($sXkey)
; Calculate hash hmac of the file
Local $bHash = $oHMAC.ComputeHash_2(FileRead($hFile))
ConsoleWrite($bHash) ; send result to stdout

I have also modified/added only small parts of your main script just to allow the use of the MultiTask.udf, leaving everything else unchanged. I leave you the control of your overall logic ...
so save also this modified version of your Main script and run it (of course no need to say to also save the MultiTask.udf  udf in your folder)
Parts I've modified are enclosed between two comment lines like this:

; ==========================================================================================================

To see it in action drop some files on the GUI and then hit your "Start calculate" button.

; #RequireAdmin
Opt("TrayAutoPause", 0)
Opt("MustDeclareVars", 1)
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <Crypt.au3>
; ==========================================================================================================
#include 'MultiTask.au3' ; <-- get here: https://www.autoitscript.com/forum/topic/192157-multi-task-easily-run-and-mange-many-processes/
; ==========================================================================================================
#Region
Global $hHUI = GUICreate("AutoIT Hash Caculator", 791, 640, 652, 117, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateLabel("Task 1:", 18, 384, 40, 17)
Global $Task1_Label_Status_1 = GUICtrlCreateLabel("DREADY", 73, 384, 55, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task1_Label_Status_2 = GUICtrlCreateLabel("Calculate CRC32", 140, 384, 130, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task1_Label_Status_3 = GUICtrlCreateLabel("", 277, 384, 500, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateLabel("Task 2:", 18, 416, 40, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task2_Label_Status_1 = GUICtrlCreateLabel("READY", 73, 416, 55, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task2_Label_Status_2 = GUICtrlCreateLabel("Calculate MD2", 140, 416, 130, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task2_Label_Status_3 = GUICtrlCreateLabel("", 277, 416, 500, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateLabel("Task 3:", 18, 445, 40, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task3_Label_Status_1 = GUICtrlCreateLabel("READY", 73, 445, 55, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task3_Label_Status_2 = GUICtrlCreateLabel("Calculate MD4", 140, 445, 130, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task3_Label_Status_3 = GUICtrlCreateLabel("", 277, 445, 500, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateLabel("Task 4:", 18, 473, 40, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task4_Label_Status_1 = GUICtrlCreateLabel("READY", 73, 473, 55, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task4_Label_Status_2 = GUICtrlCreateLabel("Calculate MD5 ", 140, 473, 130, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task4_Label_Status_3 = GUICtrlCreateLabel("", 277, 473, 500, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateLabel("Task 5:", 18, 503, 40, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task5_Label_Status_1 = GUICtrlCreateLabel("READY", 73, 503, 55, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task5_Label_Status_2 = GUICtrlCreateLabel("Calculate SHA1 ", 140, 503, 130, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task5_Label_Status_3 = GUICtrlCreateLabel("", 277, 503, 500, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateLabel("Task 6:", 18, 530, 40, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task6_Label_Status_1 = GUICtrlCreateLabel("READY", 73, 530, 55, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task6_Label_Status_2 = GUICtrlCreateLabel("Calculate SHA256 ", 140, 530, 130, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task6_Label_Status_3 = GUICtrlCreateLabel("", 277, 530, 500, 17)
GUICtrlCreateLabel("Task 7:", 18, 556, 40, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task7_Label_Status_1 = GUICtrlCreateLabel("READY", 73, 556, 55, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task7_Label_Status_2 = GUICtrlCreateLabel("Calculate SHA384 ", 140, 556, 130, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task7_Label_Status_3 = GUICtrlCreateLabel("", 277, 556, 500, 17)
GUICtrlCreateLabel("Task 8:", 18, 581, 40, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task8_Label_Status_1 = GUICtrlCreateLabel("READY", 73, 581, 55, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task8_Label_Status_2 = GUICtrlCreateLabel("Calculate SHA512 ", 140, 581, 130, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Task8_Label_Status_3 = GUICtrlCreateLabel("", 277, 581, 500, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateLabel("Number of tasks running:", 16, 352, 122, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Label_Tasks_Running = GUICtrlCreateLabel("0", 160, 352, 10, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateLabel("Number of completed files:", 200, 352, 129, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Label_Number_Files_Completed = GUICtrlCreateLabel("0", 336, 352, 42, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateLabel("Of total files to process: ", 400, 352, 117, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Label_Number_Files_Total = GUICtrlCreateLabel("0", 520, 352, 72, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Button1_Start = GUICtrlCreateButton("Start Calculate ", 512, 8, 123, 33)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Button2_STOP = GUICtrlCreateButton("STOP", 656, 8, 51, 33)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Button3_CLEAR = GUICtrlCreateButton("CLEAR", 720, 8, 51, 33)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Button4_Select_Files = GUICtrlCreateButton("Select file ...", 608, 344, 171, 25)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Group_ListFile = GUICtrlCreateGroup("Drag and Drop files here (this box)", 8, 40, 769, 297, BitOR($GUI_SS_DEFAULT_GROUP, $BS_CENTER))
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $idListview = GUICtrlCreateListView("NUM|STATUS|FILE|CRC32|MD2|MD4|MD5|SHA1|SHA256|SHA384|SHA512", 24, 72, 745, 253)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Checkbox1_CRC32 = GUICtrlCreateCheckbox("CRC32", 16, 16, 50, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED + $GUI_CHECKED)
Global $Checkbox2_MD2 = GUICtrlCreateCheckbox("MD2", 72, 16, 50, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Checkbox3_MD4 = GUICtrlCreateCheckbox("MD4", 128, 16, 50, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Checkbox4_MD5 = GUICtrlCreateCheckbox("MD5", 184, 16, 50, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED + $GUI_CHECKED)
Global $Checkbox5_SHA1 = GUICtrlCreateCheckbox("SHA1", 240, 16, 52, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED + $GUI_CHECKED)
Global $Checkbox6_SHA256 = GUICtrlCreateCheckbox("SHA256", 296, 16, 60, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED + $GUI_CHECKED)
Global $Checkbox7_SHA384 = GUICtrlCreateCheckbox("SHA384", 360, 16, 65, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Checkbox8_SHA256 = GUICtrlCreateCheckbox("SHA256", 440, 16, 73, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Global $Label_Status = GUICtrlCreateLabel("Status line: All action is completed, ready for the next request!", 16, 608, 757, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)

GUISetState(@SW_SHOW)
#EndRegion
_WinAPI_ChangeWindowMessageFilterEx($hHUI, $WM_DROPFILES, $MSGFLT_ALLOW) ; Drag and Drop on Admin
_WinAPI_ChangeWindowMessageFilterEx($hHUI, $WM_COPYDATA, $MSGFLT_ALLOW) ; Drag and Drop on Admin
_WinAPI_ChangeWindowMessageFilterEx($hHUI, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW) ; Drag and Drop on Admin

Global $nMsg, $__aDropFiles
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")

; EG DATA TEST GUI START
;~ GUICtrlCreateListViewItem("1|OnProcess|C:\Mikie Hara\Shizuka Nakamura\Buruma Aoi\Satomi Suzuki\Ai Sayama\Nao\Aki Hoshino.MP4|F7331A65|||CCD6116BB67F24905F2B128FBE2B97BA|74BC97D15B9B22649C228BC77D26C7D5011B52B0|EFE6985D1A93D5CDE9E7F5F68AC52AF894B9FC59B3E24B8F635153D526FC940C||", $idListview)
;~ GUICtrlCreateListViewItem("2|OnProcess|C:\Mai Nishida\Suzuka Ishikawa\Ameri Ichinose\Uta Kohaku\The Ca\Noriko Ashiya\Rina Koike.ts|FFFFFFFF|||9F647B59874D8D10CE6F1102D5519C1A|B63F61838E6A93572A0519FF2D0846BCBE6DF370|2774B7FF1108FF9513D6ED1F7F58EFCB0FA30F161246FF2F8E751732560E0902||", $idListview)
;~ GUICtrlCreateListViewItem("3|OnProcess|D:\Megu Fujiura\Rola Takizawa\Maria Ozawa\Ria Sakurai\Shion Utsunomiya\Emiri Suzuhara.mkv|26E70099|||2AB25EC471E53FBF3F241A5D3C51E138|2AA856E6DA6C991094335F64F45138592C451DDF|B0CFCE9490B987EC4359472853BC5007BD345D69475636508E0EB94327CD6669||", $idListview)
;~ GUICtrlCreateListViewItem("4|OnProcess|E:\Saori Hara\Ameri Ichinose\Akiho Yoshizawa\Tsubasa Amami\Risa Tachibana\Tina Yuzuki.mp4|95693338|||CCC322F4B18222858715E22A085659AC|220EB673D4AED9F1652C1CE3D2731CD96A8138F2|044263A3BA067F0967D311782916088BDB723CCC4E15E87FF4B2973E037E593E||", $idListview)
;~ GUICtrlCreateListViewItem("5|OnProcess|F:\Kotone-amamiya\Erika Momotani\Jun Aizawa\Arisa kanno\Yura Sakura\Sana Anjyu (Hina Kurumi).ts|CD5BC9F1|||||||", $idListview)
;~ GUICtrlCreateListViewItem("6|OnProcess|G:\Sora Aoi\Shiori Kamisaki\Takizawa Laura\Rina Ishihara\Rin Higurashi\Aino Kishi\Yui Hatano.mkv||||||||", $idListview)
;~ GUICtrlCreateListViewItem("7|OnProcess|H:\Asuka Ichinose\Anri Sugihara\Ai Shinozaki\Hiyo Nishizuku\Riku Minato\Kirara Asuka\Necoco.MP4||||||||", $idListview)
;~ GUICtrlCreateListViewItem("8|OnProcess|I:\Hina Maeda\Maki Hojo\Yuma Asami\Jessica Kizaki\Kokomi Naruse\Kana Yume\Mihiro Taniguchi.TS||||||||", $idListview)
; EG DATA TEST GUI END
; ==========================================================================================================
Local $sFile, $tasks
; ==========================================================================================================
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_DROPPED
            If ($__aDropFiles[0] > 0) Then
                For $i = 1 To $__aDropFiles[0]
                    ConsoleWrite($__aDropFiles[$i] & @CRLF)
                    GUICtrlCreateListViewItem($i & "|" & "WAIT|" & $__aDropFiles[$i] & "||||||||", $idListview)
                Next
            EndIf

        Case $Button1_Start
            ; ==========================================================================================================
            ; Get filenames directly from the ListView
            If _GUICtrlListView_GetItemCount($idListview) Then
                ; for each file run more tasks
                For $i = 0 To _GUICtrlListView_GetItemCount($idListview) - 1
                    $sFile = _GUICtrlListView_GetItemText($idListview, $i, 2)
                    ; for each file run 5 tasks
                    _TaskRun($i, @AutoItExe & ' .\hash_hmac.au3' & " MyCriptKey" & " " & $sFile & " MD5", "_SetColumn6")
                    _TaskRun($i, @AutoItExe & ' .\hash_hmac.au3' & " MyCriptKey" & " " & $sFile & " SHA1", "_SetColumn7")
                    _TaskRun($i, @AutoItExe & ' .\hash_hmac.au3' & " MyCriptKey" & " " & $sFile & " SHA256", "_SetColumn8")
                    _TaskRun($i, @AutoItExe & ' .\hash_hmac.au3' & " MyCriptKey" & " " & $sFile & " SHA384", "_SetColumn9")
                    _TaskRun($i, @AutoItExe & ' .\hash_hmac.au3' & " MyCriptKey" & " " & $sFile & " SHA512", "_SetColumn10")
                Next

                Do
                    Sleep(250)
                    ; you could perform other jobs here while waiting for the tasks to finish

                    $tasks = _TasksCheckStatus() ; manages the running tasks and get number of tasks still running
                    GUICtrlSetData($Label_Tasks_Running, $tasks)
                Until Not $tasks ; _TasksCheckStatus() ; <-- this function performs management of running tasks
                ;                                   and should be called as often as possible
                MsgBox(0, "Done", "Tasks completed", 2)
            EndIf
            ; ==========================================================================================================
        Case $Button2_STOP

        Case $Button3_CLEAR
            ; ==========================================================================================================
            _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($idListview)) ; empty the listview
            ; ==========================================================================================================
        Case $Button4_Select_Files

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch

WEnd

Func _HashFile($sFilePath, $iAlgID, $sIndex = 0)

;~ $CALG_MD2 0x00008001; Hashing algorithm 128-bit
;~ $CALG_MD4 0x00008002; Hashing algorithm 128-bit
;~ $CALG_MD5 0x00008003; Hashing algorithm 128-bit
;~ $CALG_SHA1 0x00008004; Hashing algorithm 160-bit
;~ $CALG_SHA_256 0x0000800c; Hashing algorithm 256-bit
;~ $CALG_SHA_384 0x0000800d; Hashing algorithm 384-bit
;~ $CALG_SHA_512 0x0000800e; Hashing algorithm 512-bit
    Local $sFileSize = FileGetSize($sFilePath)
    Local $iTimeInit = TimerInit()
    Local $dHash = _Crypt_HashFile($sFilePath, $iAlgID)
    Local $iTimerDiff = TimerDiff($iTimeInit)

EndFunc   ;==>_HashFile


Func _FormatElapsedTime($Input_Seconds = 0)
    If $Input_Seconds < 1 Then Return 0
    $Input_Seconds = $Input_Seconds / 1000
    Local $ElapsedMessage = '', $Input = $Input_Seconds, $Minutes, $Hours, $Days
    Switch $Input_Seconds
        Case 0 To 59
            $ElapsedMessage &= Round($Input, 3) & ' seconds.'
        Case 60 To 3599
            $Minutes = Int($Input / 60)
            $Input -= ($Minutes * 60)
            $ElapsedMessage &= $Minutes & ' minutes, '
            $ElapsedMessage &= Int($Input) & ' seconds.'
        Case 3600 To 86399
            $Hours = Int($Input / 3600)
            $Input -= ($Hours * 3600)
            $ElapsedMessage &= $Hours & ' hours, '
            $Minutes = Int($Input / 60)
            $Input -= ($Minutes * 60)
            $ElapsedMessage &= $Minutes & ' minutes, '
            $ElapsedMessage &= Int($Input) & ' seconds.'
        Case Else
            $Days = Int($Input / 86400)
            $Input -= ($Days * 86400)
            $ElapsedMessage &= $Days & ' days, '
            $Hours = Int($Input / 3600)
            $Input -= ($Hours * 3600)
            $ElapsedMessage &= $Hours & ' hours, '
            $Minutes = Int($Input / 60)
            $Input -= ($Minutes * 60)
            $ElapsedMessage &= $Minutes & ' minutes, '
            $ElapsedMessage &= Int($Input) & ' seconds.'
    EndSwitch
    Return $ElapsedMessage
EndFunc   ;==>_FormatElapsedTime

Func _ByteSuffix($iBytes, $iRound = 2) ; By Spiff59
    Local $a, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", "EB", "ZB", "YB"]
    While $iBytes > 1023
        $a += 1
        $iBytes /= 1024
    WEnd
    Return Round($iBytes, $iRound) & $aArray[$a]
EndFunc   ;==>_ByteSuffix

Func WM_DROPFILES($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $ilParam
    Switch $iMsg
        Case $WM_DROPFILES
            Local $aReturn = _WinAPI_DragQueryFileEx($iwParam)
            If IsArray($aReturn) Then
                $__aDropFiles = $aReturn
            Else
                Local $aError[1] = [0]
                $__aDropFiles = $aError
            EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DROPFILES
; ==========================================================================================================
; Task's Callback functions
; -------------------------
Func _SetColumn6($aData)
    _GUICtrlListView_SetItemText($idListview, $aData[0], Binary($aData[1]), 6) ; column 6 MD5
EndFunc   ;==>_SetColumn6

Func _SetColumn7($aData)
    _GUICtrlListView_SetItemText($idListview, $aData[0], Binary($aData[1]), 7) ; column 7 SHA1
EndFunc   ;==>_SetColumn7

Func _SetColumn8($aData)
    _GUICtrlListView_SetItemText($idListview, $aData[0], Binary($aData[1]), 8) ; column 8 SHA256
EndFunc   ;==>_SetColumn8

Func _SetColumn9($aData)
    _GUICtrlListView_SetItemText($idListview, $aData[0], Binary($aData[1]), 9) ; column 9 SHA384
EndFunc   ;==>_SetColumn9

Func _SetColumn10($aData)
    _GUICtrlListView_SetItemText($idListview, $aData[0], Binary($aData[1]), 10) ; column 10 SHA512
EndFunc   ;==>_SetColumn10
; ==========================================================================================================

 

Edited by Chimp
added a warning

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...