global $my_version = "0.3.8" #AutoIt3Wrapper_Res_Fileversion=0.3.8 #include #include #include #include #include #include global $my_name = "SimpleTimer" global $ini_section = "SimpleTimer" global $my_url = "https://corz.org/windows/software/accessories/SimpleTimer.php" ; A few shared functins slammed in here for convenience.. func IniReadCheckBoxValue($ini_path, $section, $key, $default_value) local $stored_value = IniRead($ini_path, $section, $key, $default_value) switch $stored_value case $GUI_UNCHECKED, "false", "off", "n", "no", "not", "nope", "nay", "nay!", "nah", "nah!", "no way!", "no sir!", "negative", "neg", "no!", "0" return $GUI_UNCHECKED case $GUI_CHECKED, "true", "on", "y", "yes", "yes!", "yay", "yay!", "yup", "hell yes!", "indeed", "yes sir!", "yessir!", "affirmative", "cool" return $GUI_CHECKED case else return $stored_value endswitch endfunc func IniWriteCheckBoxValue($ini_path, $section, $key, $value, $true_value = "true", $false_value = "false") if $value = $GUI_CHECKED or $value == true then $value = $true_value if $value = $GUI_UNCHECKED or $value == false then $value = $false_value IniWrite($ini_path, $section, $key, $value) endfunc func VisitURL($url = "https://corz.org/") ShellExecute($url) endfunc AutoItSetOption("GUIOnEventMode", 1) AutoItSetOption("TrayMenuMode", 11) AutoItSetOption("TrayOnEventMode", 1) global $app_path if @Compiled then $app_path = @ScriptFullPath else $app_path = ".\" & $my_name & ".exe" endif global $data_dir = @AppDataDir & "\corz\" & $ini_section if not FileExists($data_dir) then DirCreate($data_dir) global $ini_path, $ini_name = $ini_section & ".ini" if FileExists(@ScriptDir & "\" & $ini_name) then $data_dir = @ScriptDir $ini_path = $data_dir & "\" & $ini_name else $data_dir = @AppDataDir & "\corz\" & $my_name if not FileExists($data_dir) then DirCreate($data_dir) $ini_path = $data_dir & "\" & $ini_name if not FileExists($ini_path) then FileInstall("Resources\SimpleTimer.ini", $ini_path) endif global $ce_debug = IniReadCheckBoxValue($ini_path, $ini_section, "do_debug", $gui_unchecked) global $window_x = IniRead($ini_path, $ini_section, "x", -1) global $window_y = IniRead($ini_path, $ini_section, "y", -1) global $always_on_top = IniReadCheckBoxValue($ini_path, $ini_section, "always_on_top", $gui_unchecked) global $audio_enabled = IniReadCheckBoxValue($ini_path, $ini_section, "audio_enabled", $gui_checked) global $start_sound = IniReadCheckBoxValue($ini_path, $ini_section, "start_beep", "SimpleTimerStart.wav") global $stop_sound = IniReadCheckBoxValue($ini_path, $ini_section, "stop_beep", "SimpleTimerStop.wav") if $start_sound = "SimpleTimerStart.wav" then FileInstall("Resources\SimpleTimerStart.wav", $data_dir & "\" & "SimpleTimerStart.wav") endif if not StringInStr($start_sound, "\") then $start_sound = $data_dir & "\" & $start_sound if $stop_sound = "SimpleTimerStop.wav" then FileInstall("Resources\SimpleTimerStop.wav", $data_dir & "\" & "SimpleTimerStop.wav") endif if not StringInStr($stop_sound, "\") then $stop_sound = $data_dir & "\" & $stop_sound global $timer_color, $custom_colors ReadColors() global $main_gui = GUICreate(" " & $ini_section & "..", 200, 38, $window_x, $window_y, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_TOOLWINDOW) global $timer_label = GUICtrlCreateLabel("00:00.00", 65, 5, 150, 30) GUICtrlSetFont(-1, 20, 400, 0, "Courier New Bold") GUICtrlSetColor(-1, $timer_color) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") global $start_button = GUICtrlCreateButton("Start", 5, 8, 50, 24, $BS_DEFPUSHBUTTON, BitOR($WS_TABSTOP, $BS_NOTIFY)) GUICtrlSetFont(-1, 9, 400, 0, "Lucida Console") GUICtrlSetOnEvent(-1, "ToggleTimer") global $context_menu = GUICtrlCreateContextMenu($timer_label) GUICtrlCreateMenuItem("Change Timer Color", $context_menu) GUICtrlSetOnEvent(-1, "ChangeTimerColor") GUICtrlCreateMenuItem("", $context_menu) global $topmost_menu_item = GUICtrlCreateMenuItem("Always On Top", $context_menu) GUICtrlSetOnEvent($topmost_menu_item, "ToggleAlwaysOnTop") GUICtrlSetState(-1, $always_on_top) global $audio_menu_item = GUICtrlCreateMenuItem("Audio", $context_menu) GUICtrlSetOnEvent($audio_menu_item, "ToggleAudio") GUICtrlSetState(-1, $audio_enabled) GUICtrlCreateMenuItem("", $context_menu) GUICtrlCreateMenuItem("Edit Prefs (ini) File", $context_menu) GUICtrlSetOnEvent(-1, "EditPrefs") GUICtrlCreateMenuItem("", $context_menu) GUICtrlCreateMenuItem("About..", $context_menu) GUICtrlSetOnEvent(-1, "ShowAbout") GUICtrlCreateMenuItem("", $context_menu) global $exit_menu_item = GUICtrlCreateMenuItem("Exit", $context_menu) GUICtrlSetOnEvent($exit_menu_item, "Quit") global $tray_color_item = TrayCreateItem("Change Timer Color") TrayItemSetOnEvent($tray_color_item, "ChangeTimerColor") TrayCreateItem("") global $tray_topmost_item = TrayCreateItem("Always On Top") TrayItemSetOnEvent($tray_topmost_item, "ToggleAlwaysOnTop") global $tray_audio_item = TrayCreateItem("Audio") TrayItemSetOnEvent($tray_audio_item, "ToggleAudio") TrayCreateItem("") global $tray_prefs_item = TrayCreateItem("Edit Prefs (ini) File..") TrayItemSetOnEvent(-1, "EditPrefs") TrayCreateItem("") TrayCreateItem("About..") TrayItemSetOnEvent(-1, "ShowAbout") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "Quit") TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "ToggleWindow") TraySetClick(8) TraySetState() TraySetToolTip("left-click to toggle the main window" & @LF & "right-click to bring up the tray menu") ControlFocus($main_gui, "Start", $start_button) GUISetState() global $timer_started global $timer_running = 0 global $elapsed_minutes = 0 ToggleAlwaysOnTop() ToggleAlwaysOnTop() ToggleAudio() ToggleAudio() while 1 Sleep(333) wend func UpdateTimer() local $elapsed_seconds = StringFormat("%.2f", Round(TimerDiff($timer_started) / 1000, 2)) if $elapsed_minutes = 0 then if $elapsed_seconds < 10 then GUICtrlSetData($timer_label, "00:0" & $elapsed_seconds) else GUICtrlSetData($timer_label, "00:" & $elapsed_seconds) endif else if $elapsed_minutes < 10 then if $elapsed_seconds < 10 then GUICtrlSetData($timer_label, "0" & $elapsed_minutes & ":0" & $elapsed_seconds) else GUICtrlSetData($timer_label, "0" & $elapsed_minutes & ":" & $elapsed_seconds) endif else if $elapsed_seconds < 10 then GUICtrlSetData($timer_label, $elapsed_minutes & ":0" & $elapsed_seconds) else GUICtrlSetData($timer_label, $elapsed_minutes & ":" & $elapsed_seconds) endif endif endif if $elapsed_seconds >= 60 then $elapsed_minutes += 1 $timer_started = TimerInit() endif endfunc func ToggleTimer() if $timer_running = 0 then $elapsed_minutes = 0 $timer_running = 1 if $audio_enabled = $gui_checked then _SoundPlay($start_sound) GUICtrlSetData($start_button, "Stop") $timer_started = TimerInit() AdlibRegister("UpdateTimer", 10) else AdlibUnRegister() if $audio_enabled = $gui_checked then _SoundPlay($stop_sound) GUICtrlSetData($start_button, "Start") $timer_running = 0 endif endfunc func ChangeTimerColor() ReadColors() $custom_colors[0] = $timer_color local $selected_colors = _ChooseColor($custom_colors, $main_gui) if @error then return false switch $selected_colors[0] case -1, -3, -4, "" return false case else $custom_colors = $selected_colors SaveColors() GUICtrlSetColor($timer_label, $timer_color) return $custom_colors[0] endswitch return false endfunc func ReadColors() local $colors_string = IniRead($ini_path, $my_name, "custom_colors", "") $timer_color = IniRead($ini_path, $my_name, "time_color", "") $custom_colors = StringSplit($colors_string, ",") endfunc func SaveColors() if not IsArray($custom_colors) or UBound($custom_colors) < 17 then return false local $colors_string for $color_index = 1 to 16 $colors_string &= $custom_colors[$color_index] & "," next $colors_string = StringTrimRight($colors_string, 1) IniWrite($ini_path, $my_name, "custom_colors", $colors_string) $timer_color = $custom_colors[0] IniWrite($ini_path, $my_name, "time_color", $timer_color) endfunc func ToggleAlwaysOnTop() if $always_on_top = $gui_unchecked then WinSetOnTop($main_gui, "", 1) $always_on_top = $gui_checked GUICtrlSetState($topmost_menu_item, $GUI_CHECKED) TrayItemSetState($tray_topmost_item, $TRAY_CHECKED) else WinSetOnTop($main_gui, "", 0) $always_on_top = $gui_unchecked GUICtrlSetState($topmost_menu_item, $GUI_UNCHECKED) TrayItemSetState($tray_topmost_item, $TRAY_UNCHECKED) endif IniWriteCheckBoxValue($ini_path, $ini_section, "always_on_top", $always_on_top) endfunc func ToggleAudio() if $audio_enabled = $gui_unchecked then $audio_enabled = $gui_checked GUICtrlSetState($audio_menu_item, $GUI_CHECKED) TrayItemSetState($tray_audio_item, $TRAY_CHECKED) else $audio_enabled = $gui_unchecked GUICtrlSetState($audio_menu_item, $GUI_UNCHECKED) TrayItemSetState($tray_audio_item, $TRAY_UNCHECKED) endif IniWriteCheckBoxValue($ini_path, $ini_section, "audio_enabled", $audio_enabled) endfunc func EditPrefs() local $editor_path = IniRead($ini_path, $my_name, "editor", "notepad.exe") if not Run($editor_path & " " & $ini_path) then MsgBox(48, "ERROR!", "I couldn't run:" & @LF & @LF & '"' & $editor_path & '"' & @LF & @LF & "Ironically, you need to check your ini settings! ", 30) endif endfunc func ShowAbout() GUISetState(@SW_HIDE, $main_gui) Opt("GUIOnEventMode", 0) local $about_gui = GUICreate("About " & $ini_section & "..", 190, 85, -1, -1, $WS_CAPTION, $WS_EX_TOPMOST) local $about_label = GUICtrlCreateLabel($my_name & " v" & $my_version & @CRLF & "(c) corz.org 2005-" & @YEAR, 60, 10) local $app_icon = GUICtrlCreateIcon($app_path, 0, 10, 10) local $ok_button = GUICtrlCreateButton("OK", 65, 53, 70, 23) GUICtrlSetState($ok_button, $GUI_FOCUS) GUISetState() local $gui_message while 1 $gui_message = GUIGetMsg() switch $gui_message case $GUI_EVENT_CLOSE, $ok_button GUIDelete($about_gui) exitloop case $about_label, $app_icon VisitURL($my_url) GUIDelete($about_gui) exitloop endswitch wend Opt("GUIOnEventMode", 1) GUISetState(@SW_SHOW, $main_gui) endfunc func ToggleWindow() local $window_state = WinGetState($main_gui) if BitAND($window_state, 2) then GUISetState(@SW_HIDE, $main_gui) else GUISetState(@SW_SHOW, $main_gui) endif endfunc func SaveWindowPosition() local $window_position = WinGetPos($main_gui) if IsArray($window_position) then IniWrite($ini_path, $ini_section, "x", $window_position[0]) IniWrite($ini_path, $ini_section, "y", $window_position[1]) endif endfunc func Quit() SaveWindowPosition() exit endfunc ; Compiler Directives.. ; #Region #pragma compile(AutoItExecuteAllowed, true) ; #pragma compile(ExecLevel, HighestAvailable) #pragma compile(Compression, 9) #AutoIt3Wrapper_LogFile="%scriptdir%\wrapper.log" #AutoIt3Wrapper_Run_Au3Stripper=Y #Au3Stripper_Parameters=/StripOnly /rsln #AutoIt3Wrapper_UseX64=Y #AutoIt3Wrapper_UseUpx=N #AutoIt3Wrapper_Run_AU3Check=Y #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 -v 1 #AutoIt3Wrapper_AU3Check_Stop_OnWarning=N #AutoIt3Wrapper_Run_Stop_OnError=N #AutoIt3Wrapper_Res_HiDpi=Y ; *** YOU MIGHT NEED TO USE FORWARD SLASHES IN RELATIVE PATHS - YMMV!!! ** #AutoIt3Wrapper_Icon=Resources\SimpleTimer.ico ; Free-Form Res Fields.. #AutoIt3Wrapper_Res_Field=Author|corz.org #AutoIt3Wrapper_Res_Field=CompanyName|corz.org #AutoIt3Wrapper_Res_Field=Contact|software@corz.org #AutoIt3Wrapper_Res_Field=Copyright|corz.org #AutoIt3Wrapper_Res_Field=Instructions|Launch SimpleTimer.exe #AutoIt3Wrapper_Res_Field=Long Description|SimpleTimer is a Simple Timer. #AutoIt3Wrapper_Res_Field=ProductName|SimpleTimer #AutoIt3Wrapper_Res_Field=Publisher|corz.org #AutoIt3Wrapper_Res_Field=Web Page|https://corz.org/ #AutoIt3Wrapper_Res_Field=Compiled|%date% %time% ; application's resource info.. #AutoIt3Wrapper_Res_Comment=SimpleTimer ; this is the one that shows up in Process Explorer.. #AutoIt3Wrapper_Res_Description=SimpleTimer - from corz.org #AutoIt3Wrapper_Res_LegalCopyright=corz.org #AutoIt3Wrapper_Res_ProductVersion=1 #AutoIt3Wrapper_Res_Field=Build|Beta Release ;; BASIC BACKUP: ; Backup this version of the script (dropped into a backup.zip, below). So I don't have to remember to.. #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" ;::dev::.. ; Copy latest binaries to app folders (overwrites existing binary). Your copy may be somewhere else.. ; #AutoIt3Wrapper_Run_After=copy "%outx64%" "C:\Program Files\corz\SimpleTimer\SimpleTimer.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" #EndRegion