Page 1 of 1
Help! Program Paths!
Posted: Tue Nov 02, 2004 2:51 pm
by Num3
I need help!
Under windows my game seeks the current executable directory for game media, but under linux it doesn't.
I don't wan't to bloat the executable with all the game media included, so i resort to external media packs.
If i run using PBCOMPILER game.pb it loads all media, but if i create a stand alone executable it doesn't...
I know this has to do with the paths you should store things, but i'm a linux newbie and can't get it rigth.
1. Can one define a path for the game directory? Something like Path=/usr/mygame/
2. If not, can anyone tell me how to solve this problem with code?
I've been using a smart routine by Freak, but that does not work under Knoppix, it crashes the game
Maybe on next releases Fred can include the CurrentPath() to both windows and linux, so we can solve this!
Thanks in advance...
Posted: Tue Nov 02, 2004 4:43 pm
by Saboteur
It seems like program is executed from /home/user directory.
Executing the program by command line, it works ok, but executing from desktop, the result is different.
Try:
Code: Select all
examinedirectory(0,".","*")
while(nextdirectoryentry())
file.s+directoryentryname()+chr(10)
wend
messagerequester("Info","Files:"+chr(10)+file)
end
From command line, you must get files from local directory, but from konqueror/nautilus... what do you get? Your /home files?
Somebody asked for a method to read the output from other programs, and that could be a solution. You could execute "pwd" or another utility and capture the exit string in purebasic programs.
Another solution is to write a hide config file in home directory (like .myconfigfile), where you write the true path to your program. And you allways can access to that file ( ./.myconfigfile ).
Posted: Tue Nov 02, 2004 4:58 pm
by Beach
Another solution is to write a hide config file in home directory (like .myconfigfile), where you write the true path to your program. And you allways can access to that file ( ./.myconfigfile ).
You can access the users home dir from any path by using the "~" character. So I would access the above mentioned config file from your app like so:
"~/.myconfigfile"
Posted: Tue Nov 02, 2004 5:12 pm
by Saboteur
Beach wrote:
You can access the users home dir from any path by using the "~" character. So I would access the above mentioned config file from your app like so:
"~/.myconfigfile"
I tried thad, it works by command line, but not in purebasic program. I only get an empty string.

Fred!! is a bug?
Posted: Tue Nov 02, 2004 7:57 pm
by Beach
DOHH! Sorry, I should have tested that first...

Posted: Thu Nov 04, 2004 5:49 pm
by Fred
It's not a bug, from what I know, the '~' shortcut is shell dependant (here you use probably bash). You have to use the correct environment variable to get the user home directory (seems to be PWD).
Posted: Fri Nov 05, 2004 8:39 am
by Num3
PWD does not report to the executable path, seems to vary from profile to profile....
_ (underscore) is the variable that reports the executable path and name e.g. (/usr/bin/myexe)
But has i have told there seems to be diferences on how to get this info from Linux core to Linux core

Posted: Fri Nov 05, 2004 12:39 pm
by freak
PWD returns the current directory, doesn't it?
HOME if for the user directory.
All distributions i used so far had that environment variable present.
Posted: Fri Nov 05, 2004 3:08 pm
by Fred
You're right indeed, PWD is the for current working dir and HOME for the user home directory. My mistake.
Posted: Tue Nov 09, 2004 4:52 pm
by Num3
I just hardcoded the game path to the game....
/usr/games/mygame/
Not very elegant, but it works!
Posted: Tue Nov 09, 2004 4:58 pm
by freak
You said my routine crashes. Did you use this one?
Code: Select all
*home = getenv_("HOME")
If *home
Home$ = PeekS(*home)
Else
Home$ = ""
EndIf
Because that works much better than the one i posted earlier.
You can then set an environment variable to your program's directory,
which the user can change if he wants.
Timo
Posted: Tue Nov 09, 2004 5:59 pm
by Num3
I'll take a look to this linux API call!
From what i've read about it's exactly what i need
Does anyone have an offline API manual for linux !?
Kinda of like win32 help ?
Posted: Thu Nov 11, 2004 4:57 pm
by BasicGuy
I'm a long time (over 9 years now) Linux user and SysAdmin, so please don't take my suggestions in the wrong spirit... 8^)
"but that does not work under Knoppix..."
First, I'd suggest installing a "real" Linux distro, like Red Hat or SuSE, on your computer... Knoppix is nice but is intended more for it's ability to create a friendly desktop than a developers enviroment. It has issues, especially when trying to compile/link source code. The newer mainstream distros have the ability to provide multiboot capabilities at startup. I generally use two HD's, the C drive for M$ and the E drive for Linux.
SuSE has a very nice install suite, is very simple to use and normally the distro I recommend to noobs.
"...but i'm a linux newbie and can't get it right. Does anyone have an offline API manual for linux !?"
As you're new to Linux, I suggest getting a comprehensive book on the subject. Linux is not like M$ and if you realistically expect to accomplish much of anything, you need to know just how different is it. This applies especially to advanced programming techniques like program compilation and linking.
Or, you'll find just about everything you need to know in the 'man' pages. These are documents that describe, in varying detail, the programs that comprise a Linux distro. For instance, you might type at the commandline; 'man bash <return>' or even 'man man' to learn about man pages in general. Under X-Windows, Gnome or the KDE, try typing 'xman' (a graphical man page viewer). If it's installed, it will allow you to access the man pages quite easily.
I would also suggest reading "Learning the BASH shell" from O'Reilly. BASH is generally the default shell enviroment in most Linux'es and quite easy to use. Most problems noobs have can be solved by shell scripting. The problem you describe is solvable by adding your development directory to the $PATH variable (like in M$). If you need it to work dynamically, a simple bash shell script can set the variables for you then invoke the compiler.
Hope this might prove helpful.

Posted: Thu Nov 11, 2004 5:27 pm
by Num3
You're very helpfull BasicGuy, and i took good notes on your considerations...
I've worked around the problem has described above.
The main reason why i use a shake and bake linux distro is because most end users will also use this kind of distro at the begining.
Right know i'm using Mepis Linux (Gentoo), and took me just 5 minutes to install and setup purebasic.
All my cross-platform code worked like a charm
It's obvious i'm not experienced working with linux, so most of my stuff is try and fail. Linux reminds me of Amiga OS architecture, so i'm a bit confortable using it.
The GetWorkingPath() is a long time request of mine, and it would be cool it was built in to purebasic to avoid head haches!
Anyway, i'm very pleased you're onboard, you're experience will sure be welcome!
Posted: Fri Nov 12, 2004 8:30 am
by BasicGuy
Cool! Glad you got it work out!
