- NSIS Discussion
- Help detecting directory
Archive: Help detecting directory
esky
2nd November 2003 20:19 UTC
Help detecting directory
I'm trying to detect installation folders for the game counter-strike, which is part of a program called steam... so i can find the directory for steam, however here's the typical path I need to detect:
C:\Games\Steam\SteamApps\ncesky@hotmail.com\counter-strike
The problem is, every user will have a different email address, and I can't seem to find a registry value that points me there. So far I can get NSIS to:
C:\Games\Steam
How would I make a function that then adds SteamApps to the end of that... and then finds a folder with the @ symbol, adds that folder as well, and then adds counter-strike ... ?
Here's my code so far, I would appreciate some help, I'm still sort of new to the scripting, and even what I have still confuses me at times...
Function getParent
Exch $0 ; old $0 is on top of stack
Push $1
Push $2
StrCpy $1 -1
loop:
StrCpy $2 $0 1 $1
StrCmp $2 "" exit
StrCmp $2 "\" exit
IntOp $1 $1 - 1
Goto loop
exit:
StrCpy $0 $0 $1
Pop $2
Pop $1
Exch $0 ; put $0 on top of stack, restore $0 to original value
FunctionEnd
Function findSteam
ReadRegStr $9 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\Steam" \
"UninstallString"
Push $9
Call getParent
Call getParent
Call getParent
Call getParent
Pop $9
FunctionEnd
At this point $9 becomes C:\Games\Steam on my machine... also the uninstall string reads
C:\Games\Steam\UNWISE.EXE C:\Games\Steam\INSTALL.LOG
kichik
2nd November 2003 21:16 UTC
To find files or folders use FindFirst, FindNext and FindClose. There are some examples in the Archive that use these instructions. To add SteamApps simply use StrCpy. For example:
StrCpy $INSTDIR $9\SteamApps
You can also simply remove one GetParent call...
There were some threads of the same subject last month. Search for them using the forum's searhc engine. They might help you.
esky
3rd November 2003 04:19 UTC
Ok, I think I figured out how to get the directory easily... now let's say I have it saved in a variable...
How do I make it so that this location displays as the default InstallDir when the user starts up my setup program? I tried InstallDir variable_name which just leaves the line blank...
kichik
3rd November 2003 08:34 UTC
Just like in the example above:
StrCpy $INSTDIR C:\another\path\then\default
esky
10th November 2003 08:30 UTC
I really can't seem to get this working... I did the StrCpy in a Section that finds my correct installation folder, but I can't get this path to appear when I run my installer. The only way I have gotten something to appear in the installation path line is when I do InstallDir "whatever" outside sections/functions. But there, I cannot seem to access the vars I use to store my correct path.
I even tried making a registry sting value that would hold my install path, and then read it back.. but the value is not created till after the installation finishes... of course that defeats the purpose and is ultimately useless in this case.
Is there some special procedure to initialize $INSTDIR before I StrCpy my path into it? Do I need to push it, or set InstallDir "" or something?
kichik
10th November 2003 11:26 UTC
A section is executed in the instfiles page (the install log window) which, by default, shows after the directory selection page. You should use this code in .onInit which is called before anything else.
FireBath
25th November 2004 07:25 UTC
Ok so i don't want to start another thread so i'll ask in this one>
I made a function that searches for a directory (or a file it is almost the same) BUT the big problem is that if i have files named a001, a002, a003, a004 and so on and so forth after a while my function will read every file but not in this order for example after i read all the dirs to dir 019 except dir 001 it reads the dir 001 as the dir 020 after that it goes on so i guess it will foul again at 29 but i stopped it (had no more nerves)
The main ideea is that i would like to know if there is an order in wich FindNext get's the next file because it is surely not alfabeticaly...
And for my script i need the exact order (alfabetic) of the dirs i search for
Thanks for any help
Function is as follows
***********************************************************
Function Sets
StrCpy $SrcSets $EXEDIR\*.*
FindFirst $H1 $NameDir $SrcSets
StrCpy $R0 $NameDir -3
StrCmp $NameDir "" Over
StrCmp $R0 "Dir" Found Urmatorul
Urmatorul:
FindNext $H1 $NameDir
StrCpy $R0 $NameDir 3
StrCmp $NameDir "" Over
StrCmp $R0 "Set" Found Urmatorul
Found:
StrCpy $Src $EXEDIR\$NameDir\*.*
Call SearchFilesInDir
Goto Urmatorul
Over:
FindClose $H1
FunctionEnd
***********************************************************
Afrow UK
25th November 2004 14:59 UTC
You don't have to search for the directory. Steam stores the Half-life directory path in the registry. From that path, you can take away half-life from the path end (using GetParent) and then apply 'counter-strike' onto the end.
This thread has the exact code that you need:
http://forums.winamp.com/showthread.php?threadid=189232
-Stu
FireBath
26th November 2004 07:05 UTC
Afrow UK I don't know who you posted for because I can't use this ...
Mabe I was to slippery asking the question.
- We have The directories: Dir 001, Dir 002, Dir 003 ... Dir 020, Dir 021. <- theese are the name of the dirs on hard-drive
- I made a function in my script wich you can read in my previous post
- Now this function searches for files in the current dir get's the files without extension (directories) scans for the first 3 characters in the name and if that is Dir then we go into this new found dir and execute the SearchFilesInDir function wich searches for html files in that dir.
- Builds a text phile with the name of the files in that dir and get's out of the dir
- Goes to NEXT dir and so on and so forth
- the thing is that this NEXT dir is found with FindNext and there is a problem with this function (FindNext function) because it returns the order badly. When try to write the names of the dirs in my phile thei come in THIS order>
Dir 002, Dir 003, Dir 004, ..., Dir 017, Dir 001, Dir 018...
And that is NOT good I need the exact order
scrose
26th November 2004 12:53 UTC
FireBath, I think I can explain why this is happening. FindNext is probably reading the directories in the order they were originally created on your hard drive. You can try verifying this hypothesis by using Windows Explorer to look at the "Date Created" of each directory. I suspect Dir001 is "newer" than Dir017.
Unfortunately, I can't offer a solution. My guess is you would need FindNext to push all the names of the directories onto the stack and then have a function sort the contents of the stack. You might be able to find a function in the archive that will help.
FireBath
3rd December 2004 09:34 UTC
Scrose I checked for the dat/time stamp they where made the same day at the same hour... made a few test's to... must be something else... hmmm
scrose
3rd December 2004 16:15 UTC
Well, it looks like you'll have to sort the directory names. Maybe this will help. (Searching the forum turns up all kinds of gems.)