monter Posted February 29, 2008 Posted February 29, 2008 (edited) This is the initial version of my script. It only works on PC with Sims2 installed. I wrote it especially for my wife After launching you'll see "choose folder" to choose *.sims2pack files.Then there is a tooltip saying not to touch the computer till it installs all of the files.After this there is a question if you want to launch the Sims2 game. Currently path and executable is written in .ini: launch=drv:\path\file.exe. After 30 secs of timeout the Sims2 program launches automatically.For now it has polish version only, but the next version is coming soon.Of course, I plan to develop this script.expandcollapse popup;#NoTrayIcon $DataPr = "24.02.2008" #include <Date.au3> #include <File.au3> #include <String.au3> #include <Array.au3> #include <GUIConstants.au3> #Include <WinAPI.au3> $nSkrypt = "Sims2Pack Batch Installer" ;pelna nazwa skryptu $pSkrypt = StringSplit(@ScriptName, ".") $pSkrypt = $pSkrypt[1] ;nazwa pliku skryptu (uzytkownik mógl; ja zmienic) $skrypt = $pSkrypt If $skrypt <> "Sims2PackBat" Then $skrypt = "Sims2PackBat" ;wlasciwa nazwa skryptu $ini = @ScriptDir & "\" & $skrypt & ".ini" $plikAutoUpd = @TempDir & "\" & $skrypt & ".upd" If @Compiled Then $sVer = StringFormat("%.2f", Number(StringReplace(FileGetVersion(@ScriptFullPath), ".", "")) / 1000) Else Opt("TrayIconDebug", 1) $sVer = "0.10" $dp = FileGetTime(@ScriptFullPath, 0, 0) _FileWriteToLine(@ScriptName, 2, "$DataPr = " & Chr(34) & $dp[2] & "." & $dp[1] & "." & $dp[0] & Chr(34), 1) FileSetTime(@ScriptFullPath, $dp[0] & $dp[1] & $dp[2] & $dp[3] & $dp[4] & $dp[5], 0) EndIf $DataProd = $DataPr TraySetState() TraySetToolTip($nSkrypt & ' ' & $sVer) Dim $kat[10] $ext = "*.sims2pack" Sleep(250) If FileExists($plikAutoUpd) Then FileDelete($plikAutoUpd) If Not FileExists($ini) Then TworzIni() AktualIni() CzytajIni() $counter = $counter + 1 SprawdzAktual() WybKatalog() If StringLen($wybKat) > 0 Then SortujKatIni() ElseIf StringLen($wybKat) = 0 Then Exit EndIf $lisTxt = @TempDir & "\" & $skrypt & ".txt" If StringLen($wybKat) < 4 Then $wybKat = StringTrimRight($wybKat, 1) $szukSciez = '"' & $wybKat & "\" & $ext & '"' kom("Poczekaj chwilę, skanuję katalog " & $wybKat & " w poszukiwaniu plików " & $ext & " ...") If FileExists($lisTxt) Then FileDelete($lisTxt) Sleep(250) FileOpen($lisTxt, 0) RunWait(@ComSpec & ' /c dir ' & $szukSciez & ' /B /S >> "' & $lisTxt & '"', "", @SW_HIDE) FileClose($lisTxt) Sleep(250) $txtCon = FileRead($lisTxt) ToolTip("") If StringLen($txtCon) = 0 Then MsgBox(64, $skrypt & " " & $sVer, "Nie znalazłem plików " & $ext & " w wybranym katalogu.", 4) Exit EndIf $regext = RegRead("HKCR\" & StringTrimLeft($ext, 1), "") $unpacker = RegRead("HKCR\" & $regext & "\shell\open\command", "") $unpacker = StringTrimRight($unpacker, 5) $unpacker = StringReplace($unpacker, Chr(34), "") $linii = _FileCountLines($lisTxt) For $c = 1 To $linii $pliKonc = "plików" If StringRight($linii + 1 - $c, 1) > 1 And StringRight($linii + 1 - $c, 1) < 5 Then $pliKonc = "pliki" If $linii + 1 - $c > 10 And $linii + 1 - $c < 15 Then $pliKonc = "plików" If $linii + 1 - $c = 1 Then $pliKonc = "plik" kom("Nie dotykaj komputera. Automatyczna instalacja pliku " & @CRLF & FileReadLine($lisTxt, $c) & @CRLF & "Jeszcze " & $linii + 1 - $c & " " & $pliKonc & " do zainstalowania.") ; w przyszlosci oszacujemy pozostaly czas Run(Chr(34) & $unpacker & Chr(34) & " " & Chr(34) & FileReadLine($lisTxt, $c) & Chr(34)) WinActivate("Instalator") Sleep(3600) WinWaitActive("Instalator") MouseClick("", (@DesktopWidth / 2) - 48, (@DesktopHeight / 2) + 135) Sleep(20) MouseClick("", (@DesktopWidth / 2) + 8, (@DesktopHeight / 2) + 135) Next IniWrite($ini, $skrypt, "counter", $counter) kom("Instalacja modów zakończona.", 2000) ToolTip("") $lnch = MsgBox(36, $skrypt & " " & $sVer, "Czy mam uruchomic gre?" & @CRLF & "(za 30 sekund automatycznie uruchomie)", 30) If $lnch = 6 Or $lnch = -1 Then Launch() Exit Func TworzIni() IniWrite($ini, $skrypt, "ver", $sVer) IniWrite($ini, $skrypt, "update", "2-" & _NowCalcDate()) IniWrite($ini, $skrypt, "counter", 0) IniWrite($ini, $skrypt, "launch", "F:\Programy\The Sims\Podróże\TSBin\Sims2Launcher.exe") For $x = 0 To 9 IniWrite($ini, "Katalogi", "kat" & $x, "") Next EndFunc ;==>TworzIni Func AktualIni() $verIni = IniRead($ini, $skrypt, "ver", $sVer) If $verIni < $sVer Then If FileExists(@TempDir & "\" & $skrypt & ".bat") Then FileDelete(@TempDir & "\" & $skrypt & ".bat") IniWrite($ini, $skrypt, "ver", $sVer) IniWrite($ini, $skrypt, "update", "2-" & _NowCalcDate()) $counter = IniRead($ini, $skrypt, "counter", 0) IniWrite($ini, $skrypt, "counter", $counter) IniWrite($ini, $skrypt, "launch", $launch) EndIf EndFunc ;==>AktualIni Func CzytajIni() $update = IniRead($ini, $skrypt, "update", "2-" & _NowCalcDate()) Global $stAktual = StringLeft($update, 1) Global $sprAktual = StringTrimLeft($update, 2) Global $counter = IniRead($ini, $skrypt, "counter", 0) Global $launch = IniRead($ini, $skrypt, "launch", "F:\Programy\The Sims\Podróże\TSBin\Sims2Launcher.exe") For $x = 0 To 9 $kat[$x] = IniRead($ini, "Katalogi", "kat" & $x, "") Next EndFunc ;==>CzytajIni Func SprawdzAktual() $datRoznica = _DateDiff('D', $sprAktual, _NowCalcDate()) If $datRoznica > $stAktual Then $pcol = "http://" For $i = 1 To 3 kom('Sprawdzam aktualizację, poczekaj chwilę... (' & $i & '/3)') InetGet($pcol & "monter.homeip.net/skrypty/bin/AutoIt3Script.upd", $plikAutoUpd, 1, 1) If @error = 1 Then ExitLoop If $i = 1 Then HttpSetProxy(2, "monter.homeip.net:8068") If $i = 2 Then $pcol = "ftp://" HttpSetProxy(1) EndIf Next ToolTip("") If Not FileExists($plikAutoUpd) Then Sleep(2500) If Not FileExists($plikAutoUpd) Or FileGetSize($plikAutoUpd) < 30 Then kom('Błąd sieciowy. Aktualizacja nie powiodła się.', 3000, -1, -1, -1, 3) ToolTip('') $stAktual = 2 Else $nVer = IniRead($plikAutoUpd, $skrypt & ".exe", "wersja", "0.0.0.0") $nVer = StringFormat("%.2f", Number(StringReplace($nVer, ".", "")) / 1000) $nRozm = IniRead($plikAutoUpd, $skrypt & ".exe", "rozmiar", "999999999") If $nVer > $sVer Then $pcol = "http://" $nPlik = IniRead($plikAutoUpd, $skrypt & ".exe", "plik", "monter.homeip.net/skrypty/bin/" & $skrypt & ".exe") For $i = 1 To 3 kom('Ściągam najnowszą wersję programu, poczekaj chwilę... (' & $i & '/3)') InetGet($pcol & $nPlik, @TempDir & "\" & $skrypt & ".exe", 1, 0) If FileGetSize(@TempDir & "\" & $skrypt & ".exe") = $nRozm Then ExitLoop If $i = 1 Then HttpSetProxy(2, "monter.homeip.net:8068") If $i = 2 Then $pcol = "ftp://" HttpSetProxy(1) EndIf Next If FileGetSize(@TempDir & "\" & $skrypt & ".exe") < IniRead($plikAutoUpd, $skrypt & ".exe", "rozmiar", 0) Then kom('Ściąganie pliku nowej wersji nie powiodło się. Sprawdź ustawienia internetowe.', 3000, -1, -1, -1, 3) ToolTip('') $stAktual = 2 Else If FileExists(@TempDir & "\" & $skrypt & ".bat") Then FileDelete(@TempDir & "\" & $skrypt & ".bat") Sleep(750) $baTemp = FileOpen(@TempDir & "\" & $skrypt & ".bat", 1) FileWriteLine($baTemp, '@echo off' & @CRLF & 'if exist "' & @TempDir & '\' & $skrypt & '.exe" del "' & @ScriptDir & '\' & $skrypt & '.exe" >nul' & @CRLF & 'move "' & @TempDir & '\' & $skrypt & '.exe" "' & @ScriptDir & '\" >nul') FileWriteLine($baTemp, 'ping -n 1 monter.homeip.net >nul' & @CRLF & 'if exist "' & @ScriptDir & '\' & $skrypt & '.exe" "' & @ScriptDir & '\' & $skrypt & '.exe"' & @CRLF & 'exit' & @CRLF & 'cls') FileClose($baTemp) EndIf kom('Aktualizacja przebiegła pomyślnie. Uruchamiam nową wersję ' & $skrypt & ' ' & $nVer & '...', 3000, -1, -1, -1) ToolTip('') If FileExists($plikAutoUpd) Then FileDelete($plikAutoUpd) Run(@TempDir & "\" & $skrypt & ".bat") Exit Else $stAktual = 7 EndIf EndIf IniWrite($ini, $skrypt, "update", $stAktual & "-" & _NowCalcDate()) EndIf If FileExists($plikAutoUpd) Then FileDelete($plikAutoUpd) EndFunc ;==>SprawdzAktual Func WybKatalog() For $x = 0 To 9 Global $wybKat = FileSelectFolder("Wybierz katalog z modami do instalacji...", "", "", $kat[$x]) If StringLen($wybKat) > 0 Then ExitLoop If $x = 1 Then CzyKoniec() Next EndFunc ;==>WybKatalog Func SortujKatIni() For $x = 0 To 9 If $wybKat = $kat[$x] Then $pozKat = $x ExitLoop EndIf Next If IsDeclared("pozKat") Then For $y = $pozKat - 1 To 0 Step - 1 IniWrite($ini, "Katalogi", "kat" & $y + 1, $kat[$y]) Next IniWrite($ini, "Katalogi", "kat0", $wybKat) ElseIf Not IsDeclared("pozKat") Then ZapiszKatIni() EndIf EndFunc ;==>SortujKatIni Func ZapiszKatIni() For $x = 9 To 1 Step - 1 IniWrite($ini, "Katalogi", "kat" & $x, $kat[$x - 1]) Next IniWrite($ini, "Katalogi", "kat0", $wybKat) EndFunc ;==>ZapiszKatIni Func CzyKoniec() $czyKon = MsgBox(289, $nSkrypt & " " & $sVer, "Czy mam zakończyć działanie programu?", 8) If $czyKon = 1 Then Exit EndFunc ;==>CzyKoniec Func Launch() Run($launch) Sleep(8000) Send("{SPACE}") EndFunc ;==>Launch Func kom($txt = "Brak tekstu!", $s = 1500, $i_skrypt = -1, $ttX = -1, $ttY = -2, $icn = 1) If $s < 750 Then $s = 750 If $i_skrypt = -1 Then $skn = StringSplit(@ScriptName, ".") $i_skrypt = $skn[1] If IsDeclared("nSkrypt") Then $i_skrypt = $nSkrypt & " " & $sVer EndIf If $ttX = -1 Then $ttX = Int(@DesktopWidth / 2) If $ttY = -1 Then $ttY = Int(@DesktopHeight / 2) If $ttY = -2 Then $ttY = @DesktopHeight - 64 ToolTip($txt, $ttX, $ttY, $i_skrypt, $icn, 2) Sleep($s) EndFunc ;==>kom Edited February 29, 2008 by monter monter.FM [font="Tahoma;"]Full programs:[/font][font="'Microsoft Sans Serif';"] LogOnOff - keeps alive user session, after set time it performs logoff (instead of locking [acronym="Personal Computer"]PC[/acronym], useful in some corporations working with [acronym="Active Directory"]AD[/acronym]).[/font] ČharCönvěr - character set converter. [font="'Microsoft Sans Serif';"]CDTray - automated opening/closing the [acronym="Compact Disc"]CD[/acronym] tray.[/font] [font="'Microsoft Sans Serif';"]Example scripts: [/font][font="'Microsoft Sans Serif';"]RecentFolders - managing recently used folder list with combobox.[/font] [font="'Microsoft Sans Serif';"]AutoUpdater - periodic auto-checking, auto-updating and auto-relaunching newest script version.[/font] Changed host from monter.homeip.net to monter.homenet.org - replace address in my scripts to get back them to work.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now