1 #include <stdlib.h>
2 #include <string.h>
3 #ifdef MACOSX
4 #include <CoreFoundation/CoreFoundation.h>
5 #endif
6 
7 #include "PuyoCommander.h"
8 
9 #ifndef DATADIR
10 char *DATADIR = "data";
11 #endif
12 
13 char *dataFolder = "data";
14 
15 #ifdef MACOSX
16 const char *bundleDataPath = "/Contents/Resources/data";
show(CFStringRef formatString,...)17 void show(CFStringRef formatString, ...) {
18     CFStringRef resultString;
19     CFDataRef data;
20     va_list argList;
21 
22     va_start(argList, formatString);
23     resultString = CFStringCreateWithFormatAndArguments(NULL, NULL, formatString, argList);
24     va_end(argList);
25 
26     data = CFStringCreateExternalRepresentation(NULL, resultString, CFStringGetSystemEncoding(), '?');
27 
28     if (data != NULL) {
29         printf ("%.*s\n\n", (int)CFDataGetLength(data), CFDataGetBytePtr(data));
30         CFRelease(data);
31     }
32 
33     CFRelease(resultString);
34 }
35 #endif
36 
fileExists(char * path)37 bool fileExists(char *path)
38 {
39     FILE *f;
40     f = fopen(path, "r");
41     if (f == NULL)
42         return false;
43     fclose(f);
44     return true;
45 }
46 
47 #include <SDL/SDL_main.h>
48 
main(int argc,char * argv[])49 int main(int argc, char *argv[])
50 {
51     int i;
52 
53   if (!strcmp(argv[argc-1],"-h")) {
54       printf("-win for windowed mode.\n");
55       printf("-quiet to remove music.\n");
56       printf("-nofx to remove sound FX.\n");
57     return 0;
58   }
59 
60 #ifdef MACOSX
61 
62 #ifndef DATADIR
63     CFStringRef bundlePath = CFURLCopyFileSystemPath(CFBundleCopyBundleURL(CFBundleGetMainBundle()), kCFURLPOSIXPathStyle);
64     int pathSize = (int)CFStringGetMaximumSizeForEncoding(CFStringGetLength(bundlePath), CFStringGetSystemEncoding()) + 1;
65     DATADIR = (char *)malloc(pathSize + strlen(bundleDataPath));
66     CFStringGetCString (bundlePath, DATADIR, pathSize, CFStringGetSystemEncoding());
67     strcat(DATADIR, bundleDataPath);
68 
69     //show(CFSTR("test   : %@"), CFURLCopyFileSystemPath(CFBundleCopyBundleURL(CFBundleGetMainBundle()), kCFURLPOSIXPathStyle));
70     //fprintf(stderr, "bundle=%d path=%s\n", CFBundleGetMainBundle(), DATADIR);
71     //fprintf(stderr, "Attention ça va planter2\n");
72     //CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle(),kCFStringEncodingUnicode);
73     //DATADIR = strdup(CFStringGetCStringPtr(CFURLGetString( CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle())), kCFStringEncodingUnicode));
74     //fprintf(stderr, "Resource path: %s\n", DATADIR);
75 #endif
76 #endif
77 
78     bool fs = true;
79     bool snd = true;
80     bool fx = true;
81 
82     for (i=1; i<argc; i++)
83     {
84         if (strcmp(argv[i],"-win") == 0) fs = false;
85         if (strcmp(argv[i],"-quiet") == 0) snd = false;
86         if (strcmp(argv[i],"-nofx") == 0) fx = false;
87     }
88 
89     if (!fileExists("data/gfx/v0.png")) {
90         dataFolder = DATADIR;
91     }
92 
93     PuyoCommander commander( fs, snd, fx );
94 
95 
96   commander.run();
97   return 0;
98 }
99