NSIS - 自定义页面,下拉列表的问题

时间:2013-05-20 12:19:52

标签: nsis

我的代码中有自定义页面,其中有一个包含计算机上可用驱动器的下拉列表。当用户选择他想要的驱动器时,会创建一个.txt文件,写入该驱动器(例如:E :)。 打开自定义页面时,下拉列表中显示的驱动器为“C:\”。但是,如果我点击“下一步”而不点击下拉列表,则不会创建.txt文件。即使我想要C:\并且它已经存在,我必须去那里并点击以使其工作。如果我在点击“下一步”之前没有点击下拉列表,则不会发生任何事情。 谁知道为什么?代码如下:

  !include "MUI2.nsh" 
  !include FileFunc.nsh
  !insertmacro GetDrives

  var newCheckBox

  !define NOME "S-Monitor"

  Name "${NOME}"
  OutFile "${NOME}.exe"
  InstallDir "C:\${NOME}"  

  ShowInstDetails show
  AllowRootDirInstall true

;--- Paginas ---

  !define MUI_ICON Labels\SetupICO.ico

    !define MUI_HEADERIMAGE
    !define MUI_HEADERIMAGE_RIGHT
    !define MUI_HEADERIMAGE_BITMAP Labels\Header.bmp
    !define MUI_WELCOMEFINISHPAGE_BITMAP Labels\Left.bmp

  !insertmacro MUI_PAGE_WELCOME
  !insertmacro MUI_PAGE_DIRECTORY
  !insertmacro MUI_PAGE_INSTFILES
  Page Custom CustomCreate CustomLeave

  !define MUI_FINISHPAGE_NOAUTOCLOSE
    !define MUI_FINISHPAGE_RUN
    !define MUI_FINISHPAGE_RUN_CHECKED
    !define MUI_FINISHPAGE_RUN_TEXT "Criar atalho na Área de Trabalho"
    !define MUI_FINISHPAGE_RUN_FUNCTION "AtalhoDesktop"  

!define MUI_PAGE_CUSTOMFUNCTION_SHOW showNewCheckbox
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE launchNewLink

  !insertmacro MUI_PAGE_FINISH

;--- Idiomas ---

!insertmacro MUI_LANGUAGE "Portuguese"
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Spanish"

Function .onInit

  !insertmacro MUI_LANGDLL_DISPLAY
  InitPluginsDir
         GetTempFileName $0
         Rename $0 '$PLUGINSDIR\custom.ini'

FunctionEnd

;--------------------------------
;Arquivos a serem instalados

Section "Instalacao"

SetShellVarContext all

  SetOutPath "$INSTDIR"  
  File /r Ficheiros\*.* ; LOCALIZACAO DA APLICACAO DO S-MONITOR

  MessageBox MB_OK "O software BDE (Borland Database Engine) será instalado agora"
  ExecWait "$INSTDIR\bde_install_Win7_32_e_64.exe"

  FileOpen $1 '$INSTDIR\S-monitor.cpy' w
  FileWrite $1 "CPY Location=C:\S-Monitor.cpy"
  FileClose $1

  writeUninstaller $INSTDIR\uninstall.exe

SectionEnd

Section "Uninstall"

MessageBox MB_YESNO "Deseja desinstalar o S-Monitor?" IDYES true IDNO false
true:
  SetShellVarContext all
  delete $INSTDIR\uninstall.exe
  RMDir /R /REBOOTOK $INSTDIR
  Goto +2
false:
MessageBox MB_OK "Desinstalação cancelada."
SectionEnd

Function AtalhoDesktop
createShortCut "$DESKTOP\S-Monitor.lnk" "C:\SMonitor.exe"
FunctionEnd

Function showNewCheckbox
${NSD_CreateCheckbox} 120u 110u 100% 10u "&Iniciar o S-Monitor ao terminar a instalação"
Pop $newCheckBox
FunctionEnd

Function launchNewLink
${NSD_GetState} $newCheckBox $0
${If} $0 <> 0
    Exec "C:\S-Monitor\Smonitor.exe"
${EndIf}
FunctionEnd

Function CustomCreate
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Settings' 'NumFields' '6'

         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Type' 'Label'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Left' '5'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Top' '5'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Right' '-6'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Bottom' '60'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Text' \
         'Escolha a que disco rígido quer associar a sua licença do S-Monitor.\nA instalação do S-Monitor ficará associada de forma permanente ao disco escolhido.\n\nSe desejar transferir a sua licença para outro PC mais tarde, deverá escolher um disco amovível neste passo.\nSe não sabe que opção escolher, deixe seleccionada a opção por defeito.'

         StrCpy $R2 0
         StrCpy $R0 ''
         ${GetDrives} "HDD+FDD" GetDrivesCallBack

         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Type' 'DropList'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Left' '30'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Top' '64'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Right' '-31'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Bottom' '200'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Flags' 'Notify'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'State' '$R1'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'ListItems' '$R0'

         push $0
         InstallOptions::Dialog '$PLUGINSDIR\custom.ini'
         pop $0
         pop $0
FunctionEnd

Function CustomLeave
        ReadIniStr $0 '$PLUGINSDIR\custom.ini' 'Settings' 'State'
        StrCmp $0 '2' 0 next
        ReadIniStr $0 '$PLUGINSDIR\custom.ini' 'Field 2' 'State'
        strcpy $R0  $0
        StrCpy $0 $0 3
        FileOpen $1 '$INSTDIR\S-monitor.cpy' w
        FileWrite $1 "CPY Location=$R0S-Monitor.cpy"
        FileClose $1

        Abort
     next:
        ReadIniStr $0 '$PLUGINSDIR\custom.ini' 'Field 2' 'State'
        StrCpy '$INSTDIR' '$0'
FunctionEnd

Function GetDrivesCallBack
         StrCmp $R2 '0' 0 next
         StrCpy $R3 '$R4'
         StrCpy $R1 '$9'
         IntOp $R2 $R2 + 1
      next:
         StrCpy $R0 '$R0$9|'
         Push $0
FunctionEnd

0 个答案:

没有答案