Locate是NSIS查找文件夹或空文件夹或文件或文件类型的插件

/*
Locate是NSIS查找文件夹或空文件夹或文件或文件类型的插件
Locate可以通过通配符进行查找
Locate可以过滤文件名或后缀名进行查找
*/
!AddIncludeDir "../Include"
!AddPluginDir "../Plugin"
Name "LocateTest"
OutFile "LocateTest.exe"
!include "Locate.nsh"
!include "Sections.nsh"
Var RADIOBUTTON
Page components
Page instfiles
Section "Search for text files" SearchTxt
${locate::Open} "$WINDIR" `/F=1 /D=0 /M=*.txt /B=1` $0
StrCmp $0 0 0 loop
MessageBox MB_OK "Error" IDOK close
loop:
${locate::Find} $0 $1 $2 $3 $4 $5 $6
MessageBox MB_OKCANCEL '$1 "pathname" =[$1]$n
$2 "path" =[$2]$n
$3 "name" =[$3]$n
$4 "size" =[$4]$n
$5 "time" =[$5]$n
$6 "attributes =[$6]$n
$n
Find next?' IDOK loop
close:
${locate::Close} $0
${locate::Unload}
SectionEnd
Section /o "Search with filters" SearchWithFilters
#Locate files in Windows directory beginning with "set",
# with extensions "log" or "txt", but not "setuplog.txt", not "setuperr.log",
# exclude "C:WINDOWSSystem", "C:WINDOWSSystem32", "C:WINDOWSHelp" paths from search,
# exclude "config" directory from search (C:WINDOWSsystem32config, C:WINDOWSConfig, D:WINDOWSpchealthhelpctrConfig, ...)
${locate::Open} "$WINDIR" `/F=1
/D=0
/M=set*
/X=log|txt
/-N="setuplog.txt|setuperr.log"
/-PF="$WINDIRSystem|$WINDIRSystem32|$WINDIRHelp"
/-PN=config
/B=1` $0
StrCmp $0 -1 0 loop
MessageBox MB_OK "Error" IDOK close
loop:
${locate::Find} $0 $1 $2 $3 $4 $5 $6
MessageBox MB_OKCANCEL '$1 "pathname" =[$1]$n
$2 "path" =[$2]$n
$3 "name" =[$3]$n
$4 "size" =[$4]$n
$5 "time" =[$5]$n
$6 "attributes =[$6]$n
$n
Find next?' IDOK loop
close:
${locate::Close} $0
${locate::Unload}
SectionEnd
Section /o "Search and write founded in text file" SearchAndWriteInFile
GetTempFileName $1
FileOpen $2 $1 w
${locate::Open} "$PROGRAMFILESCommon Files" `/F=1 /D=1 /S=,Kb /T=,Creation /SF=TYPE /SD=NAME /B=1` $R0
StrCmp $R0 0 0 loop
MessageBox MB_OK "Error" IDOK close
loop:
${locate::Find} $R0 $R1 $R2 $R3 $R4 $R5 $R6
StrCmp $R1 '' close
StrCmp $R4 '' 0 +3
FileWrite $2 'DIR:"$R1" [Created: $R5] [$R6]$r$n'
goto +2
FileWrite $2 'FILE:"$R1" [$R4 Kb] [Created: $R5] [$R6]$r$n'
goto loop
close:
${locate::Close} $R0
${locate::Unload}
FileClose $2
Exec '"notepad.exe" "$1"'
SectionEnd
### If nsx.dll not found then "Search with banner" example will not be compile ###
!system 'ECHO.>"%TEMP%Temp$$.nsh"'
!system 'IF EXIST "${NSISDIR}Pluginsnxs.dll" ECHO !define nxs_exist>>"%TEMP%Temp$$.nsh"'
!include "$%TEMP%Temp$$.nsh"
!system 'DEL "%TEMP%Temp$$.nsh"'
!ifdef nxs_exist
Section /o "Search with banner - 'NxS' plugin required" SearchWithBanner
HideWindow
nxs::Show /NOUNLOAD `$(^Name) Setup`
/top `Setup searching something$nPlease wait... If you can...`
/pos 78 /h 0 /can 1 /end
${locate::Open} "$WINDIR" `/F=1 /D=1 /SF=TYPE /M="Unexisted Name.ext" /SD=NAME /B=2` $0
StrCmp $0 0 0 loop
nxs::Destroy
MessageBox MB_OK "Error" IDOK close
loop:
${locate::Find} $0 $1 $2 $3 $4 $5 $6
StrCmp $1 '' close
StrCmp $6 '' 0 code
nxs::Update /NOUNLOAD /sub "$1" /end
nxs::HasUserAborted /NOUNLOAD
Pop $1
StrCmp $1 1 close loop
code:
;... code
goto loop
close:
${locate::Close} $0
${locate::Unload}
nxs::Destroy
BringToFront
SectionEnd
!endif
Section /o "Get size of the 'C:Program Files'" GetSize
${locate::GetSize} "C:Program Files" `/S=Mb /M=*.* /G=1 /B=1` $R1 $R2 $R3
${locate::Unload}
MessageBox MB_OK "locate::GetSize$n$n
Size: [$R1]$n
Files: [$R2]$n
Folders: [$R3]"
SectionEnd
Section /o "Remove all empty directories" RMDirEmpty
CreateDirectory "$TEMP12aa"
CreateDirectory "$TEMP13aa"
${locate::RMDirEmpty} "$TEMP1" `/M=*.* /G=1 /B=1` $R1
${locate::Unload}
MessageBox MB_OK "locate::RMDirEmpty$n$n
Removed Directories: [$R1]"
RMDir "$TEMP1"
SectionEnd
Function .onInit
StrCpy $RADIOBUTTON ${SearchTxt}
FunctionEnd
Function .onSelChange
!insertmacro StartRadioButtons $RADIOBUTTON
!insertmacro RadioButton ${SearchTxt}
!insertmacro RadioButton ${SearchWithFilters}
!insertmacro RadioButton ${SearchAndWriteInFile}
!ifdef nxs_exist
!insertmacro RadioButton ${SearchWithBanner}
!endif
!insertmacro RadioButton ${GetSize}
!insertmacro RadioButton ${RMDirEmpty}
!insertmacro EndRadioButtons
FunctionEnd
© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容