BannerTrimPath: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
Instructor (talk | contribs) |
Instructor (talk | contribs) No edit summary |
||
(20 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|Instructor}} | {{PageAuthor|Instructor}} | ||
{{User:Instructor/Headers/Template}} | |||
== Function Description== | |||
<highlight-nsis> | |||
____________________________________________________________________________ | ____________________________________________________________________________ | ||
Line 23: | Line 20: | ||
"[PathString]" ; | "[PathString]" ; | ||
; | ; | ||
"[Option]" ; [Length][A|B|C] | "[Option]" ; [Length][A|B|C|D] | ||
; | ; | ||
; Length -Maximum string length | ; Length -Maximum string length | ||
Line 29: | Line 26: | ||
; (C:\root\...\third path) | ; (C:\root\...\third path) | ||
; If A mode not possible Then will be used B mode | ; If A mode not possible Then will be used B mode | ||
; B -Trim right path | ; B -Trim right path | ||
; (C:\root\second path\...) | ; (C:\root\second path\...) | ||
Line 35: | Line 31: | ||
; C -Trim right string | ; C -Trim right string | ||
; (C:\root\second path\third p...) | ; (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 | $var ; Result: Trimmed path | ||
</highlight-nsis> | |||
Example: | <b>Example:</b> | ||
Section | <highlight-nsis>Section | ||
${BannerTrimPath} "C:\Server\Documents\Terminal\license.htm" " | ${BannerTrimPath} "C:\Server\Documents\Terminal\license.htm" "34A" $R0 | ||
;$R0=C:\Server\...\Terminal\ | ;$R0=C:\Server\...\Terminal\license.htm | ||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
Example (Banner plugin): | <b>Example (Banner plugin):</b> | ||
!include "WinMessages.nsh" | <highlight-nsis>!include "WinMessages.nsh" | ||
!include "FileFunc.nsh" | !include "FileFunc.nsh" | ||
!insertmacro Locate | !insertmacro Locate | ||
Line 74: | Line 75: | ||
Push $0 | Push $0 | ||
FunctionEnd | FunctionEnd | ||
</highlight-nsis> | |||
<b>Example ([http://nsis.sourceforge.net/wiki/Banner_with_Cancel_button nxs] plugin):</b> | |||
Example ([ | <highlight-nsis>!include "FileFunc.nsh" | ||
!include "FileFunc.nsh" | |||
!insertmacro Locate | !insertmacro Locate | ||
Line 107: | Line 108: | ||
Push $0 | Push $0 | ||
FunctionEnd | FunctionEnd | ||
</highlight-nsis> | |||
== Function Code == | |||
<highlight-nsis> | <highlight-nsis> | ||
Line 115: | Line 116: | ||
!define BannerTrimPath `!insertmacro BannerTrimPathCall` | !define BannerTrimPath `!insertmacro BannerTrimPathCall` | ||
!macro BannerTrimPathCall _PATH | !macro BannerTrimPathCall _PATH _LENGTH _RESULT | ||
Push `${_PATH}` | Push `${_PATH}` | ||
Push `${ | Push `${_LENGTH}` | ||
Call BannerTrimPath | Call BannerTrimPath | ||
Pop ${_RESULT} | Pop ${_RESULT} | ||
Line 139: | Line 140: | ||
StrCmp $3 'B' B-trim | StrCmp $3 'B' B-trim | ||
StrCmp $3 'C' C-trim | StrCmp $3 'C' C-trim | ||
StrCmp $3 'D' D-trim | |||
A-trim: | A-trim: | ||
Line 177: | Line 179: | ||
StrCpy $0 $0 $1 | StrCpy $0 $0 $1 | ||
StrCpy $0 '$0...' | 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 | goto end | ||
Latest revision as of 12:12, 30 November 2005
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