todd_ingr
15th July 2009 23:15 UTC
Help with StrCpy
I'm trying to get the newest directory created and stored into a variable, but I can't seem to figure out how to do that.
My code below runs a specific DIR command in DOS and returns a bunch of directories. The top most will be the newest directory and is what is returned by the GetFirstStrPart function.
What I'd like to do is take that popped $R0 value and assign it to something like $NewestDir, but when I do the StrCpy, it errors out.
Any ideas?
Function InstallNewVersionsPost
ReadEnvStr $0 COMSPEC
nsExec::ExecToStack '$0 /C "dir g:\ /o-d/ad/b"'
Pop $0 # return value/error/timeout
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
Push $1
Call GetFirstStrPart
Pop "$R0"
;StrCpy $R0 $NewestDir
ReadINIStr ${TEMP1} "$PLUGINSDIR\test.ini" "Field 7" "State"
${If} ${TEMP1} == "1"
ExecWait '"G:\$R0\mysoftware\DISK1\SETUP.EXE" -s -f1$PLUGINSDIR\install.iss'
${EndIf}
FunctionEnd
Function GetFirstStrPart
Exch $R0
Push $R1
Push $R2
StrLen $R1 $R0
IntOp $R1 $R1 + 1
loop:
IntOp $R1 $R1 - 1
StrCpy $R2 $R0 1 -$R1
StrCmp $R2 "" exit2
StrCmp $R2 "$\r" exit1 ; Change " " to "\" if ur inputting dir path str
Goto loop
exit1:
StrCpy $R0 $R0 -$R1
exit2:
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
MSG
15th July 2009 23:27 UTC
I'm not sure what Pop "$R0" ends up doing after compilation, but I'd try removing the quotes?
todd_ingr
15th July 2009 23:33 UTC
Originally posted by MSG
I'm not sure what Pop "$R0" ends up doing after compilation, but I'd try removing the quotes?
Thanks for the idea, but that didn't work.
I noticed a problem with what I copy/pasted. I think the commented out strcpy should be
StrCpy $NewestDir $R0
Either way I tested it, I get this in my output window:
Pop: $R0
Usage: StrCpy $(user_var: output) str [maxlen] [startoffset]
Error in script "C:\Documents and Settings\myuser\Desktop\NSIS Scripts\messing_around.nsi" on line 346 -- aborting creation process
MSG
15th July 2009 23:56 UTC
Well you can of course just Pop $NewestDir, but that doesn't explain why StrCpy is complaining. If the NewestDir variable wasn't declared it should give a different error... And it shouldn't be because the string ends with a \, since that's a compile-time issue and registers are only filled at runtime. No, I can't see why it would break down.
Afrow UK
16th July 2009 01:27 UTC
You will get that error if the variable has not been declared. You will get a similar error for Pop $UndeclaredVar.
Stu
MSG
16th July 2009 11:47 UTC
Eh? I tried it myself, and the compiler just gave a 'warning: Unknown variable, line ignored'.
Afrow UK
16th July 2009 15:34 UTC
Using 2.45:
StrCpy $NewestDir $R0
Usage: StrCpy $(user_var: output) str [maxlen] [startoffset]
Pop $NewestDir
Usage: Pop $(user_var: output)
Stu
todd_ingr
17th July 2009 14:23 UTC
After declaring the variable, I was able to do a StrCpy.
Thanks for the help!