Jump to content

Installer Script


Ejoc
 Share

Recommended Posts

The latest version is 1.2

Change log 1.2

+Made a change so it will install New applications as well as upgrading/patching existing applications.

+It also has a post config section if you want to do additional tasks once its installed.

Change log 1.1

+Pulled the config portion out of installer.au3 to installer_config.au3

This is a basic litte installer I use when I want to replace file(s):

i.e. you download something and it tells you replace your file X with the file provided. Once it's setup you compile the script and it will self extract the new files, and backup the old files before replacing them.

It works but I'd like to make customizing easier, like having a setup.ini you edit or makinging an include.au3 that you use to setup the variables. So the main script isnt changed.

installer_config.au3

;
;   File Copying Installer Config file v1.2
;   You should only need to edit this file
;   Ejoc
;
#include-once

Global  $UseSplash          = 0           ; Use a splash screen
Global  $FullScreenSplash   = 1           ; Make it full screen

Global  $Upgrading          = 0           ; 0 = install a new program
                                          ; 1 = overwritting files of a
                                          ; program already installed
Global  $BackupFiles        = 1           ; backup files, if $Upgrading=1



; Default Install Dir to check
; Manually set it or get it from the registry
Global  $DefaultDir         = "C:\Program Files\test"
;Global $DefaultDir         = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\","InstallFolder")



; inital Warning Dialog, Window Title then Text
Global  $WarningWindow      = StringSplit("Warning Title|Warning Text","|")
Global  $DefaultDirFound    = StringSplit("Directory Found|Install in ","|")
Global  $SelectFolderDiag   = StringSplit("Select Folder|","|")
Global  $SelectFolderConfirm= StringSplit("Confirm|Install to ","|")
Global  $ProgressWindow     = StringSplit("Applying Patch|Patching...","|")
Global  $CompleteWindow     = StringSplit("Complete Title|Installed in" & @CR , "|")



; list of the files we are installing
; if you are using a splashscreen it has to be $FilesToInstall[0]
; if you are not using a splashscreen [0] should be your first file
Global  $TotalInstallFiles  = 2           ; # of files in exe
Dim     $FilesToInstall[$TotalInstallFiles]  ; array of the file names
$FilesToInstall[0]          = @TempDir & "\installer.au3"
$FilesToInstall[1]          = @TempDir & "\installer_config.au3"




; extract the files in the .exe
Func ExtractFiles()
    ProgressOn("Extracting Files","","")
    For $i = 0 To $TotalInstallFiles-1
        ProgressSet(Round(($i*100)/$TotalInstallFiles), "")
        Select  
; add a Case statement for each file
; for each file you HAVE to use the full path to the file, not a variable
            Case $i == 0
                FileInstall("V:\Compilers and Scripting\Autoit\installer.au3", $FilesToInstall[$i], 1)
            Case $i == 1
                FileInstall("V:\Compilers and Scripting\Autoit\installer_config.au3", $FilesToInstall[$i], 1)
        EndSelect
    Next
    ProgressSet(100,"")
    ProgressOff()
EndFunc

; Run any commands after the install completely finishes
Func PostConfig()

EndFunc

installer.au3

;
;   File Copying Installer v1.2
;   Ejoc
;
#include "installer_config.au3"

Dim     $open_windows[2]                  ; used w/ splash screen
Dim     $min_windows[2]                   ; used w/ splash screen
$v_splash                   = $FilesToInstall[0]; Splashscreen file

ExtractFiles()                            ; Extract from the .exe

If $FullScreenSplash AND $UseSplash Then
; get a list of the open windows
    $open_windows = WinList()
    $min_windows = $open_windows

; put up the splash screen whooo so offical looking :P
    SplashImageOn("Splash", $v_splash, @DesktopWidth, @DesktopHeight,0,0,1)

;minimise Other Windows
    For $i = 1 to $open_windows[0][0]
        If $open_windows[$i][0] <> "" AND IsVisible($open_windows[$i][1]) Then
            $min_windows[$i][1] = 1
            WinSetState($open_windows[$i][0],"",@SW_MINIMIZE)
        Else
            $min_windows[$i][1] = 0
        EndIf
    Next

    WinSetOnTop("Splash","",0)

ElseIf $UseSplash Then; Use small Splash Screen
    SplashImageOn("Splash", $v_splash, @DesktopWidth/3, @DesktopHeight/3, @DesktopWidth/3,@DesktopHeight/3,3)

Endif

;warn about applying
if MsgBox(4,$WarningWindow[1],$WarningWindow[2]) == 7 Then CleanUp(0)

;check if the default directory exists
$vtmbdir    = $DefaultDir
$dirchosen  = 0

if FileExists($vtmbdir) Or ($Upgrading == 0) Then
    if MsgBox(4,$DefaultDirFound[1],$DefaultDirFound[2] & $vtmbdir) <> 7 Then $dirchosen = 1
EndIf

if $dirchosen == 0 Then
    If $Upgrading Then
        $vtmbdir = FileSelectFolder($SelectFolderDiag[1], $SelectFolderDiag[2], 2)
    Else
        $vtmbdir = FileSelectFolder($SelectFolderDiag[1], $SelectFolderDiag[2], 7, $vtmbdir)
    Endif
    if $vtmbdir == "" Then CleanUp(0)
    if MsgBox(4,$SelectFolderConfirm[1],$SelectFolderConfirm[2] & $vtmbdir) == 7 Then CleanUp(-1)
    If @error Then
        MsgBox(0,"","No Directory chosen")
        CleanUp(-1)
    Endif
Endif

If $Upgrading == 0 Then
    If DirCreate($vtmbdir) == 0 Then
        MsgBox(0,"","Failed to create directory")
        CleanUp(-1)
    Endif
Endif

ProgressOn($ProgressWindow[1],$ProgressWindow[2],"")

; Dont copy the splashscreen
$i = 0
if $UseSplash Then $i = 1

For $i = $i To $TotalInstallFiles-1
    ProgressSet(Round(($i*100)/$TotalInstallFiles),"")

    $DestFile = $vtmbdir & StringTrimLeft( $FilesToInstall[$i],StringLen(@TEMPDIR))
;Backup orginal files
    If $BackupFiles And $Upgrading Then
        if FileCopy($DestFile, $DestFile & ".BAK", 1) == 0 Then
            ProgressOff()
      ; Restore files that we already updated
            $n = 0
            If $UseSplash Then $n = 1
            For $n = $n To $i
                $RestoreFile = $vtmbdir & StringTrimLeft( $FilesToInstall[$n],StringLen(@TEMPDIR))
                FileCopy($RestoreFile & ".BAK", $RestoreFile, 1)
            Next

            MsgBox(0,"","Failed to backup " & $DestFile & @CR & "Exiting")
            CleanUp(-1)
        Endif; Copy Failed
    Endif; create backup files

    if FileCopy($FilesToInstall[$i],$DestFile,1) == 0 Then
        ProgressOff()
  ; Restore files that we already updated
        $n = 0
        If $UseSplash Then $n = 1
        For $n = $n To $i
            $RestoreFile = $vtmbdir & StringTrimLeft( $FilesToInstall[$n],StringLen(@TEMPDIR))
            FileCopy($RestoreFile & ".BAK", $RestoreFile, 1)
        Next

        MsgBox(0,"","Failed to copy " & $DestFile & @CR & "Exiting")
        CleanUp(-1)

    Endif; Copy Failed
Next

ProgressSet(100,"")
ProgressOff()

MsgBox(0,$CompleteWindow[1],$CompleteWindow[2] & $vtmbdir)

PostConfig()

CleanUp(0)

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Func CleanUp($ret)
    If $UseSplash Then
        WinSetOnTop("Splash","",1)
;restore windows
        If $FullScreenSplash Then
            For $i = 0 To ($min_windows[0][0] - 1)
                If $min_windows[$min_windows[0][0]-$i][1] Then WinSetState($min_windows[$min_windows[0][0]-$i][0],"",@SW_RESTORE)
            Next
        Endif
    Endif

;delete the temp files
    For $i = 0 To $TotalInstallFiles-1
        FileDelete($FilesToInstall[$i])
    Next

    Exit $ret
EndFunc

installer1_2.zip

Edited by Ejoc
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

  • 5 years later...

You 2 do realize this post is 5 years old, and that AutoIt has changed a lot since then, and the script would need to be brought up-to-date no doubt ... to work (run) properly as a script now ... that's not to say that I've looked at it in any way.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

;nice code

;Change installer_config.au3

;line

;Global $DefaultDir = "C:\Program Files\AutoIt3"

; Case $i == 0

; ===> FileInstall("V:\Compilers and Scripting\Autoit\installer.au3", $FilesToInstall[$i], 1);

;here FileInstall("C:\Documents and Settings\Admin\Desktop\installer1_2", $FilesToInstall[$i], 1)

; Case $i == 1

; ===> FileInstall("V:\Compilers and Scripting\Autoit\installer_config.au3", $FilesToInstall[$i], 1);

;here FileInstall("C:\Documents and Settings\Admin\Desktop\installer1_2", $FilesToInstall[$i], 1)

;ok worked....

Edited by mesale0077
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...