自动无法打开脚本文件[关闭]

问题描述 投票:-1回答:2

我正在autoit中创建一个基本的安装程序。编译脚本后,我收到错误在尝试运行时无法打开脚本文件。

剧本:

#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

我知道这条线会产生错误:

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

但我不知道为什么或如何解决它。我有同样的问题:

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

我知道它是Res_Add行,因为如果删除该行,错误将消失。

autoit
2个回答
-1
投票

我停止使用res文件的东西,并切换到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")

然后你只需使用该文件。此外,您的路径是不同的:

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

打开命令提示符并检查完整路径:

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

另一种解决方案是使文本文件成为变量。在SciTE中打开文件,用^(.*)$替换正则表达式"$1" & @CRLF &_,然后将其复制并粘贴到脚本中。

这是FileInstall()的代码和几个修复程序。我测试了不同的路径,它工作。函数应该是自包含的,所以我把它们作为内部函数。理想情况下,你让他们做一个Return SetError()并将MsgBox()放在函数调用之外。

#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

-1
投票

确保该文件与脚本位于同一目录中并尝试:

#AutoIt3Wrapper_Res_File_Add=Licence.txt, rt_rcdata, Licence

如果仍有问题,请尝试关闭UPX。

© www.soinside.com 2019 - 2024. All rights reserved.