Crystal Space
Welcome, Guest. Please login or register.
July 30, 2014, 04:10:46 am

Login with username, password and session length
Search:     Advanced search
9005 Posts in 2043 Topics by 8256 Members
Latest Member: Lrusshan091
* Home Help Search Login Register
+  Crystal Space
|-+  Miscellaneous
| |-+  Article/Tutorial Requests
| | |-+  Crystal environment variable
« previous next »
Pages: [1] Print
Author Topic: Crystal environment variable  (Read 4353 times)
DaHoC
Newbie
*
Posts: 4


View Profile WWW
« on: August 27, 2005, 07:48:46 pm »

Hi,
I think it would be a good idea to explain how to change/access the CRYSTAL or CEL environment variables since that is needed if a CS game is released. The variables should be changeable internally so the real system variables remain untouched.
The aim is that if a CS game is shipped, a user who has a CRYSTAL var set different to the CS game specific directory, the game probably will not run/work properly (I noticed that several times now). That should not be too tricky, but I don't have a clue.
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #1 on: August 28, 2005, 08:30:54 pm »

Hi,
I think it would be a good idea to explain how to change/access the CRYSTAL or CEL environment variables since that is needed if a CS game is released. The variables should be changeable internally so the real system variables remain untouched.
The aim is that if a CS game is shipped, a user who has a CRYSTAL var set different to the CS game specific directory, the game probably will not run/work properly (I noticed that several times now). That should not be too tricky, but I don't have a clue.


That's just a standard C function call: 'setenv'.

Greetings,
Logged
mark
Full Member
***
Posts: 101


View Profile
« Reply #2 on: August 29, 2005, 10:15:54 am »

yes, you can do this with C. This is how I have done it:

Code:
int main(int argc, char* argv[]) {
    std::string dir;
    char* pfadname = new char[PATH_MAX];
    dir = getcwd(pfadname, PATH_MAX);
    delete [] pfadname;

#ifdef _WIN32

    setenv("CRYSTAL",(dir+"\\lib\\crystalspace").c_str(),1);
    setenv("CEL",(dir+"\\lib\\cel").c_str(),1);
#else

    setenv("CRYSTAL",(dir+"/lib/crystalspace").c_str(),1);
    setenv("CEL",(dir+"/lib/cel").c_str(),1);
#endif

    int retval = Starter().Main(argc, argv); // start csApplicationFramework
    putenv("CRYSTAL=");
    putenv("CEL=");
    return retval;
}
notice that you must not use any CS datatypes, functions etc pp because CRYSTAL isn't set before this code.
Also notice that you must use getcwd if you want to stay OS independent (Win32+Linux, I don't know if it works on Mac though it should).
When you're using getcwd you must start your application from within the directory in which the binary lies, or else "dir" will be set wrong.
The function realpath is much better than getcwd, because it gets the real path for the binary - but MinGW doesn't support this (though it's POSIX).
Also notice that you must use putenv to unset the variables, not unsetenv - yes, because that crappy Redmond "OS" doesn't support this neither.

Maybe you have to include limits.h, though it works without that on my systems.
Logged

Gentoo Linux ~x86, kernel 2.6.11-cko9 smp, gcc 3.4.4-r1, binutils 2.16.1, glibc 2.3.5 NPTL
CS+CEL Pseudo Stable 2005.09.03
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 7.339 seconds with 17 queries.