3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 Random portability stuff
23 See comments in porting.h
32 std::string path_data = "../data";
33 std::string path_userdata = "../";
35 void pathRemoveFile(char *path, char delim)
37 // Remove filename and path delimiter
39 for(i = strlen(path)-1; i>=0; i--)
47 void initializePaths()
51 Use relative paths if RUN_IN_PLACE
54 dstream<<"Using relative paths (RUN_IN_PLACE)"<<std::endl;
62 const DWORD buflen = 1000;
66 // Find path of executable and set path_data relative to it
67 len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen);
69 pathRemoveFile(buf, '\\');
71 // Use "./bin/../data"
72 path_data = std::string(buf) + "/../data";
75 path_userdata = std::string(buf) + "/../";
84 // Get path to executable
85 readlink("/proc/self/exe", buf, BUFSIZ);
87 pathRemoveFile(buf, '/');
89 // Use "./bin/../data"
90 path_data = std::string(buf) + "/../data";
93 path_userdata = std::string(buf) + "/../";
98 #elif defined(__APPLE__)
100 //TODO: Get path of executable. This assumes working directory is bin/
101 dstream<<"WARNING: Relative path not properly supported on OS X"
103 path_data = std::string("../data");
104 path_userdata = std::string("../");
108 #else // RUN_IN_PLACE
111 Use platform-specific paths otherwise
114 dstream<<"Using system-wide paths (NOT RUN_IN_PLACE)"<<std::endl;
122 const DWORD buflen = 1000;
126 // Find path of executable and set path_data relative to it
127 len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen);
128 assert(len < buflen);
129 pathRemoveFile(buf, '\\');
131 // Use "./bin/../data"
132 path_data = std::string(buf) + "/../data";
133 //path_data = std::string(buf) + "/../share/" + APPNAME;
135 // Use "C:\Documents and Settings\user\Application Data\<APPNAME>"
136 len = GetEnvironmentVariable("APPDATA", buf, buflen);
137 assert(len < buflen);
138 path_userdata = std::string(buf) + "/" + APPNAME;
146 path_userdata = std::string(getenv("HOME")) + "/." + APPNAME;
147 path_data = std::string(INSTALL_PREFIX) + "/share/" + APPNAME;
152 #elif defined(__APPLE__)
155 path_userdata = std::string(getenv("HOME")) + "/Library/Application Support/" + APPNAME;
156 path_data = std::string("minetest-mac.app/Contents/Resources/data/");
160 #endif // RUN_IN_PLACE
162 dstream<<"path_data = "<<path_data<<std::endl;
163 dstream<<"path_userdata = "<<path_userdata<<std::endl;
166 } //namespace porting