Advertisement
Guest User

Untitled

a guest
May 12th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 18.68 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;
  3. ; VLCManager.au3
  4. ;
  5. ; Execute and watchdog VLC Instances for video stream transcoding and broadcast
  6. ;
  7. ; Current architecture
  8. ; VLC Broadcaster 01: Pulls RTSP stream from rtsp://admin:password@camera.example.com/profile5/media.smp
  9. ;                     Broadcasts it locally via RTSP at rtsp://10.0.0.100:10122/camera02.sdp
  10. ;
  11. ; VLC Trancoder 01:   pulls Broadcaster 01 RTSP stream from rtsp://10.0.0.100:10122/camera02.sdp
  12. ;                     transcodes to 480x320 MJPEG available at: http://10.0.0.100:82/camera02.jpg
  13. ;
  14. ; VLC Trancoder 02:   pulls Broadcaster 01 RTSP stream from rtsp://10.0.0.100:10122/camera02.sdp
  15. ;                     transcodes to HLS available at: http://10.0.0.100:81/frontgate.m3u8
  16. ;
  17. ; VLC Trancoder 03:   pulls Broadcaster 01 RTSP stream from rtsp://10.0.0.100:10122/camera02.sdp
  18. ;                     transcodes to native resolution MJPEG available at: http://10.0.0.100:83/camera02.jpg
  19. ;
  20.  
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ; Notes
  23. ;
  24. ; - The Transcoders rely on the Broadcaster.  If the Broadcaster dies, kill the Transcoders, start the Broadcaster,
  25. ;   then restart the Transcoders.
  26. ;
  27. ; - VLC Transcoder 02 relies on IIS to share out .TS chunks saved in a RAM drive at v:\frontgate-1080
  28. ;
  29. ; - We'll also need to monitor that folder for disk space and clear it out between every run. If it runs out of
  30. ;   space while the process is running, kill the process, clear it out, then start the process again.
  31. ;
  32. ; - VLC Transcoder 2 should be kicking out files every 5 seconds or so.  If the folder doesn't have any files that
  33. ;   have been updated in the last 60 seconds, kill the process, clear it out, then start the process again.
  34. ;
  35. ; - HLS transcoding doesn't seem to work on VLC 2.2.0 or 2.2.1.  For now HLS will run on 2.1.5.
  36.  
  37. #AutoIt3Wrapper_icon=VLCProcessManager.ico
  38. #RequireAdmin
  39.  
  40. #include <Date.au3>
  41. #include <Array.au3>
  42. #include <File.au3>
  43.  
  44. #include <MsgBoxConstants.au3>
  45. #include <FileConstants.au3>
  46. #include <InetConstants.au3>
  47.  
  48. OnAutoItExitRegister("MyProcessCleanup")
  49.  
  50. Opt("TrayAutoPause", 0)
  51.  
  52. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  53. ; Define global values
  54. Global $strBroadcast01Dir = "vlc-2.1.5"
  55. Global $strBroadcast01Cmd = "vlc.exe --no-crashdump -I dummy --play-and-exit rtsp://admin:password@camera.example.com/profile5/media.smp --sout=#rtp{name=camera.example.com,sdp=rtsp://10.0.0.100:10122/camera02.sdp}"
  56. Global $strBroadcast01Title = "VLC Broadcast 01: camera02 (Front Yard) to RTSP @ rtsp://10.0.0.100:10122/camera02.sdp"
  57.  
  58. Global $strTranscode01Dir = "vlc-2.1.5"
  59. Global $strTranscode01Cmd = "vlc.exe --no-crashdump -I dummy --play-and-exit rtsp://10.0.0.100:10122/camera02.sdp --sout=#transcode{acodec=none,vcodec=mjpg,vb=512,width=480,height=320}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:82/camera02.jpg}"
  60. Global $strTranscode01Title = "VLC Transcode 01: camera02 (Front Yard) to MJPEG @ http://10.0.0.100:82/camera02.jpg"
  61.  
  62. Global $strTranscode02Dir = "vlc-2.1.5"
  63. Global $strTranscode02Cmd = "vlc.exe --no-crashdump -I dummy --play-and-exit rtsp://10.0.0.100:10122/camera02.sdp --sout=#transcode{width=1920,height=1080,fps=24,vb=2048,vcodec=h264,venc=x264{aud,profile=high,preset=ultrafast,keyint=24},acodec=aac,ab=96}:std{access=livehttp{seglen=1,delsegs=true,numsegs=3,index=V:\frontgate-1080\frontgate-1080.m3u8,index-url=frontgate-1080-########.ts},mux=ts{use-key-frames},dst=v:\frontgate-1080\frontgate-1080-########.ts}"
  64. Global $strTranscode02Title = "VLC Transcode 02: camera02 (Front Yard) to HLS @ http://10.0.0.100:81/frontgate.m3u8"
  65.  
  66. Global $strTranscode03Dir = "vlc-2.1.5"
  67. Global $strTranscode03Cmd = "vlc.exe --no-crashdump -I dummy --play-and-exit rtsp://10.0.0.100:10122/camera02.sdp --sout=#transcode{acodec=none,vcodec=mjpg}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:83/camera02.jpg}"
  68. Global $strTranscode03Title = "VLC Transcode 03: camera02 (Front Yard) to MJPEG @ http://10.0.0.100:83/camera02.jpg"
  69.  
  70. Global $strHLSTempFolder = "V:\frontgate-1080"
  71. Global $intProcessCheckInterval = 5000
  72.  
  73. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  74. ; Initialize the script
  75. ; Clear out anything in the HLS output folder
  76. FileDelete ($strHLSTempFolder)
  77.  
  78. ; Run the Broadcast 01
  79. ; This is a bit weird because AutoIt is shit at console apps.  Here we're calling cmd.exe plus the start command to get a separate console window started with the title set as we want it
  80. Run (@ComSpec & ' /c start "' & $strBroadcast01Title & '" ' & $strBroadcast01Cmd, $strBroadcast01Dir, @SW_HIDE)
  81. Local $hBroadcast01Window = WinWait ($strBroadcast01Title, "", 10)
  82. If Not $hBroadcast01Window Then
  83.    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), "VLC Process Manager", "ERROR: Failed to launch initial Broadcast 01 task.  Exiting.")
  84.    Exit(1)
  85. EndIf
  86.  
  87. ; Run the Transcode 01
  88. Run (@ComSpec & ' /c start "' & $strTranscode01Title & '" /LOW ' & $strTranscode01Cmd, $strTranscode01Dir, @SW_HIDE)
  89. Local $hTranscode01Window = WinWait ($strTranscode01Title, "", 10)
  90. If Not $hTranscode01Window Then
  91.    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), "VLC Process Manager", "ERROR: Failed to launch initial Transcode 01 task.  Exiting.")
  92.    Exit(1)
  93. EndIf
  94.  
  95. ; Run the Transcode 02
  96. Run (@ComSpec & ' /c start "' & $strTranscode02Title & '" /LOW ' & $strTranscode02Cmd, $strTranscode02Dir, @SW_HIDE)
  97. Local $hTranscode02Window = WinWait ($strTranscode02Title, "", 10)
  98. If Not $hTranscode02Window Then
  99.    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), "VLC Process Manager", "ERROR: Failed to launch initial Transcode 02 task.  Exiting.")
  100.    Exit(1)
  101. EndIf
  102.  
  103. ; Run the Transcode 03
  104. Run (@ComSpec & ' /c start "' & $strTranscode03Title & '" /LOW ' & $strTranscode03Cmd, $strTranscode03Dir, @SW_HIDE)
  105. Local $hTranscode03Window = WinWait ($strTranscode03Title, "", 10)
  106. If Not $hTranscode03Window Then
  107.    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), "VLC Process Manager", "ERROR: Failed to launch initial Transcode 03 task.  Exiting.")
  108.    Exit(1)
  109. EndIf
  110.  
  111. RecordInformationEvent("Initial startup complete.")
  112.  
  113. ; Wait a check interval for things to light up
  114. Sleep ($intProcessCheckInterval)
  115.  
  116. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  117. ; Main monitoring loop
  118. While 1
  119.   Sleep ($intProcessCheckInterval)
  120.  
  121.   ; Check if Broadcast 01 is running
  122.   if not WinExists ($hBroadcast01Window) Then
  123.     RecordErrorEvent("Broadcast 01 failure.")
  124.  
  125.     ; Kill transcode processes and clean out the HLS temp folder
  126.     WinKill ($hTranscode01Window)
  127.     WinKill ($hTranscode02Window)
  128.     WinKill ($hTranscode03Window)
  129.     FileDelete ($strHLSTempFolder)
  130.  
  131.     ; Re-launch the broadcast and the transcode processes
  132.     Run (@ComSpec & ' /c start "' & $strBroadcast01Title & '" ' & $strBroadcast01Cmd, $strBroadcast01Dir, @SW_HIDE)
  133.     $hBroadcast01Window = WinWait ($strBroadcast01Title, "", 10)
  134.     Run (@ComSpec & ' /c start "' & $strTranscode01Title & '" ' & $strTranscode01Cmd, $strTranscode01Dir, @SW_HIDE)
  135.     $hTranscode01Window = WinWait ($strTranscode01Title, "", 10)
  136.     Run (@ComSpec & ' /c start "' & $strTranscode02Title & '" ' & $strTranscode02Cmd, $strTranscode02Dir, @SW_HIDE)
  137.     $hTranscode02Window = WinWait ($strTranscode02Title, "", 10)
  138.     Run (@ComSpec & ' /c start "' & $strTranscode03Title & '" ' & $strTranscode03Cmd, $strTranscode03Dir, @SW_HIDE)
  139.     $hTranscode03Window = WinWait ($strTranscode03Title, "", 10)
  140.     ContinueLoop
  141.   EndIf
  142.  
  143.   ; Check if Transcode 01 is running
  144.   if not WinExists ($hTranscode01Window) Then
  145.     RecordErrorEvent("Transcode 01 failure.")
  146.     Run (@ComSpec & ' /c start "' & $strTranscode01Title & '" ' & $strTranscode01Cmd, $strTranscode01Dir, @SW_HIDE)
  147.     $hTranscode01Window = WinWait ($strTranscode01Title, "", 10)
  148.     ContinueLoop
  149.   EndIf
  150.  
  151.   ; Check if Transcode 02 is running
  152.   if not WinExists ($hTranscode02Window) Then
  153.     RecordErrorEvent("Transcode 02 failure.")
  154.     FileDelete ($strHLSTempFolder)
  155.     Run (@ComSpec & ' /c start "' & $strTranscode02Title & '" ' & $strTranscode02Cmd, $strTranscode02Dir, @SW_HIDE)
  156.     $hTranscode02Window = WinWait ($strTranscode02Title, "", 10)
  157.     ContinueLoop
  158.   EndIf
  159.  
  160.   ; Check if Transcode 03 is running
  161.   if not WinExists ($hTranscode03Window) Then
  162.     RecordErrorEvent("Transcode 03 failure.")
  163.     Run (@ComSpec & ' /c start "' & $strTranscode03Title & '" ' & $strTranscode03Cmd, $strTranscode03Dir, @SW_HIDE)
  164.     $hTranscode03Window = WinWait ($strTranscode03Title, "", 10)
  165.     ContinueLoop
  166.   EndIf
  167.  
  168.   ; Check to make sure we are updating the HLS folder, if not, check again after another check interval,
  169.   ; then restart Transcode 02 if we're still not updating
  170.   If Not CheckFolderFilesAreUpdating($strHLSTempFolder) Then
  171.     Sleep ($intProcessCheckInterval)
  172.     If Not CheckFolderFilesAreUpdating($strHLSTempFolder) Then
  173.       RecordErrorEvent("Transcode 02 HLS output folder not updating.")
  174.       WinKill ($hTranscode02Window)
  175.       FileDelete ($strHLSTempFolder)
  176.       Run (@ComSpec & ' /c start "' & $strTranscode02Title & '" ' & $strTranscode02Cmd, $strTranscode02Dir, @SW_HIDE)
  177.       $hTranscode02Window = WinWait ($strTranscode02Title, "", 10)
  178.       ContinueLoop
  179.     EndIf
  180.   EndIf
  181.  
  182.   ; Check if we're running out of space for HLS, trigger at 5MB free
  183.   Local $intHLSTempFolderFree = DriveSpaceFree ($strHLSTempFolder)
  184.   if $intHLSTempFolderFree <= 5 Then
  185.     RecordErrorEvent("Transcode 02 HLS output folder out of space.")
  186.  
  187.     WinKill ($hTranscode02Window)
  188.     FileDelete ($strHLSTempFolder)
  189.     Run (@ComSpec & ' /c start "' & $strTranscode02Title & '" ' & $strTranscode02Cmd, $strTranscode02Dir, @SW_HIDE)
  190.     $hTranscode02Window = WinWait ($strTranscode02Title, "", 10)
  191.     ContinueLoop
  192.   EndIf
  193.  
  194.   ; Check to see if we have a different VLC error, if so, click no and the next loop will catch the missing
  195.   ; process and do the needful
  196.   Local $strVlcStoppedErrorWindow = WinGetTitle ("VLC media player", "Close the program")
  197.   if $strVlcStoppedErrorWindow Then
  198.     RecordErrorEvent("VLC has stopped working dialog.")
  199.     WinActivate ($strVlcStoppedErrorWindow)
  200.     Send("{ENTER}")
  201.     ContinueLoop
  202.   EndIf
  203.  
  204.   ; Check to see if we have a MSVC runtime error, if so, click no and the next loop will catch the missing
  205.   ; process and do the needful
  206.   Local $strMsvcErrorWindow = WinGetTitle ("Microsoft Visual C++ Runtime Library", "Runtime Error!")
  207.   if $strMsvcErrorWindow Then
  208.     RecordErrorEvent("MS Visual C++ runtime error.")
  209.     WinActivate ($strMsvcErrorWindow)
  210.     Send("{ENTER}")
  211.     ContinueLoop
  212.   EndIf
  213.  
  214.   ; Check to see if we have a VLC error, if so, click no and the next loop will catch the missing
  215.   ; process and do the needful
  216.   Local $strVlcErrorWindow = WinGetTitle ("VLC", "Ooops: VLC media player just crashed")
  217.   if $strVlcErrorWindow Then
  218.     RecordErrorEvent("VLC crash report dialog.")
  219.     WinActivate ($strVlcErrorWindow)
  220.     Send("!n")
  221.     ContinueLoop
  222.   EndIf
  223.  
  224.   ; Check if Broadcast 01 RTSP port is open
  225.   If Not CheckTCPPortOpen("10.0.0.100", "10122") Then
  226.     RecordErrorEvent("Broadcast 01 RTSP port check 10.0.0.100:10122 failed.")
  227.  
  228.     ; Kill broadcast and transcode processes and clean out the HLS temp folder
  229.     WinKill ($hBroadcast01Window)
  230.     WinKill ($hTranscode01Window)
  231.     WinKill ($hTranscode02Window)
  232.     FileDelete ($strHLSTempFolder)
  233.  
  234.     ; Re-launch the broadcast and the transcode processes
  235.     Run (@ComSpec & ' /c start "' & $strBroadcast01Title & '" ' & $strBroadcast01Cmd, $strBroadcast01Dir, @SW_HIDE)
  236.     $hBroadcast01Window = WinWait ($strBroadcast01Title, "", 10)
  237.     Run (@ComSpec & ' /c start "' & $strTranscode01Title & '" ' & $strTranscode01Cmd, $strTranscode01Dir, @SW_HIDE)
  238.     $hTranscode01Window = WinWait ($strTranscode01Title, "", 10)
  239.     Run (@ComSpec & ' /c start "' & $strTranscode02Title & '" ' & $strTranscode02Cmd, $strTranscode02Dir, @SW_HIDE)
  240.     $hTranscode02Window = WinWait ($strTranscode02Title, "", 10)
  241.   EndIf
  242.  
  243.   ; Check if Transcode 01 MJPEG is kicking out data
  244.   If Not ServiceCheckMjpeg("http://10.0.0.100:82/camera02.jpg") Then
  245.     RecordErrorEvent("Transcode 01 MJPEG service check http://10.0.0.100:82/camera02.jpg failed.")
  246.     ; Kill Transcode 01 processes
  247.     WinKill ($hTranscode01Window)
  248.     ; Re-start Transcode 01
  249.     Run (@ComSpec & ' /c start "' & $strTranscode01Title & '" ' & $strTranscode01Cmd, $strTranscode01Dir, @SW_HIDE)
  250.     $hTranscode01Window = WinWait ($strTranscode01Title, "", 10)
  251.     ContinueLoop
  252.   EndIf
  253.  
  254.   ; Check if Transcode 03 MJPEG is kicking out data
  255.   If Not ServiceCheckMjpeg("http://10.0.0.100:83/camera02.jpg") Then
  256.     RecordErrorEvent("Transcode 03 MJPEG service check http://10.0.0.100:83/camera02.jpg failed.")
  257.     ; Kill Transcode 03 processes
  258.     WinKill ($hTranscode03Window)
  259.     ; Re-start Transcode 03
  260.     Run (@ComSpec & ' /c start "' & $strTranscode03Title & '" ' & $strTranscode03Cmd, $strTranscode03Dir, @SW_HIDE)
  261.     $hTranscode03Window = WinWait ($strTranscode03Title, "", 10)
  262.     ContinueLoop
  263.   EndIf
  264. WEnd  ;==> End main loop
  265.  
  266. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  267. ; Functions
  268.  
  269. ; If we exit the script, close the running VLC instances
  270. Func MyProcessCleanup()
  271.   if IsDeclared("hTranscode01Window") Then
  272.      WinKill ($hTranscode01Window)
  273.   EndIf
  274.  
  275.   if IsDeclared("hTranscode02Window") Then
  276.     WinKill ($hTranscode02Window)
  277.   EndIf
  278.  
  279.   if IsDeclared("hTranscode03Window") Then
  280.      WinKill ($hTranscode03Window)
  281.   EndIf
  282.  
  283.   if IsDeclared("hBroadcast01Window") Then
  284.     WinKill ($hBroadcast01Window)
  285.   EndIf
  286.  
  287.   FileDelete ($strHLSTempFolder)
  288. EndFunc  ;==>MyProcessCleanup
  289.  
  290. ; Hand this function a folder name (no trailing backslash), it will return 1 if there is a file that has been touched in the last 60 seconds
  291. ; cribbed heavily from: https://www.autoitscript.com/forum/topic/86878-script-to-check-folders-for-new-files
  292. Func CheckFolderFilesAreUpdating($Folder)
  293.   Local $iTimeDeltaTarget = 60
  294.  
  295.   Local $avFiles = _FileListToArray($Folder & "\", "*", $FLTA_FILES)
  296.   If @Error<>0 Then
  297.     Return (False)
  298.   EndIf
  299.  
  300.   Local $iNewestTime = 11111111111111; YYYYMMDDhhmmss set to an old time
  301.   Local $iNewestIndex = 0; Array index of newest file
  302.  
  303.   ; Find the newest file
  304.   For $p = 1 To $avFiles[0]
  305.     ;ConsoleWrite($avFiles[$p] & " ")
  306.     $iFileTime2 = Number(FileGetTime($Folder & "\" & $avFiles[$p], $FT_MODIFIED, $FT_STRING))
  307.     ;ConsoleWrite($iFileTime2 & @CRLF)
  308.     If $iFileTime2 > $iNewestTime Then
  309.       $iNewestTime = $iFileTime2
  310.       $iNewestIndex = $p
  311.     EndIf
  312.   Next
  313.   ;ConsoleWrite("Newest file found: " & $avFiles[$iNewestIndex] & @CRLF)
  314.  
  315.   If $iNewestIndex > 0 Then
  316.     Local $t = FileGetTime($Folder & "\" & $avFiles[$iNewestIndex])
  317.     Local $iTimeDelta = _DateDiff( 's', $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5], _NowCalc())
  318.     ;ConsoleWrite("$iTimeDelta: " & $iTimeDelta & @CRLF)
  319.     If $iTimeDelta > $iTimeDeltaTarget Then
  320.       ; Newest file is older than $iTimeDeltaTarget seconds
  321.       ;ConsoleWrite(_DateTimeFormat( _NowCalc(),0) & " The files in: " & $Folder & " have NOT been updated in the last minute." & @CRLF & $avFiles[$iNewestIndex] & " is the newest file with a modified date of " & $t[1] & "/" & $t[2] & "/" & $t[0] & " " & $t[3] & ":" & $t[4] & ":" & $t[5] & @CRLF)
  322.       Return (False)
  323.     Else
  324.       ; Newest file is NOT older than $iTimeDeltaTarget seconds
  325.       ;ConsoleWrite(_DateTimeFormat( _NowCalc(),0) & " The files in: " & $Folder & " have been updated in the last minute." & @CRLF & $avFiles[$iNewestIndex] & " is the newest file with a modified date of " & $t[1] & "/" & $t[2] & "/" & $t[0] & " " & $t[3] & ":" & $t[4] & ":" & $t[5] & @CRLF)
  326.       Return (True)
  327.     EndIf
  328.   Else
  329.     ;No files were found in the folder
  330.     ;ConsoleWrite("No files found in folder " & $Folder & @CRLF)
  331.     Return (False)
  332.   EndIf
  333. EndFunc  ;==>CheckFolderFilesAreUpdating
  334.  
  335. Func CheckTCPPortOpen($sCheckTcpHost, $iCheckTcpPort)
  336.   ; Set our connection timeout to whatever the check interval is.
  337.   Opt("TCPTimeout", $intProcessCheckInterval)
  338.   TCPStartup() ; Start the TCP service.
  339.  
  340.   ; Assign a Local variable the socket and connect to a Listening socket with the IP Address and Port specified.
  341.   Local $iSocket = TCPConnect($sCheckTcpHost, $iCheckTcpPort)
  342.  
  343.   If @error Then
  344.     ; The server is probably offline/port is not opened on the server.
  345.     ;ConsoleWrite("CheckTCPPortOpen: Could not connect" & @CRLF)
  346.     TCPCloseSocket($iSocket)
  347.     TCPShutdown() ; Close the TCP service.
  348.     Return False
  349.   Else
  350.     ;ConsoleWrite("CheckTCPPortOpen: Connection successful." & @CRLF)
  351.     TCPCloseSocket($iSocket)
  352.     TCPShutdown() ; Close the TCP service.
  353.     Return True
  354.   EndIf
  355. EndFunc  ;==>CheckTCPPortOpen
  356.  
  357. ; Hand this function the URL to an MJPEG stream, return true if it's streaming >= 100,000 bytes of data in $intProcessCheckInterval milliseconds
  358. Func ServiceCheckMjpeg($sCheckUrl)
  359.   Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
  360.   Local $hDownload = InetGet($sCheckUrl, "NUL", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) ; Start a background download
  361.   Do
  362.     Sleep(100)
  363.     ;ConsoleWrite('InetGetInfo($hDownload, $INET_DOWNLOADREAD):' & InetGetInfo($hDownload, $INET_DOWNLOADREAD) & @CRLF)
  364.     If InetGetInfo($hDownload, $INET_DOWNLOADREAD) >= 100000 Then ; if we've got a big enough chunk of data, return true
  365.       InetClose($hDownload)
  366.       Return True
  367.     EndIf
  368.   Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) Or (TimerDiff($hTimer) > $intProcessCheckInterval) ; if we've run out of time or we completed without enough data, return false
  369.   InetClose($hDownload)
  370.   Return False
  371. EndFunc   ;==>CheckTCPPortOpen
  372.  
  373. Func RecordErrorEvent($sEventDesc)
  374.   ; Log exception to Application event log and update the tray icon text
  375.   TraySetToolTip("ERROR @ " & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF & $sEventDesc)
  376.   ConsoleWrite(@YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " ERROR: " & $sEventDesc & @CRLF)
  377.   Run (@ComSpec & ' /c eventcreate.exe /t WARNING /l Application /SO VLCProcessManager /ID 1 /d "' & $sEventDesc & '"', "", @SW_HIDE)
  378. EndFunc  ;==>RecordErrorEvent
  379.  
  380. Func RecordInformationEvent($sEventDesc)
  381.   ; Log exception to Application event log and update the tray icon text
  382.   TraySetToolTip("STATUS @ " & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF & $sEventDesc)
  383.   ConsoleWrite(@YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " STATUS: " & $sEventDesc & @CRLF)
  384.   Run (@ComSpec & ' /c eventcreate.exe /t Information /l Application /SO VLCProcessManager /ID 1 /d "' & $sEventDesc & '"', "", @SW_HIDE)
  385. EndFunc  ;==>RecordInformationEvent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement