BannerTrimPath
From NSIS Wiki
Jump to navigationJump to search
Author: Instructor (talk, contrib) |
Page for NSIS 2.07 and below users
You can use the latest version of headers (recommended) or the following function code (put the function code in your script before calling it)
Function Description
____________________________________________________________________________ BannerTrimPath ____________________________________________________________________________ Trim string path for banner. Syntax: ${BannerTrimPath} "[PathString]" "[Option]" $var "[PathString]" ; ; "[Option]" ; [Length][A|B|C|D] ; ; Length -Maximum string length ; A -Trim center path (default) ; (C:\root\...\third path) ; If A mode not possible Then will be used B mode ; B -Trim right path ; (C:\root\second path\...) ; If B mode not possible Then will be used C mode ; C -Trim right string ; (C:\root\second path\third p...) ; D -Trim right string + filename ; (C:\root\second p...\third path) ; If D mode not possible Then will be used C mode ; $var ; Result: Trimmed path
Example:
Section ${BannerTrimPath} "C:\Server\Documents\Terminal\license.htm" "34A" $R0 ;$R0=C:\Server\...\Terminal\license.htm SectionEnd
Example (Banner plugin):
!include "WinMessages.nsh" !include "FileFunc.nsh" !insertmacro Locate Section Banner::show /NOUNLOAD "Starting..." Banner::getWindow /NOUNLOAD Pop $R1 ${Locate} "$WINDIR" "/L=F /M=*.* /B=1" "LocateCallback" Banner::destroy SectionEnd Function LocateCallback StrCmp $R0 $R8 code StrCpy $R0 $R8 ${BannerTrimPath} "$R8" "38B" $R8 GetDlgItem $1 $R1 1030 SendMessage $1 ${WM_SETTEXT} 0 "STR:$R8" code: StrCmp $R9 '' end ;... end: Push $0 FunctionEnd
Example (nxs plugin):
!include "FileFunc.nsh" !insertmacro Locate Section nxs::Show /NOUNLOAD `$(^Name) Setup`\ /top `Setup searching something$\nPlease wait$\nIf you can...`\ /h 1 /can 1 /end ${Locate} "$WINDIR" "/L=F /M=*.* /B=1" "LocateCallback" nxs::Destroy SectionEnd Function LocateCallback StrCmp $R0 $R8 abortcheck StrCpy $R0 $R8 ${BannerTrimPath} "$R8" "55A" $R8 nxs::Update /NOUNLOAD /sub "$R8" /pos 78 /end abortcheck: nxs::HasUserAborted /NOUNLOAD Pop $0 StrCmp $0 1 0 +2 StrCpy $0 StopLocate StrCmp $R9 '' end ;... end: Push $0 FunctionEnd
Function Code
Function BannerTrimPath !define BannerTrimPath `!insertmacro BannerTrimPathCall` !macro BannerTrimPathCall _PATH _LENGTH _RESULT Push `${_PATH}` Push `${_LENGTH}` Call BannerTrimPath Pop ${_RESULT} !macroend Exch $1 Exch Exch $0 Exch Push $2 Push $3 Push $4 StrCpy $3 $1 1 -1 IntOp $1 $1 + 0 StrLen $2 $0 IntCmp $2 $1 end end IntOp $1 $1 - 3 IntCmp $1 0 empty empty StrCmp $3 'A' A-trim StrCmp $3 'B' B-trim StrCmp $3 'C' C-trim StrCmp $3 'D' D-trim A-trim: StrCpy $3 $0 1 1 StrCpy $2 0 StrCmp $3 ':' 0 +2 IntOp $2 $2 + 2 loopleft: IntOp $2 $2 + 1 StrCpy $3 $0 1 $2 StrCmp $2 $1 C-trim StrCmp $3 '\' 0 loopleft StrCpy $3 $0 $2 IntOp $2 $2 - $1 IntCmp $2 0 B-trim 0 B-trim loopright: IntOp $2 $2 + 1 StrCpy $4 $0 1 $2 StrCmp $2 0 B-trim StrCmp $4 '\' 0 loopright StrCpy $4 $0 '' $2 StrCpy $0 '$3\...$4' goto end B-trim: StrCpy $2 $1 IntOp $2 $2 - 1 StrCmp $2 -1 C-trim StrCpy $3 $0 1 $2 StrCmp $3 '\' 0 -3 StrCpy $0 $0 $2 StrCpy $0 '$0\...' goto end C-trim: StrCpy $0 $0 $1 StrCpy $0 '$0...' goto end D-trim: StrCpy $3 -1 IntOp $3 $3 - 1 StrCmp $3 -$2 C-trim StrCpy $4 $0 1 $3 StrCmp $4 '\' 0 -3 StrCpy $4 $0 '' $3 IntOp $3 $1 + $3 IntCmp $3 2 C-trim C-trim StrCpy $0 $0 $3 StrCpy $0 '$0...$4' goto end empty: StrCpy $0 '' end: Pop $4 Pop $3 Pop $2 Pop $1 Exch $0 FunctionEnd