Advertisement
Guest User

Untitled

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