Jump to content

Installer to distribute AutoIt A3X Scripts


GokAy
 Share

Recommended Posts

Hello everyone,

I recently posted https://www.autoitscript.com/forum/topic/204281-create-self-extracting-7zip-exe-with-batch-file-and-configuration-file/ in the Developer section. Didn't receive much of a feedback though :) . This post will be about the installer script of, let's say, a suite of scripts that I wrote to support my project that is being written in VBA for Excel.

Even though I am posting to the Example forum, I am just an AutoIt noobie (joined on 8th of October, and started using AutoIt not sooner than a few days before that). I may have inefficient code, and mistakes and whatnot. All my scripts are working alright, however they lack one thing, proper error handling. Also, since I didn't have any intention to share it when I started writing them, it may take a little bit of work to adjust to your needs. However, it should be an easy thing for most.

The whole suite at the moment consists of 7 scripts total, which 4 or 5 may be useful to someone that distributes AutoIt scripts. All scripts are 32-bit. The project is named "LazyD Charter". In short, what they do:

1. CH_Installer: Copies a folder structure, rename a3x extensions within and adds registry keys to enable double-click running of a3x files. I believe this may be a good starting point who wish to distribute scripts and avoid false-positives. Just uploaded latest installer.exe to VT (VT Detection), 3/69 and all of the major players gave a passing mark.

2. CH_Configuration: Change install folder, change/delete registry keys

3. CH_Uninstaller: Uninstall/undo all changes made

4. CH_Updater: Use a Drive restricted Google API key to access a publicly shared Goggle Drive folder, and update any content you got, including AutoIt#.exe, a3x scripts.

5. CH_DownloadExtras: Download any content that I deem not needed to be included in the installer itself. Uses API key as well, just some other shared folder.

6. CH_SetFolderManager: Shouldn't mean much to anyone really, merely creates some folders with a special naming convention, and adds some numbers to end of file names accordingly.

7. CH_VideoPlayer: Might have some potential as a basis for a media player, I just use this to play a video file with the commands sent from xlsm file via Windows message SetText.

 

So, after this introduction, let me present CH_Installer:

image.png.80aa3057830c8f38e79482b99242b8ed.png

Pretty simple GUI. For my project, user has an option to not install AutoIt or any of the scripts. For most this would beat the purpose of using it. :) (Here "install AutoIt" word may be misleading as nothing is installed. Just copied somewhere known and registry association added for the changed extension type, so you can double click start any script and they also get their own icon). I choose to change the extensions intentionally as to not interfere if the user later decides to install AutoIt, and to be able to use custom icon for the file type.

What the installer does:

1. Copy the folder structure necessary for the project to the user selected folder

2. Create a folder in AppData/Roaming and create an ini file holding the options selected

3. Copy AutoIt.exe and scripts (extension changed) to pre-determined subfolder inside Project folder (InstallPath\Apps) if checked

3. Add registry keys for the extension if checked

The code:

Please don't look at it like an example alone, and point me to any mistakes and possible sources for trouble.

#NoTrayIcon
#RequireAdmin

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_type=a3x
#AutoIt3Wrapper_Outfile=CH_Install\Scripts\CH_Installer.a3x
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_Res_Description=Script file for installing LazyD Charter
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_ProductName=LazyD Charter
#AutoIt3Wrapper_Res_ProductVersion=1.0.0.0
#AutoIt3Wrapper_Res_CompanyName=LazyD is not a company
#AutoIt3Wrapper_Res_LegalCopyright=None
#AutoIt3Wrapper_Res_LegalTradeMarks=None
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <File.au3>
#include <FileConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
#include <Constants.au3>

#include <LazyD Charter Color Theme.au3>

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("GUIOnEventMode", 1)

Global $g_sDEFAULT_EXT = "a3xs"
Global $g_sAutoItVer ="AutoIt3.exe"

Global $g_h_MainApp
Global $g_id_inputInstallDirectory
Global $g_id_checkRegistry
Global $g_id_checkAutoIt
Global $g_id_inputExtension
Global $g_id_checkAppData
Global $g_id_lblInputExtension

; Get Script Files Names without the extension
Global $g_aScriptFiles = Get_ScriptFileNames_WithoutExtension()

Create_App_Window()

Func Create_App_Window()

    ; Ini File Path
    Local $sIniFilePath = @AppDataDir & "\LazyD Charter\LazyD Charter.ini"

    ; Read ini file for InstallDirectory folder path
    Local $sInstallPathforIcon = IniRead($sIniFilePath, "Install", "Install_Path","")

    Local $sIconPath = ($sInstallPathforIcon="") ? (@ScriptDir & "\..\Charter\Apps") : ($sInstallPathforIcon & "\Apps")

    ; Create App Window
    $g_h_MainApp = GUICreate("LazyD Charter Installer", 611, 549, -1, -1)
    GUISetIcon($sIconPath & "\ChResource\LazyD_Ch.ico")
    GUISetBkColor($COL_APP_WINDOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Quit_App")

    ; Create Dummy Button to intercept Return key press
    GUICtrlCreateButton("",0,0,0,0,-1,-1)
    GUICtrlSetBkColor(-1, $COL_APP_WINDOW)
    GUICtrlSetFont(-1, 14, 400, 0, "")

    ; Default Variable Values
    Local $sInstallPath ;= "C:\LazyD Charter" ;Default install location
    Local $iAppDataChecked = $GUI_CHECKED
    Local $iAutoItChecked = $GUI_CHECKED
    Local $iRegistryChecked = $GUI_CHECKED
    Local $iInputExtensionState = $GUI_ENABLE

    ; Read Ini File in case an installation already exists
    $sInstallPath = IniRead(@AppDataDir & "\LazyD Charter\LazyD Charter.ini","Install","Install_Path","C:\LazyD Charter")
    Local $sAppDataChecked = IniRead(@AppDataDir & "\LazyD Charter\LazyD Charter.ini","Install","AppData_Checked","True") ; Unused ATM
    Local $sAutoItChecked = IniRead(@AppDataDir & "\LazyD Charter\LazyD Charter.ini","Install","AutoIt_Checked","True")
    Local $sRegistryChecked = IniRead(@AppDataDir & "\LazyD Charter\LazyD Charter.ini","Install","Registry_Checked","True")
    $g_sDEFAULT_EXT = IniRead(@AppDataDir & "\LazyD Charter\LazyD Charter.ini","Install","Extension",$g_sDEFAULT_EXT)

    ; Change CheckBox Checked State if according to ini file data
    if $sAppDataChecked = "False" then $iAppDataChecked = $GUI_UNCHECKED
    ; Registry CheckBox first so AutoIt CheckBox values overwrite
    if $sRegistryChecked = "False" then
        $iRegistryChecked = $GUI_UNCHECKED
        $iInputExtensionState = $GUI_DISABLE
    EndIf
    if $sAutoItChecked = "False" then
        $iAutoItChecked = $GUI_UNCHECKED
        $iRegistryChecked = $GUI_UNCHECKED + $GUI_DISABLE
        $iInputExtensionState = $GUI_DISABLE
    EndIf

    ; Create Install Directory Input Box
    $g_id_inputInstallDirectory = GUICtrlCreateInput($sInstallPath, 16, 48, 465, 32)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_GROUP)

    ; Create Install Directory Label
    GUICtrlCreateLabel("Install Directory", 16, 16, 146, 28)
    GUICtrlSetFont(-1, 14, 800, 0, "")
    GUICtrlSetColor(-1, 0x000000)

    ; Create Install Directory SELECT Button
    GUICtrlCreateButton("SELECT", 496, 48, 100, 33)
    GUICtrlSetFont(-1, 14, 800, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_BTN_DEFAULT)
    GUICtrlSetTip(-1, "Click to select another install folder location.")
    GUICtrlSetOnEvent(-1,"Select_Install_Directory")

    ; Create QUIT Button
    GUICtrlCreateButton("QUIT", 493, 112, 100, 33)
    GUICtrlSetFont(-1, 14, 800, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_BTN_QUIT)
    GUICtrlSetTip(-1, "Click to quit the installation process. All temporary files will be automatically deleted.")
    GUICtrlSetOnEvent(-1,"Quit_App")

    ; Create INSTALL Button
    GUICtrlCreateButton("INSTALL", 16, 112, 100, 33)
    GUICtrlSetFont(-1, 14, 800, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_BTN_DEFAULT)
    GUICtrlSetTip(-1, "Install ""LazyD Charter"" to the installation folder with the options selected below.")
    GUICtrlSetOnEvent(-1,"Install_App")

    ; ----------------------------
    ; Create Install Options Group
    GUICtrlCreateGroup("Options", 24, 176, 569, 313)
    GUICtrlSetFont(-1, 14, 800, 0, "")
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    ; Create Install Options Message Label
    GUICtrlCreateLabel("Optional installation features which will make your life easier, none are essential for using LazyD Charter.", 40, 216, 504, 60)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetBkColor(-1, $COL_GROUP)

    ; Create AppData Option CheckBox (and Label seperately as text color wouldn't change)
    $g_id_checkAppData = GUICtrlCreateCheckbox("", 42, 288, 41, 41)
    GUICtrlSetState(-1, $iAppDataChecked)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetTip(-1, "This option is disabled at the moment.")
    GUICtrlSetBkColor(-1, $COL_GROUP)

    GUICtrlCreateLabel("Create ""AppData\Roaming\LazyD Charter"" folder", 60, 295, 420, 41)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetTip(-1, "This option is disabled at the moment.")
    GUICtrlSetColor(-1, $COL_GROUP_HEADER)
    GUICtrlSetBkColor(-1, $COL_GROUP)

    ; Create AutoIt installation option CheckBox
    $g_id_checkAutoIt = GUICtrlCreateCheckbox("Use AutoIt Scripts", 42, 344, 465, 41)
    GUICtrlSetState(-1, $iAutoItChecked)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetTip(-1, "Keep it checked to copy """ & $g_sAutoItVer & """ and ""LazyD Charter Scripts"" to install directory.")
    GUICtrlSetBkColor(-1, $COL_GROUP)
    GUICtrlSetOnEvent(-1, "AutoIT_Check")

    ; Create Registry Keys installation option Checkbox (tied to AutoIT option)
    $g_id_checkRegistry = GUICtrlCreateCheckbox("Add Registry Keys (Requires UAC Admin Priviledge)", 72, 384, 489, 41)
    GUICtrlSetState(-1, $iRegistryChecked)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetBkColor(-1, $COL_GROUP)
    GUICtrlSetTip(-1, "Adds Registry Keys to allow double-click running of scripts.")
    GUICtrlSetOnEvent(-1, "Registry_Check")

    ; Create Extension option InputBox (tied to Registry Keys install option)
    $g_id_inputExtension = GUICtrlCreateInput($g_sDEFAULT_EXT, 96, 432, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetState(-1, $iInputExtensionState)

    $g_id_lblInputExtension = GUICtrlCreateLabel("Extension for AutoIt scripts", 200, 432, 224, 28)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetTip(-1, "AutoIt scripts will be registered with this extension")
    GUICtrlSetBkColor(-1, $COL_GROUP)
    GUICtrlSetState(-1, $iInputExtensionState)

    ; --------------------------------
    ; Create Graphics GUIControls (for eye candy) - order is important
    GUICtrlCreateGraphic(24, 176, 569, 25) ;Group Header Color
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    GUICtrlCreateGraphic(24, 202, 569, 286) ;Group Background Color
    GUICtrlSetBkColor(-1, $COL_GROUP)

    GUICtrlCreateGraphic(32, 280, 553, 2) ; 2 pxs high horizontal line
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    GUICtrlCreateGraphic(32, 336, 553, 2) ; 2 pxs high horizontal line
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    ; ---------------------------------
    ; Create Installation Info Button
    GUICtrlCreateButton("INSTALLATION INFO", 24, 504, 188, 33)
    GUICtrlSetFont(-1, 12, 800, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetTip(-1, "Open ""LazyD Charter - Installation Information"" file")
    GUICtrlSetBkColor(-1, $COL_BTN_DEFAULT)
    GUICtrlSetOnEvent(-1,"Info_Window")

    ; Display the App Window
    GUISetState(@SW_SHOW)

    ; Message Loop
    While 1
        sleep(100)
    WEnd

EndFunc

Func Get_ScriptFileNames_WithoutExtension()

    Local $aScriptFile = _FileListToArray(@ScriptDir,Default,$FLTA_FILES,Default)
    Local $aTemp[ubound($aScriptFile)-1]

    for $i = 1 to ubound($aScriptFile)-1
        Local $sScriptFileName = $aScriptFile[$i]
        Local $sScriptFileName_WithoutExtension = StringTrimRight($sScriptFileName,4) ; 4 = 3 for "a3x" + 1 for "."
        $aTemp[$i-1] = $sScriptFileName_WithoutExtension
    Next

    return $aTemp

endfunc

func AutoIT_Check()

    ; Check if AutoIt installation option checkbox is checked
    if _IsChecked($g_id_checkAutoIt) Then
        GUICtrlSetState($g_id_checkRegistry, $GUI_UNCHECKED + $GUI_ENABLE)
    Else
        GUICtrlSetState($g_id_checkRegistry, $GUI_UNCHECKED + $GUI_DISABLE)
        GUICtrlSetState($g_id_inputExtension, $GUI_DISABLE)
        GUICtrlSetState($g_id_lblInputExtension, $GUI_DISABLE)
    EndIf

EndFunc

func Registry_Check()

    ; Check if Registry changes installation option checkbox is checked
    if _IsChecked($g_id_checkRegistry) Then
        GUICtrlSetState($g_id_inputExtension, $GUI_ENABLE)
        GUICtrlSetState($g_id_lblInputExtension, $GUI_ENABLE)
    Else
        GUICtrlSetState($g_id_inputExtension, $GUI_DISABLE)
        GUICtrlSetState($g_id_lblInputExtension, $GUI_DISABLE)
    EndIf

EndFunc

func Info_Window()

    ; Set Path according to script dir location
    Local $sInfoPath = (FileExists(@ScriptDir & "\Text Files")) ? (@ScriptDir & "\Text Files") : (@ScriptDir & "\..\Charter\Apps\Text Files")

    ; Open Installation Info.rtf in default viewer
    ShellExecute($sInfoPath & "\Installation Info.rtf")

EndFunc

func Quit_App()

    ; Close App Window, Exit App
    GUIDelete(@GUI_WinHandle)
    Exit

EndFunc

func Select_Install_Directory()

    ; Changes needed to be done on various controls when user changes the install directory
    Local $sDefaultPath = GUICtrlRead($g_id_inputInstallDirectory)
    Local $sDefaultDrive = StringLeft($sDefaultPath,3)
    Local $sInstallPath = FileSelectFolder("Select the main folder to install LazyD Charter to...",$sDefaultDrive,Default,"",@GUI_WinHandle)

    if $sInstallPath = "" then
        GUICtrlSetData($g_id_inputInstallDirectory,$sDefaultPath)
        Return
    Else
        if StringRight($sInstallPath, 13) = "LazyD Charter" Then
            ; User selected the Default Folder Name
            ; Do Nothing
        Else
            if StringLen($sInstallPath) = 3 Then
                ; User selected the root of a drive, append Default Folder name
                $sInstallPath &= "LazyD Charter"
            Else
                ; User selected a different folder
                ; Do Nothing
            EndIf
        EndIf
    EndIf

    GUICtrlSetData($g_id_inputInstallDirectory,$sInstallPath)

EndFunc

func Install_App()

    Local $sRegHive = "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\"
    Local $sInstallPath = GUICtrlRead($g_id_inputInstallDirectory)
    Local $iOverWriteMethod = $FC_OVERWRITE

    ; Install LazyD Charter with the installation options selected

    ; Check $sExt related stuff
    Local $sExt
    $sExt = GUICtrlRead($g_id_inputExtension)
    if _isEnabled($g_id_inputExtension) Then
        ; Check if $sExt is empty
        if $sExt = "" Then
            msgbox($MB_OK,"Warning","Extension Type is Blank! I will set it to the Default = """ & $g_sDEFAULT_EXT &  """ and Return back to the Options Window" & @CRLF & "Please set it accordingly or keep it as it is.")
            GUICtrlSetData($g_id_inputExtension, $g_sDEFAULT_EXT)
            Return
        Else
            ; Check if key already exists
            RegRead($sRegHive & "."  & $sExt,"")
            if @error <= 0 then
                ; Key already exists, check if it is a LazyD Charter key
                if RegRead($sRegHive & "." & $sExt,"Check") = """LazyD Charter""" Then
                    ; This key was created by LazyD Charter before
                    ; Do Nothing
                Else
                    ; This key looks like belonging to some other app
                    if $sExt = $g_sDEFAULT_EXT then
                        ; Default Extension is registered to some other app, append "s" to $g_sDEFAULT_EXT and Return to Options Window
                        msgbox($MB_OK,"Warning","The Default Extension Type """ & $g_sDEFAULT_EXT & """ is registered with another application!" & @CRLF & "I will set it to """ & $g_sDEFAULT_EXT & "s" & """ and Return back to the Options Window" & @CRLF & "Please click INSTALL button again.")
                        $g_sDEFAULT_EXT &= "s"
                        GUICtrlSetData($g_id_inputExtension, $g_sDEFAULT_EXT)
                    Else
                        ; User supplied Extension is registered to some other app, change back to Default and Return to Options Window
                        msgbox($MB_OK,"Warning","The selected Extension Type is registered with another application!" & @CRLF & "I will set it to the Default = """ & $g_sDEFAULT_EXT & """ and Return back to the Options Window" & @CRLF & "Please change it to something else.")
                        GUICtrlSetData($g_id_inputExtension, $g_sDEFAULT_EXT)
                    EndIf
                    Return
                EndIf
            EndIf
        EndIf
    Else
        ; Set a Default Value, Won't be used anyway since Registry option is unchecked
        $sExt = "a3x"
    EndIf

    ; Before anything check if previous ini file exists or contains "Install_Path" key
    Local $sPreviousInstallPath = IniRead(@AppDataDir & "\Roaming\LazyD Charter\LazyD Charter.ini","Install","Install_Path","")

    ; Check whether current install path is same as previous install path
    if not ($sPreviousInstallPath = "" or $sPreviousInstallPath <> $sInstallPath) Then
        ; Check whether Install Folder size is zero
        if not (DirGetSize($sPreviousInstallPath) = 0) Then
            ; If it is, ask to user what to do?
            Local $iAnswer = msgbox($MB_YESNOCANCEL,"Previous Installation Found","Found some folders at a previous installation location:" & @CRLF & """" & $sPreviousInstallPath & """" & @CRLF & "Should I delete the old installation folder?" & @CRLF & "Click CANCEL Button to Abort!")
            if $iAnswer = $IDNO Then
                ; Set Overwrite method to No-Overwrite and Continue
                $iOverWriteMethod = $FC_NOOVERWRITE
            Elseif $iAnswer =$IDYES Then
                ; Delete previous installation folder and continue
                DirRemove($sPreviousInstallPath,$DIR_REMOVE)
            elseif $iAnswer = $IDCANCEL Then
                ; User cancelled the install operation
                Return
            EndIf
        EndIf
    EndIf

    ; Check if Install Dir Exists, create if not
    Local $iCharterInstallDirCreated
    if not(FileExists($sInstallPath)) Then
        $iCharterInstallDirCreated = DirCreate($sInstallPath)
    EndIf

    ; Return to Main App if above steps are unsuccessful
    if $iCharterInstallDirCreated <> 1 and not(FileExists($sInstallPath)) then
        msgbox($MB_OK, "Error", "Couldn't create LazyD Charter install dir: """ & $sInstallPath & """")
        Return
    EndIf

    ; Copy Temp Install Folder\Charter Contents to Install Folder
    DirCopy(@ScriptDir & "\..\Charter",$sInstallPath,$iOverWriteMethod)

    ; Copy AutoIt3.exe and Script Files to Charter\Apps folders according to Install Options
    if not(_IsChecked($g_id_checkAutoIt)) Then
        ; Don't copy AutoIt3.exe or a3x scripts
        ; Do Nothing
    elseif (_IsChecked($g_id_checkAutoIt) and not(_IsChecked($g_id_checkRegistry))) Then
        ; Copy AutoIt3.exe and Copy Scripts with unchanged extension (a3x)
        FileCopy(@ScriptDir & "\" & $g_sAutoItVer, $sInstallPath & "\Apps",$iOverWriteMethod)
        for $i = 1 to ubound($g_aScriptFiles)
            if not ($g_aScriptFiles[$i-1] = "") then FileCopy(@ScriptDir & "\" & $g_aScriptFiles[$i-1] & ".a3x", $sInstallPath & "\Apps", $iOverWriteMethod)
        next
    elseif (_IsChecked($g_id_checkAutoIt) and _IsChecked($g_id_checkRegistry)) Then
        ; Copy AutoIt3.exe and Copy Script Files with new extension (Extension may be set to default "a3x" regardless depending on the input box State ($GUI_DISABLE))
        FileCopy(@ScriptDir & "\" & $g_sAutoItVer, $sInstallPath & "\Apps",$iOverWriteMethod)
        for $i = 1 to ubound($g_aScriptFiles)
            if not ($g_aScriptFiles[$i-1] = "") then FileCopy(@ScriptDir & "\" & $g_aScriptFiles[$i-1] & ".a3x", $sInstallPath & "\Apps\" & $g_aScriptFiles[$i-1] & "." & $sExt, $iOverWriteMethod)
        next
    EndIf

    ; Create Registry Entry for Extension (if install option is selected) if it doesn't exist and add shell command to start AutoIt3.exe with the calling a3x script's full path
    if (_IsChecked($g_id_checkRegistry) and _IsChecked($g_id_checkAutoIt)) Then
        RegRead($sRegHive & "."  & $sExt,"")

        If @Error > 0 Then
           ; Key does not exist create all entries
            RegWrite($sRegHive & "."  & $sExt)
                RegWrite($sRegHive & "."  & $sExt, "Check", "REG_SZ", """LazyD Charter""")

            RegWrite($sRegHive & "."  & $sExt & "\DefaultIcon")
                RegWrite($sRegHive & "."  & $sExt & "\DefaultIcon","","REG_SZ","""" & $sInstallPath & "\Apps\ChResource\LazyD_Ch.ico""")

            RegWrite($sRegHive & "."  & $sExt & "\shell")
                RegWrite($sRegHive & "."  & $sExt & "\shell\open")
                    RegWrite($sRegHive & "."  & $sExt & "\shell\open\command")
                        RegWrite($sRegHive & "."  & $sExt & "\shell\open\command", "","REG_SZ","""" & $sInstallPath & "\Apps\" & $g_sAutoItVer & """ ""%1""")
        Else
           ; Key does exist, check for subkeys and stuff and create subkeys if they don't exist, and update/create values
            RegWrite($sRegHive & "."  & $sExt, "Check", "REG_SZ", """LazyD Charter""") ; update/create Value(Check)

            RegRead($sRegHive & "."  & $sExt & "\DefaultIcon","") ; Read Subkey(DefaultIcon) Default Value
            if @error <> 0 then RegWrite($sRegHive & "."  & $sExt & "\DefaultIcon") ; Create Subkey(DefaultIcon)
            RegWrite($sRegHive & "."  & $sExt & "\DefaultIcon","","REG_SZ","""" & $sInstallPath & "\Apps\ChResource\LazyD_Ch.ico""") ; Update/create Value(DefaultIcon Location)

            RegRead($sRegHive & "."  & $sExt & "\shell","") ; Read Subkey(shell) Default Value
            if @error <> 0 then RegWrite($sRegHive & "."  & $sExt & "\shell") ; Create Subkey(shell)
                RegRead($sRegHive & "."  & $sExt & "\shell\open","") ; Read Subkey(shell\open) Default Value
                if @error <> 0 then RegWrite($sRegHive & "."  & $sExt & "\shell\open") ; Create Subkey(shell\open)
                    RegRead($sRegHive & "."  & $sExt & "\shell\open\command","") ; Read Subkey(shell\open\command) Default Value
                    if @error <> 0 then RegWrite($sRegHive & "."  & $sExt & "\shell\open\command") ; Create Subkey(shell\open\command)
                    RegWrite($sRegHive & "."  & $sExt & "\shell\open\command","","REG_SZ","""" & $sInstallPath & "\Apps\" & $g_sAutoItVer & """ ""%1""") ; Update/create Value(AutoIt3.exe Location)
        endif
    EndIf

    ; Create Charter AppData/Roaming Folder if it doesnt exist
    if not (FileExists(@AppDataDir & "LazyD Charter")) Then
        DirCreate(@AppDataDir & "\LazyD Charter")
    EndIf

    ; Create LazyD Charter.ini and write options
    Local $sAppDataChecked = (_IsChecked($g_id_checkAppData)) ? ("True") : ("False")
    Local $sAutoItChecked = (_IsChecked($g_id_checkAutoIt)) ? ("True") : ("False")
    Local $sRegistryChecked = ((not _IsEnabled($g_id_checkRegistry)) or (not _IsChecked($g_id_checkRegistry))) ? ("False") : ("True")

    IniWrite(@AppDataDir & "\LazyD Charter\LazyD Charter.ini", "Install", "Install_Path", $sInstallPath)
    IniWrite(@AppDataDir & "\LazyD Charter\LazyD Charter.ini", "Install", "AppData_Checked", $sAppDataChecked)
    IniWrite(@AppDataDir & "\LazyD Charter\LazyD Charter.ini", "Install", "AutoIt_Checked", $sAutoItChecked)
    IniWrite(@AppDataDir & "\LazyD Charter\LazyD Charter.ini", "Install", "Registry_Checked", $sRegistryChecked)
    IniWrite(@AppDataDir & "\LazyD Charter\LazyD Charter.ini", "Install", "Extension", $sExt)
    IniWrite(@AppDataDir & "\LazyD Charter\LazyD Charter.ini", "Install", "Registry_Hive", $sRegHive)
    IniWrite(@AppDataDir & "\LazyD Charter\LazyD Charter.ini", "Install", "AutoItVer", $g_sAutoItVer)

    ; Copy xlsm to User Desktop
    if FileExists(@DesktopDir & "\LazyD Charter - The Machine Ed.xlsm") then
        ; if previous xlsm found append (New) to filename and copy
        FileCopy($sInstallPath & "\Assets\Excel\LazyD Charter - The Machine Ed.xlsm",@DesktopDir & "\LazyD Charter - The Machine Ed (New).xlsm",$FC_NOOVERWRITE)
    Else
        ; copy as is
        FileCopy($sInstallPath & "\Assets\Excel\LazyD Charter - The Machine Ed.xlsm",@DesktopDir,$FC_NOOVERWRITE)
    EndIf

    ; Notify User about Successful Installation and Close Installer
    MsgBox($MB_OK,"LazyD Charter Installer","Installation was successful. Click OK to close Installer")

    Quit_App()

endFunc

func _IsChecked($idControlID)

    ; Check if CheckBox is checked
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED

EndFunc

func _IsEnabled($idControlID)

    ; Check for Control's State (ENABLED/DISABLED)
    if BitAnd(GUICtrlGetState($idControlID), $GUI_ENABLE) = $GUI_ENABLE Then
        Return True
    Else
        Return False
    EndIf

Endfunc

Maybe, someone interested in this can create a customizable version which is more suited to a general audience actually for using a3x rather than having them optional. Idk, let me know what you think. With some modification, you could separate 32-64 bit scripts, and different versions of AutoIt and associate with different extensions perhaps.

Thanks for reading! Also a big thanks to everyone who have shared their knowledge here on the forums. You guys/girls make the world a better place :) 

Btw: LazyD stands for 2 things, used to be "Lazy Drummer" only, and now "Lazy Developer" too, :idiot: 

Edit: For those who would like to see it in action, attached the folder that would be unzipped by the self extracting exe. However, removed AutoIt3.exe from the zip as per Jos' advice. Just copy paste it to Scripts folder from your own AutoIt install folder.

Edit: Posted CH_Configuration and CH_Uninstaller https://www.autoitscript.com/forum/topic/204395-installer-to-distribute-autoit-a3x-scripts/?do=findComment&comment=1468795

CH_Installer_Final.au3 LazyD Charter Color Theme.au3

CH_Install.7z

Edited by GokAy
Link to comment
Share on other sites

First one. Oh and no I really am not a drummer. Just played GuitarHero drums, and now Clone Hero. People see the e-drum kit at my house and ask if I play the drums. I have to explain each time. Even harder in English as you "play" the drums in a game, and "play" an instrument. So I tell them, "Don't call me a drummer, as I am not, even if I were, I would be the lazy kind". 😛 

Link to comment
Share on other sites

2. CH_Configuration

Same GUI as Installer, only task is to let user change options, and execute the changes. One worthy part to check would be the batch files created depending on:

1. InstallPath change (delete script and AutoIt3.exe from old InstallPath, which are both running at that time)

2. Extension change when InstallPath stay same (delete scripts with old extension, at that time CH_Configuration would be running)

Idea is, create the batch files, start them and terminate script. Batch file waits for 5 seconds (for interpreter and script to shutdown) and asks the user to either continue or quit. Continue: deletes whatever needed and deletes itself afterwards. Quit: Quits the batch execution and leaves it there for user to start it a later time.

The code:

Spoiler
#NoTrayIcon
#RequireAdmin

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_type=a3x
#AutoIt3Wrapper_Outfile=CH_Install\Scripts\CH_Configuration.a3x
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_Res_Description=Script file for configuring LazyD Charter installation options
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_ProductName=LazyD Charter
#AutoIt3Wrapper_Res_ProductVersion=1.0.0.0
#AutoIt3Wrapper_Res_CompanyName=LazyD is not a company
#AutoIt3Wrapper_Res_LegalCopyright=None
#AutoIt3Wrapper_Res_LegalTradeMarks=None
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <File.au3>
#include <FileConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
#include <Constants.au3>

#include <LazyD Charter Color Theme.au3>

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("GUIOnEventMode", 1)

; Default Variable Values
Global $g_sIniFile = @AppDataDir & "\LazyD Charter\LazyD Charter.ini"
Global $g_sInstallPath = IniRead($g_sIniFile,"Install","Install_Path","NotRead")
Global $g_sAppDataChecked = IniRead($g_sIniFile,"Install","AppData_Checked","NotRead") ; Unused ATM
Global $g_sAutoItChecked = IniRead($g_sIniFile,"Install","AutoIt_Checked","NotRead")
Global $g_sRegistryChecked = IniRead($g_sIniFile,"Install","Registry_Checked","NotRead")
Global $g_sExtension = IniRead($g_sIniFile,"Install","Extension","NotRead")
Global $g_sRegHive = IniRead($g_sIniFile,"Install","Registry_Hive","NotRead")
Global $g_sAutoItVer = IniRead($g_sIniFile,"Install","AutoItVer","NotRead")

Global $g_sDEFAULT_EXT = ($g_sExtension = "a3x") ? ($g_sExtension & "s") : ($g_sExtension)

; Quit_App if Install Path can not be read
If $g_sInstallPath = "NotRead" then
    MsgBox($MB_OK,"Warning!","Install Path can not be read. Please check if """ & $g_sIniFile & """ exists.")
    Exit
EndIf

;~ ; Get Script Files Names without Extension
;~ Global $g_aScriptFiles = Get_ScriptFileNames_WithoutExtension()

Global $g_sCurrentInstallPath = $g_sInstallPath
Global $g_sCurrentAppDataChecked = $g_sAppDataChecked
Global $g_sCurrentAutoItChecked = $g_sAutoItChecked
Global $g_sCurrentRegistryChecked = $g_sRegistryChecked
Global $g_sCurrentExtension = $g_sExtension
Global $g_sCurrentRegHive = $g_sRegHive

; Set GUI Control element default values according to ini file values
Global $g_iAppDataChecked = ($g_sAppDataChecked = "True") ? ($GUI_CHECKED) : ($GUI_UNCHECKED)
Global $g_iAutoItChecked = ($g_sAutoItChecked = "True") ? ($GUI_CHECKED) : ($GUI_UNCHECKED)
Global $g_iRegistryChecked = ($g_sRegistryChecked = "True") ? ($GUI_CHECKED) : ($GUI_UNCHECKED)
Global $g_iAppDataState = ($g_sAppDataChecked = "True") ? ($GUI_ENABLE) : ($GUI_DISABLE)
Global $g_iAutoItState = ($g_sAutoItChecked = "True") ? ($GUI_ENABLE) : ($GUI_DISABLE)
Global $g_iRegistryState = ($g_sAutoItChecked = "True") ? ($GUI_ENABLE) : ($GUI_DISABLE)
Global $g_iInputExtensionState = ($g_iRegistryChecked = $GUI_CHECKED) ? ($GUI_ENABLE) : ($GUI_DISABLE)

Global $g_id_inputInstallDirectory
Global $g_id_checkRegistry
Global $g_id_checkAutoIt
Global $g_id_inputExtension
Global $g_id_checkAppData
Global $g_id_lblInputExtension

Create_App_Window()

Func Create_App_Window()

    ; Create App Window
    GUICreate("LazyD Charter Configuration", 611, 550, -1, -1)
    GUISetIcon($g_sInstallPath & "\Apps\ChResource\LazyD_Ch.ico")
    GUISetBkColor($COL_APP_WINDOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Quit_App")

    ; Create Dummy Button to intercept Return key press
    GUICtrlCreateButton("",0,0,0,0,-1,-1)
    GUICtrlSetBkColor(-1, $COL_APP_WINDOW)
    GUICtrlSetFont(-1, 14, 400, 0, "")

    ; Create QUIT Button
    GUICtrlCreateButton("QUIT", 493, 112, 100, 33)
    GUICtrlSetFont(-1, 14, 800, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_BTN_QUIT)
    GUICtrlSetTip(-1, "Click to quit the re-configuration process.")
    GUICtrlSetOnEvent(-1,"Quit_App")

    ; Create Install Directory Input Box
    $g_id_inputInstallDirectory = GUICtrlCreateInput($g_sInstallPath, 16, 48, 465, 32)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_GROUP)

    ; Create Install Directory Label
    GUICtrlCreateLabel("Install Directory", 16, 16, 146, 28)
    GUICtrlSetFont(-1, 14, 800, 0, "")
    GUICtrlSetColor(-1, 0x000000)

    ; Create Install Directory SELECT Button
    GUICtrlCreateButton("SELECT", 496, 48, 100, 33)
    GUICtrlSetFont(-1, 14, 800, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_BTN_DEFAULT)
    GUICtrlSetTip(-1, "Click to select another install folder location.")
    GUICtrlSetOnEvent(-1,"Select_Install_Directory")

    ; Create APPLY Button
    GUICtrlCreateButton("APPLY", 16, 112, 100, 33)
    GUICtrlSetFont(-1, 14, 800, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_BTN_DEFAULT)
    GUICtrlSetTip(-1, "Apply configuration changes.")
    GUICtrlSetOnEvent(-1,"Execute_Changes")

    ; ----------------------------
    ; Create Install Options Group
    GUICtrlCreateGroup("Options", 24, 176, 569, 313)
    GUICtrlSetFont(-1, 14, 800, 0, "")
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    ; Create Install Options Message Label
    GUICtrlCreateLabel("Optional installation features which will make your life easier, none are essential for using LazyD Charter.", 40, 216, 504, 60)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetBkColor(-1, $COL_GROUP)

    ; Create AppData Option CheckBox (and Label seperately as text color wouldn't change)
    $g_id_checkAppData = GUICtrlCreateCheckbox("", 42, 288, 41, 41)
    GUICtrlSetState(-1, $g_iAppDataChecked + $g_iAppDataState)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetTip(-1, "This option is disabled at the moment.")
    GUICtrlSetBkColor(-1, $COL_GROUP)

    GUICtrlCreateLabel("Create ""AppData\Roaming\LazyD Charter"" folder", 60, 295, 420, 41)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetTip(-1, "This option is disabled at the moment.")
    GUICtrlSetColor(-1, $COL_GROUP_HEADER)
    GUICtrlSetBkColor(-1, $COL_GROUP)

    ; Create AutoIt installation option CheckBox
    $g_id_checkAutoIt = GUICtrlCreateCheckbox("Use AutoIt Scripts", 42, 344, 465, 41)
    GUICtrlSetState(-1, $g_iAutoItChecked + $g_iAutoItState)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetTip(-1, "Keep it checked to copy """ & $g_sAutoItVer & """ and ""LazyD Charter Scripts"" to install directory.")
    GUICtrlSetBkColor(-1, $COL_GROUP)
    GUICtrlSetOnEvent(-1, "AutoIT_Check")

    ; Create Registry Keys installation option Checkbox (tied to AutoIT option)
    $g_id_checkRegistry = GUICtrlCreateCheckbox("Add Registry Keys (Requires UAC Admin Priviledge)", 72, 384, 489, 41)
    GUICtrlSetState(-1, $g_iRegistryChecked + $g_iRegistryState)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetBkColor(-1, $COL_GROUP)
    GUICtrlSetTip(-1, "Adds Registry Keys to allow double-click running of scripts.")
    GUICtrlSetOnEvent(-1, "Registry_Check")

    ; Create Extension option InputBox (tied to Registry Keys install option)
    $g_id_inputExtension = GUICtrlCreateInput($g_sDEFAULT_EXT, 96, 432, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetState(-1, $g_iInputExtensionState)

    $g_id_lblInputExtension = GUICtrlCreateLabel("Extension for AutoIt scripts", 200, 432, 224, 28)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetTip(-1, "AutoIt scripts will be registered with this extension")
    GUICtrlSetBkColor(-1, $COL_GROUP)
    GUICtrlSetState(-1, $g_iInputExtensionState)

    ; --------------------------------
    ; Create Graphics GUIControls (for eye candy) - order is important
    GUICtrlCreateGraphic(24, 176, 569, 25) ;Group Header Color
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    GUICtrlCreateGraphic(24, 202, 569, 286) ;Group Background Color
    GUICtrlSetBkColor(-1, $COL_GROUP)

    GUICtrlCreateGraphic(32, 280, 553, 2) ; 2 pxs high horizontal line
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    GUICtrlCreateGraphic(32, 336, 553, 2) ; 2 pxs high horizontal line
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    ; ---------------------------------
    ; Create Configuration Info Button
    GUICtrlCreateButton("CONFIGURATION INFO", 24, 504, 188, 33)
    GUICtrlSetFont(-1, 12, 800, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetTip(-1, "Open ""LazyD Charter - Configuration Information"" file")
    GUICtrlSetBkColor(-1, $COL_BTN_DEFAULT)
    GUICtrlSetOnEvent(-1,"Info_File")

    ; Display the App Window
    GUISetState(@SW_SHOW)

    ; Message Loop
    While 1
        sleep(100)
    WEnd

EndFunc

Func Get_ScriptFileNames_WithoutExtension()

    Local $aScriptFile = _FileListToArray($g_sInstallPath & "\Apps",Default,$FLTA_FILES,Default)

    ; Delete from Array if FileName = $g_sAutoItVer or Extension is not $g_sExtension
    Local $iFileCount = $aScriptFile[0]
    Local $sScriptFileName
    Local $sScriptFileExtension
    Local $sScriptFileName_WithoutExtension

    for $i = 1 to ubound($aScriptFile)-1
        $sScriptFileName = $aScriptFile[$i]
        $sScriptFileExtension = StringTrimLeft($sScriptFileName,StringInStr($sScriptFileName,".",0,-1))

        if ($sScriptFileName = $g_sAutoItVer) Or not ($sScriptFileExtension = $g_sCurrentExtension) Then
            $aScriptFile[$i] = ""
            $iFileCount -= 1
        EndIf
    Next

    ; Create Temp Array to hold script file names without extension
    Local $aTemp[1]
    if $iFileCount > 0 Then
        redim $aTemp[$iFileCount]
        Local $iIndex = 0
        for $i = 1 to ubound($aScriptFile)-1
            if not ($aScriptFile[$i] = "") Then
                $sScriptFileName = $aScriptFile[$i]
                $sScriptFileName_WithoutExtension = StringTrimRight($sScriptFileName,1 + StringLen($g_sCurrentExtension)) ; 1 for "."
                $aTemp[$iIndex] = $sScriptFileName_WithoutExtension
                $iIndex += 1
            EndIf
        Next
    EndIf

    ; Return Final Array
    return $aTemp

endfunc

Func Execute_Changes()

    ; Get New Configuration Options
    $g_sInstallPath = GUICtrlRead($g_id_inputInstallDirectory)
    $g_iAppDataChecked = GUICtrlRead($g_id_checkAppData) ; Disabled ATM
    $g_iAutoItChecked = GUICtrlRead($g_id_checkAutoIt)
    $g_iRegistryChecked = GUICtrlRead($g_id_checkRegistry)
    $g_sExtension = GUICtrlRead($g_id_inputExtension)
    $g_sRegHive = $g_sRegHive ; No option for this ATM

    $g_sAppDataChecked = ($g_iAppDataChecked = $GUI_CHECKED) ? ("True") : ("False")
    $g_sAutoItChecked = ($g_iAutoItChecked = $GUI_CHECKED) ? ("True") : ("False")
    $g_sRegistryChecked = ($g_iRegistryChecked = $GUI_CHECKED) ? ("True") : ("False")

    ; Check for New Reg Key exists, if exists and Check Value <> "LazyD Charter" then warn user and return
    If _IsEnabled($g_id_inputExtension) Then
        ; Check if key already exists
        RegRead($g_sRegHive & "."  & $g_sExtension,"")
        if @error <= 0 then
            ; Key already exists, check if it is a LazyD Charter key
            if RegRead($g_sRegHive & "." & $g_sExtension,"Check") = """LazyD Charter""" Then
                ; This key was created by LazyD Charter before, can update
                If $g_sExtension = $g_sCurrentExtension Then
                    ; No need to create a new key, just change current Installation Paths to the New Installation Path
                    RegWrite($g_sRegHive & "."  & $g_sExtension & "\DefaultIcon","","REG_SZ","""" & $g_sInstallPath & "\Apps\ChResource\LazyD_Ch.ico""")
                    RegWrite($g_sRegHive & "."  & $g_sExtension & "\shell\open\command", "","REG_SZ","""" & $g_sInstallPath & "\Apps\" & $g_sAutoItVer & """ ""%1""")
                EndIf
            Else
                ; This key belongs to some other app, warn and return
                MsgBox($MB_OK, "Warning!", "The New Extension """ & $g_sExtension & """ belongs to some other application." & @CRLF & "Please select another extension. Click OK to return back to the Configuration window.")
                Return
            EndIf
        Else
            ; Create New Key
            RegWrite($g_sRegHive & "."  & $g_sExtension)
                RegWrite($g_sRegHive & "."  & $g_sExtension, "Check", "REG_SZ", """LazyD Charter""")

            RegWrite($g_sRegHive & "."  & $g_sExtension & "\DefaultIcon")
                RegWrite($g_sRegHive & "."  & $g_sExtension & "\DefaultIcon","","REG_SZ","""" & $g_sInstallPath & "\Apps\ChResource\LazyD_Ch.ico""")

            RegWrite($g_sRegHive & "."  & $g_sExtension & "\shell")
                RegWrite($g_sRegHive & "."  & $g_sExtension & "\shell\open")
                    RegWrite($g_sRegHive & "."  & $g_sExtension & "\shell\open\command")
                        RegWrite($g_sRegHive & "."  & $g_sExtension & "\shell\open\command", "","REG_SZ","""" & $g_sInstallPath & "\Apps\" & $g_sAutoItVer & """ ""%1""")
        EndIf
    Else
        $g_sExtension = "a3x"
    EndIf

    ; Create New Installation Folder (if Old <> New)
    If $g_sInstallPath <> $g_sCurrentInstallPath Then
        ; Check if Install Dir Exists, create if not
        Local $iCharterInstallDirCreated
        if not(FileExists($g_sInstallPath)) Then
            $iCharterInstallDirCreated = DirCreate($g_sInstallPath)
        EndIf

        ; Return to Main App if above steps are unsuccessful
        if $iCharterInstallDirCreated <> 1 and not(FileExists($g_sInstallPath)) then
            MsgBox($MB_OK, "Error", "Couldn't create LazyD Charter install dir: """ & $g_sInstallPath & """")
            Return
        EndIf
    EndIf

    ; Copy Install Folder (if Old <> New)
    If $g_sInstallPath <> $g_sCurrentInstallPath Then
        DirCopy($g_sCurrentInstallPath, $g_sInstallPath, $FC_OVERWRITE)
    EndIf

    ; Delete AutoIt and scripts if AutoIt is unchecked
    if not (_IsChecked($g_id_checkAutoIt)) Then
        FileDelete($g_sInstallPath & "\Apps\" & $g_sAutoItVer)
        FileDelete($g_sInstallPath & "\Apps\*." & $g_sCurrentExtension)
    EndIf

    ; Change Extension Type of scripts if Extension Input Box is Enabled, and Old Extension <> New Extension
    if _IsChecked($g_id_checkAutoIt) Then
        If $g_sExtension <> $g_sCurrentExtension Then
            ; Read script filenames from scripts file
;~          Local $hScriptFile = FileOpen($g_sScriptFiles, $FO_READ)
;~          Local $aScriptFiles = FileReadToArray($hScriptFile)
;~          FileClose($hScriptFile)

            Local $aScriptFiles = Get_ScriptFileNames_WithoutExtension()

            for $i = 0 to ubound($aScriptFiles)-1
                FileCopy($g_sCurrentInstallPath & "\Apps\" & $aScriptFiles[$i] & "." & $g_sCurrentExtension, $g_sInstallPath & "\Apps\" & $aScriptFiles[$i] & "." & $g_sExtension)
            Next
        EndIf
    EndIf

    ; Change AppData ini
    IniWrite($g_sIniFile,"Install","Install_Path",$g_sInstallPath)
    IniWrite($g_sIniFile,"Install","AppData_Checked",$g_sAppDataChecked) ; Unused ATM
    IniWrite($g_sIniFile,"Install","AutoIt_Checked",$g_sAutoItChecked)
    IniWrite($g_sIniFile,"Install","Registry_Checked",$g_sRegistryChecked)
    IniWrite($g_sIniFile,"Install","Extension",$g_sExtension)
    IniWrite($g_sIniFile,"Install","Registry_Hive",$g_sRegHive)
    IniWrite($g_sIniFile,"Install","AutoItVer",$g_sAutoItVer)

    ; Delete Old Reg Key if not same
    if $g_sCurrentRegistryChecked = "True" then
        ; Old Key exists, delete if Old <> New
        if $g_sExtension <> $g_sCurrentExtension Then
            RegRead($g_sRegHive & "."  & $g_sCurrentExtension,"")
            if @error <= 0 then
                ; Key already exists, check if it is a LazyD Charter key
                if RegRead($g_sRegHive & "." & $g_sCurrentExtension,"Check") = """LazyD Charter""" Then
                    RegDelete($g_sRegHive & "." & $g_sCurrentExtension)
                EndIf
            EndIf
        EndIf
    Else
        ; Old Key doesn't exist
        ; Do Nothing
    EndIf

    ; Create Batch file to delete old Installation Folder (if Old <> New)
    Local $sRoot = StringLeft($g_sCurrentInstallPath, 2)
    Local $sParent = StringTrimRight($g_sCurrentInstallPath, StringLen($g_sCurrentInstallPath) - StringInStr($g_sCurrentInstallPath, "\", 0, -1) + 1)
    Local $hFile

    if $g_sInstallPath <> $g_sCurrentInstallPath Then
        FileDelete($sParent & "\DeleteInstallFolder.bat")
        $hFile = FileOpen($sParent & "\DeleteInstallFolder.bat", $FO_APPEND)
        FileWriteLine($hFile, "@PUSHD %~dp0")
        FileWriteLine($hFile, "@ECHO OFF")
        FileWriteLine($hFile, "ECHO LazyD Charter:")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO This is an automatically created batch file")
        FileWriteLine($hFile, "ECHO which will remove the Old Install Folder")
        FileWriteLine($hFile, "ECHO and will delete itself after running.")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Old Install Directory: """ & $g_sCurrentInstallPath & """")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Changing Drive to """ & $sRoot & """")
        FileWriteLine($hFile, $sRoot)
        FileWriteLine($hFile, "ECHO Changing Directory to """ & $sParent & """")
        FileWriteLine($hFile, "CD """ & $sParent & """")
        if $sParent = $sRoot then
            FileWriteLine($hFile, "ECHO Batch File: %CD%DeleteInstallFolder.bat ")
        Else
            FileWriteLine($hFile, "ECHO Batch File: %CD%\DeleteInstallFolder.bat ")
        EndIf
        if $g_sCurrentExtension <> $g_sExtension then FileWriteLine($hFile, "DEL /F /Q """ & $g_sInstallPath & "\Apps\*." & $g_sCurrentExtension & """")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Please confirm correct directory and")
        FileWriteLine($hFile, "ECHO Press ""Y"" to delete Old Install Folder")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Waiting for 5 seconds to let script and interpreter")
        FileWriteLine($hFile, "ECHO to shutdown.")
        FileWriteLine($hFile, "TIMEOUT 5 >NUL")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "CHOICE /C YX /N /M ""Continue? (Press ""X"" to QUIT)""")
        FileWriteLine($hFile, "IF ERRORLEVEL 2 GOTO QUIT")
        FileWriteLine($hFile, "IF ERRORLEVEL 1 @ECHO OFF")
        FileWriteLine($hFile, "IF EXIST """ & $g_sCurrentInstallPath & """ RMDIR /Q /S """ & $g_sCurrentInstallPath & """")
        FileWriteLine($hFile, "IF EXIST """ & $sParent & "\DeleteInstallFolder.bat"" DEL /F /Q """ & $sParent & "\DeleteInstallFolder.bat""")
        FileWriteLine($hFile, ":QUIT")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Please re-run this batch script to complete deletion")
        FileWriteLine($hFile, "ECHO """ & $sParent & "\DeleteInstallFolder.bat""")
        FileWriteLine($hFile, "ECHO End of Batch Script")
        FileWriteLine($hFile, "PAUSE")
        FileClose($hFile)

        ; Run Batch file and exit Configuration App
        Run("""" & $sParent & "\DeleteInstallFolder.bat""")
        Exit
    EndIf

    ; Create Batch file to change extensions when install path stays the same
    if ($g_sInstallPath = $g_sCurrentInstallPath) and ($g_sExtension <> $g_sCurrentExtension) Then
        FileDelete($g_sInstallPath & "\DeleteLeftOverScripts.bat")
        $hFile = FileOpen($g_sInstallPath & "\DeleteLeftOverScripts.bat", $FO_APPEND)
        FileWriteLine($hFile, "@PUSHD %~dp0")
        FileWriteLine($hFile, "@ECHO OFF")
        FileWriteLine($hFile, "ECHO LazyD Charter:")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO This is an automatically created batch file")
        FileWriteLine($hFile, "ECHO which will delete some left over script files")
        FileWriteLine($hFile, "ECHO and will delete itself after running.")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Current Extension: """ & $g_sCurrentExtension & """")
        FileWriteLine($hFile, "ECHO New Extension: """ & $g_sExtension & """")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Changing Drive to """ & $sRoot & """")
        FileWriteLine($hFile, $sRoot)
        FileWriteLine($hFile, "ECHO Changing Directory to """ & $g_sInstallPath & """")
        FileWriteLine($hFile, "CD """ & $g_sInstallPath & """")
        if $sParent = $sRoot then
            FileWriteLine($hFile, "ECHO Batch File: %CD%DeleteLeftOverScripts.bat ")
        Else
            FileWriteLine($hFile, "ECHO Batch File: %CD%\DeleteLeftOverScripts.bat ")
        EndIf
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Waiting for 5 seconds to let script and interpreter")
        FileWriteLine($hFile, "ECHO to shutdown.")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "TIMEOUT 5 >NUL")
        FileWriteLine($hFile, "DEL /F /Q """ & $g_sInstallPath & "\Apps\*." & $g_sCurrentExtension & """")
        FileWriteLine($hFile, "DEL /F /Q """ & $g_sInstallPath & "\DeleteLeftOverScripts.bat""")
        FileClose($hFile)

        ; Run Batch file and exit Configuration App
        Run("""" & $g_sInstallPath & "\DeleteLeftOverScripts.bat""")
        Exit
    EndIf

EndFunc

func Select_Install_Directory()

    ; Changes needed to be done on various controls when user changes the install directory
    Local $sDefaultPath = GUICtrlRead($g_id_inputInstallDirectory)
    Local $sDefaultDrive = StringLeft($sDefaultPath,3)
    Local $g_sInstallPath = FileSelectFolder("Select the main folder to install LazyD Charter to...",$sDefaultDrive,Default,"",@GUI_WinHandle)

    if $g_sInstallPath = "" then
        GUICtrlSetData($g_id_inputInstallDirectory,$sDefaultPath)
        Return
    Else
        if StringRight($g_sInstallPath, 13) = "LazyD Charter" Then
            ; User selected the Default Folder Name
            ; Do Nothing
        Else
            if StringLen($g_sInstallPath) = 3 Then
                ; User selected the root of a drive, append Default Folder name
                $g_sInstallPath &= "LazyD Charter"
            Else
                ; User selected a different folder
                ; Do Nothing
            EndIf
        EndIf
    EndIf

    GUICtrlSetData($g_id_inputInstallDirectory,$g_sInstallPath)

EndFunc

func AutoIT_Check()

    ; Check if AutoIt installation option checkbox is checked
    if _IsChecked($g_id_checkAutoIt) Then
        GUICtrlSetState($g_id_checkRegistry, $GUI_UNCHECKED + $GUI_ENABLE)
    Else
        GUICtrlSetState($g_id_checkRegistry, $GUI_UNCHECKED + $GUI_DISABLE)
        GUICtrlSetState($g_id_inputExtension, $GUI_DISABLE)
        GUICtrlSetState($g_id_lblInputExtension, $GUI_DISABLE)
    EndIf

EndFunc

func Registry_Check()

    ; Check if Registry changes installation option checkbox is checked
    if _IsChecked($g_id_checkRegistry) Then
        GUICtrlSetState($g_id_inputExtension, $GUI_ENABLE)
        GUICtrlSetState($g_id_lblInputExtension, $GUI_ENABLE)
    Else
        GUICtrlSetState($g_id_inputExtension, $GUI_DISABLE)
        GUICtrlSetState($g_id_lblInputExtension, $GUI_DISABLE)
    EndIf

EndFunc

func Info_File()

    ; Open Configuration Info.rtf in default viewer
    ShellExecute($g_sInstallPath & "\Apps\Text Files\Configuration Info.rtf")

EndFunc

func _IsChecked($idControlID)

    ; Check if CheckBox is checked
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED

EndFunc

func _IsEnabled($idControlID)

    ; Check for Control's State (ENABLED/DISABLED)
    if BitAnd(GUICtrlGetState($idControlID), $GUI_ENABLE) = $GUI_ENABLE Then
        Return True
    Else
        Return False
    EndIf

Endfunc

func Quit_App()

    ; Close App Window, Exit App
    GUIDelete(@GUI_WinHandle)
    Exit

EndFunc

 

 

3. CH_Uninstaller:

Reverts the changes made (delete appdata folder, delete registry association, delete install folder) with options to keep 2 folders (in my case).

image.png.85017b91ac534128d149e723ff37a400.png

Also creates a batch file since AutoIt.exe and uninstaller script would be running at the time.

Spoiler
#NoTrayIcon
#RequireAdmin

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_type=a3x
#AutoIt3Wrapper_Outfile=CH_Install\Scripts\CH_Uninstaller.a3x
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_Res_Description=Script file for uninstalling LazyD Charter
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_ProductName=LazyD Charter
#AutoIt3Wrapper_Res_ProductVersion=1.0.0.0
#AutoIt3Wrapper_Res_CompanyName=LazyD is not a company
#AutoIt3Wrapper_Res_LegalCopyright=None
#AutoIt3Wrapper_Res_LegalTradeMarks=None
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

#include <LazyD Charter Color Theme.au3>

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("GUIOnEventMode", 1)

Global $g_sIniFile = @AppDataDir & "\LazyD Charter\LazyD Charter.ini"

Global $g_sInstallPath = IniRead($g_sIniFile,"Install","Install_Path","")
Global $g_sAppData = IniRead($g_sIniFile,"Install","AppData_Checked","")
Global $g_sAutoIt = IniRead($g_sIniFile,"Install","AutoIt_Checked","")
Global $g_sRegistry = IniRead($g_sIniFile,"Install","Registry_Checked","")
Global $g_sExtension = IniRead($g_sIniFile,"Install","Extension","")
Global $g_sRegHive = IniRead($g_sIniFile,"Install","Registry_Hive","")

GLobal $g_idCheckKeepSamples
Global $g_idCheckKeepSongs

Create_App_Window()

func Create_App_Window()

    ; Create the App Window
    GUICreate("LazyD Charter Uninstaller", 800, 320, -1, -1)
    GUISetIcon($g_sInstallPath & "\Apps\ChResource\LazyD_Ch.ico")
    GUISetOnEvent($GUI_EVENT_CLOSE, "Quit_App")
    GUISetBkColor($COL_APP_WINDOW)

    ; Create Dummy Button to intercept Return key press
    GUICtrlCreateButton("",0,0,0,0,-1,-1)
    GUICtrlSetBkColor(-1, $COL_APP_WINDOW)
    GUICtrlSetFont(-1, 14, 400, 0, "")

    ; Create the General Info label
    GUICtrlCreateLabel("The following changes were made to your PC while installing LazyD Charter. I will revert the changes made.", 15, 35, 775, 50)
    GUICtrlSetFont(-1, 14, 400, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    ; Create the AppData Info label
    GUICtrlCreateLabel("[AppData]:", 10, 120, 90, 30, $SS_RIGHT)
    GUICtrlSetFont(-1, 12, 400, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    GUICtrlCreateLabel("No Changes", 130, 120, 650, 30)
    GUICtrlSetFont(-1, 12, 400, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_GROUP)
    if $g_sAppData = "True" then GUICtrlSetData(-1, """AppData\Roaming\LazyD Charter"" folder was created")

    ; Create the Install Path Info label
    GUICtrlCreateLabel("[Install Path]:", 10, 160, 90, 30, $SS_RIGHT)
    GUICtrlSetFont(-1, 12, 400, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    GUICtrlCreateLabel("No Changes", 130, 160, 650, 30)
    GUICtrlSetFont(-1, 12, 400, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_GROUP)
    GUICtrlSetData(-1, """" & $g_sInstallPath & """ folder was created")

    ; Create the Registry Info label
    GUICtrlCreateLabel("[Registry]:", 10, 200, 90, 30, $SS_RIGHT)
    GUICtrlSetFont(-1, 12, 400, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    GUICtrlCreateLabel("No Changes", 130, 200, 650, 30)
    GUICtrlSetFont(-1, 12, 400, 0, "")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $COL_GROUP)
    if $g_sRegistry = "True" then GUICtrlSetData(-1, """" & $g_sRegHive & "." & $g_sExtension & """ key and sub-keys were added")

    ; Create the Uninstall Button
    GUICtrlCreateButton("UNINSTALL", 15, 255, 110, 50)
    GUICtrlSetTip(-1, "Uninstall LazyD Charter")
    GUICtrlSetOnEvent(-1, "Uninstall")
    GUICtrlSetBkColor(-1, $COL_BTN_DEFAULT)
    GUICtrlSetFont(-1, 14, 400, 0, "")

    ; Create the QUIT Button
    GUICtrlCreateButton("QUIT", 138, 255, 110, 50)
    GUICtrlSetTip(-1, "Exit without uninstalling.")
    GUICtrlSetOnEvent(-1, "Quit_App")
    GUICtrlSetBkColor(-1, $COL_BTN_QUIT)
    GUICtrlSetFont(-1, 16, 400, 0, "")

    ; Create Keep Samples Folder CheckBox
    $g_idCheckKeepSamples = GUICtrlCreateCheckbox("Keep Samples Folder", 270, 255, 500, 25)
    GUICtrlSetBkColor(-1, $COL_GROUP)
    GUICtrlSetFont(-1, 14, 400, 0, "")

    ; Create Keep Songs Folder CheckBox
    $g_idCheckKeepSongs = GUICtrlCreateCheckbox("Keep Songs Folder", 270, 280, 500, 25)
    GUICtrlSetBkColor(-1, $COL_GROUP)
    GUICtrlSetFont(-1, 14, 400, 0, "")

    ; Create Graphic GUI Controls (for eye candy)
    GUICtrlCreateGraphic(10, 45, 780, 50) ; 2 pxs high horizontal line
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    GUICtrlCreateGraphic(10, 110, 100, 120) ; 2 pxs high horizontal line
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    GUICtrlCreateGraphic(120, 110, 670, 120) ; 2 pxs high horizontal line
    GUICtrlSetBkColor(-1, $COL_GROUP)

    GUICtrlCreateGraphic(10, 250, 780, 60) ; 2 pxs high horizontal line
    GUICtrlSetBkColor(-1, $COL_GROUP)

    GUICtrlCreateGraphic(10, 240, 780, 3) ; 2 pxs high horizontal line
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    GUICtrlCreateGraphic(10, 100, 780, 3) ; 2 pxs high horizontal line
    GUICtrlSetBkColor(-1, $COL_GROUP_HEADER)

    ; Display the App Window
    GUISetState(@SW_SHOW)

    ; Message Loop
    While 1
        Sleep(100)
    WEnd

EndFunc

func Uninstall()

    Local $iAppDataDelSuccess
    Local $iInstallDirDelSuccess = 1
    ;Local $iDirRemove

    Local $sRegDelString = "Registry: No actions taken"
    Local $g_sAppDataDelString = "AppData Folder: No actions taken"
    Local $sInstallDirString = "Install Directory: No actions taken"

    ; Delete Registry
    RegRead($g_sRegHive & "."  & $g_sExtension,"")
    if @error <= 0 then
        ; Key already exists, check if it is a LazyD Charter key
        if RegRead($g_sRegHive & "." & $g_sExtension,"Check") = """LazyD Charter""" Then
            ; This key was created by LazyD Charter before, delete
            RegDelete($g_sRegHive & "." & $g_sExtension)
            $sRegDelString = (@Error = 0) ? ("Registry: Key was successfully deleted") : ("Registry: WARNING! Unable to delete """ & $g_sRegHive & "." & $g_sExtension & """!")
        EndIf
    EndIf

    ; Delete AppData
    $iAppDataDelSuccess = DirRemove(@AppDataDir & "\LazyD Charter", $DIR_REMOVE)
    $g_sAppDataDelString = ($iAppDataDelSuccess = 1) ? ("AppData Folder: Deleted successfully") : ("AppData Folder: WARNING! Unable to delete """ & @AppDataDir & "\LazyD Charter""!")

    ; Delete Folders (keep Samples and/or Songs folders if checked)
    $iInstallDirDelSuccess = DirRemove($g_sInstallPath & "\Assets", $DIR_REMOVE) * $iInstallDirDelSuccess
    $iInstallDirDelSuccess = DirRemove($g_sInstallPath & "\Project", $DIR_REMOVE) * $iInstallDirDelSuccess
    $iInstallDirDelSuccess = DirRemove($g_sInstallPath & "\Temp", $DIR_REMOVE) * $iInstallDirDelSuccess
    if not (_IsChecked($g_idCheckKeepSamples)) Then $iInstallDirDelSuccess = DirRemove($g_sInstallPath & "\Samples", $DIR_REMOVE) * $iInstallDirDelSuccess
    if not (_IsChecked($g_idCheckKeepSongs)) then $iInstallDirDelSuccess = DirRemove($g_sInstallPath & "\Songs", $DIR_REMOVE) * $iInstallDirDelSuccess
    ;$iInstallDirDelSuccess = DirRemove($g_sInstallPath & "\Apps", $DIR_REMOVE)

    ; if any of the deletion steps above is unsuccessful, result would be 0
    $sInstallDirString = ($iInstallDirDelSuccess = 1) ? ("Install Folder: All SubFolders deleted successfully") : ("Install Folder: WARNING! Unable to delete some SubFolders! " & $iInstallDirDelSuccess)

    Local $sRoot = StringLeft($g_sInstallPath, 2)
    Local $sParent = StringTrimRight($g_sInstallPath, StringLen($g_sInstallPath) - StringInStr($g_sInstallPath, "\", 0, -1) + 1)
    Local $hFile

    ; Run Batch to Delete Apps if either one of the CheckBoxes are checked
    if (_IsChecked($g_idCheckKeepSamples) or _IsChecked($g_idCheckKeepSongs)) Then
        FileDelete($g_sInstallPath & "\DeleteAppsFolder.bat")
        $hFile = FileOpen($g_sInstallPath & "\DeleteAppsFolder.bat", $FO_APPEND)
        FileWriteLine($hFile, "@PUSHD %~dp0")
        FileWriteLine($hFile, "@ECHO OFF")
        FileWriteLine($hFile, "ECHO LazyD Charter:")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO This is an automatically created batch file")
        FileWriteLine($hFile, "ECHO which will remove the remaining APPS folder")
        FileWriteLine($hFile, "ECHO and will delete itself after running.")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO " & $sRegDelString)
        FileWriteLine($hFile, "ECHO " & $g_sAppDataDelString)
        FileWriteLine($hFile, "ECHO " & $sInstallDirString)
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        if _IsChecked($g_idCheckKeepSamples) then FileWriteLine($hFile, "ECHO SAMPLES SubDirectory was skipped per user choice")
        if _IsChecked($g_idCheckKeepSongs) then FileWriteLine($hFile, "ECHO SONGS SubDirectory was skipped per user choice")
        if _IsChecked($g_idCheckKeepSamples) or _IsChecked($g_idCheckKeepSongs) then FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Changing Drive to """ & $sRoot & """")
        FileWriteLine($hFile, $sRoot)
        FileWriteLine($hFile, "ECHO Changing Directory to """ & $g_sInstallPath & """")
        FileWriteLine($hFile, "CD """ & $g_sInstallPath & """")
        FileWriteLine($hFile, "ECHO Batch File: %CD%\DeleteAppsFolder.bat ")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Please confirm correct directory and")
        FileWriteLine($hFile, "ECHO Press ""Y"" to delete APPS folder")
        FileWriteLine($hFile, "TIMEOUT 5 >NUL")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Waiting for 5 seconds to let script and interpreter")
        FileWriteLine($hFile, "ECHO to shutdown.")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "CHOICE /C YX /N /M ""Continue? (Press ""X"" to QUIT)""")
        FileWriteLine($hFile, "IF ERRORLEVEL 2 GOTO QUIT")
        FileWriteLine($hFile, "IF ERRORLEVEL 1 @ECHO OFF")
        FileWriteLine($hFile, "IF EXIST """ & $g_sInstallPath & "\Apps"" RMDIR /Q /S """ & $g_sInstallPath & "\Apps""")
        FileWriteLine($hFile, "IF EXIST """ & $g_sInstallPath & "\DeleteAppsFolder.bat"" DEL /F /Q """ & $g_sInstallPath & "\DeleteAppsFolder.bat""")
        FileWriteLine($hFile, ":QUIT")
        FileWriteLine($hFile, "ECHO ------------------------------------------------")
        FileWriteLine($hFile, "ECHO Please re-run this batch script to complete deletion")
        FileWriteLine($hFile, "ECHO """ & $sParent & "\DeleteAppsFolder.bat""")
        FileWriteLine($hFile, "ECHO End of Batch Script")
        FileWriteLine($hFile, "PAUSE")
        FileClose($hFile)

        Run("""" & $g_sInstallPath & "\DeleteAppsFolder.bat""") ; ,@SW_HIDE add after file name

        Exit
    EndIf

    ; Run Batch to Delete $g_sInstallPath if none of the CheckBoxes are checked
    FileDelete($sParent & "\DeleteInstallFolder.bat")
    $hFile = FileOpen($sParent & "\DeleteInstallFolder.bat", $FO_APPEND)
    FileWriteLine($hFile, "@PUSHD %~dp0")
    FileWriteLine($hFile, "@ECHO OFF")
    FileWriteLine($hFile, "ECHO LazyD Charter:")
    FileWriteLine($hFile, "ECHO ------------------------------------------------")
    FileWriteLine($hFile, "ECHO This is an automatically created batch file")
    FileWriteLine($hFile, "ECHO which will remove the remaining Install Folder")
    FileWriteLine($hFile, "ECHO and will delete itself after running.")
    FileWriteLine($hFile, "ECHO ------------------------------------------------")
    FileWriteLine($hFile, "ECHO " & $sRegDelString)
    FileWriteLine($hFile, "ECHO " & $g_sAppDataDelString)
    FileWriteLine($hFile, "ECHO " & $sInstallDirString)
    FileWriteLine($hFile, "ECHO ------------------------------------------------")
    FileWriteLine($hFile, "ECHO Changing Drive to """ & $sRoot & """")
    FileWriteLine($hFile, $sRoot)
    FileWriteLine($hFile, "ECHO Changing Directory to """ & $sParent & """")
    FileWriteLine($hFile, "CD """ & $sParent & """")
    if $sParent = $sRoot then
        FileWriteLine($hFile, "ECHO Batch File: %CD%DeleteInstallFolder.bat ")
    Else
        FileWriteLine($hFile, "ECHO Batch File: %CD%\DeleteInstallFolder.bat ")
    EndIf
    FileWriteLine($hFile, "ECHO ------------------------------------------------")
    FileWriteLine($hFile, "ECHO Please confirm correct directory and")
    FileWriteLine($hFile, "ECHO Press ""Y"" to delete Install Folder")
    FileWriteLine($hFile, "TIMEOUT 5 >NUL")
    FileWriteLine($hFile, "ECHO ------------------------------------------------")
    FileWriteLine($hFile, "ECHO Waiting for 5 seconds to let script and interpreter")
    FileWriteLine($hFile, "ECHO to shutdown.")
    FileWriteLine($hFile, "ECHO ------------------------------------------------")
    FileWriteLine($hFile, "CHOICE /C YX /N /M ""Continue? (Press ""X"" to QUIT)""")
    FileWriteLine($hFile, "IF ERRORLEVEL 2 GOTO QUIT")
    FileWriteLine($hFile, "IF ERRORLEVEL 1 @ECHO OFF")
    FileWriteLine($hFile, "IF EXIST """ & $g_sInstallPath & """ RMDIR /Q /S """ & $g_sInstallPath & """")
    FileWriteLine($hFile, "IF EXIST """ & $sParent & "\DeleteInstallFolder.bat"" DEL /F /Q """ & $sParent & "\DeleteInstallFolder.bat""")
    FileWriteLine($hFile, ":QUIT")
    FileWriteLine($hFile, "ECHO ------------------------------------------------")
    FileWriteLine($hFile, "ECHO Please re-run this batch script to complete deletion")
    FileWriteLine($hFile, "ECHO """ & $sParent & "\DeleteInstallFolder.bat""")
    FileWriteLine($hFile, "ECHO End of Batch Script")
    FileWriteLine($hFile, "PAUSE")
    FileClose($hFile)

    Run("""" & $sParent & "\DeleteInstallFolder.bat""")

    Exit

EndFunc

func _IsChecked($idControlID)

    ; Check if CheckBox is checked
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED

EndFunc

func Quit_App()

    ; Close App Window, Exit App
    GUIDelete(@GUI_WinHandle)
    Exit

EndFunc

 

 

CH_Configuration_Final.au3 CH_Uninstaller_Final.au3

Edited by GokAy
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...