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
31 std::string path_data = "../data";
32 std::string path_userdata = "../";
34 void pathRemoveFile(char *path, char delim)
36 // Remove filename and path delimiter
38 for(i = strlen(path)-1; i>=0; i--)
46 void initializePaths()
50 Use relative paths if RUN_IN_PLACE
53 dstream<<"Using relative paths (RUN_IN_PLACE)"<<std::endl;
61 const DWORD buflen = 1000;
65 // Find path of executable and set path_data relative to it
66 len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen);
68 pathRemoveFile(buf, '\\');
70 // Use "./bin/../data"
71 path_data = std::string(buf) + "/../data";
74 path_userdata = std::string(buf) + "/../";
83 // Get path to executable
84 readlink("/proc/self/exe", buf, BUFSIZ);
86 pathRemoveFile(buf, '/');
88 // Use "./bin/../data"
89 path_data = std::string(buf) + "/../data";
92 path_userdata = std::string(buf) + "/../";
97 #elif defined(__APPLE__)
99 //TODO: Get path of executable. This assumes working directory is bin/
100 dstream<<"WARNING: Relative path not properly supported on OS X"
102 path_data = std::string("../data");
103 path_userdata = std::string("../");
108 Use platform-specific paths otherwise
111 dstream<<"Using system-wide paths (NOT RUN_IN_PLACE)"<<std::endl;
119 const DWORD buflen = 1000;
123 // Find path of executable and set path_data relative to it
124 len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen);
125 assert(len < buflen);
126 pathRemoveFile(buf, '\\');
128 // Use "./bin/../data"
129 path_data = std::string(buf) + "/../data";
131 // Use "C:\Documents and Settings\user\Application Data\<APPNAME>"
132 len = GetEnvironmentVariable("APPDATA", buf, buflen);
133 assert(len < buflen);
134 path_userdata = std::string(buf) + "/" + APPNAME;
141 path_userdata = std::string("~/.") + APPNAME;
142 path_data = std::string("/usr/share/") + APPNAME;
147 #elif defined(__APPLE__)
149 path_userdata = std::string("~/Library/Application Support/") + APPNAME;
150 path_data = std::string("minetest-mac.app/Contents/Resources/data/");
155 dstream<<"path_data = "<<path_data<<std::endl;
156 dstream<<"path_userdata = "<<path_userdata<<std::endl;
159 } //namespace porting