Only make the major modifications to the platform files

This commit is contained in:
dakriy 2019-10-20 02:11:01 -07:00
parent 50b09d11d2
commit f05ccf0128
3 changed files with 31 additions and 4 deletions

View File

@ -65,6 +65,7 @@ const cc_result ReturnCode_SocketWouldBlock = WSAEWOULDBLOCK;
#define Socket__Error() errno #define Socket__Error() errno
#define NATIVE_STR_LEN 600 #define NATIVE_STR_LEN 600
static const char *Platform_DefaultDirectory = NULL;
const cc_result ReturnCode_FileShareViolation = 1000000000; /* TODO: not used apparently */ const cc_result ReturnCode_FileShareViolation = 1000000000; /* TODO: not used apparently */
const cc_result ReturnCode_FileNotFound = ENOENT; const cc_result ReturnCode_FileNotFound = ENOENT;
const cc_result ReturnCode_SocketInProgess = EINPROGRESS; const cc_result ReturnCode_SocketInProgess = EINPROGRESS;
@ -1131,7 +1132,7 @@ static cc_result Process_RawGetExePath(char* path, int* len);
cc_result Process_StartGame(const String* args) { cc_result Process_StartGame(const String* args) {
char path[NATIVE_STR_LEN], raw[NATIVE_STR_LEN]; char path[NATIVE_STR_LEN], raw[NATIVE_STR_LEN];
int i, j, len = 0; int i, j, len = 0;
char* argv[15]; const char* argv[15];
cc_result res = Process_RawGetExePath(path, &len); cc_result res = Process_RawGetExePath(path, &len);
if (res) return res; if (res) return res;
@ -1148,6 +1149,9 @@ cc_result Process_StartGame(const String* args) {
raw[i] = '\0'; raw[i] = '\0';
argv[j++] = &raw[i + 1]; argv[j++] = &raw[i + 1];
} }
if (Platform_DefaultDirectory) {
argv[j++] = Platform_DefaultDirectory;
}
argv[j] = NULL; argv[j] = NULL;
return Process_RawStart(path, argv); return Process_RawStart(path, argv);
} }
@ -1768,13 +1772,32 @@ int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, String* args)
#endif #endif
count = min(argc, GAME_MAX_CMDARGS); count = min(argc, GAME_MAX_CMDARGS);
for (i = 0; i < count; i++) { args[i] = String_FromReadonly(argv[i]); } for (i = 0; i < count; i++) {
if (strlen(argv[i]) > 1 && argv[i][0] == '-' && argv[i][1] == 'd') {
--count;
continue;
}
args[i] = String_FromReadonly(argv[i]);
}
return count; return count;
} }
cc_result Platform_SetDefaultCurrentDirectory(void) {
cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
char path[NATIVE_STR_LEN]; char path[NATIVE_STR_LEN];
int i, len = 0; int i, len = 0;
for (i = 1; i < argc; ++i) {
if (strlen(argv[i]) > 2 && argv[i][0] == '-' && argv[i][1] == 'd') {
Platform_DefaultDirectory = argv[i];
break;
}
}
if (Platform_DefaultDirectory) {
return chdir(Platform_DefaultDirectory + 2) == -1 ? errno : 0;
}
cc_result res = Process_RawGetExePath(path, &len); cc_result res = Process_RawGetExePath(path, &len);
if (res) return res; if (res) return res;

View File

@ -41,7 +41,11 @@ void Platform_Init(void);
/* Frees the platform specific state. */ /* Frees the platform specific state. */
void Platform_Free(void); void Platform_Free(void);
/* Sets the appropriate default current/working directory. */ /* Sets the appropriate default current/working directory. */
#if defined CC_BUILD_POSIX
cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv);
#else
cc_result Platform_SetDefaultCurrentDirectory(void); cc_result Platform_SetDefaultCurrentDirectory(void);
#endif
/* Gets the command line arguments passed to the program. */ /* Gets the command line arguments passed to the program. */
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, String* args); int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, String* args);

View File

@ -169,7 +169,7 @@ int main(int argc, char** argv) {
Platform_Init(); Platform_Init();
Window_Init(); Window_Init();
res = Platform_SetDefaultCurrentDirectory(); res = Platform_SetDefaultCurrentDirectory(argc, argv);
if (res) Logger_Warn(res, "setting current directory"); if (res) Logger_Warn(res, "setting current directory");
#ifdef CC_TEST_VORBIS #ifdef CC_TEST_VORBIS
main_imdct(); main_imdct();