Search the Community
Showing results for tags 'NSIS'.
-
Heres some code to look at. #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.9.4 (beta) Author: Decipher Script Function: WinGet - Windows Program Downloader/Installer #ce ---------------------------------------------------------------------------- HttpSetUserAgent("Wget/1.13.4") ;- "portableapps.com/updater/update.ini" #include <String.au3> #include <Array.au3> #include <Date.au3> #include <File.au3> #include <IncludesWinHTTP.au3> #include <WinAPIEx.au3> Global $sTemp_Dir = _TempFile() DirCreate($sTemp_Dir) HotKeySet("{ESC}", "_Exit") ;/DESTINATION="" /AUTOCLOSE=true /HIDEINSTALLER=true /SILENT=true _Setup_uTorrent() ;"http://downloads.sourceforge.net/portableapps" Func _Setup_uTorrent() Local $uTorrent_Portable_Installer = _Download_uTorrent_Portable('http://sourceforge.net/projects/portableapps/files/uTorrent Portable') If $uTorrent_Portable_Installer Then If Not @error Then _Configure_uTorrent_Portable($uTorrent_Portable_Installer) If Not @error Then FileChangeDir(@ScriptDir) _Configure_uTorrent_WebUI() FileChangeDir($sTemp_Dir & "uTorrentPortable") Run("uTorrentPortable.exe /HIDE") ShellExecute("http://admin:test@127.0.0.1:8080/gui") ; Testing Else ConsoleWrite(@CRLF & "!> Error configuring uTorrent Portable! Code: " & @error & @CRLF) _Exit() EndIf EndIf While 1 Sleep(1000) WEnd EndFunc ;==>_Setup_uTorrent Func _Download_uTorrent_Portable($uTorrent_Portable_SourceForge_URL, $iIteration = False) Local $sPage_Data = _WinHttpGet($uTorrent_Portable_SourceForge_URL) If $sPage_Data = '' Or @error Then ConsoleWrite(@CRLF & '!> Connection Error or Invalid URL!' & @CRLF) Return SetError(1, 0, 0) EndIf Local $aDate, $iLatest_Index = 0, $iLast_Calc = Default, $aFileList = _StringBetween($sPage_Data, '<tr title="', '</tr>') ; 2012-08-01 For $iFile = 0 To UBound($aFileList, 1) - 1 $aDate = _StringBetween($aFileList[$iFile], '<abbr title="', '"') If Not IsArray($aDate) Then ContinueLoop If $aDate[0] = '' Then ContinueLoop $aDate = StringSplit($aDate[0], ' ', 3) $aDate[0] = StringReplace($aDate[0], '-', '/') Local $iDateCalc = _DateDiff('s', $aDate[0] & ' ' & $aDate[1], _NowCalc()) If $iLast_Calc = Default Then $iLast_Calc = $iDateCalc If $iDateCalc <= $iLast_Calc Then $iLatest_Index = $iFile $iLast_Calc = $iDateCalc Next Local $aFile_Name = _StringBetween($aFileList[$iLatest_Index], 'class="' & 'name' & '">', '</a>') If $iIteration Then FileChangeDir($sTemp_Dir) Local $sFile_Name = StringStripWS($aFile_Name[0], 7) If _WinHttpGet($uTorrent_Portable_SourceForge_URL & '/' & $sFile_Name, True) Then Return $sFile_Name Else Return False EndIf Else Local $sFile_Name = _Download_uTorrent_Portable($uTorrent_Portable_SourceForge_URL & '/' & StringStripWS($aFile_Name[0], 7), True) If $sFile_Name Then Return $sFile_Name Else Return False EndIf EndIf EndFunc ;==>_Download_uTorrent_Portable Func _Configure_uTorrent_Portable($sFile_Name) Run($sFile_Name) Local $sUTP_Title_Def = "[CLASS:#32770; TITLE:uTorrent Portable]" If Not WinWait($sUTP_Title_Def, "", 30) Then Return SetError(1, 0, 0) $hUTP = WinGetHandle($sUTP_Title_Def) If @error Then Return SetError(2, 0, 0) WinActivate($hUTP, "") If Not WinWaitActive($hUTP, "", 5) Then Return SetError(3, 0, 0) $sUTP_Text = WinGetText($hUTP, "") If StringInStr($sUTP_Text, "Please select a language for the installer.") Then If Not WinActive($hUTP) Then WinActivate($hUTP, "") If Not WinWaitActive($hUTP, "", 5) Then Return SetError(4, 0, 0) ControlCommand($hUTP, "", "[CLASS:ComboBox; INSTANCE:1]", "SelectString", "English") If @error Then Return SetError(5, 0, 0) If Not ControlClick($hUTP, "", "[CLASS:Button; INSTANCE:1]") Then Return SetError(6, 0, 0) EndIf $sUTP_Title_Def = "[CLASS:#32770; INSTANCE:1; TITLE:uTorrent Portable | PortableApps.com Installer]" If Not WinWait($sUTP_Title_Def, "", 10) Then Return SetError(7, 0, 0) $hUTP = WinGetHandle($sUTP_Title_Def) For $i = 1 To 100 ; 10 seconds If WinGetTitle($hUTP, "") <> "uTorrent Portable | PortableApps.com Installer" Then Sleep(500) If $i = 100 Then Return SetError(8, 0, 0) ContinueLoop EndIf ExitLoop Next WinActivate($hUTP, "") If Not WinWaitActive($hUTP, "", 5) Then Return SetError(9, 0, 0) If Not ControlClick($hUTP, "", "[CLASS:Button; INSTANCE:2]") Then Return SetError(10, 0, 0) For $i = 1 To 100 $sText = ControlGetText($hUTP, "", "Button2") If $sText <> "I &Agree" Then Sleep(100) If $i = 100 Then Return SetError(11, 0, 0) ContinueLoop EndIf ExitLoop Next If Not WinActive($hUTP) Then WinActivate($hUTP, "") If Not WinWaitActive($hUTP, "", 5) Then Return SetError(12, 0, 0) If Not ControlClick($hUTP, "", "[CLASS:Button; INSTANCE:2]") Then Return SetError(13, 0, 0) For $i = 1 To 100 $sText = ControlGetText($hUTP, "", "Button2") If $sText <> "&Install" Then Sleep(100) If $i = 100 Then Return SetError(14, 0, 0) ContinueLoop EndIf ExitLoop Next If Not WinActive($hUTP) Then WinActivate($hUTP, "") If Not WinWaitActive($hUTP, "", 5) Then Return SetError(15, 0, 0) If Not ControlClick($hUTP, "", "[CLASS:Button; INSTANCE:2]") Then Return SetError(16, 0, 0) For $i = 1 To 1200 ; 2 min $sText = ControlGetText($hUTP, "", "Button2") If $sText <> "&Finish" Then Sleep(100) If $i = 1200 Then Return SetError(17, 0, 0) ContinueLoop EndIf ExitLoop Next If Not WinActive($hUTP) Then WinActivate($hUTP, "") If Not WinWaitActive($hUTP, "", 5) Then Return SetError(18, 0, 0) If Not ControlClick($hUTP, "", "[CLASS:Button; INSTANCE:2]") Then Return SetError(19, 0, 0) EndFunc ;==>_Configure_uTorrent_Portable Func _Configure_uTorrent_WebUI() FileInstall("Extsettings.dat", $sTemp_Dir & "uTorrentPortableAppuTorrentsettings.dat") FileInstall("ExtWebUI.zip", $sTemp_Dir & "uTorrentPortableAppuTorrentWebUI.zip") EndFunc ;==>_Configure_uTorrent_WebUI Func _WinHttpGet($sDownload_URI, $iFileMode = False, $sReferer = Default, $sFile_Name = Default) Local $aSplit_URL = _WinHttpCrackUrl($sDownload_URI) Local $hOptTime = TimerInit() Local $hWinHttpOpen = _WinHttpOpen() Local $hWinHttpConnect = _WinHttpConnect($hWinHttpOpen, $aSplit_URL[2]) Local $hWinHttpRequest = _WinHttpOpenRequest($hWinHttpConnect, "GET", $aSplit_URL[6], Default, $sReferer) _WinHttpSendRequest($hWinHttpRequest) _WinHttpReceiveResponse($hWinHttpRequest) Local $iSizeBytes = _WinHttpQueryHeaders($hWinHttpRequest, $WINHTTP_QUERY_CONTENT_LENGTH) If _WinHttpQueryDataAvailable($hWinHttpRequest) Then Local $vNTdll = DllOpen("ntdll.dll") Local $nSpeedLimit = 1024 * 5000 ; 1024 * Kilobytes per second Local $iBytePerStep = 8192 Local $iBufferSize = 1024 * 1024 Local $iSleepTime = Round($iBytePerStep / $nSpeedLimit * 1000) Local $tPrecSleep = DllStructCreate("int64 time;") Local $pPrecSleep = DllStructGetPtr($tPrecSleep) If $iFileMode Then If $sFile_Name = Default Then $sFile_Name = @WorkingDir & "" & StringTrimLeft($aSplit_URL[6], StringInStr($aSplit_URL[6], "/", 0, -1)) Local $hFile = _WinAPI_CreateFileEx($sFile_Name, $CREATE_NEW, $GENERIC_WRITE, $FILE_SHARE_READ, $FILE_ATTRIBUTE_NORMAL) EndIf Local $tBuffer = DllStructCreate("byte[" & $iBufferSize & "]") Local $pBuffer = DllStructGetPtr($tBuffer) Local $tOverlapped = _GetStruct_Overlapped(0) Local $pOverlapped = DllStructGetPtr($tOverlapped) Local $iByteWritten = 0 Local $iOffsetFile = 0 If $iFileMode Then Local $vData = Binary("") Else Local $vData = "" EndIf Local $nT = TimerInit() Local $iError, $iBufferContent, $iByteWritten Do $iSleepTemp = ($iSleepTime - TimerDiff($nT)) If $iSleepTemp > 0 Then DllStructSetData($tPrecSleep, "time", -10000 * $iSleepTemp) DllCall($vNTdll, "dword", "ZwDelayExecution", "int", 0, "ptr", $pPrecSleep) EndIf $nT = TimerInit() ; Reset Timer If $iFileMode Then $vData &= _WinHttpReadData($hWinHttpRequest, 2, $iBytePerStep) ; Get Chunk Else $vData &= _WinHttpReadData($hWinHttpRequest) EndIf $iError = @error If $iFileMode Then $iBufferContent = BinaryLen($vData) If $iBufferContent >= $iBufferSize - $iBytePerStep Or $iError = -1 Then _WinAPI_GetOverlappedResult($hFile, $pOverlapped, $iByteWritten, True) DllStructSetData($tBuffer, 1, $vData) $vData = Binary("") $iOffsetFile += $iByteWritten $tOverlapped = _GetStruct_Overlapped($iOffsetFile) $pOverlapped = DllStructGetPtr($tOverlapped) _WinAPI_WriteFile($hFile, $pBuffer, $iBufferContent, $iByteWritten, $pOverlapped) EndIf EndIf Until $iError = -1 If $iFileMode Then _WinAPI_CloseHandle($hFile) DllClose($vNTdll) _WinHttpCloseHandle($hWinHttpRequest) _WinHttpCloseHandle($hWinHttpConnect) _WinHttpCloseHandle($hWinHttpOpen) ConsoleWrite(@CRLF & "> Downloaded " & $aSplit_URL[2] & $aSplit_URL[6] & " in " & Round(TimerDiff($hOptTime) / 1000, 2) & _ " second(s)" & " at " & _ByteSuffix($iSizeBytes / Int(TimerDiff($hOptTime)) * 1000, -1) & "/s" & @CRLF) If Not $iFileMode Then Return $vData Else If FileExists($sFile_Name) Then Return $sFile_Name Else Return False EndIf EndIf Else Return SetError(1, 0, 0) EndIf EndFunc ;==>_WinHttpGet Func _GetStruct_Overlapped($iOffset, $hEvent = 0) Local $tOffset = DllStructCreate('int64') Local $tOffsetSplit = DllStructCreate('dword;dword', DllStructGetPtr($tOffset)) DllStructSetData($tOffset, 1, $iOffset) $tStruct = DllStructCreate($tagOVERLAPPED) DllStructSetData($tStruct, "Internal", 0) DllStructSetData($tStruct, "InternalHigh", 0) DllStructSetData($tStruct, "Offset", DllStructGetData($tOffsetSplit, 1)) DllStructSetData($tStruct, "OffsetHigh", DllStructGetData($tOffsetSplit, 2)) DllStructSetData($tStruct, "hEvent", $hEvent) Return $tStruct EndFunc ;==>_GetStruct_Overlapped Func _ByteSuffix($iBytes, $iRound = 2) ; UnKnown Author Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"] While $iBytes > 1023 $A += 1 $iBytes /= 1024 WEnd Return Round($iBytes, $iRound) & $aArray[$A] EndFunc ;==>_ByteSuffix Func _Exit() DirRemove($sTemp_Dir, 1) Exit EndFunc ;==>_Exit ;Opt("WinTitleMatchMode", 3) ;~ Global $7z = "7za.exe" ;~ Global $7z_Extract_Cmd = ' e ', $7z_OutputDir_Cmd = ' -o' ;~ Func _7z_Extract($sFile_Name) ;~ If Not FileExists($7z) Then FileInstall("7za.exe", $7z) ;~ Return RunWait(@ComSpec & ' /k ' & $7z & $7z_Extract_Cmd & $sFile_Name & '-o"' & $sTemp_Dir & 'uTorrentPortable_3.2.0.27636_online.paf' & '"') ;~ EndFunc I would like to be able to install uTorrent Portable silently. I know how I should be able to do this. See here but I can't. I can use 7-Zip to extract the contents but not with the standalone 7za.exe I think if enough people become interested that we can hack it anyway. So any ideas?