Skip to content
⌘ NSIS Forum Archive

remove last words from InstallDirRegKey and then use that

7 posts

r2du-soft#

remove last words from InstallDirRegKey and then use that

hi
i have a problem with InstallDirRegKey and InstallDir,i use from InstallDirRegKey for installation patch in my application and read a address from reg: "HKEY_CURRENT_USER\Software\RoseSoftwares\CarRepairShop\" "ExePath" and in ExePath is this: "C:\Program Files\Rose\CarRepairShop\RepairShop.exe" now i want remove "RepairShop.exe" from address and use that address Sample this: "C:\Program Files\Rose\CarRepairShop\" for InstallDirRegKey.
i how can do it?!
thanks
r2du-soft#
thanks
i found a solution:



page directory
page instfiles

function RegsKeys
ReadRegStr $0 HKCU Software\RoseSoftwares\CarRepairShop "ExePath"
;in String Exepath is address "C:\Program Files\Rose\CarRepairShop\RepairShop.exe"
functionend

Section "Install Application Dll Files Need"
SetOutPath "$INSTDIR"
File RosePlug.Dll
File ClPack.Dll
SectionEnd

Function .onInit
call RegsKeys
StrCpy $INSTDIR $0 -14
FunctionEnd


and another question:
is possible i split "C:\Program Files\Rose\CarRepairShop\RepairShop.exe" by \ character?\
finally change to "C:\Program Files\Rose\CarRepairShop\" by split? something like StrCpy $INSTDIR $0 -14
r2du-soft#
i have a question About split string...
i have string: (C:\Program Files\Rose\CarRepairShop\RepairShop.exe) in a variable.
now i want split this string by \ and remove the last \ after.
In the end change that string to (C:\Program Files\Rose\CarRepairShop\)
is possible this?how?
thanks
Anders#
All string operations can be implemented with strlen+strcpy+strcmp. Have you looked at some of the standard NSIS headers? WordFunc etc. If you cannot find what you are looking for you might have to write your own function...
r2du-soft#
thanks
i use from StrStr+StrLen+StrCpy , are you think this code have problem? and think this way for solve problem is bad?


!define StrStr "!insertmacro StrStr"

!macro StrStr ResultVar String SubString
Push '${String}'
Push '${SubString}'
Call StrStr
Pop '${ResultVar}'
!macroend

Function StrStr
/*After this point:
------------------------------------------
$R0 = SubString (input)
$R1 = String (input)
$R2 = SubStringLen (temp)
$R3 = StrLen (temp)
$R4 = StartCharPos (temp)
$R5 = TempStr (temp)*/

;Get input from user
Exch $R0
Exch
Exch $R1
Push $R2
Push $R3
Push $R4
Push $R5

;Get "String" and "SubString" length
StrLen $R2 $R0
StrLen $R3 $R1
;Start "StartCharPos" counter
StrCpy $R4 1
;Loop until "SubString" is found or "String" reaches its end
loop:
;Remove everything before and after the searched part ("TempStr")
StrCpy $R5 $R1 $R2 $R4
;Compare "TempStr" with "SubString"
StrCmp $R5 $R0 done
;If not "SubString", this could be "String"'s end
IntCmp $R4 $R3 done 0 done
;If not, continue the loop
IntOp $R4 $R4 - 1
Goto loop
done:
/*After this point:
------------------------------------------
$R0 = ResultVar (output)*/
;Remove part before "SubString" on "String" (if there has one)
StrCpy $R0 $R1 '' $R4
;Return output to user
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd






Section
StrCpy $1 "C:\Program Files\Rose\CarRepairShop\RepairShop.exe"
MessageBox MB_OK "$1"


${StrStr} $0 "$1" "\"
StrLen $3 $0
StrCpy $4 $1 -$3
MessageBox MB_OK "$4\"
SectionEnd
demiller9#
Things that you might find in the manual:
E.1.15 GetParent
Get parent directory.

Syntax:

${GetParent} "[PathString]" $var

Example:
!include "FileFunc.nsh"
Section
${GetParent} "C:\Program Files\Winamp\uninstwa.exe" $R0
; $R0="C:\Program Files\Winamp"
SectionEnd