2012-01-02 12 views
5

Sto creando un programma di installazione che utilizza NSIS. Questo programma di installazione installa in realtà due programmi in due diverse directory nello stesso programma di installazione. Lo sto facendo usando le pagine dell'interfaccia utente moderna (MUI) e semplicemente chiamando MUI_PAGE_DIRECTORY due volte specificando diversi parametri di partenza e catturando la directory nella macro LEAVE. Quello che mi chiedo è, posso in qualche modo chiamare InstallDir in una funzione, o impostare il valore di popolamento della directory automatica in una funzione? O forse anche chiamare una funzione dopo che è stato restituito il pulsante di navigazione?Impostare il valore di InstallDir in una funzione o impostare il valore del popolamento automatico in qualche modo?

Il motivo per cui voglio farlo è quando l'utente fa clic sul pulsante Sfoglia in una delle due pagine di directory, dopo aver selezionato una directory, verrà aggiunto il nome della directory finnal specificata in InstallDir.

Per esempio: valore InstallDir per il programma 1: c: \ client valore InstallDir per il programma 2: c: \ program files \ server

clic degli utenti di navigare sul programma 1 e sceglie c: \ temp la risultante percorso è c: \ temp \ client

clic degli utenti di navigare sul programma 2 e sceglie c: \ qualunque sia il percorso risultante è c: \ qualunque server di

\ Per riferimento qui sono il codice snipits di quello che ho che funziona, ma non si occupa del comportamento del pulsante di ricerca dell'appendice automatico:

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ClientDirectoryLeave 
!insertmacro MUI_PAGE_DIRECTORY 

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ServerDirectoryLeave 
!insertmacro MUI_PAGE_DIRECTORY 

; Setup the page display for the client install page 
Function ShowPageClient 
    !insertmacro MUI_HEADER_TEXT "Client" "Client" 
    !insertmacro MUI_INNERDIALOG_TEXT 1006 "Client" 

    ; setup intal directory 
    Push $0 
    StrCpy $0 $PROGRAMFILES 2 # 
    ; CLIENT_FOLDER_NAME is defined as a folder, but this would basicaly 
    ; result in C:\Client as the first 2 characters of $PROGRAMFILES 
    ; is the hard drive with program files installed on it 
    StrCpy $INSTDIR "$0\${CLIENT_FOLDER_NAME}" 
    Pop $0 

    ; set the inital value of the directory text box 
    !insertmacro MUI_INNERDIALOG_TEXT 1019 $INSTDIR 

    ; find and disable the directory selection box 
    ; We do not want users to type in this box 
    FindWindow $R0 "#32770" "" $HWNDPARENT 
    GetDlgItem $R1 $R0 1019 ;Text Box 
    EnableWindow $R1 0 
FunctionEnd 


; Setup the page display for the server install location page 
Function ShowPageServer 
    !insertmacro MUI_HEADER_TEXT "Server" "Server" 
    !insertmacro MUI_INNERDIALOG_TEXT 1006 "Server" 

    ; setup intal directory 
    ; SERVER_FOLDER_NAME is defined as a folder, but this would basicaly 
    ; result in C:\Program Files\Server 
    StrCpy $INSTDIR "$PROGRAMFILES\${SERVER_FOLDER_NAME}" 

    ; set the inital value of the directory text box 
    !insertmacro MUI_INNERDIALOG_TEXT 1019 $INSTDIR 

    ; find and disable the directory selection box 
    ; We do not want users to type in this box 
    FindWindow $R0 "#32770" "" $HWNDPARENT 
    GetDlgItem $R1 $R0 1019 ;Text Box 
    EnableWindow $R1 0 

FunctionEnd 

Nota: posso fare il lavoro pulsante Sfoglia per una delle pagine di directory, ma poi quando sono nella seconda pagina, l'auto popolare auto attuale popola in modo non corretto

risposta

4

Ok ho finalmente capito su. Fondamentalmente esiste una funzione chiamata a "verificare" il percorso dopo aver cliccato sul pulsante di navigazione. Ho legato in questa funzione un allegato il manuale di directory, se necessario. Per fare questo ho creato una nuova variabile e metterlo in una funzione chiamata quando la pagina è visualizzata come segue:

; Client Directory 
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ShowPageClient 
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ClientDirectoryLeave 
!insertmacro MUI_PAGE_DIRECTORY 

; Setup the page display for the client install page 
Function ShowPageClient 
    ; setup intal directory 
    Push $0 
    StrCpy $0 $PROGRAMFILES 2 # 
    StrCpy $INSTDIR "$0\${CLIENT_FOLDER_NAME}" 
    Pop $0 

    !insertmacro MUI_INNERDIALOG_TEXT 1019 $INSTDIR 

    FindWindow $R0 "#32770" "" $HWNDPARENT 
    GetDlgItem $R1 $R0 1019 ;Text Box 
    EnableWindow $R1 0 

    ; Setup the client or server variable to indicate that 
    ; we're in the client install part to signal the .onVerifyInstDir function 
    ; to put the correct directory 
    StrCpy $CLIENT_OR_SERVER "client" 
FunctionEnd 

La funzione che viene chiamato dopo che passa in rassegna è .onVerifyInstDir così che è dove posso controllare la variabile CLIENT_OR_SERVER e impostare il percorso appropriato

; This function is special and is called any time a 
; path is validated on returning from the browse button 
; need to append the correct directory if it does not already exists 
; in the install directory path 
Function .onVerifyInstDir 
    ; save the current $0 register, as it is used in this function 
    Push $0 

    ${If} $CLIENT_OR_SERVER == "client" 
    ; in the client stage so directory must contain CLIENT_FOLDER_NAME 
    ${StrContains} $0 "${CLIENT_FOLDER_NAME}" "$INSTDIR" 
    ${If} $0 == "" 
     ; the install dir does not contain the folder so append it 
     StrCpy $INSTDIR "$INSTDIR\${CLIENT_FOLDER_NAME}" 
    ${EndIf} 
    ${Else} 
    ; in the server stage so directory must contain SERVER_FOLDER_NAME 
    ${StrContains} $0 "${SERVER_FOLDER_NAME}" "$INSTDIR" 
    ${If} $0 == "" 
     ; the install dir does not contain the folder so append it 
     StrCpy $INSTDIR "$INSTDIR\${SERVER_FOLDER_NAME}" 
    ${EndIf} 
    ${EndIf} 

    ; pop the saved register value 
    Pop $0 
FunctionEnd 

note coppia: la funzione StrContains ho usato è stato trovato qui: http://nsis.sourceforge.net/StrContains

Ulteriori riferimento alla .onVerifyInstD La funzione IR può essere trovata qui: http://nsis.sourceforge.net/Docs/Chapter4.html#4.7.2.1.10

+0

La disattivazione del metodo di scrittura non è IMHO fresco – Anders

4

Il nome della cartella aggiunta è costante e impostato in fase di compilazione, a questo corrisponde un bug report.

Il mio consiglio è quello di abbandonare la funzione di aggiunta e consentire all'utente di avere il pieno controllo sulle due destinazioni:

Name "NSIS Test" 
InstallDir "" 
!include MUI.nsh 
Var DirClient 
Var DirServer 

Function .onInit 
;Set default destinations 
StrCpy $DirClient "$ProgramFiles\$(^Name)\Client" 
StrCpy $DirServer "$ProgramFiles\$(^Name)\Server" 
FunctionEnd 

!macro ConfigureMyDirPage type var 
!define MUI_DIRECTORYPAGE_VARIABLE ${var} 
!define MUI_PAGE_HEADER_SUBTEXT "Choose the folder in which to install $(^NameDA) ${type}" 
!define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install $(^NameDA) ${type} in the following folder. To install in a different folder, click Browse and select another folder. $_CLICK" 
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION "${type} $(^DirSubText)" 
!macroend 

!insertmacro ConfigureMyDirPage "Client" $DirClient 
!insertmacro MUI_PAGE_DIRECTORY 

!insertmacro ConfigureMyDirPage "Server" $DirServer 
!insertmacro MUI_PAGE_DIRECTORY 

!insertmacro MUI_PAGE_INSTFILES 

!insertmacro MUI_LANGUAGE "English" 

Section 
DetailPrint DirClient=$DirClient 
DetailPrint DirServer=$DirServer 
SectionEnd 
Problemi correlati