Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Аватара для Creat0R

Must AutoIt


Сообщения: 3054
Благодарности: 1009

Профиль | Сайт | Отправить PM | Цитировать


Цитата semiono:
Можно ль оптимизировать что нибудь тут? »
Можно, например я бы как можно меньше использовал Send().
В ControlClick() не обязательно CLASS указывать, а в конце вместо "Left" лучше использовать "Primary", т.к кнопки мышки могут быть изменены (для левшей):

Код: Выделить весь код
ControlClick($Title, "Modify, Repair or Remove installation", "Button3", "Primary", 1)
Также используется WinWaitActive(), хотя после запуска приложения окно не обязательно будет активированно, например если в системе будет выведенно какое то сообщение - Поэтому лучше просто ждать окно, потом активировать его, а потом ждать активирования..

Вобщем вот:
Поправленная версия
Код: Выделить весь код
Opt("WinWaitDelay", 1) ;Это чтобы быстрее окна отлавливал

Global $iShowErrorMessages = False ;Если тут выставить 'True' то будут отображаться сообщения об ошибках

Global $Title = "PowerArchiver"
Global $SetupFile = "powarc1022.exe" ; powarc1100b4.exe
Global $InstallPath = @ProgramFilesDir & "\Parch\"

BlockInput(1)

Run($SetupFile)
If @error Then _ProduceErrorMsg("There was an error (%i) to execute [powarc1022.exe]", 1, 1)

_WinWaitWinActivate($Title, "Welcome to PowerArchiver")
Send("{ENTER}")

If WinExists($Title, "Modify, Repair or Remove installation") Then
    ControlClick($Title, "Modify, Repair or Remove installation", "Button3", "Primary", 1)
    Send("&Remove")
    _WinWaitWinActivate($Title, "Completing the PowerArchiver")
    Send("{ENTER}")

    DirRemove($InstallPath, 1)
    FileDelete(@UserProfileDir & "\SendTo\Parch.lnk")
    FileDelete(@ProgramsDir & "\Parch.lnk")
    FileDelete(@SystemDir & "\Parch.cmd")

    RegDelete("HKLM\Software\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\Parch")
    RegDelete("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\Parch.exe")

    Exit
EndIf

_WinWaitWinActivate($Title, "Additional Install Options")
ControlClick($Title, "Additional Install Options", "Button4", "Primary", 1)
ControlClick($Title, "Additional Install Options", "Button5", "Primary", 1)
ControlClick($Title, "Additional Install Options", "Button7", "Primary", 1)
ControlClick($Title, "Additional Install Options", "Button8", "Primary", 1)
ControlClick($Title, "Additional Install Options", "Button9", "Primary", 1)
ControlClick($Title, "Additional Install Options", "Button10", "Primary", 1)
Send("{ENTER}")

_WinWaitWinActivate($Title, "Select Installation Folder")
ControlClick($Title, "Select Installation Folder", "Button2", "Primary", 1)

_WinWaitWinActivate($Title, "Change current destination folder")
ControlSetText($Title, "Change current destination folder", "RichEdit20W", $InstallPath, 1)
ControlClick($Title, "Change current destination folder", "Button1", "Primary", 1)

_WinWaitWinActivate($Title, "Select Installation Folder")
ControlClick($Title, "Select Installation Folder", "Button1", "Primary", 1)

_WinWaitWinActivate($Title, "Ready to Install")
Send("{ENTER}")

_WinWaitWinActivate($Title, "Completing the PowerArchiver")
ControlClick($Title, "", "Button4", "Primary", 1)
ControlClick($Title, "", "Button5", "Primary", 1)
Send("{ENTER}")

$hFile = FileOpen($InstallPath & "\desktop.ini", 10)

If $hFile = -1 Then
    _ProduceErrorMsg("There was an error (%i) to open the file [desktop.ini]", 2, 0)
Else
    FileWrite($hFile, "[.ShellClassInfo]" & @CRLF)
    FileWrite($hFile, "IconFile=Powerarc.exe" & @CRLF)
    FileWrite($hFile, "IconIndex=0" & @CRLF)

    FileClose($hFile)
EndIf

FileSetAttrib($InstallPath, "+R")

FileCreateShortcut($InstallPath & "\Powerarc.exe", @UserProfileDir & "\SendTo\Parch.lnk", _
    $InstallPath, "", "Parch", "", "", 0, @SW_SHOWNORMAL)
FileCreateShortcut($InstallPath & "\Powerarc.exe", @ProgramsDir & "\Parch.lnk", _
    $InstallPath, "", "Parch", "", "", 0, @SW_SHOWNORMAL)

; Registry
RegWrite("HKCU\Software\PowerArchiver\General", "Regname", "REG_SZ", "*")
RegWrite("HKCU\Software\PowerArchiver\General", "Regnumber", "REG_SZ", "*")
;
RegWrite("HKLM\Software\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\Parch", "", "REG_SZ", "&Parch")
RegWrite("HKLM\Software\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\Parch\command", "", _
    "REG_SZ", $InstallPath & "\Powerarc.exe")
;
RegWrite("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\Parch.exe", "", "REG_SZ", $InstallPath & "\Powerarc.exe")
RegWrite("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\Parch.exe", "Path", "REG_SZ", $InstallPath & "\")

$hFile = FileOpen(@SystemDir & "\Parch.cmd", 10)

If $hFile = -1 Then
    _ProduceErrorMsg("There was an error (%i) to open the file [Parch.cmd]", 3, 1)
Else
    FileWrite($hFile, "@start " & $InstallPath & "\Powerarc.exe " & """%1""" & @CRLF)
    FileClose($hFile)
EndIf

Func OnAutoItExit()
    BlockInput(0)
EndFunc   ;==>OnAutoItExit

Func _WinWaitWinActivate($sTitle, $sText, $iWait = 0)
    WinWait($sTitle, $sText, $iWait)
    WinActivate($sTitle, $sText)
    WinWaitActive($sTitle, $sText, $iWait)
EndFunc   ;==>_WinWaitWinActivate

Func _ProduceErrorMsg($sMsg, $iError, $iExit = 0)
    If $iShowErrorMessages Then
        If $iExit Then $sMsg &= @CRLF & @CRLF & "OK ===> EXIT"
        MsgBox(262144 + 16, $Title & " - Auto-Installer", StringFormat($sMsg, $iError))
    EndIf

    If $iExit Then Exit
EndFunc   ;==>_ProduceErrorMsg


P.S
При проверке синтаксиса в версии 3.2.12.x будут ошибки на ControlClick(), там забли обновить утилиту проверки синтаксиса в соответствии с новыми параметрами функции, в последних бетах этот баг исправили.

-------
“Сделай так просто, как возможно, но не проще этого.”... “Ты никогда не решишь проблему, если будешь думать так же, как те, кто её создал.”

Альберт Эйнштейн

P.S «Не оказываю техподдержку через ПМ/ICQ, и по email - для этого есть форум. ©»

http://creator-lab.ucoz.ru/Images/Icons/autoit_icon.png Русское сообщество AutoIt | http://creator-lab.ucoz.ru/Images/Ic...eator_icon.png CreatoR's Lab | http://creator-lab.ucoz.ru/Images/Icons/oac_icon.png Opera AC Community

Это сообщение посчитали полезным следующие участники:

Отправлено: 15:45, 22-09-2008 | #927