Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Core - App.cpp - GetDataFile
icon13.gif  Core - App.cpp - GetDataFile [message #3172] Tue, 09 May 2006 21:48 Go to next message
3togo is currently offline  3togo
Messages: 83
Registered: May 2006
Location: Hong Kong SAR
Member
I think that no matter exec program is running under posix or windows, GetDataFile should always get the current working directory(getcwd) and concat with *filename.

However, the present release behaves differently on these two different systems.

I suggest replace GetHomeDirectory() below with GetCWD()

String& GetCWD() {
char buffer[100];
int size = 100;
getcwd(buffer,size);
static String ss;
ss.Cat(buffer);
return ss;

}

Regards,

3togo

************************************************************
App.cpp
************************************************************ *
String GetDataFile(const char *filename)
{
String s = Environment().Get("UPP_MAIN__",
#ifdef PLATFORM_WIN32
GetFileFolder(GetExeFilePath())
#endif
#ifdef PLATFORM_POSIX
GetHomeDirectory()
#endif
);

return AppendFileName(s, filename);
}

[Updated on: Tue, 09 May 2006 22:03]

Report message to a moderator

Re: Core - App.cpp - GetDataFile [message #3174 is a reply to message #3172] Tue, 09 May 2006 23:14 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
3togo wrote on Tue, 09 May 2006 15:48

I think that no matter exec program is running under posix or windows, GetDataFile should always get the current working directory(getcwd) and concat with *filename.



What makes you think so? Wink

GetDataFile is intended for files that are shipped with application. The most logical place in Win32 is therefore the same dir as where .exe resides (in Linux this is still to be decided, however I am starting to think that GetExeDirFile would be a good idea even in linux, despite being against current linux conventions).

For development purposes, there is a hack that allows you to place those app specific files in package folder (for easier maintainance) and U++ takes them from there when started from TheIDE (that is what that environment variable is for).

Mirek
Re: Core - App.cpp - GetDataFile [message #3178 is a reply to message #3174] Wed, 10 May 2006 04:27 Go to previous messageGo to next message
3togo is currently offline  3togo
Messages: 83
Registered: May 2006
Location: Hong Kong SAR
Member
Below is a directory listing of /usr/local/bin. You could find that most of the programs nowaday like crossover, quake and etc place a symbolic link in /usr/local/bin only while keeping the data files within the same folder with their "exe" programs.

Therefore, GetExeDirFile would be a good idea even in linux and is not against current linux conventions.

3togo


[root@localhost Desktop]# cd /usr/local/bin
[root@localhost bin]# ls -l
total 11416
-rwxr-xr-x 1 root root 4072346 Apr 21 03:04 dboxfe*
lrwxrwxrwx 1 root root 35 Apr 17 03:21 et -> /usr/local/games/enemy-territ ory/et*
-rwxr-xr-x 1 root root 402 Apr 28 13:04 et~*
lrwxrwxrwx 1 root root 38 Apr 17 03:21 etded -> /usr/local/games/enemy-ter ritory/etded*
-rwxr-xr-x 1 root root 109686 Apr 28 13:00 etswitch*
lrwxrwxrwx 1 root root 29 Apr 30 11:33 findwine -> /usr/local/winetools/fi ndwine*
-rwxr-xr-x 1 root root 241 Apr 28 17:11 jmware*
-rwxr-xr-x 1 root root 241 Apr 27 03:57 jmware~*
-rwxr-xr-x 1 root root 52 Apr 28 23:35 jupdate*
-rwxr-xr-x 1 root root 339276 May 10 10:11 mj*
-rwxr-xr-x 1 root root 69 Apr 17 03:27 ossfix*
lrwxrwxrwx 1 root root 30 Apr 28 08:22 quake4 -> /usr/local/games/quake4/q uake4
lrwxrwxrwx 1 root root 40 Apr 28 08:22 quake4-dedicated -> /usr/local/game s/quake4/quake4-dedicated
-rwxr-xr-x 1 root root 7117860 May 4 18:53 theide*
lrwxrwxrwx 1 root root 28 Apr 30 11:33 winetools -> /usr/local/winetools/w t0.9jo*
lrwxrwxrwx 1 root root 28 Apr 30 11:33 wt -> /usr/local/winetools/wt0.9jo*
[root@localhost bin]#

Re: Core - App.cpp - GetDataFile [message #3180 is a reply to message #3178] Wed, 10 May 2006 07:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
3togo wrote on Tue, 09 May 2006 22:27

Below is a directory listing of /usr/local/bin. You could find that most of the programs nowaday like crossover, quake and etc place a symbolic link in /usr/local/bin only while keeping the data files within the same folder with their "exe" programs.

Therefore, GetExeDirFile would be a good idea even in linux and is not against current linux conventions.

3togo


[root@localhost Desktop]# cd /usr/local/bin
[root@localhost bin]# ls -l
total 11416
-rwxr-xr-x 1 root root 4072346 Apr 21 03:04 dboxfe*
lrwxrwxrwx 1 root root 35 Apr 17 03:21 et -> /usr/local/games/enemy-territ ory/et*
-rwxr-xr-x 1 root root 402 Apr 28 13:04 et~*
lrwxrwxrwx 1 root root 38 Apr 17 03:21 etded -> /usr/local/games/enemy-ter ritory/etded*
-rwxr-xr-x 1 root root 109686 Apr 28 13:00 etswitch*
lrwxrwxrwx 1 root root 29 Apr 30 11:33 findwine -> /usr/local/winetools/fi ndwine*
-rwxr-xr-x 1 root root 241 Apr 28 17:11 jmware*
-rwxr-xr-x 1 root root 241 Apr 27 03:57 jmware~*
-rwxr-xr-x 1 root root 52 Apr 28 23:35 jupdate*
-rwxr-xr-x 1 root root 339276 May 10 10:11 mj*
-rwxr-xr-x 1 root root 69 Apr 17 03:27 ossfix*
lrwxrwxrwx 1 root root 30 Apr 28 08:22 quake4 -> /usr/local/games/quake4/q uake4
lrwxrwxrwx 1 root root 40 Apr 28 08:22 quake4-dedicated -> /usr/local/game s/quake4/quake4-dedicated
-rwxr-xr-x 1 root root 7117860 May 4 18:53 theide*
lrwxrwxrwx 1 root root 28 Apr 30 11:33 winetools -> /usr/local/winetools/w t0.9jo*
lrwxrwxrwx 1 root root 28 Apr 30 11:33 wt -> /usr/local/winetools/wt0.9jo*
[root@localhost bin]#




Thanks Wink

Well, then the only problem is implementation - that really is quite complex in Linux AFAIK (I am afraid you have to duplicate the PATH searching process and follow that link....)

Mirek
Re: Core - App.cpp - GetDataFile [message #3193 is a reply to message #3174] Thu, 11 May 2006 13:24 Go to previous message
guido is currently offline  guido
Messages: 169
Registered: April 2006
Experienced Member
The POSIX convention is ../share/<appname> relativ to the executable. But as the exe could be symlinked, you need to call realpath() to resolve the symlink:


http://www.opengroup.org/onlinepubs/7990989775/xsh/realpath. html

Both Gnome and KDE have an API for resource location.
In the case of KDE you can add the datadir to the KDEDIRS env variable (in an startup script), to make the app relocatable.
Most Gnome apps are sadly not relocatable at all. Even though Gnome has an API for that, most programmers don't bother and simply hardcode the pathes through the standard autotools mechanism (DATADIR, LOCALEDIR...).
Previous Topic: TrayIcon for linux
Next Topic: how to listnen to File System Events?
Goto Forum:
  


Current Time: Thu Mar 28 19:02:57 CET 2024

Total time taken to generate the page: 0.01167 seconds