发新话题
打印

[求助] 有关NSIS的问题?

本主题由 9esu 于 2008-2-21 09:53 AM 移动

有关NSIS的问题?

我想制作一个包含很多软件的安装包;然后可以将软件的快捷方式归纳到一起【一个窗口】;改变安装路径,快捷方式也做相应改变!有高手知道用NSIS怎么做?

对不起我没形容清楚;望楼主原谅!!我说的到一起是如下图


[ 本帖最后由 碗水云尧 于 2008-2-20 08:34 PM 编辑 ]
附件: 您所在的用户组无法下载或查看附件

TOP

回复 1# 的帖子

看下这个例子吧
Two installations in one installer

Description This script shows how we can install two programs with one installer, where each program has its own Directory and InstFiles page. Obviously we still have the single Components page though, as if we chose to have two then we'd might as well make two bloody installer exe's!


The Script Here's the code. You can compile this script straight off. I've added MessageBox's to test it.
复制内容到剪贴板
代码:
Name "Multiple InstFiles"
OutFile "multi-install.exe"

!include MUI.nsh
!include Sections.nsh

##===========================================================================
## Modern UI Pages
##===========================================================================

!insertmacro MUI_PAGE_WELCOME

!define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesCheck
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ComponentsLeave
!insertmacro MUI_PAGE_COMPONENTS

## This is the title on the first Directory page
!define MUI_DIRECTORYPAGE_TEXT_TOP "$(MUI_DIRECTORYPAGE_TEXT_TOP_A)"

!define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesA
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

## This is the title on the second Directory page
!define MUI_DIRECTORYPAGE_TEXT_TOP "$(MUI_DIRECTORYPAGE_TEXT_TOP_B)"

!define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesB
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE DeleteSectionsINI
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

##===========================================================================
## Language strings
##===========================================================================

LangString NoSectionsSelected ${LANG_ENGLSH} "You haven't selected any sections!"

LangString MUI_DIRECTORYPAGE_TEXT_TOP_A ${LANG_ENGLSH} "Setup will install \
Program #1 in the following folder..."
LangString MUI_DIRECTORYPAGE_TEXT_TOP_B ${LANG_ENGLSH} "Setup will install \
Program #2 in the following folder..."

##===========================================================================
## Start sections
##===========================================================================

## Sections Group 1
SectionGroup /e "Program #1" PROG1
Section "Main" SEC1
##All the files in Group 1 will be installed to the same location, $INSTDIR
SetOutPath "$INSTDIR"
## Main files to install here

messagebox mb_ok sec1

SectionEnd

Section "Other" SEC2
## Other files to install here

messagebox mb_ok sec2

SectionEnd

SectionGroupEnd

## Sections Group 2
SectionGroup /e "Program #2" PROG2

Section "Main" SEC3
##All the files in Group 2 will be installed to the same location, $INSTDIR
SetOutPath "$INSTDIR"
## Main files to install here

messagebox mb_ok sec3

SectionEnd

Section "Other" SEC4
## Other files to install here

messagebox mb_ok sec4

SectionEnd

SectionGroupEnd

##===========================================================================
## Settings
##===========================================================================

!define PROG1_InstDir    "C:\PROG1"
!define PROG1_StartIndex ${PROG1}
!define PROG1_EndIndex   ${SEC2}

!define PROG2_InstDir "C:\PROG2"
!define PROG2_StartIndex ${PROG2}
!define PROG2_EndIndex   ${SEC4}

##===========================================================================
## Please don't modify below here unless you're a NSIS 'wiz-kid'
##===========================================================================

## Create $PLUGINSDIR
Function .onInit
InitPluginsDir
FunctionEnd

## If user goes back to this page from 1st Directory page
## we need to put the sections back to how they were before
Var IfBack
Function SelectFilesCheck
StrCmp $IfBack 1 0 NoCheck
  Call ResetFiles
NoCheck:
FunctionEnd

## Also if no sections are selected, warn the user!
Function ComponentsLeave
Push $R0
Push $R1

Call IsPROG1Selected
  Pop $R0
Call IsPROG2Selected
  Pop $R1
StrCmp $R0 1 End
StrCmp $R1 1 End
  Pop $R1
  Pop $R0
MessageBox MB_OK|MB_ICONEXCLAMATION "$(NoSectionsSelected)"
Abort

End:
Pop $R1
Pop $R0
FunctionEnd

Function IsPROG1Selected
Push $R0
Push $R1

StrCpy $R0 ${PROG1_StartIndex} # Group 1 start

  Loop:
   IntOp $R0 $R0 + 1
   SectionGetFlags $R0 $R1                        # Get section flags
    IntOp $R1 $R1 & ${SF_SELECTED}
    StrCmp $R1 ${SF_SELECTED} 0 +3                # If section is selected, done
     StrCpy $R0 1
     Goto Done
    StrCmp $R0 ${PROG1_EndIndex} 0 Loop

Done:
Pop $R1
Exch $R0
FunctionEnd

Function IsPROG2Selected
Push $R0
Push $R1

StrCpy $R0 ${PROG2_StartIndex}    # Group 2 start

  Loop:
   IntOp $R0 $R0 + 1
   SectionGetFlags $R0 $R1                        # Get section flags
    IntOp $R1 $R1 & ${SF_SELECTED}
    StrCmp $R1 ${SF_SELECTED} 0 +3                # If section is selected, done
     StrCpy $R0 1
     Goto Done
    StrCmp $R0 ${PROG2_EndIndex} 0 Loop

Done:
Pop $R1
Exch $R0
FunctionEnd

## Here we are selecting first sections to install
## by unselecting all the others!
Function SelectFilesA

# If user clicks Back now, we will know to reselect Group 2's sections for
# Components page
StrCpy $IfBack 1

# We need to save the state of the Group 2 Sections
# for the next InstFiles page
Push $R0
Push $R1

StrCpy $R0 ${PROG2_StartIndex} # Group 2 start

  Loop:
   IntOp $R0 $R0 + 1
   SectionGetFlags $R0 $R1                                    # Get section flags
    WriteINIStr "$PLUGINSDIR\sections.ini" Sections $R0 $R1 # Save state
    !insertmacro UnselectSection $R0                            # Then unselect it
    StrCmp $R0 ${PROG2_EndIndex} 0 Loop

# Don't install prog 1?
Call IsPROG1Selected
Pop $R0
StrCmp $R0 1 +4
  Pop $R1
  Pop $R0
  Abort

# Set current $INSTDIR to PROG1_InstDir define
StrCpy $INSTDIR "${PROG1_InstDir}"

Pop $R1
Pop $R0
FunctionEnd

## Here we need to unselect all Group 1 sections
## and then re-select those in Group 2 (that the user had selected on
## Components page)
Function SelectFilesB
Push $R0
Push $R1

StrCpy $R0 ${PROG1_StartIndex}    # Group 1 start

  Loop:
   IntOp $R0 $R0 + 1
    !insertmacro UnselectSection $R0                # Unselect it
    StrCmp $R0 ${PROG1_EndIndex} 0 Loop

Call ResetFiles

# Don't install prog 2?
Call IsPROG2Selected
Pop $R0
StrCmp $R0 1 +4
  Pop $R1
  Pop $R0
  Abort

# Set current $INSTDIR to PROG2_InstDir define
StrCpy $INSTDIR "${PROG2_InstDir}"

Pop $R1
Pop $R0
FunctionEnd

## This will set all sections to how they were on the components page
## originally
Function ResetFiles
Push $R0
Push $R1

StrCpy $R0 ${PROG2_StartIndex}    # Group 2 start

  Loop:
   IntOp $R0 $R0 + 1
   ReadINIStr "$R1" "$PLUGINSDIR\sections.ini" Sections $R0 # Get sec flags
    SectionSetFlags $R0 $R1                                  # Re-set flags for this sec
    StrCmp $R0 ${PROG2_EndIndex} 0 Loop

Pop $R1
Pop $R0
FunctionEnd

## Here we are deleting the temp INI file at the end of installation
Function DeleteSectionsINI
Delete "$PLUGINSDIR\Sections.ini"
FlushINI "$PLUGINSDIR\Sections.ini"
FunctionEnd
求助的语气相当恼人,想必没多少人愿意出手相助。

如果想自己的求助路途一路畅通,改改自己的语气,或许你在其他论坛是版主,是被人称为大师也好,在这里只要你是求助的,就学着把语气放缓点。谁都想有个好心情,举手之劳何乐而不为呢?

欢迎大家帮我踩踩我的百度空间   http://hi.baidu.com/xstar2008

TOP

如果做成这样好看的界面
可能nsis 实现起来 不容易吧

可以尝试 第一个是自定义界面

利用单选 或多选框来实现 安装不同的软件
感谢Baidu,Google,Dreams8给我这次机会!
还要感谢我的爸爸妈妈!
HOHO

TOP

使用LINK控件实现点选功能;如果界面要做到上图;就得改UI...

TOP

那要怎么做呢?给个例子吧!!谢谢啦!!!

TOP

听说可以用 InstallOptionsEx.dll 插件实现
http://bbs.hanzify.org/index.php?showtopic=49476&hl=

TOP

gfm688,是按钮功能,不是图片!!点击按钮打开程序!!

TOP

发新话题