Archive: Installation question


Installation question
Hello,
I'm writing a scriptpackage for Counter-Strike Source.
I want to have a good installer, and i found the very good progtam NSIS. I've finished nearly everything, only one problem left: I want the installer to find the right directory. Problem? THe directory contains a various username, I don't know how to finish it.
HKLM "SOFTWARE\Valve\Steam" "InstallPath" <<the registry key which contains the steam directory.
But the script has to be installed
steam\steamapps\<<ACCOUNTNAME>>\counter-strike source\cstrike

can anyone help me plz?
A complete solution would be very nice!


ReadINIStr $INSTDIR HKCU "Software\Valve\Steam" "ModInstallPath"
StrCmp $INSTDIR "" noInstDirFound
Push $INSTDIR
Call GetParent
Pop $INSTDIR
StrCpy $INSTDIR "$INSTDIR\counter-strike source\cstrike"
Goto instDirFound
noInstDirFound:
ReadINIStr $INSTDIR HKCU "Software\Valve\Steam" "SourceModInstallPath"
Push $INSTDIR
Call GetParent
Pop $INSTDIR
StrCpy $INSTDIR "$INSTDIR\<<ACCOUNTNAME>>\counter-strike source\cstrike"
instDirFound:


This first uses ModInstallPath (which will exist if user has Half-Life 1 installed) or SourceModInstallPath for Half-Life 2.
ModInstallPath will contain the Steam account name whereas SourceModInstallPath will not.

Edit: You need GetParent which you can find in NSIS docs or on the archive (http://nsis.sf.net/archive).

-Stu

thx, but
thank you for youre nice help, but i still got a problem:
getparent is this one, isn't it?



Function GetParent

Exch $R0
Push $R1
Push $R2
Push $R3

StrCpy $R1 0
StrLen $R2 $R0

loop:
IntOp $R1 $R1 + 1
IntCmp $R1 $R2 get 0 get
StrCpy $R3 $R0 1 -$R1
StrCmp $R3 "\" get
Goto loop

get:
StrCpy $R0 $R0 -$R1

Pop $R3
Pop $R2
Pop $R1
Exch $R0

FunctionEnd

i couldn't find a DL-link, neither in the archive nor with google. THis code was in the NSIS manual

Youre code has to be in a function, otherwise there is an error.
How shell I use it?
making a function disables the error, but if I use the installer, the directory field is empty.
How to set InstDir or InstDirRegKey ???
thank you 4 everything!!!

Place my code in Function .onInit

Function .onInit
...
FunctionEnd

I did mention NSIS manual (NSIS docs)

-Stu


hey wo it works thanx!!!!!!!!!!!!!!!

just one question left:
isn't there a possibility the program detects the accountname automatically???

its good like that, but i would prefer if the user didn't have to enter his accountname
but - i coul leave it like this, it just would be the PERFECT solution :)

but a big thx 2 u afrow you know how the program works !!!


Here you go:


Function .onInit
Call GetSteamAccountName
Pop $R0
Pop $INSTDIR
StrCmp $R0 "" 0 +4
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "Steam does not appear to be installed!$\r$\n$\r$\nContinue anyway?" IDOK +2
Abort
StrCpy $INSTDIR "C:\Valve\Steam\SteamApps\[ACCOUNT_NAME]"
StrCpy $INSTDIR "$INSTDIR\counter-strike source\cstrike"
FunctionEnd

Function GetSteamAccountName
Push $R0
Push $R1
Push $R2
Push $R3

ReadRegStr $R0 HKCU "Software\Valve\Steam" "SteamExe"
StrCmp $R0 "" error
StrCpy $R1 0
IntOp $R1 $R1 - 1
StrCpy $R2 $R0 1 $R1
StrCmp $R2 "" noAccount
StrCmp $R2 "/" 0 -3
StrCpy $R0 $R0 $R1

StrCpy $R1 0
IntOp $R1 $R1 + 1
StrCpy $R2 $R0 1 -$R1
StrCmp $R2 "" +8
StrCmp $R2 "/" 0 -3
StrCpy $R2 $R0 -$R1
IntOp $R1 $R1 - 1
StrCpy $R3 $R0 "" -$R1
StrCpy $R0 "$R2\$R3"
IntOp $R1 $R1 + 1
Goto -9

FindFirst $R1 $R2 "$R0\steamapps\*.*"
loopFile:
StrCmp $R2 "SourceMods" nextFile
StrCmp $R2 "." nextFile
StrCmp $R2 ".." nextFile

IfFileExists "$R0\steamapps\$R2\*.*" done

nextFile:
ClearErrors
FindNext $R1 $R2
IfErrors 0 loopFile
FindClose $R1

noAccount:
StrCpy $R2 "[ACCOUNT_NAME]"

done:
StrCpy $R1 "$R0\steamapps\$R2"
StrCpy $R0 $R2
Goto +3

noSteam:
StrCpy $R1 ""
StrCpy $R0 ""

Pop $R3
Pop $R2
Exch $R1
Exch
Exch $R0
FunctionEnd


If no account name is found, "[ACCOUNT_NAME]" is used instead (can't use < or > in paths).

Notice that I've got Function .onInit in the new script, so you need to replace the whole of the old .onInit function (including all the code I posted before) with this new code.
I added a message box if Steam is not installed.

The function gets the Steam path from the registry (and has to remove steam.exe from end and convert all / to \) and then it searches the SteamApps folder for any folder other than one called "SourceMods" which will be the account name.

I'll put the script on the archive for others to use.

Usage:
Call GetSteamAccountName
Pop $R0
Pop $R1

Where $R1 is e.g. "d:\games\valve\steam\steamapps\afrow uk" and $R0 is "afrow uk"
Both $R0 or $R1 will be "" if Steam is not installed.

-Stu

wow afrow 4 president!!!!!!!
fantastic!!!

first i got an error, after the installer seemed to be compiled

Processed 1 file, writing output:
Adding plug-ins initializing function... Done!
Error: could not resolve label "error" in function "GetSteamAccountName"
Error - aborting creation process


it only worked after i changed this one:
StrCmp $R0 "" error

to this one:
;StrCmp $R0 "" error

im not sure if your error-message and so work now, I have got 2 PCs, but both with steam installed...

This seems to be the last small bug, the rest is pretty PERFECT!

sry 4 2 posts, I'm not a registered user so I can't edit anything ...
I just wanted to say, that, if i change this:

 StrCmp $R0 "" error

for example to this
 StrCmp $R0 "" rror

the error-message at the end of the compiler was the same, just the error changed to rror

I hope i could help you a little (after you helped me so much!)

Sorry,
StrCmp $R0 "" error
should be
StrCmp $R0 "" noSteam

-Stu