I'm currently having a small issue with my script. I'm automating the export of some files with a 3rd party application which lacks a decent way to script around.
The app works just fine, but after the 2nd or 3rd run, whole OS (I'm running this on Windows 7 inside VMWare) is slow as hell!
I tried adding sleep()'s all around just to give it time to catch up, but to no avail.
Can someone shed some light as to why this is happening? (My code to "allow the VM to catch up" doesn't really fix anything, even after that long pause, the VM is still slow as hell)
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $program = "C:\Program Files\Smart Player\Smart Player.exe"
Opt("MouseCoordMode", 0)
Opt("WinTitleMatchMode", 4)
Opt("SendKeyDelay", 25)
Opt("TrayIconHide", 1)
$count = 0
Func GetFile
()
$file = RecursiveFileSearch
("Z:\Surv\_swap", "\.(dav)", ".", 1, True)
If $file[0] > 0 Then
ConsoleWrite("There are " & $file[0] & " files left" & @CRLF)
Return $file[1]
Else
Return False
EndIf
EndFunc ;==>GetFile
Func _log
($string)
$time = _Date_Time_GetSystemTime()
$time = _Date_Time_SystemTimeToDateTimeStr($time)
ConsoleWrite("[" & $time & "] " & $string & @CRLF)
Sleep(15)
EndFunc ;==>_log
Func ConvertFile
($file)
_log
("Do: " & $file);
If ProcessExists("Smart Player.exe") Then
_log
("Exit Program")
ProcessClose("Smart Player.exe")
EndIf
_log
("Run Program")
Run($program & " " & $file)
_log
("Waiting for activation...")
WinWaitActive("Smart Player")
Sleep(500)
_log
("Closing preview...")
; close preview
MouseMove(629, 83, 0)
MouseClick("left", 629, 83, 1, 0)
Sleep(50)
MouseMove(627, 110, 50)
Sleep(250)
MouseClick("left", 627, 110, 1, 0)
;ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:119]", "left", 1, 296, 11)
_log
("Clicking export...")
; click to export
;MouseMove(336,36)
Sleep(75)
MouseClick("left", 336, 36, 1, 0)
_log
("Checkmark on the file")
; check file
;MouseMove(644, 157)
Sleep(75)
MouseClick("left", 644, 157, 1, 0)
; stopping preview
;MouseMove(184, 475)
Sleep(150)
;MouseClick("left", 184, 475, 1, 0)
ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:32]")
Sleep(1000)
_log
("Clicking on Format")
; click on format
;MouseMove(788, 442, 0)
Sleep(500)
;MouseClick("left", 788, 442, 1, 0)
ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:11]")
_log
("Selecting AVI")
; Select AVI
MouseMove(770, 538, 0)
Sleep(250)
MouseClick("left", 770, 538, 1, 0)
Sleep(250)
_log
("Exporting now...")
; Click EXPORT
MouseMove(487, 544, 0)
Sleep(250)
MouseClick("left", 487, 544, 1, 10)
ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:27]")
; get directory
$dir = GetDir
($file)
_log
("Typing Directory: " & $dir)
; type directory
Sleep(2500)
WinWaitActive("Find Directory")
Send($dir & "{ENTER}")
Sleep(15000)
_log
("Checking if there are JPG files in here")
$findjpg = RecursiveFileSearch
($dir, "\.(jpg)", ".", 1, False)
If $findjpg[0] > 0 Then
_log
("Found JPG files... we failed :-(")
ProcessClose("Smart Player.exe")
FileChangeDir($dir)
FileDelete("*.jpg")
Sleep(1000)
Return True
EndIf
_log
("Waiting to finish export...")
; now waiting to finish export...
WinWaitActive("[W:301; H:136]")
_log
("Clicking OK")
; clicking "OK"
;MouseMove(159, 111)
Sleep(75)
MouseClick("left", 159, 111, 1, 0)
_log
("Exit Program")
ProcessClose("Smart Player.exe")
Sleep(500)
;DONE
$newfile = StringReplace($file, ".dav", ".done")
_log
("Moving file to: " & $newfile)
FileMove($file, $newfile)
_log
("--- --- --- DONE --- --- --")
EndFunc ;==>ConvertFile
While True
ConvertFile
(GetFile
())
Sleep(1000)
$count = $count + 1
If $count >= 5 Then
ConsoleWrite(@CRLF & "Allowing VM to catch up..." & @CRLF)
Sleep(20000)
$count = 0
EndIf
WEnd
Func GetDir
($sFilePath)
Local $aFolders = StringSplit($sFilePath, "\")
Local $iArrayFoldersSize = UBound($aFolders)
Local $FileDir = ""
If (Not IsString($sFilePath)) Then
Return SetError(1, 0, -1)
EndIf
$aFolders = StringSplit($sFilePath, "\")
$iArrayFoldersSize = UBound($aFolders)
For $i = 1 To ($iArrayFoldersSize - 2)
$FileDir &= $aFolders[$i] & "\"
Next
Return $FileDir
EndFunc ;==>GetDir
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.2.10.0
Author: WeaponX
Updated: 2/21/08
Script Function: Recursive file search
2/21/08 - Added pattern for folder matching, flag for return type
1/24/08 - Recursion is now optional
Parameters:
RFSstartdir: Path to starting folder
RFSFilepattern: RegEx pattern to match
"\.(mp3)" - Find all mp3 files - case sensitive (by default)
"(?i)\.(mp3)" - Find all mp3 files - case insensitive
"(?-i)\.(mp3|txt)" - Find all mp3 and txt files - case sensitive
RFSFolderpattern:
"(Music|Movies)" - Only match folders named Music or Movies - case sensitive (by default)
"(?i)(Music|Movies)" - Only match folders named Music or Movies - case insensitive
"(?!(Music|Movies)\:)\b.+" - Match folders NOT named Music or Movies - case sensitive (by default)
RFSFlag: Specifies what is returned in the array
0 - Files and folders
1 - Files only
2 - Folders only
RFSrecurse: TRUE = Recursive, FALSE = Non-recursive
RFSdepth: Internal use only
#ce ----------------------------------------------------------------------------
Func RecursiveFileSearch
($RFSstartDir, $RFSFilepattern = ".", $RFSFolderpattern = ".", $RFSFlag = 0, $RFSrecurse = True, $RFSdepth = 0)
;Ensure starting folder has a trailing slash
If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\"
If $RFSdepth = 0 Then
;Get count of all files in subfolders for initial array definition
$RFSfilecount = DirGetSize($RFSstartDir, 1)
;File count + folder count (will be resized when the function returns)
Global $RFSarray[$RFSfilecount[1] + $RFSfilecount[2] + 1]
EndIf
$RFSsearch = FileFindFirstFile($RFSstartDir & "*.*")
If @error Then Return
;Search through all files and folders in directory
While 1
$RFSnext = FileFindNextFile($RFSsearch)
If @error Then ExitLoop
;If folder and recurse flag is set and regex matches
If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then
If $RFSrecurse And StringRegExp($RFSnext, $RFSFolderpattern, 0) Then
RecursiveFileSearch
($RFSstartDir & $RFSnext, $RFSFilepattern, $RFSFolderpattern, $RFSFlag, $RFSrecurse, $RFSdepth + 1)
If $RFSFlag <> 1 Then
;Append folder name to array
$RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext
$RFSarray[0] += 1
EndIf
EndIf
ElseIf StringRegExp($RFSnext, $RFSFilepattern, 0) And $RFSFlag <> 2 Then
;Append file name to array
$RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext
$RFSarray[0] += 1
EndIf
WEnd
FileClose($RFSsearch)
If $RFSdepth = 0 Then
ReDim $RFSarray[$RFSarray[0] + 1]
Return $RFSarray
EndIf
EndFunc ;==>RecursiveFileSearch