#AutoIt3Wrapper_Res_Fileversion=1.0.1 global const $version = "1.0.1" ; Simple Checksum ~ checksum's little brother. ; (c) corz.org 2003->. #include #include #include #include #include #include "..\Includes\checksumShared.au3" global $running = true global $drop_files[2] global const $INSTANCE_READY_TIMEOUT = 10000 AutoItSetOption("GUIOnEventMode", 1) AutoItSetOption("GUICoordMode", 0) AutoItSetOption("TrayMenuMode", 11) AutoItSetOption("TrayOnEventMode", 1) GUIRegisterMsg($WM_DROPFILES, "HandleMsgDroppedFiles") GUIRegisterMsg($WM_EXITSIZEMOVE, "HandleMsgFinishedMoving") GUIRegisterMsg($WM_SIZING, "HandleMsgResizing") $app_name = "simple checksum" global $visible_title = " " & $app_name global $app_url = "https://corz.org/windows/software/checksum/simple-checksum.php" global $GUI, $exe_path, $client_size, $win_width global $incoming_cmd_line global $curr_input, $hash_1, $hash_2, $app_dir, $current_title global $default_ini_path = "checksum.ini" global $cached_hashes[4][2] = [[3]] global $tray_items[12] = [""] ; Portable mode.. if _LFN_FileExists(@ScriptDir & "\" & $default_ini_path) then $app_dir = @ScriptDir $ini_path = $app_dir & "\" & $default_ini_path FileChangeDir(@ScriptDir) else $app_dir = @AppDataDir & "\corz\checksum" if not _LFN_FileExists($app_dir) then _LFN_DirCreate($app_dir) $ini_path = $app_dir & "\" & $default_ini_path if not _LFN_FileExists($ini_path) then FileInstall("..\checksum\Source\Resources\checksum.ini", $ini_path) endif if @Compiled then $exe_path = @ScriptFullPath else $exe_path = ".\" & $app_name & ".exe" endif $debug_level = Int(IniRead($ini_path, $app_name, "debug_level", 0)) global $dump_file="dump" if $debug_level then $dump_file = IniRead($ini_path, $app_name, "dump_file", $dump_file) MakeAFile($dump_file, true) ; true = wipe. InitDebug() endif ; Start gathering prefs.. global $simple_x = IniRead($ini_path, $app_name, "simple_x", -1) global $simple_y = IniRead($ini_path, $app_name, "simple_y", -1) global $algorithm = IniRead($ini_path, $app_name, "algorithm", $hash_algorithms[3]) $algorithm_id = _ArraySearch($hash_algorithms, $algorithm, 1) if $algorithm_id = -1 then $algorithm_id = 3 $algorithm = $hash_algorithms[$algorithm_id] IniWrite($ini_path, $app_name, "algorithm", $algorithm) endif debug("algorithm: =>" & $algorithm & "<=" , @ScriptLineNumber, 2);debug debug("algorithm_id: =>" & $algorithm_id & "<=" , @ScriptLineNumber, 2);debug global $edge_snap = IniReadCheckBox($ini_path, $app_name, "edge_snap", $OFF) global $snap_distance = IniRead($ini_path, $app_name, "snap_distance", 8) if $snap_distance < 1 or $snap_distance > @DesktopHeight / 2 then $snap_distance = 8 ; TODO pref for this so no need to write here. IniWrite($ini_path, $app_name, "snap_distance", $snap_distance) global $uppercase = IniReadCheckBox($ini_path, $app_name, "uppercase", $OFF) global $on_top = IniReadCheckBox($ini_path, $app_name, "on_top", $OFF) global $autocopy = IniReadCheckBox($ini_path, $app_name, "autocopy", $OFF) global $autosave = IniReadCheckBox($ini_path, $app_name, "autosave", $OFF) global $transparency = IniRead($ini_path, $app_name, "transparency", 0) if $transparency < 0 or $transparency > 90 then $transparency = 0 SaveTransparency() endif global $trans_alpha = 255 * (100 - $transparency) / 100 global $opaque_on_mouseover = IniReadCheckBox($ini_path, $app_name, "opaque_on_mouseover", $OFF) global $close_to_tray = IniReadCheckBox($ini_path, $app_name, "close_to_tray", $OFF) SetupTray($close_to_tray) global $simple_width = IniRead($ini_path, $app_name, "simple_width", 320) if $simple_width < 180 then $simple_width = 180 ; Create the main Graphical User Interface.. global $gui_parent = 0 global $hide_taskbar_entry = IniReadCheckBox($ini_path, $app_name, "hide_taskbar_entry", $ON) if $hide_taskbar_entry = $ON then $gui_parent = GUICreate(-1, -1, -1, -1, -1, $WS_EX_TOOLWINDOW) $GUI = GUICreate($visible_title & " [" & $algorithm & "]", $simple_width, 32, $simple_x, $simple_y, _ BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX), $WS_EX_ACCEPTFILES, $gui_parent) GUISetIcon($exe_path, 0, $GUI) GUICtrlSetTip(-1, " click the application menu (top-left) for some visual options. ") GUISetOnEvent($GUI_EVENT_MINIMIZE, "ToggleGUI") if $close_to_tray = $ON then GUISetOnEvent($GUI_EVENT_CLOSE, "ToggleGUI") else GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") endif global $input = GUICtrlCreateInput("", 7, 7, $simple_width - 70, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetTip(-1, " input a string and click 'hash it' (or hit or ALT-A)" & @LF & _ " or simply drag files onto here to automatically compute their checksum. ") GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKLEFT + $GUI_DOCKMENUBAR + $GUI_DOCKWIDTH) debugPrintArray($CmdLine, "$CmdLine:", @ScriptLineNumber, 8);debug global $cmd_line = $CmdLine debugPrintArray($cmd_line, "$cmd_line:", @ScriptLineNumber, 8);debug ; ; Singleton.. ; Ensure we only run a single instance. ; Handle command-line data from second instance and pass to running instance. global $app_id = "simple_checksum_sys_msg" ; some arbitrary string we can set as a unique identifier in the Windows subsystem. global $msg_restore = DllCall("user32.dll", "uint", "RegisterWindowMessageW", "wstr", $app_id)[0] SetError(0) if _Singleton($app_id, 1) = 0 then ; Only the fully initialized primary window has this property. ; Titles change during hashing and can also match this new window. local $existing_window = 0 local $instance_wait = TimerInit() while not $existing_window and TimerDiff($instance_wait) < $INSTANCE_READY_TIMEOUT local $instance_windows = WinList("[CLASS:AutoIt v3 GUI]") for $instance_index = 1 to $instance_windows[0][0] local $instance_property = DllCall("user32.dll", "handle", "GetPropW", "hwnd", $instance_windows[$instance_index][1], "wstr", $app_id) if @error then continueloop if $instance_property[0] then $existing_window = $instance_windows[$instance_index][1] exitloop endif next if not $existing_window then Sleep(10) wend if not $existing_window then exit 5 debug("************************** _Singleton() [SECOND INSTANCE] ACTIVATED! [0]: =>" & $cmd_line[0] & "<=", @ScriptLineNumber, 2) debug("existing_window: =>" & $existing_window & "<= Our Window .. @error .. Zero here means ALL GOOD =>" & @error & "<=", @ScriptLineNumber, 2) local $command_line = "" for $index = 1 to $cmd_line[0] $command_line &= $cmd_line[$index] & chr(1) next local $string_struct = DllStructCreate("wchar[" & (stringlen($command_line) + 1) & "]") DllStructSetData($string_struct, 1, $command_line) local $copy_data_struct = DllStructCreate("uint_ptr dwData;dword cbData;ptr lpData") DllStructSetData($copy_data_struct, "dwData", 1) DllStructSetData($copy_data_struct, "cbData", DllStructGetSize($string_struct)) DllStructSetData($copy_data_struct, "lpData", DllStructGetPtr($string_struct)) local $send_result = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $existing_window, "uint", $WM_COPYDATA, "wparam", 0, "lparam", DllStructGetPtr($copy_data_struct)) debug("send_result: =>" & $send_result[0] & "<=", @ScriptLineNumber, 2) DllCall("user32.dll", "bool", "PostMessageW", "hwnd", $existing_window, "uint", $msg_restore, "wparam", 0, "lparam", 0) exit 5 endif global $butt_hash_it = GUICtrlCreateButton("h&ash it", $simple_width - 61, 0, 50, 20) GUICtrlSetOnEvent(-1, "OnHashClick") GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetTip(-1, " click this (or hit or ALT-A) to get your checksum" & @LF & _ " if it's a real file, you'll get a checksum of the file, or else it is treated as a string. " & @LF & _ " [right-click this button for the open/save menu] ") GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSTATEBAR + $GUI_DOCKWIDTH) global $hash_butt_context_menu = GUICtrlCreateContextMenu($butt_hash_it) global $hash_butt_context_save = GUICtrlCreateMenuItem("Save hash to file.. Ctrl+S", $hash_butt_context_menu, 0) GUICtrlSetOnEvent(-1, "SaveFileDialog") GUICtrlSetState(-1, $GUI_DISABLE) global $hash_butt_context_open = GUICtrlCreateMenuItem("Open file to hash.. Ctrl+O", $hash_butt_context_menu, 0) GUICtrlSetOnEvent(-1, "OpenFileDialog") HotKeySet("{Enter}", "OnEnter") HotKeySet("^a", "OnSelectAll") HotKeySet("^o", "OpenFileDialog") HotKeySet("^s", "SaveFileDialog") HotKeySet("!c", "OnToggleCompare") HotKeySet("!m", "SelectMD5") HotKeySet("!s", "SelectSHA1") HotKeySet("!2", "SelectSHA2") HotKeySet("^t", "OnToggleOnTop") HotKeySet("^z", "OnToggleSnap") HotKeySet("!u", "OnToggleUpper") HotKeySet("^h", "ShowHelp") HotKeySet("^i", "OnOpenIni") WinSetTrans($GUI, "", $trans_alpha) GUICtrlSetState($input, $GUI_ONTOP) GUISetState() ; Capture actual minimum height now. global $win_pos = WinGetPos($GUI, "") debugPrintArray($win_pos, "$win_pos:", @ScriptLineNumber, 8);debug OutputPrefs() ; App menu.. global $transparency_menu_id = 0 GUIRegisterMsg($WM_SYSCOMMAND, "HandleSysCommandMsg") AddSysMenuItem("", -1, false, 0) global $menu_close_to_tray = AddSysMenuItem("Close to System Tray", -1, false, 0) ToggleCloseToTray(true) ToggleCloseToTray(true) AddSysMenuItem("", -1, false, 0) global $menu_hide_taskbar = AddSysMenuItem("Hide Taskbar Entry", -1, false, 0) ToggleHideTaskbar(true) ToggleHideTaskbar(true) AddSysMenuItem("", -1, false, 0) global $menu_on_top = AddSysMenuItem("Al&ways on Top Ctrl+T", -1, false, 0) ToggleOnTop(true) ToggleOnTop(true) AddSysMenuItem("", -1, false, 0) global $menu_snap = AddSysMenuItem("Snap to Edges Ctrl+Z", -1, false, 0) ToggleSnap(true) ToggleSnap(true) AddSysMenuItem("", -1, false, 0) global $menu_transpacency = AddSysMenuItem("&Transparency..", -1, true, 0) global $menu_trans_items[10] global $idx for $idx = 0 to 9 $menu_trans_items[$idx] = AddSysMenuItem($idx * 10 & "%", $menu_transpacency) if $idx = $transparency / 10 then $transparency_menu_id = $menu_trans_items[$idx] CheckMenuItem($menu_transpacency, $transparency_menu_id, $MF_CHECKED) endif next AddSysMenuItem("", $menu_transpacency) global $menu_opaque = AddSysMenuItem("Opaque On MouseOver", $menu_transpacency) if $opaque_on_mouseover = $ON then CheckMenuItem($menu_transpacency, $menu_opaque, $MF_CHECKED) AddSysMenuItem("", -1, false, 0) global $menu_auto = AddSysMenuItem("&Auto..", -1, true, 0) global $menu_autosave = AddSysMenuItem("Auto Save to File", $menu_auto, false, 0) if $autosave = $ON then CheckMenuItem($menu_auto, $menu_autosave, $MF_CHECKED) global $menu_autocopy = AddSysMenuItem("Auto Copy to Clipboard", $menu_auto, false, 0) if $autocopy = $ON then CheckMenuItem($menu_auto, $menu_autocopy, $MF_CHECKED) AddSysMenuItem("", -1, false, 0) global $menu_clear_clip = AddSysMenuItem("Clear the Clipboard", -1, false, 0) AddSysMenuItem("", -1, false, 0) global $menu_uppercase = AddSysMenuItem("&UPPERCASE Hashes Alt+U", -1, false, 0) ToggleUpper(true) ToggleUpper(true) AddSysMenuItem("", -1, false, 0) global $menu_algo = AddSysMenuItem("&Hashing Algorithm..", -1, true, 0) global $menu_algo_md5 = AddSysMenuItem("MD5 Alt+M", $menu_algo) global $menu_algo_sha1 = AddSysMenuItem("SHA1 Alt+S", $menu_algo) global $menu_algo_sha2 = AddSysMenuItem("SHA2 Alt+2", $menu_algo) switch $algorithm_id case 1 CheckMenuItem($menu_algo, $menu_algo_md5, $MF_CHECKED) case 2 CheckMenuItem($menu_algo, $menu_algo_sha1, $MF_CHECKED) case 3 CheckMenuItem($menu_algo, $menu_algo_sha2, $MF_CHECKED) endswitch AddSysMenuItem("", -1, false, 0) global $menu_edit_ini = AddSysMenuItem("Edit checksum.ini Ctrl+I", -1, false, 0) AddSysMenuItem("", -1, false, 0) global $menu_about = AddSysMenuItem("&About " & $app_name, -1, false, 0) AddSysMenuItem("", -1, false, 0) global $menu_help = AddSysMenuItem("&Help Ctrl+H", -1, false, 0) AddSysMenuItem("", -1, false, 0) global $menu_exit = AddSysMenuItem("Exit", -1, false, 0) ; Publish the primary window only after every control and menu exists. GUIRegisterMsg($msg_restore, "HandleMsgMultipleInstances") GUIRegisterMsg($WM_COPYDATA, "HandleMsgIncomingData") DllCall("user32.dll", "bool", "SetPropW", "hwnd", $GUI, "wstr", $app_id, "handle", $GUI) if $cmd_line[0] <> 0 then debugPrintArray($cmd_line, "$cmd_line", @ScriptLineNumber) ProcessCommandLine($cmd_line) endif ; Main loop.. while $running = true Sleep(50) if $opaque_on_mouseover = $ON then CheckHover() wend exit ; ; ProcessCommandLine() ; Main command processing function. Handles $CmdLine and $drop_files as well ; as $cmd_line data from any 2nd instance; all arrays share same format. ; func ProcessCommandLine(byref $cmd_array) debugPrintArray($cmd_array, "ProcessCommandLine() -->", @ScriptLineNumber, 8);debug if not IsArray($cmd_array) or $cmd_array[0] = 0 or $cmd_array[1] = "" then return ClearHashes() switch $cmd_array[0] ; Single file / string.. case 1 local $target_path = StringStripCR($cmd_array[1]) if not CheckClipboardHash($target_path) then $curr_input = $target_path GUICtrlSetData($input, $curr_input) if _LFN_FileExists($curr_input) then $current_title = " [" & $algorithm & "] " & BaseName($curr_input) SetTitleTemp() endif HashInput(true) endif ; Two files / folders.. case 2 $current_title = " [" & $algorithm & "] Comparing: " & BaseName($cmd_array[1]) & " with " & BaseName($cmd_array[2]) SetTitleTemp() CompareFiles($cmd_array[1], $cmd_array[2]) $current_title = " Use Alt+C to view hashes.. " SetTitleTemp() case else GUICtrlSetData($input, "You may pass a maximum of TWO files.") endswitch endfunc ; ; CheckClipboardHash() ; Check if the clipboard contains a valid hash. ; If so, immediately hash the new file and compare hashes. ; func CheckClipboardHash($target) local $clip = StringStripWS(ClipGet(), $STR_STRIP_ENDS) debug("CheckClipboardHash() =>" & $clip & "<=", @ScriptLineNumber, 2) local $len = StringLen($clip) if $len > 64 then return false local $got_hash = false local $prev_algo = $algorithm local $prev_algo_id = $algorithm_id if StringIsXDigit($clip) then switch $len case $MD5_HEX_LEN $got_hash = true SetAlgoMD5(false) CompareFiles($target, $clip, 1) case $SHA1_HEX_LEN $got_hash = true SetAlgoSHA1(false) CompareFiles($target, $clip, 2) case $SHA2_HEX_LEN $got_hash = true SetAlgoSHA2(false) CompareFiles($target, $clip, 3) endswitch endif if $got_hash then $algorithm = $prev_algo $algorithm_id = $prev_algo_id ResetTitle() return true endif return false endfunc ; ; HashInput() ; Hash whatever is currently in the input and post the result. ; func HashInput($force = false) local $copy, $save $curr_input = GUICtrlRead($input) GUICtrlSetState($hash_butt_context_save, $GUI_DISABLE) TrayItemSetState($tray_items[4], $TRAY_DISABLE) if $force then global $cached_hashes[4][3] = [[3]] if $curr_input <> "" and $cached_hashes[$algorithm_id][0] = $curr_input then GUICtrlSetData($input, $cached_hashes[$algorithm_id][1]) GUICtrlSetState($hash_butt_context_save, $GUI_ENABLE) TrayItemSetState($tray_items[4], $TRAY_ENABLE) else if _LFN_FileExists($curr_input) then if StringInStr(_LFN_FileGetAttrib($curr_input), "D") then GUICtrlSetData($input, "directories cannot be hashed (use checksum)") else $copy = true $save = true SetHashBusy() GUICtrlSetData($input, "hashing. please wait a moment..") local $res = HashFile($curr_input, $algorithm_id, $uppercase) GUICtrlSetData($input, $res) $cached_hashes[$algorithm_id][0] = $curr_input $cached_hashes[$algorithm_id][1] = $res GUICtrlSetState($hash_butt_context_save, $GUI_ENABLE) TrayItemSetState($tray_items[4], $TRAY_ENABLE) endif else GUICtrlSetData($input, HashString($curr_input, $algorithm_id, $uppercase)) $copy = true endif endif GUICtrlSetState($input, $GUI_FOCUS) SetHashReady() if $autocopy = $ON and $copy then ClipPut(GUICtrlRead($input)) if $autosave = $ON and $save then WriteHashFile(GetLongParentDir($curr_input) & "\" & BaseName($curr_input) & ".hash", $curr_input) endfunc func OnHashClick() HashInput(true) endfunc ; ; Open a file for hashing.. func OnOpenClick() WinActivate($GUI) OpenFileDialog() endfunc func OpenFileDialog() if WinActive($GUI) then local $file = FileOpenDialog("Open a file to hash..", "", "All (*.*)", 1, "", $GUI) if @error <> 1 then GUICtrlSetData($input, $file) HashInput(true) endif else HotKeySet("^o") Send("^o") HotKeySet("^o", "OpenFileDialog") endif endfunc ; ; Save-on-demand.. func OnSaveClick() WinActivate($GUI) SaveFileDialog() endfunc func SaveFileDialog() if WinActive($GUI) then if $curr_input = "" then MsgBox($MB_OK, "No can save!", "Please hash something first!", $GUI) return endif if not _LFN_FileExists($curr_input) then MsgBox($MB_OK, "No can save!", " simple checksum will only save hashes made from FILES, " & @LF & " you must hash a file before you save a hash. ", $GUI) return endif local $dir = GetLongParentDir($curr_input) local $def = RemoveExtension(BaseName($curr_input)) & ".hash" local $filter = "Hash Files (*.hash)" if ($cached_hashes[1][0] <> "" and $cached_hashes[2][0] <> "") or ($cached_hashes[1][0] <> "" and $cached_hashes[3][0] <> "") _ or ($cached_hashes[2][0] <> "" and $cached_hashes[3][0] <> "") then else if $cached_hashes[1][0] <> "" then $filter &= "|MD5 Files (*.md5)" if $cached_hashes[2][0] <> "" then $filter &= "|SHA1 Files (*.sha1)" if $cached_hashes[3][0] <> "" then $filter &= "|SHA2 Files (*.sha2)" endif local $save = FileSaveDialog("Save hash to a file..", $dir, $filter, 18, $def, $GUI) if @error <> 1 then if GetExtension($save) <> "hash" and GetExtension($save) <> "md5" and GetExtension($save) <> "sha1" and GetExtension($save) <> "sha2" then $save &= ".hash" endif WriteHashFile($save, $curr_input) endif else HotKeySet("^s") Send("^s") HotKeySet("^s", "SaveFileDialog") endif endfunc ; ; WriteHashFile() ; Write out a hash file with the computed hash ; Switch algorithms for an instant multi-hash file. ; func WriteHashFile($out, $target, $mode = 2) local $my_line_feed = @CRLF local $line_feed = IniRead($ini_path, "checksum", "line_feed", "CRLF") if $line_feed == "LF" or $line_feed == "lf" then $my_line_feed = @LF if $line_feed == "CR" or $line_feed == "cr" then $my_line_feed = @CR local $enc = 0 local $utf8_hashes = IniReadCheckBox($ini_path, "checksum", "utf8_hashes", 1) if $utf8_hashes = $ON then $enc = 128 if GetLongParentDir($out) = GetLongParentDir($target) then $target = BaseName($target) local $file = OpenFileHandle($out, $mode + $enc) local $arch = " (32-bit edition)" if @AUTOITX64 = 1 then $arch = " (64-bit edition)" if $file then _LFN_FileWriteLine($file, "# made with simple checksum.. drag-and-drop hashing for windows." & $arch & $my_line_feed) _LFN_FileWriteLine($file, "# from corz.org.. " & $app_url & $my_line_feed) _LFN_FileWriteLine($file, "#" & $my_line_feed) if $cached_hashes[1][0] <> "" then _LFN_FileWriteLine($file, $cached_hashes[1][1] & " *" & $target & $my_line_feed) if $cached_hashes[2][0] <> "" then _LFN_FileWriteLine($file, $cached_hashes[2][1] & " *" & $target & $my_line_feed) if $cached_hashes[3][0] <> "" then _LFN_FileWriteLine($file, $cached_hashes[3][1] & " *" & $target & $my_line_feed) _LFN_FileClose($file) endif endfunc func OnEnter() if WinActive($GUI) then HashInput(true) else HotKeySet("{Enter}") Send("{Enter}") HotKeySet("{Enter}", "OnEnter") endif endfunc func OnSelectAll() if WinActive($GUI) then GUICtrlSetState($input, $GUI_FOCUS) else HotKeySet("^a") Send("^a") HotKeySet("^a", "OnSelectAll") endif endfunc func OnOpenIni() if WinActive($GUI) then OpenIni() else HotKeySet("^i") Send("^i") HotKeySet("^i", "OnOpenIni") endif endfunc func OnToggleOnTop() if WinActive($GUI) then ToggleOnTop() else HotKeySet("^t") Send("^t") HotKeySet("^t", "OnToggleOnTop") endif endfunc func OnToggleSnap() if WinActive($GUI) then ToggleSnap() else HotKeySet("^z") Send("^z") HotKeySet("^z", "OnToggleSnap") endif endfunc func OnToggleUpper() if WinActive($GUI) then ToggleUpper() else HotKeySet("!u") Send("!u") HotKeySet("!u", "OnToggleUpper") endif endfunc func OnToggleCompare() if WinActive($GUI) then if GUICtrlRead($input) = $hash_1 then if not $hash_2 then return GUICtrlSetData($input, $hash_2) local $compare_item_title = "Clipboard Hash" if $drop_files[0] = 2 then $compare_item_title = $drop_files[2] $current_title = " [" & $algorithm & "] " & BaseName($compare_item_title) SetTitleTemp() else if not $hash_1 then return GUICtrlSetData($input, $hash_1) $current_title = " [" & $algorithm & "] " & BaseName($drop_files[1]) SetTitleTemp() endif else HotKeySet("!c") Send("!c") HotKeySet("!c", "OnToggleCompare") endif endfunc func SetTitleTemp() AdlibUnregister("ResetTitle") AdlibRegister("ResetTitle", 3000) WinSetTitle($GUI, "", $current_title) endfunc func ResetTitle() $current_title = $visible_title & " [" & $algorithm & "]" WinSetTitle($GUI, "", $current_title) AdlibUnregister("ResetTitle") endfunc ; ; Switch Algorithm.. func SelectMD5() SetAlgoMD5(true) endfunc func SelectSHA1() SetAlgoSHA1(true) endfunc func SelectSHA2() SetAlgoSHA2(true) endfunc func SetAlgoMD5($update = true) debug("SetAlgoMD5() =>", @ScriptLineNumber, 2) if not WinActive($GUI) and $update then HotKeySet("!m") Send("!m") HotKeySet("!m", "SelectMD5") return endif SetNewAlgorithm(1, $update) endfunc func SetAlgoSHA1($update = true) debug("SetAlgoSHA1() =>", @ScriptLineNumber, 2) if not WinActive($GUI) and $update then HotKeySet("!s") Send("!s") HotKeySet("!s", "SelectSHA1") return endif SetNewAlgorithm(2, $update) endfunc func SetAlgoSHA2($update = true) debug("SetAlgoSHA2() =>", @ScriptLineNumber, 2) if not WinActive($GUI) and $update then HotKeySet("!2") Send("!2") HotKeySet("!2", "SelectSHA2") return endif SetNewAlgorithm(3, $update) endfunc ; ; SetNewAlgorithm() ; Master algorithm switcher, either temporarily (when comparing against a ; clipboard hash) or "permanently", updating menu items and writing the new ; algorithm pref to checksum.ini ; func SetNewAlgorithm($my_algo_id, $update) debug("SetNewAlgorithm() --> $my_algo_id: =>" & $my_algo_id & "<= $update ==>" & $update , @ScriptLineNumber, 2);debug local $prev_algo_id = $algorithm_id $algorithm_id = $my_algo_id $algorithm = $hash_algorithms[$algorithm_id] if $prev_algo_id = $algorithm_id then return debug("SetNewAlgorithm() --> NEW algorithm: =>" & $algorithm & "<=" , @ScriptLineNumber, 2);debug if $update then CheckMenuItem($menu_algo, $menu_algo_md5, $MF_UNCHECKED) CheckMenuItem($menu_algo, $menu_algo_sha1, $MF_UNCHECKED) CheckMenuItem($menu_algo, $menu_algo_sha2, $MF_UNCHECKED) switch $algorithm_id case 1 CheckMenuItem($menu_algo, $menu_algo_md5, $MF_CHECKED) case 2 CheckMenuItem($menu_algo, $menu_algo_sha1, $MF_CHECKED) case 3 CheckMenuItem($menu_algo, $menu_algo_sha2, $MF_CHECKED) endswitch ClearHashes() SaveAlgoOpt() if $prev_algo_id <> $algorithm_id and GUICtrlRead($input) <> "" then ResetTitle() GUICtrlSetData($input, $curr_input) HashInput(false) endif if GUICtrlRead($input) = "" then ResetTitle() endif endfunc ; ; Some Toggles.. func ToggleGUI() local $state = WinGetState($GUI) if BitAND($state, 2) then GUISetState(@SW_HIDE, $GUI) else GUISetState(@SW_SHOW, $GUI) endif endfunc func ToggleUpper($skip = false) local $sys = GetSysMenu($GUI, 0) if $uppercase = $OFF then $uppercase = $ON CheckMenuItem($sys, $menu_uppercase, $MF_CHECKED) else $uppercase = $OFF CheckMenuItem($sys, $menu_uppercase, $MF_UNCHECKED) endif if not $skip then SaveUpperOpt() SwitchCase() OnSelectAll() endif endfunc func SwitchCase() local $text = GUICtrlRead($input) if $cached_hashes[$algorithm_id][1] <> "" then for $i = 1 to UBound($cached_hashes) - 1 if $cached_hashes[$i][0] <> "" then $cached_hashes[$i][1] = ($uppercase = $ON) ? StringUpper($cached_hashes[$i][1]) : StringLower($cached_hashes[$i][1]) endif next GUICtrlSetData($input, $cached_hashes[$algorithm_id][1]) elseif $text <> "" then GUICtrlSetData($input, ($uppercase = $ON) ? StringUpper($text) : StringLower($text)) endif endfunc func ToggleSnap($skip = false) local $sys = GetSysMenu($GUI, 0) if $edge_snap <> $ON then $edge_snap = $ON CheckMenuItem($sys, $menu_snap, $MF_CHECKED) SnapWin() else $edge_snap = $OFF CheckMenuItem($sys, $menu_snap, $MF_UNCHECKED) endif if not $skip then SaveSnapWin() endfunc func ToggleOnTop($skip = false) local $sys = GetSysMenu($GUI, 0) if $on_top <> $ON then WinSetOnTop($GUI, "", 1) $on_top = $ON CheckMenuItem($sys, $menu_on_top, $MF_CHECKED) else WinSetOnTop($GUI, "", 0) $on_top = $OFF CheckMenuItem($sys, $menu_on_top, $MF_UNCHECKED) endif if not $skip then SaveTopOpt() endfunc func ToggleCloseToTray($skip = false) local $sys = GetSysMenu($GUI, 0) if $close_to_tray = $OFF then $close_to_tray = $ON GUISetOnEvent($GUI_EVENT_CLOSE, "ToggleGUI") CheckMenuItem($sys, $menu_close_to_tray, $MF_CHECKED) else $close_to_tray = $OFF CheckMenuItem($sys, $menu_close_to_tray, $MF_UNCHECKED) GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") endif SetupTray($close_to_tray) if not $skip then SaveTrayOpt() endfunc func ToggleAutoCopy($skip = 0) local $sys = GetSysMenu($GUI, 0) if $autocopy <> $ON then $autocopy = $ON CheckMenuItem($sys, $menu_autocopy, $MF_CHECKED) else $autocopy = $OFF CheckMenuItem($sys, $menu_autocopy, $MF_UNCHECKED) endif if not $skip then SaveAutoCopyOpt() endfunc func ToggleAutoSave($skip = 0) local $res local $sys = GetSysMenu($GUI, 0) if $autosave <> $ON then if IniReadCheckBox($ini_path, "dialogs", "simple save notice", $OFF) = $OFF then $res = MsgBox($MB_YESNO + $MB_ICONWARNING + $MB_DEFBUTTON2 + $MB_TASKMODAL, _ " simple checksum will overwrite existing checksum files! ", "WARNING! " & @LF & @LF & _ "When using Auto Save, simple checksum will OVERWRITE existing checksum " & @LF & _ 'files in the format "file.ext.hash". If this is not what you want, click No. ' & @LF & @LF & _ "Do you wish to enable AutoSave to file? ") if $res = 6 then IniWriteCheckBox($ini_path, "dialogs", "simple save notice", $ON) else $res = 6 endif if $res <> 6 then return false $autosave = $ON CheckMenuItem($sys, $menu_autosave, $MF_CHECKED) else $autosave = $OFF CheckMenuItem($sys, $menu_autosave, $MF_UNCHECKED) endif if not $skip then SaveAutoSaveOpt() endfunc func SetTransparency($id_item) local $id_x for $id_x = 0 to 9 if $menu_trans_items[$id_x] = $id_item then exitloop next $transparency = 10 * $id_x $trans_alpha = 255 * (100 - $transparency) / 100 WinSetTrans($GUI, "", $trans_alpha) if $transparency_menu_id <> $id_item then CheckMenuItem($menu_transpacency, $transparency_menu_id, $MF_UNCHECKED) CheckMenuItem($menu_transpacency, $id_item, $MF_CHECKED) SaveTransparency() $transparency_menu_id = $id_item endfunc func ToggleOpaqueMouseOver() if $opaque_on_mouseover = $ON then $opaque_on_mouseover = $OFF CheckMenuItem($menu_transpacency, $menu_opaque, $MF_UNCHECKED) else $opaque_on_mouseover = $ON CheckMenuItem($menu_transpacency, $menu_opaque, $MF_CHECKED) endif SaveOpaqueOnMouseover() endfunc func ToggleHideTaskbar($skip = false) local $sys = GetSysMenu($GUI, 0) if $hide_taskbar_entry = $ON then $hide_taskbar_entry = $OFF CheckMenuItem($sys, $menu_hide_taskbar, $MF_UNCHECKED) else $hide_taskbar_entry = $ON CheckMenuItem($sys, $menu_hide_taskbar, $MF_CHECKED) endif if not $skip then SaveHideTaskbarButton() ReStart() endif endfunc ; If opaque_on_mouseover.. func CheckHover() local $info = GUIGetCursorInfo($GUI) if $info[0] >= -8 and $info[1] >= -32 and $info[0] <= $simple_width + 4 and $info[1] <= 36 then WinSetTrans($GUI, "", 255) else WinSetTrans($GUI, "", $trans_alpha) endif endfunc ; Snap GUI back on-screen, if required. func SnapWin() if $edge_snap = $OFF then return if WinExists($GUI) then local $my_win_pos = WinGetPos($GUI) if not IsArray($my_win_pos) then return 0 else return 0 endif local $x = $my_win_pos[0] local $y = $my_win_pos[1] if $x < $snap_distance then $x = 0 if $y < $snap_distance then $y = 0 if $x > @DesktopWidth - $my_win_pos[2] then $x = @DesktopWidth - $my_win_pos[2] if $y > @DesktopHeight - $my_win_pos[3] - $snap_distance then $y = @DesktopHeight - $my_win_pos[3] WinMove($GUI, "", $x, $y) SaveWin() endfunc ; Finished resizing/moving main GUI. Check for edge snap. func HandleMsgFinishedMoving($window_handle, $message, $w_param, $l_param) #forceref $message, $w_param, $l_param if $window_handle == $GUI then SnapWin() return $GUI_RUNDEFMSG endfunc ; User resized the main GUI.. func HandleMsgResizing($window_handle, $message, $w_param, $l_param) #forceref $message, $w_param if $window_handle == $GUI then local $struct = DllStructCreate("int Left; int Top; int Right; int Bottom", $l_param) local $current_top = DllStructGetData($struct, "Top") ; Lock the bottom boundary relative to the current top -> enforce fixed height. DllStructSetData($struct, "Bottom", $current_top + $win_pos[3]) SaveWin() endif return $GUI_RUNDEFMSG endfunc ; C:\Users\Dad\AppData\Roaming\corz\checksum\languages\en.ini C:\Users\Dad\AppData\Roaming\corz\checksum\languages\--en.ini ; ; Save prefs.. func SaveUpperOpt() IniWriteCheckBox($ini_path, $app_name, "uppercase", $uppercase) endfunc func SaveTrayOpt() IniWriteCheckBox($ini_path, $app_name, "close_to_tray", $close_to_tray) endfunc func SaveTopOpt() IniWriteCheckBox($ini_path, $app_name, "on_top", $on_top) endfunc func SaveSnapWin() IniWriteCheckBox($ini_path, $app_name, "edge_snap", $edge_snap) endfunc func SaveAutoCopyOpt() IniWriteCheckBox($ini_path, $app_name, "autocopy", $autocopy) endfunc func SaveAutoSaveOpt() IniWriteCheckBox($ini_path, $app_name, "autosave", $autosave) endfunc func SaveWin() SaveWinPos() SaveWinSize() endfunc func SaveWinPos() local $pos = WinGetPos($GUI) if IsArray($pos) then IniWrite($ini_path, $app_name, "simple_x", $pos[0]) IniWrite($ini_path, $app_name, "simple_y", $pos[1]) endif endfunc func SaveWinSize() $client_size = WinGetClientSize($GUI) $win_width = $client_size[0] if $win_width < 180 then $simple_width = 180 IniWrite($ini_path, $app_name, "simple_width", $win_width) endfunc func SaveAlgoOpt() IniWrite($ini_path, $app_name, "algorithm", $algorithm) endfunc func SaveTransparency() IniWrite($ini_path, $app_name, "transparency", $transparency) endfunc func SaveOpaqueOnMouseover() IniWriteCheckBox($ini_path, $app_name, "opaque_on_mouseover", $opaque_on_mouseover) endfunc func SaveHideTaskbarButton() IniWriteCheckBox($ini_path, $app_name, "hide_taskbar_entry", $hide_taskbar_entry) endfunc ; ; System menu functions.. func GetSysMenu($hwnd, $revert) local $res = DllCall("user32.dll", "hwnd", "GetSystemMenu", "hwnd", $hwnd, "int", $revert) return $res[0] endfunc func InsertMenuItem($menu, $pos, $flags, $id_item, $text) local $res = DllCall("user32.dll", "int", "InsertMenu", "hwnd", $menu, "int", $pos, "int", $flags, "int", $id_item, "str", $text) return $res[0] endfunc func CreatePopupMenu() local $res = DllCall("user32.dll", "hwnd", "CreatePopupMenu") return $res[0] endfunc func CheckMenuItem($menu, $id_item, $check) DllCall("user32.dll", "int", "CheckMenuItem", "hwnd", $menu, "int", $id_item, "int", $check) endfunc func AddSysMenuItem($text, $menu = -1, $popup = false, $pos = -1) if $menu = -1 then $menu = GetSysMenu($GUI, 0) local $id_item = GUICtrlCreateDummy() local $flags = 0 if $text = "" then $flags = $MF_SEPARATOR elseif $popup then $id_item = CreatePopupMenu() $flags = $MF_POPUP endif $flags = BitOR($MF_STRING, $flags) InsertMenuItem($menu, $pos, $flags, $id_item, $text) return $id_item endfunc func HandleSysCommandMsg($hwnd, $msg, $wparam, $lparam) #forceref $hwnd, $msg, $lparam local $id_item = BitAND($wparam, 65535) switch $id_item case $menu_trans_items[0] to $menu_trans_items[9] SetTransparency($id_item) case $menu_opaque ToggleOpaqueMouseOver() case $menu_hide_taskbar ToggleHideTaskbar() case $menu_edit_ini OpenIni() case $menu_clear_clip ClearClipboard() case $menu_help ShowHelp() case $menu_about DoAboutBox() case $menu_exit OnExit() case $menu_autocopy ToggleAutoCopy() case $menu_autosave ToggleAutoSave() case $menu_on_top ToggleOnTop() case $menu_snap ToggleSnap() case $menu_close_to_tray ToggleCloseToTray() case $menu_uppercase ToggleUpper() case $menu_algo_md5 SelectMD5() case $menu_algo_sha1 SelectSHA1() case $menu_algo_sha2 SelectSHA2() endswitch endfunc ; ; System Tray menu.. func SetupTray($exit = 1) for $id_x = 1 to UBound($tray_items) - 1 TrayItemDelete($tray_items[$id_x]) next $tray_items[1] = TrayCreateItem("About " & $app_name) TrayItemSetOnEvent(-1, "DoAboutBox") $tray_items[2] = TrayCreateItem("") $tray_items[3] = TrayCreateItem("Open file to hash.. Ctrl+O") TrayItemSetOnEvent(-1, "OnOpenClick") $tray_items[4] = TrayCreateItem("Save hash to file.. Ctrl+S") TrayItemSetOnEvent(-1, "OnSaveClick") TrayItemSetState(-1, $TRAY_DISABLE) $tray_items[5] = TrayCreateItem("") $tray_items[6] = TrayCreateItem("Edit checksum.ini.. Ctrl+I") $tray_items[7] = TrayCreateItem("") if $exit = 1 then $tray_items[8] = TrayCreateItem("Exit") else $tray_items[8] = TrayCreateItem("Exit (Alt+F4 / Esc)") endif TrayItemSetOnEvent(-1, "OnExit") TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "ToggleGUI") TraySetClick(8) TraySetState() TraySetToolTip(" left-click to toggle the main window " & @LF & " right-click to bring up the tray menu ") endfunc func OpenIni() local $editor = IniRead($ini_path, "checksum", "editor", "notepad.exe") if not Run($editor & " " & $ini_path) then MsgBox($MB_ICONWARNING, "ERROR!", "I couldn't run:" & @LF & @LF & '"' & $editor & '"' & @LF & @LF & "Ironically, you need to check your ini settings! ", 30) endif endfunc func SetHashBusy() GUICtrlSetState($butt_hash_it, $GUI_DISABLE + $GUI_HIDE) endfunc func SetHashReady() GUICtrlSetState($butt_hash_it, $GUI_ENABLE + $GUI_SHOW) endfunc func ClearClipboard() ClipPut("") endfunc func ClearHashes() $hash_1 = "" $hash_2 = "" endfunc ; Hash a file with bcrypt.dll.. func HashFile($file, $algorithmID = 3, $upper = 0) local $target = PrependLongPathPrefix($file) debug("HashFile() file =>" & $file & "<= Algo ID:" & $algorithmID & " target =>" & $target & "<=", @ScriptLineNumber, 2) local $timer = TimerInit() local $hash_digest = bcryptHashFile($target, $algorithm_strings[$algorithmID], $upper) if not @error then local $execute_time = TimerDiff($timer) / 1000 $current_title = $current_title & " [completed in " & Round($execute_time, 2) & "s]" SetTitleTemp() return SetError(-1, 0, $hash_digest) else local $err = @error local $ext = @extended local $error_msg = "" switch $err case 1 $error_msg = "*** FAILED TO LOAD BCRYPT.DLL ***" case 2, 3, 4, 8, 9 $error_msg = StringFormat("*** CRYPTO API ERROR (0x%08X) ***", $ext) case 5 switch $ext case 2, 3 $error_msg = "*** FILE NOT FOUND ***" case 5, 32 $error_msg = "*** READ PERMISSION DENIED ***" case else $error_msg = StringFormat("*** FILE ACCESS ERROR (%d) ***", $ext) endswitch case 6 $error_msg = "*** OPERATION ABORTED ***" case 7 $error_msg = StringFormat("*** FILE READ ERROR (%d) ***", $ext) case else $error_msg = "*** UNKNOWN ERROR ***" endswitch return SetError($err, $ext, $error_msg) endif endfunc ; For Singleton. ; Bring the old instance to the front. func HandleMsgMultipleInstances($hwnd, $msg, $wparam, $lparam) #forceref $hwnd, $msg, $wparam, $lparam RestoreAndActivateGui() return $GUI_RUNDEFMSG endfunc ; Pass the command-line parameters from the new instance to the old instance. func HandleMsgIncomingData($hwnd, $msg, $wparam, $lparam) #forceref $hwnd, $msg, $wparam local $copy_data_struct = DllStructCreate("uint_ptr dwData;dword cbData;ptr lpData", $lparam) local $data_size = DllStructGetData($copy_data_struct, "cbData") local $data_pointer = DllStructGetData($copy_data_struct, "lpData") local $string_struct = DllStructCreate("wchar[" & ($data_size / 2) & "]", $data_pointer) $incoming_cmd_line = DllStructGetData($string_struct, 1) if StringRight($incoming_cmd_line, 1) = Chr(1) then $incoming_cmd_line = StringTrimRight($incoming_cmd_line, 1) $incoming_cmd_line = StringSplit($incoming_cmd_line, Chr(1)) debugPrintArray($incoming_cmd_line, "HandleMsgIncomingData() =>$incoming_cmd_line", @ScriptLineNumber, 8) ClearHashes() RestoreAndActivateGui() ProcessCommandLine($incoming_cmd_line) return $GUI_RUNDEFMSG endfunc func RestoreAndActivateGui() GUISetState(@SW_SHOW, $GUI) ; Force immediate repaint.. DllCall("user32.dll", "bool", "UpdateWindow", "hwnd", $GUI) WinActivate($GUI) endfunc ; Build $drop_files array from the dropped files, process dropped file(s).. func HandleMsgDroppedFiles($hwnd, $msg, $wparam, $lparam) #forceref $hwnd, $msg, $lparam debug("HandleMsgDroppedFiles() =>", @ScriptLineNumber, 2) local $len, $t_buf local $count = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wparam, "int", -1, "ptr", 0, "int", 255) $drop_files[0] = $count[0] local $id_x for $id_x = 0 to $drop_files[0] - 1 $len = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wparam, "int", $id_x, "ptr", 0, "int", 0) $len = $len[0] + 1 $t_buf = DllStructCreate("wchar[" & $len & "]") DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wparam, "int", $id_x, "ptr", DllStructGetPtr($t_buf), "int", $len) redim $drop_files[$id_x + 2] $drop_files[$id_x + 1] = DllStructGetData($t_buf, 1) $t_buf = 0 if $id_x = 1 then exitloop next ClearHashes() ProcessCommandLine($drop_files) ; Use 0 to prevent message falling through and filling input. return 0 endfunc func CompareFiles($file_1, $file_2, $algorithm = 3) debug("CompareFiles() file_1 =>" & $file_1 & " file_2 =>" & $file_2 & " algorithm =>" & $algorithm , @ScriptLineNumber, 2) if IsDir($file_1) and IsDir($file_2) then CompareDirs($file_1, $file_2) return endif local $clip = false GUICtrlSetData($input, "Hashing: " & BaseName($file_1)) SetHashBusy() $hash_1 = HashFile($file_1, $algorithm) debug("COMPARE:: hash_1 =>" & $hash_1 & "<=", @ScriptLineNumber, 2) if _LFN_FileExists($file_2) then GUICtrlSetData($input, "Hashing: " & BaseName($file_2)) $hash_2 = HashFile($file_2, $algorithm) debug("COMPARE:: hash_2 =>" & $hash_2 & "<=", @ScriptLineNumber, 2) else GUICtrlSetData($input, "Clipboard: " & $file_2) $hash_2 = $file_2 $clip = true endif local $msg if $hash_1 = $hash_2 then if $clip then $msg = "File MATCHES clipboard ( " & $hash_algorithms[$algorithm_id] & " ) hash " else $msg = "Files MATCH" endif GUICtrlSetData($input, $msg) else if $clip then $msg = "File does NOT match clipboard ( " & $hash_algorithms[$algorithm_id] & " ) hash" else $msg = "Files DO NOT MATCH" endif GUICtrlSetData($input, $msg) endif SetHashReady() if not $clip and $autocopy = $ON then ClipPut($msg & ": " & @LF & $hash_1 & " <-- " & $file_1 & @LF & $hash_2 & " <-- " & $file_2 & @LF) endfunc func CompareDirs($dir_one, $dir_two) debug("CompareDirs() dir_one =>" & $dir_one & " dir_two =>" & $dir_two, @ScriptLineNumber, 2) SetHashBusy() local $uni = IniReadCheckBox($ini_path, "checksum", "unified_extension", $ON) local $ext = ".sha2" if $uni = $ON then $ext = ".hash" _LFN_DirCreate(@TempDir & "\simple-checksum-compare") DeleteFilesRecursive(@TempDir & "\simple-checksum-compare\source-hashes" & $ext) DeleteFilesRecursive(@TempDir & "\simple-checksum-compare\target-hashes" & $ext) GUICtrlSetData($input, "hashing source folder - please wait..") SetError(0) local $code = RunWait("checksum.exe cqr2-b-5-s1j(source-hashes)d(" & @TempDir & "\simple-checksum-compare) " & '"' & $dir_one & '"') if @error <> 0 then GUICtrlSetData($input, "Problem running checksum. Is it located next to me?") SetHashReady() return false endif if $code <> 0 then GUICtrlSetData($input, "Problem hashing source folder (code:" & $code & ") COMPARE ABORTED!") SetHashReady() return false endif GUICtrlSetData($input, "hashing target folder - please wait..") SetError(0) $code = RunWait("checksum.exe cqr2-b-5-s1j(target-hashes)d(" & @TempDir & "\simple-checksum-compare) " & '"' & $dir_two & '"') if @error <> 0 then GUICtrlSetData($input, "Problem running checksum. Is it located next to me?") SetHashReady() return false endif if $code <> 0 then GUICtrlSetData($input, "Problem hashing target folder (code:" & $code & ") COMPARE ABORTED!") SetHashReady() return false endif local $src = HashFile(@TempDir & "\simple-checksum-compare\" & "source-hashes" & $ext, 3, 0) if not StringLen($src) = $SHA2_HEX_LEN or not StringIsXDigit($src) then GUICtrlSetData($input, "Problem with source hash file (" & $src & ") COMPARE ABORTED!") SetHashReady() return false endif local $tgt = HashFile(@TempDir & "\simple-checksum-compare\" & "target-hashes" & $ext, 3, 0) if not StringLen($tgt) = $SHA2_HEX_LEN or not StringIsXDigit($tgt) then GUICtrlSetData($input, "Problem with target hash file (" & $tgt & ") COMPARE ABORTED") SetHashReady() return false endif if $src = $tgt then GUICtrlSetData($input, "Folders MATCH!") else GUICtrlSetData($input, "Folders DO NOT MATCH!") endif _LFN_DirRemove(@TempDir & "\simple-checksum-compare", 1) SetHashReady() endfunc func ShowHelp() if WinActive($GUI) then MsgBox($MB_OK + $MB_ICONINFORMATION + $MB_TASKMODAL, "simple checksum help", _ "To use: Type a string and click 'hash it', or drag and drop a file onto the input. " & @LF & @LF & _ "To configure: Click the Title Bar icon (in the top corner) or right-click the title bar for a handy application menu. " & @LF & @LF & _ "simple checksum has a system tray menu - hover your mouse over it for more details. " & @LF & @LF & _ "You can also right-click the 'hash it' button for a regular file open/save menu. " & @LF & @LF & _ "Most everything has a HotKey. See the menus for more details. ", 0, $GUI) else HotKeySet("^h") Send("^h") HotKeySet("^h", "ShowHelp") endif endfunc ; ; DoAboutBox() ; The About Box. ; Contains the same system info / env readout easter egg functions as checksum. ; func DoAboutBox() local $opt_event = AutoItSetOption("GUIOnEventMode", 0) local $opt_coord = AutoItSetOption("GUICoordMode", 1) local $GUI_About = GUICreate(" About " & $app_name & "..", 265, 105, -1, -1, Default, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor($COLOR_WHITE) local $label_title = GUICtrlCreateLabel($app_name & " v" & $version & @LF & "from corz.org", 80, 8) FileInstall("Resources\simple_checksum_64.gif", @TempDir & "\") local $icon if _LFN_FileExists(@TempDir & "\simple_checksum_64.gif") then $icon = GUICtrlCreatePic(@TempDir & "\simple_checksum_64.gif", 6, 9, 64, 64) else $icon = GUICtrlCreateIcon($exe_path, 0, 6, 9, 64, 64) endif local $label_visit = GUICtrlCreateLabel("Do you want to visit the simple" & @LF & "checksum web page?", 80, 40) local $butt_no = GUICtrlCreateButton("No, not right now", 10, 80, 95, 22) GUICtrlSetTip(-1, " The other button is the one you want to click! ") local $butt_yes = GUICtrlCreateButton("Yes, let's do it!", 161, 80, 95, 22) GUICtrlSetTip(-1, " The link will open in your system default browser ") local $arch = "x86" if @AUTOITX64 = 1 then $arch = "x64" local $label_arch = GUICtrlCreateLabel($arch, 246, 1, 18, 12) GUICtrlSetFont(-1, 8, 200, 0, "Lucida Console") GUISetState() local $action, $gui_msg local $loop_counter = 1 while 1 $loop_counter += 1 if Mod($loop_counter, 25) = 0 then GUICtrlSetColor($label_arch, 4473924) endif if Mod($loop_counter, 50) = 0 then GUICtrlSetColor($label_arch, 0) endif Sleep(10) $gui_msg = GUIGetMsg() switch $gui_msg case $GUI_EVENT_CLOSE, $butt_no, $icon, $label_title, $label_visit exitloop case $butt_yes $action = "url" exitloop case $label_arch $action = "info" exitloop endswitch wend GUIDelete($GUI_About) AutoItSetOption("GUICoordMode", $opt_coord) AutoItSetOption("GUIOnEventMode", $opt_event) switch $action case "url" VisitUrl($app_url) case "info" SysInfoBox("simple checksum") endswitch endfunc ; Initial Debug Output.. func InitDebug() if $debug_level < 2 then return debug("", @ScriptLineNumber, 2) debug("", @ScriptLineNumber, 2) debug("Begin Simple Checksum debug output ===>" & @ComputerName & "<=", @ScriptLineNumber, 2) debug("Computer Name =>" & @ComputerName & "<=", @ScriptLineNumber, 2) debug("Free Memory =>" & GetFreeMem() & "<=", @ScriptLineNumber, 2) local $arch = "x86" if @AUTOITX64 = 1 then $arch = "x64" local $os = StringReplace(@OSVersion, "_", " ") & " (" & $arch & ") " & @OSServicePack & " [" & @OSTYPE & "][cpu:" & StringLower(@CPUARCH) & "]" debug("Operating System =>" & $os & "<=", @ScriptLineNumber, 2) debug("SYSTEM PATH=>" & EnvGet("PATH") & "<=", @ScriptLineNumber, 2) debug("Working DIR=>" & @WorkingDir & "<=", @ScriptLineNumber, 2) debug("Startup Directory:" & @StartupDir & "<=", @ScriptLineNumber, 2) debug("Windows Directory:" & @WindowsDir & "<=", @ScriptLineNumber, 2) debug("System Folder:" & @SystemDir & "<=", @ScriptLineNumber, 2) debug("Desktop Directory:" & @DesktopDir & "<=", @ScriptLineNumber, 2) debug("'My Documents' Directory:" & @MyDocumentsDir & "<=", @ScriptLineNumber, 2) debug("Program Files Directory:" & @ProgramFilesDir & "<=", @ScriptLineNumber, 2) debug("Start Menu Directory:" & @StartMenuDir & "<=", @ScriptLineNumber, 2) debug("Temporary File Directory:" & @TempDir & "<=", @ScriptLineNumber, 2) debug("Desktop:" & @DesktopWidth & "x" & @DesktopHeight & "<=", @ScriptLineNumber, 2) debug("Date [Y-M-D]:" & @YEAR & "-" & @MON & "-" & @MDAY & "<=", @ScriptLineNumber, 2) debug("Time [H:M:S]:" & @HOUR & ":" & @MIN & ":" & @SEC & "<=", @ScriptLineNumber, 2) debug("", @ScriptLineNumber, 2) endfunc func OutputPrefs() if $debug_level < 2 then return debug("Simple Checksum Prefs ===>", @ScriptLineNumber, 2) debug("transparency =>" & $transparency & "<=", @ScriptLineNumber, 2) debug("algorithm =>" & $algorithm & "<=", @ScriptLineNumber, 2) debug("uppercase =>" & Human($uppercase) & "<=", @ScriptLineNumber, 2) debug("simple_width =>" & $simple_width & "<=", @ScriptLineNumber, 2) debug("simple_x =>" & $simple_x & "<=", @ScriptLineNumber, 2) debug("simple_y =>" & $simple_y & "<=", @ScriptLineNumber, 2) debug("on_top =>" & Human($on_top) & "<=", @ScriptLineNumber, 2) debug("edge_snap =>" & Human($edge_snap) & "<=", @ScriptLineNumber, 2) debug("snap_distance =>" & $snap_distance & "<=", @ScriptLineNumber, 2) debug("autosave =>" & Human($autosave) & "<=", @ScriptLineNumber, 2) debug("opaque_on_mouseover =>" & Human($opaque_on_mouseover) & "<=", @ScriptLineNumber, 2) debug("", @ScriptLineNumber, 2) endfunc func ReStart() if IniReadCheckBox($ini_path, "dialogs", "restart_taskbar_change_notice", $OFF) = $OFF then MsgBox($MB_TOPMOST, " RESTART REQUIRED", "In order to change the Taskbar settings, " & _ "simple checksum must now restart. There will be a one second delay. " & @LF & @LF & "This is a one-time notice.", 0, $GUI) IniWriteCheckBox($ini_path, "dialogs", "restart_taskbar_change_notice", $ON) endif ; Restart after 1 second to avoid Singleton collision. ; I haven't bothered adding the .au3 version, only for @Compiled versions.. local $command = StringFormat('cmd.exe /c timeout /t 1 /nobreak >nul & start "" "%s"', @AutoItExe, $CmdLineRaw) Run($command, "", @SW_HIDE) exit endfunc func OnExit() SaveWin() DeleteFilesRecursive(@TempDir & "\simple_checksum_64.gif") $running = false endfunc ; AutoIt Wrapper / Compiler directives.. ; #Region ----- START ---------------- COMPILE / WRAPPER DIRECTIVES -------------- ; for resources included with File__Install() #pragma compile(Compression, 9) ;::dev::.. ; if you want your binary NOW, set this to N #AutoIt3Wrapper_Run_Au3Stripper=Y ; See the notes above debug() (in corzSahred.au3, 2) for what /rsln does. #Au3Stripper_Parameters=/StripOnly /rsln ; Like calling the wrapper with /debug, which we do anyway. This is handy, though .. #AutoIt3Wrapper_Run_Debug_Mode=Y #AutoIt3Wrapper_LogFile=%scriptdir%\wrapper.log #AutoIt3Wrapper_UseX64=Y #AutoIt3Wrapper_UseUpx=N #AutoIt3Wrapper_Run_AU3Check=Y ; -w 1: Variable already declared. ; -w 2: Variable declared/assigned but unused. ; -w 3: Function declared but never called. ; -w 4: Global variable declared inside a function (Prefer top of file). ; -w 5: Local variable used before declaration. ; -w 6: Warn when actual parameters match optional default parameters. ; -w 7: Warn when pass-by-ref parameters (ByRef) don't match the calling signature. #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 5 -w 6 -w 7 -v 1 #AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y #AutoIt3Wrapper_Run_Stop_OnError=Y ; Main program icon.. ; Note: *** MAY NEED FORWARD SLASHES IN RELATIVE PATHS - YMMV!!! *** #AutoIt3Wrapper_Icon=Resources\simple checksum.ico ; Free-form Res Fields.. #AutoIt3Wrapper_Res_Field=Author|corz.org #AutoIt3Wrapper_Res_Field=Contact|checksum@corz.org #AutoIt3Wrapper_Res_Field=Long Description|Simple Checksum #AutoIt3Wrapper_Res_Field=Publisher|corz.org #AutoIt3Wrapper_Res_Field=Web Page|https://corz.org/windows/software/checksum/simple-checksum.php #AutoIt3Wrapper_Res_Field=Compiled|%date% %time% ; These now have their own fields.. #AutoIt3Wrapper_Res_ProductName=simple checksum #AutoIt3Wrapper_Res_CompanyName=corz.org #AutoIt3Wrapper_Res_LegalCopyright=corz.org ; Application's resource info.. #AutoIt3Wrapper_Res_Comment=simple checksum ; This is the one that shows up in Process Explorer.. #AutoIt3Wrapper_Res_Description=simple file hashing for Windows #AutoIt3Wrapper_Res_LegalCopyright=corz.org #AutoIt3Wrapper_Res_ProductVersion=2 ;#AutoIt3Wrapper_Res_Field=Build|DEBUG ;#AutoIt3Wrapper_Res_Field=Build|Beta Release #AutoIt3Wrapper_Res_Field=Build|Resurrection ; I must get a shot of my son's Surface and see if this does anything! #AutoIt3Wrapper_Res_HiDpi=Y ; Run pre- & post-compile tasks elevated (as admin).. ; #AutoIt3Wrapper_Run_Before_Admin=Y #AutoIt3Wrapper_Run_After_Admin=Y ; Tasks to perform BEforE compilation.. ; ; You might want to comment this out (kills any running instance of checksum).. #AutoIt3Wrapper_Run_Before=taskkill /F /T /IM "simple checksum.exe" ; But if you do, copying your new binary over (below) probably won't work. #AutoIt3Wrapper_Run_Before=del /f /q ".\%scriptfile% - %fileversion%_stripped.au3" ; Tasks to perform AFTER compilation.. ; ; Backup this version of the script. #AutoIt3Wrapper_Run_After=copy "%in%" ".\%scriptfile% - %fileversion%.au3" ; Handy to keep a backup of the stripped version, too.. #AutoIt3Wrapper_Run_After=move /Y .\%scriptfile%_stripped.au3 ".\%scriptfile% - %fileversion%_stripped.au3" ; Copy latest binaries to app folders (overwrites existing binary).. ; Your copy of simple checksum may be somewhere else.. #AutoIt3Wrapper_Run_After=copy "%outx64%" "C:\Program Files\corz\checksum\simple checksum.exe" ; Backup this version of the source files to BackUp.zip.. #AutoIt3Wrapper_Run_After=7z.exe a -mx7 -tzip ".\BackUp.zip" ".\%scriptfile% - %fileversion%.au3" #AutoIt3Wrapper_Run_After=7z.exe a -mx7 -tzip ".\BackUp.zip" ".\%scriptfile% - %fileversion%_stripped.au3" ; Note: The 7z and checksum program directories are in my %PATH% (System Properties >> Advanced >> Environment Variables). ; Which is why I don't need to supply the full paths in these commands. ; Finally, remove the (now-zipped) source files.. #AutoIt3Wrapper_Run_After=del /f /q ".\%scriptfile% - %fileversion%.au3" #AutoIt3Wrapper_Run_After=del /f /q ".\%scriptfile% - %fileversion%_stripped.au3" ; When you run AutoIt wrapper, compile the script; the version number is automatically increased. ; It actually edits this file. So no editing during compiling! And you lose your undos! Nah. ; #AutoIt3Wrapper_Res_FileVersion_AutoIncrement=Y ; Version (keep this!).. ; This is visible all over the place (explorer properties, on mouse hover, etc.) ; and also used internally for version checking and the about box.. ; see top ; find nasty end-of-line comments: (\w+)(\h+);.*$ ; *** Before compiling:: ; To delete debug lines, do a regex search for: debug\([^)]*\)\n #endRegion ----- END --------------- COMPILE / WRAPPER DIRECTIVES ------------ #cs TODO: #ce #cs "B:\Test\ScooterRace [2021-03-22].mp4" "B:\Test\PS3 Baby_360p [2021-03-31].mkv" 1e82dbbefd5c140db0a1e066d6debf6190248e83a3e10754bab72db9db5166bf 891af6edb449955f4bbfb47201ac87a4f9e7fee71c7d7d9cc1b7b23ea39bd937 891af6edb449955f4bbfb47201ac87a4f9e7fee7 891af6edb449955f4bbfb47201ac87a4 B:\Test\1.GB #ce