1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2003
4 // This file is part of Scorched3D.
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
25 #include <common/DefinesScorched.h>
26 #include <common/DefinesFile.h>
27 #include <common/DefinesString.h>
28 #include <common/DefinesAssert.h>
29 #include <common/Logger.h>
30 #define WIN32_LEAN_AND_MEAN
33 #pragma warning(disable : 4996)
39 unsigned int S3D::ScorchedPort
= 27270;
40 std::string
S3D::ScorchedVersion
= "42";
41 std::string
S3D::ScorchedProtocolVersion
= "ea";
43 std::string
S3D::ScorchedBuildTime
= __DATE__
;
45 std::string
S3D::ScorchedBuildTime
= "Unknown";
47 static std::string exeName
;
48 static std::string dataModFile
= "none";
49 static std::string settingsDir
= ".scorched3d";
51 void S3D::showURL(const std::string
&url
)
54 std::string buffer
= S3D::formatStringBuffer("explorer %s", url
.c_str());
55 WinExec(buffer
.c_str() ,SW_SHOWDEFAULT
);
58 std::string buffer
= S3D::formatStringBuffer("open %s", url
.c_str());
59 system(buffer
.c_str());
61 std::string buffer
= S3D::formatStringBuffer("firefox %s", url
.c_str());
62 system(buffer
.c_str());
68 void S3D::setExeName(const std::string
&name
)
73 std::string
S3D::getExeName()
78 std::string
S3D::getStartTime()
80 static std::string startTime
;
81 if (startTime
.empty())
83 time_t theTime
= time(0);
84 startTime
= ctime(&theTime
);
89 void S3D::setSettingsDir(const std::string
&dir
)
94 void S3D::setDataFileMod(const std::string
&mod
)
99 std::string
S3D::getDataFileMod()
105 #define S3D_DATADIR "."
108 #define S3D_DOCDIR "./documentation"
111 #define S3D_BINDIR "."
114 static const char *GET_DIR(const char *dir
)
118 static char path
[1024];
120 GetCurrentDirectory(sizeof(path
), path
);
122 getcwd(path
, sizeof(path
));
124 if (strlen(path
) + strlen(dir
) + 1 < sizeof(path
))
134 std::string
S3D::getDataFile(const std::string
&filename
)
138 buffer
= S3D::getModFile(
139 S3D::formatStringBuffer("%s/%s", dataModFile
.c_str(), filename
.c_str()));
140 S3D::fileDos2Unix(buffer
);
141 if (S3D::fileExists(buffer
)) return buffer
;
143 buffer
= S3D::getGlobalModFile(
144 S3D::formatStringBuffer("%s/%s", dataModFile
.c_str(), filename
.c_str()));
145 S3D::fileDos2Unix(buffer
);
146 if (S3D::fileExists(buffer
)) return buffer
;
148 buffer
= S3D::formatStringBuffer("%s/%s", GET_DIR(S3D_DATADIR
), filename
.c_str());
149 S3D::fileDos2Unix(buffer
);
154 extern bool S3D::checkDataFile(const std::string
&filename
)
156 std::string dataFileName
= S3D::getDataFile(filename
);
157 if (!S3D::fileExists(dataFileName
))
159 if (0 == strstr(filename
.c_str(), "none"))
161 S3D::dialogMessage("Scorched3D", S3D::formatStringBuffer(
162 "The file \"%s\" does not exist",
163 dataFileName
.c_str()));
170 std::string
S3D::getDocFile(const std::string
&filename
)
173 S3D::formatStringBuffer("%s/%s", GET_DIR(S3D_DOCDIR
), filename
.c_str());
174 S3D::fileDos2Unix(buffer
);
178 std::string
S3D::getHomeFile(const std::string
&filename
)
180 static std::string homeDir
;
181 if (!homeDir
.c_str()[0])
183 homeDir
= GET_DIR(S3D_DATADIR
);
184 if (S3D::dirExists(S3D::getHomeDir()))
186 homeDir
= S3D::getHomeDir();
190 std::string buffer
= S3D::formatStringBuffer(
191 "%s/%s", homeDir
.c_str(), filename
.c_str());
192 S3D::fileDos2Unix(buffer
);
196 std::string
S3D::getSettingsFile(const std::string
&filename
)
198 static std::string homeDir
;
199 if (!homeDir
.c_str()[0])
201 std::string homeDirStr
= S3D::getHomeFile(
202 S3D::formatStringBuffer("/%s", settingsDir
.c_str()));
203 if (!S3D::dirExists(homeDirStr
))
205 if (!S3D::dirMake(homeDirStr
))
207 homeDirStr
= S3D::getHomeFile("");
210 homeDir
= homeDirStr
;
213 std::string buffer
= S3D::formatStringBuffer(
214 "%s/%s", homeDir
.c_str(), filename
.c_str());
215 S3D::fileDos2Unix(buffer
);
219 std::string
S3D::getLogFile(const std::string
&filename
)
221 std::string homeDirStr
= S3D::getSettingsFile("");
222 std::string
newDir(std::string(homeDirStr
) + std::string("/logs"));
223 if (S3D::dirExists(newDir
)) homeDirStr
= newDir
;
224 else if (S3D::dirMake(newDir
)) homeDirStr
= newDir
;
226 std::string buffer
= S3D::formatStringBuffer(
227 "%s/%s", homeDirStr
.c_str(), filename
.c_str());
228 S3D::fileDos2Unix(buffer
);
232 std::string
S3D::getSaveFile(const std::string
&filename
)
234 std::string homeDirStr
= S3D::getSettingsFile("");
235 std::string
newDir(std::string(homeDirStr
) + std::string("/saves"));
236 if (S3D::dirExists(newDir
)) homeDirStr
= newDir
;
237 else if (S3D::dirMake(newDir
)) homeDirStr
= newDir
;
239 std::string buffer
= S3D::formatStringBuffer(
240 "%s/%s", homeDirStr
.c_str(), filename
.c_str());
241 S3D::fileDos2Unix(buffer
);
245 std::string
S3D::getModFile(const std::string
&filename
)
247 static std::string modDir
;
248 if (!modDir
.c_str()[0])
250 std::string homeDirStr
= S3D::getSettingsFile("");
251 std::string
newDir(std::string(homeDirStr
) + std::string("/mods"));
252 if (S3D::dirExists(newDir
)) homeDirStr
= newDir
;
253 else if (S3D::dirMake(newDir
)) homeDirStr
= newDir
;
258 std::string buffer
= S3D::formatStringBuffer(
259 "%s/%s", modDir
.c_str(), filename
.c_str());
260 S3D::fileDos2Unix(buffer
);
264 std::string
S3D::getGlobalModFile(const std::string
&filename
)
266 std::string buffer
= S3D::formatStringBuffer(
267 "%s/data/globalmods/%s", GET_DIR(S3D_DATADIR
), filename
.c_str());
268 S3D::fileDos2Unix(buffer
);