corz.org uses cookies to remember that you've seen this notice explaining that corz.org uses cookies, okay!
global const $LOG_LF = @CRLF
global const $MSG_LF = @LF
global const $ON = $GUI_CHECKED
global const $OFF = $GUI_UNCHECKED
global const $UNSET = $GUI_INDETERMINATE
global const $STR_ENABLED = "enabled"
global const $STR_DISABLED = "disabled"
global const $DEF_MSG_TIME = 2000
global const $COLOR_LTGREY = 0xD0D0D0
global $dump_file
global $debug_level = 10
global $max_debug_log_size = 0
global $my_name, $my_domain, $data_dir, $ini_path
global $log_string, $log_location
global $max_log_size = 0
global $monitors_list[1][5]
$monitors_list[0][0] = 0
global $do_tooltips
global $tip_icon = @ScriptFullPath & ",0"
global $tip_style = 1
global $tooltip_time = 10000
global $file_array, $new_array[1]
global $am_sending
global $oMyError = ObjEvent("AutoIt.Error", "AAError")
global $known_user_tokens[1][2]
Const $Internet_Explorer = 0x1
Const $Programs = 0x2
Const $Control_Panel = 0x3
Const $Printers_and_Faxes = 0x4
Const $My_Documents = 0x5
Const $Favorites = 0x6
Const $Startup = 0x7
Const $My_Recent_Documents = 0x8
Const $SendTo = 0x9
Const $Recycle_Bin = 0xa
Const $Start_Menu = 0xb
Const $My_Music = 0xd
Const $My_Videos = 0xe
Const $Desktop = 0x10
Const $My_Computer = 0x11
Const $My_Network_Places = 0x12
Const $NetHood = 0x13
Const $Fonts = 0x14
Const $Templates = 0x15
Const $All_Users_Start_Menu = 0x16
Const $All_Users_Programs = 0x17
Const $All_Users_Startup = 0x18
Const $All_Users_Desktop = 0x19
Const $Application_Data = 0x1a
Const $PrintHood = 0x1b
Const $Local_Settings_Application_Data = 0x1c
Const $All_Users_Favorites = 0x19
Const $Local_Settings_Temporary_Internet_Files = 0x20
Const $Cookies = 0x21
Const $Local_Settings_History = 0x22
Const $All_Users_Application_Data = 0x23
Const $Windows = 0x24
Const $System32 = 0x25
Const $Program_Files = 0x26
Const $My_Pictures = 0x27
Const $User_Profile = 0x28
Const $Common_Files = 0x2b
Const $All_Users_Templates = 0x2e
Const $Administrative_Tools = 0x2f
Const $Network_Connections = 0x31
Const $CD_Burning_Folder = 0x003b
func OpenSpecialFolder($Folder_ID)
local $ShellObj = ObjCreate("Shell.Application")
$ShellObj.Open($ShellObj.NameSpace($Folder_ID))
$ShellObj = 0
endfunc
func OpenSomething($filepath, $use_log_viewer=false)
debug("OpenSomething: =>" & $filepath & "<=" , @ScriptLineNumber, 7)
if not FileExists($filepath) then
debug($filepath & " not found!", @ScriptLineNumber, 1)
return false
endif
if IsDir($filepath) then
if not WinExists($filepath) then
debug("Opening: =>" & $filepath & "<=" , @ScriptLineNumber, 7)
Run("Explorer.exe """ & $filepath & '"')
else
WinActivate($filepath)
endif
else
local $user_editor = DeTokenizeString(IniRead($ini_path, $my_name, "editor", "notepad.exe"))
if $use_log_viewer then
local $log_viewer = DeTokenizeString(IniRead($ini_path, $my_name, "log_viewer", ""))
if FileExists($log_viewer) then $user_editor = $log_viewer
endif
if not Run($user_editor & " " & $filepath) then
debug("ERROR! I couldn't run:" & '"' & $user_editor & '"', @ScriptLineNumber, 7)
debug("You need to check your ini settings! ", @ScriptLineNumber, 7)
endif
endif
endfunc
func OpenDumpFile()
OpenSomething($dump_file)
endfunc
func OpenDataDir()
OpenSomething($data_dir)
endfunc
func EditIniFile()
ShellExecute($ini_path)
endfunc
func OpenLogFile()
ShellExecute($log_location)
endfunc
func DisplayTooltipMessage($message, $time=$DEF_MSG_TIME, $title=$my_name, $screen=false)
debug("", @ScriptLineNumber, 7)
debug("DisplayTooltipMessage(" & $message & "," & $time & "," & $title & ")", @ScriptLineNumber, 7)
local $x, $y
if not $screen then
local $mousepos = MouseGetPos()
$x = $mousepos[0]
$y = $mousepos[1]-16
else
$x = (@DesktopWidth/2)-StringLen($message)*3
$y = 32
endif
ToolTip($message, $x, $y, $title, 1)
debug("Displaying Message: =>" & $message & "<=" , @ScriptLineNumber, 7)
AdLibRegister("ClearMessage", $time)
endfunc
func ClearMessage()
debug("", @ScriptLineNumber, 7)
debug("ClearMessage()", @ScriptLineNumber, 7)
ToolTip("")
AdLibUnRegister("ClearMessage")
endfunc
Optional ToolTips
Set a tooltip or don't, dependant on the global $do_tooltips variable,
which you should set first, generally when gathering global prefs.
This is a drop-in replacement for GUICtrlSetTip() and will happily
work in this simple state.
$options: these numbers can be added together..
1 = Display as Balloon Tip
2 = Centre the tip horizontally under the control
And so on. See below this function for more details.
func GUICtrlSetTipOptional($control_ID, $tip_text=default, $title=default, $icon=default, $options=default)
if $do_tooltips = $OFF then return
if $tip_text = default then $tip_text = ""
if $title = default then $title = "Information:"
if $icon = default then $icon = $tip_icon
if $options = default then $options = $tip_style
local $style = 0, $hicon, $ret
$control_ID = GUICtrlGetHandle($control_ID)
if BitAND($options, 1) then $style = $TTS_BALLOON
$style = BitOr($style, $TTS_ALWAYSTIP)
local $hToolTip = _GUIToolTip_Create(0, $style)
$options = BitOr($options, $TTF_SUBCLASS, $TTF_IDISHWND)
_GUIToolTip_AddTool($hToolTip, 0, $tip_text, $control_ID, default, default, default, default, $options, 0)
_GUIToolTip_SetDelayTime($hToolTip, $TTDT_INITIAL, 400)
_GUIToolTip_SetDelayTime($hToolTip, $TTDT_AUTOPOP, $tooltip_time)
_GUIToolTip_SetDelayTime($hToolTip, $TTDT_RESHOW, 150)
if not StringInStr($icon, ".") then
_GUIToolTip_SetTitle($hToolTip, $title, $icon)
else
$hicon = DllStructCreate("ptr")
$icon = StringSplit($icon, ",")
if $icon[0] > 1 then
$ret = DllCall("shell32.dll", _
"uint", _
"ExtractIconExW", _
"wstr", $icon[$icon[0] - 1], _
"int", -1 * (Int($icon[$icon[0]])), _
"ptr", 0, _
"ptr", DllStructGetPtr($hicon), _
"uint", 1)
if not @error and $ret[0] then
$hicon = DllStructGetData($hicon, 1)
else
$hicon = 0
endif
_GUIToolTip_SetTitle($hToolTip, $title, $hicon)
DllCall("user32.dll", "none", "DestroyIcon", "handle", $hIcon)
endif
endif
return $hToolTip
endfunc
[optional] Flags that control the ToolTip display:
global Const $TTF_IDISHWND = 0x00000001 - Indicates that $iID is a window or control handle, instead of the ID of the tool
global Const $TTF_CENTERTIP = 0x00000002 - Centers the tooltip below the control specified by $iID
global Const $TTF_RTLREADING = 0x00000004 - Indicates that text will be displayed in opposite direction of the parent window
(see remarks)
global Const $TTF_SUBCLASS = 0x00000010 - Indicates that the control should subclass the tool's window
global Const $TTF_TRACK = 0x00000020 - Positions the tooltip window next to the tool to which it corresponds
global Const $TTF_ABSOLUTE = 0x00000080 - Positions the window at the same coordinates provided by TTM_TRACKPOSITION.
(see remarks)
global Const $TTF_TRANSPARENT = 0x00000100 - Causes the control to forward mouse messages to the parent window
global Const $TTF_PARSELINKS = 0x00001000 - Indicates that links in the control text should be displayed as links
global Const $TTF_DI_SETITEM = 0x00008000
Default = BitOr($TTF_SUBCLASS, $TTF_IDISHWND)
_GUIToolTip_Create STYLE
$TTS_ALWAYSTIP (0x01) - Indicates that the ToolTip control appears when the cursor is on a tool even if the
ToolTip control's owner window is inactive.
Without this style, the ToolTip appears only when the tool's owner window is active.
$TTS_NOPREFIX (0x02) - Prevents the system from stripping the ampersand character from a string.
Without this style the system automatically strips ampersand characters.
This allows an application to use the same string as both a menu item and as text in a ToolTip control.
$TTS_NOANIMATE (0x10) - Disables sliding ToolTip animation.
$TTS_NOFADE (0x20) - Disables fading ToolTip animation.
$TTS_BALLOON (0x40) - Indicates that the ToolTip control has the appearance of a cartoon "balloon"
$TTS_CLOSE (0x80) - Displays a close icon so that the tooltip can be cancelled
Default: $_TT_ghTTDefaultStyle = BitOr($TTS_ALWAYSTIP, $TTS_NOPREFIX)
Icon idx..
[optional] Set to one of the values below:.
$TTI_NONE (0) - No icon [default]
$TTI_INFO (1) - Information icon
$TTI_WARNING (2) - Warning icon
$TTI_ERROR (3) - Error Icon
$TTI_INFO_LARGE (4) - Large Information Icon
$TTI_WARNING_LARGE (5) - Large Warning Icon
$TTI_ERROR_LARGE (6) - Large Error Icon
func DeTokenizeString($string, $inipath=$ini_path, $section=$my_name, $pref="date_format")
debug("", @ScriptLineNumber, 7)
debug("DeTokenizeString(" & $string & ")", @ScriptLineNumber, 7)
if not $string then return $string
if not StringInStr($string, "@") then return $string
$string = DeUserTokenizeString($string)
if not StringInStr($string, "@") then return $string
$string = StringReplace($string, "@ClipBoard", ClipGet())
$string = DeTokenizeTimeStrings($string)
$string = ReplaceDateTimeToken($string)
$string = ReplaceDateToken($string, $inipath, $section, $pref)
$string = ReplacePathToken($string)
debug("DeTokenizeString() RETURNING: =>" & $string & "<=", @ScriptLineNumber, 7)
return $string
endfunc
func DeTokenizeTimeStrings($string)
$string = StringReplace($string, "@MSec", @MSec)
$string = StringReplace($string, "@Sec", @Sec)
$string = StringReplace($string, "@Min", @Min)
$string = StringReplace($string, "@Hour", @Hour)
$string = StringReplace($string, "@MDay", @MDay)
$string = StringReplace($string, "@Mon", @Mon)
$string = StringReplace($string, "@Year", @Year)
$string = StringReplace($string, "@WDay", @WDay)
$string = StringReplace($string, "@YDay", @YDay)
$string = StringReplace($string, "@Time", _NowTime())
return $string
endfunc
func ReplaceDateToken($string, $inipath=$ini_path, $section=$my_name, $pref="date_format")
$string = StringReplace($string, "@Date", GetUserDate($inipath, $section, $pref))
return $string
endfunc
func ReplaceDateTimeToken($string)
local $test = StringRegExp ($string, "(@DateTime([0-5]))", $STR_REGEXPARRAYMATCH)
if IsArray($test) and $test[0] and $test[1] then
local $datetime = _DateTimeFormat(_NowCalc(), Int($test[1]))
$string = StringReplace($string, $test[0], $datetime)
endif
return $string
endfunc
func GetUserDate($inipath=$ini_path, $section=$my_name, $pref="date_format")
return DeTokenizeTimeStrings(IniRead($inipath, $section, $pref, @Year & "-" & @Mon & "-" & @Mday))
endfunc
func ReplacePathToken($string)
if $data_dir <> "" then
$string = StringReplace($string, "@DataDir", $data_dir)
$string = StringReplace($string, "@ScriptsDir", $data_dir & "\Scripts")
endif
$string = StringReplace($string, "@Documents", @MyDocumentsDir)
$string = StringReplace($string, "@MyDocuments", @MyDocumentsDir)
$string = StringReplace($string, "@MyDocumentsdir", @MyDocumentsDir)
$string = StringReplace($string, "@Desktop", @DesktopDir)
$string = StringReplace($string, "@TempDir", @TempDir)
$string = StringReplace($string, "@ThisApp", @ScriptFullPath)
$string = StringReplace($string, "@KeyBind", @ScriptFullPath)
$string = StringReplace($string, "@Me", @UserName)
$string = StringReplace($string, "@User", @UserName)
$string = StringReplace($string, "@UserName", @UserName)
$string = StringReplace($string, "@ConfigEditor", GetParent(@ScriptFullPath) & "\" & $my_name & "Config.exe")
$string = StringReplace($string, "@HomeDir", @HomeDrive & @HomePath)
$string = StringReplace($string, "@HomeDrive", @HomeDrive)
$string = StringReplace($string, "@HomePath", @HomePath)
$string = StringReplace($string, "@ProgramFiles", @ProgramFilesDir)
$string = StringReplace($string, "@UserDir", @UserProfileDir)
$string = StringReplace($string, "@UserProfileDir", @UserProfileDir)
@outputfile", $outputfile)
return $string
endfunc
var_VARIABLE_NAME"
func DeUserTokenizeString($string)
debug("", @ScriptLineNumber, 7)
debug("DeUserTokenizeString(" & $string & ")", @ScriptLineNumber, 7)
debug_PrintArray($known_user_tokens, "cel.au3 :: $known_user_tokens:", @ScriptLineNumber, 7)
if not StringInStr($string, "@") then return $string
local $this_token, $maybe_token
local $split_string = StringSplit($string, "@")
for $i = 2 to $split_string[0]
$this_token = ""
$maybe_token = $split_string[$i]
debug("$maybe_token: =>" & $maybe_token & "<=", @ScriptLineNumber, 7)
$this_token = StringRegExpReplace($maybe_token, "(\w+).*", "\1", 1)
debug("Test $this_token: =>" & $this_token & "<=", @ScriptLineNumber, 7)
if InArray2D($known_user_tokens, $this_token, 0) and IsDeclared ("var_" & $this_token) then
debug("SUCCESS!! Found USER Variable: =>@" & $this_token & "<=", @ScriptLineNumber, 7)
local $token_val = Eval("var_" & $this_token)
debug("Assign USER Value: " & $this_token & " => " & $token_val & "<=", @ScriptLineNumber, 7)
$split_string[$i] = StringReplace($maybe_token, $this_token, $token_val)
else @@")!!.
debug("No Such User Token as @" & $this_token & "!", @ScriptLineNumber, 7)
$split_string[$i] = "@" & $maybe_token
endif
next
debug_PrintArray($split_string, "cel.au3 :: $split_string:", @ScriptLineNumber, 7)
$string = ArrayJoin($split_string, "")
debug("DeUserTokenizeString() RETURNING: =>" & $string & "<=", @ScriptLineNumber, 7)
return $string
endfunc
func TokenizeString($string, $path=true)
if not $string then return $string
if $path then $string = FixPathSlashes($string)
if $data_dir <> "" then
$string = StringReplace($string, $data_dir & "\Scripts", "@ScriptsDir")
$string = StringReplace($string, $data_dir, "@DataDir")
endif
$string = StringReplace($string, @DesktopDir, "@Desktop")
$string = StringReplace($string, @MyDocumentsDir, "@MyDocuments")
$string = StringReplace($string, @HomeDrive & @HomePath, "@HomeDir")
$string = StringReplace($string, @UserProfileDir, "@UserDir")
$string = StringReplace($string, @TempDir, "@TempDir")
$string = StringReplace($string, @ScriptFullPath, "@ThisApp")
$string = StringReplace($string, @ProgramFilesDir, "@ProgramFiles")
return $string
endfunc
func FixPathSlashes($string)
if StringInStr($string, ":(.+)([^ ])/", "\1\2\\")
$string = StringReplace($string, "\\", "\")
return $string
endfunc
\" then $string = StringTrimRight($string, 1)
my string")
my string")
my string") then ...
func CRT(byref $string, $character="\")
local $ret = 0, $char_num = StringLen($character)
if StringRight($string, $char_num) == $character then
while StringRight($string, $char_num) == $character
$ret += 1
$string = StringTrimRight($string, $char_num)
wend
endif
return $ret
endfunc
func CLT(byref $string, $character=" ")
local $ret = 0, $char_num = StringLen($character)
while StringLeft($string, $char_num) == $character
$ret += 1
$string = StringTrimLeft($string, $char_num)
wend
return $ret
endfunc
func CBT(byref $string, $character_left=default, $character_right=default)
if $character_left = default then $character_left = ","
if $character_right = default then $character_right = $character_left
local $ret = 0
$ret += CLT($string, $character_left)
$ret += CRT($string, $character_right)
return $ret
endfunc
").
func PadLeft($string, $pad_string=" ", $number=1)
$string = StringStripWS($string, 1)
$string = _StringRepeat($pad_string, $number) & $string
return $string
endfunc
func TestFileWrite($tmpfile)
local $t = FileWrite($tmpfile, "")
if $t <> 1 then return false
FileDelete($tmpfile)
return true
endfunc
AutoIt Arrays", where the first value is
func BubbleSort(byref $bs_array)
for $i = uBound($bs_array)-1 to 1 step -1
for $j = 2 to $i
if $bs_array[$j-1] > $bs_array[$j] then
local $temp = $bs_array[$j-1]
$bs_array[$j-1] = $bs_array[$j]
$bs_array[$j] = $temp
endif
next
next
return $bs_array
endfunc
words" would be 0. But it does work, and works great!
func InsertionSort(byref $is_array)
for $i = 1 to uBound($is_array)-1
local $index = $is_array[$i]
local $j = $i
while $j > 1 and $is_array[$j-1] > $index
$is_array[$j] = $is_array[$j-1]
$j -= 1
wend
$is_array[$j] = $index
next
return $is_array
endfunc
AutoIt Arrays" (first element it the total).
func ShellSort(byref $some_array)
local $increment = 1
while $increment > 0
for $i = 2 to uBound($some_array)-1
local $j = $i
local $temp = $some_array[$i]
while $j >= $increment and $some_array[$j-$increment] > $temp
$some_array[$j] = $some_array[$j-$increment]
$j = $j - $increment
wend
$some_array[$j] = $temp
next
if $increment/2 <> 0 then
$increment = int($increment/2)
elseif $increment = 1 then
$increment = 0
else
$increment = 1
endif
wend
return $some_array
endfunc
func MaxMax($num1, $num2, $num3=1.7E-308)
if not IsNumber($num1) or not IsNumber($num2) or not IsNumber($num3) then return
if $num1 > $num2 then
if $num3 > $num1 then return $num3
return $num1
else
if $num3 > $num2 then return $num3
return $num2
endif
endfunc
func MinMin($num1, $num2, $num3=1.7E+308)
if not IsNumber($num1) or not IsNumber($num2) or not IsNumber($num3) then return
if $num1 > $num2 then
if $num3 < $num2 then return $num3
return $num2
else
if $num3 < $num1 then return $num3
return $num1
endif
endfunc
func printf($format, $var1, $var2=-1, $var3=-1)
if $var2=-1 then
return StringFormat($format, $var1)
else
return StringFormat($format, $var1, $var2, $var3)
endif
endfunc
func StringRepeat($string, $count)
$count = Int($count)
if not $count then return ""
if not StringLen($string) then return SetError(-1, 0, "Invalid Parameters sent.")
local $return
while $count
$return &= $string
$count -= 1
wend
return $return
endfunc
GUIDataSeparatorChar", "") ; A Record Separator, Chr(30).
RS" in it (or similar cute
; Notepad++ is free! >> https:
func Str2LV($string)
return StringReplace($string, "|", "ǀ")
endfunc
func LV2Str($string)
return StringReplace($string, "ǀ", "|")
endfunc
ǀfoo" is not equal to "|foo" when, you know, they LOOK THE SAME ...
func CleanPath($string, $chr="~")
", "_")
$string = StringReplace($string, "|", $chr)
$string = StringReplace($string, '"', "'")
$string = StringReplace($string, ":", $chr)
$string = StringReplace($string, "*", $chr)
$string = StringReplace($string, "/", $chr)
$string = StringReplace($string, "\", $chr)
$string = StringReplace($string, ">", $chr)
$string = StringReplace($string, "<", $chr)
$string = StringReplace($string, "?", $chr)
return $string
endfunc
func CleanPrefName($string, $translate_spaces=true)
$string = CleanPath($string)
if $translate_spaces then $string = StringReplace($string, " ", "_")
$string = StringReplace($string, '"', "_")
$string = StringReplace($string, "'", "_")
$string = StringReplace($string, "=", "_")
$string = StringReplace($string, "[", "_")
$string = StringReplace($string, "]", "_")
$string = StringReplace($string, "(", "_")
$string = StringReplace($string, ")", "_")
$string = StringReplace($string, ".", "_")
$string = StringReplace($string, ",", "_")
$string = StringReplace($string, "-", "_")
return $string
endfunc
func BaseName($bn_path)
$bn_path = StringReplace($bn_path, "/", "\")
CRT($bn_path)
local $parts = StringSplit($bn_path, "\")
local $bn_tmp = $parts[$parts[0]]
CRT($bn_tmp, ":")
return $bn_tmp
endfunc
func GetParent($gp_dir)
local $gp_full_path = StringSplit($gp_dir, "\")
return StringTrimRight($gp_dir, StringLen($gp_full_path[$gp_full_path[0]]) + 1) \"
endfunc
txt"
" string
func GetExtension($some_name)
local $parts = StringSplit($some_name, ".")
local $e = $parts[$parts[0]]
." was not found - extensionless file, possibly in a path with a dot..
if $e <> $some_name and not StringInStr($e, "\") then
return $e
else
return ""
endif
endfunc
.")
func RemoveExtension($some_name)
local $add = 0
if StringInStr(BaseName($some_name), ".") then $add = 1
return StringTrimRight($some_name, StringLen(GetExtension($some_name)) + $add)
endfunc
func CleanName($some_name)
return RemoveExtension(BaseName($some_name))
endfunc
func SimpleProper($string)
local $first_chr = Asc(StringLeft($string, 1))
if $first_chr < 97 or $first_chr > 122 then return $string
$string = Chr($first_chr-32) & StringMid($string, 2)
return $string
endfunc
", A2RBool($always_on_top))
func A2RBool($autoit_boolean)
if $autoit_boolean == $OFF then return 0
return 1
endfunc
func MakeTheParents(byref $file_path)
if not FileExists(GetParent($file_path)) then
DirCreate(GetParent($file_path))
endif
endfunc
func MakeAFile(byref $file_path)
if not FileExists($file_path) then
local $target_file = FileOpen($file_path, 2)
FileClose($target_file)
endif
endfunc
AppendFileData()
Append the contents of $data_file to the end of $target_file..
$flags are the usual FileOpen flags, which apply to opening $data_file.
Obviously you don't want to send any WRITE flags. Nincompoop!
But this is handy for forcing binary reading, or whatever..
Useful flags:
$FO_READ (0) = Read mode (default) (Auto-Detects Encoding)
$FO_BINARY (16) = Force binary (byte) data mode.
$FO_UNICODE or $FO_UTF16_LE (32) = Use Unicode UTF16 Little Endian reading and writing mode.
$FO_UTF16_BE (64) = Use Unicode UTF16 Big Endian reading and writing mode.
$FO_UTF8 (128) = Use Unicode UTF8 (with BOM) reading and writing mode.
$FO_UTF8_NOBOM (256) = Use Unicode UTF8 (without BOM) reading and writing mode.
$FO_ANSI (512) = Use ANSI reading and writing mode.
$FO_UTF16_LE_NOBOM (1024) = Use Unicode UTF16 Little Endian (without BOM) reading and writing mode.
$FO_UTF16_BE_NOBOM (2048) = Use Unicode UTF16 Big Endian (without BOM) reading and writing mode.
$FO_FULLFILE_DETECT (16384) = When opening for reading and no BOM is present, use the entire file to
determine if it is UTF8 or UTF16. If this is not used then only the
initial part of the file (up to 64KB) is checked for performance reasons.
func AppendFileData($target_file, $data_file, $flags=0)
$data_file = FileOpen($data_file, $flags)
local $file_data = FileRead($data_file)
FileClose($data_file)
$target_file = FileOpen($target_file, 1)
local $return = FileWrite($target_file, $file_data)
FileClose($target_file)
return $return
endfunc
I:\temp\test\musk.mp3" >> returns: I
func GetWinDrive($gd_path)
select
case StringMid($gd_path, 2, 1) == ":"
return StringLeft($gd_path, 1)
case else
return ""
endselect
endfunc
func LnkToReal($file)
if GetExtension($file) = "lnk" then
local $lnk_arr = FileGetShortCut($file)
if IsArray($lnk_arr) and FileExists($lnk_arr[0]) then return $lnk_arr[0]
else
return $file
endif
return false
endfunc
func DateToDayOfWeekISO($iYear, $iMonth, $iDay)
local $i_aFactor, $i_yFactor, $i_mFactor, $i_dFactor
$i_aFactor = Int((14 - $iMonth) / 12)
$i_yFactor = $iYear - $i_aFactor
$i_mFactor = $iMonth + (12 * $i_aFactor) - 2
$i_dFactor = Mod($iDay + $i_yFactor + Int($i_yFactor / 4) - Int($i_yFactor / 100) _
+ Int($i_yFactor / 400) + Int((31 * $i_mFactor) / 12), 7)
if $i_dFactor >= 1 then return $i_dFactor - 1
return 6
endfunc
func DateTimeString($msec=false, $sec=true, $time=true)
local $addm, $adds
if $time then $time = " @ " & @Hour & "." & @Min
if $sec then $adds = ":" & @Sec
if $msec then $addm = "." & @Msec
return @Year & "-" & @Mon & "-" & @Mday & $time & $adds & $addm
endfunc
func FileDateStamp()
return @Year & "-" & @Mon & "-" & @Mday & "@" & @Hour & "." & @Min
endfunc
func FolderIsEmpty($fie_folder)
if not FileExists($fie_folder) then return 2
local $ret = 0
local $fie_search_files = FileFindFirstFile($fie_folder & "\*.*")
if $fie_search_files = -1 then
if @error = 1 then
$ret = 1
else
$ret = 2
endif
endif
FileClose($fie_search_files)
return $ret
endfunc
func IsWild($string)
if StringInStr($string, "*") or StringInStr($string, "?") then return true
return false
endfunc
func CheckDirWild(byref $pathstring)
if IsDir($pathstring) and not IsWild($pathstring) then
$pathstring &= "\*"
endif
local $testfiles = FileFindFirstFile($pathstring)
if $testfiles = -1 then return false
return true
endfunc
func IsDir($some_path)
return StringInStr(FileGetAttrib($some_path), "D")
endfunc
." dot)
func ReadDir($folder, $extension, $full_filename="")
local $files[1]
local $new_array[2]
local $filename = "*."
if $full_filename then
$filename = $full_filename
$extension = ""
else
CLT($extension, ".")
endif
local $init_dir = $folder & "\" & $filename & $extension
search handle" of all the *.$extension files in the folder
local $search_files = FileFindFirstFile($init_dir)
if $search_files = -1 then
FileClose($search_files)
$search_files = FileFindFirstFile($init_dir)
endif
local $i = 1
do
local $tmp = FileFindNextFile($search_files)
$files[$i-1] = $tmp
$i += 1
redim $files[$i]
until @error
FileClose($search_files)
$i = 2
for $this_file in $files
local $entry = StringStripWS($this_file, 3)
if $entry then
redim $new_array[$i]
$new_array[0] = $i-1
$new_array[$i-1] = $entry
$i = $i + 1
endif
next
$files = 0
if $new_array[0] = "" then return 0
return $new_array
endfunc
AutoIt Array").
C:\Program Files", "*.reg,*.ini,*.cfg")
$top_level_only" tells RecurseDir() to only
dump file" to dump (log) the paths of all matched files; for debugging only,
$return_dirs" which
&=" operator. Those wee differences mount up.
func RecurseDir($dir, $mask, $top_level_only=false, $dump="", $return_dirs=false, $mx=1000000)
local $n_dirnames[$mx]
local $n_dircount = 0
local $n_file
local $n_search
local $n_tfile
local $file_array
local $filenames
local $dircount = 1
\" on the end of the given directory, remove that..
CRT($dir)
debug("$dir: =>" & $dir & "<=", @ScriptLineNumber, 7)
$n_dirnames[$dircount] = $dir
if not FileExists($dir) then return 0
while $dircount > $n_dircount
$n_dircount += 1
$n_search = FileFindFirstFile($n_dirnames[$n_dircount] & "\*.*")
if @Error then debug("@Error: =>" & @Error & "<=", @ScriptLineNumber, 7)
debug("$n_search: =>" & $n_search & "<=", @ScriptLineNumber, 7)
while true
$n_file = FileFindNextFile($n_search)
if @Error then exitloop
if $n_file = "." or $n_file = ".." then continueloop
$n_tfile = $n_dirnames[$n_dircount] & "\" & $n_file
if StringInStr(FileGetAttrib($n_tfile ), "D") and not $top_level_only then
$dircount += 1
$n_dirnames[$dircount] = $n_tfile
endif
wend
FileClose($n_search)
if StringInStr($mask, ",", 2) then
local $mask_array = StringSplit($mask, ",")
else
local $mask_array[2] = [1, $mask]
endif
for $mask_c = 1 to $mask_array[0]
$n_search = FileFindFirstFile($n_dirnames[$n_dircount] & "\" & $mask_array[$mask_c] )
if $n_search = -1 then continueloop
while true
$n_file = FileFindNextFile($n_search)
if @Error then exitloop
if $n_file = "." or $n_file = ".." then continueloop
$n_tfile = $n_dirnames[$n_dircount] & "\" & $n_file
if not StringInStr(FileGetAttrib( $n_tfile ), "D") then
$filenames &= $n_tfile & @LF
endif
wend
FileClose($n_search)
next
wend
if $return_dirs then
local $tmp_str = ""
local $i = 1
while $n_dirnames[$i] <> ""
$tmp_str &= $n_dirnames[$i] & "|"
$i += 1
wend
$tmp_str = StringTrimRight($tmp_str, 1)
$n_dirnames = StringSplit($tmp_str, "|")
return $n_dirnames
endif
$filenames = StringTrimRight($filenames, 1)
if $filenames = "" then return 0
$file_array = StringSplit($filenames, @LF)
if $dump then
local $dumpfile = FileOpen($dump, 2)
FileWrite($dumpfile, $filenames)
FileClose($dumpfile)
endif
return($file_array)
endfunc
IniReadCheckBoxValue()
Slightly altered for BlobDrop and its "tristate" checkboxes..
This function "transforms" an AutoIt or human unchecked value (4 or 0,
respectively), into plain old 4, which AutoIt can understand. this
function is intended as a drop-in replacement for the IniRead command,
simply replace the function name. Of course, it's only useful when
reading checkbox values, e.g..
$big_switch = IniReadCheckBoxValue($ini_path, $my_name, "big_switch", $GUI_UNCHECKED)
However I've gotten into the habit of using $GUI_CHECKED and
$GUI_UNCHECKED as general booleans, which has proven to be very
effective, especially when coupled with these two functions. I have them
set to $ON and $OFF.
global const $ON = $GUI_CHECKED
global const $OFF = $GUI_UNCHECKED
Why?
Windows uses 1 as the value for checked checkboxes, and 4 as the value
for unchecked checkboxes.* This makes passing the values directly in and
out of ini files undesirable, because "4" is not a logical value, and
most humans would expect it to be 0 (zero). The following two functions
act as interface between the program and the ini file, making sense of
the "human" equivalents. Other "human" values are also understood, just
in case.
Using these custom booleans enables us to pass values directly back-and-
forth between user settings and GUI Controls and tray menu items DIRECTLY,
e.g..
TrayItemSetState($tray_menu, $some_pref)
func IniReadCheckBoxValue($rcbv_inifile, $rcbv_section, $rcbv_key, $rcbv_default, $three_state=false)
local $ircbv_val = IniRead($rcbv_inifile, $rcbv_section, $rcbv_key, "---")
if $ircbv_val = "---" then $ircbv_val = $rcbv_default
if $three_state and $ircbv_val = "" then return $GUI_INDETERMINATE
switch $ircbv_val
case $GUI_UNCHECKED
return $GUI_UNCHECKED
case "false", "off", "no", "not", "nope", "nay", "nay!", "nah", "nah!", "no way!", _
"no sir!", "negative", "neg", "no!", "disable", "disabled"
return $GUI_UNCHECKED
case "true", "on", "yes", "yes!", "yay", "yay!", "yup", "hell yes!", "indeed", _
"yes sir!", "yessir!", "affirmative", "cool", "enable", "enabled"
return $GUI_CHECKED
case "2", 2, "unset", "-", "maybe"
return $GUI_INDETERMINATE
case "0"
return $GUI_UNCHECKED
case "1", $GUI_CHECKED
return $GUI_CHECKED
case else
return $ircbv_val
endswitch
endfunc
no", "off", or whatever, by passing the optional 5th parameter..
func IniWriteCheckBoxValue($wcbv_inifile, $wcbv_section, $wcbv_key, $wcbv_val, $tru_val="true", $fal_val="false")
debug("IniWriteCheckBoxValue() : "&$wcbv_inifile&" : "&$wcbv_section&" : "&$wcbv_key&" : "&$wcbv_val, @ScriptLineNumber, 8)
switch $wcbv_val
case $GUI_CHECKED
$wcbv_val = $tru_val
case $GUI_UNCHECKED
$wcbv_val = $fal_val
case $GUI_INDETERMINATE
$wcbv_val = ""
endswitch
if $wcbv_val then
IniWrite($wcbv_inifile, $wcbv_section, $wcbv_key, $wcbv_val)
else
unset" proper!
IniDelete($wcbv_inifile, $wcbv_section, $wcbv_key)
endif
endfunc
func ProcessReadHumanCheckBoxValue($some_string)
switch $some_string
case $OFF
return $OFF
case "false", "off", "n", "no", "not", "nope", "nay", "nay!", "nah", "nah!", "no way!", "no sir!", "negative", "neg", "no!"
return $OFF
case "true", "on", "y", "yes", "yes!", "yay", "yay!", "yup", "hell yes!", "indeed", "yes sir!", "yessir!", "affirmative", "cool"
return $ON
case "0"
return $OFF
case $ON
return $ON
case else
if StringLeft($some_string, 1) = "y" then
return $ON
else
return $OFF
endif
endswitch
endfunc
enabled"
disabled"
func ProcessWriteHumanCheckBoxValue($some_string, $on_str=$str_enabled, $off_str=$str_disabled, $indet_str="unset")
switch $some_string
case $ON
return $on_str
case $OFF
return $off_str
case $GUI_INDETERMINATE, ""
return $indet_str
case else
return $some_string
endswitch
endfunc
func Human($some_string, $on_str=$str_enabled, $off_str=$str_disabled,$indet_str="unset")
return ProcessWriteHumanCheckBoxValue($some_string, $on_str, $off_str, $indet_str)
endfunc
func IniKeyExists(byref $search_array, $search_string)
if not IsArray($search_array) then
return false
endif
for $i = 1 to $search_array[0][0]
if $search_string = $search_array[$i][0] then
return $search_array[$i][1]
endif
next
return false
endfunc
func CreateEmptyIniSection($inipath, $inisection)
IniWrite($inipath, $inisection, "", "")
IniDelete($inipath, $inisection, "")
endfunc
UpdateIniFile()
Add any new prefs from our master ini file.
Keep all user's old prefs (see forced_settings for exceptions).
Optionally clean out all info comments from new ini file.
Optionally copy certain sections "RAW".
UpdateIniFile([clean comments {BOOL}[, forced prefs {STRING(comma-delimited list)}[, Raw Section {STRING}]]])
NOTE: This function isn't exactly 100% portable. Your default ini file MUST
be:
./Resources/Default.ini
In other words a folder next to this source called "resource" with
"Default.ini" inisde it. You must also insure that $ini_path and $my_name
are correctly set.
The first parameter controls whether nor not the updated ini file will
contain all the comments from the master ini file. For new users, these
are probably very handy. For old-hats, they are more likely annoying. So
let the user disable them, if required. Send $ON or $OFF, e.g..
local $clean_ini = IniReadCheckBoxValue($ini_path, $my_name, "clean_ini", $OFF)
if not $installed_ini then UpdateIniFile($clean_ini)
If you have settings in your master ini file that you MUST put in the
user's ini, overwriting their own setting (CAREFUL!) add the names of
those settings to $forced_settings, in a comma-delimited list, e.g..
UpdateIniFile(default, "commands,click_commands")
The final parameter, $raw_section is the name of any sections you would
like written (from the user's ini) as-is. This is useful for sections which
have more than one preference with the exact same name, e.g..
[Window Triggers]
Downloads=WinMove(@DesktopWidth/5+4,@DesktopHeight/4-32,@DesktopWidth/1.25,@DesktopHeight/2+64)
Chrome=^t
Research=WinMove(0,12,@DesktopWidth/2,@DesktopHeight-20)
Downloads={End}
Using the normal IniWrite mechanism, the second "Downloads" would overwrite
the first, basically destroying the setting.
UpdateIniFile($clean_ini, default, "Window Triggers")
", $raw_section="")
"
"
Update Ini File: " & $ini_path & $LOG_LF, @ScriptLineNumber, 7);debug
version", 0)
,")
\" & $my_name & ".new.ini"
./Resources/Default.ini", $tmp_ini, 1)
;" then
Existing SECTION:: =>" & $existing_sections[$a] & "<=", @ScriptLineNumber, 7);debug
$section:", @ScriptLineNumber, 7);debug
[@date] app.ini"
\[" & @Year & "-" & @Mon & "-" & @Mday & "@" & _
." & @Min & "]_v" & $old_version & "_" & $my_name & ".ini")
version", $new_version)
func UpdateIniFile($new_version, $clean_comments=$OFF, $forced_settings="", $no_new_prefs="")
debug("", @ScriptLineNumber, 7)
debug("UpdateIniFile(" & $new_version & "," & $clean_comments & "," & $forced_settings & ")", @ScriptLineNumber, 7)
if $clean_comments = default then $clean_comments = $OFF
if $forced_settings = default then $forced_settings = ""
if $no_new_prefs = default then $no_new_prefs = ""
debug("Update Ini File: " & $ini_path & $LOG_LF, @ScriptLineNumber, 7)
local $old_version = IniRead($ini_path, $my_name, "version", 0)
local $vcomp = _VersionCompare($new_version, $old_version)
switch $vcomp
case 0, -1
return false
endswitch
[@date] app.ini"
FileCopy($ini_path, GetParent($ini_path) & "\[" & @Year & "-" & @Mon & "-" & @Mday & "@" & _
@Hour & "." & @Min & "][v" & $old_version & "]" & $my_name & ".ini")
if $forced_settings then
$forced_settings = StringSplit($forced_settings, ",")
endif
local $wrote = 0
if not FileExists($ini_path) then
FileInstall($my_name & ".ini", $ini_path)
else
local $tmp_ini_path = @TempDir & "\TEMP_.ini"
FileInstall($my_name & ".ini", $tmp_ini_path)
local $existing_sections = IniReadSectionNames($tmp_ini_path)
if IsArray($existing_sections) then
for $i = 1 to $existing_sections[0]
local $current_section = $existing_sections[$i]
debug("SECTION:: =>" & $current_section & "<=", @ScriptLineNumber, 7)
if $current_section <> $no_new_prefs then
debug("Writing prefs to:: =>" & $current_section & "<=", @ScriptLineNumber, 7)
local $this_section_data = IniReadSection($tmp_ini_path, $current_section)
debug_PrintArray($this_section_data, "cel.au3 :: $this_section_data:", @ScriptLineNumber, 7)
if IsArray($this_section_data) then
for $k = 1 to $this_section_data[0][0]
local $current_setting = $this_section_data[$k][0]
debug("$current_setting: =>" & $current_setting & "<=", @ScriptLineNumber, 7)
local $user_value = IniRead($ini_path, $current_section, $current_setting, "")
local $default_value = IniRead($tmp_ini_path, $current_section, $current_setting, "")
debug("$user_value: =>" & $user_value & "<=", @ScriptLineNumber, 7)
debug("$default_value: =>" & $default_value & "<=", @ScriptLineNumber, 7)
if not $user_value or InArray($forced_settings, $current_setting) then
$wrote += 1
IniWrite($ini_path, $current_section, $current_setting, $default_value)
endif
next
endif
endif
next
endif
endif
FileDelete($tmp_ini_path)
if $clean_comments = $ON then
if _FileReadToArray($ini_path, $file_array) then
for $i = 1 to $file_array[0]
local $line = StringStripWS($file_array[$i], 3)
if StringLeft($line, 1) <> "new_install")
IniWrite($ini_path, $my_name, "version", $new_version)
debug($ini_path & " updated. Wrote: " & $wrote & " ini settings", @ScriptLineNumber, 1)
endfunc
new" section to the bottom of the ini
func BetterIniRenameSection($inifile, $old_name, $new_name)
debug("", @ScriptLineNumber, 8)
debug("cel.au3 :: BetterIniRenameSection($inifile=" & $inifile & ", $old_name=" & $old_name & ", $new_name=" & $new_name & "):", @ScriptLineNumber, 8)
local $existing_sections = IniReadSectionNames($inifile)
if not InArray($existing_sections, $old_name) then return SetError(1, 0, false)
local $inifile_contents = FileRead($inifile)
local $new_ini_string = StringReplace($inifile_contents, "[" & $old_name & "]", "[" & $new_name & "]")
local $temp_inifile = _WinAPI_GetTempFileName(@TempDir, "cel")
FileDelete($temp_inifile)
FileWrite($temp_inifile, $new_ini_string)
local $compare1 = ArrayJoin($existing_sections, "|")
$compare1 = StringReplace($compare1, $old_name, "|")
local $new_sections = IniReadSectionNames($temp_inifile)
local $compare2 = ArrayJoin($new_sections, "|")
$compare2 = StringReplace($compare2, $new_name, "|")
if StringCompare($compare1, $compare2) == 0 then
BackupFile($inifile)
FileMove($temp_inifile, $inifile, 1)
return true
endif
return SetError(2, 0, false)
endfunc
func TogglePref(byref $variable)
if $variable = $ON then
$variable = $OFF
else
$variable = $ON
endif
endfunc
func SaveTrayPref($tray_control, $pref_var, $pref_name)
IniWriteCheckBoxValue($ini_path, $my_name, $pref_name, $pref_var)
TrayItemSetState($tray_control, $pref_var)
endfunc
func InArray(byref $ia_array, $ia_string, $match_case=false)
if not IsArray($ia_array) then return false
local $ia_limit = UBound($ia_array) - 1
for $i = 1 to $ia_limit 1"
switch $match_case
case true
if $ia_string == $ia_array[$i] then return $i
case false
if $ia_string = $ia_array[$i] then return $i
endswitch
next
return false
endfunc
func InArrayValue(byref $ia_array, $ia_string)
if not IsArray($ia_array) then return SetError(1, -8, false)
local $ia_limit = UBound($ia_array) - 1
for $i = 1 to $ia_limit
if StringInStr($ia_array[$i], $ia_string) then return $i
next
return false
endfunc
column marker" is simply a delimiter within the value which
path/name.ext") inside a
path/name.ext|179|20080621114934".
func InArrayColumn(byref $ia_array, $ia_string, $col=1, $marker="*")
if not IsArray($ia_array) then return SetError(1, -8, false)
local $ia_limit = UBound($ia_array) - 1
for $i = 1 to $ia_limit
local $columns = StringSplit($ia_array[$i], $marker, $STR_ENTIRESPLIT)
if $columns[$col] == $ia_string then return $i
next
return false
endfunc
AutoIt array" with a single data element, that is, two elements; $dummy_array[1]
func MakeDummyArray($regular_string)
local $dummy_array[2] = [1, $regular_string]
return $dummy_array
endfunc
associated" data. See also Associative Array
func OneToTwoDArray($array)
debug("OneToTwoDArray()", @ScriptLineNumber, 9)
local $new_array[1][2]
$new_array[0][0] = $array[0]
for $e = 1 to $array[0]
redim $new_array[$e+1][2]
$new_array[$e][0] = $array[$e]
$new_array[$e][1] = ""
debug_PrintArray($new_array, "cel.au3 :: 1D->2D Array:", @ScriptLineNumber, 9)
next
debug_PrintArray($new_array, "cel.au3 :: 1D->2D RETURNING Array:", @ScriptLineNumber, 9)
return $new_array
endfunc
") from each key or value. Handy for trimming @Macros and such.
func TwoD2OneDArray(byref $Array2D, $keys=false, $strip="")
if not IsArray($Array2D) then return false
local $array[$Array2D[0][0]+1]
$array[0] = $Array2D[0][0]
for $i = 1 to $Array2D[0][0]
if $keys then local $key = $Array2D[$i][0]
local $value = $Array2D[$i][1]
if $strip then
if $keys then $key = StringReplace($key, $strip, "")
$value = StringReplace($value, $strip, "")
endif
if $keys then
$array[$i] = $key
else
$array[$i] = $value
endif
next
return $array
endfunc
func TwoDCol2OneDArray($Array2D, $col=0)
debug("TwoDCol2OneDArray()", @ScriptLineNumber, 9)
debug_PrintArray($Array2D, "cel.au3 :: $Array2D:", @ScriptLineNumber, 7)
if not IsArray($Array2D) then return false
local $array[$Array2D[0][0]+1]
$array[0] = $Array2D[0][0]
for $i = 1 to $Array2D[0][0]
$array[$i] = $Array2D[$i][$col]
debug_PrintArray($array, "cel.au3 :: $array:", @ScriptLineNumber, 9)
next
debug_PrintArray($array, "cel.au3 :: 2D->1D RETURNING Array:", @ScriptLineNumber, 9)
return $array
endfunc
func TwoD22OneDArrays(byref $Array2D)
if not IsArray($Array2D) then return false
local $array[$Array2D[0][0]+1]
local $array2[$Array2D[0][0]+1]
$array[0] = $Array2D[0][0]
$array2[0] = $Array2D[0][0]
for $i = 1 to $Array2D[0][0]
$array[$i] = $Array2D[$i][0]
$array2[$i] = $Array2D[$i][1]
next
local $newarray[2] = [$array, $array2]
return $newarray
endfunc
ArrayAdd()
Add a single item to an AutoIt array..
ArrayAdd() automatically increases the [0] index, but DOES NOT rely upon it.
Enable the third parameter to NOT add items which already exist in the
array.
Set the fourth parameter to true, and when an item is added which
already exists, the array is re-indexed, moving the entry to the END of
the array. In other words, it becomes the "most recent entry".
func ArrayAdd(byref $array, $item, $unique=false, $update=false)
if not IsArray($array) then return
local $size = UBound($array)
if $unique and $update = false then
if InArray($array, $item) then return
endif
if $update then
local $idx = InArray($array, $item)
if $idx then
for $i = $idx to $size-2
$array[$i] = $array[$i+1]
next
$size -= 1
endif
endif
redim $array[$size+1]
$array[$size] = $item
$array[0] = $size
endfunc
ArrayRemove()
If $item is a number, that index is removed, otherwise the array is
searched for values matching {String} $item and that key is removed.
Remaining elements are moved down to fill the gap and the resulting
array is one element shorter. The [0] count element is updated with
the new total.
Returns true is changes were made, false otherwise.
func ArrayRemove(byref $array, $item)
debug("", @ScriptLineNumber, 7)
debug("ArrayRemove(" & $item & ")", @ScriptLineNumber, 7)
if not IsArray($array) then return SetError(1, 0, false)
debug_PrintArray($array, "cel.au3 :: Remove from this: $array:", @ScriptLineNumber, 7)
local $match = false
local $total_rows = UBound($array, $UBOUND_ROWS)-1
debug("$total_rows: =>" & $total_rows & "<=", @ScriptLineNumber, 7)
if IsNumber($item) then
$match = $item
else
for $i = 1 to $total_rows
debug("$array[$i] =>" & $array[$i] & "<=", @ScriptLineNumber, 7)
if $array[$i] == $item then
$match = $i
exitloop
endif
next
endif
if $match then
for $k = $match to $total_rows-1
debug("$array[$k+1]: =>" & $array[$k+1] & "<=", @ScriptLineNumber, 7)
$array[$k] = $array[$k+1]
next
Redim $array[$total_rows]
$array[0] = $total_rows-1
return true
endif
endfunc
func ArrayDelete(byref $array, $item)
return ArrayRemove($array, $item)
endfunc
Very simple 2D array add.
Param 1: The array to add to.
Param 2: A pipe delimited list of values.
ArrayAdd2D($my_array, "foo|bar|sheep|shoe")
If your list has less items than there are columns, the remaining
columns will be empty. If you list contains more items than there are
columns, the extra items will be ignored. It's okay to send blank
vaules.
ArrayAdd2D($my_array, "||foo||bar")
The index value $my_array[0][0] is automatically updated.
Set the 3rd parameter to true to ensure no duplicate entries. Only the
first column is checked.
Set the 4th parameter to true to replace existing values, otherwise if a
key already exists, it will we left alone.
ArrayAdd2D($array, "foo|bar|sheep|shoe", $unique, $replace_existing)
func ArrayAdd2D(byref $array, $items, $unique=false, $replace=false, $delim="|")
if not IsArray($array) then return SetError(1, 0, false)
$items = StringSplit($items, $delim, $STR_ENTIRESPLIT)
debug("$items[1]: =>" & $items[1] & "<=", @ScriptLineNumber, 7)
local $exists = InArray2D($array, $items[1])
debug("$exists: =>" & $exists & "<=", @ScriptLineNumber, 7)
if $exists and $unique and not $replace then return SetError(2, 0, false)
if not $items[1] then $exists = false
local $rows
if $exists and $replace then $rows = $exists
local $columns = UBound($array, $UBOUND_COLUMNS)
if not $exists then
$rows = UBound($array, $UBOUND_ROWS)
redim $array[$rows+1][$columns]
$array[0][0] += 1
debug("$array[0][0]: =>" & $array[0][0] & "<=", @ScriptLineNumber, 7)
endif
for $i = 1 to $items[0]
$array[$rows][$i-1] = $items[$i]
if $i = $columns then exitloop
next
return true
endfunc
ArrayRemove2D(byref $array, $item, $column)
Remove the first row of a 2D array where $array[row][$column] matches
$item.
Supply the array to search, a string to search for (This is a
CaSe-sEnsItiVe search), and the column to search in for that string.
When a match is found, the entire row is removed and the remaining rows
are re-indexed from the removal point and the array is one row shorter.
The count [0][0] element is not relied upon when removing rows, but it
is updated with the correct new total, which will usually be the old
total minus one.
Returns true if changes were made, otherwise false.
func ArrayRemove2D(byref $array, $item, $column)
debug("", @ScriptLineNumber, 7)
debug("ArrayRemove2D([" & $item & "," & $column & "])", @ScriptLineNumber, 7)
if not IsArray($array) then return SetError(1, 0, false)
debug_PrintArray($array, "cel.au3 :: Remove from: $array:", @ScriptLineNumber, 7)
local $total_columns = UBound($array, $UBOUND_COLUMNS)
local $total_rows = UBound($array, $UBOUND_ROWS)-1
debug("$total_columns: =>" & $total_columns & "<=", @ScriptLineNumber, 7)
debug("$total_rows: =>" & $total_rows & "<=", @ScriptLineNumber, 7)
for $i = 1 to $total_rows
debug("$array[$i][$column]: =>" & $array[$i][$column] & "<=", @ScriptLineNumber, 7)
if $array[$i][$column] == $item then
for $k = $i to $total_rows-1
for $m = 0 to $total_columns-1
debug("$array[$k+1][$m]: =>" & $array[$k+1][$m] & "<=", @ScriptLineNumber, 7)
$array[$k][$m] = $array[$k+1][$m]
next
next
Redim $array[$total_rows][$total_columns]
$array[0][0] = $total_rows-1
return true
endif
next
endfunc
InArray2D($array, $search_string, $search_column)
Very Simple 2D Array Search.
Suppy:
param 1: The 2D Array to search.
param 2: The string to search for (CaSe-sEnsItiVe match).
param 3: (optional) The column to search.
If this is omitted, all columns are searched.
Returns the number of the row which contained the string as one of its
column's values. Otherwise returns false.
If you can suppply the search column, it will increase speed slightly.
Column numbering begins at zero (0). Example..
global $array[1][7]
ArrayAdd2D($array, "|apple|pear||orange")
ArrayAdd2D($array, "dog|cat|cow|pig|goat")
ArrayAdd2D($array, "||||nut|seed|")
local $row = InArray2D($array, "pig", 3)
if $row then debug("PIG IN THE DUNGEON!!!", @ScriptLineNumber, 7)
Will print out "PIG IN THE DUNGEON!!!"
$row will equal 2.
func InArray2D(byref $array, $string, $search_column=false)
if not IsArray($array) then return false
local $rows = UBound($array, $UBOUND_ROWS) - 1
local $columns = UBound($array, $UBOUND_COLUMNS)
for $i = 1 to $rows
if $search_column then
if $string == $array[$i][$search_column] then return $i
else
for $k = 0 to $columns-1
if $string == $array[$i][$k] then return $i
next
endif
next
return false
endfunc
func CommaDelimListToArray(byref $my_list)
CBT($my_list, ",")
$my_list = StringSplit(StringReplace($my_list, ",,", ","), ",")
endfunc
;
", @CR, @TAB, @CR, @LF, etc.)
func FileReadIntoArray($TmpFile, byref $aArray, $iFlag = 0)
local $ArrayCount, $RegExp = "(?:\r\n|\n|\r)([^\r\n]*)"
local $hFileOpen = FileOpen($TmpFile, 0)
if $hFileOpen = -1 then return SetError(1, 0, 0)
local $sFileRead = StringStripWS(FileRead($hFileOpen), 3)
FileClose($hFileOpen)
if not BitAND($iFlag, 1) then $ArrayCount = "ArrayCount" & @LF
if BitAND($iFlag, 2) then $RegExp = "(?:\r\n|\n|\r)([^\r\n]+)"
if BitAND($iFlag, 4) then $RegExp = "s*(?:\r\n|\n|\r)([^\r\n]+)"
if BitAND($iFlag, 8) then $RegExp = StringReplace($RegExp, ")", ")h*", 1, 1)
$aArray = StringRegExp(@LF & $ArrayCount & $sFileRead, $RegExp, 3)
if @error then
if StringLen($sFileRead) then
local $ret[2] = [1, $sFileRead]
$aArray = $ret
else
return SetError(2, 0, 0)
endif
elseif $ArrayCount then
$aArray[0] = UBound($aArray) - 1
endif
return 1
endfunc
$associative_array" will be your own array variable.
AutoIt.Error", "AAError") ;
func AAInit(byref $dict_obj)
$dict_obj = ObjCreate("Scripting.Dictionary")
endfunc
func AAAdd(byref $dict_obj, $key, $val, $unique=false)
if $unique and AAExists($dict_obj, $key) then return SetError(1, 1, -2)
$dict_obj.Add($key, $val)
If @error Then return SetError(1, 1, -1)
endfunc
func AARemove(byref $dict_obj, $key)
$dict_obj.Remove($key)
If @error Then return SetError(1, 1, -1)
endfunc
func AAExists(byref $dict_obj, $key)
return $dict_obj.Exists($key)
endfunc
func AAGetItem(byref $dict_obj, $key)
return $dict_obj.Item($key)
endfunc
func AACount(byref $dict_obj)
return $dict_obj.Count
endfunc
Key" => "Item" pairs in the array..
func AAList(byref $dict_obj, $title="Associative Array:", $level=1)
if $level > $debug_level then return false
debug($title & " [" & AACount($dict_obj) & " items] :=>", @ScriptLineNumber, 7)
local $k = $dict_obj.Keys
for $i = 0 to AACount($dict_obj) -1
debug($k[$i] & " ==> " & AAGetItem($dict_obj, $k[$i]))
next
endfunc
func AAWipe(byref $dict_obj)
$dict_obj.RemoveAll()
endfunc
func AAError()
Local $err = $oMyError.number
If $err = 0 Then $err = -1
SetError($err)
endfunc
SaveComboSelection()
SaveComboSelection( array{this combo box's special selection array}, string{value to store})
Does what it says on the tin (erm, also works for regular drop-downs!)
If the user deletes an item, the previous item will be selected
This makes multiple deltions easier, and more. This code is also
more compact than checking for even a single "previous" entry on
each combo box individually. It's neater, too.
To use, simply create a global "AutoIt" array for the values,
with the number of values you would like to remember (remember
to set element 0 to the total)..
global $previous_combo_selections[501] = [500]
Make one for each combo.
Rather than set a limit, we could use redim, but it's slow.
Anyway, when the user selects something, store that..
SaveComboSelection($previous_combo_selections, $current_preset)
And when they delete an item, recall the previous item with..
$previous_selection = GetComboSelection($previous_combo_selections_array, $valid_names_array)
Or use it directly..
ControlCommand($GUI_foo, "", $Control_ID, "SelectString", _
GetComboSelection($previous_combo_selections_array, $valid_names_array))
If your deleted entry is still in the list at the point you need to get this information,
simply repeat the command. Essentially, go "back two"..
GetComboSelection($previous_combo_selections_array, $valid_names_array)
ControlCommand($GUI_foo, "", $Control_ID, "SelectString", _
GetComboSelection($previous_combo_selections_array, $valid_names_array))
func SaveComboSelection(byref $combo_array, $value)
for $i = 1 to $combo_array[0]
if $combo_array[$i] = "" then
if $combo_array[$i-1] <> $value then
$combo_array[$i] = $value
endif
exitloop
endif
next
endfunc
last" value in the names
history", if you require that.
func GetComboSelection(byref $combo_array, byref $names_list)
local $new_val = ""
local $i = $combo_array[0]
while $i > 0
if $combo_array[$i] <> "" then
if not InArray($names_list, $combo_array[$i]) then
$combo_array[$i] = ""
$i -= 1
continueloop
endif
$new_val = $combo_array[$i]
$combo_array[$i] = ""
exitloop
endif
$i -= 1
wend
if $new_val = "" then $new_val = $names_list[$names_list[0]]
return $new_val
endfunc
default browser" to our URL..
func VisitUrl($VisitURL="http:VisitURL: =>" & $VisitURL & "<=" , @ScriptLineNumber, 7)
ShellExecute($VisitURL)
if @Error <> 0 then
return true
else
return SetError (@Error, default , true)
endif
endfunc
func ReplaceHTMLEntities($text)
Local $Entity[65536]
$Entity[34] = "quot"
$Entity[38] = "amp"
$Entity[39] = "apos"
$Entity[60] = "lt"
$Entity[62] = "gt"
$Entity[160] = "nbsp"
$Entity[161] = "iexcl"
$Entity[162] = "cent"
$Entity[163] = "pound"
$Entity[164] = "curren"
$Entity[165] = "yen"
$Entity[166] = "brvbar"
$Entity[167] = "sect"
$Entity[168] = "uml"
$Entity[169] = "copy"
$Entity[170] = "ordf"
$Entity[171] = "laquo"
$Entity[172] = "not"
$Entity[173] = "shy"
$Entity[174] = "reg"
$Entity[175] = "macr"
$Entity[176] = "deg"
$Entity[177] = "plusmn"
$Entity[178] = "sup2"
$Entity[179] = "sup3"
$Entity[180] = "acute"
$Entity[181] = "micro"
$Entity[182] = "para"
$Entity[183] = "middot"
$Entity[184] = "cedil"
$Entity[185] = "sup1"
$Entity[186] = "ordm"
$Entity[187] = "raquo"
$Entity[188] = "frac14"
$Entity[189] = "frac12"
$Entity[190] = "frac34"
$Entity[191] = "iquest"
$Entity[192] = "Agrave"
$Entity[193] = "Aacute"
$Entity[194] = "Acirc"
$Entity[195] = "Atilde"
$Entity[196] = "Auml"
$Entity[197] = "Aring"
$Entity[198] = "AElig"
$Entity[199] = "Ccedil"
$Entity[200] = "Egrave"
$Entity[201] = "Eacute"
$Entity[202] = "Ecirc"
$Entity[203] = "Euml"
$Entity[204] = "Igrave"
$Entity[205] = "Iacute"
$Entity[206] = "Icirc"
$Entity[207] = "Iuml"
$Entity[208] = "ETH"
$Entity[209] = "Ntilde"
$Entity[210] = "Ograve"
$Entity[211] = "Oacute"
$Entity[212] = "Ocirc"
$Entity[213] = "Otilde"
$Entity[214] = "Ouml"
$Entity[215] = "times"
$Entity[216] = "Oslash"
$Entity[217] = "Ugrave"
$Entity[218] = "Uacute"
$Entity[219] = "Ucirc"
$Entity[220] = "Uuml"
$Entity[221] = "Yacute"
$Entity[222] = "THORN"
$Entity[223] = "szlig"
$Entity[224] = "agrave"
$Entity[225] = "aacute"
$Entity[226] = "acirc"
$Entity[227] = "atilde"
$Entity[228] = "auml"
$Entity[229] = "aring"
$Entity[230] = "aelig"
$Entity[231] = "ccedil"
$Entity[232] = "egrave"
$Entity[233] = "eacute"
$Entity[234] = "ecirc"
$Entity[235] = "euml"
$Entity[236] = "igrave"
$Entity[237] = "iacute"
$Entity[238] = "icirc"
$Entity[239] = "iuml"
$Entity[240] = "eth"
$Entity[241] = "ntilde"
$Entity[242] = "ograve"
$Entity[243] = "oacute"
$Entity[244] = "ocirc"
$Entity[245] = "otilde"
$Entity[246] = "ouml"
$Entity[247] = "divide"
$Entity[248] = "oslash"
$Entity[249] = "ugrave"
$Entity[250] = "uacute"
$Entity[251] = "ucirc"
$Entity[252] = "uuml"
$Entity[253] = "yacute"
$Entity[254] = "thorn"
$Entity[255] = "yuml"
$Entity[338] = "OElig"
$Entity[339] = "oelig"
$Entity[352] = "Scaron"
$Entity[353] = "scaron"
$Entity[376] = "Yuml"
$Entity[402] = "fnof"
$Entity[710] = "circ"
$Entity[732] = "tilde"
$Entity[913] = "Alpha"
$Entity[914] = "Beta"
$Entity[915] = "Gamma"
$Entity[916] = "Delta"
$Entity[917] = "Epsilon"
$Entity[918] = "Zeta"
$Entity[919] = "Eta"
$Entity[920] = "Theta"
$Entity[921] = "Iota"
$Entity[922] = "Kappa"
$Entity[923] = "Lambda"
$Entity[924] = "Mu"
$Entity[925] = "Nu"
$Entity[926] = "Xi"
$Entity[927] = "Omicron"
$Entity[928] = "Pi"
$Entity[929] = "Rho"
$Entity[931] = "Sigma"
$Entity[932] = "Tau"
$Entity[933] = "Upsilon"
$Entity[934] = "Phi"
$Entity[935] = "Chi"
$Entity[936] = "Psi"
$Entity[937] = "Omega"
$Entity[945] = "alpha"
$Entity[946] = "beta"
$Entity[947] = "gamma"
$Entity[948] = "delta"
$Entity[949] = "epsilon"
$Entity[950] = "zeta"
$Entity[951] = "eta"
$Entity[952] = "theta"
$Entity[953] = "iota"
$Entity[954] = "kappa"
$Entity[955] = "lambda"
$Entity[956] = "mu"
$Entity[957] = "nu"
$Entity[958] = "xi"
$Entity[959] = "omicron"
$Entity[960] = "pi"
$Entity[961] = "rho"
$Entity[962] = "sigmaf"
$Entity[963] = "sigma"
$Entity[964] = "tau"
$Entity[965] = "upsilon"
$Entity[966] = "phi"
$Entity[967] = "chi"
$Entity[968] = "psi"
$Entity[969] = "omega"
$Entity[977] = "thetasym"
$Entity[978] = "upsih"
$Entity[982] = "piv"
$Entity[8194] = "ensp"
$Entity[8195] = "emsp"
$Entity[8201] = "thinsp"
$Entity[8204] = "zwnj"
$Entity[8205] = "zwj"
$Entity[8206] = "lrm"
$Entity[8207] = "rlm"
$Entity[8211] = "ndash"
$Entity[8212] = "mdash"
$Entity[8216] = "lsquo"
$Entity[8217] = "rsquo"
$Entity[8218] = "sbquo"
$Entity[8220] = "ldquo"
$Entity[8221] = "rdquo"
$Entity[8222] = "bdquo"
$Entity[8224] = "dagger"
$Entity[8225] = "Dagger"
$Entity[8226] = "bull"
$Entity[8230] = "hellip"
$Entity[8240] = "permil"
$Entity[8242] = "prime"
$Entity[8243] = "Prime"
$Entity[8249] = "lsaquo"
$Entity[8250] = "rsaquo"
$Entity[8254] = "oline"
$Entity[8260] = "frasl"
$Entity[8364] = "euro"
$Entity[8465] = "image"
$Entity[8472] = "weierp"
$Entity[8476] = "real"
$Entity[8482] = "trade"
$Entity[8501] = "alefsym"
$Entity[8592] = "larr"
$Entity[8593] = "uarr"
$Entity[8594] = "rarr"
$Entity[8595] = "darr"
$Entity[8596] = "harr"
$Entity[8629] = "crarr"
$Entity[8656] = "lArr"
$Entity[8657] = "uArr"
$Entity[8658] = "rArr"
$Entity[8659] = "dArr"
$Entity[8660] = "hArr"
$Entity[8704] = "forall"
$Entity[8706] = "part"
$Entity[8707] = "exist"
$Entity[8709] = "empty"
$Entity[8711] = "nabla"
$Entity[8712] = "isin"
$Entity[8713] = "notin"
$Entity[8715] = "ni"
$Entity[8719] = "prod"
$Entity[8721] = "sum"
$Entity[8722] = "minus"
$Entity[8727] = "lowast"
$Entity[8730] = "radic"
$Entity[8733] = "prop"
$Entity[8734] = "infin"
$Entity[8736] = "ang"
$Entity[8743] = "and"
$Entity[8744] = "or"
$Entity[8745] = "cap"
$Entity[8746] = "cup"
$Entity[8747] = "int"
$Entity[8756] = "there4"
$Entity[8764] = "sim"
$Entity[8773] = "cong"
$Entity[8776] = "asymp"
$Entity[8800] = "ne"
$Entity[8801] = "equiv"
$Entity[8804] = "le"
$Entity[8805] = "ge"
$Entity[8834] = "sub"
$Entity[8835] = "sup"
$Entity[8836] = "nsub"
$Entity[8838] = "sube"
$Entity[8839] = "supe"
$Entity[8853] = "oplus"
$Entity[8855] = "otimes"
$Entity[8869] = "perp"
$Entity[8901] = "sdot"
$Entity[8968] = "lceil"
$Entity[8969] = "rceil"
$Entity[8970] = "lfloor"
$Entity[8971] = "rfloor"
$Entity[9001] = "lang"
$Entity[9002] = "rang"
$Entity[9674] = "loz"
$Entity[9824] = "spades"
$Entity[9827] = "clubs"
$Entity[9829] = "hearts"
$Entity[9830] = "diams"
local $e1 = StringRegExp($text, '&
local $e2 = StringRegExp($text, '&
local $e3 = StringRegExp($text, '&(.*?)
for $i = 0 To UBound($e1) - 1 step 1
$text = StringReplace($text, '&
next
for $i = 0 To UBound($e2) - 1 step 1
$text = StringReplace($text, '&
next
for $i = 0 To UBound($e3) - 1 step 1
$text = StringReplace($text, '&' & $e3[$i] & '
next
return $text
endfunc
func CreateHTMLEntities($string)
local $len = StringLen($string)
local $ret
if not $len then return $string
for $i = 1 to $len
local $wchar = StringMid($string, $i, 1)
$ret &= "& ", "%20")
$text = StringReplace($text, "!", "%21")
$text = StringReplace($text, '"', "%22")
$text = StringReplace($text, ", "%23")
$text = StringReplace($text, "$", "%24")
$text = StringReplace($text, "%", "%25")
$text = StringReplace($text, "&", "%26")
$text = StringReplace($text, "'", "%27")
$text = StringReplace($text, "(", "%28")
$text = StringReplace($text, ")", "%29")
$text = StringReplace($text, "*", "%2A")
$text = StringReplace($text, "+", "%2B")
$text = StringReplace($text, ",", "%2C")
$text = StringReplace($text, "-", "%2D")
$text = StringReplace($text, ".", "%2E")
$text = StringReplace($text, "/", "%2F")
$text = StringReplace($text, "0", "%30")
$text = StringReplace($text, "1", "%31")
$text = StringReplace($text, "2", "%32")
$text = StringReplace($text, "3", "%33")
$text = StringReplace($text, "4", "%34")
$text = StringReplace($text, "5", "%35")
$text = StringReplace($text, "6", "%36")
$text = StringReplace($text, "7", "%37")
$text = StringReplace($text, "8", "%38")
$text = StringReplace($text, "9", "%39")
$text = StringReplace($text, ":", "%3A")
$text = StringReplace($text, ", "%3B")
$text = StringReplace($text, "<", "%3C")
$text = StringReplace($text, "=", "%3D")
$text = StringReplace($text, ">", "%3E")
$text = StringReplace($text, "?", "%3F")
$text = StringReplace($text, "@", "%40")
$text = StringReplace($text, "A", "%41")
$text = StringReplace($text, "B", "%42")
$text = StringReplace($text, "C", "%43")
$text = StringReplace($text, "D", "%44")
$text = StringReplace($text, "E", "%45")
$text = StringReplace($text, "F", "%46")
$text = StringReplace($text, "G", "%47")
$text = StringReplace($text, "H", "%48")
$text = StringReplace($text, "I", "%49")
$text = StringReplace($text, "J", "%4A")
$text = StringReplace($text, "K", "%4B")
$text = StringReplace($text, "L", "%4C")
$text = StringReplace($text, "M", "%4D")
$text = StringReplace($text, "N", "%4E")
$text = StringReplace($text, "O", "%4F")
$text = StringReplace($text, "P", "%50")
$text = StringReplace($text, "Q", "%51")
$text = StringReplace($text, "R", "%52")
$text = StringReplace($text, "S", "%53")
$text = StringReplace($text, "T", "%54")
$text = StringReplace($text, "U", "%55")
$text = StringReplace($text, "V", "%56")
$text = StringReplace($text, "W", "%57")
$text = StringReplace($text, "X", "%58")
$text = StringReplace($text, "Y", "%59")
$text = StringReplace($text, "Z", "%5A")
$text = StringReplace($text, "[", "%5B")
$text = StringReplace($text, "\", "%5C")
$text = StringReplace($text, "]", "%5D")
$text = StringReplace($text, "^", "%5E")
$text = StringReplace($text, "_", "%5F")
$text = StringReplace($text, "`", "%60")
$text = StringReplace($text, "a", "%61")
$text = StringReplace($text, "b", "%62")
$text = StringReplace($text, "c", "%63")
$text = StringReplace($text, "d", "%64")
$text = StringReplace($text, "e", "%65")
$text = StringReplace($text, "f", "%66")
$text = StringReplace($text, "g", "%67")
$text = StringReplace($text, "h", "%68")
$text = StringReplace($text, "i", "%69")
$text = StringReplace($text, "j", "%6A")
$text = StringReplace($text, "k", "%6B")
$text = StringReplace($text, "l", "%6C")
$text = StringReplace($text, "m", "%6D")
$text = StringReplace($text, "n", "%6E")
$text = StringReplace($text, "o", "%6F")
$text = StringReplace($text, "p", "%70")
$text = StringReplace($text, "q", "%71")
$text = StringReplace($text, "r", "%72")
$text = StringReplace($text, "s", "%73")
$text = StringReplace($text, "t", "%74")
$text = StringReplace($text, "u", "%75")
$text = StringReplace($text, "v", "%76")
$text = StringReplace($text, "w", "%77")
$text = StringReplace($text, "x", "%78")
$text = StringReplace($text, "y", "%79")
$text = StringReplace($text, "z", "%7A")
$text = StringReplace($text, "{", "%7B")
$text = StringReplace($text, "|", "%7C")
$text = StringReplace($text, "}", "%7D")
$text = StringReplace($text, "~", "%7E")
$text = StringReplace($text, " ", "%7F")
$text = StringReplace($text, "€", "%80")
$text = StringReplace($text, " ", "%81")
$text = StringReplace($text, "‚", "%82")
$text = StringReplace($text, "ƒ", "%83")
$text = StringReplace($text, "„", "%84")
$text = StringReplace($text, "…", "%85")
$text = StringReplace($text, "†", "%86")
$text = StringReplace($text, "‡", "%87")
$text = StringReplace($text, "ˆ", "%88")
$text = StringReplace($text, "‰", "%89")
$text = StringReplace($text, "Š", "%8A")
$text = StringReplace($text, "‹", "%8B")
$text = StringReplace($text, "Œ", "%8C")
$text = StringReplace($text, " ", "%8D")
$text = StringReplace($text, "Ž", "%8E")
$text = StringReplace($text, " ", "%8F")
$text = StringReplace($text, " ", "%90")
$text = StringReplace($text, "‘", "%91")
$text = StringReplace($text, "’", "%92")
$text = StringReplace($text, "“", "%93")
$text = StringReplace($text, "”", "%94")
$text = StringReplace($text, "•", "%95")
$text = StringReplace($text, "–", "%96")
$text = StringReplace($text, "—", "%97")
$text = StringReplace($text, "˜", "%98")
$text = StringReplace($text, "™", "%99")
$text = StringReplace($text, "š", "%9A")
$text = StringReplace($text, "›", "%9B")
$text = StringReplace($text, "œ", "%9C")
$text = StringReplace($text, " ", "%9D")
$text = StringReplace($text, "ž", "%9E")
$text = StringReplace($text, "Ÿ", "%9F")
$text = StringReplace($text, " ", "%A0")
$text = StringReplace($text, "¡", "%A1")
$text = StringReplace($text, "¢", "%A2")
$text = StringReplace($text, "£", "%A3")
$text = StringReplace($text, " ", "%A4")
$text = StringReplace($text, "¥", "%A5")
$text = StringReplace($text, "|", "%A6")
$text = StringReplace($text, "§", "%A7")
$text = StringReplace($text, "¨", "%A8")
$text = StringReplace($text, "©", "%A9")
$text = StringReplace($text, "ª", "%AA")
$text = StringReplace($text, "«", "%AB")
$text = StringReplace($text, "¬", "%AC")
$text = StringReplace($text, "¯", "%AD")
$text = StringReplace($text, "®", "%AE")
$text = StringReplace($text, "¯", "%AF")
$text = StringReplace($text, "°", "%B0")
$text = StringReplace($text, "±", "%B1")
$text = StringReplace($text, "²", "%B2")
$text = StringReplace($text, "³", "%B3")
$text = StringReplace($text, "´", "%B4")
$text = StringReplace($text, "µ", "%B5")
$text = StringReplace($text, "¶", "%B6")
$text = StringReplace($text, "·", "%B7")
$text = StringReplace($text, "¸", "%B8")
$text = StringReplace($text, "¹", "%B9")
$text = StringReplace($text, "º", "%BA")
$text = StringReplace($text, "»", "%BB")
$text = StringReplace($text, "¼", "%BC")
$text = StringReplace($text, "½", "%BD")
$text = StringReplace($text, "¾", "%BE")
$text = StringReplace($text, "¿", "%BF")
$text = StringReplace($text, "À", "%C0")
$text = StringReplace($text, "Á", "%C1")
$text = StringReplace($text, "Â", "%C2")
$text = StringReplace($text, "Ã", "%C3")
$text = StringReplace($text, "Ä", "%C4")
$text = StringReplace($text, "Å", "%C5")
$text = StringReplace($text, "Æ", "%C6")
$text = StringReplace($text, "Ç", "%C7")
$text = StringReplace($text, "È", "%C8")
$text = StringReplace($text, "É", "%C9")
$text = StringReplace($text, "Ê", "%CA")
$text = StringReplace($text, "Ë", "%CB")
$text = StringReplace($text, "Ì", "%CC")
$text = StringReplace($text, "Í", "%CD")
$text = StringReplace($text, "Î", "%CE")
$text = StringReplace($text, "Ï", "%CF")
$text = StringReplace($text, "Ð", "%D0")
$text = StringReplace($text, "Ñ", "%D1")
$text = StringReplace($text, "Ò", "%D2")
$text = StringReplace($text, "Ó", "%D3")
$text = StringReplace($text, "Ô", "%D4")
$text = StringReplace($text, "Õ", "%D5")
$text = StringReplace($text, "Ö", "%D6")
$text = StringReplace($text, " ", "%D7")
$text = StringReplace($text, "Ø", "%D8")
$text = StringReplace($text, "Ù", "%D9")
$text = StringReplace($text, "Ú", "%DA")
$text = StringReplace($text, "Û", "%DB")
$text = StringReplace($text, "Ü", "%DC")
$text = StringReplace($text, "Ý", "%DD")
$text = StringReplace($text, "Þ", "%DE")
$text = StringReplace($text, "ß", "%DF")
$text = StringReplace($text, "à", "%E0")
$text = StringReplace($text, "á", "%E1")
$text = StringReplace($text, "â", "%E2")
$text = StringReplace($text, "ã", "%E3")
$text = StringReplace($text, "ä", "%E4")
$text = StringReplace($text, "å", "%E5")
$text = StringReplace($text, "æ", "%E6")
$text = StringReplace($text, "ç", "%E7")
$text = StringReplace($text, "è", "%E8")
$text = StringReplace($text, "é", "%E9")
$text = StringReplace($text, "ê", "%EA")
$text = StringReplace($text, "ë", "%EB")
$text = StringReplace($text, "ì", "%EC")
$text = StringReplace($text, "í", "%ED")
$text = StringReplace($text, "î", "%EE")
$text = StringReplace($text, "ï", "%EF")
$text = StringReplace($text, "ð", "%F0")
$text = StringReplace($text, "ñ", "%F1")
$text = StringReplace($text, "ò", "%F2")
$text = StringReplace($text, "ó", "%F3")
$text = StringReplace($text, "ô", "%F4")
$text = StringReplace($text, "õ", "%F5")
$text = StringReplace($text, "ö", "%F6")
$text = StringReplace($text, "÷", "%F7")
$text = StringReplace($text, "ø", "%F8")
$text = StringReplace($text, "ù", "%F9")
$text = StringReplace($text, "ú", "%FA")
$text = StringReplace($text, "û", "%FB")
$text = StringReplace($text, "ü", "%FC")
$text = StringReplace($text, "ý", "%FD")
$text = StringReplace($text, "þ", "%FE")
$text = StringReplace($text, "ÿ", "%FF")
return $text
endfunc
func DeCodeUrl($text)
$text = StringReplace($text, "%20", " ")
$text = StringReplace($text, "%21", "!")
$text = StringReplace($text, "%22", '"')
$text = StringReplace($text, "%23", "%24", "$")
$text = StringReplace($text, "%25", "%")
$text = StringReplace($text, "%26", "&")
$text = StringReplace($text, "%27", "'")
$text = StringReplace($text, "%28", "(")
$text = StringReplace($text, "%29", ")")
$text = StringReplace($text, "%2A", "*")
$text = StringReplace($text, "%2B", "+")
$text = StringReplace($text, "%2C", ",")
$text = StringReplace($text, "%2D", "-")
$text = StringReplace($text, "%2E", ".")
$text = StringReplace($text, "%2F", "/")
$text = StringReplace($text, "%30", "0")
$text = StringReplace($text, "%31", "1")
$text = StringReplace($text, "%32", "2")
$text = StringReplace($text, "%33", "3")
$text = StringReplace($text, "%34", "4")
$text = StringReplace($text, "%35", "5")
$text = StringReplace($text, "%36", "6")
$text = StringReplace($text, "%37", "7")
$text = StringReplace($text, "%38", "8")
$text = StringReplace($text, "%39", "9")
$text = StringReplace($text, "%3A", ":")
$text = StringReplace($text, "%3B", "%3C", "<")
$text = StringReplace($text, "%3D", "=")
$text = StringReplace($text, "%3E", ">")
$text = StringReplace($text, "%3F", "?")
$text = StringReplace($text, "%40", "@")
$text = StringReplace($text, "%41", "A")
$text = StringReplace($text, "%42", "B")
$text = StringReplace($text, "%43", "C")
$text = StringReplace($text, "%44", "D")
$text = StringReplace($text, "%45", "E")
$text = StringReplace($text, "%46", "F")
$text = StringReplace($text, "%47", "G")
$text = StringReplace($text, "%48", "H")
$text = StringReplace($text, "%49", "I")
$text = StringReplace($text, "%4A", "J")
$text = StringReplace($text, "%4B", "K")
$text = StringReplace($text, "%4C", "L")
$text = StringReplace($text, "%4D", "M")
$text = StringReplace($text, "%4E", "N")
$text = StringReplace($text, "%4F", "O")
$text = StringReplace($text, "%50", "P")
$text = StringReplace($text, "%51", "Q")
$text = StringReplace($text, "%52", "R")
$text = StringReplace($text, "%53", "S")
$text = StringReplace($text, "%54", "T")
$text = StringReplace($text, "%55", "U")
$text = StringReplace($text, "%56", "V")
$text = StringReplace($text, "%57", "W")
$text = StringReplace($text, "%58", "X")
$text = StringReplace($text, "%59", "Y")
$text = StringReplace($text, "%5A", "Z")
$text = StringReplace($text, "%5B", "[")
$text = StringReplace($text, "%5C", "\")
$text = StringReplace($text, "%5D", "]")
$text = StringReplace($text, "%5E", "^")
$text = StringReplace($text, "%5F", "_")
$text = StringReplace($text, "%60", "`")
$text = StringReplace($text, "%61", "a")
$text = StringReplace($text, "%62", "b")
$text = StringReplace($text, "%63", "c")
$text = StringReplace($text, "%64", "d")
$text = StringReplace($text, "%65", "e")
$text = StringReplace($text, "%66", "f")
$text = StringReplace($text, "%67", "g")
$text = StringReplace($text, "%68", "h")
$text = StringReplace($text, "%69", "i")
$text = StringReplace($text, "%6A", "j")
$text = StringReplace($text, "%6B", "k")
$text = StringReplace($text, "%6C", "l")
$text = StringReplace($text, "%6D", "m")
$text = StringReplace($text, "%6E", "n")
$text = StringReplace($text, "%6F", "o")
$text = StringReplace($text, "%70", "p")
$text = StringReplace($text, "%71", "q")
$text = StringReplace($text, "%72", "r")
$text = StringReplace($text, "%73", "s")
$text = StringReplace($text, "%74", "t")
$text = StringReplace($text, "%75", "u")
$text = StringReplace($text, "%76", "v")
$text = StringReplace($text, "%77", "w")
$text = StringReplace($text, "%78", "x")
$text = StringReplace($text, "%79", "y")
$text = StringReplace($text, "%7A", "z")
$text = StringReplace($text, "%7B", "{")
$text = StringReplace($text, "%7C", "|")
$text = StringReplace($text, "%7D", "}")
$text = StringReplace($text, "%7E", "~")
$text = StringReplace($text, "%7F", " ")
$text = StringReplace($text, "%80", "€")
$text = StringReplace($text, "%81", " ")
$text = StringReplace($text, "%82", "‚")
$text = StringReplace($text, "%83", "ƒ")
$text = StringReplace($text, "%84", "„")
$text = StringReplace($text, "%85", "…")
$text = StringReplace($text, "%86", "†")
$text = StringReplace($text, "%87", "‡")
$text = StringReplace($text, "%88", "ˆ")
$text = StringReplace($text, "%89", "‰")
$text = StringReplace($text, "%8A", "Š")
$text = StringReplace($text, "%8B", "‹")
$text = StringReplace($text, "%8C", "Œ")
$text = StringReplace($text, "%8D", " ")
$text = StringReplace($text, "%8E", "Ž")
$text = StringReplace($text, "%8F", " ")
$text = StringReplace($text, "%90", " ")
$text = StringReplace($text, "%91", "‘")
$text = StringReplace($text, "%92", "’")
$text = StringReplace($text, "%93", "“")
$text = StringReplace($text, "%94", "”")
$text = StringReplace($text, "%95", "•")
$text = StringReplace($text, "%96", "–")
$text = StringReplace($text, "%97", "—")
$text = StringReplace($text, "%98", "˜")
$text = StringReplace($text, "%99", "™")
$text = StringReplace($text, "%9A", "š")
$text = StringReplace($text, "%9B", "›")
$text = StringReplace($text, "%9C", "œ")
$text = StringReplace($text, "%9D", " ")
$text = StringReplace($text, "%9E", "ž")
$text = StringReplace($text, "%9F", "Ÿ")
$text = StringReplace($text, "%A0", " ")
$text = StringReplace($text, "%A1", "¡")
$text = StringReplace($text, "%A2", "¢")
$text = StringReplace($text, "%A3", "£")
$text = StringReplace($text, "%A4", " ")
$text = StringReplace($text, "%A5", "¥")
$text = StringReplace($text, "%A6", "|")
$text = StringReplace($text, "%A7", "§")
$text = StringReplace($text, "%A8", "¨")
$text = StringReplace($text, "%A9", "©")
$text = StringReplace($text, "%AA", "ª")
$text = StringReplace($text, "%AB", "«")
$text = StringReplace($text, "%AC", "¬")
$text = StringReplace($text, "%AD", "¯")
$text = StringReplace($text, "%AE", "®")
$text = StringReplace($text, "%AF", "¯")
$text = StringReplace($text, "%B0", "°")
$text = StringReplace($text, "%B1", "±")
$text = StringReplace($text, "%B2", "²")
$text = StringReplace($text, "%B3", "³")
$text = StringReplace($text, "%B4", "´")
$text = StringReplace($text, "%B5", "µ")
$text = StringReplace($text, "%B6", "¶")
$text = StringReplace($text, "%B7", "·")
$text = StringReplace($text, "%B8", "¸")
$text = StringReplace($text, "%B9", "¹")
$text = StringReplace($text, "%BA", "º")
$text = StringReplace($text, "%BB", "»")
$text = StringReplace($text, "%BC", "¼")
$text = StringReplace($text, "%BD", "½")
$text = StringReplace($text, "%BE", "¾")
$text = StringReplace($text, "%BF", "¿")
$text = StringReplace($text, "%C0", "À")
$text = StringReplace($text, "%C1", "Á")
$text = StringReplace($text, "%C2", "Â")
$text = StringReplace($text, "%C3", "Ã")
$text = StringReplace($text, "%C4", "Ä")
$text = StringReplace($text, "%C5", "Å")
$text = StringReplace($text, "%C6", "Æ")
$text = StringReplace($text, "%C7", "Ç")
$text = StringReplace($text, "%C8", "È")
$text = StringReplace($text, "%C9", "É")
$text = StringReplace($text, "%CA", "Ê")
$text = StringReplace($text, "%CB", "Ë")
$text = StringReplace($text, "%CC", "Ì")
$text = StringReplace($text, "%CD", "Í")
$text = StringReplace($text, "%CE", "Î")
$text = StringReplace($text, "%CF", "Ï")
$text = StringReplace($text, "%D0", "Ð")
$text = StringReplace($text, "%D1", "Ñ")
$text = StringReplace($text, "%D2", "Ò")
$text = StringReplace($text, "%D3", "Ó")
$text = StringReplace($text, "%D4", "Ô")
$text = StringReplace($text, "%D5", "Õ")
$text = StringReplace($text, "%D6", "Ö")
$text = StringReplace($text, "%D7", " ")
$text = StringReplace($text, "%D8", "Ø")
$text = StringReplace($text, "%D9", "Ù")
$text = StringReplace($text, "%DA", "Ú")
$text = StringReplace($text, "%DB", "Û")
$text = StringReplace($text, "%DC", "Ü")
$text = StringReplace($text, "%DD", "Ý")
$text = StringReplace($text, "%DE", "Þ")
$text = StringReplace($text, "%DF", "ß")
$text = StringReplace($text, "%E0", "à")
$text = StringReplace($text, "%E1", "á")
$text = StringReplace($text, "%E2", "â")
$text = StringReplace($text, "%E3", "ã")
$text = StringReplace($text, "%E4", "ä")
$text = StringReplace($text, "%E5", "å")
$text = StringReplace($text, "%E6", "æ")
$text = StringReplace($text, "%E7", "ç")
$text = StringReplace($text, "%E8", "è")
$text = StringReplace($text, "%E9", "é")
$text = StringReplace($text, "%EA", "ê")
$text = StringReplace($text, "%EB", "ë")
$text = StringReplace($text, "%EC", "ì")
$text = StringReplace($text, "%ED", "í")
$text = StringReplace($text, "%EE", "î")
$text = StringReplace($text, "%EF", "ï")
$text = StringReplace($text, "%F0", "ð")
$text = StringReplace($text, "%F1", "ñ")
$text = StringReplace($text, "%F2", "ò")
$text = StringReplace($text, "%F3", "ó")
$text = StringReplace($text, "%F4", "ô")
$text = StringReplace($text, "%F5", "õ")
$text = StringReplace($text, "%F6", "ö")
$text = StringReplace($text, "%F7", "÷")
$text = StringReplace($text, "%F8", "ø")
$text = StringReplace($text, "%F9", "ù")
$text = StringReplace($text, "%FA", "ú")
$text = StringReplace($text, "%FB", "û")
$text = StringReplace($text, "%FC", "ü")
$text = StringReplace($text, "%FD", "ý")
$text = StringReplace($text, "%FE", "þ")
$text = StringReplace($text, "%FF", "ÿ")
return $text
endfunc
func StripHTML($web_text, $lf=$LOG_LF)
$web_text = StringReplace($web_text, " "
endif
local $appends[10]
$appends[0] = "th"
$appends[1] = "st"
$appends[2] = "nd"
$appends[3] = "rd"
$appends[4] = "th"
$appends[5] = "th"
$appends[6] = "th"
$appends[7] = "th"
$appends[8] = "th"
$appends[9] = "th"
if StringMid($d_str, StringLen($d_str)-1, 1) == 1 then
$appends[1] = "th"
$appends[2] = "th"
$appends[3] = "th"
endif
return $d_str & $appends[StringRight($d_str, 1)]
endfunc
func SecondsToDHMS($sec=0, $round=true)
debug("SecondsToDHMS(sec) =>" & $sec & "<=", @ScriptLineNumber, 9)
if $round then $sec = StringFormat("%.02f", $sec)
if $sec < 0 then return -1
select
case $sec < 61
return $sec & " seconds"
case $sec < 3601
return StringFormat('%.01dm %.01ds', Mod(($sec / 60), 60), Mod($sec, 60))
case $sec < 86401
return StringFormat('%.01dh %.01dm %.01ds', Mod($sec / 3600, 24), Int(Mod(($sec / 60), 60)), Mod($sec, 60))
case else
return StringFormat('%.01dd %.01dh %.01dm %.01ds', Mod($sec / 86400, 7), _
Mod($sec / 3600, 24), Int(Mod(($sec / 60), 60)), Mod($sec, 60))
endselect
endfunc
%.02f", $sec) & " seconds"
user" (Human) time to an integer unit of time.
full info" (3rd parameter) which will have UserTimeToUnitTime
h".
func UserTimeToUnitTime($user_time, $time_unit="ms", $full_info=false)
local $ret_array[2] = [0,"ms"]
if IsNumber($user_time) then
if $full_info then
$ret_array[0] = $user_time
return $ret_array
else
return $user_time
endif
endif
select
case StringRight($user_time, 2) = "ms"
CRT($user_time, "ms")
case StringRight($user_time, 1) = "s"
CRT($user_time, "s")
$user_time *= 1000
case StringRight($user_time, 1) = "m"
CRT($user_time, "m")
$user_time *= (1000*60)
case StringRight($user_time, 1) = "h"
CRT($user_time, "h")
$user_time *= (1000*60*60)
case StringRight($user_time, 1) = "d"
CRT($user_time, "d")
$user_time *= (1000*60*60*24)
endselect
switch $time_unit
ms" ; also 1st for quickness
case "s"
$user_time = $user_time/1000
$ret_array[1] = "s"
case "m"
$user_time = $user_time/1000/60
$ret_array[1] = "m"
case "h"
$user_time = $user_time/1000/60/60
$ret_array[1] = "h"
case "d"
$user_time = $user_time/1000/60/60/24
$ret_array[1] = "h"
endswitch
$ret_array[0] = Number($user_time)
if $full_info then
return $ret_array
else
return $user_time
endif
endfunc
16").
pm"]
func HourToHumanTime($24hour)
local $human_hour[2]
$human_hour[0] = Number($24hour)
$human_hour[1] = "am"
if $24hour > 11 then $human_hour[1] = "pm"
if $24hour = 00 then $human_hour[0] = 12
if $24hour > 12 then $human_hour[0] -= 12
$human_hour[0] = int($human_hour[0])
return $human_hour
endfunc
am" or "pm")
am") = 03
pm") = 15
puter" in a variable for ages.
func HumanTimeToHour($12hour, $am_pm)
local $puter_hours
switch $am_pm
case "am"
if $12hour = 12 then
$puter_hours = 0
else
$puter_hours = $12hour
endif
case "pm"
if $12hour = 12 then
$puter_hours = 12
else
$puter_hours = $12hour + 12
endif
endswitch
return StringFormat("%02d", $puter_hours)
endfunc
func MakeUnicodeFile($file)
local $non_unicode_text = FileRead($file)
if FileGetSize($file) = StringLen($non_unicode_text) then
local $unicode_file = FileOpen($file, 2 + 32)
FileWrite($unicode_file, $non_unicode_text)
return true
endif
return false
endfunc
func UnifyCRLF($some_text, $LF=@CRLF)
return StringRegExpReplace($some_text, "\R", $LF)
endfunc
\n" to actual Linefeeds, for use in logs,
func ConvertNewlines(ByRef $pref_string, $reverse=false, $LF=$LOG_LF)
if $reverse then
$pref_string = StringReplace($pref_string, $LF, "\n")
else
$pref_string = StringReplace($pref_string, "\n", $LF)
endif
endfunc
MB". If the
GB", then
TB".
func FormatMB($mb, $round=0, $array=false)
local $return, $unit
$mb = Number($mb)
select
case $mb = 0
$return = 0
case $mb < 1024
$return = Round($mb, $round)
$unit = "MB"
case $mb >= 1048576
$return = Round($mb / 1048576, $round)
$unit = "TB"
case $mb >= 1024
$return = Round($mb / 1024, $round)
$unit = "GB"
endselect
if $array then
local $ret[2]
$ret[0] = $mb
$ret[1] = $unit
return $ret
endif
return $return & " " & $unit
endfunc
func BytesToByteUnit($bytes_value, $unit_required, $round=2)
debug("", @ScriptLineNumber, 7)
debug("BytesToByteUnit(" & $bytes_value & "," & $unit_required & "," & $round & ")", @ScriptLineNumber, 7)
local $return = $bytes_value
switch $unit_required
B"
case "KB"
$return = Round($bytes_value/1024, $round)
case "MB"
$return = Round($bytes_value/1048576, $round)
case "GB"
$return = Round($bytes_value/1.073742e+009, $round)
case "TB"
$return = Round($bytes_value/1.099512e+012, $round)
case "PB"
$return = Round($bytes_value/1.1259e+015, $round)
case "EB"
$return = Round($bytes_value/1.152922e+018, $round)
case "ZB"
$return = Round($bytes_value/1.180592e+021, $round)
case "YB"
$return = Round($bytes_value/1.208926e+024, $round)
endswitch
debug("Returning: =>" & $return & "<=", @ScriptLineNumber, 7)
return $return
endfunc
random" upper and lower case letters to the specified length.
func MakeRandomString($length=32, $seed=@Min*@Sec*@MSec)
debug("", @ScriptLineNumber, 7)
debug("MakeRandomString(" & $seed & ")", @ScriptLineNumber, 7)
SRandom($seed)
local $a[$length]
local $x = 0
while $a[$length-1] = ""
local $tmp = Chr(Random(65, 122, 1))
if StringIsAlpha($tmp) then
$a[$x] = Asc($tmp)
$x += 1
endif
wend
$a = StringFromASCIIArray($a)
debug("MakeRandomString() returning: =>" & $a & "<=", @ScriptLineNumber, 7)
return $a
endfunc
X-String", which is hexadecimal digits (0-9, A-F)
func MakeRandomXString($length=32, $seed=@Min*@Sec*@MSec)
SRandom($seed)
local $a[$length]
local $x = 0
while $a[$length-1] = ""
local $tmp = Chr(Random(48, 71, 1))
if StringIsXDigit($tmp) then
$a[$x] = Asc($tmp)
$x += 1
endif
wend
$a = StringFromASCIIArray($a)
debug("MakeRandomXString() returning: =>" & $a & "<=", @ScriptLineNumber, 7)
return $a
endfunc
i", "RGB Integer", "RGB Int" or "int".
a", "Autoit RGB Hex", "Autoit RGB", "AutoIt Hex", or "AutoIt".
b", "Autoit BGR Hex", "Autoit BGR", "BGR Hex" or "bgr".
d", "Delphi" or "Delphi Hex".
v", "vc", "Visual C++ Hex", "Visual C++ BGR", "Visual C++", "Visual C++ BGR Hex" or "C++".
RGB Float", "float" or "f".
h", "Hue/Sat/Lum", "HSL" or "h/s/l".
k", "cmyk" or "c/m/y/k".
w", "Web Hex", "Web", or "Hex".
func ConvertColorValue($color, $mode = "web", $prefix = false, $index = 0, $lowercase = $off)
if StringLeft($color, 1) = ""
switch $mode
case "i", "RGB Integer", "RGB Int", "int"
switch $index
case 0
$color = Dec(StringLeft($color, 2)) & "," & Dec(StringMid($color, 3, 2)) & "," & Dec(StringRight($color, 2))
case 1
return Dec(StringLeft($color, 2))
case 2
return Dec(StringMid($color, 3, 2))
case 3
return Dec(StringRight($color, 2))
endswitch
case "a", "Autoit RGB Hex", "Autoit RGB", "AutoIt Hex", "AutoIt"
$color = "0x" & $color
case "b", "Autoit BGR Hex", "Autoit BGR", "BGR Hex", "bgr"
$color = "0x" & StringRight($color, 2) & StringMid($color, 3, 2) & StringLeft($color, 2)
case "d", "Delphi", "Delphi Hex"
$color = "00" & StringRight($color, 2) & StringMid($color, 3, 2) & StringLeft($color, 2)
$pre = "$"
case "v", "vc", "Visual C++ Hex", "Visual C++ BGR", "Visual C++", "Visual C++ BGR Hex", "C++"
$color = "0x00" & StringRight($color, 2) & StringMid($color, 3, 2) & StringLeft($color, 2)
case "RGB Float", "float", "f"
local $r = Round((1 / 255) * Dec(StringLeft($color, 2)), 2)
local $g = Round((1 / 255) * Dec(StringMid($color, 3, 2)), 2)
local $b = Round((1 / 255) * Dec(StringRight($color, 2)), 2)
$color = StringFormat("%h", "Hue/Sat/Lum", "HSL", "h/s/l"
$color = RGBtoHSL($color, ",", 100)
case "k", "cmyk", "c/m/y/k"
if $prefix = 1 then
$color = RGBtoCMYK($color, true)
else
$color = RGBtoCMYK($color)
endif
case "w", "Web Hex", "Web", "Hex"
$pre = ""
if $lowercase = $on then $color = StringLower($color)
return $pre & $color
endfunc
Func RGBtoCMYK($rgb_color, $norm = 0)
local $rc_r = ConvertColorValue($rgb_color, "i", 0, 1) / 255
local $rc_g = ConvertColorValue($rgb_color, "i", 0, 2) / 255
local $rc_b = ConvertColorValue($rgb_color, "i", 0, 3) / 255
local $k = MinMin(1 - $rc_r, 1 - $rc_g, 1 - $rc_b)
local $c = (1 - $rc_r - $k) / (1 - $k)
local $m = (1 - $rc_g - $k) / (1 - $k)
local $y = (1 - $rc_b - $k) / (1 - $k)
if $norm then
return Round($c * 100, 1) & "," & Round($m * 100, 1) & "," & Round($y * 100, 1) & "," & Round($k * 100, 1)
else
return Round($c, 3) & "," & Round($m, 3) & "," & Round($y, 3) & "," & Round($k, 3)
endif
endfunc
func RGBtoHSL($rgb_color, $idx = "", $simple_array = False, $hsl_scale = 1)
local $rh_r = ConvertColorValue($rgb_color, "i", 0, 1) / 255
local $rh_g = ConvertColorValue($rgb_color, "i", 0, 2) / 255
local $rh_b = ConvertColorValue($rgb_color, "i", 0, 3) / 255
local $rh_min = MinMin($rh_r, $rh_g, $rh_b)
local $rh_max = MaxMax($rh_r, $rh_g, $rh_b)
local $rh_delta = $rh_max - $rh_min
if $idx <> 1 then
local $rh_lightness = ($rh_min + $rh_max) / 2
if $idx = 3 then return Round($rh_lightness * $hsl_scale, 2)
local $rh_saturation = 0
if $rh_lightness > 0 and $rh_lightness < 1 then
If $rh_lightness < 0.5 then
$rh_saturation = $rh_delta / (2 * $rh_lightness)
else
$rh_saturation = $rh_delta / (2 - 2 * $rh_lightness)
endif
endif
If $idx = 2 then return Round($rh_saturation * $hsl_scale, 2)
endif
local $rh_hue = 0
if $rh_delta > 0 then
if $rh_max = $rh_r and $rh_max <> $rh_g then
$rh_hue += ($rh_g - $rh_b) / $rh_delta
endif
if $rh_max = $rh_g and $rh_max <> $rh_b then
$rh_hue += 2 + ($rh_b - $rh_r) / $rh_delta
endif
if $rh_max = $rh_b and $rh_max <> $rh_r then
$rh_hue += 4 + ($rh_r - $rh_g) / $rh_delta
endif
$rh_hue *= 60
endif
if $rh_hue < 0 then $rh_hue += 360
if $idx = 1 then return Round($rh_hue)
local $do_string = true
if not $idx then
$idx = ","
$do_string = false
endif
local $hsl_arr[3]
$hsl_arr[0] = Round($rh_hue)
$hsl_arr[1] = Round($rh_saturation * $hsl_scale, 2)
$hsl_arr[2] = Round($rh_lightness * $hsl_scale, 2)
local $hsl = $hsl_arr[0] & $idx & $hsl_arr[1] & $idx & $hsl_arr[2]
if $do_string then return $hsl
if $simple_array then return $hsl_arr
return StringSplit($hsl, $idx)
endfunc
func SendWait($string, $flag=0, $warn="You don't need to hold the modifier keys down for so long!")
", @ScriptLineNumber, 7);debug
string(" & $string & "," & $flag & "," & $warn & ")", @ScriptLineNumber, 7);debug
$am_sending = true
local $HKt = TimerInit()
while _IsPressed("10") or _IsPressed("11") or _IsPressed("12") or _IsPressed("5B") or _IsPressed("5C")
if $warn <> "" and TimerDiff($HKt) > 1000 then
debug("SendWait(HOLDING_KEYS_WARNING)", @ScriptLineNumber, 7)
if IniRead($ini_path, $my_name, "holding_keys_warning", $OFF) = $OFF then
MsgBox($MB_TOPMOST, "Note..", $warn)
IniWrite($ini_path, $my_name, "holding_keys_warning", $ON)
endif
endif
Sleep(50)
wend
Send($string, $flag)
$am_sending = false
return $string
endfunc
" value.
func CorzFancyInputBox($title, $prompt, $default_text="", $pass=default, $ib_w=default, $ib_h=default, $ib_x=default, $ib_y=default, _
$timeout=default, $gui_ex=false, $style=default, $inipath=default, $sectionname=default, $sel1=default, $sel2=default)
debug("CorzFancyInputBox(title: " & $title & ", prompt: " & $prompt & ", default_text: " & $default_text & ", pass: " & $pass & ", ib_w: " & $ib_w & ", ib_h: " & $ib_h & ", ib_x: " & $ib_x & ", ib_y: " & $ib_y & ", timeout: " & $timeout & ", gui_ex: " & $gui_ex & ", style: " & $style & ", inipath: " & $inipath & ", sectionname: " & $sectionname & ", sel1: " & $sel1 & ", sel2: " & $sel2 & ")...", @ScriptLineNumber, 7)
local $previous_event_mode = AutoItSetOption("GUIOnEventMode", 0)
local $previous_coord_mode = AutoItSetOption("GUICoordMode", 1)
local $pref_name = CleanPrefName($title)
if not $inipath or $inipath = default then $inipath = $ini_path
if not $sectionname or $sectionname = default then $sectionname = $my_name
if not $style or $style = default then $style = -1
if not $pass or $pass = default then $pass = ""
if $ib_x = Default then $ib_x = -1
if $ib_y = default then $ib_y = -1
if $ib_h = default then $ib_h = 96
if $ib_w = default then $ib_w = @DesktopWidth/2
$ib_x = IniRead($inipath, $sectionname, "inputbox_" & $pref_name & "_x", $ib_x)
$ib_y = IniRead($inipath, $sectionname, "inputbox_" & $pref_name & "_y", $ib_y)
$ib_w = IniRead($inipath, $sectionname, "inputbox_" & $pref_name & "_width", $ib_w)
if not $ib_x then $ib_x = -1
if not $ib_y then $ib_y = -1
if not $ib_h then $ib_h = 96
if not $ib_w then $ib_w = @DesktopWidth/2
debug("$ib_x: " & $ib_x, @ScriptLineNumber, 8)
debug("$ib_y: " & $ib_y, @ScriptLineNumber, 8)
debug("$ib_h: " & $ib_h, @ScriptLineNumber, 8)
debug("$ib_w: " & $ib_w, @ScriptLineNumber, 8)
if $timeout = default then $timeout = 0
if $sel1 = default then $sel1 = 0
if $sel2 = default then $sel2 = -1
local $line = $prompt
if StringInStr($prompt, $MSG_LF) then
$line = StringMid($line, 1, StringInStr($line, $MSG_LF)-1)
endif
debug("line to length-check: " & $line, @ScriptLineNumber, 8)
local $line_length = StringLen($line)
debug("$line_length: " & $line_length, @ScriptLineNumber, 8)
local $min_w = $line_length * 7.2
debug("$min_w: " & $min_w, @ScriptLineNumber, 8)
if $ib_w < $min_w then $ib_w = $min_w
StringReplace($prompt, $MSG_LF, $MSG_LF)
local $line_count = @Extended + 1
debug("$line_count: " & $line_count, @ScriptLineNumber, 8)
local $return = false
local $error = 0
local $inputstyle = $ES_AUTOHSCROLL
local $exStyle = BitOr($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST)
if $style = -1 then $style = BitOr($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX)
if $pass <> 0 then $inputstyle = BitOr($ES_AUTOHSCROLL, $ES_PASSWORD)
local $ib_GUI = GUICreate($title, $ib_w, $ib_h, $ib_x, $ib_y, $style, $exStyle, $gui_ex)
local $lab_prompt = GUICtrlCreateLabel($prompt, 10, 5, $ib_w-10, 16*$line_count)
GUICtrlSetFont(-1, 10)
local $but_OK = GUICtrlCreateButton("OK", $ib_w-45, $ib_h-30, 40, 22, $BS_DEFPUSHBUTTON)
GUICtrlSetState(-1, $GUI_ONTOP)
GUICtrlSetTip(-1, "Save the setting." & $MSG_LF & _
"When you click this button (and the input is not empty)," & $MSG_LF & _
"the size and position of this dialog will be saved for future use.")
local $but_Cancel = GUICtrlCreateButton("Cancel", 5, $ib_h-30, 60, 22)
GUICtrlSetState(-1, $GUI_ONTOP)
GUICtrlSetTip(-1, "Cancel this dialog." & $MSG_LF & _
"Do not save the input." & $MSG_LF & _
"Do not save dialog's size and position.")
local $ib_font = IniRead($inipath, $sectionname, "inputbox_font", "Consolas")
local $inp_MyID = GUICtrlCreateInput($default_text, 70, $ib_h-30, $ib_w-125, 22, $inputstyle)
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlSetFont(-1, 10 , 400, "", $ib_font)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetTip(-1, $prompt)
GUICtrlSetResizing($lab_prompt, $GUI_DOCKALL)
GUICtrlSetResizing($but_OK, $GUI_DOCKSTATEBAR+$GUI_DOCKWIDTH+$GUI_DOCKRIGHT)
GUICtrlSetResizing($but_Cancel, $GUI_DOCKSTATEBAR+$GUI_DOCKLEFT+$GUI_DOCKWIDTH)
GUICtrlSetResizing($inp_MyID, $GUI_DOCKSTATEBAR+$GUI_DOCKLEFT+$GUI_DOCKRIGHT)
GUISetState(@SW_SHOW, $ib_GUI)
_GUICtrlEdit_SetSel($inp_MyID, $sel1, $sel2)
WinMove($title, "", default, default, $ib_w, $ib_h)
if $timeout <> 0 then local $dialog_begin = TimerInit()
local $size_array
while true
switch GUIGetMsg()
case $GUI_EVENT_RESIZED
$size_array = WinGetPos($title)
if not IsArray($size_array) then continueloop
local $my_width = $size_array[2]
if $size_array[2] < $min_w then
WinMove($title, "", default, default, $min_w, $ib_h)
$my_width = $min_w
endif
if $size_array[3] <> $ib_h then WinMove($title, "", default, default, $my_width, $ib_h)
case $GUI_EVENT_CLOSE, $but_Cancel
$return = false
$error = 1
exitloop
case $but_OK
$return = StringStripWS(GUICtrlRead($inp_MyID), 3)
exitloop
endswitch
if $timeout <> 0 then
if TimerDiff($dialog_begin)/1000 > $timeout then
$return = false
$error = 2
exitloop
endif
endif
wend
if $return then
local $x_coord = -1, $y_coord = -1, $ib_width
$size_array = WinGetPos($title)
if IsArray($size_array) then
$x_coord = $size_array[0]
$y_coord = $size_array[1]
$ib_width = $size_array[2]
endif
endif
AutoItSetOption("GUIOnEventMode", $previous_event_mode)
AutoItSetOption("GUICoordMode", $previous_coord_mode)
GUIDelete($ib_GUI)
if $return then
if $x_coord and $x_coord <> -1 then IniWrite($inipath, $sectionname, "inputbox_" & $pref_name & "_x", $x_coord)
if $y_coord and $y_coord <> -1 then IniWrite($inipath, $sectionname, "inputbox_" & $pref_name & "_y", $y_coord)
if $ib_width and $ib_width <> @DesktopWidth/2 then
IniWrite($inipath, $sectionname, "inputbox_" & $pref_name & "_width", $ib_width)
endif
return $return
endif
return SetError($error, 0, "")
endfunc
CorzFancyMsgBox()
A replacement for MsgBox, except with a checkbox for the user to never be
asked about the issue again. It's basic, but does the job.
Returns the number of the button the user clicked (1, 2, 3 or 4).
You can set the usual $hwnd and styles (defaults should be fine).
It will resize its height to fit the text sent (ish).
You can have from one to four buttons, sending the text required for each
button, or blank to produce no button. Obviously, if you want only two
buttons, you set the value of the first two and leave the last two blank.
If you set, for example, the value of the first and last buttons, leaving 2
and 3 blank, you will get four buttons, two of which will be blank!
You can also set which is the default button (1, 2, 3 or 4).
CorzFancyMsgBox() will store the X & Y position of the dialog for future
instances. Each dialog gets its own settings (the pref name being derived
from the title of the message box).
You can supply an ini path and section name to store the prefs, otherwise
CorzFancyMsgBox() will use the app default ini and main app [name] section.
If the user checks the "Always perform the chosen action" box, the user's
choice is saved to the ini file and in future CorzFancyMsgBox() will simply
return the pre-saved value.
You can also set an icon (full path, unless it's in your PATH) and icon
index (note: most icons inside shell32.dll use -negative IDs)..
Handy shell32.dll icons..
ID Icon
----- -------------
24 question mark
-211 question mark 3D
-28/28 stop (appliance)
-220 stop (no entry)
-237 warning triangle
-278 information (i) old 2D (default icon)
-317 cog (completely square, no transparency required!)
-239 Recycle
CorzFancyMsgBox() returns:
The number of the button the user clicked (1, 2, 3 or 4).
If the user clicked a button, @error and @extended are set to the final
X and Y positions of the dialog, respectively. FYI.
If the user cancels out of the dialog, @error will be set to 1 and the
function will return 0 as the value.
Examples:
CorzFancyMsgBox("This is a notice", "You never have to see this notice again")
$debug = CorzFancyMsgBox("Really Overwrite Files?", "Many triggers and tasks have been found to already exist in KeyBind.ini. Overwrite?" , 60, false, -1, $ini_path, "Test", "Yes", "No", "", "", 2, "shell32.dll", -237)
debug("$debug: =>" & $debug & "<=", @ScriptLineNumber, 7)
func CorzFancyMsgBox($title, $text, $timeout=0, $gui_ex=false, $style=-1, $inipath=$ini_path, _
$sectionname=$my_name, $butt1_txt="OK", $butt2_txt="", $butt3_txt="", $butt4_txt="", _
$default_butt=1, $icon_path="shell32.dll", $icon_id=-278)
debug("", @ScriptLineNumber, 7)
debug("CorzFancyMsgBox(" & $title & "," & $text & "," & $gui_ex & "," & $style & "," & $inipath & "," & $sectionname & "," & $butt1_txt & "," & $butt2_txt & "," & $butt3_txt & "," & $butt4_txt & "," & $default_butt & "," & $icon_path & "," & $icon_id & ")", @ScriptLineNumber, 7)
local $pref_name = CleanPrefName($title)
local $dont_bug_me = IniRead($inipath, $sectionname, $pref_name & "_dont_bug_me", 0)
debug("$dont_bug_me: =>" & $dont_bug_me & "<=", @ScriptLineNumber, 7)
if $dont_bug_me <> 0 then return $dont_bug_me
if $timeout = default then $timeout = 0
if $gui_ex = default then $gui_ex = false
if $style = default then $style = -1
if $inipath = default then $inipath = $ini_path
if $butt1_txt = default then $butt1_txt = "OK"
if not $butt1_txt then $butt1_txt = "OK"
if $sectionname = default then $sectionname = $my_name
local $dt_pushed
local $dt_warn_count = 0
local $error, $extended
local $last_event_mode = AutoItSetOption("GUIOnEventMode", 0)
local $last_coord_mode = AutoItSetOption("GUICoordMode", 0)
if $style = -1 then $style = BitOr($WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX)
local $exStyle = BitOr($WS_EX_TOPMOST, $GUI_WS_EX_PARENTDRAG)
local $dt_min_w = 400
local $dt_min_h = 130
local $dt_w
local $dt_h = $dt_min_h
local $text_len = StringLen($text)
debug("$text_len: =>" & $text_len & "<=", @ScriptLineNumber, 7)
local $size_array
local $addin_height = 0
while $addin_height < $text_len
$dt_h += 22
$addin_height += 50
$dt_min_h += 22
wend
local $butt_width
local $dt_x = IniRead($inipath, $sectionname, "msgbox_" & $pref_name & "_x", -1)
local $dt_y = IniRead($inipath, $sectionname, "msgbox_" & $pref_name & "_y", -1)
$dt_w = IniRead($inipath, $sectionname, "msgbox_" & $pref_name & "_width", $dt_min_w)
local $dt_GUI = GUICreate($title, $dt_w, $dt_h, $dt_x, $dt_y, $style, $exStyle, $gui_ex)
GUISetFont(-1, 10, 400, 0, "Segoe UI", 5)
GUISetBkColor(0xFFFFFF)
local $icon_width = 0
if $icon_path then $icon_width = 36
GUISetCoord(10, $dt_h-66)
local $check_dont_bug = GUICtrlCreateCheckBox("Always perform the chosen action.", 0, 0, 220, default, _
Bitor($WS_TABSTOP, $BS_AUTOCHECKBOX), BitOr($WS_EX_TOPMOST, $WS_EX_TRANSPARENT, $GUI_WS_EX_PARENTDRAG))
GUICtrlSetFont(-1, 8.5, 400, 0, "Segoe UI", 5)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKSIZE+$GUI_DOCKLEFT)
text" label..
GUISetCoord(15+$icon_width, 6)
GUICtrlCreatelabel($text, 0, 0, $dt_w-30-$icon_width, $dt_h-53, _
BitOr($SS_NOTIFY, $SS_LEFT), $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI", 5)
GUICtrlSetTip(-1, " You can click and drag the entire window around quickly from here ")
shell32.dll"
if $icon_path then
GUISetCoord(10, 10)
GUICtrlCreateIcon("", "", 0, -2, 32, 32, $SS_ICON, $WS_EX_TRANSPARENT)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetTip(-1, " this is an image ")
GUICtrlSetState(-1,$GUI_DISABLE)
GUICtrlSetImage(-1, $icon_path, $icon_id)
GUICtrlSetResizing(-1, $GUI_DOCKSIZE+$GUI_DOCKLEFT+$GUI_DOCKTOP)
endif
GUISetCoord(50,$dt_h-43)
", 0, 0, $dt_w, $dt_h, 0, $GUI_WS_EX_PARENTDRAG)
GUICtrlCreatelabel(" ", 0, 0, $dt_w-100, 2, 0, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, 0xF0F0F0)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKHEIGHT)
local $buttons = 1
if $butt2_txt then $buttons = 2
if $butt3_txt then $buttons = 3
if $butt4_txt then $buttons = 4
local $buttons_array[$buttons+1][2] = [[$buttons]]
local $buttonstyle = BitOr($BS_CENTER, $BS_FLAT, $BS_VCENTER, $BS_NOTIFY, $WS_TABSTOP)
local $total_width = 0, $gap = 7
local $button_top = $dt_h-33
local $i = 1
while $i <= $buttons
$buttons_array[$i][1] = Eval("butt" & $i & "_txt")
$i += 1
wend
for $i = $buttons_array[0][0] to 1 step -1
$butt_width = (StringLen($buttons_array[$i][1])*8)+20
GUISetCoord($dt_w-$total_width-$butt_width-$gap, $button_top)
$buttons_array[$i][0] = GUICtrlCreateButton($buttons_array[$i][1], 0, 0, $butt_width, 25, $buttonstyle)
GUICtrlSetFont(-1, 9, 400, 0, "Segoe UI", 5)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKSIZE+$GUI_DOCKRIGHT)
$total_width += $butt_width+$gap
if $i = $default_butt then ControlFocus($dt_GUI, "", $buttons_array[$i][0])
next
GUISetCoord(0,$button_top-8)
GUICtrlCreateLabel("", 0, 0, $dt_w-$total_width-2, 50, 0, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetTip(-1, " Yes, you can click and drag the entire window around quickly from here, too ")
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKSIZE+$GUI_DOCKLEFT+$GUI_DOCKRIGHT)
GUISetState(@SW_SHOW, $dt_GUI)
WinMove($dt_GUI, "", default, default, $dt_w, $dt_h)
local $msg
while true
$dt_pushed = 0
$msg = GUIGetMsg()
for $i = 1 to $buttons_array[0][0]
if $msg = $buttons_array[$i][0] then
$dt_pushed = $i
exitloop
endif
next
if $dt_pushed then
exitloop
else
select
case $msg = $GUI_EVENT_CLOSE
exitloop
case $msg = $GUI_EVENT_RESIZED
$size_array = WinGetPos($dt_GUI)
if not IsArray($size_array) then return false
if $size_array[2] < $dt_min_w then WinMove($dt_GUI, "", default, default, $dt_min_w, $size_array[3])
if $size_array[3] < $dt_min_h then WinMove($dt_GUI, "", default, default, $size_array[2], $dt_min_h)
case $msg = $check_dont_bug
if GUICtrlread($check_dont_bug) = $ON then
$dt_warn_count += 1
local $message = "From now on you will no longer be notified and " & $my_name & _
" will just get on with doing whatever YOU CHOOSE NEXT..."
if $dt_warn_count > 1 then $message = "You have been warned!"
if $dt_warn_count > 3 then $message = "Oh! Just DECIDE will you!"
MsgBox($MB_ICONWARNING+$MB_SYSTEMMODAL, "This is PERMANENT!!", $message)
endif
endselect
endif
Sleep(50)
wend
if $dt_pushed = 0 then
$error = 1
else
debug("CorzFancyMsgBox() User Clicked Button: " & $dt_pushed, @ScriptLineNumber, 7)
debug("CorzFancyMsgBox() User Chooses Option: " & $buttons_array[$dt_pushed][1], @ScriptLineNumber, 7)
$dont_bug_me = GUICtrlRead($check_dont_bug)
if $dont_bug_me = $ON then
IniWrite($inipath, $sectionname, $pref_name & "_dont_bug_me", $dt_pushed)
else
$size_array = WinGetPos($dt_GUI)
if IsArray($size_array) then
IniWrite($inipath, $sectionname, "msgbox_" & $pref_name & "_x", $size_array[0])
IniWrite($inipath, $sectionname, "msgbox_" & $pref_name & "_y", $size_array[1])
IniWrite($inipath, $sectionname, "msgbox_" & $pref_name & "_width", $size_array[2])
$error = $size_array[0]
$extended = $size_array[1]
endif
endif
endif
AutoItSetOption("GUIOnEventMode", $last_event_mode)
AutoItSetOption("GUICoordMode", $last_coord_mode)
GUIDelete($dt_GUI)
return SetError($error, $extended, $dt_pushed)
endfunc
func CorzFancyMsgBoxEM($title, $text, $timeout=0, $gui_ex=false, $style=-1, $inipath=$ini_path, _
$sectionname=$my_name, $butt1_txt="OK", $butt2_txt="", $butt3_txt="", $butt4_txt="", _
$default_butt=1, $icon_path="shell32.dll", $icon_id=-278)
debug("", @ScriptLineNumber, 7)
debug("CorzFancyMsgBoxEM(" & $title & "," & $text & "," & $gui_ex & "," & $style & "," & $inipath & "," & $sectionname & "," & $butt1_txt & "," & $butt2_txt & "," & $butt3_txt & "," & $butt4_txt & "," & $default_butt & "," & $icon_path & "," & $icon_id & ")", @ScriptLineNumber, 7)
local $pref_name = CleanPrefName($title)
local $dont_bug_me = IniRead($inipath, $sectionname, $pref_name & "_dont_bug_me", 0)
debug("$dont_bug_me: =>" & $dont_bug_me & "<=", @ScriptLineNumber, 7)
if $dont_bug_me <> 0 then return $dont_bug_me
if $timeout = default then $timeout = 0
if $gui_ex = default then $gui_ex = false
if $style = default then $style = -1
if $inipath = default then $inipath = $ini_path
if $butt1_txt = default then $butt1_txt = "OK"
if not $butt1_txt then $butt1_txt = "OK"
if $sectionname = default then $sectionname = $my_name
global $dt_open = true
global $dt_pushed = 0
global $dt_warn_count = 0
local $error, $extended
local $last_event_mode = AutoItSetOption("GUIOnEventMode", 1)
local $last_coord_mode = AutoItSetOption("GUICoordMode", 0)
if $style = -1 then $style = BitOr($WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX)
local $exStyle = BitOr($WS_EX_TOPMOST, $GUI_WS_EX_PARENTDRAG)
global $dt_min_w = 400
global $dt_min_h = 130
local $dt_w
local $dt_h = $dt_min_h
local $text_len = StringLen($text)
debug("$text_len: =>" & $text_len & "<=", @ScriptLineNumber, 7)
local $addin_height = 0
while $addin_height < $text_len
$dt_h += 22
$addin_height += 50
$dt_min_h += 22
wend
local $butt_width
local $dt_x = IniRead($inipath, $sectionname, "msgbox_" & $pref_name & "_x", -1)
local $dt_y = IniRead($inipath, $sectionname, "msgbox_" & $pref_name & "_y", -1)
$dt_w = IniRead($inipath, $sectionname, "msgbox_" & $pref_name & "_width", $dt_min_w)
global $dt_GUI = GUICreate($title, $dt_w, $dt_h, $dt_x, $dt_y, $style, $exStyle, $gui_ex)
GUISetFont(-1, 10, 400, 0, "Segoe UI", 5)
GUISetBkColor(0xFFFFFF)
GUISetOnEvent($GUI_EVENT_CLOSE, "cfmbCloseDialog", $dt_GUI)
GUISetOnEvent($GUI_EVENT_RESIZED, "cfmbResize", $dt_GUI)
local $icon_width = 0
if $icon_path then $icon_width = 36
GUISetCoord(10, $dt_h-66)
global $check_dont_bug = GUICtrlCreateCheckBox("Always perform the chosen action.", 0, 0, 220, default, _
Bitor($WS_TABSTOP, $BS_AUTOCHECKBOX), BitOr($WS_EX_TOPMOST, $WS_EX_TRANSPARENT, $GUI_WS_EX_PARENTDRAG))
GUICtrlSetFont(-1, 8.5, 400, 0, "Segoe UI", 5)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKSIZE+$GUI_DOCKLEFT)
GUICtrlSetOnEvent(-1, "cfmbWarnPermanent")
text" label..
GUISetCoord(15+$icon_width, 6)
GUICtrlCreatelabel($text, 0, 0, $dt_w-30-$icon_width, $dt_h-53, _
BitOr($SS_NOTIFY, $SS_LEFT), $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI", 5)
GUICtrlSetTip(-1, " You can click and drag the entire window around quickly from here ")
shell32.dll"
if $icon_path then
GUISetCoord(10, 10)
GUICtrlCreateIcon("", "", 0, -2, 32, 32, $SS_ICON, $WS_EX_TRANSPARENT)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetTip(-1, " this is an image ")
GUICtrlSetState(-1,$GUI_DISABLE)
GUICtrlSetImage(-1, $icon_path, $icon_id)
GUICtrlSetResizing(-1, $GUI_DOCKSIZE+$GUI_DOCKLEFT+$GUI_DOCKTOP)
endif
GUISetCoord(50,$dt_h-43)
", 0, 0, $dt_w, $dt_h, 0, $GUI_WS_EX_PARENTDRAG)
GUICtrlCreatelabel(" ", 0, 0, $dt_w-100, 2, 0, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, 0xF0F0F0)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKHEIGHT)
local $buttons = 1
if $butt2_txt then $buttons = 2
if $butt3_txt then $buttons = 3
if $butt4_txt then $buttons = 4
global $buttons_array[$buttons+1][2] = [[$buttons]]
local $buttonstyle = BitOr($BS_CENTER, $BS_FLAT, $BS_VCENTER, $BS_NOTIFY, $WS_TABSTOP)
local $total_width = 0, $gap = 7
local $button_top = $dt_h-33
local $i = 1
while $i <= $buttons
$buttons_array[$i][1] = Eval("butt" & $i & "_txt")
$i += 1
wend
for $i = $buttons_array[0][0] to 1 step -1
$butt_width = (StringLen($buttons_array[$i][1])*8)+20
GUISetCoord($dt_w-$total_width-$butt_width-$gap, $button_top)
$buttons_array[$i][0] = GUICtrlCreateButton($buttons_array[$i][1], 0, 0, $butt_width, 25, $buttonstyle)
GUICtrlSetFont(-1, 9, 400, 0, "Segoe UI", 5)
GUICtrlSetOnEvent(-1, "cfmbPushButton")
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKSIZE+$GUI_DOCKRIGHT)
$total_width += $butt_width+$gap
if $i = $default_butt then ControlFocus($dt_GUI, "", $buttons_array[$i][0])
next
GUISetCoord(0,$button_top-8)
GUICtrlCreateLabel("", 0, 0, $dt_w-$total_width-2, 50, 0, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetTip(-1, " Yes, you can click and drag the entire window around quickly from here, too ")
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKSIZE+$GUI_DOCKLEFT+$GUI_DOCKRIGHT)
GUISetState(@SW_SHOW, $dt_GUI)
WinMove($dt_GUI, "", default, default, $dt_w, $dt_h)
while $dt_open
Sleep(25)
wend
if $dt_pushed = 0 then
$error = 1
else
debug("CorzFancyMsgBox() User Clicked Button:: " & $dt_pushed, @ScriptLineNumber, 7)
debug("CorzFancyMsgBox() User Chooses Option:: " & $buttons_array[$dt_pushed][1], @ScriptLineNumber, 7)
$dont_bug_me = GUICtrlRead($check_dont_bug)
if $dont_bug_me = $ON then
IniWrite($inipath, $sectionname, $pref_name & "_dont_bug_me", $dt_pushed)
else
local $size_array = WinGetPos($dt_GUI)
if IsArray($size_array) then
IniWrite($inipath, $sectionname, "msgbox_" & $pref_name & "_x", $size_array[0])
IniWrite($inipath, $sectionname, "msgbox_" & $pref_name & "_y", $size_array[1])
IniWrite($inipath, $sectionname, "msgbox_" & $pref_name & "_width", $size_array[2])
$error = $size_array[0]
$extended = $size_array[1]
endif
endif
endif
AutoItSetOption("GUIOnEventMode", $last_event_mode)
AutoItSetOption("GUICoordMode", $last_coord_mode)
GUIDelete($dt_GUI)
return SetError($error, $extended, $dt_pushed)
endfunc
func cfmbResize()
local $size_array = WinGetPos($dt_GUI)
if not IsArray($size_array) then return false
if $size_array[2] < $dt_min_w then WinMove($dt_GUI, "", default, default, $dt_min_w, $size_array[3])
if $size_array[3] < $dt_min_h then WinMove($dt_GUI, "", default, default, $size_array[2], $dt_min_h)
endfunc
func cfmbPushButton()
debug("", @ScriptLineNumber, 7)
debug("cfmbPushButton(" & @GUI_CtrlId & ")", @ScriptLineNumber, 7)
for $i = 1 to $buttons_array[0][0]
if @GUI_CtrlId = $buttons_array[$i][0] then
$dt_pushed = $i
cfmbCloseDialog()
endif
next
endfunc
func cfmbWarnPermanent()
if GUICtrlread($check_dont_bug) = $OFF then return
$dt_warn_count += 1
local $message = "From now on you will no longer be notified and " & $my_name & _
" will just get on with doing whatever YOU CHOOSE NEXT..."
if $dt_warn_count > 1 then $message = "You have been warned!"
if $dt_warn_count > 3 then $message = "Oh! Just DECIDE will you!"
MsgBox($MB_ICONWARNING+$MB_SYSTEMMODAL, "This is PERMANENT!!", $message)
endfunc
func cfmbCloseDialog()
$dt_open = false
endfunc
;
;
;
;
func VersionCheckOnline($v_name, $vck_url, $dl_url, $my_ini, $my_section, $this_version, $GUI=default)
debug("VersionCheckOnline(v)" & $this_version, @ScriptLineNumber, 6)
if not @Compiled then return
local $version_checking = IniRead($my_ini, $my_section, "version_checking", "")
if $version_checking == 0 then return false
if $version_checking = -1 or $version_checking = "" then
local $do_checkver = CorzFancyInputBox("Automatic Version Checking?", $v_name & _
" can check online for a new version of itself." & $MSG_LF & _
"Enter the number of days between checks." & $MSG_LF & _
"(enter 0 to disable version checking.)", "" , " M" , _
400, 130 , (@DesktopWidth/2)-200, (@DesktopHeight/2)-50, 0, $GUI)
if $do_checkver = "" then return false
fuck off!", we write "0"
IniWrite($my_ini, $my_section, "version_checking", Number($do_checkver))
if $do_checkver = 0 then return false
endif
if $version_checking > 365 then $version_checking = 365
if $version_checking > 0 or StringLeft($version_checking, 1) = "a" then
local $version_checked = IniRead($my_ini, $my_section, "version_checked", "2000/01/01 00:00:00")
if StringLeft($version_checking, 1) <> "a" then
local $days_passed = _DateDiff("D", $version_checked, _NowCalc())
if $days_passed < $version_checking then return false
endif
endif
local $daystr = "every day"
if $version_checking > 1 then $daystr = "every " & $version_checking & " days"
if StringLeft($version_checking, 1) = "a" then $daystr = "always"
ProgressOn("Version Check (" & $daystr & ")" , "Checking for new version..")
ProgressSet(25)
$vck_url &= "&frequency=" & $version_checking & "¤t=" & $this_version
local $published_version = BackGroundDownload($vck_url, 5000, 25)
local $errmsg, $ext_error = @extended
if @error <> 0 or not $published_version then
ProgressOff()
switch $ext_error
case 1
$errmsg = $MSG_LF & "It looks like " & $my_domain & " is down."
case 2
$errmsg = $MSG_LF & "Connexion timed-out."
case 3
$errmsg = $MSG_LF & "Check your firewall."
endswitch
debug("Version Check FAILED." & $errmsg, @ScriptLineNumber, 1)
MsgBox(16, "Version Check FAILED!", "Could not determine version online." & $errmsg)
return false
endif
ProgressSet(50)
IniWrite($my_ini, $my_section, "version_checked", _NowCalc())
ProgressSet(75)
local $vcomp = _VersionCompare($this_version, $published_version)
switch $vcomp
case 0, 1
ProgressSet(100)
ProgressOff()
return false
case -1
ProgressSet(100)
local $version_response = MsgBox(4+48+262144, "New Version Available", _
"A newer version of " & $v_name & " is available." & $MSG_LF _
& "Would you like to visit the download page?")
ProgressOff()
switch $version_response
case 6
ShellExecute($dl_url)
endswitch
return $published_version
endswitch
endfunc
func BackGroundDownload($dl_URL, $timeout=default, $start=default, $save_file=default)
if $timeout = default then $timeout = 3000
if $start = default then $start = 0
if $save_file = default then $save_file = false
Local $c_time, $TmpFile
$TmpFile = _WinAPI_GetTempFileName(@TempDir)
if $save_file then
$TmpFile = $save_file
else
$TmpFile = _WinAPI_GetTempFileName(@TempDir)
endif
local $DL = InetGet($dl_URL, $TmpFile, ($INET_FORCERELOAD + $INET_FORCEBYPASS), $INET_DOWNLOADBACKGROUND)
local $BG_time = TimerInit()
local $dmsg
do
Sleep(10)
$c_time = Round(TimerDiff($BG_time))
if Mod($c_time, 100) < 11 then
if $c_time > 999 then
ProgressSet($start+(($c_time*3)/1000), "", "Checking: timeout in " & ($timeout-$c_time) & " ms")
endif
endif
if $c_time >= $timeout then
InetClose($DL)
$dmsg = "Failed. Connexion Timeout."
ProgressSet(0, "", $dmsg)
debug($dmsg, @ScriptLineNumber, 1)
return SetError(1, 2, $dmsg)
endif
until InetGetInfo($DL, $INET_DOWNLOADCOMPLETE)
local $success = InetGetInfo($DL, $INET_DOWNLOADSUCCESS)
InetClose($DL)
if not $success then
if Ping($my_domain, 500) < 10 then
$dmsg = "Failed. Suspect Firewall."
ProgressSet(0, "", $dmsg)
debug($dmsg, @ScriptLineNumber, 1)
return SetError(1, 3, $dmsg)
else
$dmsg = "Failed. Suspect Server Error."
debug($dmsg, @ScriptLineNumber, 1)
ProgressSet(0, "", $dmsg)
return SetError(1, 1, $dmsg)
endif
endif
local $dl_data = FileRead($TmpFile)
ProgressSet(0, "", "Success!")
if not $save_file then
FileDelete($TmpFile)
return $dl_data
endif
endfunc
func SetRelPathToDataDir($some_path)
if $some_path and StringLeft($some_path, 2) <> '\\' and StringMid($some_path, 2, 1) <> ':' then
CLT($some_path)
$some_path = $data_dir & "\" & $some_path
CRT($some_path)
endif
return $some_path
endfunc
func StartScreenSaver()
global $user32_dll = DllOpen("user32.dll")
local Const $WM_SYSCOMMAND = 0x112
local Const $SC_SCREENSAVE = 0xF140
local $gui = GUICreate("",10,10,-100,-100)
local $guiHandle = WinGetHandle($gui)
DllCall($user32_dll, "long", "SendMessageA", "long", $guiHandle, "long", $WM_SYSCOMMAND, "long", $SC_SCREENSAVE, "long", 0x0)
DllClose($user32_dll)
GUIDelete($gui)
endfunc
func LockWorkStation()
ShellExecute("rundll32.exe", 'user32.dll,LockWorkStation')
if @Error then return SetError(@Error, @Extended, false)
return true
endfunc
func _GetMonitors()
$monitors_list[0][0] = 0
local $handle = DllCallbackRegister("_MonitorEnumProc", "int", "hwnduser32.dll", "int", "EnumDisplayMonitors", "hwnd", 0, "ptr", 0, "ptr", DllCallbackGetPtr($handle), "lparam", 0)
DllCallbackFree($handle)
local $i = 0
for $i = 1 To $monitors_list[0][0]
if $monitors_list[$i][1] < $monitors_list[0][1] then $monitors_list[0][1] = $monitors_list[$i][1]
if $monitors_list[$i][2] < $monitors_list[0][2] then $monitors_list[0][2] = $monitors_list[$i][2]
if $monitors_list[$i][3] > $monitors_list[0][3] then $monitors_list[0][3] = $monitors_list[$i][3]
if $monitors_list[$i][4] > $monitors_list[0][4] then $monitors_list[0][4] = $monitors_list[$i][4]
next
return $monitors_list
endfunc
func _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam)
local $Rect = DllStructCreate("int leftleft")
$monitors_list[$monitors_list[0][0]][2] = DllStructGetData($Rect, "top")
$monitors_list[$monitors_list[0][0]][3] = DllStructGetData($Rect, "right")
$monitors_list[$monitors_list[0][0]][4] = DllStructGetData($Rect, "bottom")
return 1
endfunc
func GetWindowUnderMouse($iX,$iY)
local $stInt64,$aRet,$stPoint=DllStructCreate("longint64",DllStructGetPtr($stPoint))
$aRet=DllCall("user32.dll","hwnd","WindowFromPoint","int64",DllStructGetData($stInt64,1))
if @Error then return SetError(2,@Error,0)
if $aRet[0]=0 Then return SetError(3,0,0)
local $aResult = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $aRet[0], "uint", 2)
if @Error then return SetError(@Error, @Extended, 0)
return $aResult[0]
endfunc
func NumberInRange($number, $min, $max)
return ($number >= $min and $number <= $max)
endfunc
Hazel").
func Speak($text, $vol=50, $rate=0, $voice="", $wait=false)
debug("", @ScriptLineNumber, 7)
debug("Speak(" & $text & "," & $vol & "," & $rate & "," & $wait & ")", @ScriptLineNumber, 7)
global $o_speech = ObjCreate("SAPI.SpVoice")
if not IsObj($o_speech) then return false
local $speak_flag
if $wait then
$speak_flag = 10
else
$speak_flag = 11
endif
debug("Speak() --> DeTokenizeString -->" & $text & "<=", @ScriptLineNumber, 7)
$text = DeTokenizeString($text)
if FileExists($text) then
$speak_flag += 4
endif
local $choose_voice = $o_speech.GetVoices().Item(0)
if $voice then
for $i = 0 to $o_speech.GetVoices().Count() - 1
local $MS_voice = $o_speech.GetVoices().Item($i)
if StringInStr($MS_voice.GetAttribute("Name"), $voice) then
$choose_voice = $MS_voice
exitloop
endif
next
endif
with $o_speech
.Voice = $choose_voice
.Rate = $rate
.Volume = $vol
.Speak($text, $speak_flag)
endwith
return true
endfunc
func GetSpeechVoices()
local $o_speech = ObjCreate("SAPI.SpVoice")
if not IsObj($o_speech) then return -1
local $this_voice
local $voice_array[1]
for $i = 0 to $o_speech.GetVoices().Count() - 1
$this_voice = $o_speech.GetVoices().Item($i)
ArrayAdd($voice_array, $this_voice.GetAttribute("Name"))
next
return $voice_array
endfunc
func GetCommandLine($command_line, $cmd_array)
debug("", @ScriptLineNumber, 7)
debug("GetCommandLine(" & $command_line & ")", @ScriptLineNumber, 7)
debug_PrintArray($cmd_array, $LOG_LF & "cel.au3 :: (" & @ScriptLineNumber & ") " & " $cmd_array: ")
$command_line = StringStripWS($command_line, 3)
local $ret_array[2]
if $cmd_array[0] then
for $i = 1 to $cmd_array[0]
$cmd_array[$i] = StringStripWS($cmd_array[$i], 3)
next
if StringRight($command_line, 1) <> ")" then
$ret_array[1] = StringStripWS($cmd_array[$cmd_array[0]], 3)
for $i = 1 to $cmd_array[0]
if StringStripWS($cmd_array[$i], 3) <> $ret_array[1] then _
$ret_array[0] &= StringStripWS($cmd_array[$i], 3) & " "
next
else
$ret_array[1] = ""
for $i = 1 to $cmd_array[0]
$ret_array[0] &= StringStripWS($cmd_array[$i], 3) & " "
next
endif
endif
CRT($ret_array[0], " ")
return $ret_array
endfunc
." dots are also added to break up big sections.
; $myText = UrlToText('http:
; $myText = UrlToText('http:
func UrlToText($url)
debug("", @ScriptLineNumber, 7)
debug("UrlToText(" & $url & ")", @ScriptLineNumber, 7)
local $start = ""
local $end = ""
local $handle = ""
if StringInStr($url, "*", 0, -1) then
local $url_parts = StringSplit($url, "*")
$url = $url_parts[1]
if uBound($url_parts) > 2 then $start = $url_parts[2]
if uBound($url_parts) > 3 then $end = $url_parts[3]
endif
if StringLeft($url, 4) = "http" then
InetGet($url, @TempDir & "\UrlToText.tmp", 1)
$handle = FileOpen(@TempDir & "\UrlToText.tmp", 0)
else
$handle = FileOpen($url, 0)
endif
local $web_text = FileRead($handle)
if StringInStr($web_text, "<") then
$web_text = StringRegExpReplace($web_text, '</(div|p|tr|table)>', '. ')
$web_text = StringRegExpReplace($web_text, '\s', ' ')
$web_text = StringRegExpReplace($web_text, '<(?i)head(.*?)</(?i)head>', '')
$web_text = StringRegExpReplace($web_text, '<(?i)script(.*?)</(?i)script>', '')
$web_text = StringRegExpReplace($web_text, '<(?i)style(.*?)</(?i)style>', '')
$web_text = StringRegExpReplace($web_text, '</?[^>]*?>', '')
$web_text = ReplaceHTMLEntities($web_text)
endif
if $start then
$web_text = StringTrimLeft($web_text, StringInStr($web_text, $start)-1)
endif
local $strlen = StringLen($web_text)
local $end_pos = StringInStr($web_text, $end)
if $end_pos = 0 then $end_pos = $strlen
if $end then
$web_text = StringTrimRight($web_text, $strlen-$end_pos+1)
endif
FileClose($handle)
FileDelete(@TempDir & "\UrlToText.tmp")
return StringStripWS($web_text, 4)
endfunc
out" as your log string
out" command, eg..
out", 0, "command-line: " & $my_arguments & $LOG_LF & $LOG_LF)
func DoLog($dl_string, $dl_append=4, $log_extra="")
debug("Log extra: " & $log_extra, @ScriptLineNumber, 10 )
if $dl_string = "out" then
if $log_string then
if $dl_append = $ON then
$dl_append = $FO_APPEND + $FO_CREATEPATH
else
$dl_append = $FO_OVERWRITE + $FO_CREATEPATH
endif
local $my_log_file = FileOpen($log_location, $dl_append)
FileWriteLine($my_log_file, $my_name & _
" log: " & DateTimeString() & ".. " & $LOG_LF & _
"--------------------------------------------------------------------------------" & $LOG_LF)
if not $log_extra then
FileWriteLine($my_log_file, "command-line: " & $CmdLineRaw & $LOG_LF & $LOG_LF)
endif
FileWriteLine($my_log_file, $log_extra)
FileWriteLine($my_log_file, $log_string & $LOG_LF)
FileClose($my_log_file)
$log_string = ""
endif
else
$log_string &= UnifyCRLF($dl_string) & $LOG_LF
endif
return $dl_string
endfunc
/rsln" ensures these line numbers are
func debug($d_string, $ln=false, $level=1, $max_size=$max_debug_log_size)
if $level > $debug_level then return false
if IsArray($d_string) then return debug_PrintArray($d_string, "cel.au3 :: NOT A STRING!", $ln, $level, 0, $max_size)
if @Compiled then return debug_dump($d_string, $ln, $level, true, $max_size)
local $pre = ""
if $ln and $ln <> -1 then $pre = "(" & $ln & ") " & @Tab
.\" & @ScriptName & "(" & $ln & "): ==> "
""" & @ScriptFullPath & """(" & $ln & "): ==> "
if $pre then $pre &= "[ " & _NowCalcDate() & " @ " & _NowTime() & "::" & @Msec & " ][l:" & $level & "]" & @Tab
ConsoleWrite($pre & $d_string & $LOG_LF)
endfunc
func debug_dump($d_string, $ln=false, $level=1, $append=true, $max_size=$max_debug_log_size)
if $level > $debug_level then return false
if IsArray($d_string) then return debug_dumpArray($d_string, "$ARRAY:", $append, $level, $max_size)
local $pre, $code = 129
if $append = false then $code = 130
if $ln and $ln <> -1 then $pre = "(" & $ln & ") : ==> "
CheckLogSize($max_size)
local $fileh = FileOpen($dump_file, $code)
FileWriteLine($fileh, $pre & $d_string & $LOG_LF)
FileClose ($fileh)
endfunc
errer", really.
func debug_LogError($error_string)
FileWriteLine(@ScriptDir & "\error.log", "")
FileWriteLine(@ScriptDir & "\error.log", _
"--------------------------------------------------------------------------------")
FileWriteLine(@ScriptDir & "\error.log", @Year & "/" & @Mon & "/" & @MDay _
& " " & @Hour & ":" & @Min & ":" & @Sec )
FileWriteLine(@ScriptDir & "\error.log", "")
FileWriteLine(@ScriptDir & "\error.log", "command-line: " & $CmdLineRaw)
FileWriteLine(@ScriptDir & "\error.log", "")
FileWriteLine(@ScriptDir & "\error.log", $error_string)
endfunc
func debug_PrintArray(byref $array, $tring="array", $ln="", $level=1, $limit=0, $max_size=$max_debug_log_size, $forcedump=false, $string=false)
if $level > $debug_level then return false
local $pre
$pre = "(" & $ln & ") " & @Tab
if $pre then $pre &= "[ " & _NowCalcDate() & " @ " & _NowTime() & "::" & @Msec & " ][l:" & $level & "]" & @Tab
if not IsArray($array) then return ConsoleWrite($LOG_LF & $pre & $tring & ": NOT an array!" & _
$LOG_LF & $pre & "it's a string: " & "->" & $array & "<-" & $LOG_LF & $LOG_LF)
if UBound($array, 0) > 1 then return debug_Print2DArray($array, $tring, $ln, $level, $limit, $max_size, $forcedump, $string)
local $pa_string = ""
local $count = 0
for $element in $array
$pa_string &= '[' & $count & '] : ' & $element & $LOG_LF
$count += 1
if $count = $limit then exitloop
next
if $string then return $LOG_LF & $pre & $tring & ": " & $LOG_LF & $pa_string & $LOG_LF
if @Compiled or $forcedump then
debug_dump($LOG_LF & $pre & $tring & ": " & $LOG_LF & $pa_string & $LOG_LF, $ln, $level, true, $max_size)
else
ConsoleWrite($LOG_LF & $pre & $tring & ": " & $LOG_LF & $pa_string & $LOG_LF)
endif
endfunc
func debug_Print2DArray(byref $array, $tring="array", $ln="", $level=1, $limit=0, $max_size=$max_debug_log_size, $forcedump=false, $string=false)
if @Compiled and ($level > $debug_level) then return 0
local $pre
if $ln then $pre = "(" & $ln & ") " & @Tab
if not IsArray($array) then return debug($pre & $tring & ": NOT an array!" & $LOG_LF & _
$pre & "it's a string: " & "->" & $array & "<-" & $LOG_LF, @ScriptLineNumber, 5)
if UBound($array, 0) < 2 then return debug_PrintArray($array, $tring, $ln, $level, $limit, $ln)
if $pre then $pre &= "[ " & _NowCalcDate() & " @ " & _NowTime() & "::" & @Msec & " ][l:" & $level & "]" & @Tab
$limit += 1
local $cols = UBound($array, 2)
local $pa_string = ""
for $i = 0 to UBound($array, 1)-1
$pa_string &= '[' & $i & '] [0] = ' & $array[$i][0] & ' '
for $j = 1 to $cols-1
$pa_string &= ' [' & $j & '] = ' & $array[$i][$j] & ' '
next
$pa_string &= $LOG_LF
next
if $string then return $LOG_LF & $pre & $tring & ": " & $LOG_LF & $pa_string & $LOG_LF
if @Compiled or $forcedump then
debug_dump($LOG_LF & $pre & $tring & ": " & $LOG_LF & $pa_string & $LOG_LF, $ln, $level, true, $max_size)
else
ConsoleWrite($LOG_LF & $pre & $tring & ": " & $LOG_LF & $pa_string & $LOG_LF)
endif
endfunc
func debug_dumpArray(byref $array, $title="array", $append=true, $level=1, $max_size=$max_debug_log_size)
if not IsArray($array) then return 0
if $level > $debug_level then return false
if UBound($array, 0) > 1 then return debug_Print2DArray($array, $title, "", $level, 0, $max_size)
CheckLogSize($max_size)
local $code = 129
if $append = false then $code = 130
local $fileh = FileOpen($dump_file, $code)
local $da_string = $title & $LOG_LF
local $count = 0
for $element in $array
$da_string &= '[' & $count & '] : ' & $element & $LOG_LF
$count += 1
next
FileWrite($fileh, $da_string)
FileClose($fileh)
endfunc
func CheckLogSize($max_size=$max_debug_log_size)
if $max_size <> 0 then
if FileGetSize($dump_file) > ($max_size * 1048576) then
BackupFile($dump_file)
endif
endif
endfunc
func BackupFile($file)
local $backup = GetParent($file) & "\[" & FileDateStamp() & "]_" & RemoveExtension(Basename($file)) & "." & GetExtension($file)
local $ret = FileMove($file, $backup)
Run(@ComSpec & " /c " & 'compact.exe /C "' & $dump_file & '"', "", @SW_HIDE)
return $ret
endfunc
func ce_IsPressed($Key)
local $kp = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x' & $Key)
if not @error and BitAND($kp[0], 0x8000) = 0x8000 then return 1
return 0
endfunc
func WinVisible($GUI)
return BitAnd(WinGetState($GUI), 2)
endfunc
func ArrayJoin($array, $join_str=$LOG_LF)
debug_PrintArray($array, "cel.au3 :: ArrayJoin():", @ScriptLineNumber, 8)
debug("$join_str: " & $join_str, @ScriptLineNumber, 8)
local $ret_str
for $i = 1 to $array[0]
if $array[$i] <> "" then
$ret_str &= $array[$i] & $join_str
endif
next
CRT($ret_str, $join_str)
debug("$ret_str: " & $ret_str, @ScriptLineNumber, 8)
return $ret_str
endfunc
func GetFreeMem()
local $mem_stats = MemGetStats()
local $free = $mem_stats[2] * 1024
return $free
endfunc
func GetFreeMemHuman()
local $mem_stats = MemGetStats()
local $free = $mem_stats[2] / 1024
return FormatMB($free, 2)
endfunc
func CloseProcess($process_name)
SetError(0)
local $closed = ProcessClose($process_name)
if @Error then $closed = ProcessWaitClose($process_name)
if @Error then $closed = Run(@ComSpec & " /c " & 'taskkill /F /T /IM ' & $process_name, "", @SW_HIDE)
debug("Closed " & $process_name & ": " & $closed, @ScriptLineNumber, 7)
return $closed
endfunc
func SysInfoBox()
local $last_event_mode = AutoItSetOption("GUIOnEventMode", 0)
local $last_coord_mode = AutoItSetOption("GUICoordMode", 0)
local $si_x = IniRead($ini_path, $my_name, "si_x", -1)
local $si_y = IniRead($ini_path, $my_name, "si_y", -1)
local $si_w = IniRead($ini_path, $my_name, "si_w", 800)
local $si_h = IniRead($ini_path, $my_name, "si_h", 388)
if $si_w < 400 Then $si_w = 400
local $label_width = 140
local $info_width = $si_w - $label_width - 20
"
local $gui_sysinfo = GUICreate("System Information", $si_w, $si_h, $si_x, $si_y, _
BitOR($WS_CLIPSIBLINGS, $WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX), $WS_EX_TOPMOST)
GUISetIcon(@AutoItExe, 0, $gui_sysinfo)
GUISetCoord($si_w-33, 10)
local $label_env = GUICtrlCreateLabel("ENV", 0, 0, 30, 20)
GUICtrlSetResizing(-1, $GUI_DOCKMENUBAR+$GUI_DOCKWIDTH+$GUI_DOCKRIGHT)
GUICtrlSetTip(-1, " Click here to see this system's Environment Variables (aka. 'ENV VAR'). ")
GUISetCoord(10, -10)
local $computername = 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) ExpandEnvStrings", 1)
local $ip = GUICtrlCreateLabel("Local IP Address:", 0, 20, $label_width)
local $combo_info_drives = GUICtrlCreateCombo("", 0, 22, 100, 200)
local $my_drives = DriveGetDrive("FIXED")
for $i = 1 to $my_drives[0]
GUICtrlSetData($combo_info_drives, $my_drives[$i])
next
ControlCommand($gui_sysinfo, "", $combo_info_drives, "SelectString", @HomeDrive)
local $startupdir = 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)
GUICtrlCreateLabel("Time [H:M:S]:", 0, 20, $label_width)
local $myini = GUICtrlCreateLabel("My ini:", 0, 20, $label_width)
GUISetCoord($label_width + 10, -12)
local $current_drive = GUICtrlRead($combo_info_drives)
local $inp_computername = GUICtrlCreateInput(@ComputerName, 0, 20, 200, 20)
local $input_freemem = GUICtrlCreateInput(GetFreeMemHuman(), $label_width * 2, 0, 120, 20)
for $i = $computername to $input_freemem
GUICtrlSetResizing($i, $GUI_DOCKALL)
GUICtrlSetTip($i, " 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, 10)
local $input_username = GUICtrlCreateInput(@UserName, 0, 20, $info_width, 20)
local $vbit = "x86"
if @AutoItX64 = 1 then $vbit = "x64"
local $os_string = StringReplace(@OSVersion, "_", " ") & " (" & $vbit & ") " & @OSServicePack & " [" & @OSType & "][cpu:" & StringLower(@CPUArch) & "]"
GUICtrlCreateInput($os_string, 0, 20, $info_width, 20)
GUICtrlCreateInput(EnvGet("PATH"), 0, 20, $info_width, 20)
GUICtrlCreateInput(@IPAddress1, 0, 20, $info_width, 20)
local $input_drive_label = GUICtrlCreateInput(DriveGetLabel($current_drive & "\"), 0, 23, 150, 20)
local $input_totalspace = GUICtrlCreateInput(FormatMB(DriveSpaceTotal($current_drive & "\"), 2), 155, 0, 100, 20)
local $input_freespace = GUICtrlCreateInput(FormatMB(DriveSpaceFree($current_drive & "\"), 2) & " Free", 105, 0, 150, 20)
GUISetCoord($label_width + 10, 138)
GUICtrlCreateInput(@StartupDir, 0, 0, $info_width, 20)
GUICtrlCreateInput(@WindowsDir, 0, 20, $info_width, 20)
GUICtrlCreateInput(@SystemDir, 0, 20, $info_width, 20)
GUICtrlCreateInput(@DesktopDir, 0, 20, $info_width, 20)
GUICtrlCreateInput(@MyDocumentsDir, 0, 20, $info_width, 20)
GUICtrlCreateInput(@ProgramFilesDir, 0, 20, $info_width, 20)
GUICtrlCreateInput(@StartMenuDir, 0, 20, $info_width, 20)
GUICtrlCreateInput(@TempDir, 0, 20, $info_width, 20)
GUICtrlCreateInput(@DesktopWidth & "px" & " x " & @DesktopHeight & "px " & _
@DesktopDepth & "bit [" & @DesktopRefresh & "Hz]", 0, 20, $info_width, 20)
local $input_date = GUICtrlCreateInput(@YEAR & "-" & @MON & "-" & @MDAY, 0, 20, $info_width, 20)
local $input_time = GUICtrlCreateInput(@HOUR & ":" & @MIN & ":" & @SEC, 0, 20, $info_width, 20)
local $input_ini = GUICtrlCreateInput($ini_path, 0, 20, $info_width, 20)
for $i = $input_username To $input_ini
GUICtrlSetResizing($i, $GUI_DOCKALL+$GUI_DOCKRIGHT)
next
for $i = $inp_computername To $input_ini
GUICtrlSetFont($i, 8.5, 400, 0, "Consolas", 5)
next
for $i = $input_drive_label To $input_freespace
GUICtrlSetResizing($i, $GUI_DOCKALL)
next
GUISetState()
local $last_sec = @Sec
local $link = false
while true
if @Sec<> $last_sec then
GUICtrlSetData($input_time, @HOUR & ":" & @MIN & ":" & @SEC)
if @SEC < 2 and @HOUR = 0 and @MIN = 0 then
GUICtrlSetData($input_date, @YEAR & "-" & @MON & "-" & @MDAY)
endif
$current_drive = GUICtrlRead($combo_info_drives)
GUICtrlSetData($input_drive_label, DriveGetLabel($current_drive & "\"))
local $capacity = DriveSpaceTotal($current_drive & "\")
local $free_space = DriveSpaceFree($current_drive & "\")
GUICtrlSetData($input_totalspace, FormatMB($capacity, 2))
GUICtrlSetData($input_freespace, FormatMB($free_space, 2) & " Free")
if $free_space < ($capacity / 10) then
GUICtrlSetBkColor($input_freespace, 0xff0000)
else
GUICtrlSetBkColor($input_freespace, default)
endif
GUICtrlSetData($input_freemem, GetFreeMemHuman() & " Free")
$last_sec = @Sec
endif
local $msg = GUIGetMsg()
switch $msg
case $label_env
GUISetState(@SW_DISABLE, $gui_sysinfo)
DisplayEnvVars()
GUISetState(@SW_ENABLE, $gui_sysinfo)
case $gui_event_close
exitloop
case $combo_info_drives
$current_drive = GUICtrlRead($combo_info_drives)
GUICtrlSetData($input_drive_label, DriveGetLabel($current_drive & "\"))
GUICtrlSetData($input_totalspace, FormatMB(DriveSpaceTotal($current_drive & "\"), 2))
GUICtrlSetData($input_freespace, FormatMB(DriveSpaceFree($current_drive & "\"), 2) & " Free")
case $computername to $ip
GUICtrlSetState($msg + 19, $gui_focus)
case $startupdir to $myini
GUICtrlSetState($msg + 21, $gui_focus)
endswitch
local $mouse = GUIGetCursorInfo($gui_sysinfo)
if $mouse[4] <> $link then
if $mouse[4] = $label_env and $link = false then
$link = $mouse[4]
GUICtrlSetColor($label_env, 0x008DFF)
GUISetCursor(0, 1, $gui_sysinfo)
else
GUICtrlSetColor($label_env, default)
GUISetCursor()
$link = false
endif
endif
Sleep(100)
wend
local $size_array = WinGetPos($gui_sysinfo)
if IsArray($size_array) then
if $si_x <> $size_array[0] and $size_array[0] >= 0 and $size_array[0] < (@DesktopWidth - 25) then IniWrite($ini_path, $my_name, "si_x", $size_array[0])
if $si_y <> $size_array[1] and $size_array[1] >= 0 and $size_array[1] < (@DesktopHeight - 25) then IniWrite($ini_path, $my_name, "si_y", $size_array[1])
$size_array = WinGetClientSize($gui_sysinfo)
if IsArray($size_array) then
if $size_array[0] <> $si_w and $size_array[0] >= 100 then IniWrite($ini_path, $my_name, "si_w", $size_array[0])
if $size_array[1] <> $si_h and $size_array[1] >= 100 then IniWrite($ini_path, $my_name, "si_h", $size_array[1])
endif
endif
GUIDelete($gui_sysinfo)
AutoItSetOption("GUIOnEventMode", $last_event_mode)
AutoItSetOption("GUICoordMode", $last_coord_mode)
endfunc
func DisplayEnvVars()
local $PID = Run(@ComSpec & " /c set", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
local $env_vars
while true
$env_vars &= StdoutRead($PID)
if @Error then exitloop
wend
$env_vars = StringStripWS($env_vars, 3)
DisplayText($env_vars, "Environment Variables", 700, 600)
endfunc
func DisplayText($text, $title="For Reading..", $width=650, $height=$width, $inipath=$ini_path, $sectionname=$my_name)
local $last_event_mode = AutoItSetOption("GUIOnEventMode", 0)
local $last_coord_mode = AutoItSetOption("GUICoordMode", 0)
local $GUI_styles = BitOR($WS_CLIPSIBLINGS, $WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX)
local $edit_styles = BitOr($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOHSCROLL, $ES_MULTILINE, $WS_TABSTOP)
local $prefname = "display_txt_" & CleanPrefName($title)
local $dt_x = IniRead($inipath, $sectionname, $prefname & "_x", -1)
local $dt_y = IniRead($inipath, $sectionname, $prefname & "_y", -1)
local $GUI_txt_display = GUICreate($title, $width, $height, $dt_x, $dt_y, $GUI_styles, $WS_EX_TOPMOST)
local $edit_env = GUICtrlCreateEdit($text, 5, 5, $width-10, $height-40, $edit_styles)
local $butt_copy = GUICtrlCreateButton("Copy To ClipBoard", $width-155, $height-35, 105, 25)
local $butt_done = GUICtrlCreateButton("OK", 110, 0, 35, 25)
GUICtrlSetResizing($edit_env, $GUI_DOCKBORDERS)
GUICtrlSetResizing($butt_copy, $GUI_DOCKSTATEBAR+$GUI_DOCKWIDTH+$GUI_DOCKRIGHT)
GUICtrlSetResizing($butt_done, $GUI_DOCKSTATEBAR+$GUI_DOCKWIDTH+$GUI_DOCKRIGHT)
ControlFocus($GUI_txt_display, "", $edit_env)
Send("{Right}")
GUISetState(@SW_SHOW, $GUI_txt_display)
while true
switch GUIGetMsg()
case $butt_done, $gui_event_close
exitloop
case $butt_copy
ClipPut($text)
DisplayTooltipMessage("Data Successfully Copied to the ClipBoard", 3000, "Success!", true)
endswitch
Sleep(25)
wend
local $size_array = WinGetPos($GUI_txt_display)
if IsArray($size_array) then
IniWrite($inipath, $sectionname, $prefname & "_x", $size_array[0])
IniWrite($inipath, $sectionname, $prefname & "_y", $size_array[1])
endif
GUIDelete($GUI_txt_display)
AutoItSetOption("GUIOnEventMode", $last_event_mode)
AutoItSetOption("GUICoordMode", $last_coord_mode)
return true
endfunc"