仅卸载NSIS上安装的文件

仅卸载NSIS上安装的文件,nsis,Nsis,我想找到一种只卸载已安装文件的方法。 我尝试过,但我有大约10000个文件嵌套在许多目录中,因此在nsis脚本中单独指定每个文件不是一个解决方案。您可以使用!编译时执行外部工具的系统命令。此外部工具/脚本应生成包含安装和卸载说明的文件 您也可以动态使用NSIS生成指令,但将所有指令放在一个脚本中时会有点混乱: ; Generate some files for this example: !system 'mkdir "$%temp%\testdir\subdir\sub2\sub3"' !ap

我想找到一种只卸载已安装文件的方法。
我尝试过,但我有大约10000个文件嵌套在许多目录中,因此在nsis脚本中单独指定每个文件不是一个解决方案。

您可以使用
!编译时执行外部工具的系统
命令。此外部工具/脚本应生成包含安装和卸载说明的文件

您也可以动态使用NSIS生成指令,但将所有指令放在一个脚本中时会有点混乱:

; Generate some files for this example:
!system 'mkdir "$%temp%\testdir\subdir\sub2\sub3"'
!appendfile "$%temp%\testdir\file1.txt" ""
!appendfile "$%temp%\testdir\subdir\file2.txt" ""
!appendfile "$%temp%\testdir\subdir\sub2\file3.txt" ""
!appendfile "$%temp%\testdir\subdir\sub2\sub3\file4.txt" ""



!macro GENFILELIST_Enum SourceDir InstDir
Push "${SourceDir}"
Push "${InstDir}"
Call GENFILELIST_Enum
!macroend

### Start editing here ###

!macro GeneratePages
OutFile "test.exe"
Name "Test"
RequestExecutionLevel admin
InstallDir "$ProgramFiles\MyTestApp"

Page Directory
Page InstFiles
UninstPage UninstConfirm
UninstPage InstFiles
!macroend

!macro GENFILELIST
!insertmacro GENFILELIST_Enum "$%temp%\testdir" "" ; Files to install
!macroend

!macro GenerateInstallSections FileInstructions
Section
SetOutPath $InstDir
!include "${FileInstructions}"
WriteUninstaller "$InstDir\Uninst.exe"
SectionEnd
!macroend

!macro GenerateUninstallSections FileInstructions
Section Uninstall
SetOutPath $InstDir
!include "${FileInstructions}"
SetOutPath $Temp
Delete "$InstDir\Uninst.exe"
RmDir $InstDir
SectionEnd
!macroend

### Stop editing here ###


!ifndef GENFILELIST_IN
!tempfile GENFILELISTAPP
!tempfile GENFILELIST_IN
!tempfile GENFILELIST_UN
!appendfile "${GENFILELIST_IN}" '!define GENFILELIST_UN "${GENFILELIST_UN}"$\n'
!appendfile "${GENFILELIST_IN}" 'OutFile "${GENFILELISTAPP}"$\n'
!system '"${NSISDIR}/makensis" "/DGENFILELIST_IN=${GENFILELIST_IN}" "${__FILE__}"' = 0
!system '"${GENFILELISTAPP}" /S' = 0
!delfile "${GENFILELISTAPP}"
!insertmacro GeneratePages
!insertmacro GenerateInstallSections "${GENFILELIST_IN}"
!insertmacro GenerateUninstallSections "${GENFILELIST_UN}"
!delfile "${GENFILELIST_IN}"
!delfile "${GENFILELIST_UN}"
!else
!include LogicLib.nsh
!include "${GENFILELIST_IN}"
!delfile "${GENFILELIST_IN}"
!macro GENFILELIST_Append file string tmpvar
FileOpen ${tmpvar} "${file}" a
FileSeek ${tmpvar} 0 END
FileWrite ${tmpvar} '${string}'
FileClose ${tmpvar}
!macroend
!define DOLLAR "$$"
Function GENFILELIST_Enum
System::Store S
Pop $9 ; Relative path
Pop $8 ; Base path
${IfThen} $9 == "" ${|} StrCpy $9 "${DOLLAR}OutDir" ${|}
FindFirst $0 $1 "$8\*"
loop:
StrCmp $1 "" stop
    StrCmp $1 "." next
    StrCmp $1 ".." next
    StrCpy $3 $1
    ${If} ${FileExists} "$8\$1\*"
        !insertmacro GENFILELIST_Append "${GENFILELIST_IN}" 'SetOutPath "${DOLLAR}OutDir\$1"$\n' $2
        Push $8\$1
        Push $9\$1
        Call GENFILELIST_Enum
    ${Else}
        !insertmacro GENFILELIST_Append "${GENFILELIST_IN}" 'File "$8\$1"$\n' $2
        !insertmacro GENFILELIST_Append "${GENFILELIST_UN}" 'Delete "$9\$1"$\n' $2
    ${EndIf}
    next:
    FindNext $0 $1
    Goto loop
stop:
FindClose $0
!insertmacro GENFILELIST_Append "${GENFILELIST_UN}" 'RmDir "$9"$\n' $2
System::Store L
FunctionEnd
RequestExecutionLevel user
Section
!insertmacro GENFILELIST
SectionEnd
!endif

您可以使用
!编译时执行外部工具的系统
命令。此外部工具/脚本应生成包含安装和卸载说明的文件

您也可以动态使用NSIS生成指令,但将所有指令放在一个脚本中时会有点混乱:

; Generate some files for this example:
!system 'mkdir "$%temp%\testdir\subdir\sub2\sub3"'
!appendfile "$%temp%\testdir\file1.txt" ""
!appendfile "$%temp%\testdir\subdir\file2.txt" ""
!appendfile "$%temp%\testdir\subdir\sub2\file3.txt" ""
!appendfile "$%temp%\testdir\subdir\sub2\sub3\file4.txt" ""



!macro GENFILELIST_Enum SourceDir InstDir
Push "${SourceDir}"
Push "${InstDir}"
Call GENFILELIST_Enum
!macroend

### Start editing here ###

!macro GeneratePages
OutFile "test.exe"
Name "Test"
RequestExecutionLevel admin
InstallDir "$ProgramFiles\MyTestApp"

Page Directory
Page InstFiles
UninstPage UninstConfirm
UninstPage InstFiles
!macroend

!macro GENFILELIST
!insertmacro GENFILELIST_Enum "$%temp%\testdir" "" ; Files to install
!macroend

!macro GenerateInstallSections FileInstructions
Section
SetOutPath $InstDir
!include "${FileInstructions}"
WriteUninstaller "$InstDir\Uninst.exe"
SectionEnd
!macroend

!macro GenerateUninstallSections FileInstructions
Section Uninstall
SetOutPath $InstDir
!include "${FileInstructions}"
SetOutPath $Temp
Delete "$InstDir\Uninst.exe"
RmDir $InstDir
SectionEnd
!macroend

### Stop editing here ###


!ifndef GENFILELIST_IN
!tempfile GENFILELISTAPP
!tempfile GENFILELIST_IN
!tempfile GENFILELIST_UN
!appendfile "${GENFILELIST_IN}" '!define GENFILELIST_UN "${GENFILELIST_UN}"$\n'
!appendfile "${GENFILELIST_IN}" 'OutFile "${GENFILELISTAPP}"$\n'
!system '"${NSISDIR}/makensis" "/DGENFILELIST_IN=${GENFILELIST_IN}" "${__FILE__}"' = 0
!system '"${GENFILELISTAPP}" /S' = 0
!delfile "${GENFILELISTAPP}"
!insertmacro GeneratePages
!insertmacro GenerateInstallSections "${GENFILELIST_IN}"
!insertmacro GenerateUninstallSections "${GENFILELIST_UN}"
!delfile "${GENFILELIST_IN}"
!delfile "${GENFILELIST_UN}"
!else
!include LogicLib.nsh
!include "${GENFILELIST_IN}"
!delfile "${GENFILELIST_IN}"
!macro GENFILELIST_Append file string tmpvar
FileOpen ${tmpvar} "${file}" a
FileSeek ${tmpvar} 0 END
FileWrite ${tmpvar} '${string}'
FileClose ${tmpvar}
!macroend
!define DOLLAR "$$"
Function GENFILELIST_Enum
System::Store S
Pop $9 ; Relative path
Pop $8 ; Base path
${IfThen} $9 == "" ${|} StrCpy $9 "${DOLLAR}OutDir" ${|}
FindFirst $0 $1 "$8\*"
loop:
StrCmp $1 "" stop
    StrCmp $1 "." next
    StrCmp $1 ".." next
    StrCpy $3 $1
    ${If} ${FileExists} "$8\$1\*"
        !insertmacro GENFILELIST_Append "${GENFILELIST_IN}" 'SetOutPath "${DOLLAR}OutDir\$1"$\n' $2
        Push $8\$1
        Push $9\$1
        Call GENFILELIST_Enum
    ${Else}
        !insertmacro GENFILELIST_Append "${GENFILELIST_IN}" 'File "$8\$1"$\n' $2
        !insertmacro GENFILELIST_Append "${GENFILELIST_UN}" 'Delete "$9\$1"$\n' $2
    ${EndIf}
    next:
    FindNext $0 $1
    Goto loop
stop:
FindClose $0
!insertmacro GENFILELIST_Append "${GENFILELIST_UN}" 'RmDir "$9"$\n' $2
System::Store L
FunctionEnd
RequestExecutionLevel user
Section
!insertmacro GENFILELIST
SectionEnd
!endif

结果和我上面提到的脚本差不多,结果和我上面提到的脚本差不多。