Revert "Add POSIX only changes in the platform and program"

This reverts commit dd4319088d2408dc69fd408c7676f60fc6da0bbd.

Revert this commit as Unk wants to do things differently.
This commit is contained in:
dakriy 2019-10-20 01:42:41 -07:00
parent 7b0924d9c7
commit 50b09d11d2
3 changed files with 20 additions and 48 deletions

View File

@ -1772,40 +1772,29 @@ int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, String* args)
return count;
}
cc_result Platform_SetDefaultCurrentDirectory(const String *requestedDirectory) {
cc_result Platform_SetDefaultCurrentDirectory(void) {
char path[NATIVE_STR_LEN];
int i, len = 0;
cc_result res;
cc_result res = Process_RawGetExePath(path, &len);
if (res) return res;
if (requestedDirectory != NULL) {
String_CopyToRaw(path, NATIVE_STR_LEN, requestedDirectory);
len = requestedDirectory->length;
} else {
res = Process_RawGetExePath(path, &len);
if (res) return res;
/* get rid of filename at end of directory */
for (i = len - 1; i >= 0; i--, len--) {
if (path[i] == '/') break;
}
#ifdef CC_BUILD_OSX
static const String bundle = String_FromConst(".app/Contents/MacOS/");
String raw = String_Init(path, len, 0);
if (String_CaselessEnds(&raw, &bundle)) {
len -= bundle.length;
/* get rid of filename at end of directory */
for (i = len - 1; i >= 0; i--, len--) {
if (path[i] == '/') break;
}
#ifdef CC_BUILD_OSX
static const String bundle = String_FromConst(".app/Contents/MacOS/");
String raw = String_Init(path, len, 0);
if (String_CaselessEnds(&raw, &bundle)) {
len -= bundle.length;
for (i = len - 1; i >= 0; i--, len--) {
if (path[i] == '/') break;
}
}
}
#endif
}
if (len >= NATIVE_STR_LEN) {
len = NATIVE_STR_LEN - 1;
}
path[len] = '\0';
return chdir(path) == -1 ? errno : 0;

View File

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

View File

@ -97,12 +97,13 @@ CC_NOINLINE static void ExitMissingArgs(int argsCount, const String* args) {
#ifdef CC_BUILD_ANDROID
int Program_Run(int argc, char** argv) {
#else
static int Program_Run(int argsCount, String args[GAME_MAX_CMDARGS]) {
static int Program_Run(int argc, char** argv) {
#endif
String args[GAME_MAX_CMDARGS];
cc_uint8 ip[4];
cc_uint16 port;
int argsCount = Platform_GetCommandLineArgs(argc, argv, args);
#ifdef _MSC_VER
/* NOTE: Make sure to comment this out before pushing a commit */
//String rawArgs = String_FromConst("UnknownShadow200 fffff 127.0.0.1 25565");
@ -163,26 +164,12 @@ int main_real(int argc, char** argv) {
int main(int argc, char** argv) {
#endif
static char ipBuffer[STRING_SIZE];
String args[GAME_MAX_CMDARGS];
int argsCount;
cc_result res;
Logger_Hook();
Platform_Init();
Window_Init();
argsCount = Platform_GetCommandLineArgs(argc, argv, args);
#if defined CC_BUILD_POSIX
if (argsCount > 0 && args[argsCount - 1].length > 2 && args[argsCount - 1].buffer[0] == '-' && args[argsCount - 1].buffer[1] == 'd') {
res = Platform_SetDefaultCurrentDirectory(&args[--argsCount]);
} else {
res = Platform_SetDefaultCurrentDirectory(NULL);
}
#else
res = Platform_SetDefaultCurrentDirectory();
#endif
if (res) Logger_Warn(res, "setting current directory");
#ifdef CC_TEST_VORBIS
main_imdct();
@ -196,7 +183,7 @@ int main(int argc, char** argv) {
Utils_EnsureDirectory("plugins");
Options_Load();
return Program_Run(argsCount, args);
return Program_Run(argc, argv);
}
/* ClassiCube is just a native library on android, */