stringAppend(string, symbol, count)
{
if !string
string := ""
if !symbol or !count
return string
Loop % count
string .= symbol
return string
}
dialog_closed(pid := 0)
{
Loop 10
{
if isDialogOpen(pid)
{
pressDialogButton(0, pid)
sleep 100
}
else return true
}
return false
}
SortArray(Array, Order="A") {
MaxIndex := ObjMaxIndex(Array)
If (Order = "R") {
count := 0
Loop, % MaxIndex
ObjInsert(Array, ObjRemove(Array, MaxIndex - count++))
Return
}
Partitions := "|" ObjMinIndex(Array) "," MaxIndex
Loop {
comma := InStr(this_partition := SubStr(Partitions, InStr(Partitions, "|", False, 0)+1), ",")
spos := pivot := SubStr(this_partition, 1, comma-1) , epos := SubStr(this_partition, comma+1)
if (Order = "A") {
Loop, % epos - spos {
if (Array[pivot] > Array[A_Index+spos])
ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
}
} else {
Loop, % epos - spos {
if (Array[pivot] < Array[A_Index+spos])
ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
}
}
Partitions := SubStr(Partitions, 1, InStr(Partitions, "|", False, 0)-1)
if (pivot - spos) > 1
Partitions .= "|" spos "," pivot-1
if (epos - pivot) > 1
Partitions .= "|" pivot+1 "," epos
} Until !Partitions
}
loadFile(file, _path := "")
{
Array := StrSplit(file , "\")
file_name := Array[Array.MaxIndex()]
RegExMatch(file, "(.*)\\", path_file)
path_file := path_file1
while findFile(file_name, _path)
file_name := selectName(file_name)
FileRead, text, %file%
if !_path
FileAppend, % text, %path_file%\%file_name%
else
{
FileCreateDir % _path
FileAppend, % text, %_path%\%file_name%
}
}
selectName(file)
{
Array := StrSplit(file , ".")
expansion := "." Array[Array.MaxIndex()]
if RegExMatch(file, "\((\d+)\)" expansion "$", index)
file := RegExReplace(file, "\(\d+\)" expansion "$", "(" ++index1 ")" expansion)
else file := RegExReplace(file, expansion "$", " (2)" expansion)
return file
}
findFile(file, _path="")
{
if !_path {
Loop, Files, *.*
if (A_LoopFileName == file)
return true
} else {
Loop, Files, %_path%\*.*
if (A_LoopFileName == file)
return true
}
return false
}
breakDownText(text, length, length_radius, ArraySpace := "")
{
ArrayText := []
if !ArraySpace
ArraySpace := ["`n`n", "`n", " "]
Loop
{
text_1 := SubStr(text, 1, length-1)
text_1_2 := SubStr(text, length-length_radius, length+length_radius)
text_2 := SubStr(text, length)
if text_2
{
For i, space in ArraySpace
{
if (number := RegExMatch(text_1_2, "\Q" space "\E"))
{
text_output := SubStr(text, 1, length-length_radius+number-2)
text := SubStr(text, length-length_radius+number+StrLen(space)-1)
goto next
}
}
}
text_output := text_1
text := text_2
next:
ArrayText.Insert(text_output)
if !text_2
{
break
}
}
return ArrayText
}
lineSplitToLastSymbol(string, symbol)
{
number := 0
start_string := string
symbol_length := strLen(symbol)
Loop
{
temp_number := RegExMatch(string, "\Q" symbol "\E(.*)", var)
if temp_number
{
string := var1
number += temp_number + symbol_length - 1
}
else break
}
return [SubStr(start_string, 1, number-symbol_length), string]
}
getIp(ip) {
HTTP := "http://ip-api.com/json/" ip "?lang=ru"
site := ComObjCreate("WinHttp.WinHttpRequest.5.1")
site.open("POST", HTTP)
site.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
site.Send()
site.WaitForResponse(500)
siteinfo:=site.ResponseText
City = .*"city":"(.*)"\,"country"
Country = .*"country":"(.*)"\,"countryCode"
CountryCode = .*"countryCode":"(.*)"\,"isp"
ISP = .*"isp":"(.*)"\,"lat"
ZIP = .*"zip":"(.*)"\`}
if (RegExMatch(siteinfo, City, pCity) | (RegExMatch(siteinfo, Country, pCountry)) | RegExMatch(siteinfo, CountryCode, pCode) | RegExMatch(siteinfo, ISP, pISP) | RegExMatch(siteinfo, ZIP, pZIP)) {
return [pCity1,pCountry1,pCode1,pISP1,pZIP1]
}
}
distance(city1, city2) {
dist := ComObjCreate("WinHttp.WinHttpRequest.5.1")
dist.open("POST", "https://www.avtodispetcher.ru/distance/?from=" city1 "&to=" city2)
dist.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
dist.Send()
dist.WaitForResponse(500)
distinfo:=dist.ResponseText
RegDist = .*Расстояние:\s+<span id="totalDistance">(\d+)</span>\s+км; Время:.*
if(RegExMatch(distinfo, RegDist, Km)) {
DistKM := Km1
}
if(RegExMatch(distinfo, ".*>Начальная и конечная точка должны отличаться</li>")) {
DistKM := 0
}
return DistKM
}
GetYandexWeatherinfo(Id_Region){
urlDownloadToFile, % "https://export.yandex.ru/bar/reginfo.xml?region=" Id_Region, infoWeather.xml
FileRead, infoWeather, *P65001 %A_ScriptDir%\infoWeather.xml
RegExMatch(infoWeather,"<day>.*<title>(.*)</title>.*<country>(.*)</country>.*<day weekday..(..)..(\d+)</day>.*<month name..(.*)\W>(\d+)</month>.*<weather_type>(.*)</weather_type>.*<wind_speed>(.*)</wind_speed>.*<wind_direction .*>(.*)</wind_direction>.*</pressure>....<temperature .*>(.*)</temperature>....<time_zone>",weather)
FileDelete, %A_ScriptDir%\infoWeather.xml
weather := Array(weather1,weather2,weather3,weather4,weather5,weather6,weather7,weather8,weather9,weather10)
return weather
}
GetIpInfoEng(IP){
urlDownloadToFile, % "http://ip-api.com/xml/" IP, ipinfo.xml
FileRead, ipinfo, *P65001 %A_ScriptDir%\ipinfo.xml
RegExMatch(ipinfo,"<country><........(.*)..></country>.*<regionName><........(.*)..></regionName>.*<city><........(.*)..></city>.*<lat><........(.*)..></lat>.*<lon><........(.*)..></lon>.*<org><........(.*)..></org>.*<query><........(.*)..></query>",infip)
FileDelete, %A_ScriptDir%\ipinfo.xml
infip := Array(infip1,infip2,infip3,infip4,infip5,infip6,infip7)
return infip
}
GetIpInfoRu(IP){
UrlDownloadToFile, % "http://api.2ip.ua/geo.xml?ip=" IP, ipinfo.xml
UrlDownloadToFile, % "http://api.2ip.ua/provider.xml?ip=" IP, infprov.xml
FileRead, ipinfo, *P65001 %A_ScriptDir%\ipinfo.xml
FileRead, infprov, *P65001 %A_ScriptDir%\infprov.xml
RegExMatch(ipinfo,"<country_rus>(.*)</country_rus>.*<region_rus>(.*)</region_rus>.*<city_rus>(.*)</city_rus>.*<latitude>(.*)</latitude>.*<longitude>(.*)</longitude>.*<time_zone>(.*)</time_zone>",infip)
infprov := RegExReplace(infprov,""","''")
RegExMatch(infprov,"<ip>(.*)</ip>.*<name_rus>(.*)</name_rus>.*<site>(.*)</site>",infp)
FileDelete, %A_ScriptDir%\ipinfo.xml
FileDelete, %A_ScriptDir%\infprov.xml
infip := Array(infip1,infip2,infip3,infip4,infip5,infip6,infp1,infp2,infp3)
return infip
}
http(type, adress, error_msg := false) {
if (!DllCall("Wininet.dll\InternetGetConnectedState", "Str", 0x40, "Int", 0)) {
if (error_msg) {
return "No internet connection"
} else {
return false
}
}
if (!StrLen(adress)) {
if (error_msg) {
return "URL adress is empty"
} else {
return false
}
}
if (!RegExMatch(adress, "i)^http[s]?:\/\/.*$")) {
if (error_msg) {
return "Invalid URL adress"
} else {
return false
}
}
try {
http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
http.Open(type, adress, false)
http.SetRequestHeader("Referer", adress)
http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
http.SetRequestHeader("Accept-Encoding", "gzip, deflate")
http.Send()
http.WaitForResponse()
if (!StrLen(response := http.ResponseText)) {
if (error_msg) {
return "Response is empty"
} else {
return false
}
}
return response
} catch e {
if (error_msg) {
return e
} else {
return false
}
}
}