我需要设置我的安装目录

时间:2016-03-08 04:41:05

标签: nsis

Noob问题!

所以到目前为止我已经编写了这段代码

Example:
var query = { fields: {password: false} }
Model.find(query, function()
{
});

这些适用于学校计算机,因此我希望用户能够在他们选择的文件夹中安装exe。 (学校限制C盘) 我试过了

; NSIS packaging/install script
; Docs: http://nsis.sourceforge.net/Docs/Contents.html

!include LogicLib.nsh
!include nsDialogs.nsh

; --------------------------------
; Variables
; --------------------------------

!define dest "{{dest}}"
!define src "{{src}}"
!define name "{{name}}"
!define productName "{{productName}}"
!define author "{{author}}"
!define version "{{version}}"
!define icon "{{icon}}"
!define setupIcon "{{setupIcon}}"
!define banner "{{banner}}"

!define exec "{{productName}}.exe"

!define regkey "Software\${productName}"
!define uninstkey "Software\Microsoft\Windows\CurrentVersion\Uninstall\${productName}"

!define uninstaller "uninstall.exe"

; --------------------------------
; Installation
; --------------------------------

Unicode true
SetCompressor /SOLID lzma

Name "${productName}"
Icon "${setupIcon}"
OutFile "${dest}"
;InstallDir "$PROGRAMFILES\${productName}"
InstallDir $PROGRAMFILES\WhapTk
DirText "This will install WhapTk on your computer. Choose a directory"
InstallDirRegKey HKLM "${regkey}" ""

RequestExecutionLevel admin
CRCCheck on
SilentInstall normal

XPStyle on
ShowInstDetails nevershow
AutoCloseWindow false
WindowIcon off

Caption "${productName} Setup"
; Don't add sub-captions to title bar
SubCaption 3 " "
SubCaption 4 " "

Page custom welcome
Page instfiles

Var Image
Var ImageHandle

Function .onInit

    ; Extract banner image for welcome page
    InitPluginsDir
    ReserveFile "${banner}"
    File /oname=$PLUGINSDIR\banner.bmp "${banner}"

FunctionEnd

; Custom welcome page
Function welcome

    nsDialogs::Create 1018

    ${NSD_CreateLabel} 185 1u 210 100% "Welcome to ${productName} version ${version} installer.$\r$\n$\r$\nClick install to begin."

    ;InstallDir $PROGRAMFILES\WhapTk

    ${NSD_CreateBitmap} 0 0 170 210 ""
    Pop $Image
    ${NSD_SetImage} $Image $PLUGINSDIR\banner.bmp $ImageHandle

    SetOutPath $INSTDIR

    nsDialogs::Show

    ${NSD_FreeImage} $ImageHandle

FunctionEnd

; Installation declarations
Section "Install"

    WriteRegStr HKLM "${regkey}" "Install_Dir" "$INSTDIR"
    WriteRegStr HKLM "${uninstkey}" "DisplayName" "${productName}"
    WriteRegStr HKLM "${uninstkey}" "DisplayIcon" '"$INSTDIR\icon.ico"'
    WriteRegStr HKLM "${uninstkey}" "UninstallString" '"$INSTDIR\${uninstaller}"'
    WriteRegStr HKLM "${uninstkey}" "Publisher" "${author}"
    WriteRegStr HKLM "${uninstkey}" "DisplayVersion" "${version}"

    ; Remove all application files copied by previous installation
    RMDir /r "$INSTDIR"


    ; Include all files from /build directory
    File /r "${src}\*"

    ; Create start menu shortcut
    SetShellVarContext all
    CreateShortCut "$SMPROGRAMS\${productName}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\icon.ico"
    ; Create desktop shortcut
    CreateShortCut "$DESKTOP\${productName}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\icon.ico"

    WriteUninstaller "${uninstaller}"

SectionEnd

; --------------------------------
; Uninstaller
; --------------------------------

ShowUninstDetails nevershow

UninstallCaption "Uninstall ${productName}"
UninstallText "Don't like ${productName} anymore? Hit uninstall button."
UninstallIcon "${icon}"

UninstPage custom un.confirm un.confirmOnLeave
UninstPage instfiles

Var RemoveAppDataCheckbox
Var RemoveAppDataCheckbox_State

; Custom uninstall confirm page
Function un.confirm

    nsDialogs::Create 1018

    ${NSD_CreateLabel} 1u 1u 100% 24u "If you really want to remove ${productName} from your computer press uninstall button."

    ${NSD_CreateCheckbox} 1u 35u 100% 10u "Remove also my ${productName} personal data"
    Pop $RemoveAppDataCheckbox

    nsDialogs::Show

FunctionEnd

Function un.confirmOnLeave

    ; Save checkbox state on page leave
    ${NSD_GetState} $RemoveAppDataCheckbox $RemoveAppDataCheckbox_State

FunctionEnd

; Uninstall declarations
Section "Uninstall"

    DeleteRegKey HKLM "${uninstkey}"
    DeleteRegKey HKLM "${regkey}"

    SetShellVarContext all
    Delete "$SMPROGRAMS\${productName}.lnk"
    ; Remove desktop shortcut
    Delete "$DESKTOP\${productName}.lnk"
    ; Remove whole directory from Program Files
    RMDir /r "$INSTDIR"

    ; Remove also appData directory generated by your app if user checked this option
    ${If} $RemoveAppDataCheckbox_State == ${BST_CHECKED}
        RMDir /r "$APPDATA\${productName}"
    ${EndIf}

SectionEnd

但拒绝工作:((安装程序工作正常,只是我不能选择我的目录) 请告诉我我做错了什么! 提前谢谢!

2 个答案:

答案 0 :(得分:1)

$InstDir属性在执行任何代码之前安装程序启动时初始化StrCpy $InstDir "c:\some\new\path"变量。

如果您想允许最终用户更改安装目录,那么您通常会添加目录页面,但您也可以在自定义页面或InstFiles页面之前的任何其他位置执行此操作;只需使用类似File的内容。

在使用SetOutPath指令提取文件之前,必须使用File指令。它创建目录并设置OutFile "MySetup.exe" InstallDir "$ProgramFiles\MyApp" ; $InstDir default value RequestExecutionLevel Admin Page Directory ; This page might change $InstDir Page InstFiles Section SetOutPath "$InstDir" ; This basically does StrCpy $OutDir $InstDir + CreateDirectory $OutDir File "MyApp.exe" ; This will extract as "$OutDir\MyApp.exe" SectionEnd 指令的目的地。

最小安装程序可能如下所示:

SetOutPath

您的示例代码在自定义欢迎页面中调用$InstDir,此时InstallDir只有SetOutPath的值,之后您再也不会再调用html,body { width: 100%; height: 100%; margin: 0px; padding: 0px; overflow-x: hidden; }。< / p>

答案 1 :(得分:0)

您需要为选择对话框指定其他Page

Page directory
Page instfiles

请注意,声明这些网页的顺序非常重要,通常instfiles会持久。