Jump to content
Sign in to follow this  
Starfighter

Automation Installation

Recommended Posts

Hi People,

I'm a Newbie. I made the following code for a automatic Installation (massive!):

#include <GUIConstants.au3>

GUICreate("Unattended Installation",400,100,0,0)

GUISetState ()

Dim $CountProgram

Dim $LabelLeft

Dim $LabelTop

Dim $ProgramNumber

Dim $Position

Dim $Programm

Dim $Progressbar

$CountPrograms=3

$LabelLeft=190

$LabelTop=75

$Programm=GUICtrlCreateLabel ("Fortschritt...", 10, 15)

$Progressbar=GUICtrlCreateProgress(10,35,380,20,$PBS_SMOOTH)

;***************************************************************************************************

************************

;

; CUEcards 2.12a

;

;***************************************************************************************************

************************

$ProgramNumber=1

$Position=Int(($ProgramNumber*100)/$CountPrograms)

RunWait(@WorkingDir & "\CUEcards\Setup.exe /SILENT")

GUICtrlCreateLabel ($Position & " %", $LabelLeft, $LabelTop)

GUICtrlSetData ($Progressbar, $Position)

;***************************************************************************************************

************************

;

; DScaler 4.1.8

;

;***************************************************************************************************

************************

$ProgramNumber=2

$Position=Int(($ProgramNumber*100)/$CountPrograms)

RunWait(@WorkingDir & "\DScaler\Setup.exe /SILENT")

GUICtrlCreateLabel ($Position & " %", $LabelLeft, $LabelTop)

GUICtrlSetData ($Progressbar, $Position)

;***************************************************************************************************

************************

;

; Foxit PDF Reader 1.2 Build 201

;

;***************************************************************************************************

************************

$ProgramNumber=3

$Position=Int(($ProgramNumber*100)/$CountPrograms)

RunWait(@WorkingDir & "\Foxit PDF Reader\Setup.exe /SILENT")

GUICtrlCreateLabel ($Position & " %", $LabelLeft, $LabelTop)

GUICtrlSetData ($Progressbar, $Position)

Sleep(2000)

How can I make better code? Any Ideas?

Sorry, my English is not so good.

Thanks

Share this post


Link to post
Share on other sites

Hi People,

Puh...done!

I made a better code for me. Perhaps for you too?

Ok, here is the code:

#include <file.au3>
#include <GUIConstants.au3>

; Variablen deklarieren.
Dim $CommandlineOption
Dim $DelimiterCount
Dim $ErrorLogFile
Dim $ExtractedString
Dim $File
Dim $FindString
Dim $InstallListFile
Dim $LineOInstallListFile
Dim $LineOTempListFile
Dim $LineNumber
Dim $NotExistFile
Dim $PositionOfDelimiter
Dim $ProgramCount
Dim $ProgramName
Dim $ProgramNumber
Dim $ProgramVersion
Dim $Position
Dim $Progressbar
Dim $RemovedSpacesString
Dim $RightString
Dim $SetupDirectory
Dim $SetupFile
Dim $SourceString
Dim $TempListFile
Dim $Text

; Dateien festlegen.
$InstallListFile="Software.csv"
$TempListFile="TempListFile.txt"
$ErrorLogFile="Error.log"

; Prüfen, ob die Installationsliste geöffnet werden kann.
$File=FileOpen($InstallListFile , 0)
If $InstallListFile=-1 Then
    MsgBox(48, "Unattended Installation", "Die Datei " & $InstallListFile & " kann nicht geöffnet werden!")
    Exit
Else
; Installationsliste schliessen.
    FileClose($File)
EndIf

; Alle Leerzeilen entfernen.
$File=FileOpen($InstallListFile , 0)
While 1
; Zeile auslesen.
    $LineOInstallListFile=FileReadLine($File)
    If @error=-1 Then ExitLoop
    If StringLen($LineOInstallListFile)>0 Then
        $Text=$Text & $LineOInstallListFile & @CRLF
    EndIf
Wend
FileClose($File)

; Bereinigter Text speichern.
$File=FileOpen($TempListFile, 1)
FileWrite($File, $Text)
FileClose($File)

; Temporäre Installationsliste öffnen.
$File=FileOpen($TempListFile, 0)

; Anzahl der zu installierende Programme bestimmen.
$ProgramCount=_FileCountLines($TempListFile)
$ProgramCount=$ProgramCount-1
If $ProgramCount=0 Then
    MsgBox(48, "Unattended Installation", "Die Installationsliste " & $InstallListFile & " ist leer")
; Installationsliste schliessen.
    FileClose($File)
; Nichts zu installieren, also raus.
    Exit
EndIf

; GUI vorbereiten.
GUICreate("Unattended Installation",400,100,0,0)
$Progressbar=GUICtrlCreateProgress(10,35,380,20,$PBS_SMOOTH)

; Bis zum Dateiende lesen.
$DelimiterCount=5
$FindString=";"
While 1
; Zeile auslesen.
    $LineOTempListFile=FileReadLine($File)
    If @error=-1 Then ExitLoop

; Entferne Anführungszeichen.
    $LineOTempListFile=StringReplace($LineOTempListFile, '"', '')

; Entferne alle überflüssige Leerzeichen.
    $RemovedSpacesString=StringStripWS ($LineOTempListFile, 7)
    If StringLen($RemovedSpacesString)>0 Then
   ; Extrahiere alle Infos aus der Zeile.
        $RightString=$LineOTempListFile 
        For $i=1 to $DelimiterCount
            $SourceString=$RightString
            $PositionOfDelimiter=StringInStr($SourceString, $FindString)
            $ExtractedString=StringMid($SourceString, 1 , $PositionOfDelimiter-1)
            $RightString=StringMid($SourceString, $PositionOfDelimiter+1 , StringLen($SourceString))
            If $i=1 Then
                $ProgramName=$ExtractedString
            ElseIf $i=2 Then
                $ProgramVersion=$ExtractedString
            ElseIf $i=3 Then
                $SetupDirectory=$ExtractedString
            ElseIf $i=4 Then
                $SetupFile=$ExtractedString
            ElseIf $i=5 Then
                $CommandlineOption=$ExtractedString
            EndIf
        Next

   ; Iterieren.
        $LineNumber=$LineNumber+1
        If $LineNumber>1 Then
            $ProgramNumber=$LineNumber-1
       ; Nur dann Installieren, wenn die Setupdatei existiert.
            If FileExists(@WorkingDir & "\" & $SetupDirectory & "\" & $SetupFile) Then
                GUISetState ()
                $Position=Int(($ProgramNumber*100)/$ProgramCount)
                GUICtrlCreateLabel ($ProgramName & " " & $ProgramVersion, 10, 15, 380, 20)
                RunWait (@WorkingDir & "\" & $SetupDirectory & "\" & $SetupFile & " " & $CommandlineOption)
                GUICtrlCreateLabel ($Position & " %", 190, 75, 380, 20)
                GUICtrlSetData ($Progressbar, $Position)
            Else
                $NotExistFile=$NotExistFile & @WorkingDir & "\" & $SetupDirectory & "\" & $SetupFile & @CRLF
            EndIf
        EndIf
    EndIf
Wend

; warten.
Sleep(1000)
; GUI zerstören.
GUIDelete()
; Warten.
Sleep(1000)
; Temporäre Installationsliste schliessen.
FileClose($File)
; Temporäre Installationsliste löschen.
FileDelete($TempListFile)

; Fehlerbericht erstellen, falls einige der Installationsdateien fehlen.
If StringLen($NotExistFile)>0 Then
    If FileExists($ErrorLogFile) Then
   ; Alter Fehlerbericht löschen.
        FileDelete($ErrorLogFile)
    EndIf
    $File=FileOpen($ErrorLogFile, 1)
    FileWrite($File, $NotExistFile)
    FileClose($File)
; Informieren.
    MsgBox(48, "Unattended Installation", "Einige der Installationsdateien existieren nicht!" & @CRLF & _
    "Konsultieren Sie dazu den Fehlerbericht Error.log")
EndIf

The CSV-File:

"ProgramName";"ProgramVersion";"SetupDirectory";"SetupFile";"CommandlineOption"

"ClearProg";"1.4.2 Beta 3";"ClearProg";"Setup.exe";"/SILENT"

"CodeStuff Starter";"5.6.1.38";"CodeStuff Starter";"Setup.exe";"/SILENT"

"CUEcards";"2.12a";"Cuecards";"Setup.exe";"/SILENT"

Have a fun with this code :)

Edited by Starfighter

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...