BannerTrimPath: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
Line 8: Line 8:
== The Function ==
== The Function ==


<highlight-nsis>/*
/*
____________________________________________________________________________
____________________________________________________________________________


Line 77: Line 77:




Example (*/ [[nxs]] /*plugin):
Example ([[nxs]] plugin):
!include "FileFunc.nsh"
!include "FileFunc.nsh"
!insertmacro Locate
!insertmacro Locate
Line 111: Line 111:
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------


<highlight-nsis>
Function BannerTrimPath
Function BannerTrimPath
!define BannerTrimPath `!insertmacro BannerTrimPathCall`
!define BannerTrimPath `!insertmacro BannerTrimPathCall`

Revision as of 08:06, 4 July 2005

Author: Instructor (talk, contrib)


Links

Latest version of headers "nsh.zip"
http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost

The Function

/* ____________________________________________________________________________

                           BannerTrimPath

____________________________________________________________________________


Trim string path for banner.


Syntax: ${BannerTrimPath} "[PathString]" "[Option]" $var

"[PathString]"  ;

                 ;

"[Option]"  ; [Length][A|B|C]

                 ;
                 ; Length  -Maximum string length
                 ;   A     -Trim center path (default)
                 ;           (C:\root\...\third path) 
                 ;           If A mode not possible Then will be used B mode
                 ;           If B mode not possible Then will be used C 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...)
                 ;

$var  ; Result: Trimmed path


Example: Section ${BannerTrimPath} "C:\Server\Documents\Terminal\license.htm" "35A" $R0 ;$R0=C:\Server\...\Terminal\licensing.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 BannerTrimPath
	!define BannerTrimPath `!insertmacro BannerTrimPathCall`
 
	!macro BannerTrimPathCall _PATH _LENGHT _RESULT
		Push `${_PATH}`
		Push `${_LENGHT}`
		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
 
	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
 
	empty:
	StrCpy $0 ''
 
	end:
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Exch $0
FunctionEnd