U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ Core » GetExeFilePath() in Linux
Re: GetExeFilePath() in Linux [message #6597 is a reply to message #6411] Mon, 20 November 2006 07:55 Go to previous messageGo to previous message
guido is currently offline  guido
Messages: 169
Registered: April 2006
Experienced Member
Hi,

I think there is a simpler implementation for POSIX.
Acrobat Reader, OpenOffice, Firefox, ROX-Filer.. achieve relocatability by means of a simple shell launcher script:

#!/bin/sh

PROG=SampleApp

APP_DIR=`dirname "$0"`
APP_DIR=`cd "$APP_DIR";pwd`; export APP_DIR

exec "$APP_DIR/SampleApp" "$@"


Then, from inside the app simply
app_dir = strdup(getenv(APP_DIR));


Now I thought, why not port this shell script to C++?:

String GetExeFilePath()
{
	static String exepath;
	ONCELOCK {
		String x = Argv0__;
		if(IsFullPath(x) && FileExists(x))
			exepath = x;
		else {
			String cwd = GetCurrentDirectory();
			String filename = GetFileName(x);
			x = x.Left(x.ReverseFind('/'));
			chdir(ToSystemCharset(x));
			exepath = GetCurrentDirectory() + "/" + filename;
			chdir(ToSystemCharset(cwd));
		}
	}
	return exepath;
}


I don't know if there are tricky circumstances of the environment that would break this, but so far it seems to be working.

Guido
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Double formatting bug?
Next Topic: How to catch keyboard input?
Goto Forum:
  


Current Time: Wed Jul 15 13:54:26 GMT+2 2026

Total time taken to generate the page: 0.00716 seconds