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
1=== modified file 'src/wlapplication.cc'
2--- src/wlapplication.cc 2011-02-19 14:30:12 +0000
3+++ src/wlapplication.cc 2011-02-21 04:08:04 +0000
4@@ -112,10 +112,10 @@
5 {
6 try {
7 #ifdef __APPLE__
8- // on mac, the default data dir is relative to the current directory
9- log ("Adding directory:Widelands.app/Contents/Resources/\n");
10- g_fs->AddFileSystem
11- (FileSystem::Create("Widelands.app/Contents/Resources/"));
12+ // on mac, the default data dir is relative to the executable directory
13+ std::string s = get_executable_path();
14+ log("Adding executable directory to search path\n");
15+ g_fs->AddFileSystem(FileSystem::Create(s));
16 #else
17 // first, try the data directory used in the last scons invocation
18 log ("Adding directory:%s\n", INSTALL_PREFIX "/" INSTALL_DATADIR);
19@@ -886,6 +886,35 @@
20 }
21
22 /**
23+ * Returns the widelands executable path.
24+ */
25+std::string WLApplication::get_executable_path()
26+{
27+ std::string executabledir;
28+#ifdef __APPLE__
29+ uint32_t buffersize = 0;
30+ _NSGetExecutablePath(NULL, &buffersize);
31+ char buffer[buffersize];
32+ int32_t check = _NSGetExecutablePath(buffer, &buffersize);
33+ if (check != 0) {
34+ throw wexception (_("could not find the path of the main executable"));
35+ }
36+ executabledir = std::string(buffer);
37+ executabledir.resize(executabledir.rfind('/') + 1);
38+#elif linux
39+ char buffer[PATH_MAX];
40+ size_t size = readlink("/proc/self/exe", buffer, PATH_MAX);
41+ if (size <= 0) {
42+ throw wexception (_("could not find the path of the main executable"));
43+ }
44+ executabledir = std::string(buffer, size);
45+ executabledir.resize(executabledir.rfind('/') + 1);
46+#endif
47+ log("Widelands executable directory: %s\n", executabledir.c_str());
48+ return executabledir;
49+}
50+
51+/**
52 * In case that the localedir is defined in a relative manner to the
53 * executable file.
54 *
55@@ -893,34 +922,13 @@
56 */
57 std::string WLApplication::find_relative_locale_path(std::string localedir)
58 {
59-#ifdef __APPLE__
60+#ifndef WIN32
61 if (localedir[0] != '/') {
62- uint32_t buffersize = 0;
63- _NSGetExecutablePath(NULL, &buffersize);
64- char buffer[buffersize];
65- int32_t check = _NSGetExecutablePath(buffer, &buffersize);
66- if (check != 0) {
67- throw wexception (_("could not find the path of the main executable"));
68- }
69- std::string executabledir = buffer;
70- executabledir.resize(executabledir.rfind('/') + 1);
71+ std::string executabledir = get_executable_path();
72 executabledir+= localedir;
73 log ("localedir: %s\n", executabledir.c_str());
74 return executabledir;
75 }
76-#elif linux
77- if (localedir[0] != '/') {
78- char buffer[PATH_MAX];
79- size_t size = readlink("/proc/self/exe", buffer, PATH_MAX);
80- if (size <= 0) {
81- throw wexception (_("could not find the path of the main executable"));
82- }
83- std::string executabledir(buffer, size);
84- executabledir.resize(executabledir.rfind('/') + 1);
85- executabledir += localedir;
86- log ("localedir : %s\n", executabledir.c_str());
87- return executabledir;
88- }
89 #endif
90 return localedir;
91 }
92
93=== modified file 'src/wlapplication.h'
94--- src/wlapplication.h 2011-02-13 16:14:23 +0000
95+++ src/wlapplication.h 2011-02-21 04:08:04 +0000
96@@ -224,6 +224,7 @@
97 bool init_settings();
98 void init_language();
99 std::string find_relative_locale_path(std::string localedir);
100+ std::string get_executable_path();
101 void shutdown_settings();
102
103 bool init_hardware();

Subscribers

People subscribed via source and target branches

to status/vote changes: