00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #define WIN32_LEAN_AND_MEAN
00022
00023 #include <windows.h>
00024
00025 #ifdef HAVE_UNISTD_H
00026 #include <unistd.h>
00027 #endif
00028
00029 static ARGParser aParser;
00030 char scorched3dAppName[128];
00031
00032
00033
00034 int _matherr(struct _exception *e)
00035 {
00036 e;
00037 return 1;
00038 }
00039
00040 void _no_storage()
00041 {
00042 printf("Failed to allocate memory!!");
00043 std::exit(1);
00044 }
00045
00046 void run_main(int argc, char *argv[], OptionsParameters ¶ms)
00047 {
00048 std::set_new_handler(&_no_storage);
00049
00050
00051 S3D::setExeName((const char *) argv[0]);
00052
00053
00054 snprintf(scorched3dAppName, 128, "Scorched3D - Version %s (%s)",
00055 S3D::ScorchedVersion.c_str(), S3D::ScorchedProtocolVersion.c_str());
00056
00057 srand((unsigned)time(0));
00058
00059
00060
00061 if (!OptionEntryHelper::addToArgParser(
00062 params.getOptions(), aParser)) exit(64);
00063 std::list<OptionEntry *>::iterator nonParamItor;
00064 for (nonParamItor = params.getNonParamOptions().begin();
00065 nonParamItor != params.getNonParamOptions().end();
00066 nonParamItor++)
00067 {
00068 OptionEntryString *str = (OptionEntryString *) *nonParamItor;
00069 aParser.addNonParamEntry(
00070 (char *) str->getName(), str,
00071 (char *) str->getDescription());
00072 }
00073 if (!aParser.parse(argc, argv)) exit(64);
00074 S3D::setSettingsDir(params.getSettingsDir());
00075
00076
00077 std::string fileName = S3D::getDataFile("data/autoexec.xml");
00078 FILE *checkfile = fopen(fileName.c_str(), "r");
00079 if (!checkfile)
00080 {
00081
00082 char path[1024];
00083 snprintf(path, sizeof(path), "%s", argv[0]);
00084 char *sep = strrchr(path, '/');
00085 if (sep)
00086 {
00087
00088 *sep = '\0';
00089 #ifdef _WIN32
00090 SetCurrentDirectory(path);
00091 #else
00092 chdir(path);
00093 #endif // _WIN32
00094 }
00095
00096
00097 std::string execFile = S3D::getDataFile("data/autoexec.xml");
00098 checkfile = fopen(execFile.c_str(), "r");
00099 if (!checkfile)
00100 {
00101 #ifdef _WIN32
00102 GetCurrentDirectory(sizeof(path), path);
00103 #else
00104 getcwd(path, sizeof(path));
00105 #endif // _WIN32
00106 std::string dataPath = S3D::getDataFile("data");
00107 S3D::dialogExit(
00108 scorched3dAppName, S3D::formatStringBuffer(
00109 "Error: This game requires the Scorched3D data directory to run.\n"
00110 "Your machine does not appear to have the Scorched3D data directory in\n"
00111 "the required location.\n"
00112 "The data directory is set to \"%s\" which does not exist.\n"
00113 "(Current working directory %s)\n\n"
00114 "If Scorched3D does not run please re-install Scorched3D.",
00115 dataPath.c_str(), path));
00116 }
00117 }
00118 else fclose(checkfile);
00119
00120
00121
00122 ModDirs dirs;
00123 dirs.loadModDirs();
00124
00125 #ifndef _WIN32
00126
00127
00128 signal(SIGPIPE, SIG_IGN);
00129 signal(SIGFPE, SIG_IGN);
00130 #endif
00131
00132 if (setlocale(LC_ALL, "C") == 0)
00133 {
00134 S3D::dialogMessage(
00135 scorched3dAppName,
00136 "Warning: Failed to set client locale");
00137 }
00138 }