0

我需要的是:安装软件后,我需要确定可用的驱动程序(硬盘、笔式驱动器等),用户可以选择要在哪个驱动器上安装软件的许可证。当他选择时,会创建一个 .txt 文件并将其写入他选择的驱动器(例如:C:)。

我没有该功能的代码在这里:

  !include "MUI2.nsh"   
  !define NOME "S-Monitor"

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

  ShowInstDetails show

;--- 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


  !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"  


  !insertmacro MUI_PAGE_FINISH

;--- Idiomas ---

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

Function .onInit

  !insertmacro MUI_LANGDLL_DISPLAY

FunctionEnd

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

Section "Instalacao"

SetShellVarContext all

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

SectionEnd


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

1 回答 1

0

用户smilepleeeaz在另一个问题上帮助了我,这也可以用来回答这个问题。

具有我想要的功能的代码如下:

!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 "Ficheiros\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' '17'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'Text' \
         'Selecione o drive a ser instalada a licensa do S-Monitor:'

         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' '26'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Right' '-31'
         WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 2' 'Bottom' '100'
         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
于 2013-05-16T10:48:50.910 回答