Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 9.89 KB | None | 0 0
  1. ; AOL File Downloader. *VERY MUCH BETA*
  2. ; by slipstream, in 2014
  3. ; Needs AOL 9.7.
  4. ; Run AOL 9.7, sign in, close all windows, run this script, it'll start downloading to C:\AOLDLs.
  5. ; Sorry for the mess of this script.. a mix of used stuff and no longer used stuff from debugging and previous iterations..
  6. ; The script *will* screw up if it encounters something it can't handle..
  7.  
  8. ; Start Area: the area number we start at
  9. $startarea = 270
  10.  
  11. #include <GuiListView.au3>
  12. #include <GuiListBox.au3>
  13. #include <ListBoxConstants.au3>
  14. #include <Array.au3>
  15. #include <Constants.au3>
  16. ;#include <StringConstants.au3>
  17. #include <WinAPI.au3>
  18. #include <SendMessage.au3>
  19. Const $PROCESS_READ = 0x10
  20. Const $RIGHTS_REQUIRED = 0xF0000
  21.  
  22. Func AOLList_GetCount($hwnd)
  23.     return _SendMessage($hwnd,$LB_GETCOUNT,0,0)
  24. EndFunc
  25.  
  26. Func AOLList_Select($hwnd,$index)
  27.     return _SendMessage($hwnd,$index,0)
  28. EndFunc
  29.  
  30. Func AOLList_GetText($hwnd,$index)
  31.     Global $hProcess
  32.     $memptr = _SendMessage($hwnd,$LB_GETITEMDATA,$index,0)
  33.     $memptr += 28
  34.     $struct1 = DllStructCreate("long pointer;")
  35.     $rBytes = 0
  36.     _WinAPI_ReadProcessMemory($hProcess,$memptr,DllStructGetPtr($struct1,"pointer"),4,$rBytes)
  37.     $struct2 = DllStructCreate("char string[2048];") ; we shouldn't need this much ram but just in case!
  38.     _WinAPI_ReadProcessMemory($hProcess,DllStructGetData($struct1,"pointer")+6,DllStructGetPtr($struct2,"string"),2048,$rbytes)
  39.     return DllStructGetData($struct2,"string")
  40. EndFunc
  41.  
  42. Func MakeValidFilename($fn)
  43.     $fn = StringReplace($fn,"\","_")
  44.     $fn = StringReplace($fn,"/","_")
  45.     $fn = StringReplace($fn,":","_")
  46.     $fn = StringReplace($fn,"*","_")
  47.     $fn = StringReplace($fn,"?","_")
  48.     $fn = StringReplace($fn,'"',"_")
  49.     $fn = StringReplace($fn,"<","_")
  50.     $fn = StringReplace($fn,">","_")
  51.     $fn = StringReplace($fn,"|","_")
  52.     Return $fn
  53. EndFunc
  54.  
  55. Func WinGetFirstChild($hwnd,$class)
  56.     ; loops the list of child windows, returns the hwnd of the first with specified class name or class names, if not found return 0
  57.     if not IsArray($class) then
  58.         Local $class2[1] = [$class]
  59.         $class = $class2
  60.     EndIf
  61.  
  62.     $hChild = _WinAPI_GetWindow($hwnd,$GW_CHILD)
  63.     While $hChild
  64.         $childClass = _WinAPI_GetClassName($hChild)
  65.         for $wanted in $class
  66.             if $wanted = $childClass then return $hChild
  67.         Next
  68.         $result = WinGetFirstChild($hChild,$class)
  69.         if not $result = 0 then return $result
  70.         $hChild = _WinAPI_GetWindow($hChild,$GW_HWNDNEXT)
  71.     WEnd
  72.  
  73.     return 0
  74. EndFunc
  75.  
  76. Func WinListChildren($hWnd, ByRef $avArr)
  77.     If UBound($avArr, 0) <> 2 Then
  78.         Local $avTmp[10][3] = [[0]]
  79.         $avArr = $avTmp
  80.     EndIf
  81.  
  82.     Local $hChild = _WinAPI_GetWindow($hWnd, $GW_CHILD)
  83.  
  84.     While $hChild
  85.         If $avArr[0][0]+1 > UBound($avArr, 1)-1 Then ReDim $avArr[$avArr[0][0]+10][3]
  86.         $avArr[$avArr[0][0]+1][0] = $hChild
  87.         $avArr[$avArr[0][0]+1][1] = _WinAPI_GetWindowText($hChild)
  88.         $avArr[$avArr[0][0]+1][2] = _WinAPI_GetClassName($hChild)
  89.         $avArr[0][0] += 1
  90.         WinListChildren($hChild, $avArr)
  91.         $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
  92.     WEnd
  93.  
  94.     ReDim $avArr[$avArr[0][0]+1][3]
  95. EndFunc
  96.  
  97. $hwnd = WinGetHandle("America  Online")
  98. if $hwnd = 0 then $hwnd = WinGetHandle("AOL")
  99. $pid = 0
  100. $tid = _WinAPI_GetWindowThreadProcessId($hwnd,$pid)
  101. $hProcess = _WinAPI_OpenProcess(BitOr($PROCESS_READ,$RIGHTS_REQUIRED),0,$pid)
  102. if not $hProcess then Exit
  103. for $area = $startarea to 40000
  104. ; kill everything that will be a nuisance to us
  105. while True
  106.     $hwnd2 = ControlGetHandle($hwnd,"","[REGEXPCLASS:(?i)(_AOL_Modal|AOL Child)]")
  107.     if $hwnd2 = 0 then ExitLoop
  108.     $title = WinGetTitle($hwnd2)
  109.     WinKill($hwnd2)
  110.     if WinExists($hwnd2) then WinClose($hwnd2)
  111.     if WinExists($hwnd2) then WinSetState($hwnd2,"",@SW_SHOW)
  112.     if WInExists($hwnd2) then ExitLoop
  113. WEnd
  114.  
  115. ControlFocus($hwnd,"","[CLASS:_AOL_Edit; INSTANCE:1]")
  116. ; aol://4400:
  117.  
  118. #cs
  119. If we get a list of downloads:
  120. Advanced (Class):   [CLASS:AOL Child; INSTANCE:1]
  121. ID: 31746
  122. Text:   Guild of Heroes WAV Files
  123.  
  124. List of errors:
  125.  
  126. >>>> Window <<<<
  127. Title:
  128. Class:  _AOL_Modal
  129.  
  130. Advanced (Class):   [CLASS:_AOL_Static; INSTANCE:1]
  131. ID:
  132. Text:   Sorry, but you do not have access to this library/file.
  133.  
  134. Class:  _AOL_Icon
  135. Instance:   1
  136. ClassnameNN:    _AOL_Icon1
  137. Name:
  138. Advanced (Class):   [CLASS:_AOL_Icon; INSTANCE:1]
  139. ID:
  140.  
  141. No released files [with upload]:
  142. ClassnameNN:    AOL Child1
  143. Name:
  144. Advanced (Class):   [CLASS:AOL Child; INSTANCE:1]
  145.  
  146. ; 2nd button;
  147. Class:  _AOL_Icon
  148. Instance:   2
  149. ClassnameNN:    _AOL_Icon2
  150. Name:
  151. Advanced (Class):   [CLASS:_AOL_Icon; INSTANCE:2]
  152.  
  153. ; Only one button [no upload]
  154. Name:
  155. Advanced (Class):   [CLASS:AOL Child; INSTANCE:1]
  156.  
  157. ClassnameNN:    _AOL_Icon2
  158. Name:
  159. Advanced (Class):   [CLASS:_AOL_Icon; INSTANCE:2]
  160. #ce
  161.  
  162. ; so.. based on this info.. let's try this:
  163.  
  164. while ControlGetText($hwnd,"","[CLASS:_AOL_Edit; INSTANCE:1]") <> "aol://4400:"&$area
  165.     ControlSetText($hwnd,"","[CLASS:_AOL_Edit; INSTANCE:1]","")
  166.     ControlSend($hwnd,"","[CLASS:_AOL_Edit; INSTANCE:1]","aol://4400:"&$area&"{DELETE}")
  167. WEnd
  168. ControlSend($hwnd,"","[CLASS:_AOL_Edit; INSTANCE:1]","{ENTER}")
  169. ;Sleep(1000)
  170. ;Global $test
  171. ;WinListChildren($hwnd,$test)
  172. ;_ArrayDisplay($test)
  173. ;Exit
  174. ;Sleep(1000)
  175. while True
  176.     $hwnd2 = WinGetHandle("[CLASS:_AOL_Modal]")
  177.     if $hwnd2 = 0 then $hwnd2 = WinGetFirstChild($hwnd,"AOL Child")
  178.     if ($hwnd2 = 0) or (StringInStr(WinGetTitle($hwnd2),"Welcome, ")) or (StringInStr(WinGetTitle($hwnd2),"AOL Channels")) Then
  179.         Sleep(500)
  180.     else
  181.         ExitLoop
  182.     EndIf
  183. WEnd
  184. $title = WinGetTitle($hwnd2)
  185. if $title == "" Then
  186.     ; this is an _AOL_Modal?
  187.     WinKill($hwnd2)
  188. Else
  189.     $ctrl = ControlGetText($hwnd2,"","[CLASS:_AOL_Static; INSTANCE:1]")
  190.     if StringInStr($ctrl,"There are no released files.") then
  191.         WinKill($hwnd2)
  192.         ContinueLoop
  193.     EndIf
  194.     ; plunder the list of downloads!
  195.     $hListBox = ControlGetHandle($hwnd2,"","[CLASS:_AOL_Listbox; INSTANCE:1]")
  196.     if $hListBox = 0 then
  197.         WinKill($hwnd2)
  198.         ContinueLoop
  199.     EndIf
  200.     ; wait for the list to be populated
  201.     while AOLList_GetCount($hListBox) = 0
  202.         sleep(500)
  203.     WEnd
  204.     $title = StringStripWS(WinGetTitle($hwnd2),3)
  205.     for $dlnumber = 1 to AOLList_GetCount($hListBox)
  206.     ControlSend($hListBox,"","","{ENTER}")
  207.     ; wait for the second child
  208.     $fail = False
  209.     while True
  210.         $hwnd3 = WinGetFirstChild($hwnd,"AOL Child")
  211.         if $hwnd3 = $hwnd2 then
  212.             Sleep(500)
  213.             $hwnd3 = WinGetHandle("[CLASS:_AOL_Modal]")
  214.             if not $hwnd3 = 0 Then
  215.                 $fail = True
  216.                 ExitLoop
  217.             EndIf
  218.         Else
  219.             ExitLoop
  220.         EndIf
  221.     WEnd
  222.     if $fail Then
  223.         WinKill($hwnd3)
  224.         ControlSend($hListBox,"","","{DOWN}")
  225.         WinActivate($hwnd2)
  226.         ContinueLoop
  227.     EndIf
  228.     While True
  229.         $ctrl = ControlGetText($hwnd3,"","[CLASS:_AOL_View; INSTANCE:1]")
  230.         if $ctrl = "" then
  231.             Sleep(500)
  232.         Else
  233.             ExitLoop
  234.         EndIf
  235.     WEnd
  236.     ;for $i = -1 to AOLList_GetCount($hListBox)+1
  237.     ;   ConsoleWrite(AOLList_GetText($hListBox,$i)&@CRLF)
  238.     ;Next
  239.     ControlEnable($hwnd3,"Download Now","[CLASS:_AOL_Icon]")
  240.     $fail = False
  241.     for $count = 1 to 10
  242.         WinActivate($hwnd3)
  243.         ControlSend($hwnd3,"","","{ENTER}")
  244.         $hwnd4 = WinWait("Download Manager","",1)
  245.         if not $hwnd4 = 0 then ExitLoop
  246.         if $count = 10 then $fail = True
  247.     Next
  248.     if $fail Then
  249.         WinKill($hwnd3)
  250.         ControlSend($hListBox,"","","{DOWN}")
  251.         while True
  252.             $hwndkill = ControlGetHandle($hwnd,"","[REGEXPCLASS:(?i)(_AOL_Modal|AOL Child)]")
  253.             if $hwndkill = 0 then ExitLoop
  254.             $titlekill = WinGetTitle($hwndkill)
  255.             if $titlekill = WinGetTitle($hwnd2) then ExitLoop
  256.             WinKill($hwndkill)
  257.             if WinExists($hwndkill) then WinClose($hwndkill)
  258.             if WinExists($hwndkill) then WinSetState($hwndkill,"",@SW_SHOW)
  259.             if WInExists($hwndkill) then ExitLoop
  260.         WEnd
  261.         WinActivate($hwnd2)
  262.         ContinueLoop
  263.     EndIf
  264.     if StringInStr(ControlGetText($hwnd4,"","[CLASS:_AOL_Static]"),"You have already downloaded this file") Then
  265.         WinKill($hwnd4)
  266.         WinKill($hwnd3)
  267.         ControlSend($hListBox,"","","{DOWN}")
  268.         while True
  269.             $hwndkill = ControlGetHandle($hwnd,"","[REGEXPCLASS:(?i)(_AOL_Modal|AOL Child)]")
  270.             if $hwndkill = 0 then ExitLoop
  271.             $titlekill = WinGetTitle($hwndkill)
  272.             if $titlekill = WinGetTitle($hwnd2) then ExitLoop
  273.             WinKill($hwndkill)
  274.             if WinExists($hwndkill) then WinClose($hwndkill)
  275.             if WinExists($hwndkill) then WinSetState($hwndkill,"",@SW_SHOW)
  276.             if WInExists($hwndkill) then ExitLoop
  277.         WEnd
  278.         WinActivate($hwnd2)
  279.         ContinueLoop
  280.     EndIf
  281.     $hEdit = ControlGetHandle($hwnd4,"","[CLASS:Edit; INSTANCE:1]")
  282.     $filename = ControlGetText($hEdit,"","")
  283.     if not FileExists("C:\AOLDLs\"&MakeValidFilename($title)) then
  284.         DirCreate("C:\AOLDLs\"&MakeValidFilename($title))
  285.         FileWrite("C:\AOLDLs\"&MakeValidFilename($title)&"\url.txt","aol://4400:"&$area)
  286.     EndIf
  287.     $subj = StringSplit($ctrl,@CRLF,3)
  288.     $subj = StringStripWS(StringTrimLeft($subj[0],8),3)
  289.     if not FileExists("C:\AOLDLs\"&MakeValidFilename($title)&"\"&MakeValidFilename($subj)) then DirCreate("C:\AOLDLs\"&MakeValidFilename($title)&"\"&MakeValidFilename($subj))
  290.     ControlSetText($hEdit,"","","C:\AOLDLs\"&MakeValidFilename($title)&"\"&MakeValidFilename($subj))
  291.     ControlSend($hEdit,"","","{ENTER}")
  292.     FileWrite("C:\AOLDLs\"&MakeValidFilename($title)&"\"&MakeValidFilename($subj)&"\info.txt",$ctrl)
  293.     ControlSetText($hEdit,"","",$filename)
  294.     ControlSend($hEdit,"","","{ENTER}")
  295.     while True
  296.         $hwnd5 = WinGetFirstChild($hwnd,"AOL Child")
  297.         if StringInStr(WinGetTitle($hwnd5),"File Transfer -") Then
  298.             WinWaitClose($hwnd5)
  299.             ExitLoop
  300.         EndIf
  301.         if stringinstr(wingettitle($hwnd5),"Download Confirmation - ") Then
  302.             ExitLoop
  303.         EndIf
  304.     WEnd
  305.     ;$hwnd5 = WinWait("Download Confirmation")
  306.     ;ControlSend($hwnd5,"","","{ENTER}")
  307.     WinKill($hwnd3)
  308.     ControlSend($hListBox,"","","{DOWN}")
  309.     while True
  310.         $hwndkill = ControlGetHandle($hwnd,"","[REGEXPCLASS:(?i)(_AOL_Modal|AOL Child)]")
  311.         if $hwndkill = 0 then ExitLoop
  312.         $titlekill = WinGetTitle($hwndkill)
  313.         if $titlekill = WinGetTitle($hwnd2) then ExitLoop
  314.         WinKill($hwndkill)
  315.         if WinExists($hwndkill) then WinClose($hwndkill)
  316.         if WinExists($hwndkill) then WinSetState($hwndkill,"",@SW_SHOW)
  317.         if WInExists($hwndkill) then ExitLoop
  318.     WEnd
  319.     WinActivate($hwnd2)
  320.     Next
  321. EndIf
  322. Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement