Old 15th July 2009, 23:15   #1
todd_ingr
Junior Member
 
Join Date: Jan 2006
Posts: 21
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?

code:
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

todd_ingr is offline   Reply With Quote
Old 15th July 2009, 23:27   #2
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
I'm not sure what Pop "$R0" ends up doing after compilation, but I'd try removing the quotes?
MSG is offline   Reply With Quote
Old 15th July 2009, 23:33   #3
todd_ingr
Junior Member
 
Join Date: Jan 2006
Posts: 21
Quote:
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
code:
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
todd_ingr is offline   Reply With Quote
Old 15th July 2009, 23:56   #4
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
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.
MSG is offline   Reply With Quote
Old 16th July 2009, 01:27   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You will get that error if the variable has not been declared. You will get a similar error for Pop $UndeclaredVar.

Stu
Afrow UK is offline   Reply With Quote
Old 16th July 2009, 11:47   #6
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Eh? I tried it myself, and the compiler just gave a 'warning: Unknown variable, line ignored'.
MSG is offline   Reply With Quote
Old 16th July 2009, 15:34   #7
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Using 2.45:

StrCpy $NewestDir $R0
Usage: StrCpy $(user_var: output) str [maxlen] [startoffset]

Pop $NewestDir
Usage: Pop $(user_var: output)

Stu
Afrow UK is offline   Reply With Quote
Old 17th July 2009, 14:23   #8
todd_ingr
Junior Member
 
Join Date: Jan 2006
Posts: 21
After declaring the variable, I was able to do a StrCpy.

Thanks for the help!
todd_ingr is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump