Entry point for Linux and Windows systems. Initializes logging. If -load is passed, the argument after that is loaded as savegame.
69{
70#ifdef GNUSTEP_BASE_LIBRARY
71 int i;
72
73#if (GNUSTEP_BASE_MAJOR_VERSION == 1 && (GNUSTEP_BASE_MINOR_VERSION == 24 && GNUSTEP_BASE_SUBMINOR_VERSION >= 9) || (GNUSTEP_BASE_MINOR_VERSION > 24)) || (GNUSTEP_BASE_MAJOR_VERSION > 1)
74 [NSDate class];
75#endif
76
77#if OOLITE_WINDOWS
78
79 #define OO_SHOW_MSG(ooMsg, ooMsgTitle, ooMsgFlags) MessageBox(NULL, ooMsg, ooMsgTitle, ooMsgFlags)
80 #define TABS1 "\t"
81 #define TABS2 "\t\t"
82 #define TABS3 "\t\t\t"
83 #define TABS4 ""
84
85
86 #define MAX_PATH_LEN 256
87 char currentWorkingDir[MAX_PATH_LEN];
88 DWORD bufferSize = MAX_PATH_LEN;
89
90 QueryFullProcessImageName(GetCurrentProcess(), 0, currentWorkingDir, &bufferSize);
91
92 char *probeString = strrchr(currentWorkingDir, '\\');
93 if (probeString) *probeString = '\0';
94
95
96 char *pathEnvVar = "Path";
97 const char *systemPath = SDL_getenv(pathEnvVar);
98 if (!systemPath)
99 {
100 pathEnvVar = "PATH";
101 systemPath = SDL_getenv(pathEnvVar);
102 }
103 size_t currentWorkingDirLen = strlen(currentWorkingDir);
104 size_t systemPathLen = strlen(systemPath);
105
106
107 char *finalPath = malloc(systemPathLen + currentWorkingDirLen + 2 * sizeof(char));
108 strcpy(finalPath, currentWorkingDir);
109 strcat(finalPath, ";");
110 strcat(finalPath, systemPath);
111
112 SDL_setenv_unsafe("GNUSTEP_PATH_HANDLING", "windows", YES);
113 SDL_setenv_unsafe(pathEnvVar, finalPath, YES);
114 SDL_setenv_unsafe("GNUSTEP_SYSTEM_ROOT", currentWorkingDir, YES);
115 SDL_setenv_unsafe("GNUSTEP_LOCAL_ROOT", currentWorkingDir, YES);
116 SDL_setenv_unsafe("GNUSTEP_NETWORK_ROOT", currentWorkingDir, YES);
117 SDL_setenv_unsafe("GNUSTEP_USERS_ROOT", currentWorkingDir, YES);
118#if OO_GAME_DATA_TO_USER_FOLDER
119 SDL_setenv_unsafe("HOMEPATH", strcat(SDL_getenv("LOCALAPPDATA"), "\\Oolite\\oolite.app"), YES);
120#else
121 SDL_setenv_unsafe("HOMEPATH", currentWorkingDir, YES);
122#endif
123
124 SetCurrentDirectory(currentWorkingDir);
125
126 free(finalPath);
127
128
129
130
131
132 setlocale(LC_ALL, "C");
133
134#else
135 #define OO_SHOW_MSG(ooMsg, ooTitle, ooFlags) fprintf(stdout, "%s", ooMsg)
136 #define TABS1 "\t\t"
137 #define TABS2 "\t\t\t"
138 #define TABS3 "\t\t\t\t"
139 #define TABS4 "\t"
140#endif
141
142
143
144 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
146
147 @try
148 {
149
150
152
153 for (i = 1; i < argc; i++)
154 {
155 if (strcmp("-load", argv[i]) == 0)
156 {
157 i++;
158 }
159 NSString *argument = [NSString stringWithCString:argv[i]];
160 if (i < argc && [[argument lowercaseString] hasSuffix:@".oolite-save"])
161 {
162 [controller setPlayerFileToLoad:argument];
163 }
164
165 if (!strcmp("-help", argv[i]) || !strcmp("--help", argv[i]))
166 {
167 char const *processName = [[[NSProcessInfo processInfo] processName] UTF8String];
168 char s[2048];
169 snprintf(s, sizeof(s), "Usage: %s [options]\n\n"
170 "Options can be any of the following: \n\n"
171 "--compile-sysdesc"TABS2"Compile system descriptions *\n"
172 "--export-sysdesc"TABS2"Export system descriptions *\n"
174 "-hdr"TABS3"Start up in HDR mode\n"
175#endif
176 "-load [filepath]"TABS2"Load commander from [filepath]\n"TABS3 TABS4"(\"-load\" is optional)\n"
177 "-message [messageString]"TABS1"Display [messageString] at startup\n"
178 "-nodust "TABS2 TABS4"Do not draw space dust\n"
179 "-noshaders"TABS2 TABS4"Start up with shaders disabled\n"
180 "-nosplash "TABS2 TABS4"Force disable splash screen on startup\n"
181 "-nosound "TABS2 TABS4"Start up with sound disabled\n"
182 "-novsync"TABS3"Force disable V-Sync\n"
183 "--openstep"TABS2 TABS4"When compiling or exporting\n"TABS3 TABS4"system descriptions, use openstep\n"TABS3 TABS4"format *\n"
184 "-showversion"TABS2 TABS4"Display version at startup screen\n"
185 "-splash"TABS3 TABS4"Force splash screen on startup\n"
186 "-verify-oxp [filepath] "TABS1"Verify OXP at [filepath] *\n"
187 "--xml"TABS3 TABS4"When compiling or exporting\n"TABS3 TABS4"system descriptions, use xml\n"TABS3 TABS4"format *\n"
188 "\n"
189 "Options marked with \"*\" are available only in Test Release configuration.\n"
191 "Debug functionality enabled (Test Release): "
192#ifndef NDEBUG
193 "yes\n"
194#else
195 "no\n"
196#endif
197 "Built with "
199 "Clang version " STRINGIFY(__clang_major__) "." STRINGIFY(__clang_minor__) "." STRINGIFY(__clang_patchlevel__)
200#else
201 "GCC version " STRINGIFY(__GNUC__) "." STRINGIFY(__GNUC_MINOR__) "." STRINGIFY(__GNUC_PATCHLEVEL__)
202#endif
203 "\n\n", processName
204 );
205 OO_SHOW_MSG(s, processName, MB_OK);
206 OOLog(
@"process.args",
@"%s option detected, exiting after help page has been displayed.", argv[i]);
207 return 0;
208 }
209 }
210
211
212
214
215
216
217 [controller applicationDidFinishLaunching: nil];
218 }
219 @catch (NSException *exception)
220 {
221 OOLogERR(
kOOLogException,
@"Root exception handler hit - terminating. This is an internal error, please report it. Exception name: %@, reason: %@", [exception name], [exception reason]);
222 return EXIT_FAILURE;
223 }
224#endif
225
226
227 return 0;
228}
#define OOLITE_HAVE_CLANG
#define OOLogERR(class, format,...)
NSString *const kOOLogException