[NSIS] 문자열에 원하는 문자열이 포함되어 있는지 체크하는 함수

# 호출 예

# ${StrContains} '반환' '찾을 문자열' '원본 문자열'
# ${StrContains} $0 "tri" "The String"
# 성공 시 $0 == "tri", 실패 시 $0 == ""

!macro _StrContains un
	Function ${un}_StrContains
		Push $R0 # 찾을 문자열
		Exch
		Pop $R0
		Push $R1 # 원본 문자열
		Exch 2
		Pop $R1
		Push $R2 # 리턴 문자열
		Push $R3
		Push $R4
		Push $R5
		Push $R6

		;MessageBox MB_OK "찾을 문자열[$R0], 원본 문자열[$R1]"

		StrCpy $R2 ""
		StrCpy $R3 -1
		StrLen $R4 $R0
		StrLen $R6 $R1

		loop:
			IntOp $R3 $R3 + 1
			StrCpy $R5 $R1 $R4 $R3
			StrCmp $R5 $R0 found
			StrCmp $R3 $R6 done
			Goto loop
		found:
			StrCpy $R2 $R0
			Goto done
		done:

		Pop $R6
		Pop $R5
		Pop $R4
		Pop $R3
		Exch $R2
		Exch
		Pop $R0
		Exch
		Pop $R1
	FunctionEnd
!macroend
!insertmacro _StrContains ""
!insertmacro _StrContains "un."

!macro StrContains OUTPUT str_find str_origin
	Push "${str_origin}"
	Push "${str_find}"

	!ifndef __UNINSTALL__
		Call _StrContains
	!else
		Call un._StrContains
	!endif

	Pop "${OUTPUT}"
!macroend

!define StrContains "!insertmacro StrContains"

댓글

이 블로그의 인기 게시물

[NSIS] 32비트와 64비트 모듈 등록하는 법. (regsvr32)

[Visual Studio] Windows 7 에서 Visual Studio 6.0 디버그 시 프로세스 좀비되는 증상 해결 방법