-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsdlport.c
More file actions
149 lines (131 loc) · 3.51 KB
/
Copy pathsdlport.c
File metadata and controls
149 lines (131 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* OpenBOR - http://www.chronocrash.com
* -----------------------------------------------------------------------
* All rights reserved, see LICENSE in OpenBOR root for details.
*
* Copyright (c) 2004 - 2014 OpenBOR Team
*/
#include "sdlport.h"
#include "packfile.h"
#include "ram.h"
#include "video.h"
#include "menu.h"
#include <time.h>
#include <unistd.h>
#undef usleep
#ifdef DARWIN
#include <CoreFoundation/CoreFoundation.h>
#elif WIN
#undef main
#endif
char packfile[MAX_FILENAME_LEN] = {"bor.pak"};
#if ANDROID
#include <unistd.h>
char rootDir[MAX_BUFFER_LEN] = {""};
#endif
char paksDir[MAX_FILENAME_LEN] = {"Paks"};
char savesDir[MAX_FILENAME_LEN] = {"Saves"};
char logsDir[MAX_FILENAME_LEN] = {"Logs"};
char screenShotsDir[MAX_FILENAME_LEN] = {"ScreenShots"};
// sleeps for the given number of microseconds
#if _POSIX_C_SOURCE >= 199309L
void _usleep(u32 usec)
{
struct timespec sleeptime;
sleeptime.tv_sec = usec / 1000000LL;
sleeptime.tv_nsec = (usec % 1000000LL) * 1000;
nanosleep(&sleeptime, NULL);
}
#endif
#if ANDROID
char* AndroidRoot(char *relPath)
{
static char filename[MAX_FILENAME_LEN];
strcpy(filename, rootDir);
strcat(filename, relPath);
return filename;
}
#endif
void borExit(int reset)
{
#ifdef GP2X
gp2x_end();
chdir("/usr/gp2x");
execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL);
#elif SDL
SDL_Delay(1000);
SDL_Quit(); // call this instead of atexit(SDL_Quit); It's best practice!
#endif
exit(reset);
}
int main(int argc, char *argv[])
{
#ifndef SKIP_CODE
char pakname[MAX_FILENAME_LEN] = {""};
#endif
#ifdef CUSTOM_SIGNAL_HANDLER
struct sigaction sigact;
#endif
#ifdef DARWIN
char resourcePath[PATH_MAX] = {""};
CFBundleRef mainBundle;
CFURLRef resourcesDirectoryURL;
mainBundle = CFBundleGetMainBundle();
resourcesDirectoryURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
if(!CFURLGetFileSystemRepresentation(resourcesDirectoryURL, true, (UInt8 *) resourcePath, PATH_MAX))
{
borExit(0);
}
CFRelease(resourcesDirectoryURL);
chdir(resourcePath);
#endif
#ifdef CUSTOM_SIGNAL_HANDLER
sigact.sa_sigaction = handleFatalSignal;
sigact.sa_flags = SA_RESTART | SA_SIGINFO;
if(sigaction(SIGSEGV, &sigact, NULL) != 0)
{
printf("Error setting signal handler for %d (%s)\n", SIGSEGV, strsignal(SIGSEGV));
borExit(EXIT_FAILURE);
}
#endif
setSystemRam();
initSDL();
packfile_mode(0);
#ifdef ANDROID
if(strstr(SDL_AndroidGetExternalStoragePath(), "org.openbor.engine"))
{
strcpy(rootDir, "/mnt/sdcard/OpenBOR/");
strcpy(paksDir, "/mnt/sdcard/OpenBOR/Paks");
strcpy(savesDir, "/mnt/sdcard/OpenBOR/Saves");
strcpy(logsDir, "/mnt/sdcard/OpenBOR/Logs");
strcpy(screenShotsDir, "/mnt/sdcard/OpenBOR/ScreenShots");
}
else
{
strcpy(rootDir, SDL_AndroidGetExternalStoragePath());
strcat(rootDir, "/");
strcpy(paksDir, SDL_AndroidGetExternalStoragePath());
strcat(paksDir, "/Paks");
strcpy(savesDir, SDL_AndroidGetExternalStoragePath());
strcat(savesDir, "/Saves");
strcpy(logsDir, SDL_AndroidGetExternalStoragePath());
strcat(logsDir, "/Logs");
strcpy(screenShotsDir, SDL_AndroidGetExternalStoragePath());
strcat(screenShotsDir, "/ScreenShots");
}
dirExists(rootDir, 1);
chdir(rootDir);
#endif
dirExists(paksDir, 1);
dirExists(savesDir, 1);
dirExists(logsDir, 1);
dirExists(screenShotsDir, 1);
Menu();
#ifndef SKIP_CODE
getPakName(pakname, -1);
video_set_window_title(pakname);
#endif
openborMain(argc, argv);
borExit(0);
return 0;
}