widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #00245
[Merge] lp:~aber/widelands/datadir into lp:widelands
David Allwicher has proposed merging lp:~aber/widelands/datadir into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~aber/widelands/datadir/+merge/50547
A short recapitulation of the problem. If you start widelands in a different way then ./widelands it will not find the datadir and crash (Mac OS X). Also, if someone would use a pointing device. This problem occured also in build15 with the locale directory.
I always asked myself, why it was possible to detect the data directory but not the locale directory. Now widelands is not more able to find the data directory.
I will try to apply the same fix as currently used for the locale problem.
A. Please take a look at my code. I'm still unsecure writing c++ code.
B. Maybe someone knows how it was possible to detect the datadir with the portable or non absolute setup. Maybe it is possible to remove all that platform dependend code again.
--
https://code.launchpad.net/~aber/widelands/datadir/+merge/50547
Your team Widelands Developers is requested to review the proposed merge of lp:~aber/widelands/datadir into lp:widelands.
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc 2011-02-19 14:30:12 +0000
+++ src/wlapplication.cc 2011-02-21 04:08:04 +0000
@@ -112,10 +112,10 @@
{
try {
#ifdef __APPLE__
- // on mac, the default data dir is relative to the current directory
- log ("Adding directory:Widelands.app/Contents/Resources/\n");
- g_fs->AddFileSystem
- (FileSystem::Create("Widelands.app/Contents/Resources/"));
+ // on mac, the default data dir is relative to the executable directory
+ std::string s = get_executable_path();
+ log("Adding executable directory to search path\n");
+ g_fs->AddFileSystem(FileSystem::Create(s));
#else
// first, try the data directory used in the last scons invocation
log ("Adding directory:%s\n", INSTALL_PREFIX "/" INSTALL_DATADIR);
@@ -886,6 +886,35 @@
}
/**
+ * Returns the widelands executable path.
+ */
+std::string WLApplication::get_executable_path()
+{
+ std::string executabledir;
+#ifdef __APPLE__
+ uint32_t buffersize = 0;
+ _NSGetExecutablePath(NULL, &buffersize);
+ char buffer[buffersize];
+ int32_t check = _NSGetExecutablePath(buffer, &buffersize);
+ if (check != 0) {
+ throw wexception (_("could not find the path of the main executable"));
+ }
+ executabledir = std::string(buffer);
+ executabledir.resize(executabledir.rfind('/') + 1);
+#elif linux
+ char buffer[PATH_MAX];
+ size_t size = readlink("/proc/self/exe", buffer, PATH_MAX);
+ if (size <= 0) {
+ throw wexception (_("could not find the path of the main executable"));
+ }
+ executabledir = std::string(buffer, size);
+ executabledir.resize(executabledir.rfind('/') + 1);
+#endif
+ log("Widelands executable directory: %s\n", executabledir.c_str());
+ return executabledir;
+}
+
+/**
* In case that the localedir is defined in a relative manner to the
* executable file.
*
@@ -893,34 +922,13 @@
*/
std::string WLApplication::find_relative_locale_path(std::string localedir)
{
-#ifdef __APPLE__
+#ifndef WIN32
if (localedir[0] != '/') {
- uint32_t buffersize = 0;
- _NSGetExecutablePath(NULL, &buffersize);
- char buffer[buffersize];
- int32_t check = _NSGetExecutablePath(buffer, &buffersize);
- if (check != 0) {
- throw wexception (_("could not find the path of the main executable"));
- }
- std::string executabledir = buffer;
- executabledir.resize(executabledir.rfind('/') + 1);
+ std::string executabledir = get_executable_path();
executabledir+= localedir;
log ("localedir: %s\n", executabledir.c_str());
return executabledir;
}
-#elif linux
- if (localedir[0] != '/') {
- char buffer[PATH_MAX];
- size_t size = readlink("/proc/self/exe", buffer, PATH_MAX);
- if (size <= 0) {
- throw wexception (_("could not find the path of the main executable"));
- }
- std::string executabledir(buffer, size);
- executabledir.resize(executabledir.rfind('/') + 1);
- executabledir += localedir;
- log ("localedir : %s\n", executabledir.c_str());
- return executabledir;
- }
#endif
return localedir;
}
=== modified file 'src/wlapplication.h'
--- src/wlapplication.h 2011-02-13 16:14:23 +0000
+++ src/wlapplication.h 2011-02-21 04:08:04 +0000
@@ -224,6 +224,7 @@
bool init_settings();
void init_language();
std::string find_relative_locale_path(std::string localedir);
+ std::string get_executable_path();
void shutdown_settings();
bool init_hardware();