Code: Select all
thread1 := AhkDllThread( A_ScriptDir "\autohotkey.dll" )
thread1.ahktextdll("msgbox 1")
sleep 5000
exitapp
Edit:
To be more specific the following works fine with 1.1.13.0
Code: Select all
#SingleInstance Force
DetectHiddenWindows On
FileEncoding utf-8
SetWorkingDir %A_ScriptDir%
OnExit Exit
MobyURL := "http://www.mobygames.com"
MobyStatsURL := MobyURL "/moby_stats"
MobySearchURL := MobyURL "/search/quick?q="
MobyNewGamesURL := MobyURL "/stats/recent_entries"
MobySitemapURL := MobyURL "/images/sitemap/sitemap_index.xml"
dataDir := A_WorkingDir "\Data"
resDir := A_WorkingDir "\Res"
smFile := dataDir "\sitemap.gS"
loadGIF := resDir "\loading.gif"
Systems := Object()
searchInts := Object()
Sitemaps := Object()
GlobalVarsScript( "Systems", 0, Systems )
GlobalVarsScript( "searchInts", 0, searchInts )
GlobalVarsScript( "Sitemaps", 0, Sitemaps )
GlobalVarsScript( "Systems_List", 100 )
mainGuiHwnd := New_Gui( "center", "w600 h400", "+LabelmainGuiThread_", "Undecided - ?????????" )
gosub mainGui_Build
loadImg := HTMLImage( mainGuiHwnd, loadGIF, 600 - 160, 400 - 160, 150, 150 )
ShowGui( mainGuiHwnd )
dllFunctions := CreateScript( ""
. "GetSystems{}`n"
. "GetSearchIntegers{}`r`n"
. "GetSitemapNames_F{}`n"
. "GetSitemapNames_W{}`n"
. "CheckSitemapNames{}`n"
. "CreateSitemapFile{}`n"
. "htmlLoad{}`n"
. "CheckJQuery{}`n"
. "UrlToVar{}`n"
. "sReplace{}`n"
. "msg{}`n"
. "StrX{}" )
Loop 5
dllThread%A_Index% := AhkDllThread( A_WorkingDir "\gScrape.dll" )
dllThread1.ahktextdll( GlobalVarsScript() "GetSearchIntegers( searchInts, """ MobySearchURL """ )`n" dllFunctions )
dllThread2.ahktextdll( GlobalVarsScript()
. "GetSystems( Systems, """ MobyStatsURL """ )`n"
. "for k, v in Systems`n{`n"
. "if k in SystemCount`n"
. "continue`n"
. "Systems_List .= k ""``n""`n}`n"
. "StringTrimRight Systems_List, Systems_List, 1`n"
. dllFunctions )
dllThread3.ahktextdll( GlobalVarsScript()
. "while !Systems.SystemCount`n"
. "sleep 500`n"
. "if !FileExist( """ smFile """ ) {`n"
. "GetSitemapNames_W( Sitemaps, """ MobySitemapURL """ )`n"
. "CreateSitemapFile( Sitemaps, """ smFile """ )`n} else {`n"
. "GetSitemapNames_F( Sitemaps, """ smFile """ )`n"
. "if CheckSitemapNames( Sitemaps, Systems ) {`n"
. "GetSitemapNames_W( Sitemaps, """ MobySitemapURL """ )`n"
. "CreateSitemapFile( Sitemaps, """ smFile """ )`n}`n}`n"
. dllFunctions )
while !Systems.SystemCount || !searchInts.HasKey( "zzzzzz" ) || !Sitemaps.HasKey( "zzzzzz" )
sleep 500
Loop 3
dllThread%A_Index%.ahkterminate()
loadImg.src := ""
EmptyMem()
msg( Sitemaps.nes "`n" Systems.NES.gameCount "`n" searchInts.NES )
return
Exit:
{
CloseGui( mainGuiHwnd )
Loop 5
dllThread%A_Index%.ahkterminate()
exitapp
}
mainGui_Build:
{
Gui %mainGuiHwnd%:margin, 0, 0
return
}
Escape::
mainGuiThread_Close:
{
exitapp
}
sReplace( var, SearchText, ReplaceText:="", All:="" ) {
StringReplace out, var, %SearchText%, %ReplaceText%, % All ? "All" : ""
return out
}
msg( lpText:="", lpCaption:="", uType:=0x00000000, hwnd:="" ) {
return DllCall( "MessageBox", UInt, hwnd, Str, lpText, Str, lpCaption, UInt, uType )
}
New_Gui( Pos:="", Size:="", Options:="", WinTitle:="", Color:="", pWin:="" ) {
if pWin
Gui New, % "-DPIScale +LastFound " Options " +Parent" pWin, %WinTitle%
else
Gui New, -DPIScale +LastFound %Options%, %WinTitle%
hwnd := WinExist()
if pWin
DllCall( "SetParent", UInt, hwnd, UInt, pWin )
Gui %hwnd%:Color, % Color = "" ? GetSysColor( 15 ) : Color
Gui %hwnd%:Show, %Pos% %Size% Hide
return hwnd
}
ShowGui( hwnd, Pos:="", Size:="", ShowOptions:="", GuiOptions:="" ) {
if GuiOptions
Gui %hwnd%:%GuiOptions%
Gui %hwnd%:Show, %Pos% %Size% %ShowOptions%
return
}
CloseGui( hwnd ) {
Gui %hwnd%:Destroy
return
}
HTMLImage( guiHwnd, Image, X, Y, W, H, BackgroundColor="", Id="AnimatedGif", eventHandler="" ) {
DefaultGUIColor := DllCall( "GetSysColor", UInt, 15 )
R := DefaultGUIColor & 0xFF
G := ( DefaultGUIColor >> 8 ) & 0xFF
B := ( DefaultGUIColor >> 16 ) & 0xFF
DefaultGUIColor := "rgb(" R ", " G ", " B ")"
Gui %guiHwnd%:Add, ActiveX, x%X% y%Y% w%W% h%H% +HwndGifHwnd, MSHTML:
GuiControlGet HtmlObj, %guiHwnd%:, %GifHwnd%
HtmlObj.Body.style.BackgroundColor := BackgroundColor = "" ? DefaultGUIColor : BackgroundColor
HtmlObj.Body.style.margin := 0
HtmlObj.Body.style.padding := 0
out := HtmlObj.createElement( "img" )
out.id := Id
out.src := Image
out.style.position := "absolute"
out.style.left := 0
out.style.top := 0
out.style.width := "100%"
out.style.height := "100%"
out.style.minWidth := "100%"
out.style.minHeight := "100%"
out.style.visibility := "visible"
HtmlObj.Body.appendChild( out )
if eventHandler
ComObjConnect( out, eventHandler )
return out
}
GetSysColor( DisplayElement:=1 ) {
VarSetCapacity( HexClr,7,0 )
SClr := DllCall( "GetSysColor", UInt, DisplayElement )
RGB := ( ( ( SClr & 0xFF ) << 16 ) | ( SClr & 0xFF00 ) | ( ( SClr & 0xFF0000 ) >> 16 ) )
DllCall( "msvcrt\sprintf", Str, HexClr, Str, "%06X", UInt, RGB )
Return HexClr
}
GetSystems( Systems, statsUrl ) {
statDoc := htmlLoad( statsUrl )
pWin := statDoc.parentWindow
jArray := pWin.JQuery( "tr:contains('Platform Stats')" ).nextAll().children( "td.sbL " ).toArray()
jArray2 := pWin.JQuery( "tr:contains('Platform Stats')" ).nextAll().children().children( "a" ).toArray()
Loop % jArray.length {
sysName := jArray[ A_Index - 1 ].innertext, 10, 10, 1
sysURL := jArray2[ A_Index - 1 ].href, 40, 40, 2
StringSplit linkName, sysURL, /
Systems.Insert( sysName, {} )
Systems[ sysName ].Insert( "gameCount", sReplace( jArray2[ A_Index - 1 ].innertext, "," ) )
Systems[ sysName ].Insert( "systemURL", sReplace( sysURL, "about:" ) )
Systems[ sysName ].Insert( "linkName", linkName4 )
}
Systems.Insert( "SystemCount", pWin.JQuery( "td.sbL:contains('Total Platforms')" ).next( ":first" ).text() )
}
GetSearchIntegers( Integers, searchURL ) {
searchDoc := htmlLoad( searchURL )
pWin := searchDoc.parentWindow
jArray := pWin.JQuery( "#platformInput" ).children().toArray()
Loop % jArray.length
Integers.Insert( jArray[ A_Index - 1 ].innertext, jArray[ A_Index - 1 ].value )
Integers.Insert( "zzzzzz", "zzzzzz" )
}
GetSitemapNames_F( Sitemaps, sitemapFile ) {
FileRead smNamesVar, %sitemapFile%
Loop Parse, smNamesVar, `n
{
Loop Parse, A_LoopField, CSV
{
if A_Index = 1
key := A_LoopField
else
Sitemaps.Insert( key, A_LoopField )
}
}
}
GetSitemapNames_W( Sitemaps, sitemapURL ) {
MobySitemap := UrlToVar( sitemapURL )
while smURL := StrX( MobySitemap, "<sitemap>", N, 9, "</sitemap>", 1, 10, N )
{
sys_smURL := StrX( smURL, "<loc>", 1, 5, "</loc>", 1, 6 )
if InStr( sys_smURL, "gamegroups.xml" )
continue
sys_smURLVar := UrlToVar( sys_smURL )
firstGameURL := StrX( sys_smURLVar, "<loc>", 1, 5, "</loc>", 1, 6 )
StringSplit smName, sys_smURL, _
StringSplit sLinkName, firstGameURL, /
if ( checkName != sLinkName5 )
Sitemaps.Insert( sLinkName5, smName2 )
checkName := sLinkName5
}
Sitemaps.Insert( "zzzzzz", "zzzzzz" )
}
CheckSitemapNames( Sitemaps, SystemsObj ) {
updtNeeded := 0
for k in SystemsObj
{
if k in SystemCount
continue
if !Sitemaps[ SystemsObj[ k ].linkName ] && SystemsObj[ k ].gameCount {
updtNeeded := 1
break
}
}
if !updtNeeded
Sitemaps.Insert( "zzzzzz", "zzzzzz" )
return updtNeeded
}
CreateSitemapFile( Sitemaps, sitemapFile ) {
if FileExist( sitemapFile )
FileDelete %sitemapFile%
for k, v in Sitemaps
{
if k in zzzzzz
continue
out .= """" k """,""" v """`n"
}
StringTrimRight out, out, 1
FileAppend %out%, %sitemapFile%
}
htmlLoad( url ) {
doc := ComObjCreate( "HtmlFile" )
docText := UrlToVar( url )
doc.open()
doc.write( docText )
doc.close()
Loop
{
sleep 500
if doc.readyState in complete
break
}
CheckJQuery( doc )
return doc
}
CheckJQuery( doc ) {
if !IsObject( doc.parentWindow.Jquery ) {
jQueryVar := UrlToVar( "https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" )
doc.parentWindow.execScript( jQueryVar )
Loop
{
sleep 500
if IsObject( doc.parentWindow.Jquery )
break
}
}
return
}
UrlToVar( URL, Charset:="utf-8", URLCodePage:="65001", Timeout:=5 ) {
ComObjError( 0 )
WebRequest := ComObjCreate( "WinHttp.WinHttpRequest.5.1" )
WebRequest.Option( 2 ) := URLCodePage
Loop
{
if A_Index = 3
{
msg( "There was a problem downloading the requested url:`n`n" URL "`n`nPlease close the application and try again.", "ERROR" )
exitapp
}
WebRequest.Open( "GET", URL, true )
WebRequest.Send()
WebRequest.WaitForResponse( Timeout )
if ( WebRequest.Status = 200 )
break
else
continue
}
ADO := ComObjCreate( "adodb.stream" )
ADO.Type := 1
ADO.Mode := 3
ADO.Open()
ADO.Write( WebRequest.ResponseBody )
ADO.Position := 0
ADO.Type := 2
ADO.Charset := Charset
return ADO.ReadText()
}
StrX(H, BS="", BO=0, BT=1, ES="", EO=0, ET=1, ByRef N="") {
Return SubStr(H,P:=(((Z:=StrLen(ES))+(X:=StrLen(H))+StrLen(BS)-Z-X)?((T:=InStr(H,BS,0,((BO<0)?(1):(BO))))?(T+BT):(X+1)):(1)),(N:=P+((Z)?((T:=InStr(H,ES,0,((EO)?(P+1):(0))))?(T-P+Z+(0-ET)):(X+P)):(X)))-P)
}