no dup games
This commit is contained in:
parent
5517a2cdc4
commit
0ceaaf4b3d
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -20,6 +20,7 @@ instead (1.2.0) unstable; urgency=low
|
||||||
* exist() added (seen over disabled objects);
|
* exist() added (seen over disabled objects);
|
||||||
* improved debugger;
|
* improved debugger;
|
||||||
* save vars in _G;
|
* save vars in _G;
|
||||||
|
* no duplicated games while looking gamespaths;
|
||||||
* many small bugfixes...
|
* many small bugfixes...
|
||||||
|
|
||||||
-- Peter Kosyh <p.kosyh@gmail.com> Tue, 01 Jun 2010 17:40:00 +0300
|
-- Peter Kosyh <p.kosyh@gmail.com> Tue, 01 Jun 2010 17:40:00 +0300
|
||||||
|
|
|
@ -56,39 +56,51 @@ struct game *games = NULL;
|
||||||
int games_nr = 0;
|
int games_nr = 0;
|
||||||
|
|
||||||
void free_last(void);
|
void free_last(void);
|
||||||
|
|
||||||
int game_select(const char *name)
|
static struct game *game_lookup(const char *name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
free_last();
|
|
||||||
if (!name || !*name) {
|
if (!name || !*name) {
|
||||||
if (games_nr == 1)
|
if (games_nr == 1)
|
||||||
name = games[0].dir;
|
return &games[0];
|
||||||
else
|
return NULL;
|
||||||
return 0;
|
}
|
||||||
}
|
|
||||||
chdir(game_cwd);
|
|
||||||
for (i = 0; i<games_nr; i ++) {
|
for (i = 0; i<games_nr; i ++) {
|
||||||
if (!strcmp(games[i].dir, name)) {
|
if (!strcmp(games[i].dir, name)) {
|
||||||
char *oldgame = curgame_dir;
|
return &games[i];
|
||||||
curgame_dir = games[i].dir;
|
|
||||||
instead_done();
|
|
||||||
if (instead_init()) {
|
|
||||||
curgame_dir = oldgame;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (chdir(games[i].path)) {
|
|
||||||
curgame_dir = oldgame;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (instead_load(MAIN_FILE)) {
|
|
||||||
curgame_dir = oldgame;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
instead_eval("game:ini()"); instead_clear();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int game_select(const char *name)
|
||||||
|
{
|
||||||
|
struct game *g;
|
||||||
|
free_last();
|
||||||
|
g = game_lookup(name);
|
||||||
|
if ((!name || !*name) && !g)
|
||||||
|
return 0;
|
||||||
|
if (chdir(game_cwd))
|
||||||
|
return -1;
|
||||||
|
if (g) {
|
||||||
|
char *oldgame = curgame_dir;
|
||||||
|
curgame_dir = g->dir;
|
||||||
|
instead_done();
|
||||||
|
if (instead_init()) {
|
||||||
|
curgame_dir = oldgame;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (chdir(g->path)) {
|
||||||
|
curgame_dir = oldgame;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (instead_load(MAIN_FILE)) {
|
||||||
|
curgame_dir = oldgame;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
instead_eval("game:ini()"); instead_clear();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,24 +151,24 @@ static int games_add(const char *path, const char *dir)
|
||||||
|
|
||||||
int games_replace(const char *path, const char *dir)
|
int games_replace(const char *path, const char *dir)
|
||||||
{
|
{
|
||||||
int i, rc;
|
int rc;
|
||||||
char *p;
|
char *p;
|
||||||
|
struct game *g;
|
||||||
if (!is_game(path, dir))
|
if (!is_game(path, dir))
|
||||||
return -1;
|
return -1;
|
||||||
for (i = 0; i<games_nr; i ++) {
|
g = game_lookup(dir);
|
||||||
if (!strcmp(games[i].dir, dir)) {
|
if (g) {
|
||||||
p = getpath(path, dir);
|
p = getpath(path, dir);
|
||||||
if (!p)
|
if (!p)
|
||||||
return -1;
|
return -1;
|
||||||
free(games[i].path);
|
free(g->path);
|
||||||
free(games[i].dir);
|
free(g->dir);
|
||||||
free(games[i].name);
|
free(g->name);
|
||||||
games[i].path = p;
|
g->path = p;
|
||||||
games[i].dir = strdup(dir);
|
g->dir = strdup(dir);
|
||||||
games[i].name = game_name(p, dir);
|
g->name = game_name(p, dir);
|
||||||
games_sort();
|
games_sort();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
games = realloc(games, sizeof(struct game) * (1 + games_nr));
|
games = realloc(games, sizeof(struct game) * (1 + games_nr));
|
||||||
if (!games)
|
if (!games)
|
||||||
|
@ -182,6 +194,9 @@ int games_lookup(const char *path)
|
||||||
while ((de = readdir(d))) {
|
while ((de = readdir(d))) {
|
||||||
/*if (de->d_type != DT_DIR)
|
/*if (de->d_type != DT_DIR)
|
||||||
continue;*/
|
continue;*/
|
||||||
|
if (game_lookup(de->d_name))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (!is_game(path, de->d_name))
|
if (!is_game(path, de->d_name))
|
||||||
continue;
|
continue;
|
||||||
n ++;
|
n ++;
|
||||||
|
@ -194,6 +209,9 @@ int games_lookup(const char *path)
|
||||||
while ((de = readdir(d)) && i < n) {
|
while ((de = readdir(d)) && i < n) {
|
||||||
/*if (de->d_type != DT_DIR)
|
/*if (de->d_type != DT_DIR)
|
||||||
continue;*/
|
continue;*/
|
||||||
|
if (game_lookup(de->d_name))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (games_add(path, de->d_name))
|
if (games_add(path, de->d_name))
|
||||||
continue;
|
continue;
|
||||||
i ++;
|
i ++;
|
||||||
|
|
|
@ -493,6 +493,8 @@ static void themes_sort()
|
||||||
qsort(themes, themes_nr, sizeof(struct theme), cmp_theme);
|
qsort(themes, themes_nr, sizeof(struct theme), cmp_theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct theme *theme_lookup(const char *name);
|
||||||
|
|
||||||
int themes_lookup(const char *path)
|
int themes_lookup(const char *path)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
@ -507,6 +509,8 @@ int themes_lookup(const char *path)
|
||||||
if (!d)
|
if (!d)
|
||||||
return -1;
|
return -1;
|
||||||
while ((de = readdir(d))) {
|
while ((de = readdir(d))) {
|
||||||
|
if (theme_lookup(de->d_name))
|
||||||
|
continue;
|
||||||
if (!is_theme(path, de->d_name))
|
if (!is_theme(path, de->d_name))
|
||||||
continue;
|
continue;
|
||||||
n ++;
|
n ++;
|
||||||
|
@ -519,6 +523,8 @@ int themes_lookup(const char *path)
|
||||||
while ((de = readdir(d)) && i < n) {
|
while ((de = readdir(d)) && i < n) {
|
||||||
/*if (de->d_type != DT_DIR)
|
/*if (de->d_type != DT_DIR)
|
||||||
continue;*/
|
continue;*/
|
||||||
|
if (theme_lookup(de->d_name))
|
||||||
|
continue;
|
||||||
if (!is_theme(path, de->d_name))
|
if (!is_theme(path, de->d_name))
|
||||||
continue;
|
continue;
|
||||||
p = getpath(path, de->d_name);
|
p = getpath(path, de->d_name);
|
||||||
|
@ -554,6 +560,7 @@ static struct theme *theme_lookup(const char *name)
|
||||||
if (!name || !*name) {
|
if (!name || !*name) {
|
||||||
if (themes_nr == 1)
|
if (themes_nr == 1)
|
||||||
return &themes[0];
|
return &themes[0];
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
for (i = 0; i<themes_nr; i ++) {
|
for (i = 0; i<themes_nr; i ++) {
|
||||||
if (!strcmp(themes[i].dir, name)) {
|
if (!strcmp(themes[i].dir, name)) {
|
||||||
|
|
Loading…
Reference in a new issue