projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added a space on --version.
[supertux.git]
/
lib
/
app
/
setup.cpp
diff --git
a/lib/app/setup.cpp
b/lib/app/setup.cpp
index
de2e2a9
..
ca667bb
100644
(file)
--- a/
lib/app/setup.cpp
+++ b/
lib/app/setup.cpp
@@
-42,7
+42,6
@@
#include <cctype>
#include "../app/globals.h"
#include <cctype>
#include "../app/globals.h"
-#include "../app/defines.h"
#include "../app/setup.h"
#include "../video/screen.h"
#include "../video/surface.h"
#include "../app/setup.h"
#include "../video/screen.h"
#include "../video/surface.h"
@@
-66,10
+65,10
@@
void seticon(void);
void usage(char * prog, int ret);
/* Does the given file exist and is it accessible? */
void usage(char * prog, int ret);
/* Does the given file exist and is it accessible? */
-int FileSystem::faccessible(const
char *
filename)
+int FileSystem::faccessible(const
std::string&
filename)
{
struct stat filestat;
{
struct stat filestat;
- if (stat(filename, &filestat) == -1)
+ if (stat(filename
.c_str()
, &filestat) == -1)
{
return false;
}
{
return false;
}
@@
-83,10
+82,10
@@
int FileSystem::faccessible(const char *filename)
}
/* Can we write to this location? */
}
/* Can we write to this location? */
-int FileSystem::fwriteable(const
char *
filename)
+int FileSystem::fwriteable(const
std::string&
filename)
{
FILE* fi;
{
FILE* fi;
- fi = fopen(filename, "wa");
+ fi = fopen(filename
.c_str()
, "wa");
if (fi == NULL)
{
return false;
if (fi == NULL)
{
return false;
@@
-95,14
+94,13
@@
int FileSystem::fwriteable(const char *filename)
}
/* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/
}
/* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/
-int FileSystem::fcreatedir(const
char*
relative_dir)
+int FileSystem::fcreatedir(const
std::string&
relative_dir)
{
{
- char path[1024];
- snprintf(path, 1024, "%s/%s/", st_dir, relative_dir);
- if(mkdir(path,0755) != 0)
+ std::string path = st_dir + "/" + relative_dir + "/";
+ if(mkdir(path.c_str(),0755) != 0)
{
{
-
snprintf(path, 1024, "%s/%s/", datadir.c_str(), relative_dir)
;
- if(mkdir(path,0755) != 0)
+
path = datadir + "/" + relative_dir + "/"
;
+ if(mkdir(path
.c_str()
,0755) != 0)
{
return false;
}
{
return false;
}
@@
-120,68
+118,66
@@
int FileSystem::fcreatedir(const char* relative_dir)
/* Get all names of sub-directories in a certain directory. */
/* Returns the number of sub-directories found. */
/* Note: The user has to free the allocated space. */
/* Get all names of sub-directories in a certain directory. */
/* Returns the number of sub-directories found. */
/* Note: The user has to free the allocated space. */
-st
ring_list_type FileSystem::dsubdirs(const char *rel_path,const char*
expected_file)
+st
d::set<std::string> FileSystem::dsubdirs(const std::string &rel_path,const std::string&
expected_file)
{
DIR *dirStructP;
struct dirent *direntp;
{
DIR *dirStructP;
struct dirent *direntp;
- st
ring_list_type
sdirs;
-
char filename[1024]
;
-
char path[1024]
;
+ st
d::set<std::string>
sdirs;
+
std::string filename
;
+
std::string path = st_dir + "/" + rel_path
;
- string_list_init(&sdirs);
- sprintf(path,"%s/%s",st_dir,rel_path);
- if((dirStructP = opendir(path)) != NULL)
+ if((dirStructP = opendir(path.c_str())) != NULL)
{
while((direntp = readdir(dirStructP)) != NULL)
{
{
while((direntp = readdir(dirStructP)) != NULL)
{
-
char absolute_filename[1024]
;
+
std::string absolute_filename
;
struct stat buf;
struct stat buf;
-
sprintf(absolute_filename, "%s/%s", path, direntp->d_name)
;
+
absolute_filename = path + "/" + direntp->d_name
;
- if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
+ if (stat(absolute_filename
.c_str()
, &buf) == 0 && S_ISDIR(buf.st_mode))
{
{
- if(
expected_file != NULL
)
+ if(
!expected_file.empty()
)
{
{
-
sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file)
;
+
filename = path + "/" + direntp->d_name + "/" + expected_file
;
if(!faccessible(filename))
continue;
}
if(!faccessible(filename))
continue;
}
-
string_list_add_item(&sdirs,
direntp->d_name);
+
sdirs.insert(
direntp->d_name);
}
}
closedir(dirStructP);
}
}
}
closedir(dirStructP);
}
-
sprintf(path,"%s/%s",datadir.c_str(),rel_path)
;
- if((dirStructP = opendir(path)) != NULL)
+
path = datadir + "/" + rel_path
;
+ if((dirStructP = opendir(path
.c_str()
)) != NULL)
{
while((direntp = readdir(dirStructP)) != NULL)
{
{
while((direntp = readdir(dirStructP)) != NULL)
{
-
char absolute_filename[1024]
;
+
std::string absolute_filename
;
struct stat buf;
struct stat buf;
-
sprintf(absolute_filename, "%s/%s", path, direntp->d_name)
;
+
absolute_filename = path + "/" + direntp->d_name
;
- if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
+ if (stat(absolute_filename
.c_str()
, &buf) == 0 && S_ISDIR(buf.st_mode))
{
{
- if(
expected_file != NULL
)
+ if(
!expected_file.empty()
)
{
{
-
sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file)
;
- if(!faccessible(filename))
+
filename = path + "/" + direntp->d_name + "/" + expected_file
;
+ if(!faccessible(filename
.c_str()
))
{
continue;
}
else
{
{
continue;
}
else
{
-
sprintf(filename,"%s/%s/%s/%s",st_dir,rel_path,direntp->d_name,expected_file)
;
- if(faccessible(filename))
+
filename = st_dir + "/" + rel_path + "/" + direntp->d_name + "/" + expected_file
;
+ if(faccessible(filename
.c_str()
))
continue;
}
}
continue;
}
}
-
string_list_add_item(&sdirs,
direntp->d_name);
+
sdirs.insert(
direntp->d_name);
}
}
closedir(dirStructP);
}
}
closedir(dirStructP);
@@
-190,63
+186,61
@@
string_list_type FileSystem::dsubdirs(const char *rel_path,const char* expected
return sdirs;
}
return sdirs;
}
-st
ring_list_type FileSystem::dfiles(const char *rel_path, const char* glob, const char*
exception_str)
+st
d::set<std::string> FileSystem::dfiles(const std::string& rel_path, const std::string& glob, const std::string&
exception_str)
{
DIR *dirStructP;
struct dirent *direntp;
{
DIR *dirStructP;
struct dirent *direntp;
- st
ring_list_type
sdirs;
-
char path[1024]
;
+ st
d::set<std::string>
sdirs;
+
std::string path = st_dir + "/" + rel_path
;
- string_list_init(&sdirs);
- sprintf(path,"%s/%s",st_dir,rel_path);
- if((dirStructP = opendir(path)) != NULL)
+ if((dirStructP = opendir(path.c_str())) != NULL)
{
while((direntp = readdir(dirStructP)) != NULL)
{
{
while((direntp = readdir(dirStructP)) != NULL)
{
-
char absolute_filename[1024]
;
+
std::string absolute_filename
;
struct stat buf;
struct stat buf;
-
sprintf(absolute_filename, "%s/%s", path, direntp->d_name)
;
+
absolute_filename = path + "/" + direntp->d_name
;
- if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode))
+ if (stat(absolute_filename
.c_str()
, &buf) == 0 && S_ISREG(buf.st_mode))
{
{
- if(
exception_str != NULL
)
+ if(
!exception_str.empty()
)
{
{
- if(strstr(direntp->d_name,exception_str) != NULL)
+ if(strstr(direntp->d_name,exception_str
.c_str()
) != NULL)
continue;
}
continue;
}
- if(
glob != NULL
)
- if(strstr(direntp->d_name,glob) == NULL)
+ if(
!glob.empty()
)
+ if(strstr(direntp->d_name,glob
.c_str()
) == NULL)
continue;
continue;
-
string_list_add_item(&sdirs,
direntp->d_name);
+
sdirs.insert(
direntp->d_name);
}
}
closedir(dirStructP);
}
}
}
closedir(dirStructP);
}
-
sprintf(path,"%s/%s",datadir.c_str(),rel_path)
;
- if((dirStructP = opendir(path)) != NULL)
+
path = datadir + "/" + rel_path
;
+ if((dirStructP = opendir(path
.c_str()
)) != NULL)
{
while((direntp = readdir(dirStructP)) != NULL)
{
{
while((direntp = readdir(dirStructP)) != NULL)
{
-
char absolute_filename[1024]
;
+
std::string absolute_filename
;
struct stat buf;
struct stat buf;
-
sprintf(absolute_filename, "%s/%s", path, direntp->d_name)
;
+
absolute_filename = path + "/" + direntp->d_name
;
- if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode))
+ if (stat(absolute_filename
.c_str()
, &buf) == 0 && S_ISREG(buf.st_mode))
{
{
- if(
exception_str != NULL
)
+ if(
!exception_str.empty()
)
{
{
- if(strstr(direntp->d_name,exception_str) != NULL)
+ if(strstr(direntp->d_name,exception_str
.c_str()
) != NULL)
continue;
}
continue;
}
- if(
glob != NULL
)
- if(strstr(direntp->d_name,glob) == NULL)
+ if(
!glob.empty()
)
+ if(strstr(direntp->d_name,glob
.c_str()
) == NULL)
continue;
continue;
-
string_list_add_item(&sdirs,
direntp->d_name);
+
sdirs.insert(
direntp->d_name);
}
}
closedir(dirStructP);
}
}
closedir(dirStructP);
@@
-266,8
+260,7
@@
package_version = _package_version;
/* Set SuperTux configuration and save directories */
void Setup::directories(void)
{
/* Set SuperTux configuration and save directories */
void Setup::directories(void)
{
- char *home;
- char str[1024];
+ std::string home;
/* Get home directory (from $HOME variable)... if we can't determine it,
use the current directory ("."): */
if (getenv("HOME") != NULL)
/* Get home directory (from $HOME variable)... if we can't determine it,
use the current directory ("."): */
if (getenv("HOME") != NULL)
@@
-275,30
+268,21
@@
void Setup::directories(void)
else
home = ".";
else
home = ".";
- std::string st_dir_tmp = "/." + package_symbol_name;
- st_dir = (char *) malloc(sizeof(char) * (strlen(home) +
- strlen(st_dir_tmp.c_str()) + 1));
- strcpy(st_dir, home);
- strcat(st_dir,st_dir_tmp.c_str());
+ st_dir = home + "/." + package_symbol_name;
/* Remove .supertux config-file from old SuperTux versions */
if(FileSystem::faccessible(st_dir))
{
/* Remove .supertux config-file from old SuperTux versions */
if(FileSystem::faccessible(st_dir))
{
- remove
- (st_dir);
+ remove(st_dir.c_str());
}
}
- st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
-
- strcpy(st_save_dir,st_dir);
- strcat(st_save_dir,"/save");
+ st_save_dir = st_dir + "/save";
/* Create them. In the case they exist they won't destroy anything. */
/* Create them. In the case they exist they won't destroy anything. */
- mkdir(st_dir, 0755);
- mkdir(st_save_dir, 0755);
+ mkdir(st_dir
.c_str()
, 0755);
+ mkdir(st_save_dir
.c_str()
, 0755);
- sprintf(str, "%s/levels", st_dir);
- mkdir(str, 0755);
+ mkdir((st_dir + "/levels").c_str(), 0755);
// User has not that a datadir, so we try some magic
if (datadir.empty())
// User has not that a datadir, so we try some magic
if (datadir.empty())
@@
-313,16
+297,21
@@
void Setup::directories(void)
}
else
{
}
else
{
-
std::string exedir = std::string(dirname(exe_file)) + "/";
-
+ std::string exedir = std::string(dirname(exe_file)) + "/";
+
datadir = exedir + "../data"; // SuperTux run from source dir
if (access(datadir.c_str(), F_OK) != 0)
{
datadir = exedir + "../data"; // SuperTux run from source dir
if (access(datadir.c_str(), F_OK) != 0)
{
+ datadir = exedir + "../../data"; //SuperTux run from source dir (with libtool script)
+
+ if (access(datadir.c_str(), F_OK) != 0)
+ {
datadir = exedir + "../share/" + package_symbol_name; // SuperTux run from PATH
if (access(datadir.c_str(), F_OK) != 0)
{ // If all fails, fall back to compiled path
datadir = DATA_PREFIX;
}
datadir = exedir + "../share/" + package_symbol_name; // SuperTux run from PATH
if (access(datadir.c_str(), F_OK) != 0)
{ // If all fails, fall back to compiled path
datadir = DATA_PREFIX;
}
+ }
}
}
#else
}
}
#else
@@
-605,9
+594,9
@@
void Setup::audio(void)
void Termination::shutdown(void)
{
void Termination::shutdown(void)
{
+ config->save();
SoundManager::get()->close_audio();
SDL_Quit();
SoundManager::get()->close_audio();
SDL_Quit();
- config->save();
}
/* --- ABORT! --- */
}
/* --- ABORT! --- */
@@
-718,6
+707,10
@@
void Setup::parseargs(int argc, char * argv[])
{
launch_worldmap_mode = true;
}
{
launch_worldmap_mode = true;
}
+ else if (strcmp(argv[i], "--flip-levels") == 0)
+ {
+ flip_levels_mode = true;
+ }
else if (strcmp(argv[i], "--datadir") == 0
|| strcmp(argv[i], "-d") == 0 )
{
else if (strcmp(argv[i], "--datadir") == 0
|| strcmp(argv[i], "-d") == 0 )
{
@@
-752,7
+745,7
@@
void Setup::parseargs(int argc, char * argv[])
else if (strcmp(argv[i], "--version") == 0)
{
/* Show version: */
else if (strcmp(argv[i], "--version") == 0)
{
/* Show version: */
- printf((package_name + package_version + "\n").c_str() );
+ printf((package_name +
" " +
package_version + "\n").c_str() );
exit(0);
}
else if (strcmp(argv[i], "--disable-sound") == 0)
exit(0);
}
else if (strcmp(argv[i], "--disable-sound") == 0)
@@
-775,8
+768,8
@@
void Setup::parseargs(int argc, char * argv[])
}
else if (strcmp(argv[i], "--help") == 0)
{ /* Show help: */
}
else if (strcmp(argv[i], "--help") == 0)
{ /* Show help: */
- puts(_(
" SuperTux " VERSION
"\n"
- " Please see the file \"README.txt\" for more details.\n"));
+ puts(_(
(" SuperTux " + package_version +
"\n"
+ " Please see the file \"README.txt\" for more details.\n")
.c_str())
);
printf(_("Usage: %s [OPTIONS] FILENAME\n\n"), argv[0]);
puts(_("Display Options:\n"
" -f, --fullscreen Run in fullscreen mode.\n"
printf(_("Usage: %s [OPTIONS] FILENAME\n\n"), argv[0]);
puts(_("Display Options:\n"
" -f, --fullscreen Run in fullscreen mode.\n"
@@
-796,6
+789,7
@@
void Setup::parseargs(int argc, char * argv[])
" Define how joystick buttons and axis should be mapped\n"
" --leveleditor Opens the leveleditor in a file.\n"
" --worldmap Opens the specified worldmap file.\n"
" Define how joystick buttons and axis should be mapped\n"
" --leveleditor Opens the leveleditor in a file.\n"
" --worldmap Opens the specified worldmap file.\n"
+ " --flip-levels Flip levels upside-down.\n"
" -d, --datadir DIR Load Game data from DIR (default: automatic)\n"
" --debug Enables the debug mode, which is useful for developers.\n"
" --help Display a help message summarizing command-line\n"
" -d, --datadir DIR Load Game data from DIR (default: automatic)\n"
" --debug Enables the debug mode, which is useful for developers.\n"
" --help Display a help message summarizing command-line\n"
@@
-836,7
+830,7
@@
void usage(char * prog, int ret)
/* Display the usage message: */
/* Display the usage message: */
- fprintf(fi, _("Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug] | [--usage | --help | --version] [--leveleditor] [--worldmap] FILENAME\n"),
+ fprintf(fi, _("Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug] | [--usage | --help | --version] [--leveleditor] [--worldmap]
[--flip-levels]
FILENAME\n"),
prog);
prog);
@@
-845,9
+839,9
@@
void usage(char * prog, int ret)
exit(ret);
}
exit(ret);
}
-std::
vector
<std::string> FileSystem::read_directory(const std::string& pathname)
+std::
set
<std::string> FileSystem::read_directory(const std::string& pathname)
{
{
- std::
vector
<std::string> dirnames;
+ std::
set
<std::string> dirnames;
DIR* dir = opendir(pathname.c_str());
if (dir)
DIR* dir = opendir(pathname.c_str());
if (dir)
@@
-856,7
+850,7
@@
std::vector<std::string> FileSystem::read_directory(const std::string& pathname)
while((direntp = readdir(dir)))
{
while((direntp = readdir(dir)))
{
- dirnames.
push_back
(direntp->d_name);
+ dirnames.
insert
(direntp->d_name);
}
closedir(dir);
}
closedir(dir);