Merge lp:~aber/widelands/datadir into lp:widelands

Proposed by David Allwicher
Status: Merged
Merged at revision: 5860
Proposed branch: lp:~aber/widelands/datadir
Merge into: lp:widelands
Diff against target: 103 lines (+36/-27)
2 files modified
src/wlapplication.cc (+35/-27)
src/wlapplication.h (+1/-0)
To merge this branch: bzr merge lp:~aber/widelands/datadir
Reviewer Review Type Date Requested Status
SirVer Approve
Review via email: mp+50547@code.launchpad.net

Description of the change

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.

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

Looks clear enough to me. I vote for inclusion in build 16. I will do the merge myself this evening, if noone complains.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
112{112{
113 try {113 try {
114#ifdef __APPLE__114#ifdef __APPLE__
115 // on mac, the default data dir is relative to the current directory115 // on mac, the default data dir is relative to the executable directory
116 log ("Adding directory:Widelands.app/Contents/Resources/\n");116 std::string s = get_executable_path();
117 g_fs->AddFileSystem117 log("Adding executable directory to search path\n");
118 (FileSystem::Create("Widelands.app/Contents/Resources/"));118 g_fs->AddFileSystem(FileSystem::Create(s));
119#else119#else
120 // first, try the data directory used in the last scons invocation120 // first, try the data directory used in the last scons invocation
121 log ("Adding directory:%s\n", INSTALL_PREFIX "/" INSTALL_DATADIR);121 log ("Adding directory:%s\n", INSTALL_PREFIX "/" INSTALL_DATADIR);
@@ -886,6 +886,35 @@
886}886}
887887
888/**888/**
889 * Returns the widelands executable path.
890 */
891std::string WLApplication::get_executable_path()
892{
893 std::string executabledir;
894#ifdef __APPLE__
895 uint32_t buffersize = 0;
896 _NSGetExecutablePath(NULL, &buffersize);
897 char buffer[buffersize];
898 int32_t check = _NSGetExecutablePath(buffer, &buffersize);
899 if (check != 0) {
900 throw wexception (_("could not find the path of the main executable"));
901 }
902 executabledir = std::string(buffer);
903 executabledir.resize(executabledir.rfind('/') + 1);
904#elif linux
905 char buffer[PATH_MAX];
906 size_t size = readlink("/proc/self/exe", buffer, PATH_MAX);
907 if (size <= 0) {
908 throw wexception (_("could not find the path of the main executable"));
909 }
910 executabledir = std::string(buffer, size);
911 executabledir.resize(executabledir.rfind('/') + 1);
912#endif
913 log("Widelands executable directory: %s\n", executabledir.c_str());
914 return executabledir;
915}
916
917/**
889 * In case that the localedir is defined in a relative manner to the918 * In case that the localedir is defined in a relative manner to the
890 * executable file.919 * executable file.
891 *920 *
@@ -893,34 +922,13 @@
893 */922 */
894std::string WLApplication::find_relative_locale_path(std::string localedir)923std::string WLApplication::find_relative_locale_path(std::string localedir)
895{924{
896#ifdef __APPLE__925#ifndef WIN32
897 if (localedir[0] != '/') {926 if (localedir[0] != '/') {
898 uint32_t buffersize = 0;927 std::string executabledir = get_executable_path();
899 _NSGetExecutablePath(NULL, &buffersize);
900 char buffer[buffersize];
901 int32_t check = _NSGetExecutablePath(buffer, &buffersize);
902 if (check != 0) {
903 throw wexception (_("could not find the path of the main executable"));
904 }
905 std::string executabledir = buffer;
906 executabledir.resize(executabledir.rfind('/') + 1);
907 executabledir+= localedir;928 executabledir+= localedir;
908 log ("localedir: %s\n", executabledir.c_str());929 log ("localedir: %s\n", executabledir.c_str());
909 return executabledir;930 return executabledir;
910 }931 }
911#elif linux
912 if (localedir[0] != '/') {
913 char buffer[PATH_MAX];
914 size_t size = readlink("/proc/self/exe", buffer, PATH_MAX);
915 if (size <= 0) {
916 throw wexception (_("could not find the path of the main executable"));
917 }
918 std::string executabledir(buffer, size);
919 executabledir.resize(executabledir.rfind('/') + 1);
920 executabledir += localedir;
921 log ("localedir : %s\n", executabledir.c_str());
922 return executabledir;
923 }
924#endif932#endif
925 return localedir;933 return localedir;
926}934}
927935
=== 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 @@
224 bool init_settings();224 bool init_settings();
225 void init_language();225 void init_language();
226 std::string find_relative_locale_path(std::string localedir);226 std::string find_relative_locale_path(std::string localedir);
227 std::string get_executable_path();
227 void shutdown_settings();228 void shutdown_settings();
228229
229 bool init_hardware();230 bool init_hardware();

Subscribers

People subscribed via source and target branches

to status/vote changes: