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
33 Signal handler (grabs Ctrl-C on POSIX systems)
36 bool g_killed = false;
38 bool * signal_handler_killstatus(void)
43 #if !defined(_WIN32) // POSIX
46 void sigint_handler(int sig)
50 dstream<<DTIME<<"sigint_handler(): "
51 <<"Ctrl-C pressed, shutting down."<<std::endl;
56 (void)signal(SIGINT, SIG_DFL);
60 void signal_handler_init(void)
62 dstream<<"signal_handler_init()"<<std::endl;
63 (void)signal(SIGINT, sigint_handler);
68 void signal_handler_init(void)
79 std::string path_data = "../data";
80 std::string path_userdata = "../";
82 void pathRemoveFile(char *path, char delim)
84 // Remove filename and path delimiter
86 for(i = strlen(path)-1; i>=0; i--)
94 void initializePaths()
98 Use relative paths if RUN_IN_PLACE
101 dstream<<"Using relative paths (RUN_IN_PLACE)"<<std::endl;
109 const DWORD buflen = 1000;
113 // Find path of executable and set path_data relative to it
114 len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen);
115 assert(len < buflen);
116 pathRemoveFile(buf, '\\');
118 // Use "./bin/../data"
119 path_data = std::string(buf) + "/../data";
122 path_userdata = std::string(buf) + "/../";
131 memset(buf, 0, BUFSIZ);
132 // Get path to executable
133 readlink("/proc/self/exe", buf, BUFSIZ-1);
135 pathRemoveFile(buf, '/');
137 // Use "./bin/../data"
138 path_data = std::string(buf) + "/../data";
141 path_userdata = std::string(buf) + "/../";
146 #elif defined(__APPLE__)
148 //TODO: Get path of executable. This assumes working directory is bin/
149 dstream<<"WARNING: Relative path not properly supported on OS X"
151 path_data = std::string("../data");
152 path_userdata = std::string("../");
156 #else // RUN_IN_PLACE
159 Use platform-specific paths otherwise
162 dstream<<"Using system-wide paths (NOT RUN_IN_PLACE)"<<std::endl;
170 const DWORD buflen = 1000;
174 // Find path of executable and set path_data relative to it
175 len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen);
176 assert(len < buflen);
177 pathRemoveFile(buf, '\\');
179 // Use "./bin/../data"
180 path_data = std::string(buf) + "/../data";
181 //path_data = std::string(buf) + "/../share/" + APPNAME;
183 // Use "C:\Documents and Settings\user\Application Data\<APPNAME>"
184 len = GetEnvironmentVariable("APPDATA", buf, buflen);
185 assert(len < buflen);
186 path_userdata = std::string(buf) + "/" + APPNAME;
195 memset(buf, 0, BUFSIZ);
196 // Get path to executable
197 readlink("/proc/self/exe", buf, BUFSIZ-1);
199 pathRemoveFile(buf, '/');
201 path_data = std::string(buf) + "/../share/" + APPNAME;
202 //path_data = std::string(INSTALL_PREFIX) + "/share/" + APPNAME;
204 path_userdata = std::string(getenv("HOME")) + "/." + APPNAME;
209 #elif defined(__APPLE__)
212 path_userdata = std::string(getenv("HOME")) + "/Library/Application Support/" + APPNAME;
213 path_data = std::string("minetest-mac.app/Contents/Resources/data/");
217 #endif // RUN_IN_PLACE
219 dstream<<"path_data = "<<path_data<<std::endl;
220 dstream<<"path_userdata = "<<path_userdata<<std::endl;
223 } //namespace porting