Advertisement
Guest User

Untitled

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