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);
|
||||
* improved debugger;
|
||||
* save vars in _G;
|
||||
* no duplicated games while looking gamespaths;
|
||||
* many small bugfixes...
|
||||
|
||||
-- Peter Kosyh <p.kosyh@gmail.com> Tue, 01 Jun 2010 17:40:00 +0300
|
||||
|
|
|
@ -57,27 +57,40 @@ int games_nr = 0;
|
|||
|
||||
void free_last(void);
|
||||
|
||||
int game_select(const char *name)
|
||||
static struct game *game_lookup(const char *name)
|
||||
{
|
||||
int i;
|
||||
free_last();
|
||||
if (!name || !*name) {
|
||||
if (games_nr == 1)
|
||||
name = games[0].dir;
|
||||
else
|
||||
return 0;
|
||||
return &games[0];
|
||||
return NULL;
|
||||
}
|
||||
chdir(game_cwd);
|
||||
for (i = 0; i<games_nr; i ++) {
|
||||
if (!strcmp(games[i].dir, name)) {
|
||||
return &games[i];
|
||||
}
|
||||
}
|
||||
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 = games[i].dir;
|
||||
curgame_dir = g->dir;
|
||||
instead_done();
|
||||
if (instead_init()) {
|
||||
curgame_dir = oldgame;
|
||||
return -1;
|
||||
}
|
||||
if (chdir(games[i].path)) {
|
||||
if (chdir(g->path)) {
|
||||
curgame_dir = oldgame;
|
||||
return -1;
|
||||
}
|
||||
|
@ -88,7 +101,6 @@ int game_select(const char *name)
|
|||
instead_eval("game:ini()"); instead_clear();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -139,25 +151,25 @@ static int games_add(const char *path, const char *dir)
|
|||
|
||||
int games_replace(const char *path, const char *dir)
|
||||
{
|
||||
int i, rc;
|
||||
int rc;
|
||||
char *p;
|
||||
struct game *g;
|
||||
if (!is_game(path, dir))
|
||||
return -1;
|
||||
for (i = 0; i<games_nr; i ++) {
|
||||
if (!strcmp(games[i].dir, dir)) {
|
||||
g = game_lookup(dir);
|
||||
if (g) {
|
||||
p = getpath(path, dir);
|
||||
if (!p)
|
||||
return -1;
|
||||
free(games[i].path);
|
||||
free(games[i].dir);
|
||||
free(games[i].name);
|
||||
games[i].path = p;
|
||||
games[i].dir = strdup(dir);
|
||||
games[i].name = game_name(p, dir);
|
||||
free(g->path);
|
||||
free(g->dir);
|
||||
free(g->name);
|
||||
g->path = p;
|
||||
g->dir = strdup(dir);
|
||||
g->name = game_name(p, dir);
|
||||
games_sort();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
games = realloc(games, sizeof(struct game) * (1 + games_nr));
|
||||
if (!games)
|
||||
return -1;
|
||||
|
@ -182,6 +194,9 @@ int games_lookup(const char *path)
|
|||
while ((de = readdir(d))) {
|
||||
/*if (de->d_type != DT_DIR)
|
||||
continue;*/
|
||||
if (game_lookup(de->d_name))
|
||||
continue;
|
||||
|
||||
if (!is_game(path, de->d_name))
|
||||
continue;
|
||||
n ++;
|
||||
|
@ -194,6 +209,9 @@ int games_lookup(const char *path)
|
|||
while ((de = readdir(d)) && i < n) {
|
||||
/*if (de->d_type != DT_DIR)
|
||||
continue;*/
|
||||
if (game_lookup(de->d_name))
|
||||
continue;
|
||||
|
||||
if (games_add(path, de->d_name))
|
||||
continue;
|
||||
i ++;
|
||||
|
|
|
@ -493,6 +493,8 @@ static void themes_sort()
|
|||
qsort(themes, themes_nr, sizeof(struct theme), cmp_theme);
|
||||
}
|
||||
|
||||
static struct theme *theme_lookup(const char *name);
|
||||
|
||||
int themes_lookup(const char *path)
|
||||
{
|
||||
char *p;
|
||||
|
@ -507,6 +509,8 @@ int themes_lookup(const char *path)
|
|||
if (!d)
|
||||
return -1;
|
||||
while ((de = readdir(d))) {
|
||||
if (theme_lookup(de->d_name))
|
||||
continue;
|
||||
if (!is_theme(path, de->d_name))
|
||||
continue;
|
||||
n ++;
|
||||
|
@ -519,6 +523,8 @@ int themes_lookup(const char *path)
|
|||
while ((de = readdir(d)) && i < n) {
|
||||
/*if (de->d_type != DT_DIR)
|
||||
continue;*/
|
||||
if (theme_lookup(de->d_name))
|
||||
continue;
|
||||
if (!is_theme(path, de->d_name))
|
||||
continue;
|
||||
p = getpath(path, de->d_name);
|
||||
|
@ -554,6 +560,7 @@ static struct theme *theme_lookup(const char *name)
|
|||
if (!name || !*name) {
|
||||
if (themes_nr == 1)
|
||||
return &themes[0];
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i<themes_nr; i ++) {
|
||||
if (!strcmp(themes[i].dir, name)) {
|
||||
|
|
Loading…
Reference in a new issue