Help! Program Paths!
-
- PureBasic Expert
- Posts: 2810
- Joined: Fri Apr 25, 2003 4:51 pm
- Location: Portugal, Lisbon
- Contact:
Help! Program Paths!
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...
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...
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:
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 ).
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
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 ).
[:: PB Registered ::]
Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
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: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 ).
"~/.myconfigfile"
-Beach
I tried thad, it works by command line, but not in purebasic program. I only get an empty string. Fred!! is a bug?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"
[:: PB Registered ::]
Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
You said my routine crashes. Did you use this one?
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
Code: Select all
*home = getenv_("HOME")
If *home
Home$ = PeekS(*home)
Else
Home$ = ""
EndIf
You can then set an environment variable to your program's directory,
which the user can change if he wants.
Timo
quidquid Latine dictum sit altum videtur
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.
"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.
-
- PureBasic Expert
- Posts: 2810
- Joined: Fri Apr 25, 2003 4:51 pm
- Location: Portugal, Lisbon
- Contact:
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!
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!