Question

I am creating a basic installer in autoit. After compiling the script, I got the error Unable to open the script file when trying to run it.

The Script:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\Resources\unnamed.ico
#AutoIt3Wrapper_Outfile=..\..\..\Desktop\Minecraft Server Launcher Installer.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe, rt_rcdata, Launcher
#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt, rt_rcdata, Licence
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <resources.au3>
$msgbox1 = MsgBox(36, "Minecraft Server Launcher Installer", "Do you want to install the Launcher?")
If $msgbox1 = 6 Then
    GUICreate("Minecraft Server Launcher Installer", 373, 325)
    GUICtrlCreateLabel("Read the following agreement. Scroll down to view the rest of the agreement.", 10, 10)
    GUICtrlCreateEdit(_ResourceGetAsString("Licence"), 10, 51, 350, 191, $WS_VSCROLL + $ES_READONLY + $ES_MULTILINE)
    GUICtrlCreateLabel("Do you accept all the terms of the license agreement? Selecting No" & @CRLF & "cancels the installation. You must accept the agreement to install.", 10, 250)
    $YES = GUICtrlCreateButton("Yes", 204, 296, 75, 23)
    $NO = GUICtrlCreateButton("No", 290, 296, 75, 23)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $YES
                Choose_Loc()
            Case $NO
                Exit
        EndSwitch
    WEnd
EndIf
Func Choose_Loc()
    GUIDelete()
    GUICreate("Minecraft Server Launcher Installer", 363, 108)
    GUICtrlCreateLabel("Choose Install Location", 10, 5)
    $INPUT = GUICtrlCreateInput("C:\Program Files (x86)\KnarCraft\Minecraft Server Launcher", 10, 40, 255, 22)
    $BROWSE = GUICtrlCreateButton("Browse...", 275, 40, 80, 23)
    $CANCEL = GUICtrlCreateButton("Cancel", 275, 75, 80, 23)
    $OK = GUICtrlCreateButton("OK", 185, 75, 80, 23)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $CANCEL
                Exit
            Case $OK
                Install($INPUT)
            Case $BROWSE
                $FOLDER = FileSelectFolder("Choose Install Location...", "", 7)
                If Not $FOLDER = "" Then GUICtrlSetData($INPUT, $FOLDER)
        EndSwitch
    WEnd
EndFunc   ;==>Choose_Loc
Func Install($INPUT)
    _ResourceSaveToFile(GUICtrlRead($INPUT) & "\Bungee Minecraft Server Launcher.exe", "Launcher", $RT_RCDATA, 0, 1)
    FileCreateShortcut(GUICtrlRead($INPUT) & "\Bungee Minecraft Server Launcher.exe", @DesktopDir & "\Bungee Minecraft Server Launcher.ink")
    GUIDelete()
    If Not @error Then
        MsgBox(36, "Finished", "Installation completed with no errors. Please enjoy your new software.")
    Else
        MsgBox(16, "Finished", "The installation was interrupted by an error and the software may not work.")
    EndIf
    Exit
EndFunc   ;==>Install

I know that it's this line that creates the error:

#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt, rt_rcdata, Licence

But I don't know why or how to fix it. I had the same problem with:

#AutoIt3Wrapper_Res_File_Add=C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe, rt_rcdata, Launcher

I know that it's the Res_Add line because if I remove that line, the error will disappear.

Was it helpful?

Solution

I stopped using the res file stuff, and switched to FileInstall() :

FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe",@TEMPDIR & "\Bungee Minecraft Server Launcher.exe")
FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt",@TEMPDIR & "\Licence.txt")

Then you just use the file. Also, your paths are different:

Autoit\{BUNGEE MINECRAFT SERVER LAUNCHER.EXE}
Autoit\Bungee Server Launcher\{LICENCE.TXT}

Open up a command prompt and check the full path :

cd C:\Users\Kristian\SkyDrive\Autoit & dir licence.txt /b /s

Another solution would be to make the text file a variable. Open the file in SciTE, replace the regular expression ^(.*)$ by "$1" & @CRLF &_, then copy and paste it into the script.

Here is the code with FileInstall() and a couple fixes. I tested with different paths, and it worked. Functions should be self-contained, so I made them mostly internal. Ideally, you'd have them do a Return SetError() and put the MsgBox() outside the function call.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\Resources\unnamed.ico
#AutoIt3Wrapper_Outfile=..\..\..\Desktop\Minecraft Server Launcher Installer.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

; Target path of temp files - you should add code to delete these when done
$LAUNCHPATH = @TempDir & "\BMSLauncher.exe"
$LICENCEPATH = @TempDir & "\BMSLicence.txt"

; Check if the install files exist, and if not, output to console
$EXIST1 = FileExists("C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe")
$EXIST2 = FileExists("C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt")

If Not $EXIST1 Or Not $EXIST2 Then
    ConsoleWrite("ERROR! FILE(S) NOT FOUND!" & @CRLF)
    If Not $EXIST1 Then ConsoleWrite("LAUNCHER FILE NOT FOUND!" & @CRLF)
    If Not $EXIST2 Then ConsoleWrite("LICENCE FILE NOT FOUND!" & @CRLF)
EndIf

; Copy files to destination
FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Minecraft Server Launcher.exe", $LAUNCHPATH, 1)
FileInstall("C:\Users\Kristian\SkyDrive\Autoit\Bungee Server Launcher\Licence.txt", $LICENCEPATH, 1)

; Read licence file to variable
$LICENCE = FileRead($LICENCEPATH)

$msgbox1 = MsgBox(36, "Minecraft Server Launcher Installer", "Do you want to install the Launcher?")

If $msgbox1 = 6 Then
    $EULAGUI = GUICreate("Minecraft Server Launcher Installer", 373, 325)
    GUICtrlCreateLabel("Read the following agreement. Scroll down to view the rest of the agreement.", 10, 10)
    GUICtrlCreateEdit($LICENCE, 10, 51, 350, 191, $WS_VSCROLL + $ES_READONLY + $ES_MULTILINE)
    GUICtrlCreateLabel("Do you accept all the terms of the license agreement? Selecting No" & @CRLF & "cancels the installation. You must accept the agreement to install.", 10, 250)
    $YES = GUICtrlCreateButton("Yes", 204, 296, 75, 23)
    $NO = GUICtrlCreateButton("No", 290, 296, 75, 23)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE, $NO
                Exit
            Case $YES
                GUIDelete($EULAGUI)
                Choose_Loc()
        EndSwitch
    WEnd
EndIf

Func Choose_Loc()
    Local $LOCGUI = GUICreate("Minecraft Server Launcher Installer", 363, 108)
    GUICtrlCreateLabel("Choose Install Location", 10, 5)
    $INPUT = GUICtrlCreateInput("C:\Program Files (x86)\KnarCraft\Minecraft Server Launcher", 10, 40, 255, 22)
    $BROWSE = GUICtrlCreateButton("Browse...", 275, 40, 80, 23)
    $CANCEL = GUICtrlCreateButton("Cancel", 275, 75, 80, 23)
    $OK = GUICtrlCreateButton("OK", 185, 75, 80, 23)
    GUISetState(@SW_SHOW)
    While 1
        ; you could make the switch guigetmsg() without $msg, idk what's best practice here
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE, $CANCEL
                Exit
            Case $OK
                Local $INSTALLPATH = GUICtrlRead($INPUT)
                If FileExists($INSTALLPATH) Then
                    GUIDelete($LOCGUI)
                    Install($LAUNCHPATH, $INSTALLPATH)
                EndIf
            Case $BROWSE
                $FOLDER = FileSelectFolder("Choose Install Location...", "", 7)
                If Not $FOLDER = "" Then GUICtrlSetData($INPUT, $FOLDER)
        EndSwitch
    WEnd
EndFunc   ;==>Choose_Loc

Func Install($FPATH, $IPATH)
    Local $ERROR
    ; you should check for a trailing slash on the $IPATH input
    $IPATH &= "\Bungee Minecraft Server Launcher.exe"
    FileCopy($FPATH, $IPATH)
    $ERROR = @error
    FileCreateShortcut($IPATH, @DesktopDir & "\Bungee Minecraft Server Launcher.ink")
    If Not @error And Not $ERROR Then
        MsgBox(64, "Finished", "Installation completed with no errors. Please enjoy your new software.")
    Else
        MsgBox(16, "Finished", "The installation was interrupted by an error and the software may not work.")
    EndIf
    Exit
EndFunc   ;==>Install

OTHER TIPS

Make sure the file is in the same dir as the script and Try:

#AutoIt3Wrapper_Res_File_Add=Licence.txt, rt_rcdata, Licence

If you still have problems, try to turn off UPX.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top