6245e49953b39990415cb693141d4a899aa45368
[supertux.git] / lib / app / setup.cpp
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #include <config.h>
21
22 #include <cassert>
23 #include <cstdio>
24 #include <iostream>
25 #include <cstdio>
26 #include <cstdlib>
27 #include <cstring>
28 #include <cerrno>
29 #include <unistd.h>
30
31 #include "SDL.h"
32 #include "SDL_image.h"
33 #ifndef NOOPENGL
34 #include "SDL_opengl.h"
35 #endif
36
37 #include <sys/stat.h>
38 #include <sys/types.h>
39 #include <dirent.h>
40 #ifndef WIN32
41 #include <libgen.h>
42 #endif
43
44 #include <cctype>
45
46 #include "../app/globals.h"
47 #include "../app/setup.h"
48 #include "../video/screen.h"
49 #include "../video/surface.h"
50 #include "../gui/menu.h"
51 #include "../utils/configfile.h"
52 #include "../audio/sound_manager.h"
53 #include "../app/gettext.h"
54
55 using namespace SuperTux;
56
57 #ifdef WIN32
58 #define mkdir(dir, mode)    mkdir(dir)
59 // on win32 we typically don't want LFS paths
60 #undef DATA_PREFIX
61 #define DATA_PREFIX "./data/"
62 #endif
63
64 /* Local function prototypes: */
65
66 void seticon(void);
67 void usage(char * prog, int ret);
68
69 /* Does the given file exist and is it accessible? */
70 int FileSystem::faccessible(const std::string& filename)
71 {
72   struct stat filestat;
73   if (stat(filename.c_str(), &filestat) == -1)
74     {
75       return false;
76     }
77   else
78     {
79       if(S_ISREG(filestat.st_mode))
80         return true;
81       else
82         return false;
83     }
84 }
85
86 /* Can we write to this location? */
87 int FileSystem::fwriteable(const std::string& filename)
88 {
89   FILE* fi;
90   fi = fopen(filename.c_str(), "wa");
91   if (fi == NULL)
92     {
93       return false;
94     }
95   fclose(fi);
96   return true;
97 }
98
99 /* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/
100 int FileSystem::fcreatedir(const std::string& relative_dir)
101 {
102   std::string path = st_dir + "/" + relative_dir + "/";
103   if(mkdir(path.c_str(),0755) != 0)
104     {
105       path = datadir + "/" + relative_dir + "/";
106       if(mkdir(path.c_str(),0755) != 0)
107         {
108           return false;
109         }
110       else
111         {
112           return true;
113         }
114     }
115   else
116     {
117       return true;
118     }
119 }
120
121 /* Get all names of sub-directories in a certain directory. */
122 /* Returns the number of sub-directories found. */
123 /* Note: The user has to free the allocated space. */
124 std::set<std::string> FileSystem::dsubdirs(const std::string &rel_path,const  std::string& expected_file)
125 {
126   DIR *dirStructP;
127   struct dirent *direntp;
128   std::set<std::string> sdirs;
129   std::string filename;
130   std::string path = st_dir + "/" + rel_path;
131
132   if((dirStructP = opendir(path.c_str())) != NULL)
133     {
134       while((direntp = readdir(dirStructP)) != NULL)
135         {
136           std::string absolute_filename;
137           struct stat buf;
138
139           absolute_filename = path + "/" + direntp->d_name;
140
141           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISDIR(buf.st_mode))
142             {
143               if(!expected_file.empty())
144                 {
145                   filename = path + "/" + direntp->d_name + "/" + expected_file;
146                   if(!faccessible(filename))
147                     continue;
148                 }
149
150               sdirs.insert(direntp->d_name);
151             }
152         }
153       closedir(dirStructP);
154     }
155
156   path = datadir + "/" + rel_path;
157   if((dirStructP = opendir(path.c_str())) != NULL)
158     {
159       while((direntp = readdir(dirStructP)) != NULL)
160         {
161           std::string absolute_filename;
162           struct stat buf;
163
164           absolute_filename = path + "/" + direntp->d_name;
165
166           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISDIR(buf.st_mode))
167             {
168               if(!expected_file.empty())
169                 {
170                   filename = path + "/" + direntp->d_name + "/" + expected_file;
171                   if(!faccessible(filename.c_str()))
172                     {
173                       continue;
174                     }
175                   else
176                     {
177                       filename = st_dir + "/" + rel_path + "/" + direntp->d_name + "/" + expected_file;
178                       if(faccessible(filename.c_str()))
179                         continue;
180                     }
181                 }
182
183               sdirs.insert(direntp->d_name);
184             }
185         }
186       closedir(dirStructP);
187     }
188
189   return sdirs;
190 }
191
192 std::set<std::string> FileSystem::dfiles(const std::string& rel_path, const  std::string& glob, const  std::string& exception_str)
193 {
194   DIR *dirStructP;
195   struct dirent *direntp;
196   std::set<std::string> sdirs;
197   std::string path = st_dir + "/" + rel_path;
198
199   if((dirStructP = opendir(path.c_str())) != NULL)
200     {
201       while((direntp = readdir(dirStructP)) != NULL)
202         {
203           std::string absolute_filename;
204           struct stat buf;
205
206           absolute_filename = path + "/" + direntp->d_name;
207
208           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISREG(buf.st_mode))
209             {
210               if(!exception_str.empty())
211                 {
212                   if(strstr(direntp->d_name,exception_str.c_str()) != NULL)
213                     continue;
214                 }
215               if(!glob.empty())
216                 if(strstr(direntp->d_name,glob.c_str()) == NULL)
217                   continue;
218
219               sdirs.insert(direntp->d_name);
220             }
221         }
222       closedir(dirStructP);
223     }
224
225   path = datadir + "/" + rel_path;
226   if((dirStructP = opendir(path.c_str())) != NULL)
227     {
228       while((direntp = readdir(dirStructP)) != NULL)
229         {
230           std::string absolute_filename;
231           struct stat buf;
232
233           absolute_filename = path + "/" + direntp->d_name;
234
235           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISREG(buf.st_mode))
236             {
237               if(!exception_str.empty())
238                 {
239                   if(strstr(direntp->d_name,exception_str.c_str()) != NULL)
240                     continue;
241                 }
242               if(!glob.empty())
243                 if(strstr(direntp->d_name,glob.c_str()) == NULL)
244                   continue;
245
246               sdirs.insert(direntp->d_name);
247             }
248         }
249       closedir(dirStructP);
250     }
251
252   return sdirs;
253 }
254
255 void Setup::info(const std::string& _package_name, const std::string& _package_symbol_name, const std::string& _package_version)
256 {
257 package_name = _package_name;
258 package_symbol_name = _package_symbol_name;
259 package_version = _package_version;
260 }
261
262 /* --- SETUP --- */
263 /* Set SuperTux configuration and save directories */
264 void Setup::directories(void)
265 {
266   std::string home;
267   /* Get home directory (from $HOME variable)... if we can't determine it,
268      use the current directory ("."): */
269   if (getenv("HOME") != NULL)
270     home = getenv("HOME");
271   else
272     home = ".";
273
274   st_dir = home + "/." + package_symbol_name;
275
276   /* Remove .supertux config-file from old SuperTux versions */
277   if(FileSystem::faccessible(st_dir))
278     {
279       remove(st_dir.c_str());
280     }
281
282   st_save_dir = st_dir + "/save";
283
284   /* Create them. In the case they exist they won't destroy anything. */
285   mkdir(st_dir.c_str(), 0755);
286   mkdir(st_save_dir.c_str(), 0755);
287
288   mkdir((st_dir + "/levels").c_str(), 0755);
289
290   // try current directory as datadir
291   if(datadir.empty()) {
292       if(FileSystem::faccessible("./data/intro.txt"))
293           datadir = "./data";
294   }
295
296   // User has not that a datadir, so we try some magic
297   if (datadir.empty())
298     {
299 #ifndef WIN32
300       // Detect datadir
301       char exe_file[PATH_MAX];
302       if (readlink("/proc/self/exe", exe_file, PATH_MAX) < 0)
303         {
304           puts("Couldn't read /proc/self/exe, using default path: " DATA_PREFIX);
305           datadir = DATA_PREFIX;
306         }
307       else
308         {
309           std::string exedir = std::string(dirname(exe_file)) + "/";
310           
311           datadir = exedir + "../data"; // SuperTux run from source dir
312           if (access(datadir.c_str(), F_OK) != 0)
313             {
314               datadir = exedir + "../../data";  //SuperTux run from source dir (with libtool script)
315               
316               if (access(datadir.c_str(), F_OK) != 0)
317               {
318               datadir = exedir + "../share/" + package_symbol_name; // SuperTux run from PATH
319               if (access(datadir.c_str(), F_OK) != 0) 
320                 { // If all fails, fall back to compiled path
321                   datadir = DATA_PREFIX; 
322                 }
323               }
324             }
325         }
326 #else
327   datadir = DATA_PREFIX;
328 #endif
329     }
330   printf("Datadir: %s\n", datadir.c_str());
331 }
332
333 void Setup::general(void)
334 {
335   /* Seed random number generator: */
336
337   srand(SDL_GetTicks());
338
339   /* Set icon image: */
340
341   seticon();
342
343   /* Unicode needed for input handling: */
344
345   SDL_EnableUNICODE(1);
346
347   /* Load GUI/menu images: */
348   checkbox = new Surface(datadir + "/images/status/checkbox.png", true);
349   checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", true);
350   back = new Surface(datadir + "/images/status/back.png", true);
351   arrow_left = new Surface(datadir + "/images/icons/left.png", true);
352   arrow_right = new Surface(datadir + "/images/icons/right.png", true);
353
354   /* Load the mouse-cursor */
355   mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1);
356   MouseCursor::set_current(mouse_cursor);
357   
358 }
359
360 void Setup::general_free(void)
361 {
362
363   /* Free GUI/menu images: */
364   delete checkbox;
365   delete checkbox_checked;
366   delete back;
367   delete arrow_left;
368   delete arrow_right;
369
370   /* Free mouse-cursor */
371   delete mouse_cursor;
372   
373 }
374
375 void Setup::video(unsigned int screen_w, unsigned int screen_h)
376 {
377   /* Init SDL Video: */
378   if (SDL_Init(SDL_INIT_VIDEO) < 0)
379     {
380       fprintf(stderr,
381               "\nError: I could not initialize video!\n"
382               "The Simple DirectMedia error that occured was:\n"
383               "%s\n\n", SDL_GetError());
384       exit(1);
385     }
386
387   /* Open display: */
388   if(use_gl)
389     video_gl(screen_w, screen_h);
390   else
391     video_sdl(screen_w, screen_h);
392
393   Surface::reload_all();
394
395   /* Set window manager stuff: */
396   SDL_WM_SetCaption((package_name + " " + package_version).c_str(), package_name.c_str());
397 }
398
399 void Setup::video_sdl(unsigned int screen_w, unsigned int screen_h)
400 {
401   if (use_fullscreen)
402     {
403       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
404       if (screen == NULL)
405         {
406           fprintf(stderr,
407                   "\nWarning: I could not set up fullscreen video for "
408                   "800x600 mode.\n"
409                   "The Simple DirectMedia error that occured was:\n"
410                   "%s\n\n", SDL_GetError());
411           use_fullscreen = false;
412         }
413     }
414   else
415     {
416       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_HWSURFACE | SDL_DOUBLEBUF );
417
418       if (screen == NULL)
419         {
420           fprintf(stderr,
421                   "\nError: I could not set up video for 800x600 mode.\n"
422                   "The Simple DirectMedia error that occured was:\n"
423                   "%s\n\n", SDL_GetError());
424           exit(1);
425         }
426     }
427 }
428
429 void Setup::video_gl(unsigned int screen_w, unsigned int screen_h)
430 {
431 #ifndef NOOPENGL
432
433   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
434   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
435   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
436   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
437   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
438
439   if (use_fullscreen)
440     {
441       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */
442       if (screen == NULL)
443         {
444           fprintf(stderr,
445                   "\nWarning: I could not set up fullscreen video for "
446                   "640x480 mode.\n"
447                   "The Simple DirectMedia error that occured was:\n"
448                   "%s\n\n", SDL_GetError());
449           use_fullscreen = false;
450         }
451     }
452   else
453     {
454       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_OPENGL);
455
456       if (screen == NULL)
457         {
458           fprintf(stderr,
459                   "\nError: I could not set up video for 640x480 mode.\n"
460                   "The Simple DirectMedia error that occured was:\n"
461                   "%s\n\n", SDL_GetError());
462           exit(1);
463         }
464     }
465
466   /*
467    * Set up OpenGL for 2D rendering.
468    */
469   glDisable(GL_DEPTH_TEST);
470   glDisable(GL_CULL_FACE);
471
472   glViewport(0, 0, screen->w, screen->h);
473   glMatrixMode(GL_PROJECTION);
474   glLoadIdentity();
475   glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0);
476
477   glMatrixMode(GL_MODELVIEW);
478   glLoadIdentity();
479   glTranslatef(0.0f, 0.0f, 0.0f);
480
481 #endif
482
483 }
484
485 void Setup::joystick(void)
486 {
487
488   /* Init Joystick: */
489
490   use_joystick = true;
491
492   if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
493     {
494       fprintf(stderr, "Warning: I could not initialize joystick!\n"
495               "The Simple DirectMedia error that occured was:\n"
496               "%s\n\n", SDL_GetError());
497
498       use_joystick = false;
499     }
500   else
501     {
502       /* Open joystick: */
503       if (SDL_NumJoysticks() <= 0)
504         {
505           fprintf(stderr, "Info: No joysticks were found.\n");
506
507           use_joystick = false;
508         }
509       else
510         {
511           js = SDL_JoystickOpen(joystick_num);
512
513           if (js == NULL)
514             {
515               fprintf(stderr, "Warning: Could not open joystick %d.\n"
516                       "The Simple DirectMedia error that occured was:\n"
517                       "%s\n\n", joystick_num, SDL_GetError());
518
519               use_joystick = false;
520             }
521           else
522             {
523               if (SDL_JoystickNumAxes(js) < 2)
524                 {
525                   fprintf(stderr,
526                           "Warning: Joystick does not have enough axes!\n");
527
528                   use_joystick = false;
529                 }
530               else
531                 {
532                   if (SDL_JoystickNumButtons(js) < 2)
533                     {
534                       fprintf(stderr,
535                               "Warning: "
536                               "Joystick does not have enough buttons!\n");
537
538                       use_joystick = false;
539                     }
540                 }
541             }
542         }
543     }
544 }
545
546 void Setup::audio(void)
547 {
548
549   /* Init SDL Audio silently even if --disable-sound : */
550
551   if (SoundManager::get()->audio_device_available())
552     {
553       if (SDL_Init(SDL_INIT_AUDIO) < 0)
554         {
555           /* only print out message if sound or music
556              was not disabled at command-line
557            */
558           if (SoundManager::get()->sound_enabled() || SoundManager::get()->music_enabled())
559             {
560               fprintf(stderr,
561                       "\nWarning: I could not initialize audio!\n"
562                       "The Simple DirectMedia error that occured was:\n"
563                       "%s\n\n", SDL_GetError());
564             }
565           /* keep the programming logic the same :-)
566              because in this case, use_sound & use_music' values are ignored
567              when there's no available audio device
568           */
569           SoundManager::get()->enable_sound(false);
570           SoundManager::get()->enable_music(false);
571           SoundManager::get()->set_audio_device_available(false);
572         }
573     }
574
575
576   /* Open sound silently regarless the value of "use_sound": */
577
578   if (SoundManager::get()->audio_device_available())
579     {
580       if (SoundManager::get()->open_audio(44100, AUDIO_S16, 2, 2048) < 0)
581         {
582           /* only print out message if sound or music
583              was not disabled at command-line
584            */
585           if (SoundManager::get()->sound_enabled() || SoundManager::get()->music_enabled())
586             {
587               fprintf(stderr,
588                       "\nWarning: I could not set up audio for 44100 Hz "
589                       "16-bit stereo.\n"
590                       "The Simple DirectMedia error that occured was:\n"
591                       "%s\n\n", SDL_GetError());
592             }
593           SoundManager::get()->enable_sound(false);
594           SoundManager::get()->enable_music(false);
595           SoundManager::get()->set_audio_device_available(false);
596         }
597     }
598
599 }
600
601
602 /* --- SHUTDOWN --- */
603
604 void Termination::shutdown(void)
605 {
606   config->save();
607   SoundManager::get()->close_audio();
608   SDL_Quit();
609 }
610
611 /* --- ABORT! --- */
612
613 void Termination::abort(const std::string& reason, const std::string& details)
614 {
615   fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str());
616   shutdown();
617   ::abort();
618 }
619
620 /* Set Icon (private) */
621
622 void seticon(void)
623 {
624 //  int masklen;
625 //  Uint8 * mask;
626   SDL_Surface * icon;
627
628
629   /* Load icon into a surface: */
630
631   icon = IMG_Load((datadir + "/images/" + package_symbol_name + ".xpm").c_str());
632   if (icon == NULL)
633     {
634       fprintf(stderr,
635               "\nError: I could not load the icon image: %s%s\n"
636               "The Simple DirectMedia error that occured was:\n"
637               "%s\n\n", datadir.c_str(), ("/images/" + package_symbol_name + ".xpm").c_str(), SDL_GetError());
638       exit(1);
639     }
640
641
642   /* Create mask: */
643 /*
644   masklen = (((icon -> w) + 7) / 8) * (icon -> h);
645   mask = (Uint8*) malloc(masklen * sizeof(Uint8));
646   memset(mask, 0xFF, masklen);
647 */
648
649   /* Set icon: */
650
651   SDL_WM_SetIcon(icon, NULL);//mask);
652
653
654   /* Free icon surface & mask: */
655
656 //  free(mask);
657   SDL_FreeSurface(icon);
658 }
659
660
661 /* Parse command-line arguments: */
662
663 void Setup::parseargs(int argc, char * argv[])
664 {
665   int i;
666
667   config->load();
668
669   /* Parse arguments: */
670
671   for (i = 1; i < argc; i++)
672     {
673       if (strcmp(argv[i], "--fullscreen") == 0 ||
674           strcmp(argv[i], "-f") == 0)
675         {
676           use_fullscreen = true;
677         }
678       else if (strcmp(argv[i], "--window") == 0 ||
679                strcmp(argv[i], "-w") == 0)
680         {
681           use_fullscreen = false;
682         }
683       else if (strcmp(argv[i], "--joystick") == 0 || strcmp(argv[i], "-j") == 0)
684         {
685           assert(i+1 < argc);
686           joystick_num = atoi(argv[++i]);
687         }
688       else if (strcmp(argv[i], "--joymap") == 0)
689         {
690           assert(i+1 < argc);
691           if (sscanf(argv[++i],
692                      "%d:%d:%d:%d:%d", 
693                      &joystick_keymap.x_axis, 
694                      &joystick_keymap.y_axis, 
695                      &joystick_keymap.a_button, 
696                      &joystick_keymap.b_button, 
697                      &joystick_keymap.start_button) != 5)
698             {
699               puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'");
700             }
701           else
702             {
703               std::cout << "Using new joymap:\n"
704                         << "  X-Axis:       " << joystick_keymap.x_axis << "\n"
705                         << "  Y-Axis:       " << joystick_keymap.y_axis << "\n"
706                         << "  A-Button:     " << joystick_keymap.a_button << "\n"
707                         << "  B-Button:     " << joystick_keymap.b_button << "\n"
708                         << "  Start-Button: " << joystick_keymap.start_button << std::endl;
709             }
710         }
711       else if (strcmp(argv[i], "--leveleditor") == 0)
712         {
713           launch_leveleditor_mode = true;
714         }
715       else if (strcmp(argv[i], "--worldmap") == 0)
716         {
717           launch_worldmap_mode = true;
718         }
719       else if (strcmp(argv[i], "--flip-levels") == 0)
720         {
721           flip_levels_mode = true;
722         }
723       else if (strcmp(argv[i], "--datadir") == 0 
724                || strcmp(argv[i], "-d") == 0 )
725         {
726           assert(i+1 < argc);
727           datadir = argv[++i];
728         }
729       else if (strcmp(argv[i], "--show-fps") == 0)
730         {
731           /* Use full screen: */
732
733           show_fps = true;
734         }
735       else if (strcmp(argv[i], "--opengl") == 0 ||
736                strcmp(argv[i], "-gl") == 0)
737         {
738 #ifndef NOOPENGL
739           /* Use OpengGL: */
740
741           use_gl = true;
742 #endif
743         }
744       else if (strcmp(argv[i], "--sdl") == 0)
745           {
746             use_gl = false;
747           }
748       else if (strcmp(argv[i], "--usage") == 0)
749         {
750           /* Show usage: */
751
752           usage(argv[0], 0);
753         }
754       else if (strcmp(argv[i], "--version") == 0)
755         {
756           /* Show version: */
757           printf((package_name + " " + package_version + "\n").c_str() );
758           exit(0);
759         }
760       else if (strcmp(argv[i], "--disable-sound") == 0)
761         {
762           /* Disable the compiled in sound feature */
763           printf("Sounds disabled \n");
764           SoundManager::get()->enable_sound(false); 
765         }
766       else if (strcmp(argv[i], "--disable-music") == 0)
767         {
768           /* Disable the compiled in sound feature */
769           printf("Music disabled \n");
770           SoundManager::get()->enable_music(false); 
771         }
772       else if (strcmp(argv[i], "--debug") == 0)
773         {
774           /* Enable the debug-mode */
775           debug_mode = true;
776
777         }
778       else if (strcmp(argv[i], "--help") == 0)
779         {     /* Show help: */
780           puts(_(("  SuperTux  " + package_version + "\n"
781                "  Please see the file \"README.txt\" for more details.\n").c_str()));
782           printf(_("Usage: %s [OPTIONS] FILENAME\n\n"), argv[0]);
783           puts(_("Display Options:\n"
784                "  -f, --fullscreen    Run in fullscreen mode.\n"
785                "  -w, --window        Run in window mode.\n"
786                "  --opengl            If OpenGL support was compiled in, this will tell\n"
787                "                      SuperTux to make use of it.\n"
788                "  --sdl               Use the SDL software graphical renderer\n"
789                "\n"
790                "Sound Options:\n"
791                "  --disable-sound     If sound support was compiled in,  this will\n"
792                "                      disable sound for this session of the game.\n"
793                "  --disable-music     Like above, but this will disable music.\n"
794                "\n"
795                "Misc Options:\n"
796                "  -j, --joystick NUM  Use joystick NUM (default: 0)\n" 
797                "  --joymap XAXIS:YAXIS:A:B:START\n"
798                "                      Define how joystick buttons and axis should be mapped\n"
799                "  --leveleditor       Opens the leveleditor in a file.\n"
800                "  --worldmap          Opens the specified worldmap file.\n"
801                "  --flip-levels       Flip levels upside-down.\n"
802                "  -d, --datadir DIR   Load Game data from DIR (default: automatic)\n"
803                "  --debug             Enables the debug mode, which is useful for developers.\n"
804                "  --help              Display a help message summarizing command-line\n"
805                "                      options, license and game controls.\n"
806                "  --usage             Display a brief message summarizing command-line options.\n"
807                "  --version           Display the version of SuperTux you're running.\n\n"
808                ));
809           exit(0);
810         }
811       else if (argv[i][0] != '-')
812         {
813           level_startup_file = argv[i];
814         }
815       else
816         {
817           /* Unknown - complain! */
818
819           usage(argv[0], 1);
820         }
821     }
822 }
823
824
825 /* Display usage: */
826
827 void usage(char * prog, int ret)
828 {
829   FILE * fi;
830
831
832   /* Determine which stream to write to: */
833
834   if (ret == 0)
835     fi = stdout;
836   else
837     fi = stderr;
838
839
840   /* Display the usage message: */
841
842   fprintf(fi, _("Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug] | [--usage | --help | --version] [--leveleditor] [--worldmap] [--flip-levels] FILENAME\n"),
843           prog);
844
845
846   /* Quit! */
847
848   exit(ret);
849 }
850
851 std::set<std::string> FileSystem::read_directory(const std::string& pathname)
852 {
853   std::set<std::string> dirnames;
854   
855   DIR* dir = opendir(pathname.c_str());
856   if (dir)
857     {
858       struct dirent *direntp;
859       
860       while((direntp = readdir(dir)))
861         {
862           dirnames.insert(direntp->d_name);
863         }
864       
865       closedir(dir);
866     }
867
868   return dirnames;
869 }
870
871 /* EOF */