global $app_version = "0.9.15" #AutoIt3Wrapper_Res_Fileversion=0.9.15 #cs Batch Runner, from corz.org.. https://corz.org/windows/software/batch-runner/ #ce #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Includes\corzShared.au3" $app_name = "Batch Runner" global $url_home = "http://corz.org/windows/software/batch-runner/index.php" global $url_version_check = "http://corz.org/inc/versions.php?app=BatchRunner" global $url_download = "http://corz.org/windows/software/batch-runner/batch-runner.php#section-Download" global $ini_file_name = "Batch Runner.ini" global $scratch_result global $app_exit_signal = false global $should_exit = false GUIRegisterMsg($WM_DROPFILES, "HandleDropFiles") GUIRegisterMsg($WM_INITMENUPOPUP, "UpdateMoveMenuState") global $drop_files[1] AutoItSetOption("GUICoordMode", 0) AutoItSetOption("GUIOnEventMode", 1) AutoItSetOption("TrayMenuMode", 11) AutoItSetOption("TrayOnEventMode", 1) global $installed_default_ini = false, $batch_start_time, $launch_mode = false, $exit_after_run = false, $batch_running global $exit_code = 0, $gui_active = true, $batch_paused = 0, $paused_elapsed, $abort_state = 0, $startup_command global $main_item_ids[1], $setup_item_ids[1], $post_item_ids[1], $needs_sort global $setup_commands, $post_commands, $main_commands global $tray_run_item, $tray_view_log, $tray_about_item, $tab_items[4] = [3] global $about_window, $command_dialog, $input_command global $log_available, $last_log_line, $log_file_encoding = 0, $pending_heartbeat_dots = 0 global $countdown_seconds = false, $countdown_started global $hover_to_show, $hover_sensitivity, $window_position global $min_width, $min_height global $default_input_x, $default_input_y, $default_input_width, $input_x, $input_y, $input_width global $batch_names, $current_batch, $sort_batch_list, $batch_section global $show_tips, $warn_delete_batch, $warn_delete_command, $garbage_collector global $hotkey_add, $hotkey_delete, $hotkey_run, $hotkey_pause, $hotkey_abort, $last_exit_code, $exit_code_token global $command_width, $autosize_columns, $tab_name_main, $tab_name_setup, $tab_name_post, $counter_width, $counter_align global $run_on_top, $auto_name_tasks, $allow_empty_batch, $show_randomize, $show_batch_row, $opt_hide_running_tasks, $portable_paths global $column_order, $column_name_commands, $column_name_count, $show_elapsed, $allowed_extensions, $allowed_extension_list global $reset_colors, $default_color, $color_text, $color_running, $color_success, $color_fail, $color_multi_fail, $color_error, $color_abort global $batch_font, $list_font, $batch_font_size, $list_font_size global $opt_select_all, $opt_ignore_selections, $opt_success_msg, $opt_precision_seconds, $opt_notify, $opt_beep global $opt_cycle_batch, $opt_max_time, $opt_randomize, $opt_halt_on_setup_fail, $opt_halt_on_task_fail, $opt_halt_on_fail_range, $fail_range_parts global $log_handle, $log_path, $opt_timestamp_logs, $opt_timestamp_everything, $opt_timestamp_delimiter, $opt_date_delimiter, $timestamp_all_lines global $opt_log_setup, $opt_log_separator, $opt_log_options, $opt_log_log_options, $opt_log_summary, $opt_utf8_log, $opt_log_update_minutes, $opt_compress_logs global $opt_always_show_trace, $opt_trace_file, $opt_trace_all_tasks global $main_window, $icon_path, $portable_mode global $appdata_dir = @AppDataDir & "\corz\" & $app_name global $recent_batches[101] = [100] $should_exit = false $app_exit_signal = -99 if $cmdline[0] = 1 and StringStripWS($cmdline[1], 3) = "portable" then if FileExists(@ScriptDir & "\" & $ini_file_name) then MsgBox($MB_TOPMOST, "Portable Mode Already Enabled!", "Portable Mode Already Enabled! ", 30) else if FileExists($appdata_dir & "\" & $ini_file_name) then local $portable_message = "The ini file from your User folder has been copied to the program folder." FileCopy($appdata_dir & "\" & $ini_file_name, @ScriptDir & "\" & $ini_file_name) if not FileExists(@ScriptDir & "\" & $ini_file_name) then FileInstall("Resources\Batch Runner.ini", @ScriptDir & "\" & $ini_file_name) $portable_message = "A new (default) ini file has been created in the program folder." endif IniWrite(@ScriptDir & "\" & $ini_file_name, $app_name, "log_folder", "Batch Runner [@batch].log") MsgBox($MB_TOPMOST, "Portable Mode Enabled!", "Portable Mode Enabled! " & $MSG_LF & $MSG_LF & ".. which is just a fancy way of saying.. " & _ $MSG_LF & $portable_message & $MSG_LF & $MSG_LF & "Batch Runner also set your log_folder " & $MSG_LF & _ "preference to this same directory. " & $MSG_LF & "Have portable fun!", 30) endif endif endif if @Compiled then $icon_path = @ScriptFullPath else $icon_path = ".\" & $app_name & ".exe" endif if FileExists(@ScriptDir & "\" & $ini_file_name) then $portable_mode = true $ini_path = @ScriptDir & "\" & $ini_file_name FileChangeDir(@ScriptDir) else $portable_mode = false if not FileExists($appdata_dir) then DirCreate($appdata_dir) $ini_path = $appdata_dir & "\" & $ini_file_name $installed_default_ini = FileInstall("Resources\Batch Runner.ini", $ini_path) endif if not FileExists($ini_path) then MsgBox($MB_OK + $MB_ICONERROR + $MB_TASKMODAL, "Batch Runner.ini is missing ", " Batch Runner.ini is missing, and Batch Runner is unable to write a new Batch Runner.ini file. " & _ $MSG_LF & $MSG_LF & " Please ensure your user folder writable!" & $MSG_LF & " Or else put Batch Runner.ini next to " & $icon_path & ", for portable usage. " & _ $MSG_LF & $MSG_LF & " BATCH RUNNER CANNOT CONTINUE.") Exit 171 endif if $installed_default_ini then IniWrite($ini_path, $app_name, "version", $app_version) else MigrateIniOnUpgrade() endif $debug_level = Int(IniRead($ini_path, $app_name, "debug_level", 0)) _Singleton("BatchRunner", 1) if @error = 183 then ActivateExistingInstance() exit endif LoadPreferences() TraySetIcon($icon_path, 0) TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "ToggleMainWindow") TraySetOnEvent($TRAY_EVENT_MOUSEOVER, "HoverShowWindow") AdlibRegister("ScheduleHourlyTimer", 3000) if $cmdline[0] then local $first_arg_index = false $startup_command = $cmdline[1] switch $cmdline[1] case "run" if $cmdline[0] > 1 then $current_batch = $cmdline[2] $first_arg_index = 3 endif $gui_active = false case "launch" if $cmdline[0] > 1 then $current_batch = $cmdline[2] $first_arg_index = 3 endif $launch_mode = true $startup_command = $cmdline[1] case "launchdie" if $cmdline[0] > 1 then $current_batch = $cmdline[2] $first_arg_index = 3 endif $launch_mode = true $exit_after_run = true case else $current_batch = $cmdline[1] $first_arg_index = 2 endswitch if $first_arg_index then for $arg_index = $first_arg_index to $cmdline[0] $current_batch &= " " & $cmdline[$arg_index] next $startup_command &= " " & $current_batch endif endif if not $gui_active then RunBatchNow() ExitApp($exit_code) endif RegisterHotKeys() ; GUI.. $main_window = GUICreate($app_name & " [" & $current_batch & "]", $window_width, $window_height, $window_x, $window_y, _ BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX), $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_CLOSE, "SaveAllAndExit") GUISetOnEvent($GUI_EVENT_RESIZED, "HandleWindowResize") GUISetOnEvent($GUI_EVENT_DROPPED, "PromptEnableAutoName") GUISetOnEvent($GUI_EVENT_MINIMIZE, "HideWindowOnMinimize") global $tab_control = GUICtrlCreateTab(1, 2, $window_width - 10, $window_height - 32, BitOR($TCS_BUTTONS, $TCS_FLATBUTTONS, $TCS_TOOLTIPS, $TCS_HOTTRACK, $WS_CHILD, $WS_TABSTOP)) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) global $add_button_x = 234 global $list_height_trim = 75 if $show_batch_row = $OFF then $list_height_trim = 50 $tab_items[1] = GUICtrlCreateTabItem(" " & $tab_name_main & " ") GUISetCoord(0, 0) global $list_main = GUICtrlCreateListView($column_name_commands & "|" & $column_name_count, -1, 22, $window_width, $window_height - $list_height_trim, _ BitOR($LVS_EDITLABELS, $LVS_REPORT), _ BitOR($LVS_EX_REGIONAL, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_ACCEPTFILES, $LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB, $LVS_EX_TWOCLICKACTIVATE, $LVS_EX_HEADERDRAGDROP)) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKRIGHT) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetCoord(0, 0) global $button_add_main = GUICtrlCreateButton("Add &Command", $add_button_x, $window_height - 24, 80, 20) GUICtrlSetOnEvent(-1, "AddMainCommand") GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE) GUICtrlCreateContextMenu($list_main) GUICtrlCreateMenuItem("Run This Command", $list_main) GUICtrlSetOnEvent(-1, "RunMainCommandOnce") GUICtrlCreateMenuItem("", $list_main) GUICtrlCreateMenuItem("Reveal in Explorer", $list_main) GUICtrlSetOnEvent(-1, "RevealMainInExplorer") GUICtrlCreateMenuItem("", $list_main) GUICtrlCreateMenuItem("Add Command", $list_main) GUICtrlSetOnEvent(-1, "AddMainCommand") GUICtrlCreateMenuItem("Edit Command", $list_main) GUICtrlSetOnEvent(-1, "EditSelectedMainCommand") GUICtrlCreateMenuItem("", $list_main) GUICtrlCreateMenuItem("Delete", $list_main) GUICtrlSetOnEvent(-1, "DeleteMainCommands") GUICtrlCreateMenuItem("", $list_main) GUICtrlCreateMenuItem("Invert Selection", $list_main) GUICtrlSetOnEvent(-1, "InvertMainSelection") GUICtrlCreateMenuItem("", $list_main) GUICtrlCreateMenuItem("Reload the List", $list_main) GUICtrlSetOnEvent(-1, "RefreshBatchLists") GUICtrlCreateMenuItem("", $list_main) global $menu_move_main_up = GUICtrlCreateMenuItem("Move Up", $list_main) GUICtrlSetOnEvent(-1, "MoveContextCommand") global $menu_move_main_down = GUICtrlCreateMenuItem("Move Down", $list_main) GUICtrlSetOnEvent(-1, "MoveContextCommand") GUICtrlCreateMenuItem("", $list_main) GUICtrlCreateMenuItem("Edit the List", $list_main) GUICtrlSetOnEvent(-1, "EditMainList") $tab_items[2] = GUICtrlCreateTabItem(" " & $tab_name_setup & " ") GUISetCoord(0, 0) global $list_setup = GUICtrlCreateListView($column_name_commands, -1, 22, $window_width, $window_height - $list_height_trim, _ BitOR($LVS_EDITLABELS, $LVS_REPORT), _ BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_ACCEPTFILES, $LVS_EX_REGIONAL, $LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB, $LVS_EX_TWOCLICKACTIVATE)) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKRIGHT) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetCoord(0, 0) global $button_add_setup = GUICtrlCreateButton("Add &Command", $add_button_x, $window_height - 24, 80, 20) GUICtrlSetOnEvent(-1, "AddSetupCommand") GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE) GUICtrlCreateContextMenu($list_setup) GUICtrlCreateMenuItem("Run This Command", $list_setup) GUICtrlSetOnEvent(-1, "RunSetupCommandOnce") GUICtrlCreateMenuItem("", $list_setup) GUICtrlCreateMenuItem("Reveal in Explorer", $list_setup) GUICtrlSetOnEvent(-1, "RevealSetupInExplorer") GUICtrlCreateMenuItem("", $list_setup) GUICtrlCreateMenuItem("Add Command", $list_setup) GUICtrlSetOnEvent(-1, "AddSetupCommand") GUICtrlCreateMenuItem("Edit Command", $list_setup) GUICtrlSetOnEvent(-1, "EditSelectedSetupCommand") GUICtrlCreateMenuItem("", $list_setup) GUICtrlCreateMenuItem("Delete", $list_setup) GUICtrlSetOnEvent(-1, "DeleteSetupCommands") GUICtrlCreateMenuItem("", $list_setup) GUICtrlCreateMenuItem("Invert Selection", $list_setup) GUICtrlSetOnEvent(-1, "InvertSetupSelection") GUICtrlCreateMenuItem("", $list_setup) GUICtrlCreateMenuItem("Reload The List", $list_setup) GUICtrlSetOnEvent(-1, "RefreshBatchLists") GUICtrlCreateMenuItem("", $list_setup) global $menu_move_setup_up = GUICtrlCreateMenuItem("Move Up", $list_setup) GUICtrlSetOnEvent(-1, "MoveContextCommand") global $menu_move_setup_down = GUICtrlCreateMenuItem("Move Down", $list_setup) GUICtrlSetOnEvent(-1, "MoveContextCommand") GUICtrlCreateMenuItem("", $list_setup) GUICtrlCreateMenuItem("Edit the List", $list_setup) GUICtrlSetOnEvent(-1, "EditSetupList") $tab_items[3] = GUICtrlCreateTabItem(" " & $tab_name_post & " ") GUISetCoord(0, 0) global $list_post = GUICtrlCreateListView($column_name_commands, -1, 22, $window_width, $window_height - $list_height_trim, _ BitOR($LVS_EDITLABELS, $LVS_REPORT), _ BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_ACCEPTFILES, $LVS_EX_REGIONAL, $LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB, $LVS_EX_TWOCLICKACTIVATE)) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKRIGHT) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetCoord(0, 0) global $button_add_post = GUICtrlCreateButton("Add &command", $add_button_x, $window_height - 24, 80, 20) GUICtrlSetOnEvent(-1, "AddPostCommand") GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE) GUICtrlCreateContextMenu($list_post) GUICtrlCreateMenuItem("Run This Command", $list_post) GUICtrlSetOnEvent(-1, "RunPostCommandOnce") GUICtrlCreateMenuItem("", $list_post) GUICtrlCreateMenuItem("Reveal in Explorer", $list_post) GUICtrlSetOnEvent(-1, "RevealPostInExplorer") GUICtrlCreateMenuItem("", $list_post) GUICtrlCreateMenuItem("Add command", $list_post) GUICtrlSetOnEvent(-1, "AddPostCommand") GUICtrlCreateMenuItem("Edit command", $list_post) GUICtrlSetOnEvent(-1, "EditSelectedPostCommand") GUICtrlCreateMenuItem("", $list_post) GUICtrlCreateMenuItem("Delete", $list_post) GUICtrlSetOnEvent(-1, "DeletePostCommands") GUICtrlCreateMenuItem("", $list_post) GUICtrlCreateMenuItem("Invert selection", $list_post) GUICtrlSetOnEvent(-1, "InvertPostSelection") GUICtrlCreateMenuItem("", $list_post) GUICtrlCreateMenuItem("Reload the list", $list_post) GUICtrlSetOnEvent(-1, "RefreshBatchLists") GUICtrlCreateMenuItem("", $list_post) global $menu_move_post_up = GUICtrlCreateMenuItem("Move Up", $list_post) GUICtrlSetOnEvent(-1, "MoveContextCommand") global $menu_move_post_down = GUICtrlCreateMenuItem("Move Down", $list_post) GUICtrlSetOnEvent(-1, "MoveContextCommand") GUICtrlCreateMenuItem("", $list_post) GUICtrlCreateMenuItem("Edit the List", $list_post) GUICtrlSetOnEvent(-1, "EditPostList") GUICtrlCreateTabItem("") GUISetCoord(0, 0) global $options_range_start = GUICtrlCreateDummy() if $show_batch_row = $ON then global $check_randomize global $check_cycle = GUICtrlCreateCheckbox("Cycle Main Batch:", 5, $window_height - 48, default, 20, $BS_RIGHTBUTTON) GUICtrlSetOnEvent(-1, "OnCycleToggled") GUICtrlSetState(-1, $opt_cycle_batch) global $label_time_limit = GUICtrlCreateLabel("Time Limit:", 120, 3, default, 20) global $input_max_time = GUICtrlCreateInput(FormatMinutesInterval($opt_max_time), 55, -3, 50, 20) GUICtrlSetOnEvent(-1, "OnTimeLimitChanged") GUICtrlSetFont(-1, 9, 400, 0, "Lucida Console") if $show_randomize = $ON then $check_randomize = GUICtrlCreateCheckbox("Randomize Tasks:", 60, 0, default, 20, $BS_RIGHTBUTTON) GUICtrlSetOnEvent(-1, "OnRandomizeToggled") GUICtrlSetState(-1, $opt_randomize) else $check_randomize = GUICtrlCreateCheckbox("", -999, -999) endif endif GUISetCoord(0, 0) global $combo_batch = GUICtrlCreateCombo("", 5, $window_height - 24, 150, 200) GUICtrlSetOnEvent(-1, "ReloadCurrentBatch") if $batch_font then GUICtrlSetFont(-1, $batch_font_size, 400, 0, $batch_font) global $button_delete_batch = GUICtrlCreateButton("Delete &Batch", 155, 0, 70, 20) GUICtrlSetOnEvent(-1, "DeleteCurrentBatch") GUICtrlSetState(-1, $GUI_HIDE) global $button_new_batch = GUICtrlCreateButton("New &Batch", 0, 0, 70, 20) GUICtrlSetOnEvent(-1, "CreateNewBatch") for $control_id = $options_range_start to $button_new_batch GUICtrlSetResizing($control_id, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE) next GUISetCoord(0, 0) global $button_countdown = GUICtrlCreateButton("&CountDown", $window_width - 75, $window_height - 24, 70, 20) GUICtrlSetOnEvent(-1, "PromptCountdownTime") GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE) GUICtrlSetState(-1, $GUI_HIDE) global $button_abort = GUICtrlCreateButton("&Abort!", 0, 0, 70, 20) GUICtrlSetOnEvent(-1, "AbortBatchRun") GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE) GUICtrlSetState(-1, $GUI_HIDE) global $button_run_batch = GUICtrlCreateButton("&Run Batch", 0, 0, 70, 20) GUICtrlSetOnEvent(-1, "ScheduleBatchRun") GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE) GUICtrlCreateContextMenu($combo_batch) GUICtrlCreateMenuItem("Reload The List", $combo_batch) GUICtrlSetOnEvent(-1, "RefreshBatchLists") GUICtrlCreateMenuItem("", $combo_batch) GUICtrlCreateMenuItem("Rename This Batch", $combo_batch) GUICtrlSetOnEvent(-1, "RenameCurrentBatch") GUICtrlCreateMenuItem("Duplicate This Batch", $combo_batch) GUICtrlSetOnEvent(-1, "DuplicateCurrentBatch") GUICtrlCreateMenuItem("", $combo_batch) GUICtrlCreateMenuItem("Save As AutoRun [Background]", $combo_batch) GUICtrlSetOnEvent(-1, "CreateRunShortcut") GUICtrlCreateMenuItem("Save As AutoRun [Foreground]", $combo_batch) GUICtrlSetOnEvent(-1, "CreateLaunchDieShortcut") if $show_tips = $ON then GUICtrlSetTip($tab_items[1], " Task Lists. Click the tabs to go to Main, Pre- or Post- Batch tasks") GUICtrlSetTip($list_main, " Task List. " & $MSG_LF & " All the tasks for the current batch, in standard execution order. " & $MSG_LF & _ " Right-click for options, click the title bar to bring selections to the front. " & $MSG_LF & " Note: You can drag stuff into here. ") GUICtrlSetTip($combo_batch, " Select a batch from here, its task will fill the task list. " & $MSG_LF & " (right-click for options) ") GUICtrlSetTip($button_delete_batch, " Delete the current batch ") GUICtrlSetTip($button_new_batch, " Click here to create a new batch. " & $MSG_LF & " Hold down the SHIFT key to get the Delete button ") GUICtrlSetTip($button_add_main, " Add a new task to the current batch. ") GUICtrlSetTip($button_countdown, " Click here to run the current batch of tasks after a countdown. ") GUICtrlSetTip($button_run_batch, " Click here to run the current batch of tasks. " & $MSG_LF & " Hold down the SHIFT key to get the Countdown button. ") GUICtrlSetTip($list_setup, " Pre-Batch Task List. All the setup tasks for the current batch, in ini order. ") GUICtrlSetTip($button_add_setup, " Add a new pre-batch task to the current batch. ") GUICtrlSetTip($list_post, " Post-Batch Task List. All the wrap-up tasks for the current batch, in ini order. ") GUICtrlSetTip($button_add_post, " Add a new post-batch task to the current batch. ") if $show_batch_row = $ON then GUICtrlSetTip($check_cycle, " Check this box to cycle the main tasks. ") GUICtrlSetTip($label_time_limit, " Set the time limit for a cycled batch, in minutes. " & $MSG_LF & " You can also specify seconds (e.g. 5s) or hours (e.g. 3h) ") GUICtrlSetTip($input_max_time, " Numbers without a suffix will be interpreted as minutes " & $MSG_LF & " but you can also use 'm' if you prefer (e.g. 6m) ") if $show_randomize = $ON then GUICtrlSetTip($check_randomize, " Run the tasks in a random order. " & $MSG_LF & ' Okay, "pseudo-random!"') endif endif PopulateBatchList() SaveComboSelection($recent_batches, $current_batch) BuildTrayMenu(true) SaveWindowPosition() RebuildAllListViews(true) ClearListHighlights() GUISetIcon($icon_path, 0, $main_window) GUISetState() if $launch_mode then RunBatchNow() if $exit_after_run then ExitApp($exit_code) while $app_exit_signal = -99 if WinActive($app_name) and _IsPressed("10") then GUICtrlSetState($button_delete_batch, $GUI_ENABLE + $GUI_SHOW) GUICtrlSetState($button_new_batch, $GUI_DISABLE + $GUI_HIDE) GUICtrlSetState($button_countdown, $GUI_ENABLE + $GUI_SHOW) GUICtrlSetState($button_run_batch, $GUI_DISABLE + $GUI_HIDE) else GUICtrlSetState($button_delete_batch, $GUI_DISABLE + $GUI_HIDE) GUICtrlSetState($button_new_batch, $GUI_ENABLE + $GUI_SHOW) GUICtrlSetState($button_countdown, $GUI_DISABLE + $GUI_HIDE) GUICtrlSetState($button_run_batch, $GUI_ENABLE + $GUI_SHOW) endif Sleep(250) wend ExitApp($exit_code) ; ; ExecuteCommandWait() ; Runs one batch command and waits for it. ; func ExecuteCommandWait($command_text, $working_dir = "", $show_flag = @SW_HIDE) local $run_error = 0 local $run_extended = 0 local $capture_extended = 0 local $command_exit = 0 local $captured_output = false local $run_result[5] $command_text = UnescapePipes($command_text) $command_text = StringReplace($command_text, $exit_code_token, $last_exit_code) SetError(0) select case IsShellexPrefix($command_text) $command_text = StripCommandPrefixes($command_text) ShellExecuteWait($command_text, "", $working_dir, "open", $show_flag) case $opt_trace_all_tasks = $ON if IsTracePrefix($command_text) then $command_text = StripTracePrefix($command_text) $captured_output = ExecuteCommandCapture($command_text, $working_dir, $show_flag) $command_exit = @error $capture_extended = @extended $run_error = 0 case IsTracePrefix($command_text) $captured_output = ExecuteCommandCapture(StripTracePrefix($command_text), $working_dir, $show_flag) $command_exit = @error $capture_extended = @extended $run_error = 0 case IsDosPrefix($command_text) $command_exit = RunWait('"' & @ComSpec & '" /c ' & StripDosPrefix($command_text), $working_dir, $show_flag) if @error then $run_error = @error if @extended then $run_extended = @extended case else $command_exit = RunWait($command_text, $working_dir, $show_flag) if @error then $run_error = @error if @extended then $run_extended = @extended endselect $run_result[0] = $command_exit $run_result[1] = $run_error $run_result[2] = $run_extended $run_result[3] = $captured_output $run_result[4] = $capture_extended $last_exit_code = $command_exit return $run_result endfunc ; ; ExecuteCommandCapture() ; Runs one command and captures its output. ; func ExecuteCommandCapture($command_text, $working_dir = "", $show_flag = @SW_HIDE) SetError(0, 0) local $process_id, $std_output, $exit_code, $process_handle if IsDosPrefix($command_text) then $process_id = Run(@ComSpec & " /c " & StringTrimLeft($command_text, 4), $working_dir, $show_flag, $STDERR_MERGED) else $process_id = Run($command_text, $working_dir, $show_flag, $STDERR_MERGED) endif $process_handle = OpenProcessForQuery($process_id) while ProcessExists($process_id) Sleep(25) if $abort_state > 0 then exitloop wend $std_output = StdoutRead($process_id) $exit_code = GetProcessExitCode($process_handle) CloseProcessHandle($process_handle) return SetError($exit_code, $process_id, $std_output) endfunc ; ; WriteTraceFile() ; Writes a command trace file. ; func WriteTraceFile($command_text, $command_output) if $opt_trace_file = "" then $opt_trace_file = false $opt_trace_file = ResolveLogPath($opt_trace_file, "Batch Runner [" & $current_batch & "] Trace File.log") if not $opt_trace_file then return false $command_text = UnescapePipes(StringTrimLeft($command_text, 6)) local $output_prefix if IsDosPrefix($command_text) then $command_text = StringTrimLeft($command_text, 4) $output_prefix = "DOS " endif $command_output = UnifyCRLF($command_output, $LF) FileWriteLine($opt_trace_file, $opt_log_separator & $LF & $output_prefix & 'Trace for "' & $command_text & '" at ' & TimestampString() & $LF & $LF & $command_output & $LF) endfunc ; ; ShowCommandOutput() ; Shows captured command output. ; func ShowCommandOutput($command_text, $command_output = "") if not $command_text then return false if not $command_output then $command_output = "NO COMMAND OUTPUT!" & $LF & "perhaps it was piped to some other file?" local $saved_event_mode = AutoItSetOption("GUIOnEventMode", 0) if $gui_active and WinVisible($main_window) then LockAppWindow($main_window) local $dialog_x = IniRead($ini_path, $app_name, "st_x", $window_x) local $dialog_y = IniRead($ini_path, $app_name, "st_y", $window_y) local $dialog_width = IniRead($ini_path, $app_name, "st_w", $window_width) local $dialog_height = IniRead($ini_path, $app_name, "st_h", $window_height) if $dialog_width < 400 then $dialog_width = 400 if $dialog_height < 64 then $dialog_y = 64 if IsTracePrefix($command_text) then $command_text = StringTrimLeft($command_text, 6) local $output_window = GUICreate($app_name & " v" & $app_version & ".. output for " & UnescapePipes($command_text), $dialog_width, $dialog_height, $dialog_x, $dialog_y, BitOR($WS_DLGFRAME, $WS_SIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU)) GUISetIcon($icon_path, 0, $output_window) $command_output = UnifyCRLF($command_output, $LF) GUICtrlCreateEdit($command_output, 5, 5, $dialog_width - 10, $dialog_height - 45, BitOR($WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_MULTILINE, $ES_OEMCONVERT, $ES_NOHIDESEL, $ES_WANTRETURN)) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKRIGHT) local $ok_button = GUICtrlCreateButton("OK.", 0, $dialog_height - 42, $dialog_width - 10, 32, $BS_DEFPUSHBUTTON) GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) GUISetState(@SW_SHOW) local $gui_message while 1 $gui_message = GUIGetMsg() switch $gui_message case $ok_button SaveWinPos($output_window, "st_x", "st_y", "st_w", "st_h") exitloop case $GUI_EVENT_CLOSE exitloop endswitch wend GUIDelete($output_window) AutoItSetOption("GUIOnEventMode", $saved_event_mode) if $gui_active and WinVisible($main_window) then UnlockAppWindow($main_window) endfunc func RevealMainInExplorer() RevealSelectedInExplorer($list_main) endfunc func RevealSetupInExplorer() RevealSelectedInExplorer($list_setup) endfunc func RevealPostInExplorer() RevealSelectedInExplorer($list_post) endfunc ; ; RevealSelectedInExplorer() ; Reveals one selected command in Explorer. Debug tag: "RevealInExplorer =>". ; func RevealSelectedInExplorer(byref $list_view) debug("RevealInExplorer =>" & $list_view & "<=", @ScriptLineNumber) local $selected_index = RequireSingleSelection($list_view) if $selected_index == false then return false local $selected_command = _GUICtrlListView_GetItemText($list_view, $selected_index, 0) if $selected_command = "" then return false local $file_path, $extension, $dot_pos for $extension_index = 1 to $allowed_extension_list[0] $extension = $allowed_extension_list[$extension_index] $dot_pos = StringInStr($selected_command, "." & $extension) if $dot_pos then $file_path = StringMid($selected_command, 1, $dot_pos + StringLen($extension) + 1) Run("Explorer.exe " & GetLongParent($file_path)) return endif next endfunc func RunMainCommandOnce() RunSelectedCommandOnce($list_main, $main_item_ids) endfunc func RunSetupCommandOnce() RunSelectedCommandOnce($list_setup, $setup_item_ids) endfunc func RunPostCommandOnce() RunSelectedCommandOnce($list_post, $post_item_ids) endfunc ; ; RunSelectedCommandOnce() ; Runs one selected command and waits for it. ; func RunSelectedCommandOnce(byref $list_view, byref $item_ids) local $selected_index = RequireSingleSelection($list_view) if $selected_index == false then return false local $selected_command = _GUICtrlListView_GetItemText($list_view, $selected_index, 0) if $selected_command = "" then return false local $run_result = ExecuteCommandWait($selected_command, "", @SW_SHOW) local $command_exit = $run_result[0] local $run_error = $run_result[1] local $captured_output = $run_result[3] $selected_command = UnescapePipes($selected_command) local $result_label select case $command_exit == 0 and $run_error <> 0 GUICtrlSetBkColor($item_ids[$selected_index], $color_error) $result_label = "Error" case $command_exit > 0 GUICtrlSetBkColor($item_ids[$selected_index], $color_fail) $result_label = "Failed" case $command_exit < 0 GUICtrlSetBkColor($item_ids[$selected_index], $color_abort) $result_label = "Fatal Error" case $command_exit == 0 and $run_error = 0 GUICtrlSetBkColor($item_ids[$selected_index], $color_success) $result_label = "Success" endselect if IsTracePrefix($selected_command) or $opt_trace_all_tasks = $ON then WriteTraceFile($selected_command, $captured_output) ShowCommandOutput($selected_command & " [" & $result_label & "]", $captured_output) endif _GUICtrlListView_SetItemText($list_view, $selected_index, $result_label, 1) ControlFocus($main_window, "", $combo_batch) endfunc func PromptCountdownRun() PromptCountdownTime() endfunc ; ; PromptCountdownTime() ; Prompts for the countdown delay. ; func PromptCountdownTime() LockAppWindow($main_window) local $countdown_input = InputBox("Enter The Countdown Time..", "Enter the time to count down before running the batch..", "", "", 400, 122, $window_x, $window_y, 30, $main_window) UnlockAppWindow($main_window) if $countdown_input = "" then return false $countdown_seconds = ParseHourInterval($countdown_input) ScheduleBatchRun() endfunc ; ; ScheduleBatchRun() ; Schedules a batch run via timer. ; func ScheduleBatchRun() AdlibRegister("RunBatchNow", 5) return true endfunc ; ; RunBatchNow() ; Runs the batch immediately (command-line path). ; func RunBatchNow() BuildRunTrayMenu() AdlibUnRegister("RestoreWindowTitle") AdlibUnRegister("UpdateStatusTicker") AdlibUnRegister("RunBatchNow") if $gui_active then ControlFocus($main_window, "", $combo_batch) $run_on_top = IniReadCheckBox($ini_path, $app_name, "run_on_top", $OFF) SetRunUiState() if $opt_ignore_selections = $ON then SelectAllLists() local $setup_queue = BuildProcessQueue(_GUICtrlListView_GetSelectedIndices($list_setup, true), $setup_commands) local $main_queue = BuildProcessQueue(_GUICtrlListView_GetSelectedIndices($list_main, true), $main_commands) local $post_queue = BuildProcessQueue(_GUICtrlListView_GetSelectedIndices($list_post, true), $post_commands) else if not LoadBatchSection() then $exit_code = 5 AppendLogLine("*** Could not get commands for " & $current_batch & " ***" & $LF) ExitApp($exit_code) endif $main_queue = $main_commands $setup_queue = $setup_commands $post_queue = $post_commands endif $abort_state = 0 $batch_paused = 0 $paused_elapsed = 0 local $run_count = 0 local $error_count = 0 local $exec_error_count = 0 local $command_exit = "" local $run_error = 0 local $captured_output = false local $trace_output = "" if $allow_empty_batch = $OFF then if not IsArray($main_queue) then $exit_code = -3 AppendLogLine("*** Empty Batches (e.g. '" & $current_batch & "') not allowed in user prefs! ***" & $LF) if $gui_active then ShowAppMsgBox($MB_OK + $MB_ICONWARNING + $MB_TASKMODAL, "Nothing to do!", "No commands are selected!", 0) SetRunUiState(true) return false else ExitApp($exit_code) endif endif endif OpenLogForRun() AppendLogLine("Running Batch: " & '"' & $current_batch & '"' & " [begun at: " & TimestampString() & "] " & $LF, $timestamp_all_lines) AppendLogLine($LF, $timestamp_all_lines) if $opt_log_options = $ON then AppendLogLine("Options: " & $LF, $timestamp_all_lines) AppendLogLine($LF, $timestamp_all_lines) AppendLogLine(" Time Limit: " & FormatDurationMinutes($opt_max_time) & $LF, $timestamp_all_lines) AppendLogLine(" Cycle: " & Human($opt_cycle_batch) & $LF, $timestamp_all_lines) AppendLogLine(" Randomize: " & Human($opt_randomize) & $LF, $timestamp_all_lines) AppendLogLine(" Halt on task fail: " & Human($opt_halt_on_task_fail) & $LF, $timestamp_all_lines) AppendLogLine(" Halt on fail range: " & Human($opt_halt_on_fail_range) & $LF, $timestamp_all_lines) AppendLogLine(" Halt on setup fail: " & Human($opt_halt_on_setup_fail) & $LF, $timestamp_all_lines) AppendLogLine(" Select All: " & Human($opt_select_all) & $LF, $timestamp_all_lines) AppendLogLine(" Ignore Selections: " & Human($opt_ignore_selections) & $LF, $timestamp_all_lines) AppendLogLine(" Precision Seconds: " & Human($opt_precision_seconds) & $LF, $timestamp_all_lines) AppendLogLine(" Hide Running Tasks: " & Human($opt_hide_running_tasks) & $LF, $timestamp_all_lines) AppendLogLine(" Trace All Tasks: " & Human($opt_trace_all_tasks) & $LF, $timestamp_all_lines) AppendLogLine(" Always Show Trace: " & Human($opt_always_show_trace) & $LF, $timestamp_all_lines) AppendLogLine(" Trace File: " & Human($opt_trace_file) & $LF, $timestamp_all_lines) AppendLogLine(" Hide Running Tasks: " & Human($opt_hide_running_tasks) & $LF, $timestamp_all_lines) AppendLogLine(' Success Message: "' & Human($opt_success_msg) & '"' & $LF, $timestamp_all_lines) AppendLogLine(" Notify: " & Human($opt_notify) & $LF, $timestamp_all_lines) local $beep_text = Human($opt_beep) if $beep_text = Number($beep_text) and $beep_text > 36 then $beep_text &= " Hz" AppendLogLine(" Beep: " & $beep_text & $LF, $timestamp_all_lines) AppendLogLine($LF, $timestamp_all_lines) endif if $opt_log_log_options = $ON then AppendLogLine(' Log Path: "' & $log_path & '"' & $LF, $timestamp_all_lines) AppendLogLine(" UTF8 Log: " & Human($opt_utf8_log) & $LF, $timestamp_all_lines) AppendLogLine(" UTF8 BOM: " & Human(IniReadPrefLayers($ini_path, $app_name, $current_batch, "uft8_bom", $OFF, 1)) & $LF, $timestamp_all_lines) AppendLogLine(" Log Line Feed: " & IniReadPrefLayers($ini_path, $app_name, $current_batch, "log_line_feed", "CRLF") & $LF, $timestamp_all_lines) AppendLogLine(" Timestamp Logs: " & Human($opt_timestamp_logs) & $LF, $timestamp_all_lines) AppendLogLine(" Timestamp Everything: " & Human($opt_timestamp_everything) & $LF, $timestamp_all_lines) AppendLogLine(" timestamp_delimit: " & $opt_timestamp_delimiter & $LF, $timestamp_all_lines) AppendLogLine(" Log Setup: " & Human($opt_log_setup) & $LF, $timestamp_all_lines) AppendLogLine(" Log Options: " & Human($opt_log_options) & $LF, $timestamp_all_lines) AppendLogLine(" Log Log Options: " & Human($opt_log_log_options) & $LF, $timestamp_all_lines) AppendLogLine(" Log Summary: " & Human($opt_log_summary) & $LF, $timestamp_all_lines) AppendLogLine(" Log Separator: " & $opt_log_separator & $LF, $timestamp_all_lines) AppendLogLine(" Log Update: " & $opt_log_update_minutes & $LF, $timestamp_all_lines) AppendLogLine(" Compress Logs: " & Human($opt_compress_logs) & $LF, $timestamp_all_lines) AppendLogLine($LF, $timestamp_all_lines) endif if $gui_active then for $queue_index = 0 to _GUICtrlListView_GetItemCount($list_main) - 1 _GUICtrlListView_SetItemText($list_main, $queue_index, "0 / 0", 1) next endif if $gui_active and $reset_colors = $ON then ClearListHighlights() if $countdown_seconds then $countdown_started = TimerInit() TrayItemSetState($tray_run_item, $TRAY_DISABLE) $batch_running = false while $countdown_seconds and $abort_state = 0 local $countdown_remaining = CountdownRemainingMs() if $show_elapsed = $ON then WinSetTitle($main_window, "", $app_name & " [" & $current_batch & "][Batch begins in: " & FormatElapsedMs($countdown_remaining + 999) & "]") else WinSetTitle($main_window, "", $app_name & " [" & $current_batch & "][counting down]") endif Sleep(200) if $countdown_remaining < 0 then $countdown_seconds = false wend $batch_running = true TrayItemSetState($tray_run_item, $TRAY_ENABLE) endif $batch_start_time = TimerInit() if $gui_active then WinSetTitle($main_window, "", $app_name & " [" & $current_batch & "][running]") if IsArray($setup_queue) and $setup_queue[0][0] > 0 then if $opt_log_setup = $ON then AppendLogLine("Running " & $tab_name_setup & " Tasks.." & $LF, $timestamp_all_lines) $exit_code = 0 for $queue_index = 1 to $setup_queue[0][0] if $gui_active then UpdateStatusTicker() local $command_text = $setup_queue[$queue_index][1] if $opt_log_setup = $ON then AppendLogLine("[" & $tab_name_setup & " Command:]" & UnescapePipes($command_text), true) ArmHeartbeatTimer() if $gui_active then GUICtrlSetBkColor($setup_item_ids[$setup_queue[$queue_index][2]], $color_running) $run_error = 0 $command_exit = "" $captured_output = false local $show_flag = @SW_HIDE if $opt_hide_running_tasks = $OFF then $show_flag = @SW_SHOW local $run_result = ExecuteCommandWait($command_text, "", $show_flag) $command_exit = $run_result[0] $run_error = $run_result[1] $captured_output = $run_result[3] TrimHeartbeatDots() select case $command_exit == 0 and $run_error = 0 if $gui_active then GUICtrlSetBkColor($setup_item_ids[$setup_queue[$queue_index][2]], $color_success) case else if $command_exit == 0 and $run_error <> 0 then if $gui_active then GUICtrlSetBkColor($setup_item_ids[$setup_queue[$queue_index][2]], $color_error) else if $gui_active then GUICtrlSetBkColor($setup_item_ids[$setup_queue[$queue_index][2]], $color_fail) endif if $opt_halt_on_setup_fail = $ON then $exit_code = -1 ShowAppMsgBox($MB_OK + $MB_ICONERROR + $MB_TASKMODAL, $tab_name_setup & "Task Failure", _ "One of your " & $tab_name_setup & " tasks exited with an error. " & $MSG_LF & "The operation has been aborted. " & $MSG_LF & $MSG_LF & _ "Note: If you prefer to ignore these errors, set the " & $MSG_LF & "following inside Batch Runner.ini.. " & $MSG_LF & $MSG_LF & "halt_on_setup_fail=false") if $opt_log_setup = $ON then AppendLogLine(" Result: " & $command_exit & $LF) $main_queue = "" $post_queue = "" exitloop endif endselect if $opt_log_setup = $ON then AppendLogLine(" Result: " & $command_exit & $LF) endif if $captured_output then WriteTraceFile($command_text, $captured_output) if $opt_always_show_trace = $ON then $trace_output &= $LF & $captured_output endif next AdlibUnRegister("UpdateStatusTicker") if $opt_log_setup = $ON then AppendLogLine($LF, $timestamp_all_lines) endif if IsArray($main_queue) and $main_queue[0][0] > 0 then local $used_indices[$main_queue[0][0] + 1] AppendLogLine("Running " & $tab_name_main & " Tasks.." & $LF, $timestamp_all_lines) local $batch_done = false local $batch_timer = TimerInit() $exit_code = 0 while $batch_done = false for $queue_index = 1 to $main_queue[0][0] if $opt_randomize = $ON and $main_queue[0][0] > 1 then if $opt_cycle_batch = $OFF then $queue_index = Random(1, $main_queue[0][0], 1) while FindInStringArray($used_indices, $queue_index) $queue_index = Random(1, $main_queue[0][0], 1) wend _ArrayAdd($used_indices, $queue_index) else $queue_index = Random(1, $main_queue[0][0], 1) endif endif $command_text = $main_queue[$queue_index][1] if $app_exit_signal = 0 then exitloop while $batch_paused = 1 UpdateStatusTicker() AdlibUnRegister("UpdateStatusTicker") if $abort_state > 0 then exitloop Sleep(250) $paused_elapsed += 250 wend if $abort_state > 0 then exitloop 2 if $gui_active then TraySetToolTip(" Click to toggle Batch Runner " & $MSG_LF & " Right-click for the menu. " & $MSG_LF & " Running: " & $command_text) else TraySetToolTip(" Batch Runner.. Right-click for the menu. " & $MSG_LF & " Running: " & $command_text) endif if $gui_active then UpdateStatusTicker() AppendLogLine("[Command:]" & UnescapePipes($command_text), true) ArmHeartbeatTimer() if $gui_active then GUICtrlSetBkColor($main_item_ids[$main_queue[$queue_index][2]], $color_running) local $result_message $run_error = 0 $command_exit = "" $captured_output = false $show_flag = @SW_HIDE if $opt_hide_running_tasks = $OFF then $show_flag = @SW_SHOW $run_result = ExecuteCommandWait($command_text, "", $show_flag) $run_count += 1 $command_exit = $run_result[0] $run_error = $run_result[1] $captured_output = $run_result[3] select case $command_exit == 0 and $run_error = 0 $result_message = $command_exit & " " & $opt_success_msg select case $main_queue[$queue_index][3] <> 0 if $gui_active then GUICtrlSetBkColor($main_item_ids[$main_queue[$queue_index][2]], $color_multi_fail) case else if $gui_active then GUICtrlSetBkColor($main_item_ids[$main_queue[$queue_index][2]], $color_success) endselect case $command_exit == 0 and $run_error <> 0 $result_message = "Something bad happened attempting to run this command. Please first check it can run OUTSIDE Batch Runner." $main_queue[$queue_index][3] += 1 if $gui_active then GUICtrlSetBkColor($main_item_ids[$main_queue[$queue_index][2]], $color_error) $exec_error_count += 1 case $command_exit > 0 $result_message = "Error code: " & $command_exit if $main_queue[$queue_index][3] == 0 then if $gui_active then GUICtrlSetBkColor($main_item_ids[$main_queue[$queue_index][2]], $color_fail) else if $gui_active then GUICtrlSetBkColor($main_item_ids[$main_queue[$queue_index][2]], $color_multi_fail) endif $main_queue[$queue_index][3] += 1 $error_count += 1 case $command_exit < 0 if $opt_halt_on_task_fail = $ON and $command_exit >= (0 + $fail_range_parts[1]) and $command_exit <= (0 + $fail_range_parts[2]) then $exit_code = $command_exit $result_message = "ERROR: " & $command_exit & " -- ** BATCH ABORTED **" if $gui_active then GUICtrlSetBkColor($main_item_ids[$main_queue[$queue_index][2]], $color_abort) $abort_state = 1 else $result_message = "ERROR: " & $command_exit & " -- ** BATCH NOT ABORTED **" if $main_queue[$queue_index][3] == 0 then if $gui_active then GUICtrlSetBkColor($main_item_ids[$main_queue[$queue_index][2]], $color_fail) else if $gui_active then GUICtrlSetBkColor($main_item_ids[$main_queue[$queue_index][2]], $color_multi_fail) endif endif $error_count += 1 $main_queue[$queue_index][3] += 1 endselect $main_queue[$queue_index][4] += 1 if $gui_active then _GUICtrlListView_SetItemText($list_main, $main_queue[$queue_index][2], $main_queue[$queue_index][3] & " / " & $main_queue[$queue_index][4], 1) TrimHeartbeatDots() AppendLogLine(" Result: " & $result_message & $LF) if $captured_output then WriteTraceFile($command_text, $captured_output) if $opt_always_show_trace = $ON then $trace_output &= $LF & $captured_output endif if $abort_state > 0 then exitloop 2 if StringInStr($result_message, "183") then exitloop if $opt_max_time > 0 and (TimerDiff($batch_timer) - $paused_elapsed) / 1000 / 60 >= $opt_max_time then $batch_done = true exitloop endif if $gui_active and $abort_state = 0 then AdlibUnRegister("UpdateStatusTicker") local $elapsed_text if $show_elapsed = $ON then $elapsed_text = "[time: " & FormatElapsedMs(TimerDiff($batch_start_time) - $paused_elapsed) & "]" WinSetTitle($main_window, "", $app_name & " [" & $current_batch & "][running]" & $elapsed_text) endif if $opt_randomize = $ON and $main_queue[0][0] > 1 and $opt_cycle_batch = $OFF then if $run_count = $main_queue[0][0] then exitloop 2 $queue_index = 0 endif next if $opt_cycle_batch = $OFF then exitloop wend endif AdlibUnRegister("UpdateStatusTicker") if $opt_log_summary = $ON then AppendLogLine($LF, $timestamp_all_lines) AppendLogLine("Summary: " & $LF, $timestamp_all_lines) local $no_fail_note = "" if not $error_count then $no_fail_note = " (No Fails) " AppendLogLine($LF, $timestamp_all_lines) AppendLogLine(" Total Tasks: " & $run_count & $no_fail_note, $timestamp_all_lines) if $error_count then AppendLogLine($LF) AppendLogLine(" Total Fails: " & $error_count, $timestamp_all_lines) endif if $exec_error_count then AppendLogLine($LF) AppendLogLine(" Total Errors: " & $exec_error_count, $timestamp_all_lines) endif AppendLogLine($LF) endif if IsArray($post_queue) and $post_queue[0][0] > 0 then if $opt_log_setup = $ON then AppendLogLine($LF, $timestamp_all_lines) if $opt_log_setup = $ON then AppendLogLine("Running " & $tab_name_post & " Tasks.." & $LF, $timestamp_all_lines) $exit_code = 0 for $queue_index = 1 to $post_queue[0][0] $command_text = $post_queue[$queue_index][1] if $gui_active then UpdateStatusTicker() if $opt_log_setup = $ON then AppendLogLine("[" & $tab_name_post & " Command:]" & UnescapePipes($command_text), true) ArmHeartbeatTimer() if $gui_active then GUICtrlSetBkColor($post_item_ids[$post_queue[$queue_index][2]], $color_running) $run_error = 0 $command_exit = "" $captured_output = false $show_flag = @SW_HIDE if $opt_hide_running_tasks = $OFF then $show_flag = @SW_SHOW $run_result = ExecuteCommandWait($command_text, "", $show_flag) $command_exit = $run_result[0] $run_error = $run_result[1] $captured_output = $run_result[3] TrimHeartbeatDots() select case $command_exit == 0 and $run_error = 0 if $gui_active then GUICtrlSetBkColor($post_item_ids[$post_queue[$queue_index][2]], $color_success) case else if $command_exit == 0 and $run_error <> 0 then if $gui_active then GUICtrlSetBkColor($post_item_ids[$post_queue[$queue_index][2]], $color_error) else if $gui_active then GUICtrlSetBkColor($post_item_ids[$post_queue[$queue_index][2]], $color_fail) endif if $opt_halt_on_setup_fail = $ON then $exit_code = -1 ShowAppMsgBox($MB_OK + $MB_ICONERROR + $MB_TASKMODAL, $tab_name_post & "Task Failure", "One of your " & $tab_name_post & " tasks exited with an error. " & $MSG_LF & _ "The operation has been aborted. " & $MSG_LF & $MSG_LF & "Note: If you prefer to ignore these errors, set the " & $MSG_LF & _ "following inside Batch Runner.ini.. " & $MSG_LF & $MSG_LF & "halt_on_setup_fail=false") if $opt_log_setup = $ON then AppendLogLine(" Result: " & $command_exit & $LF) exitloop endif endselect if $opt_log_setup = $ON then AppendLogLine(" Result: " & $command_exit & $LF) endif if $captured_output then WriteTraceFile($command_text, $captured_output) if $opt_always_show_trace = $ON then $trace_output &= $LF & $captured_output endif next endif AdlibUnRegister("UpdateStatusTicker") local $total_elapsed = TimerDiff($batch_start_time) - $paused_elapsed local $run_outcome = "completed" switch $abort_state case 1 $run_outcome = "ABORTED" $exit_code = -1 case 2 $run_outcome = "USER ABORTED" $exit_code = -2 endswitch AppendLogLine($LF, $timestamp_all_lines) AppendLogLine("Batch: " & '"' & $current_batch & '"' & " " & $run_outcome & " at " & TimestampString() & " [total time: " & Round($total_elapsed / 1000, 3) & "s] " & $LF, $timestamp_all_lines) CloseLogFile() if $opt_beep <> $OFF then PlayBeepFeedback() if $gui_active then BuildTrayMenu() TraySetToolTip(" Click to toggle Batch Runner " & $MSG_LF & " Right-click for the menu. ") else TraySetToolTip(" Batch Runner.. Right-click for the menu. ") endif if $opt_notify = $ON and $gui_active and $run_count > 0 then local $notify_title = "Batch Run Complete! " local $notify_text = "Selected commands have been processed! " if $opt_ignore_selections = $ON then $notify_text = "All commands have been processed! " if $abort_state > 0 then $notify_title = "Batch Run Aborted! " switch $abort_state case 1 $notify_text = "Batch Run Aborted! " case 2 $notify_text = "User Aborted Batch Run! " endswitch endif ShowAppMsgBox($MB_OK + $MB_ICONINFORMATION + $MB_TASKMODAL, $notify_title, $notify_text) endif if $trace_output and $opt_always_show_trace = $ON then ShowCommandOutput("All Commands", $trace_output) if $gui_active then SetRunUiState(true) local $title_suffix if $show_elapsed = $ON then $title_suffix = " [total time: " & FormatElapsedSeconds(Round($total_elapsed / 1000, 3)) & "]" endif if $abort_state = 1 then $title_suffix &= " [ABORTED]" if $abort_state = 2 then $title_suffix &= " [USER ABORT!]" FlashWindowTitle($title_suffix) endif endfunc func OnCycleToggled() SaveRunFlags() endfunc func SaveRunFlags() SaveRunOptionFlags() endfunc func OnRandomizeToggled() SaveRunOptionFlags() endfunc func OnTimeLimitChanged() SaveRunOptionFlags() endfunc ; ; SaveRunOptionFlags() ; Saves the per-batch run option flags. ; func SaveRunOptionFlags() local $control_value = GUICtrlRead($check_cycle) if $opt_cycle_batch <> $control_value then $opt_cycle_batch = $control_value IniWrite($ini_path, $current_batch, "opt|cycle_main_batch", Human($opt_cycle_batch)) endif $control_value = NormalizeCheckInterval(GUICtrlRead($input_max_time)) if $opt_max_time <> $control_value then $opt_max_time = $control_value IniWrite($ini_path, $current_batch, "opt|max_batch_time", FormatMinutesInterval($opt_max_time)) endif if $show_randomize = $ON then $control_value = GUICtrlRead($check_randomize) if $opt_randomize <> $control_value then $opt_randomize = $control_value IniWrite($ini_path, $current_batch, "opt|randomize_batch", Human($opt_randomize)) endif endif endfunc ; ; LoadBatchSection() ; Loads one batch section into tables. ; func LoadBatchSection() local $column_count = 5 local $main_rows[1][$column_count] local $setup_rows[1][$column_count] local $post_rows[1][$column_count] $batch_section = IniReadSection($ini_path, $current_batch) if not IsArray($batch_section) then if $gui_active then if SaveSettings6() then $batch_section = IniReadSection($ini_path, $current_batch) else ShowAppMsgBox($MB_ICONWARNING + $MB_TASKMODAL, "No Batch!", "Invalid Batch Specified! ") ClearAllLists() $exit_code = 5 return false endif else AppendLogLine("*** Invalid Batch (" & $current_batch & ") Specified! ***" & $LF) Exit 5 endif endif local $main_count = 1, $setup_count = 1, $post_count = 1 if IsArray($batch_section) then for $row_index = 1 to $batch_section[0][0] if $portable_paths = $ON and StringLeft($batch_section[$row_index][1], 2) = ".\" then $batch_section[$row_index][1] = StringReplace($batch_section[$row_index][1], ".\", @ScriptDir & "\", 1, 0) endif $batch_section[$row_index][1] = EscapePipes($batch_section[$row_index][1]) select case StringLeft($batch_section[$row_index][0], 4) = "pre|" redim $setup_rows[$setup_count + 1][$column_count] $setup_rows[0][0] = $setup_count $setup_rows[$setup_count][0] = $batch_section[$row_index][0] $setup_rows[$setup_count][1] = $batch_section[$row_index][1] $setup_rows[$setup_count][2] = $row_index $setup_rows[$setup_count][3] = 0 $setup_rows[$setup_count][4] = 0 $setup_count += 1 case StringLeft($batch_section[$row_index][0], 5) = "post|" redim $post_rows[$post_count + 1][$column_count] $post_rows[0][0] = $post_count $post_rows[$post_count][0] = $batch_section[$row_index][0] $post_rows[$post_count][1] = $batch_section[$row_index][1] $post_rows[$post_count][2] = $row_index $post_rows[$post_count][3] = 0 $post_rows[$post_count][4] = 0 $post_count += 1 case StringLeft($batch_section[$row_index][0], 4) = "opt|" case else redim $main_rows[$main_count + 1][$column_count] $main_rows[0][0] = $main_count $main_rows[$main_count][0] = $batch_section[$row_index][0] $main_rows[$main_count][1] = $batch_section[$row_index][1] $main_rows[$main_count][2] = $row_index $main_rows[$main_count][3] = 0 $main_rows[$main_count][4] = 0 $main_count += 1 endselect next endif $main_commands = $main_rows $setup_commands = $setup_rows $post_commands = $post_rows LoadBatchRunOptions($current_batch) return true endfunc ; ; ClearAllLists() ; Clears every command list. ; func ClearAllLists() _GUICtrlListView_DeleteAllItems($list_main) _GUICtrlListView_DeleteAllItems($list_setup) _GUICtrlListView_DeleteAllItems($list_post) _GUICtrlListView_SetItemCount($list_main, 0) _GUICtrlListView_SetItemCount($list_setup, 0) _GUICtrlListView_SetItemCount($list_post, 0) endfunc ; ; RebuildAllListViews() ; ; Rebuilds every list view from its array. ; func RebuildAllListViews($full_rebuild = false) if LoadBatchSection() = false then return false ClearAllLists() if $setup_commands[0][0] then redim $setup_item_ids[$setup_commands[0][0]] for $row_index = 1 to $setup_commands[0][0] $setup_item_ids[$row_index - 1] = GUICtrlCreateListViewItem($setup_commands[$row_index][1], $list_setup) next if $post_commands[0][0] then redim $post_item_ids[$post_commands[0][0]] for $row_index = 1 to $post_commands[0][0] $post_item_ids[$row_index - 1] = GUICtrlCreateListViewItem($post_commands[$row_index][1], $list_post) next if $main_commands[0][0] then redim $main_item_ids[$main_commands[0][0]] for $row_index = 1 to $main_commands[0][0] $main_item_ids[$row_index - 1] = GUICtrlCreateListViewItem($main_commands[$row_index][1] & "|0 / 0", $list_main) next if $list_font then GUICtrlSetFont($list_main, $list_font_size, 400, 0, $list_font) GUICtrlSetFont($list_setup, $list_font_size, 400, 0, $list_font) GUICtrlSetFont($list_post, $list_font_size, 400, 0, $list_font) endif if $opt_select_all = $ON then SelectAllLists() $column_order = IniRead($ini_path, $app_name, "column_order", "0|1") _GUICtrlListView_SetColumnOrder($list_main, $column_order) AutosizeListColumns($full_rebuild) switch $counter_align case "right" SetColumnAlignment($list_main, 1, 1) case "center", "centre" SetColumnAlignment($list_main, 1, 2) case else SetColumnAlignment($list_main, 1, 0) endswitch if $show_batch_row = $ON then GUICtrlSetState($check_cycle, $opt_cycle_batch) GUICtrlSetData($input_max_time, FormatMinutesInterval($opt_max_time)) GUICtrlSetState($check_randomize, $opt_randomize) endif LoadLogSettings($current_batch) if FileExists($log_path) then TrayItemSetState($tray_view_log, $TRAY_ENABLE) else TrayItemSetState($tray_view_log, $TRAY_DISABLE) endif endfunc func SelectAllCommands() SelectAllLists() endfunc func SelectAllLists() SelectAllRows($list_main) SelectAllRows($list_setup) SelectAllRows($list_post) endfunc func SelectAllRows(byref $list_view) _GUICtrlListView_SetItemSelected($list_view, -1, true) endfunc func InvertMainSelection() InvertRowSelection($list_main) endfunc func InvertSetupSelection() InvertRowSelection($list_setup) endfunc func InvertPostSelection() InvertRowSelection($list_post) endfunc ; ; InvertRowSelection() ; ; Inverts the selected state of every row. ; func InvertRowSelection(byref $list_view) local $is_selected for $row_index = 0 to _GUICtrlListView_GetItemCount($list_view) - 1 $is_selected = _GUICtrlListView_GetItemSelected($list_view, $row_index) if $is_selected then _GUICtrlListView_SetItemSelected($list_view, $row_index, false) else _GUICtrlListView_SetItemSelected($list_view, $row_index, true) endif next endfunc func AddMainCommand() AddCommandToList($list_main) endfunc func AddSetupCommand() AddCommandToList($list_setup) endfunc func AddPostCommand() AddCommandToList($list_post) endfunc ; ; AddCommandToActiveTab() ; Adds a command to the active tab list. ; func AddCommandToActiveTab() local $active_tab = _GUICtrlTab_GetCurSel($tab_control) switch $active_tab case 0 AddMainCommand() case 1 AddSetupCommand() case 2 AddPostCommand() endswitch endfunc ; ; AddCommandToList() ; Adds one command row to a list. ; func AddCommandToList(byref $list_view) if _GUICtrlComboBox_GetCount($combo_batch) < 1 then if not CreateNewBatch() then return false endif AddCommandDialog($list_view, "", false) RebuildAllListViews() endfunc ; ; ValidateAndAddDrop() ; Validates a dropped path and adds it. ; func ValidateAndAddDrop($list_view, $file_path) $file_path = LnkToReal($file_path) if not FindInStringArray($allowed_extension_list, GetExtension($file_path)) then ShowAppMsgBox($MB_ICONWARNING + $MB_TASKMODAL, "Invalid drop!", BaseName($file_path) & " is not executable (try " & $allowed_extensions & " files) ") return -1 endif if InsertCommandWithPrompt($list_view, $file_path, $main_window) then return true return false endfunc ; ; PromptEnableAutoName() ; Offers to enable automatic task naming. ; func PromptEnableAutoName() if not IsArray($drop_files) then return false if $drop_files[0] > 1 and $auto_name_tasks = $OFF then local $auto_name_setting = IniReadCheckBox($ini_path, $app_name, "auto_name_notify", $OFF) if $auto_name_setting = $OFF then local $user_choice = ShowAppMsgBox($MB_YESNO + $MB_ICONQUESTION + $MB_TASKMODAL, "Manual Labour Detected!", " " & $app_name & " has an option to auto-name new tasks. " & $MSG_LF & " Would you like to enable this now? ", 30) if $user_choice = 6 then $auto_name_tasks = $ON IniWriteCheckBoxValue($ini_path, $app_name, "auto_name_tasks", $auto_name_tasks) endif IniWriteCheckBoxValue($ini_path, $app_name, "auto_name_notify", $ON) endif endif for $file_index = 1 to $drop_files[0] if ValidateAndAddDrop(ListViewHandleForTab(_GUICtrlTab_GetCurSel($tab_control)), $drop_files[$file_index]) = false then exitloop next endfunc ; ; AppendDropPathsToInput() ; Appends dropped paths to the input field. ; func AppendDropPathsToInput($path_prefix) if not IsArray($drop_files) then return false local $combined_text = $path_prefix for $file_index = 1 to $drop_files[0] $combined_text &= $drop_files[$file_index] & " " next $combined_text = StringTrimRight($combined_text, 1) GUICtrlSetData($input_command, $combined_text) endfunc ; ; HandleDropFiles() ; Collects files dropped onto the window (WM_DROPFILES). ; func HandleDropFiles($window_handle, $message_id, $drop_handle, $extra_param) #forceref $window_handle, $message_id, $extra_param local $name_length, $name_buffer local $drop_count = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $drop_handle, "int", -1, "ptr", 0, "int", 255) $drop_files[0] = $drop_count[0] for $file_index = 0 to $drop_files[0] - 1 $name_length = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $drop_handle, "int", $file_index, "ptr", 0, "int", 0) $name_length = $name_length[0] + 1 $name_buffer = DllStructCreate("char[" & $name_length & "]") DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $drop_handle, "int", $file_index, "ptr", DllStructGetPtr($name_buffer), "int", $name_length) redim $drop_files[$file_index + 2] $drop_files[$file_index + 1] = DllStructGetData($name_buffer, 1) $name_buffer = 0 next endfunc func EditSelectedMainCommand() SaveSelectedCommand($list_main, $main_commands) endfunc func EditSelectedSetupCommand() SaveSelectedCommand($list_setup, $setup_commands) endfunc func EditSelectedPostCommand() SaveSelectedCommand($list_post, $post_commands) endfunc ; ; SaveSelectedCommand() ; Saves the selected command text back to settings. ; func SaveSelectedCommand(byref $list_view, $column_info) if not IsArray($column_info) then return false local $selected_row = RequireSingleSelection($list_view) if $selected_row == false then return false local $command_text = _GUICtrlListView_GetItemText($list_view, $selected_row, 0) if $command_text = "" then return false local $edited_text = AddCommandDialog($list_view, $command_text, true) if $edited_text = "" then return false IniWrite($ini_path, $current_batch, $column_info[$selected_row + 1][0], $edited_text) RebuildAllListViews() _GUICtrlListView_SetItemSelected($list_view, $selected_row, true) endfunc func DeleteMainCommands() DeleteSelectedWithConfirm($list_main, $main_commands) endfunc func DeleteSetupCommands() DeleteSelectedWithConfirm($list_setup, $setup_commands) endfunc func DeletePostCommands() DeleteSelectedWithConfirm($list_post, $post_commands) endfunc ; ; DeleteCommandsFromActiveTab() ; Deletes selected commands from the active tab list. ; func DeleteCommandsFromActiveTab() local $active_tab = _GUICtrlTab_GetCurSel($tab_control) switch $active_tab case 0 DeleteMainCommands() case 1 DeleteSetupCommands() case 2 DeletePostCommands() endswitch endfunc ; ; DeleteSelectedWithConfirm() ; Deletes the selection after confirmation. ; func DeleteSelectedWithConfirm(byref $list_view, $command_table) LockAppWindow($main_window) local $selected_indices = _GUICtrlListView_GetSelectedIndices($list_view, true) if $selected_indices[0] = 0 then ShowAppMsgBox($MB_OK + $MB_ICONWARNING + $MB_TASKMODAL, "Nothing to do!", "No commands are selected! ") UnlockAppWindow($main_window) return false endif local $user_choice if $warn_delete_command = $OFF then $user_choice = 6 else local $plural_words[2] = ["the", "?"] if $selected_indices[0] > 1 then dim $plural_words[2] = ["EVERY ONE of the", "s?"] endif $user_choice = ShowAppMsgBox($MB_YESNO + $MB_ICONWARNING + $MB_TASKMODAL, "PLEASE CONFIRM!", "Are you SURE you wish to delete " & $plural_words[0] & " selected command" & $plural_words[1] & " ", 30) endif UnlockAppWindow($main_window) if $user_choice = 6 then for $selection_index = 1 to $selected_indices[0] IniDelete($ini_path, $current_batch, $command_table[$selected_indices[$selection_index] + 1][0]) next RebuildAllListViews() return true endif endfunc ; ; AddCommandDialog() ; Shows the add/edit command dialog. ; func AddCommandDialog(byref $list_view, $initial_text, $edit_mode = true) LockAppWindow($main_window) local $saved_event_mode = AutoItSetOption("GUIOnEventMode", 0) local $result_text = "" local $dialog_result = -99 local $min_dialog_width = 345 $initial_text = UnescapePipes($initial_text) local $edit_text = $initial_text local $dialog_title = "add new command.." local $ok_tip = " ok the command and update the list. " if $edit_mode then $dialog_title = "edit command.." $ok_tip = " ok the edit and update the command list. " endif $input_x = IniRead($ini_path, $app_name, "input_x", $default_input_x) $input_y = IniRead($ini_path, $app_name, "input_y", $default_input_y) $input_width = IniRead($ini_path, $app_name, "input_width", $default_input_width) if $input_width < $min_dialog_width then $input_width = $min_dialog_width local $dialog_height = 60 $command_dialog = GUICreate($dialog_title, $input_width, $dialog_height, $input_x, $input_y, _ BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX), BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOOLWINDOW), $main_window) GUICtrlCreateLabel("Enter the full command. You can drag && drop stuff onto here, too..", 5, 5, 350, 20) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKSIZE) $input_command = GUICtrlCreateInput($initial_text, 5, 20, $input_width - 50, 23) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKRIGHT + $GUI_DOCKSIZE) GUICtrlSetTip(-1, " Enter the full command here. Note: you can drag & drop stuff onto here, too. ") GUICtrlSetFont(-1, 9, 400, 0, "Lucida Console") local $ok_button = GUICtrlCreateButton("ok", $input_width - 45, 0, 30, 23) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKRIGHT + $GUI_DOCKSIZE) GUICtrlSetTip(-1, $ok_tip) WinSetOnTop($command_dialog, "", 1) local $accelerators[1][2] = [["{enter}", $ok_button]] GUISetAccelerators($accelerators) GUISetState() local $dialog_height_px = WinGetPos($command_dialog) $dialog_height_px = $dialog_height_px[3] ControlFocus($command_dialog, "", $input_command) local $gui_message while $dialog_result = -99 $gui_message = GUIGetMsg() switch $gui_message case $input_command $edit_text = GUICtrlRead($input_command) case $GUI_EVENT_DROPPED AppendDropPathsToInput($edit_text) $result_text = GUICtrlRead($input_command) $edit_text = $result_text case $GUI_EVENT_CLOSE $dialog_result = 0 case $GUI_EVENT_RESIZED WinMove($command_dialog, "", default, default, default, $dialog_height_px) local $window_pos = WinGetPos($command_dialog) if $window_pos[2] < $min_dialog_width then WinMove($command_dialog, "", default, default, $min_dialog_width, default) case $ok_button $result_text = GUICtrlRead($input_command) SaveWinPos($command_dialog, "input_x", "input_y", "input_width") if $edit_mode then if $result_text = "" then continuecase else if $result_text = "" then exitloop if InsertCommandWithPrompt($list_view, $result_text, $main_window) then exitloop $result_text = EscapePipes($result_text) endif $dialog_result = 1 endswitch Sleep(10) wend AutoItSetOption("GUIOnEventMode", $saved_event_mode) GUIDelete($command_dialog) UnlockAppWindow($main_window) if $dialog_result = 1 then return $result_text FlashWindowTitle("[CANCELLED]", 1000) return false endfunc ; ; InsertCommandWithPrompt() ; Inserts a command, prompting for its name. ; func InsertCommandWithPrompt(byref $list_view, $command_text, $parent_window) if $batch_names[0] < 1 then if not CreateNewBatch() then return false endif local $user_choice = 0, $command_name if $auto_name_tasks = $OFF then LockAppWindow($main_window) $command_name = InputBox("Name the command..", "Enter a name for the new command..", "", "", 300, 122, $window_x, $window_y, 0, $parent_window) UnlockAppWindow($main_window) endif if StringLeft($command_name, 1) = ";" then $command_name = StringTrimLeft($command_name, 1) $command_name = StringReplace($command_name, "[", "{") $command_name = StringReplace($command_name, "]", "}") local $key_prefix, $command_key switch $list_view case $list_main $key_prefix = "" $command_key = $command_name case $list_setup $key_prefix = "pre|" $command_key = $key_prefix & $command_name case $list_post $key_prefix = "post|" $command_key = $key_prefix & $command_name endswitch if $auto_name_tasks = $ON then local $key_index = 1 while IniRead($ini_path, $current_batch, $key_prefix & StringFormat("%05d", $key_index), "*****") <> "*****" $key_index += 1 wend $user_choice = 6 $command_name = StringFormat("%05d", $key_index) elseif $command_name <> "" then if IniRead($ini_path, $current_batch, $command_key, "*****") <> "*****" then $user_choice = ShowAppMsgBox($MB_YESNO + $MB_TASKMODAL, "Command Exists!", "There is already a command with that name! " & $MSG_LF & "Do you wish to overwrite it?") if $user_choice <> 6 then FlashWindowTitle("[Save Aborted]", 1000) return false endif else $user_choice = 6 endif endif if $user_choice = 6 then local $write_prefix switch $list_view case $list_setup $write_prefix = "pre|" case $list_post $write_prefix = "post|" endswitch IniWrite($ini_path, $current_batch, $write_prefix & $command_name, MakePathRelative($command_text)) RebuildAllListViews() return true endif return false endfunc ; ; BuildProcessQueue() ; Builds the run queue table for selected commands. ; func BuildProcessQueue($selected_indices, $command_table) local $column_count = 5 local $run_queue[1][$column_count] local $queue_rows = 1 for $selection_index = 1 to $selected_indices[0] redim $run_queue[$queue_rows + 1][$column_count] $run_queue[0][0] = $queue_rows $run_queue[$queue_rows][0] = $command_table[$selected_indices[$selection_index] + 1][0] $run_queue[$queue_rows][1] = $command_table[$selected_indices[$selection_index] + 1][1] $run_queue[$queue_rows][2] = $selected_indices[$selection_index] $run_queue[$queue_rows][3] = 0 $run_queue[$queue_rows][4] = 0 $queue_rows += 1 next if $run_queue[0][0] = 0 then return false return $run_queue endfunc ; ; RequireSingleSelection() ; Requires exactly one selected command, prompting otherwise. ; func RequireSingleSelection(byref $list_view) local $dialog_title, $prompt_text local $selected_items = _GUICtrlListView_GetSelectedIndices($list_view, true) if $selected_items[0] < 1 or $selected_items[0] > 1 then LockAppWindow($main_window) $dialog_title = "One at a time!" $prompt_text = "Please select ONE command! " if $selected_items[0] < 1 then $dialog_title = "Nothing Selected!" $prompt_text = "First, select a command! " endif ShowAppMsgBox($MB_ICONWARNING + $MB_TASKMODAL, $dialog_title, $prompt_text) UnlockAppWindow($main_window) return false endif return $selected_items[1] endfunc ; ; ClearListHighlights() ; Clears row highlighting on all lists. func ClearListHighlights() ResetItemBackground($list_setup, $setup_item_ids) ResetItemBackground($list_main, $main_item_ids) ResetItemBackground($list_post, $post_item_ids) endfunc ; ResetItemBackground() ; Resets one list background colour. func ResetItemBackground(byref $list_view, $color_table) if not $gui_active then return false for $row_index = 0 to _GUICtrlListView_GetItemCount($list_view) - 1 GUICtrlSetBkColor($color_table[$row_index], 16777215) next endfunc ; ; PopulateBatchList() ; Fills the batch combo from settings. ; func PopulateBatchList() if not FindInStringArray($batch_names, $current_batch) then if not SaveSettings6() then $current_batch = "" endif _GUICtrlComboBox_ResetContent($combo_batch) if $sort_batch_list = $ON then _ArraySort($batch_names, 0, 1) for $batch_index = 1 to $batch_names[0] GUICtrlSetData($combo_batch, $batch_names[$batch_index]) next ControlCommand($main_window, "", $combo_batch, "SelectString", $current_batch) endfunc ; ; CreateNewBatch() ; Creates a new batch. ; func CreateNewBatch() local $default_name = "My New Batch" local $prompt_for_name, $user_input $batch_names = ListBatchNames() local $combo_text = GUICtrlRead($combo_batch) if $combo_text and not FindInStringArray($batch_names, $combo_text) then $default_name = $combo_text if $default_name <> "My New Batch" and not FindInStringArray($batch_names, $combo_text) then $prompt_for_name = true $user_input = $default_name endif if not $prompt_for_name then LockAppWindow($main_window) $user_input = InputBox("Create new batch..", "Enter name for the new batch..", $default_name, "", 280, 122, $window_x, $window_y, 0, $main_window) UnlockAppWindow($main_window) if $user_input = "" then FlashWindowTitle("[New Batch Cancelled]", 1500) return false endif endif if FindInStringArray($batch_names, $user_input) then FlashWindowTitle("[Name Already Exists!]", 1000) return false endif $current_batch = $user_input FlashWindowTitle("[New Batch Created!]", 1000) IniWriteSection($ini_path, $current_batch, "") PopulateBatchList() ControlCommand($main_window, "", $combo_batch, "SelectString", $current_batch) SwitchCurrentBatch(true) return true endfunc ; ; RenameCurrentBatch() ; Renames the current batch. ; func RenameCurrentBatch() local $prompt_for_name, $new_name local $combo_text = GUICtrlRead($combo_batch) if not FindInStringArray($batch_names, $combo_text) then $prompt_for_name = true $new_name = $combo_text endif if not $prompt_for_name then LockAppWindow($main_window) $new_name = InputBox("Rename " & $current_batch & "..", "Enter a new name for" & $current_batch & "..", $current_batch, "", 280, 122, $window_x, $window_y, 0, $main_window) UnlockAppWindow($main_window) if $new_name = "" then return false endif if FindInStringArray($batch_names, $new_name) then FlashWindowTitle("[Name Already Exists!]", 1000) return false endif IniWrite($ini_path, $current_batch, "BatchRunnerTMPValue", 0) IniRenameSection($ini_path, $current_batch, $new_name, 0) IniDelete($ini_path, $new_name, "BatchRunnerTMPValue") FlashWindowTitle("[Rename Complete!]", 1000) SwitchToBatch($new_name) endfunc ; ; DuplicateCurrentBatch() ; Duplicates the current batch. ; func DuplicateCurrentBatch() local $prompt_for_name, $duplicate_name, $section_data local $combo_text = GUICtrlRead($combo_batch) if not FindInStringArray($batch_names, $combo_text) then $prompt_for_name = true $duplicate_name = $combo_text endif if not $prompt_for_name then LockAppWindow($main_window) $duplicate_name = InputBox("Enter a name for the duplicate..", "Enter a name for the duplicate of " & $current_batch & "..", _ $current_batch, "", 280, 122, $window_x, $window_y, 0, $main_window) UnlockAppWindow($main_window) if $duplicate_name = "" then return false endif if $duplicate_name = $current_batch then FlashWindowTitle("[Operation Completed! ;o)]", 1000) return false endif $section_data = IniReadSection($ini_path, $current_batch) IniWriteSection($ini_path, $duplicate_name, $section_data) $current_batch = $duplicate_name FlashWindowTitle("[Duplication Complete!]", 1000) SwitchToBatch($duplicate_name) endfunc func CreateRunShortcut() CreateBatchShortcut("run") endfunc func CreateLaunchDieShortcut() CreateBatchShortcut("launchdie") endfunc ; ; CreateBatchShortcut() ; Creates a shortcut that launches one batch. ; func CreateBatchShortcut($shortcut_mode = "run") LockAppWindow($main_window) local $save_dir = IniRead($ini_path, $app_name, "batch_save_dir", @DesktopDir) local $shortcut_path = FileSaveDialog("Name the Shortcut..", $save_dir, "All (*.*)") if $shortcut_path = "" then FlashWindowTitle(" Invalid Path!") else IniWrite($ini_path, $app_name, "batch_save_dir", GetLongParent($shortcut_path)) FileCreateShortcut(@AutoItExe, $shortcut_path & ".lnk", @ScriptDir, $shortcut_mode & " " & $current_batch) endif UnlockAppWindow($main_window) endfunc ; ; DeleteCurrentBatch() ; Deletes the current batch after confirmation. ; func DeleteCurrentBatch() local $user_choice, $batch_data, $deleted_data, $fallback_batch, $backup_index = "" if $warn_delete_batch = $OFF then $user_choice = 6 else $user_choice = ShowAppMsgBox($MB_YESNO + $MB_ICONWARNING + $MB_TASKMODAL, "Are you SURE?", "Are you ABSOLUTELY sure you wish to delete the current batch? ") endif if $user_choice = 6 then $batch_data = IniReadSection($ini_path, $current_batch) if not IsArray($batch_data) then IniWrite($ini_path, $current_batch, "BatchRunnerTMPValue", 0) IniDelete($ini_path, $current_batch) $deleted_data = IniReadSection($ini_path, "deleted-" & $current_batch) if IsArray($deleted_data) then $backup_index = 1 while $backup_index < 10 $deleted_data = IniReadSection($ini_path, $backup_index & "deleted-" & $current_batch) if not IsArray($deleted_data) then exitloop $backup_index += 1 wend endif IniWriteSection($ini_path, $backup_index & "deleted-" & $current_batch, $batch_data) $batch_names = ListBatchNames() $fallback_batch = GetComboSelection($recent_batches, $batch_names) $current_batch = $fallback_batch PopulateBatchList() ControlCommand($main_window, "", $combo_batch, "SelectString", $current_batch) FlashWindowTitle("[Delete Complete!]", 1000) RebuildAllListViews() endif endfunc ; ; SaveSettings6() ; Saves application settings. ; func SaveSettings6() $batch_names = ListBatchNames() if FindInStringArray($batch_names, $current_batch) then return true else if $launch_mode then return false if $cmdline[0] = 1 then if not $current_batch then return false IniWriteSection($ini_path, $current_batch, "") $batch_names = ListBatchNames() return true endif if $batch_names[0] > 0 then $current_batch = $batch_names[1] IniWrite($ini_path, $app_name, "current_batch", $current_batch) return true else $current_batch = "" IniWrite($ini_path, $app_name, "current_batch", $current_batch) return false endif endif return endfunc ; ; ListBatchNames() ; Lists batch sections stored in the ini file. ; func ListBatchNames() local $section_names = IniReadSectionNames($ini_path) local $batch_list[1] local $batch_count = 0 for $section_index = 1 to $section_names[0] if $section_names[$section_index] <> "Batch Runner" and not StringInStr($section_names[$section_index], "deleted-") then $batch_count += 1 redim $batch_list[$batch_count + 1] $batch_list[0] += 1 $batch_list[$batch_count] = $section_names[$section_index] endif next IniWrite($ini_path, $app_name, "current_batch", $current_batch) return $batch_list endfunc func ReloadCurrentBatch() SwitchCurrentBatch(true) endfunc ; ; SwitchCurrentBatch() ; Switches to the batch named in the combo. ; func SwitchCurrentBatch($refresh_lists = false) $current_batch = GUICtrlRead($combo_batch) SaveComboSelection($recent_batches, $current_batch) IniWrite($ini_path, $app_name, "current_batch", $current_batch) WinSetTitle($main_window, "", $app_name & " [" & $current_batch & "]") if $refresh_lists then RebuildAllListViews() endfunc func RefreshBatchLists() PopulateBatchList() RebuildAllListViews() endfunc func SwitchToBatch($batch_name) $current_batch = $batch_name PopulateBatchList() SwitchCurrentBatch(true) endfunc func EditMainList() EditCommandList($main_commands) endfunc func EditSetupList() EditCommandList($setup_commands) endfunc func EditPostList() EditCommandList($post_commands) endfunc ; ; UpdateMoveMenuState() ; Selects the right-clicked row and enables the moves valid for its position. ; func UpdateMoveMenuState($window_handle, $message_id, $control_handle, $mouse_position) #forceref $window_handle, $message_id, $control_handle, $mouse_position local $list_view, $menu_up, $menu_down switch GUICtrlRead($tab_control) case 0 $list_view = $list_main $menu_up = $menu_move_main_up $menu_down = $menu_move_main_down case 1 $list_view = $list_setup $menu_up = $menu_move_setup_up $menu_down = $menu_move_setup_down case 2 $list_view = $list_post $menu_up = $menu_move_post_up $menu_down = $menu_move_post_down case else return $GUI_RUNDEFMSG endswitch GUICtrlSetState($menu_up, $GUI_DISABLE) GUICtrlSetState($menu_down, $GUI_DISABLE) local $hit_test = _GUICtrlListView_HitTest(GUICtrlGetHandle($list_view)) if not IsArray($hit_test) or $hit_test[0] < 0 then return $GUI_RUNDEFMSG local $row_index = $hit_test[0] _GUICtrlListView_SetItemSelected($list_view, -1, false) _GUICtrlListView_SetItemSelected($list_view, $row_index, true, true) if $row_index > 0 then GUICtrlSetState($menu_up, $GUI_ENABLE) if $row_index < _GUICtrlListView_GetItemCount($list_view) - 1 then GUICtrlSetState($menu_down, $GUI_ENABLE) return $GUI_RUNDEFMSG endfunc ; ; MoveContextCommand() ; Moves selected commands from a main-window context menu. ; func MoveContextCommand() switch @GUI_CtrlId case $menu_move_main_up MoveListCommands($list_main, $main_commands, -1) case $menu_move_main_down MoveListCommands($list_main, $main_commands, 1) case $menu_move_setup_up MoveListCommands($list_setup, $setup_commands, -1) case $menu_move_setup_down MoveListCommands($list_setup, $setup_commands, 1) case $menu_move_post_up MoveListCommands($list_post, $post_commands, -1) case $menu_move_post_down MoveListCommands($list_post, $post_commands, 1) endswitch endfunc ; ; MoveListCommands() ; Moves selected commands and saves their new INI order. ; func MoveListCommands(byref $list_view, byref $command_array, $direction) local $selected_indices = _GUICtrlListView_GetSelectedIndices($list_view, true) if not $selected_indices[0] then return false if $direction < 0 and $selected_indices[1] = 0 then return false if $direction > 0 and $selected_indices[$selected_indices[0]] = $command_array[0][0] - 1 then return false local $command_count = $command_array[0][0] local $key_list[$command_count + 1], $original_keys[$command_count + 1], $command_list[$command_count + 1] $key_list[0] = $command_count $original_keys[0] = $command_count $command_list[0] = $command_count for $item_index = 1 to $command_count $key_list[$item_index] = $command_array[$item_index][0] $original_keys[$item_index] = $command_array[$item_index][0] $command_list[$item_index] = $command_array[$item_index][1] next if $direction < 0 then MoveSelectedCommandsUp($main_window, $list_view, $key_list, false) MoveSelectedCommandsUp($main_window, $list_view, $command_list, false) else MoveSelectedCommandsDown($main_window, $list_view, $key_list, false) MoveSelectedCommandsDown($main_window, $list_view, $command_list, false) endif for $item_index = 1 to $original_keys[0] IniDelete($ini_path, $current_batch, $original_keys[$item_index]) next for $item_index = 1 to $key_list[0] IniWrite($ini_path, $current_batch, $key_list[$item_index], MakePathRelative($command_list[$item_index])) next RefreshBatchLists() for $selection_index = 1 to $selected_indices[0] ControlListView($main_window, "", $list_view, "Select", $selected_indices[$selection_index] + $direction) next return true endfunc ; ; EditCommandList() ; Opens a command list editor. ; func EditCommandList($command_array) local $split_columns = TwoD22OneDArrays($command_array) if not IsArray($split_columns) then return false $needs_sort = false local $saved_event_mode = AutoItSetOption("GUIOnEventMode", 0) local $saved_coord_mode = AutoItSetOption("GUICoordMode", 1) LockAppWindow($main_window) local $key_list = $split_columns[0] local $original_keys = $key_list local $command_list = $split_columns[1] local $dialog_x = $window_x + 10 local $dialog_y = $window_y + 30 local $dialog_width = $window_width - 48 local $dialog_height = 75 + (24 * $command_list[0]) if $dialog_height > (@DesktopHeight - $dialog_y - 24) then $dialog_height = @DesktopHeight - $dialog_y - 24 local $editor_window = GUICreate(" Edit The Task List..", $dialog_width, $dialog_height, $dialog_x, $dialog_y, BitOR($WS_CAPTION, $WS_SIZEBOX), $WS_EX_TOOLWINDOW, $main_window) local $editor_list = GUICtrlCreateListView("Tasks..", 5, 5, $dialog_width - 5, $dialog_height - 38, BitOR($LVS_REPORT, 0)) GUICtrlSetResizing(-1, $GUI_DOCKAUTO + $GUI_DOCKSTATEBAR + $GUI_DOCKTOP + $GUI_DOCKLEFT) local $list_height = _GUICtrlListView_ApproximateViewHeight($editor_list) _WinAPI_SetWindowPos(GUICtrlGetHandle($editor_list), 0, $dialog_x, $dialog_y, $dialog_width, $list_height + 64, 4) RebuildCommandListView($editor_window, $editor_list, $command_list) local $button_y = $dialog_height - 25 local $button_up = GUICtrlCreateButton("&UP", 5, $button_y, 44, 22) local $button_down = GUICtrlCreateButton("&DOWN", 48, $button_y, 44, 22) local $button_delete = GUICtrlCreateButton("Del&ete", 100, $button_y, 44, 22) local $button_sort = GUICtrlCreateButton("So&rt", 150, $button_y, 44, 22) local $button_cancel = GUICtrlCreateButton("&Cancel", $dialog_width - 105, $button_y, 50, 22) local $button_save = GUICtrlCreateButton("&Save", $dialog_width - 45, $button_y, 44, 22) for $index = $button_up to $button_sort GUICtrlSetResizing($index, $GUI_DOCKSIZE + $GUI_DOCKLEFT + $GUI_DOCKBOTTOM) next for $index = $button_cancel to $button_save GUICtrlSetResizing($index, $GUI_DOCKSIZE + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM) next if $show_tips = $ON then GUICtrlSetTip($button_up, " Move the selcted command(s) UP. ") GUICtrlSetTip($button_down, " Move the selcted command(s) DOWN. ") GUICtrlSetTip($button_delete, " Delete the selected command(s) from the list. ") GUICtrlSetTip($button_sort, " Sort the list (click again to reverse-sort). ") GUICtrlSetTip($button_cancel, " Close this window and don't save any changes. ") GUICtrlSetTip($button_save, " Save any changes and close this window. ") endif GUISetState() _GUICtrlListView_SetColumnWidth($editor_list, 0, $LVSCW_AUTOSIZE_USEHEADER) local $gui_message while 1 $gui_message = GUIGetMsg() switch $gui_message case $GUI_EVENT_CLOSE, $button_cancel exitloop case $button_up MoveSelectedCommandsUp($editor_window, $editor_list, $key_list, false) MoveSelectedCommandsUp($editor_window, $editor_list, $command_list) case $button_down MoveSelectedCommandsDown($editor_window, $editor_list, $key_list, false) MoveSelectedCommandsDown($editor_window, $editor_list, $command_list) case $button_delete DeleteSelectedCommands($editor_window, $editor_list, $command_list, $key_list) case $button_sort SortCommandArrays($editor_window, $editor_list, $command_list, $key_list) case $button_save for $index = 1 to $original_keys[0] IniDelete($ini_path, $current_batch, $original_keys[$index]) next for $index = 1 to $key_list[0] IniWrite($ini_path, $current_batch, $key_list[$index], MakePathRelative($command_list[$index])) next RefreshBatchLists() exitloop endswitch Sleep(5) wend GUIDelete($editor_window) AutoItSetOption("GUICoordMode", $saved_coord_mode) AutoItSetOption("GUIOnEventMode", $saved_event_mode) UnlockAppWindow($main_window) endfunc ; ; MakePathRelative() ; Shortens a path relative to the script folder. Mirror of override:refined-dice match in Includes\Schedules.au3. ; func MakePathRelative($file_path) if $portable_paths = $OFF then return $file_path if StringInStr($file_path, @ScriptDir) then $file_path = StringReplace($file_path, @ScriptDir & "\", ".\", 1, 0) endif return $file_path endfunc ; ; RebuildCommandListView() ; Rebuilds a command list view from its array. ; func RebuildCommandListView($parent_window, byref $list_view, byref $command_items) if not IsArray($command_items) then return false _GUICtrlListView_DeleteAllItems($list_view) for $item_index = 1 to $command_items[0] if $command_items[$item_index] then GUICtrlCreateListViewItem($command_items[$item_index], $list_view) endif next GUICtrlSendMsg($list_view, $LVM_SETCOLUMNWIDTH, 0, $LVSCW_AUTOSIZE_USEHEADER) ControlFocus($parent_window, "", $list_view) endfunc ; ; SortCommandArrays() ; Sorts the command arrays, keeping rows aligned. ; func SortCommandArrays(byref $parent_window, byref $list_view, byref $key_array, byref $value_array) local $sorted_pair if $needs_sort then $sorted_pair = BubbleSortParallelArrays($key_array, $value_array) $key_array = $sorted_pair[0] $value_array = $sorted_pair[1] _ArrayReverse($key_array, 1) _ArrayReverse($value_array, 1) $needs_sort = false else $sorted_pair = BubbleSortParallelArrays($key_array, $value_array) $key_array = $sorted_pair[0] $value_array = $sorted_pair[1] $needs_sort = true endif RebuildCommandListView($parent_window, $list_view, $key_array) endfunc ; ; BubbleSortParallelArrays() ; Bubble-sorts two parallel arrays together. ; func BubbleSortParallelArrays(byref $key_list, byref $value_list) local $saved_key, $saved_value for $pass_index = UBound($key_list) - 1 to 1 step -1 for $compare_index = 2 to $pass_index if $key_list[$compare_index - 1] > $key_list[$compare_index] then $saved_key = $key_list[$compare_index - 1] $saved_value = $value_list[$compare_index - 1] $key_list[$compare_index - 1] = $key_list[$compare_index] $value_list[$compare_index - 1] = $value_list[$compare_index] $key_list[$compare_index] = $saved_key $value_list[$compare_index] = $saved_value endif next next local $swap_temp[2] = [$key_list, $value_list] return $swap_temp endfunc ; ; MoveSelectedCommandsUp() ; Moves selected commands one row up. ; func MoveSelectedCommandsUp(byref $parent_window, byref $list_view, byref $item_array, $redraw_list = true) if not IsArray($item_array) then return false local $selected_text = ControlListView($parent_window, "", $list_view, "GetSelected", 1) local $selected_parts = StringSplit($selected_text, "|") for $part_index = 1 to $selected_parts[0] local $selected_index = $selected_parts[$part_index] local $moved_value = $item_array[$selected_index + 1] if $selected_index > 0 then _ArrayDelete($item_array, $selected_index + 1) _ArrayInsert($item_array, $selected_index, $moved_value) endif next if $redraw_list then RebuildCommandListView($parent_window, $list_view, $item_array) for $part_index = 1 to $selected_parts[0] local $reselect_index = $selected_parts[$part_index] - 1 if $reselect_index = -1 then $reselect_index = 0 ControlListView($parent_window, "", $list_view, "Select", $reselect_index) next endif endfunc ; ; MoveSelectedCommandsDown() ; Moves selected commands one row down. ; func MoveSelectedCommandsDown(byref $parent_window, byref $list_view, byref $item_array, $redraw_list = true) if not IsArray($item_array) then return false local $selected_text = ControlListView($parent_window, "", $list_view, "GetSelected", 1) local $selected_parts = StringSplit($selected_text, "|") local $moved_value for $part_index = $selected_parts[0] to 1 step -1 local $selected_index = $selected_parts[$part_index] if $selected_index >= $item_array[0] - 1 then continueloop $moved_value = $item_array[$selected_index + 1] _ArrayDelete($item_array, $selected_index + 1) local $insert_position = $selected_index + 2 if $insert_position >= UBound($item_array) then _ArrayAdd($item_array, $moved_value) else _ArrayInsert($item_array, $insert_position, $moved_value) endif next if $redraw_list then RebuildCommandListView($parent_window, $list_view, $item_array) for $part_index = $selected_parts[0] to 1 step -1 local $reselect_index = $selected_parts[$part_index] + 1 if $reselect_index >= $item_array[0] then $reselect_index = $item_array[0] - 1 ControlListView($parent_window, "", $list_view, "Select", $reselect_index) next endif endfunc ; ; DeleteSelectedCommands() ; Deletes the selected commands from both arrays. ; func DeleteSelectedCommands(byref $parent_window, byref $list_view, byref $key_list, byref $command_list) if not IsArray($key_list) then return false local $selected_text = ControlListView($parent_window, "", $list_view, "GetSelected", 1) local $selected_parts = StringSplit($selected_text, "|") for $part_index = $selected_parts[0] to 1 step -1 _ArrayDelete($key_list, $selected_parts[$part_index] + 1) _ArrayDelete($command_list, $selected_parts[$part_index] + 1) if IsArray($key_list) then $key_list[0] -= 1 if IsArray($command_list) then $command_list[0] -= 1 next RebuildCommandListView($parent_window, $list_view, $key_list) endfunc ; ; FlashWindowTitle() ; Flashes a status suffix in the window title. ; func FlashWindowTitle($title_suffix, $display_ms = 3000) WinSetTitle($main_window, "", $app_name & " [" & $current_batch & "]" & $title_suffix) AdlibUnRegister("RestoreWindowTitle") AdlibUnRegister("UpdateStatusTicker") AdlibRegister("RestoreWindowTitle", $display_ms) endfunc ; ; RestoreWindowTitle() ; Restores the plain window title. ; func RestoreWindowTitle() WinSetTitle($main_window, "", $app_name & " [" & $current_batch & "]") AdlibUnRegister("RestoreWindowTitle") endfunc ; ; UpdateStatusTicker() ; Updates the status title every second. ; func UpdateStatusTicker() if $gui_active then AdlibUnRegister("UpdateStatusTicker") AdlibRegister("UpdateStatusTicker", 1000) AdlibUnRegister("RestoreWindowTitle") local $run_status = "running" local $elapsed_text if $batch_paused > 0 then $run_status = "PAUSED" if $abort_state > 0 then $run_status = "ABORTING" if $show_elapsed = $ON then $elapsed_text = "[time: " & FormatElapsedMs(TimerDiff($batch_start_time) - $paused_elapsed) & "]" WinSetTitle($main_window, "", $app_name & " [" & $current_batch & "][" & $run_status & "]" & $elapsed_text) endif endfunc ; ; TogglePauseBatch() ; Toggles pause and resume. ; func TogglePauseBatch() if $batch_paused == 1 then ResumeBatchRun() else PauseBatchRun() endif endfunc ; ; PauseBatchRun() ; Pauses the running batch. ; func PauseBatchRun() $batch_paused = 1 TrayItemSetText($tray_run_item, "Resume Batch Run (Pause/Break)") SetWindowOnTop(0) TraySetToolTip(" Batch Runner.. [" & $current_batch & "][PAUSED] Right-click for the menu. ") TraySetState(8) endfunc ; ; ResumeBatchRun() ; Resumes the paused batch. ; func ResumeBatchRun() $batch_paused = 0 BuildRunTrayMenu() SetWindowOnTop(1) endfunc ; ; AbortBatchRun() ; Aborts the running batch. ; func AbortBatchRun() $abort_state = 2 TraySetToolTip(" Batch Runner.. [" & $current_batch & "][ABORTING] ") local $elapsed_text if $show_elapsed = $ON then $elapsed_text = "[time: " & FormatElapsedMs(TimerDiff($batch_start_time) - $paused_elapsed) & "]" WinSetTitle($main_window, "", $app_name & " [" & $current_batch & "][ABORTING]" & $elapsed_text) AdlibUnRegister("RestoreWindowTitle") endfunc ; ; ScheduleHourlyTimer() ; Re-arms the hourly background timer. ; func ScheduleHourlyTimer() AdlibUnRegister("ScheduleHourlyTimer") AdlibRegister("ScheduleHourlyTimer", 1000 * 60 * 60) endfunc ; ; BuildTrayMenu() ; Builds the tray menu. ; func BuildTrayMenu($disable_log_item = false) ClearTrayMenu() TraySetToolTip(" Click to toggle Batch Runner " & $MSG_LF & " Right-click for the menu. ") TrayCreateItem("Run the batch (Enter)") TrayItemSetOnEvent(-1, "ScheduleBatchRun") TrayCreateItem("") $tray_view_log = TrayCreateItem("View the Log.. (Ctrl+L)") TrayItemSetOnEvent(-1, "OpenLogInEditor") if $disable_log_item then TrayItemSetState(-1, $TRAY_DISABLE) TrayCreateItem("Edit Preferences.. (Ctrl+P)") TrayItemSetOnEvent(-1, "EditPreferencesFile") TrayCreateItem("") $tray_about_item = TrayCreateItem("About Batch Runner.. (Win+Alt+A)") TrayItemSetOnEvent(-1, "ShowAboutDialog") TrayCreateItem("") TrayCreateItem("Hard Exit") TrayItemSetOnEvent(-1, "ExitWithFailure") TraySetClick(8) TraySetState(8) endfunc ; ; BuildRunTrayMenu() ; Builds the run-mode tray menu. ; func BuildRunTrayMenu() ClearTrayMenu() TraySetToolTip(" Batch Runner.. Right-click for the menu. ") $tray_run_item = TrayCreateItem("Pause Batch Run (Pause/Break)") TrayItemSetOnEvent(-1, "TogglePauseBatch") TrayCreateItem("Abort Batch Run (Numpad -)") TrayItemSetOnEvent(-1, "AbortBatchRun") TrayCreateItem("") $tray_view_log = TrayCreateItem("View the Log.. (Ctrl+L)") TrayItemSetOnEvent(-1, "OpenLogInEditor") if not $log_available then TrayItemSetState(-1, $TRAY_DISABLE) TrayCreateItem("Edit Preferences.. (Ctrl+P)") TrayItemSetOnEvent(-1, "EditPreferencesFile") TrayCreateItem("") $tray_about_item = TrayCreateItem("About Batch Runner..") TrayItemSetOnEvent(-1, "ShowAboutDialog") TrayCreateItem("") TrayCreateItem("Hard Exit") TrayItemSetOnEvent(-1, "ExitWithFailure") TraySetClick(8) TraySetState(4) endfunc ; ; ClearTrayMenu() ; Removes all tray menu items. ; func ClearTrayMenu() for $item_index = 0 to 24 TrayItemDelete($item_index) next endfunc ; ; SetRunUiState() ; Switches the window between idle and running state. ; func SetRunUiState($is_idle = false) if $is_idle then UnbindSecondaryHotkeys() RegisterHotKeys() $batch_running = false SetWindowOnTop(0) else UnbindPrimaryHotkeys() BindSecondaryHotkeys() $batch_running = true SetWindowOnTop(1) endif for $control_id = $button_add_main to $button_run_batch if $is_idle then GUICtrlSetState($control_id, $GUI_ENABLE) else GUICtrlSetState($control_id, $GUI_DISABLE) endif next if $is_idle then GUICtrlSetState($button_abort, $GUI_DISABLE + $GUI_HIDE) GUICtrlSetState($button_countdown, $GUI_DISABLE + $GUI_HIDE) GUICtrlSetState($button_run_batch, $GUI_ENABLE + $GUI_SHOW) else GUICtrlSetState($button_countdown, $GUI_DISABLE + $GUI_HIDE) GUICtrlSetState($button_run_batch, $GUI_DISABLE + $GUI_HIDE) GUICtrlSetState($button_abort, $GUI_ENABLE + $GUI_SHOW) endif GUICtrlSetState($list_setup, $GUI_ENABLE) GUICtrlSetState($list_post, $GUI_ENABLE) endfunc ; LockAppWindow() ; Disables the main window while a dialog runs. ; func LockAppWindow($window_handle) GUISetState(@SW_DISABLE, $window_handle) TraySetState(2) UnbindPrimaryHotkeys() endfunc ; ; UnlockAppWindow() ; Re-enables the main window after a dialog. ; func UnlockAppWindow($window_handle) TraySetState(1) GUISetState(@SW_ENABLE, $window_handle) GUISwitch($window_handle) WinActivate($window_handle) RegisterHotKeys() endfunc ; ; HideWindowOnMinimize() ; Hides the window to the tray on minimize. ; func HideWindowOnMinimize() ToggleMainWindowVisibility() return false endfunc ; ; ActivateExistingInstance() ; Restores and activates an existing Batch Runner window. ; func ActivateExistingInstance() local $existing_window = WinGetHandle($app_name) if not $existing_window then return false WinSetState($existing_window, "", @SW_SHOW) WinSetState($existing_window, "", @SW_RESTORE) WinActivate($existing_window) return true endfunc ; ; ToggleMainWindow() ; Toggles the main window from the tray. ; func ToggleMainWindow() ToggleMainWindowVisibility() endfunc ; ; ToggleMainWindowVisibility() ; Shows or hides the main window, preserving state. ; func ToggleMainWindowVisibility($preserve_hotkeys = 0) if not $gui_active then return 0 if WinVisible($main_window) then if $batch_running then UnbindSecondaryHotkeys() else if not $preserve_hotkeys then UnbindPrimaryHotkeys() endif GUISetState(@SW_HIDE, $main_window) else if $batch_running then BindSecondaryHotkeys() else if not $preserve_hotkeys then RegisterHotKeys() endif GUISetState(@SW_SHOW, $main_window) WinActivate($main_window) endif endfunc ; ; SetWindowOnTop() ; Sets the always-on-top flag. ; func SetWindowOnTop($on_top_flag = 1) if $gui_active and $run_on_top = $ON then WinSetOnTop($main_window, "", $on_top_flag) endfunc ; ; HandleWindowResize() ; Enforces size limits and refreshes columns on resize. ; func HandleWindowResize() SaveWindowPosition() SaveColumnLayout() AutosizeListColumns() endfunc ; ; SaveWindowPosition() func SaveWindowPosition() if not $gui_active then return local $window_pos = WinGetPos($main_window) if not IsArray($window_pos) then return 0 if $window_pos[2] < $min_width then WinMove($main_window, "", default, default, $min_width) if $window_pos[3] < $min_height then WinMove($main_window, "", default, default, default, $min_height) if $window_x <> -1 and $window_x < 0 or $window_x > @DesktopWidth - 25 then $window_x = 30 IniWrite($ini_path, $app_name, "x", $window_x) WinMove($app_name, "", $window_x, default) endif if $window_y <> -1 and $window_y < 0 or $window_y > @DesktopHeight - 25 then $window_y = 30 IniWrite($ini_path, $app_name, "y", $window_y) WinMove($app_name, "", default, $window_y) endif endfunc ; ; SetColumnAlignment() ; Sets one column alignment. ; func SetColumnAlignment($list_view, $column_index, $align_mode = -1) local $align_options[3] = [$LVCFMT_LEFT, $LVCFMT_RIGHT, $LVCFMT_CENTER] local $is_unicode = _GUICtrlListView_GetUnicodeFormat($list_view) local $column_struct = DllStructCreate($tagLVCOLUMN) if $align_mode < 0 or $align_mode > 2 then $align_mode = 0 local $field_mask = $LVCF_FMT local $column_format = $align_options[$align_mode] DllStructSetData($column_struct, "Mask", $field_mask) DllStructSetData($column_struct, "Fmt", $column_format) local $api_result if IsHWnd($list_view) then if _WinAPI_InProcess($list_view, $scratch_result) then $api_result = _SendMessage($list_view, $LVM_SETCOLUMNW, $column_index, $column_struct, 0, "wparam", "struct*") else local $struct_size = DllStructGetSize($column_struct) local $memory_block local $remote_address = _MemInit($list_view, $struct_size, $memory_block) _MemWrite($memory_block, $column_struct, $remote_address, $struct_size) if $is_unicode then $api_result = _SendMessage($list_view, $LVM_SETCOLUMNW, $column_index, $remote_address, 0, "wparam", "ptr") else $api_result = _SendMessage($list_view, $LVM_SETCOLUMNA, $column_index, $remote_address, 0, "wparam", "ptr") endif _MemFree($memory_block) endif else local $struct_ptr = DllStructGetPtr($column_struct) if $is_unicode then $api_result = GUICtrlSendMsg($list_view, $LVM_SETCOLUMNW, $column_index, $struct_ptr) else $api_result = GUICtrlSendMsg($list_view, $LVM_SETCOLUMNA, $column_index, $struct_ptr) endif endif return $api_result <> 0 endfunc ; ; AutosizeListColumns() ; Autosizes the list view columns. Mirror of override:refined-dice match in GuiListBox.au3. ; func AutosizeListColumns($force_resize = false) _GUICtrlListView_SetColumnWidth($list_setup, 0, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($list_post, 0, $LVSCW_AUTOSIZE_USEHEADER) if $autosize_columns = $ON or $force_resize then local $client_size = WinGetClientSize($main_window) _GUICtrlListView_SetColumnWidth($list_main, 0, $client_size[0] - $counter_width) _GUICtrlListView_SetColumnWidth($list_main, 1, $LVSCW_AUTOSIZE_USEHEADER) local $count_column_width = _GUICtrlListView_GetColumnWidth($list_main, 1) _GUICtrlListView_SetColumnWidth($list_main, 0, $client_size[0] - $count_column_width - 10) endif endfunc ; ; SaveColumnLayout() func SaveColumnLayout() if not $gui_active then return local $saved_order = _GUICtrlListView_GetColumnOrder($list_main) if $saved_order <> $column_order then $column_order = $saved_order IniWrite($ini_path, $app_name, "column_order", $column_order) endif SaveWindowPosition() local $window_rect = WinGetPos($main_window) if not IsArray($window_rect) then return 0 $window_x = $window_rect[0] $window_y = $window_rect[1] $window_width = $window_rect[2] $window_height = $window_rect[3] IniWrite($ini_path, $app_name, "x", $window_x) IniWrite($ini_path, $app_name, "y", $window_y) local $client_size = WinGetClientSize($main_window) if not IsArray($client_size) then return 0 IniWrite($ini_path, $app_name, "width", $client_size[0]) IniWrite($ini_path, $app_name, "height", $client_size[1]) if $autosize_columns = $OFF then local $cycle_width = _GUICtrlListView_GetColumnWidth($list_main, 1) if $cycle_width < $window_width then IniWrite($ini_path, $app_name, "cycle_width", $cycle_width) endif endfunc ; ; SaveWinPos() ; Saves dialog geometry. ; func SaveWinPos($window_handle, $x_key, $y_key = "", $width_key = "", $height_key = "") if not $gui_active then return local $window_rect = WinGetPos($window_handle) if not IsArray($window_rect) then return 0 if $x_key and $window_rect[0] >= 0 and $window_rect[0] < (@DesktopWidth - 25) then IniWrite($ini_path, $app_name, $x_key, $window_rect[0]) if $y_key and $window_rect[1] >= 0 and $window_rect[1] < (@DesktopHeight - 25) then IniWrite($ini_path, $app_name, $y_key, $window_rect[1]) $window_rect = WinGetClientSize($window_handle) if not IsArray($window_rect) then return 0 if $width_key and $window_rect[0] >= 100 and $window_rect[0] <= (@DesktopWidth) then IniWrite($ini_path, $app_name, $width_key, $window_rect[0]) if $height_key and $window_rect[1] >= 64 and $window_rect[1] <= (@DesktopHeight) then IniWrite($ini_path, $app_name, $height_key, $window_rect[1]) endfunc ; ; ListViewHandleForTab() ; Performs one application task. Mirror of override:refined-dice match in Includes\corz_essentials.au3. ; func ListViewHandleForTab($tab_index) switch $tab_index case 0 return $list_main case 1 return $list_setup case 2 return $list_post endswitch endfunc ; ; ArmHeartbeatTimer() ; Arms the log heartbeat timer. ; func ArmHeartbeatTimer() $pending_heartbeat_dots = 0 AdlibUnRegister("WriteLogHeartbeat") AdlibRegister("WriteLogHeartbeat", 1000 * 60 * $opt_log_update_minutes) endfunc ; ; TrimHeartbeatDots() ; Trims heartbeat dots from the log. ; func TrimHeartbeatDots() AdlibUnRegister("WriteLogHeartbeat") FileFlush($log_handle) if $pending_heartbeat_dots then FileSetPos($log_handle, 0 - $pending_heartbeat_dots, 2) endfunc ; ; WriteLogHeartbeat() ; Writes one log heartbeat dot. ; func WriteLogHeartbeat() AppendLogLine(".") $pending_heartbeat_dots += 1 endfunc ; ; OpenLogForRun() ; Opens the log file for a run. ; func OpenLogForRun() $log_handle = false LoadLogSettings($current_batch) if not $log_path then return false local $new_log_file if not FileExists($log_path) then $new_log_file = true else if FileGetSize($log_path) = 0 then $new_log_file = true endif $log_handle = FileOpen($log_path, 1 + 8 + $log_file_encoding) if $new_log_file then AppendLogLine("Batch Runner log.. " & $LF, $timestamp_all_lines) AppendLogLine($LF, $timestamp_all_lines) AppendLogLine($opt_log_separator & $LF, $timestamp_all_lines) else AppendLogLine($LF, $timestamp_all_lines) AppendLogLine($opt_log_separator & $LF, $timestamp_all_lines) endif TrayItemSetState($tray_view_log, $TRAY_ENABLE) endfunc ; ; CloseLogFile() ; Closes the log file and compacts it. ; func CloseLogFile() if not $log_path then return false FileClose($log_handle) CompactLogFolder() endfunc ; ; AppendLogLine() ; Appends one line to the log file. ; func AppendLogLine($log_line, $add_timestamp = false) if not $log_path then return false if $log_handle and not FileExists($log_path) then local $warning_text = "*** PREVIOUS LOG FILE DELETED!!! ***" FileClose($log_handle) $log_handle = FileOpen($log_path, 1 + $log_file_encoding) if $opt_timestamp_logs = $OFF then FileWrite($log_handle, $warning_text & $LF) if not StringInStr($last_log_line, $LF) then FileWrite($log_handle, $last_log_line) else FileWrite($log_handle, TimestampString() & $opt_timestamp_delimiter & $warning_text & $LF) if not StringInStr($last_log_line, $LF) then FileWrite($log_handle, TimestampString() & $opt_timestamp_delimiter & $last_log_line) endif endif if not $add_timestamp or $opt_timestamp_logs = $OFF then FileWrite($log_handle, $log_line) else FileWrite($log_handle, TimestampString() & $opt_timestamp_delimiter & $log_line) endif $last_log_line = $log_line endfunc ; ; ResolveLogPath() ; Resolves the log file path for writing. ; func ResolveLogPath($log_location, $default_name = "Batch Runner.log") if not $log_location then return false $log_location = ExpandRunMacros($log_location) if StringInStr($log_location, "/") then $log_location = StringReplace($log_location, "/", "\") if StringMid($log_location, 2, 2) <> ":\" then $log_location = @ScriptDir & "\" & $log_location endif if IsDir($log_location) then if StringRight($log_location, 1) = "\" then $log_location = StringTrimRight($log_location, 1) $log_location &= "\" & $default_name endif return $log_location endfunc ; ; CompactLogFolder() ; NTFS-compresses the log folder. ; func CompactLogFolder() if $opt_compress_logs = $OFF then return false local $log_folder = GetLongParent($log_path) if not StringInStr(FileGetAttrib($log_folder), "C") then if $log_folder <> @ScriptDir then Run(@ComSpec & " /c " & 'compact.exe /C "' & $log_folder & '"', "", @SW_HIDE) endif Run(@ComSpec & " /c " & 'compact.exe /C "' & $log_folder & "\*.log", "", @SW_HIDE) endif endfunc ; ; LoadPreferences() ; Loads preferences and window state from the ini file. ; func LoadPreferences() $current_batch = IniRead($ini_path, $app_name, "current_batch", "") $batch_names = ListBatchNames() $window_x = IniRead($ini_path, $app_name, "x", -1) $window_y = IniRead($ini_path, $app_name, "y", -1) $window_width = IniRead($ini_path, $app_name, "width", 484) $window_height = IniRead($ini_path, $app_name, "height", 206) $min_width = IniRead($ini_path, $app_name, "min_width", 410) $min_height = IniRead($ini_path, $app_name, "min_height", 128) $autosize_columns = IniReadCheckBox($ini_path, $app_name, "autosize_columns", $ON) $counter_width = IniRead($ini_path, $app_name, "counter_width", false) if not $counter_width then $counter_width = 80 $default_input_x = 30 $default_input_y = 241 $default_input_width = 484 $input_x = IniRead($ini_path, $app_name, "input_x", $default_input_x) $input_y = IniRead($ini_path, $app_name, "input_y", $default_input_y) $input_width = IniRead($ini_path, $app_name, "input_width", $default_input_width) $show_tips = IniReadCheckBox($ini_path, $app_name, "show_tips", $ON) $hover_to_show = IniReadCheckBox($ini_path, $app_name, "hover_to_show", $ON) $hover_sensitivity = Abs(Int(IniRead($ini_path, $app_name, "hover_sensitivity", 8))) $tab_name_main = IniRead($ini_path, $app_name, "main_name", "Main Batch") $tab_name_setup = IniRead($ini_path, $app_name, "pre_name", "Setup") $tab_name_post = IniRead($ini_path, $app_name, "post_name", "Wrap-Up") $allowed_extensions = IniRead($ini_path, $app_name, "allowed_exes", "exe") $allowed_extension_list = StringSplit($allowed_extensions, ",") $garbage_collector = IniRead($ini_path, $app_name, "garbage_collector", "hourly") $allow_empty_batch = IniReadCheckBox($ini_path, $app_name, "allow_empty_batch", $OFF) $column_name_commands = IniRead($ini_path, $app_name, "cmd_col_name", "Commands") $column_name_count = IniRead($ini_path, $app_name, "cnt_col_name", "Fail/Cycles") $column_order = IniRead($ini_path, $app_name, "column_order", "0|1") $counter_align = IniRead($ini_path, $app_name, "counter_align", "left") $warn_delete_batch = IniReadCheckBox($ini_path, $app_name, "warn_delete_batch", $ON) $warn_delete_command = IniReadCheckBox($ini_path, $app_name, "warn_delete_command", $ON) $sort_batch_list = IniReadCheckBox($ini_path, $app_name, "sort_batch_list", $ON) $show_randomize = IniReadCheckBox($ini_path, $app_name, "enable_randomize", $OFF) $show_batch_row = IniReadCheckBox($ini_path, $app_name, "show_batch_controls", $ON) $run_on_top = IniReadCheckBox($ini_path, $app_name, "run_on_top", $OFF) $show_elapsed = IniReadCheckBox($ini_path, $app_name, "time_in_title", $ON) $auto_name_tasks = IniReadCheckBox($ini_path, $app_name, "auto_name_tasks", $OFF) $portable_paths = IniReadCheckBox($ini_path, $app_name, "portable_paths", $ON) $exit_code_token = IniRead($ini_path, $app_name, "exit_token", "@exitcode") if not $exit_code_token then $exit_code_token = "@exitcode" $hotkey_add = IniRead($ini_path, $app_name, "userkey_add", "{NUMPADADD}") $hotkey_delete = IniRead($ini_path, $app_name, "userkey_del", "^{Del}") $hotkey_run = IniRead($ini_path, $app_name, "userkey_run", "^{enter}") $hotkey_pause = IniRead($ini_path, $app_name, "userkey_pause", "{pause}") $hotkey_abort = IniRead($ini_path, $app_name, "userkey_abort", "{NUMPADSUB}") $list_font = IniReadCheckBox($ini_path, $app_name, "task_list_font", false) $batch_font = IniReadCheckBox($ini_path, $app_name, "batches_font", false) $list_font_size = IniReadCheckBox($ini_path, $app_name, "task_list_font_size", 9) $batch_font_size = IniReadCheckBox($ini_path, $app_name, "batches_font_size", 9) if not IsNumber($list_font_size) then $list_font_size = 9 if not IsNumber($batch_font_size) then $batch_font_size = 9 LoadColorSettings() LoadLogSettings($current_batch) LoadBatchRunOptions($current_batch, false) if not @Compiled then BuildPreferencesDialog() endfunc ; ; LoadLogSettings() ; Loads the logging settings. ; func LoadLogSettings($section_name) $log_path = IniReadPrefLayers($ini_path, $app_name, $section_name, "log_path", "") if $log_path = "" then $log_path = false $log_path = ResolveLogPath($log_path) if not $log_path then return false $opt_utf8_log = IniReadPrefLayers($ini_path, $app_name, $section_name, "utf8_log", $OFF, 1) if $opt_utf8_log = $ON then $log_file_encoding = 256 local $use_bom = IniReadPrefLayers($ini_path, $app_name, $section_name, "uft8_bom", $OFF, 1) if $use_bom = $ON then $log_file_encoding = 128 endif $LF = @CRLF local $line_feed_style = IniReadPrefLayers($ini_path, $app_name, $section_name, "log_line_feed", "CRLF") if $line_feed_style == "LF" or $line_feed_style == "lf" then $LF = @LF if $line_feed_style == "CR" or $line_feed_style == "cr" then $LF = @CR $opt_timestamp_logs = IniReadPrefLayers($ini_path, $app_name, $section_name, "timestamp_logs", $OFF, 1) $opt_timestamp_everything = IniReadPrefLayers($ini_path, $app_name, $section_name, "timestamp_everything", $OFF, 1) $timestamp_all_lines = false if $opt_timestamp_everything = $ON then $timestamp_all_lines = true $opt_timestamp_delimiter = IniReadPrefLayers($ini_path, $app_name, $section_name, "timestamp_delimit", ",") $opt_date_delimiter = IniReadPrefLayers($ini_path, $app_name, $section_name, "date_delimit", ":") $opt_log_setup = IniReadPrefLayers($ini_path, $app_name, $section_name, "log_setup", $OFF, 1) $opt_log_options = IniReadPrefLayers($ini_path, $app_name, $section_name, "log_options", $ON, 1) $opt_log_log_options = IniReadPrefLayers($ini_path, $app_name, $section_name, "log_log_options", $ON, 1) $opt_log_summary = IniReadPrefLayers($ini_path, $app_name, $section_name, "log_summary", $ON, 1) $opt_log_separator = IniReadPrefLayers($ini_path, $app_name, $section_name, "log_separator", $SEPARATOR) $opt_log_separator = StringReplace($opt_log_separator, "\n", $LF) $opt_log_update_minutes = IniReadPrefLayers($ini_path, $app_name, $section_name, "log_update", 5) $opt_compress_logs = IniReadPrefLayers($ini_path, $app_name, $section_name, "compress_logs", $OFF, 1) endfunc ; ; LoadBatchRunOptions() ; Loads the per-batch run options. Mirror of override:refined-dice match in Array.au3. ; func LoadBatchRunOptions($section_name, $use_option_layers = true) $opt_select_all = IniReadPrefLayers($ini_path, $app_name, $section_name, "select_all", $ON, 1, $use_option_layers) $opt_ignore_selections = IniReadPrefLayers($ini_path, $app_name, $section_name, "ignore_selections", $OFF, 1, $use_option_layers) $opt_precision_seconds = IniReadPrefLayers($ini_path, $app_name, $section_name, "precision_seconds", $OFF, 1, $use_option_layers) $opt_success_msg = IniReadPrefLayers($ini_path, $app_name, $section_name, "success_msg", " (success)", 0, $use_option_layers) $opt_notify = IniReadPrefLayers($ini_path, $app_name, $section_name, "notify", $ON, 1, $use_option_layers) $opt_beep = IniReadPrefLayers($ini_path, $app_name, $section_name, "beep", $ON, 1, $use_option_layers) $opt_hide_running_tasks = IniReadPrefLayers($ini_path, $app_name, $section_name, "hide_running_tasks", $ON, 1, $use_option_layers) $opt_trace_file = IniReadPrefLayers($ini_path, $app_name, $section_name, "trace_file", "Batch Runner [" & $current_batch & "] Trace File.log", 0, $use_option_layers) $opt_trace_all_tasks = IniReadPrefLayers($ini_path, $app_name, $section_name, "trace_all_tasks", $OFF, 1) $opt_always_show_trace = IniReadPrefLayers($ini_path, $app_name, $section_name, "always_show_trace", $OFF, 1, $use_option_layers) $opt_halt_on_setup_fail = IniReadPrefLayers($ini_path, $app_name, $section_name, "halt_on_setup_fail", $ON, 1, $use_option_layers) $opt_halt_on_task_fail = IniReadPrefLayers($ini_path, $app_name, $section_name, "halt_on_task_fail", $ON, 1, $use_option_layers) $opt_halt_on_fail_range = IniReadPrefLayers($ini_path, $app_name, $section_name, "halt_on_fail_range", "-100,-1", 0, $use_option_layers) if StringInStr($opt_halt_on_fail_range, ",") then $fail_range_parts = StringSplit($opt_halt_on_fail_range, ",") endif if (0 + $fail_range_parts[1]) > -2 then $fail_range_parts[1] = -100 endif if (0 + $fail_range_parts[2]) < (0 + $fail_range_parts[1]) or (0 + $fail_range_parts[2]) > -1 then $fail_range_parts[2] = -1 endif $opt_cycle_batch = IniReadPrefLayers($ini_path, $app_name, $section_name, "cycle_main_batch", $OFF, 1, $use_option_layers) $opt_randomize = IniReadPrefLayers($ini_path, $app_name, $section_name, "randomize_batch", $OFF, 1, $use_option_layers) $opt_max_time = IniReadPrefLayers($ini_path, $app_name, $section_name, "max_batch_time", 60, 0, $use_option_layers) $opt_max_time = NormalizeCheckInterval($opt_max_time) endfunc ; ; LoadColorSettings() func LoadColorSettings() $reset_colors = IniReadCheckBox($ini_path, $app_name, "reset_colors", $ON) $default_color = IniRead($ini_path, $app_name, "color_default", "") if StringLeft($default_color, 1) = "#" then $default_color = StringTrimLeft($default_color, 1) if $default_color then if not StringIsXDigit($default_color) then $default_color = 16777215 else $default_color = "0x" & $default_color endif else $default_color = 16777215 endif $color_text = IniRead($ini_path, $app_name, "color_text", "") if StringLeft($color_text, 1) = "#" then $color_text = StringTrimLeft($color_text, 1) if $color_text then if not StringIsXDigit($color_text) then $color_text = 0 else $color_text = "0x" & $color_text endif else $color_text = 0 endif $color_running = IniRead($ini_path, $app_name, "color_running", "") if StringLeft($color_running, 1) = "#" then $color_running = StringTrimLeft($color_running, 1) if $color_running then if not StringIsXDigit($color_running) then $color_running = 8454143 else $color_running = "0x" & $color_running endif else $color_running = 8454143 endif $color_success = IniRead($ini_path, $app_name, "color_success", "") if StringLeft($color_success, 1) = "#" then $color_success = StringTrimLeft($color_success, 1) if $color_success then if not StringIsXDigit($color_success) then $color_success = 65280 else $color_success = "0x" & $color_success endif else $color_success = 65280 endif $color_fail = IniRead($ini_path, $app_name, "color_fail", "") if StringLeft($color_fail, 1) = "#" then $color_fail = StringTrimLeft($color_fail, 1) if $color_fail then if not StringIsXDigit($color_fail) then $color_fail = 16711680 else $color_fail = "0x" & $color_fail endif else $color_fail = 16711680 endif $color_multi_fail = IniRead($ini_path, $app_name, "color_multi_fail", "") if StringLeft($color_multi_fail, 1) = "#" then $color_multi_fail = StringTrimLeft($color_multi_fail, 1) if $color_multi_fail then if not StringIsXDigit($color_multi_fail) then $color_multi_fail = 12124665 else $color_multi_fail = "0x" & $color_multi_fail endif else $color_multi_fail = 12124665 endif $color_error = IniRead($ini_path, $app_name, "color_error", "") if StringLeft($color_error, 1) = "#" then $color_error = StringTrimLeft($color_error, 1) if $color_error then if not StringIsXDigit($color_error) then $color_error = 16776992 else $color_error = "0x" & $color_error endif else $color_error = 16776992 endif $color_abort = IniRead($ini_path, $app_name, "color_abort", "") if StringLeft($color_abort, 1) = "#" then $color_abort = StringTrimLeft($color_abort, 1) if $color_abort then if not StringIsXDigit($color_abort) then $color_abort = 16724991 else $color_abort = "0x" & $color_abort endif else $color_abort = 16724991 endif endfunc ; ; BuildPreferencesDialog() func BuildPreferencesDialog() debug("OutputPrefs() ->", @ScriptLineNumber) debug(@LF & $SEPARATOR & @LF) debug("Preferences =>") debugPrintArray($batch_names, "$all_sections", 0, @ScriptLineNumber) debug("$current_batch =>" & $current_batch & "<=", @ScriptLineNumber) debug("") debug("$width =>" & $window_width & "<=", @ScriptLineNumber) debug("$color_runningight =>" & $window_height & "<=", @ScriptLineNumber) debug("$min_width =>" & $min_width & "<=", @ScriptLineNumber) debug("$min_height =>" & $min_height & "<=", @ScriptLineNumber) debug("$window_x =>" & $window_x & "<=", @ScriptLineNumber) debug("$window_y =>" & $window_y & "<=", @ScriptLineNumber) debug("$autosize_columns =>" & $autosize_columns & "<=", @ScriptLineNumber) debug("$command_width =>" & $command_width & "<=", @ScriptLineNumber) debug("$counter_width =>" & $counter_width & "<=", @ScriptLineNumber) debug("$def_ix =>" & $default_input_x & "<=", @ScriptLineNumber) debug("$def_iy =>" & $default_input_y & "<=", @ScriptLineNumber) debug("$def_iw =>" & $default_input_width & "<=", @ScriptLineNumber) debug("$input_x =>" & $input_x & "<=", @ScriptLineNumber) debug("$input_y =>" & $input_y & "<=", @ScriptLineNumber) debug("$input_width =>" & $input_width & "<=", @ScriptLineNumber) debug("") debug("$show_tips =>" & $show_tips & "<=", @ScriptLineNumber) debug("$warn_delete_batch =>" & $warn_delete_batch & "<=", @ScriptLineNumber) debug("$warn_delete_command =>" & $warn_delete_command & "<=", @ScriptLineNumber) debug("$main_name =>" & $tab_name_main & "<=", @ScriptLineNumber) debug("$pre_name =>" & $tab_name_setup & "<=", @ScriptLineNumber) debug("$post_name =>" & $tab_name_post & "<=", @ScriptLineNumber) debug("$cmd_col_name =>" & $column_name_commands & "<=", @ScriptLineNumber) debug("$cnt_col_name =>" & $column_name_count & "<=", @ScriptLineNumber) debug("$allow_empty_batch =>" & $allow_empty_batch & "<=", @ScriptLineNumber) debug("$color_errorde_running_tasks =>" & $opt_hide_running_tasks & "<=", @ScriptLineNumber) debug("$portable_paths =>" & $portable_paths & "<=", @ScriptLineNumber) debug("$task_list_font =>" & $list_font & "<=", @ScriptLineNumber) debug("$batches_font =>" & $batch_font & "<=", @ScriptLineNumber) debug("$batches_font_size =>" & $batch_font_size & "<=", @ScriptLineNumber) debug("$task_list_font_size =>" & $list_font_size & "<=", @ScriptLineNumber) debug("$sort_batch_list =>" & $sort_batch_list & "<=", @ScriptLineNumber) debug("$enable_randomize =>" & $show_randomize & "<=", @ScriptLineNumber) debug("$show_batch_controls =>" & $show_batch_row & "<=", @ScriptLineNumber) debug("$column_order =>" & $column_order & "<=", @ScriptLineNumber) debug("$counter_align =>" & $counter_align & "<=", @ScriptLineNumber) debug("$run_on_top =>" & $run_on_top & "<=", @ScriptLineNumber) debug("$auto_name_tasks =>" & $auto_name_tasks & "<=", @ScriptLineNumber) debug("$time_in_title =>" & $show_elapsed & "<=", @ScriptLineNumber) debug("$allowed_exes =>" & $allowed_extensions & "<=", @ScriptLineNumber) debugPrintArray($allowed_extension_list, "$allowed_exes_array", 0, @ScriptLineNumber) debug("$reset_colors =>" & $reset_colors & "<=", @ScriptLineNumber) debug("$color_default =>" & $default_color & "<=", @ScriptLineNumber) debug("$color_text =>" & $color_text & "<=", @ScriptLineNumber) debug("$color_running =>" & $color_running & "<=", @ScriptLineNumber) debug("$color_success =>" & $color_success & "<=", @ScriptLineNumber) debug("$color_fail =>" & $color_fail & "<=", @ScriptLineNumber) debug("$color_multi_fail =>" & $color_multi_fail & "<=", @ScriptLineNumber) debug("$color_error =>" & $color_error & "<=", @ScriptLineNumber) debug("$color_abort =>" & $color_abort & "<=", @ScriptLineNumber) debug("") debug("$userkey_add =>" & $hotkey_add & "<=", @ScriptLineNumber) debug("$userkey_del =>" & $hotkey_delete & "<=", @ScriptLineNumber) debug("$userkey_run =>" & $hotkey_run & "<=", @ScriptLineNumber) debug("$userkey_pause =>" & $hotkey_pause & "<=", @ScriptLineNumber) debug("$userkey_abort =>" & $hotkey_abort & "<=", @ScriptLineNumber) debug("") debug("$log_path =>" & $log_path & "<=", @ScriptLineNumber) debug("$utf8_log =>" & $opt_utf8_log & "<=", @ScriptLineNumber) debug("$LOG_LF =>" & IniReadPrefLayers($ini_path, $app_name, $current_batch, "log_line_feed", "") & "<=", @ScriptLineNumber) debug("$timestamp_logs =>" & $opt_timestamp_logs & "<=", @ScriptLineNumber) debug("$timestamp_everything =>" & $opt_timestamp_everything & "<=", @ScriptLineNumber) debug("$stamp_all =>" & $timestamp_all_lines & "<=", @ScriptLineNumber) debug("$timestamp_delimit =>" & $opt_timestamp_delimiter & "<=", @ScriptLineNumber) debug("$date_delimit =>" & $opt_date_delimiter & "<=", @ScriptLineNumber) debug("$log_setup =>" & $opt_log_setup & "<=", @ScriptLineNumber) debug("$log_options =>" & $opt_log_options & "<=", @ScriptLineNumber) debug("$log_log_options =>" & $opt_log_log_options & "<=", @ScriptLineNumber) debug("$log_summary =>" & $opt_log_summary & "<=", @ScriptLineNumber) debug("$log_separator =>" & $opt_log_separator & "<=", @ScriptLineNumber) debug("$log_update =>" & $opt_log_update_minutes & "<=", @ScriptLineNumber) debug("$compress_logs =>" & $opt_compress_logs & "<=", @ScriptLineNumber) debug("") debug("$cycle_main_batch =>" & $opt_cycle_batch & "<=", @ScriptLineNumber) debug("$max_batch_time =>" & $opt_max_time & "<=", @ScriptLineNumber) debug("randomize_batch =>" & $opt_randomize & "<=", @ScriptLineNumber) debug("$halt_on_setup_fail =>" & $opt_halt_on_setup_fail & "<=", @ScriptLineNumber) debug("$halt_on_task_fail =>" & $opt_halt_on_task_fail & "<=", @ScriptLineNumber) debug("$halt_on_fail_range =>" & $opt_halt_on_fail_range & "<=", @ScriptLineNumber) debug("$select_all =>" & $opt_select_all & "<=", @ScriptLineNumber) debug("$ignore_selections =>" & $opt_ignore_selections & "<=", @ScriptLineNumber) debug("$success_msg =>" & $opt_success_msg & "<=", @ScriptLineNumber) debug("$precision_seconds =>" & $opt_precision_seconds & "<=", @ScriptLineNumber) debug("$notify =>" & $opt_notify & "<=", @ScriptLineNumber) debug("$beep =>" & $opt_beep & "<=", @ScriptLineNumber) debug("$trace_file =>" & $opt_trace_file & "<=", @ScriptLineNumber) debug("$trace_all_tasks =>" & $opt_trace_all_tasks & "<=", @ScriptLineNumber) debug("$always_show_trace =>" & $opt_always_show_trace & "<=", @ScriptLineNumber) debug($SEPARATOR & @LF) endfunc ; ; MigrateIniOnUpgrade() func MigrateIniOnUpgrade() local $stored_version = IniRead($ini_path, $app_name, "version", 0) if _VersionCompare($app_version, $stored_version) <> 1 then return false local $new_ini_path = @TempDir & "\Batch Runner.ini.new" FileInstall("Resources\Batch Runner.ini", $new_ini_path, 1) local $section_names = IniReadSectionNames($new_ini_path) for $section_index = 1 to $section_names[0] if $section_names[$section_index] <> $app_name then IniDelete($new_ini_path, $section_names[$section_index]) endif next $section_names = IniReadSectionNames($ini_path) local $section_data for $section_index = 1 to $section_names[0] $section_data = IniReadSection($ini_path, $section_names[$section_index]) if IsArray($section_data) then for $key_index = 1 to $section_data[0][0] IniWrite($new_ini_path, $section_names[$section_index], $section_data[$key_index][0], $section_data[$key_index][1]) next endif next FileMove($ini_path, GetLongParent($ini_path) & "\[" & @YEAR & "-" & @MON & "-" & @MDAY & "@" & @HOUR & "." & @MIN & "] Batch Runner.ini") FileMove($new_ini_path, $ini_path, 1) IniWrite($ini_path, $app_name, "version", $app_version) endfunc func EditPreferencesFile() OpenFileInEditor($ini_path) endfunc func OpenLogInEditor() OpenFileInEditor($log_path) endfunc ; ; OpenFileInEditor() func OpenFileInEditor($file_path) local $editor_path = ExpandPathMacros(IniRead($ini_path, $app_name, "editor", "")) if $editor_path = "" then $editor_path = FileOpenDialog("Please select your favourite Text Editor", @WindowsDir, "Executables (*.exe)", 1, "notepad.exe", $main_window) IniWrite($ini_path, $app_name, "editor", CompressPathMacros($editor_path)) endif if not Run($editor_path & " " & $file_path) then MsgBox($MB_OK + $MB_ICONERROR + $MB_DEFBUTTON1 + $MB_SYSTEMMODAL, "Oops!..", "Problem launching " & $editor_path & $MSG_LF & $MSG_LF & "Error: " & @error & $MSG_LF, 30) endif endfunc ; IniReadPrefLayers() ; Reads a setting with per-batch override layers. ; func IniReadPrefLayers($ini_file, $main_section, $batch_section, $key_name, $default_value, $as_bool = false, $allow_override = true, $key_prefix = "opt|") local $main_value, $batch_value if $as_bool then $main_value = IniReadCheckBox($ini_file, $main_section, $key_name, "") else $main_value = IniRead($ini_file, $main_section, $key_name, "") endif if $main_value and $allow_override then if $as_bool then $batch_value = IniReadCheckBox($ini_file, $batch_section, $key_prefix & $key_name, "") else $batch_value = IniRead($ini_file, $batch_section, $key_prefix & $key_name, "") endif if $batch_value then return $batch_value return $main_value endif return $default_value endfunc ; ExpandRunMacros() ; Expands run-time macros in a path. ; func ExpandRunMacros($path_text) if StringInStr($path_text, "\") or StringInStr($path_text, "/") then $path_text = StringReplace($path_text, "/", "\") $path_text = StringReplace($path_text, "\\", "\") else $path_text = StringReplace($path_text, "@desktop\", "") $path_text = StringReplace($path_text, "@desktop", "") $path_text = StringReplace($path_text, "@userdir\", "") $path_text = StringReplace($path_text, "@userdir", "") endif select case StringInStr($path_text, "@now") $path_text = StringReplace($path_text, "@now", @YEAR & "-" & @MON & "-" & @MDAY & " @ " & @HOUR & "." & @MIN) continuecase case StringInStr($path_text, "@today") $path_text = StringReplace($path_text, "@today", @YEAR & "-" & @MON & "-" & @MDAY) continuecase case StringInStr($path_text, "@sec") $path_text = StringReplace($path_text, "@sec", @SEC) continuecase case StringInStr($path_text, "@min") $path_text = StringReplace($path_text, "@min", @MIN) continuecase case StringInStr($path_text, "@hour") $path_text = StringReplace($path_text, "@hour", @HOUR) continuecase case StringInStr($path_text, "@mday") $path_text = StringReplace($path_text, "@mday", @MDAY) continuecase case StringInStr($path_text, "@mon") $path_text = StringReplace($path_text, "@mon", @MON) continuecase case StringInStr($path_text, "@year") $path_text = StringReplace($path_text, "@year", @YEAR) continuecase case StringInStr($path_text, "@wday") $path_text = StringReplace($path_text, "@wday", @WDAY) continuecase case StringInStr($path_text, "@yday") $path_text = StringReplace($path_text, "@yday", @YDAY) continuecase case StringInStr($path_text, "@batch") $path_text = StringReplace($path_text, "@batch", $current_batch) endselect select case StringInStr($path_text, "@desktop") $path_text = StringReplace($path_text, "@desktop", @DesktopDir) $path_text = StringReplace($path_text, "@userdir\", "") $path_text = StringReplace($path_text, "@userdir", "") case StringInStr($path_text, "@userdir") $path_text = StringReplace($path_text, "@userdir", $appdata_dir) $path_text = StringReplace($path_text, "@desktop\", "") $path_text = StringReplace($path_text, "@desktop", "") endselect return $path_text endfunc ; ; CompressPathMacros() ; Compresses a path into macros. ; func CompressPathMacros($path_text) select case StringInStr($path_text, $appdata_dir) == 1 if StringInStr(StringReplace($path_text, $appdata_dir, "@userdir", 1), ".") <> 9 then $path_text = StringReplace($path_text, $appdata_dir, "@userdir", 1) else continuecase endif case StringInStr($path_text, @AppDataDir) == 1 $path_text = StringReplace($path_text, @AppDataDir, "@appdatadir", 1) case StringInStr($path_text, @AppDataCommonDir) == 1 $path_text = StringReplace($path_text, @AppDataCommonDir, "@appdatacommon", 1) case StringInStr($path_text, @DesktopDir) == 1 $path_text = StringReplace($path_text, @DesktopDir, "@desktop", 1) case StringInStr($path_text, @UserProfileDir) == 1 $path_text = StringReplace($path_text, @UserProfileDir, "@homedir", 1) case StringInStr($path_text, @MyDocumentsDir) == 1 $path_text = StringReplace($path_text, @MyDocumentsDir, "@mydocs", 1) case StringInStr($path_text, EnvGet("ProgramFiles(x86)")) == 1 $path_text = StringReplace($path_text, EnvGet("ProgramFiles(x86)"), "@programsdir32", 1) case StringInStr($path_text, @ProgramFilesDir) == 1 $path_text = StringReplace($path_text, @ProgramFilesDir, "@programsdir", 1) case StringInStr($path_text, @WindowsDir) == 1 $path_text = StringReplace($path_text, @WindowsDir, "@windowsdir", 1) endselect return $path_text endfunc ; ; ExpandPathMacros() ; Expands directory macros in a path. ; func ExpandPathMacros($path_text) select case StringInStr($path_text, "@userdir") == 1 $path_text = StringReplace($path_text, "@userdir", $appdata_dir, 1) case StringInStr($path_text, "@appdatacommon") == 1 $path_text = StringReplace($path_text, "@appdatacommon", @AppDataCommonDir, 1) case StringInStr($path_text, "@appdatadir") == 1 $path_text = StringReplace($path_text, "@appdatadir", @AppDataDir, 1) case StringInStr($path_text, "@desktop") == 1 $path_text = StringReplace($path_text, "@desktop", @DesktopDir, 1) case StringInStr($path_text, "@homedir") == 1 $path_text = StringReplace($path_text, "@homedir", @UserProfileDir, 1) case StringInStr($path_text, "@mydocs") == 1 $path_text = StringReplace($path_text, "@mydocs", @MyDocumentsDir, 1) case StringInStr($path_text, "@programsdir32") == 1 $path_text = StringReplace($path_text, "@programsdir32", EnvGet("ProgramFiles(x86)"), 1) case StringInStr($path_text, "@programsdir") == 1 $path_text = StringReplace($path_text, "@programsdir", @ProgramFilesDir, 1) case StringInStr($path_text, "@windowsdir") == 1 $path_text = StringReplace($path_text, "@windowsdir", @WindowsDir, 1) endselect return $path_text endfunc ; ; CountdownRemainingMs() ; Returns the countdown remainder in ms. ; func CountdownRemainingMs() return Int($countdown_seconds * 60 * 1000) - Int(TimerDiff($countdown_started)) endfunc ; ; FormatElapsedMs() ; Formats elapsed milliseconds. ; func FormatElapsedMs($milliseconds) return FormatElapsedSeconds($milliseconds / 1000) endfunc ; ; FormatElapsedSeconds() ; Formats elapsed seconds, using FormatDurationMinutes(). ; func FormatElapsedSeconds($total_seconds) return FormatDurationMinutes($total_seconds / 60) endfunc ; ; FormatDurationMinutes() ; Formats a minute count as duration. ; func FormatDurationMinutes($total_minutes) local $total_seconds = $total_minutes * 60 local $hours = Floor($total_seconds / 3600) local $minutes = Floor(($total_seconds - $hours * 3600) / 60) local $seconds = Mod($total_seconds, 60) if $opt_precision_seconds = $ON then return StringFormat("%01dh %01dm %.2fs", $hours, $minutes, $seconds) else return StringFormat("%01dh %01dm %01.1ds", $hours, $minutes, $seconds) endif endfunc ; ; NormalizeCheckInterval() ; Normalises a check interval to minutes. (Mirror of override:refined-dice match in Includes\Schedules.au3.) ; func NormalizeCheckInterval($interval_text) $interval_text = ParseHourInterval($interval_text) if $interval_text < 0 then $interval_text = $opt_max_time if $opt_max_time < 0 then $interval_text = 1 return $interval_text endfunc ; ; ParseHourInterval() ; Parses an hour-based interval to minutes. ; func ParseHourInterval($interval_text) $interval_text = StringStripWS($interval_text, 7) select case StringRight($interval_text, 1) = "h" $interval_text = StringTrimRight($interval_text, 1) $interval_text = $interval_text * 60 case StringInStr($interval_text, "hours") if StringInStr($interval_text, " ") then $interval_text = StringSplit($interval_text, " ", 2) $interval_text = $interval_text[0] * 60 else $interval_text = StringTrimRight($interval_text, 5) $interval_text = $interval_text * 60 endif case StringInStr($interval_text, "hour") if StringInStr($interval_text, " ") then $interval_text = StringSplit($interval_text, " ", 2) $interval_text = $interval_text[0] * 60 else $interval_text = StringTrimRight($interval_text, 4) $interval_text = $interval_text * 60 endif case StringRight($interval_text, 1) = "m" $interval_text = StringTrimRight($interval_text, 1) case StringInStr($interval_text, "minutes") if StringInStr($interval_text, " ") then $interval_text = StringSplit($interval_text, " ", 2) $interval_text = $interval_text[0] else $interval_text = StringTrimRight($interval_text, 7) endif case StringInStr($interval_text, "minute") if StringInStr($interval_text, " ") then $interval_text = StringSplit($interval_text, " ", 2) $interval_text = $interval_text[0] else $interval_text = StringTrimRight($interval_text, 6) endif case StringInStr($interval_text, "seconds") if StringInStr($interval_text, " ") then $interval_text = StringSplit($interval_text, " ", 2) $interval_text = $interval_text[0] / 60 else $interval_text = StringTrimRight($interval_text, 7) $interval_text = $interval_text / 60 endif case StringInStr($interval_text, "second") if StringInStr($interval_text, " ") then $interval_text = StringSplit($interval_text, " ", 2) $interval_text = $interval_text[0] / 60 else $interval_text = StringTrimRight($interval_text, 6) $interval_text = $interval_text / 60 endif case StringRight($interval_text, 1) = "s" $interval_text = StringTrimRight($interval_text, 1) $interval_text = $interval_text / 60 endselect return $interval_text endfunc ; ; FormatMinutesInterval() ; Formats a minute count as s/m/h text. ; func FormatMinutesInterval($minutes) if $minutes = 0 then return 0 local $result_text local $total_seconds = $minutes * 60 local $hours = Floor($minutes / 60) select case $total_seconds < 60 $result_text = $total_seconds & "s" case $minutes >= 1 and $minutes < 60 $result_text = $minutes & "m" case $minutes >= 60 $result_text = $hours + (Floor(($total_seconds - $hours * 3600) / 60) / 60) & "h" endselect return $result_text endfunc ; ; TimestampString() ; Returns a compact timestamp string. Mirror of override:refined-dice match in Includes\cel.au3. ; func TimestampString() return @YEAR & ":" & @MON & ":" & @MDAY & $opt_date_delimiter & @HOUR & ":" & @MIN & ":" & @SEC endfunc ; ; PlayBeepFeedback() ; Plays the completion beep. ; func PlayBeepFeedback() local $wait_flag = 0 if not $gui_active then $wait_flag = 1 $opt_beep = IniReadCheckBox($ini_path, $app_name, "beep", $ON) select case FileExists($opt_beep) SoundPlay($opt_beep, $wait_flag) return case $opt_beep = $ON Beep(1000, 100) return case $opt_beep = $OFF return endselect Beep($opt_beep, 100) endfunc ; ; HoverShowWindow() ; Shows the window on tray hover. ; func HoverShowWindow() if not $gui_active then return false MaybeShowWindowOnHover($main_window) endfunc ; ; MaybeShowWindowOnHover() ; Shows the window when hover rules allow. ; func MaybeShowWindowOnHover($window_handle) if not WinVisible($window_handle) then return if $hover_to_show = $OFF then return if $window_position = 0 or TimerDiff($window_position) > 1000 then $window_position = TimerInit() endif local $hover_time = TimerDiff($window_position) if $hover_time > ((11 - $hover_sensitivity) * 100) then $window_position = 0 WinSetOnTop($window_handle, "", 1) WinSetOnTop($window_handle, "", 0) Sleep(100) WinActivate($window_handle) RedrawControl($window_handle) endif endfunc ; ; RedrawControl() ; Forces a window/control repaint. ; func RedrawControl($window_handle, $update_rect = 0, $erase_background = 0, $redraw_flags = 5) local $rect_ptr, $api_result if $update_rect <> 0 then $rect_ptr = DllStructGetPtr($update_rect) $api_result = DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $window_handle, "ptr", $rect_ptr, "int", $erase_background, "int", $redraw_flags) if IsArray($api_result) then return ($api_result[0] <> 0) endfunc ; ; RegisterHotKeys() ; Registers the application hotkeys. ; func RegisterHotKeys() if not $gui_active then return false HotKeySet("{Esc}", "HandleEscapeKey") HotKeySet($hotkey_delete, "HotkeyDispatchDelete") HotKeySet($hotkey_add, "HotkeyDispatchAdd") HotKeySet($hotkey_run, "HotkeyDispatchRun") HotKeySet("+" & $hotkey_run, "HotkeyDispatchCountdown") HotKeySet("#!a", "ShowAboutDialog") HotKeySet("^a", "HotkeyDispatchSelectAll") HotKeySet("^l", "HotkeyDispatchViewLog") HotKeySet("^p", "HotkeyDispatchPreferences") endfunc ; ; UnbindPrimaryHotkeys() ; Unbinds the primary hotkey set. ; func UnbindPrimaryHotkeys() if not $gui_active then return false HotKeySet("{Esc}") HotKeySet($hotkey_delete) HotKeySet($hotkey_add) HotKeySet($hotkey_run) HotKeySet("+" & $hotkey_run) HotKeySet("#!a") HotKeySet("^a") HotKeySet("^l") HotKeySet("^l") HotKeySet("^p") endfunc ; ; BindSecondaryHotkeys() ; Binds the secondary hotkey set. ; func BindSecondaryHotkeys() if not $gui_active then return false HotKeySet($hotkey_pause, "HotkeyDispatchPauseToggle") HotKeySet($hotkey_abort, "HotkeyDispatchAbort") HotKeySet("#!a", "ShowAboutDialog") HotKeySet("^l", "HotkeyDispatchViewLog") HotKeySet("^p", "HotkeyDispatchPreferences") endfunc ; ; UnbindSecondaryHotkeys() ; Unbinds the secondary hotkey set. ; func UnbindSecondaryHotkeys() if not $gui_active then return false HotKeySet($hotkey_pause) HotKeySet($hotkey_abort) HotKeySet("#!a") HotKeySet("^l") HotKeySet("^p") endfunc ; ; HotkeyDispatchAdd() ; Forwards the add hotkey. ; func HotkeyDispatchAdd() if WinActive($main_window) then AddCommandToActiveTab() else HotKeySet($hotkey_add) Send($hotkey_add) HotKeySet($hotkey_add, "HotkeyDispatchAdd") endif endfunc ; ; HotkeyDispatchDelete() ; Forwards the delete hotkey. ; func HotkeyDispatchDelete() if WinActive($main_window) then DeleteCommandsFromActiveTab() else HotKeySet($hotkey_delete) Send($hotkey_delete) HotKeySet($hotkey_delete, "HotkeyDispatchDelete") endif endfunc ; ; HotkeyDispatchRun() ; Forwards the run hotkey. ; func HotkeyDispatchRun() if WinActive($main_window) then ScheduleBatchRun() else HotKeySet($hotkey_run) Send($hotkey_run) HotKeySet($hotkey_run, "HotkeyDispatchRun") endif endfunc ; ; HotkeyDispatchCountdown() ; Forwards the countdown hotkey. ; func HotkeyDispatchCountdown() if WinActive($main_window) then PromptCountdownRun() else HotKeySet($hotkey_run) Send($hotkey_run) HotKeySet("+" & $hotkey_run, "HotkeyDispatchCountdown") endif endfunc ; ; HotkeyDispatchPauseToggle() ; Toggles pause via hotkey. ; func HotkeyDispatchPauseToggle() if WinActive($main_window) then if $batch_paused = 1 then ResumeBatchRun() else PauseBatchRun() endif else HotKeySet($hotkey_pause) Send($hotkey_pause) HotKeySet($hotkey_pause, "HotkeyDispatchPauseToggle") endif endfunc ; ; HotkeyDispatchAbort() ; Forwards the abort hotkey. ; func HotkeyDispatchAbort() if WinActive($main_window) then $batch_paused = 0 AbortBatchRun() else HotKeySet($hotkey_abort) Send($hotkey_abort) HotKeySet($hotkey_abort, "HotkeyDispatchAbort") endif endfunc ; ; HotkeyDispatchSelectAll() ; Forwards the select-all hotkey. ; func HotkeyDispatchSelectAll() if WinActive($main_window) then SelectAllCommands() else HotKeySet("^a") Send("^a") HotKeySet("^a", "HotkeyDispatchSelectAll") endif endfunc ; ; HotkeyDispatchViewLog() ; Forwards the view-log hotkey. ; func HotkeyDispatchViewLog() if WinActive($main_window) then OpenLogInEditor() else HotKeySet("^l") Send("^l") HotKeySet("^l", "HotkeyDispatchViewLog") endif endfunc ; ; HotkeyDispatchPreferences() ; Forwards the preferences hotkey. ; func HotkeyDispatchPreferences() if WinActive($main_window) then EditPreferencesFile() else HotKeySet("^p") Send("^p") HotKeySet("^p", "HotkeyDispatchPreferences") endif endfunc ; ; HandleEscapeKey() ; Handles the Escape hotkey. Mirror of override:refined-dice match in Includes\corz_tips.au3. ; func HandleEscapeKey() if WinActive($main_window) then SaveAllAndExit() else HotKeySet("{Esc}") Send("{Esc}") HotKeySet("{Esc}", "HandleEscapeKey") endif endfunc ; ; OpenProcessForQuery() ; ; Opens a process for querying. ; func OpenProcessForQuery($process_id) local const $query_access = 1024 local $api_result = DllCall("kernel32.dll", "ptr", "OpenProcess", "int", $query_access, "int", 0, "int", $process_id) if @error then return SetError(1, 0, 0) else return $api_result[0] endif endfunc ; ; CloseProcessHandle() ; ; Closes a process handle. ; func CloseProcessHandle($process_handle) DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $process_handle) if @error then return SetError(1, 0, 0) else return 1 endif endfunc ; ; GetProcessExitCode() ; ; Reads a process exit code. ; func GetProcessExitCode($process_handle) local $exit_code_struct = DllStructCreate("int") DllCall("kernel32.dll", "int", "GetExitCodeProcess", "ptr", $process_handle, "ptr", DllStructGetPtr($exit_code_struct)) if @error then return SetError(1, 0, 0) else return DllStructGetData($exit_code_struct, 1) endif endfunc ; ; IsDosPrefix() ; ; Tests for the dos| command prefix. ; func IsDosPrefix($command_text) if StringLeft($command_text, 4) = "dos|" then return true return false endfunc ; ; StripDosPrefix() ; ; Removes the dos| command prefix. Mirror of override:refined-dice match in Includes\cel.au3. ; func StripDosPrefix($command_text) return StringReplace($command_text, "dos|", "", 1) endfunc ; ; IsTracePrefix() ; ; Tests for the trace| command prefix. ; func IsTracePrefix($command_text) if StringLeft($command_text, 6) = "trace|" then return true return false endfunc ; ; StripTracePrefix() ; ; Removes the trace| command prefix. Mirror of override:refined-dice match in Includes\cel.au3. ; func StripTracePrefix($command_text) return StringReplace($command_text, "trace|", "", 1) endfunc ; ; IsShellexPrefix() ; ; Tests for the shellex| command prefix. ; func IsShellexPrefix($command_text) if StringLeft($command_text, 8) = "shellex|" then return true return false endfunc ; ; StripShellexPrefix() ; ; Removes the shellex| command prefix. Mirror of override:refined-dice match in Includes\cel.au3. ; func StripShellexPrefix($command_text) return StringReplace($command_text, "shellex|", "", 1) endfunc ; ; StripCommandPrefixes() ; ; Removes every command type prefix. ; func StripCommandPrefixes($command_text) $command_text = StripShellexPrefix($command_text) $command_text = StripTracePrefix($command_text) $command_text = StripDosPrefix($command_text) return $command_text endfunc ; ; EscapePipes() ; ; Escapes pipe delimiters for storage. ; func EscapePipes($command_text) return StringReplace($command_text, "|", "¦") endfunc ; ; UnescapePipes() ; ; Restores escaped pipe delimiters. ; func UnescapePipes($command_text) return StringReplace($command_text, "¦", "|") endfunc ; ; ShowAppMsgBox() ; ; Shows a message box while the main window is locked. ; func ShowAppMsgBox($message_flags, $dialog_title, $message_text, $timeout_seconds = 0) if $gui_active then LockAppWindow($main_window) local $user_choice = MsgBox($message_flags, $dialog_title, $message_text, $timeout_seconds, $main_window) if $gui_active then UnlockAppWindow($main_window) return $user_choice endfunc ; ; ExitWithFailure() ; Exits with a failure code. ; func ExitWithFailure() CleanupTempFiles() $exit_code = -9 ExitApp($exit_code) endfunc ; ; SaveAllAndExit() ; Saves state and exits. ; func SaveAllAndExit() $app_exit_signal = 0 $abort_state = 2 CleanupTempFiles() SaveColumnLayout() if $gui_active and not $launch_mode then VersionCheckOnline($app_name, $url_version_check, $url_download, $ini_path, $app_name, $app_version, $main_window) endfunc ; ; CleanupTempFiles() ; Removes temporary files created by the app. ; func CleanupTempFiles() FileDelete(@TempDir & "\about.gif") endfunc ; ; ExitApp() ; Cleans up and exits. ; func ExitApp($return_code = 0) CleanupTempFiles() Exit $return_code endfunc ; ; ShowAboutDialog() ; Shows the about dialog. ; func ShowAboutDialog() BuildAboutDialog($main_window) endfunc ; ; BuildAboutDialog() ; Builds the about dialog. ; func BuildAboutDialog($parent_window) local $dialog_x = -1 local $dialog_y = -1 local $dialog_height = 105 local $dialog_width = 265 local $label_x = 80 if WinVisible($parent_window) then local $window_pos = WinGetPos($parent_window) if IsArray($window_pos) then $dialog_x = $window_pos[0] + ($window_pos[2] / 2) - ($dialog_width / 2) $dialog_y = $window_pos[1] + ($window_pos[3] / 2) - ($dialog_height) endif DisableMainWindow($parent_window) endif local $saved_event_mode = AutoItSetOption("GUIOnEventMode", 0) local $saved_coord_mode = AutoItSetOption("GUICoordMode", 1) $about_window = GUICreate(" About " & $app_name & "..", $dialog_width, $dialog_height, $dialog_x, $dialog_y, default, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor(16777215) local $title_label = GUICtrlCreateLabel($app_name & " v" & $app_version & $MSG_LF & "from corz.org", $label_x, 8) FileInstall("Resources\about.gif", @TempDir & "\", 1) local $logo_control if FileExists(@TempDir & "\about.gif") then $logo_control = GUICtrlCreatePic(@TempDir & "\about.gif", 6, 9, 64, 64) else $logo_control = GUICtrlCreateIcon($icon_path, 0, 6, 9, 64, 64) endif local $visit_label = GUICtrlCreateLabel("Do you want to visit the " & $app_name & $MSG_LF & "web page at this time?", $label_x, 40) local $no_button = GUICtrlCreateButton("No, not right now", 10, 80, 95, 22) GUICtrlSetTip(-1, " The other button is the one you want to click! ") local $yes_button = GUICtrlCreateButton("Yes, let's do it!", $dialog_width - 104, 80, 95, 22) GUICtrlSetTip(-1, " The link will open in your system default browser ") local $arch_text = "x86" if @AutoItX64 = 1 then $arch_text = "x64" local $arch_label = GUICtrlCreateLabel($arch_text, $dialog_width - 19, 1, 18, 12) GUICtrlSetFont(-1, 8, 200, 0, "Lucida Console") GUISetState() local $blink_counter = 1 local $dialog_action while 1 $blink_counter += 1 if Mod($blink_counter, 25) = 0 then GUICtrlSetColor($arch_label, 4473924) endif if Mod($blink_counter, 50) = 0 then GUICtrlSetColor($arch_label, 0) endif local $gui_message = GUIGetMsg() Sleep(33) switch $gui_message case $GUI_EVENT_CLOSE, $no_button exitloop case $yes_button $dialog_action = "url" exitloop case $logo_control $dialog_action = "url" exitloop case $title_label, $visit_label VisitUrl($url_home) case $arch_label $dialog_action = "sysi" exitloop endswitch wend GUIDelete($about_window) AutoItSetOption("GUICoordMode", $saved_coord_mode) AutoItSetOption("GUIOnEventMode", $saved_event_mode) switch $dialog_action case "url" VisitUrl($url_home) case "sysi" BuildSystemInfoDialog() endswitch if WinVisible($parent_window) then EnableMainWindow($parent_window) endfunc ; ; DisableMainWindow() ; Disables the main window. ; func DisableMainWindow($window_handle) GUISetState(@SW_DISABLE, $window_handle) TraySetState(2) endfunc ; ; EnableMainWindow() ; Enables and activates the main window. ; func EnableMainWindow($window_handle) TraySetState(1) GUISetState(@SW_ENABLE, $window_handle) WinActivate($window_handle) GUISwitch($window_handle) endfunc ; ; BuildSystemInfoDialog() ; Builds the system information dialog. ; func BuildSystemInfoDialog() local $saved_coord_mode = AutoItSetOption("GUICoordMode", 0) local $saved_event_mode = AutoItSetOption("GUIOnEventMode", 0) local $saved_x = IniRead($ini_path, $app_name, "si_x", -1) local $saved_y = IniRead($ini_path, $app_name, "si_y", -1) local $saved_width = IniRead($ini_path, $app_name, "si_w", 800) local $saved_height = IniRead($ini_path, $app_name, "si_h", 400) if $saved_width < 400 then $saved_width = 400 local $label_width = 140 local $field_width = $saved_width - $label_width - 20 local $sysinfo_window = GUICreate("System Information", $saved_width, $saved_height, $saved_x, $saved_y, BitOR($WS_CLIPSIBLINGS, $WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX), $WS_EX_TOPMOST) GUISetIcon($icon_path, 0, $sysinfo_window) GUISetCoord(10, -10) local $first_label = GUICtrlCreateLabel("Computer Name:", 0, 20, $label_width) GUICtrlCreateLabel("Memory:", $label_width + 220, 0, 60) GUISetCoord(10, 10) GUICtrlCreateLabel("Current UserName:", 0, 20, $label_width) GUICtrlCreateLabel("Operating System:", 0, 20, $label_width) GUICtrlCreateLabel("System %PATH%:", 0, 20, $label_width) local $ip_label = GUICtrlCreateLabel("Local IP Address:", 0, 20, $label_width) local $drive_combo = GUICtrlCreateCombo("", 0, 22, 100, 200) local $drive_list = DriveGetDrive("FIXED") for $index = 1 to $drive_list[0] GUICtrlSetData($drive_combo, $drive_list[$index]) next ControlCommand($sysinfo_window, "", $drive_combo, "SelectString", @HomeDrive) local $startup_label = GUICtrlCreateLabel("Startup Directory:", 0, 28, $label_width) GUICtrlCreateLabel("Windows Directory:", 0, 20, $label_width) GUICtrlCreateLabel("System Folder:", 0, 20, $label_width) GUICtrlCreateLabel("Desktop Directory:", 0, 20, $label_width) GUICtrlCreateLabel("'My Documents' Directory:", 0, 20, $label_width) GUICtrlCreateLabel("Program Files Directory:", 0, 20, $label_width) GUICtrlCreateLabel("Start Menu Directory:", 0, 20, $label_width) GUICtrlCreateLabel("Temporary File Directory:", 0, 20, $label_width) GUICtrlCreateLabel("Desktop:", 0, 20, $label_width) GUICtrlCreateLabel("Date [Y-M-D]:", 0, 20, $label_width) local $time_label = GUICtrlCreateLabel("Time [H:M:S]:", 0, 20, $label_width) for $index = $first_label to $time_label GUICtrlSetResizing($index, $GUI_DOCKALL) GUICtrlSetTip($index, " Click the labels to select all the input text. " & $MSG_LF & " NOTE: Some update dynamically and will quickly deselect themselves! ") next GUISetCoord($label_width + 10, -12) local $selected_drive = GUICtrlRead($drive_combo) local $computer_field = GUICtrlCreateInput(@ComputerName, 0, 20, 200, 20) local $memory_field = GUICtrlCreateInput(GetFreeMemHuman(), $label_width * 2, 0, 120, 20) GUISetCoord($label_width + 10, 10) GUICtrlCreateInput(@UserName, 0, 20, $field_width, 20) local $arch_text = "x86" if @AutoItX64 = 1 then $arch_text = "x64" local $os_text = StringReplace(@OSVersion, "_", " ") & " (" & $arch_text & ") " & @OSServicePack & " [" & @OSType & "][cpu:" & StringLower(@CPUArch) & "]" GUICtrlCreateInput($os_text, 0, 20, $field_width, 20) GUICtrlCreateInput(EnvGet("PATH"), 0, 20, $field_width, 20) GUICtrlCreateInput(@IPAddress1, 0, 20, $field_width, 20) local $volume_field = GUICtrlCreateInput(DriveGetLabel($selected_drive & "\"), 0, 23, 150, 20) local $total_field = GUICtrlCreateInput(FormatMB(DriveSpaceTotal($selected_drive & "\"), 2), 155, 0, 100, 20) local $free_field = GUICtrlCreateInput(FormatMB(DriveSpaceFree($selected_drive & "\"), 2) & " Free", 105, 0, 150, 20) GUISetCoord($label_width + 10, 138) GUICtrlCreateInput(@StartupDir, 0, 0, $field_width, 20) GUICtrlCreateInput(@WindowsDir, 0, 20, $field_width, 20) GUICtrlCreateInput(@SystemDir, 0, 20, $field_width, 20) GUICtrlCreateInput(@DesktopDir, 0, 20, $field_width, 20) GUICtrlCreateInput(@MyDocumentsDir, 0, 20, $field_width, 20) GUICtrlCreateInput(@ProgramFilesDir, 0, 20, $field_width, 20) GUICtrlCreateInput(@StartMenuDir, 0, 20, $field_width, 20) GUICtrlCreateInput(@TempDir, 0, 20, $field_width, 20) GUICtrlCreateInput(@DesktopWidth & "px" & " x " & @DesktopHeight & "px " & @DesktopDepth & "bit [" & @DesktopRefresh & "Hz]", 0, 20, $field_width, 20) local $date_field = GUICtrlCreateInput(@YEAR & "-" & @MON & "-" & @MDAY, 0, 20, $field_width, 20) local $time_field = GUICtrlCreateInput(@HOUR & ":" & @MIN & ":" & @SEC, 0, 20, $field_width, 20) for $index = $computer_field to $time_field GUICtrlSetResizing($index, $GUI_DOCKALL + $GUI_DOCKRIGHT) next for $index = $computer_field to $time_field GUICtrlSetFont($index, 9, 400, 0, "Lucida Console") next for $index = $volume_field to $free_field GUICtrlSetResizing($index, $GUI_DOCKALL) next GUISetState() local $tick_counter = 1 while 1 $selected_drive = GUICtrlRead($drive_combo) if Mod($tick_counter, 10) = 0 then GUICtrlSetData($time_field, @HOUR & ":" & @MIN & ":" & @SEC) if @SEC < 5 and @HOUR = 0 and @MIN = 0 then GUICtrlSetData($date_field, @YEAR & "-" & @MON & "-" & @MDAY) endif if Mod(@SEC, 3) = 0 then GUICtrlSetData($volume_field, DriveGetLabel($selected_drive & "\")) GUICtrlSetData($total_field, FormatMB(DriveSpaceTotal($selected_drive & "\"), 2)) GUICtrlSetData($free_field, FormatMB(DriveSpaceFree($selected_drive & "\"), 2) & " Free") GUICtrlSetData($memory_field, GetFreeMemHuman() & " Free") endif endif $tick_counter += 1 Sleep(33) local $gui_message = GUIGetMsg() switch $gui_message case $GUI_EVENT_CLOSE exitloop case $drive_combo GUICtrlSetData($volume_field, DriveGetLabel($selected_drive & "\")) GUICtrlSetData($total_field, FormatMB(DriveSpaceTotal($selected_drive & "\"), 2)) GUICtrlSetData($free_field, FormatMB(DriveSpaceFree($selected_drive & "\"), 2) & " Free") case $first_label to $ip_label GUICtrlSetState($gui_message + 18, $GUI_FOCUS) case $startup_label to $time_label GUICtrlSetState($gui_message + 20, $GUI_FOCUS) endswitch wend local $window_rect = WinGetPos($sysinfo_window) if IsArray($window_rect) then if $saved_x <> $window_rect[0] and $window_rect[0] >= 0 and $window_rect[0] < (@DesktopWidth - 25) then IniWrite($ini_path, $app_name, "si_x", $window_rect[0]) if $saved_y <> $window_rect[1] and $window_rect[1] >= 0 and $window_rect[1] < (@DesktopHeight - 25) then IniWrite($ini_path, $app_name, "si_y", $window_rect[1]) $window_rect = WinGetClientSize($sysinfo_window) if IsArray($window_rect) then if $window_rect[0] <> $saved_width and $window_rect[0] >= 100 then IniWrite($ini_path, $app_name, "si_w", $window_rect[0]) if $window_rect[1] <> $saved_height and $window_rect[1] >= 100 then IniWrite($ini_path, $app_name, "si_h", $window_rect[1]) endif endif GUIDelete($sysinfo_window) AutoItSetOption("GUICoordMode", $saved_coord_mode) AutoItSetOption("GUIOnEventMode", $saved_event_mode) 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=Y #AutoIt3Wrapper_Run_Stop_OnError=Y ; *** YOU MIGHT NEED TO USE FORWARD SLASHES IN RELATIVE PATHS - YMMV!!! ** #AutoIt3Wrapper_Icon=Resources\Batch Runner.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 Batch Runner.exe. #AutoIt3Wrapper_Res_Field=Long Description|Batch Runner is a Windows Automation tool enabling you to run tasks in a batch. #AutoIt3Wrapper_Res_Field=ProductName|Batch Runner #AutoIt3Wrapper_Res_Field=Publisher|corz.org #AutoIt3Wrapper_Res_Field=Web Page|http://corz.org/ #AutoIt3Wrapper_Res_Field=Compiled|%date% %time% ; application's resource info.. #AutoIt3Wrapper_Res_Comment=Batch Runner ; this is the one that shows up in Process Explorer.. #AutoIt3Wrapper_Res_Description=Batch Runner - from corz.org #AutoIt3Wrapper_Res_LegalCopyright=corz.org #AutoIt3Wrapper_Res_ProductVersion=1 ;Build|debug Build|Beta Release Build|Public Release #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_Before_Admin=Y #AutoIt3Wrapper_Run_After_Admin=Y #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\Batch Runner\Batch Runner.exe" #AutoIt3Wrapper_Run_After=copy "..\..\Free Software License.txt" "..\Batch Runner\Free Software License.txt" #AutoIt3Wrapper_Run_After=copy "Resources\Readme.txt" "..\Batch Runner\Readme.txt" #AutoIt3Wrapper_Run_After=move /Y "%outx64%" "..\Batch Runner\Batch Runner.exe" ; Backup this version of the source files to BackUp.zip.. #AutoIt3Wrapper_Run_After=7z.exe a -mx7 -tzip "..\BackUp\BackUp.zip" ".\%scriptfile% - %fileversion%.au3" #AutoIt3Wrapper_Run_After=7z.exe a -mx7 -tzip "..\BackUp\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" #AutoIt3Wrapper_Run_After=7z.exe a -mx7 -tzip "..\Batch Runner.zip" "..\Batch Runner\" #AutoIt3Wrapper_Run_After=checksum.exe cq-t "..\Batch Runner.zip" #EndRegion