2010-01-30 20:22:04 +01:00
|
|
|
#if defined(GEKKO)
|
|
|
|
# include <network.h>
|
|
|
|
#else
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
2010-01-25 14:01:22 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_image.h>
|
|
|
|
|
2010-01-29 07:35:40 +01:00
|
|
|
#include <utils.hh>
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
#include "game_info.hh"
|
|
|
|
|
|
|
|
#define VERSION_BASE (0x1978)
|
2010-01-30 21:03:17 +01:00
|
|
|
#define VERSION(x) (VERSION_BASE + (x))
|
|
|
|
/* Current magic */
|
2010-03-28 14:42:19 +02:00
|
|
|
#define VERSION_MAGIC VERSION(2)
|
2010-01-25 14:01:22 +01:00
|
|
|
|
2010-03-27 08:33:06 +01:00
|
|
|
struct game_info
|
|
|
|
{
|
|
|
|
/* These two MUST stay the same */
|
|
|
|
uint32_t sz;
|
|
|
|
uint16_t version_magic;
|
|
|
|
uint16_t flags;
|
|
|
|
|
|
|
|
uint16_t author_off;
|
|
|
|
uint16_t name_off;
|
|
|
|
uint16_t screenshot_off; /* In PNG format */
|
|
|
|
uint16_t filename_off;
|
|
|
|
uint16_t score;
|
|
|
|
uint16_t year;
|
2010-03-28 14:42:19 +02:00
|
|
|
uint8_t genre;
|
|
|
|
uint8_t players;
|
|
|
|
uint16_t creator_off;
|
|
|
|
uint16_t musician_off;
|
|
|
|
uint16_t graphics_artist_off;
|
2010-03-27 08:33:06 +01:00
|
|
|
uint8_t data[]; /* 4-byte aligned */
|
|
|
|
};
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
struct game_info_v0
|
|
|
|
{
|
|
|
|
uint32_t sz;
|
|
|
|
uint16_t version_magic;
|
|
|
|
|
|
|
|
uint16_t author_off;
|
|
|
|
uint16_t name_off;
|
|
|
|
uint16_t screenshot_off; /* In PNG format */
|
|
|
|
uint16_t filename_off;
|
2010-01-30 20:21:01 +01:00
|
|
|
uint16_t score;
|
2010-01-25 14:01:22 +01:00
|
|
|
uint8_t data[]; /* 4-byte aligned */
|
|
|
|
};
|
|
|
|
|
2010-01-30 21:03:17 +01:00
|
|
|
struct game_info_v1
|
|
|
|
{
|
|
|
|
uint32_t sz;
|
|
|
|
uint16_t version_magic;
|
|
|
|
uint16_t flags;
|
|
|
|
|
|
|
|
uint16_t author_off;
|
|
|
|
uint16_t name_off;
|
|
|
|
uint16_t screenshot_off; /* In PNG format */
|
|
|
|
uint16_t filename_off;
|
|
|
|
uint16_t score;
|
2010-01-31 08:58:48 +01:00
|
|
|
uint16_t year;
|
2010-01-30 21:03:17 +01:00
|
|
|
uint8_t data[]; /* 4-byte aligned */
|
|
|
|
};
|
|
|
|
|
2010-03-18 13:23:11 +01:00
|
|
|
struct game_info_v2
|
|
|
|
{
|
|
|
|
uint32_t sz;
|
|
|
|
uint16_t version_magic;
|
|
|
|
uint16_t flags;
|
|
|
|
|
|
|
|
uint16_t author_off;
|
|
|
|
uint16_t name_off;
|
|
|
|
uint16_t screenshot_off; /* In PNG format */
|
|
|
|
uint16_t filename_off;
|
|
|
|
uint16_t score;
|
|
|
|
uint16_t year;
|
2010-03-27 08:53:12 +01:00
|
|
|
uint8_t genre;
|
|
|
|
uint8_t players;
|
2010-03-27 08:46:40 +01:00
|
|
|
uint16_t creator_off;
|
2010-03-18 13:23:11 +01:00
|
|
|
uint16_t musician_off;
|
|
|
|
uint16_t graphics_artist_off;
|
|
|
|
uint8_t data[]; /* 4-byte aligned */
|
|
|
|
};
|
|
|
|
|
2010-01-30 21:03:17 +01:00
|
|
|
static void demarshal_v0(struct game_info_v0 *src)
|
|
|
|
{
|
|
|
|
src->sz = ntohl(src->sz);
|
|
|
|
src->version_magic = ntohs(src->version_magic);
|
|
|
|
src->author_off = ntohs(src->author_off);
|
|
|
|
src->name_off = ntohs(src->name_off);
|
|
|
|
src->filename_off = ntohs(src->filename_off);
|
|
|
|
src->screenshot_off = ntohs(src->screenshot_off);
|
|
|
|
src->score = ntohs(src->score);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void demarshal_v1(struct game_info_v1 *src)
|
|
|
|
{
|
2010-03-18 13:23:11 +01:00
|
|
|
demarshal_v0((struct game_info_v0 *)src);
|
2010-01-30 21:03:17 +01:00
|
|
|
src->flags = ntohs(src->flags);
|
2010-03-18 13:23:11 +01:00
|
|
|
src->year = ntohs(src->year);
|
2010-01-30 21:03:17 +01:00
|
|
|
}
|
|
|
|
|
2010-03-18 13:23:11 +01:00
|
|
|
static void demarshal_v2(struct game_info_v2 *src)
|
|
|
|
{
|
|
|
|
demarshal_v1((struct game_info_v1 *)src);
|
|
|
|
src->musician_off = ntohs(src->musician_off);
|
2010-03-27 08:46:40 +01:00
|
|
|
src->creator_off = ntohs(src->creator_off);
|
2010-03-18 13:23:11 +01:00
|
|
|
src->graphics_artist_off = ntohs(src->graphics_artist_off);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-28 09:14:01 +02:00
|
|
|
static bool from_v0(GameInfo *dst, struct game_info_v0 *p)
|
2010-01-30 21:03:17 +01:00
|
|
|
{
|
2010-03-28 09:14:01 +02:00
|
|
|
demarshal_v0(p);
|
|
|
|
|
|
|
|
dst->publisher = xstrdup((char*)p->data + p->author_off);
|
|
|
|
dst->name = xstrdup((char*)p->data + p->name_off);
|
|
|
|
dst->filename = xstrdup((char*)p->data + p->filename_off);
|
|
|
|
dst->score = p->score;
|
|
|
|
dst->year = 1984;
|
|
|
|
dst->graphics_artist = xstrdup(" ");
|
|
|
|
dst->musician = xstrdup(" ");
|
|
|
|
dst->creator = xstrdup(" ");
|
|
|
|
dst->genre = GENRE_UNKNOWN;
|
|
|
|
dst->players = 1;
|
|
|
|
|
|
|
|
dst->screenshot = sdl_surface_from_data(p->data + p->screenshot_off,
|
|
|
|
p->sz - p->screenshot_off);
|
|
|
|
if (!dst->screenshot)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2010-01-30 21:03:17 +01:00
|
|
|
}
|
|
|
|
|
2010-03-28 09:14:01 +02:00
|
|
|
static bool from_v1(GameInfo *dst, struct game_info_v1 *p)
|
2010-01-30 21:03:17 +01:00
|
|
|
{
|
2010-03-28 09:14:01 +02:00
|
|
|
demarshal_v1(p);
|
|
|
|
|
|
|
|
dst->publisher = xstrdup((char*)p->data + p->author_off);
|
|
|
|
dst->name = xstrdup((char*)p->data + p->name_off);
|
|
|
|
dst->filename = xstrdup((char*)p->data + p->filename_off);
|
|
|
|
dst->score = p->score;
|
|
|
|
dst->year = p->year;
|
|
|
|
dst->graphics_artist = xstrdup(" ");
|
|
|
|
dst->musician = xstrdup(" ");
|
|
|
|
dst->creator = xstrdup(" ");
|
|
|
|
dst->genre = GENRE_UNKNOWN;
|
|
|
|
dst->players = 1;
|
|
|
|
|
|
|
|
dst->screenshot = sdl_surface_from_data(p->data + p->screenshot_off,
|
|
|
|
p->sz - p->screenshot_off);
|
|
|
|
if (!dst->screenshot)
|
|
|
|
return false;
|
2010-01-30 21:03:17 +01:00
|
|
|
|
2010-03-28 09:14:01 +02:00
|
|
|
return true;
|
2010-01-30 21:03:17 +01:00
|
|
|
}
|
|
|
|
|
2010-03-28 09:14:01 +02:00
|
|
|
static bool from_v2(GameInfo *dst, struct game_info_v2 *p)
|
2010-03-18 13:23:11 +01:00
|
|
|
{
|
2010-03-28 09:14:01 +02:00
|
|
|
demarshal_v2(p);
|
|
|
|
|
|
|
|
dst->publisher = xstrdup((char*)p->data + p->author_off);
|
|
|
|
dst->name = xstrdup((char*)p->data + p->name_off);
|
|
|
|
dst->filename = xstrdup((char*)p->data + p->filename_off);
|
|
|
|
dst->score = p->score;
|
|
|
|
dst->year = p->year;
|
|
|
|
dst->graphics_artist = xstrdup((char*)p->data + p->graphics_artist_off);
|
|
|
|
dst->musician = xstrdup((char*)p->data + p->musician_off);
|
|
|
|
dst->creator = xstrdup((char*)p->data + p->creator_off);
|
|
|
|
dst->genre = p->genre;
|
|
|
|
dst->players = p->players;
|
|
|
|
|
|
|
|
dst->screenshot = sdl_surface_from_data(p->data + p->screenshot_off,
|
|
|
|
p->sz - p->screenshot_off);
|
|
|
|
if (!dst->screenshot)
|
|
|
|
return false;
|
2010-03-18 13:23:11 +01:00
|
|
|
|
2010-03-28 09:14:01 +02:00
|
|
|
return true;
|
2010-03-18 13:23:11 +01:00
|
|
|
}
|
|
|
|
|
2010-01-30 21:03:17 +01:00
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
GameInfo::GameInfo(const char *filename,
|
2010-03-26 07:34:58 +01:00
|
|
|
const char *name, const char *publisher,
|
2010-03-27 08:46:40 +01:00
|
|
|
const char *creator, const char *graphics_artist,
|
|
|
|
const char *musician, SDL_Surface *image)
|
2010-01-25 14:01:22 +01:00
|
|
|
{
|
2010-01-30 13:48:47 +01:00
|
|
|
this->filename = xstrdup(filename);
|
2010-01-30 19:52:14 +01:00
|
|
|
if (strcmp(name, " ") == 0)
|
|
|
|
this->name = xstrdup(filename);
|
|
|
|
else
|
|
|
|
this->name = xstrdup(name);
|
2010-03-26 07:34:58 +01:00
|
|
|
this->publisher = xstrdup(publisher);
|
|
|
|
this->creator = xstrdup(creator);
|
2010-03-27 08:46:40 +01:00
|
|
|
this->graphics_artist = xstrdup(graphics_artist);
|
2010-03-26 07:34:58 +01:00
|
|
|
this->musician = xstrdup(musician);
|
2010-03-28 14:42:19 +02:00
|
|
|
this->graphics_artist = xstrdup(graphics_artist);
|
|
|
|
this->creator = xstrdup(creator);
|
|
|
|
this->musician = xstrdup(musician);
|
2010-01-25 14:01:22 +01:00
|
|
|
this->screenshot = image;
|
2010-03-26 07:34:58 +01:00
|
|
|
this->genre = GENRE_UNKNOWN;
|
|
|
|
this->players = 1;
|
2010-01-30 20:06:18 +01:00
|
|
|
this->score = 0;
|
2010-01-31 08:58:48 +01:00
|
|
|
this->year = 1982;
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GameInfo::GameInfo(GameInfo *gi)
|
|
|
|
{
|
|
|
|
if (!gi)
|
|
|
|
{
|
2010-01-30 13:48:47 +01:00
|
|
|
this->resetDefaults();
|
2010-01-25 14:01:22 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-30 13:48:47 +01:00
|
|
|
this->name = xstrdup(gi->name);
|
2010-03-26 07:34:58 +01:00
|
|
|
this->publisher = xstrdup(gi->publisher);
|
2010-01-30 13:48:47 +01:00
|
|
|
this->filename = xstrdup(gi->filename);
|
2010-03-27 08:46:40 +01:00
|
|
|
this->graphics_artist = xstrdup(gi->graphics_artist);
|
|
|
|
this->creator = xstrdup(gi->creator);
|
2010-03-26 07:34:58 +01:00
|
|
|
this->musician = xstrdup(gi->musician);
|
2010-01-25 14:01:22 +01:00
|
|
|
this->screenshot = NULL;
|
2010-03-26 07:34:58 +01:00
|
|
|
this->players = gi->players;
|
|
|
|
this->score = gi->score;
|
2010-01-31 08:58:48 +01:00
|
|
|
this->year = gi->year;
|
2010-03-26 07:34:58 +01:00
|
|
|
this->genre = gi->genre;
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
if (gi->screenshot)
|
2010-03-26 07:34:58 +01:00
|
|
|
this->screenshot = SDL_DisplayFormat(gi->screenshot);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GameInfo::~GameInfo()
|
2010-03-27 08:46:40 +01:00
|
|
|
{
|
|
|
|
this->freeAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameInfo::freeAll()
|
2010-01-25 14:01:22 +01:00
|
|
|
{
|
2010-01-30 15:34:04 +01:00
|
|
|
free((void*)this->name);
|
2010-03-26 07:34:58 +01:00
|
|
|
free((void*)this->publisher);
|
2010-01-30 15:34:04 +01:00
|
|
|
free((void*)this->filename);
|
2010-03-26 07:34:58 +01:00
|
|
|
free((void*)this->creator);
|
2010-03-27 08:46:40 +01:00
|
|
|
free((void*)this->graphics_artist);
|
2010-03-26 07:34:58 +01:00
|
|
|
free((void*)this->musician);
|
2010-01-30 15:34:04 +01:00
|
|
|
|
|
|
|
SDL_FreeSurface(this->screenshot);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameInfo::resetDefaults()
|
|
|
|
{
|
2010-03-27 08:46:40 +01:00
|
|
|
this->freeAll();
|
2010-01-25 14:01:22 +01:00
|
|
|
|
2010-01-30 13:48:47 +01:00
|
|
|
this->name = xstrdup(" ");
|
2010-03-26 07:34:58 +01:00
|
|
|
this->publisher = xstrdup(" ");
|
2010-01-30 15:47:14 +01:00
|
|
|
this->filename = xstrdup("unknown");
|
2010-03-27 08:46:40 +01:00
|
|
|
this->creator = xstrdup(" ");
|
|
|
|
this->musician = xstrdup(" ");
|
|
|
|
this->graphics_artist = xstrdup(" ");
|
2010-01-25 14:01:22 +01:00
|
|
|
this->screenshot = NULL;
|
2010-03-27 08:46:40 +01:00
|
|
|
|
|
|
|
this->genre = GENRE_UNKNOWN;
|
|
|
|
this->players = 1;
|
|
|
|
this->score = 0;
|
|
|
|
this->year = 1982;
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
2010-03-27 08:33:06 +01:00
|
|
|
void *GameInfo::dump(size_t *out_sz)
|
2010-01-25 14:01:22 +01:00
|
|
|
{
|
|
|
|
size_t total_sz = sizeof(struct game_info);
|
|
|
|
size_t png_sz;
|
|
|
|
struct game_info *out;
|
|
|
|
void *png_data;
|
|
|
|
|
|
|
|
if (!this->screenshot)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Convert surface to PNG */
|
|
|
|
png_data = sdl_surface_to_png(this->screenshot, &png_sz);
|
|
|
|
panic_if(!png_data, "Cannot create PNG from surface\n");
|
|
|
|
|
2010-03-26 07:34:58 +01:00
|
|
|
total_sz += strlen(this->publisher) + 1;
|
2010-01-25 14:01:22 +01:00
|
|
|
total_sz += strlen(this->name) + 1;
|
2010-01-30 17:04:42 +01:00
|
|
|
total_sz += strlen(this->filename) + 1;
|
2010-03-28 14:42:19 +02:00
|
|
|
total_sz += strlen(this->creator) + 1;
|
|
|
|
total_sz += strlen(this->musician) + 1;
|
|
|
|
total_sz += strlen(this->graphics_artist) + 1;
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
total_sz += png_sz;
|
|
|
|
/* 4-byte align */
|
|
|
|
total_sz += 4 - (total_sz & 3);
|
|
|
|
|
|
|
|
/* Allocate everything */
|
|
|
|
out = (struct game_info*)xmalloc(total_sz);
|
|
|
|
out->sz = total_sz;
|
2010-01-30 20:21:01 +01:00
|
|
|
out->score = this->score;
|
2010-01-31 08:58:48 +01:00
|
|
|
out->year = this->year;
|
2010-03-28 14:42:19 +02:00
|
|
|
out->genre = this->genre;
|
|
|
|
out->players = this->players;
|
2010-01-25 14:01:22 +01:00
|
|
|
out->version_magic = VERSION_MAGIC;
|
2010-01-30 20:21:01 +01:00
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
out->author_off = 0; /* Starts AFTER the header */
|
2010-03-26 07:34:58 +01:00
|
|
|
out->name_off = out->author_off + strlen(this->publisher) + 1;
|
2010-01-30 17:04:42 +01:00
|
|
|
out->filename_off = out->name_off + strlen(this->name) + 1;
|
2010-03-28 14:42:19 +02:00
|
|
|
out->creator_off = out->filename_off + strlen(this->filename) + 1;
|
|
|
|
out->musician_off = out->creator_off + strlen(this->creator) + 1;
|
|
|
|
out->graphics_artist_off = out->musician_off + strlen(this->musician) + 1;
|
|
|
|
out->screenshot_off = out->graphics_artist_off + strlen(this->graphics_artist) + 1;
|
2010-01-25 14:01:22 +01:00
|
|
|
|
2010-01-30 20:21:01 +01:00
|
|
|
|
2010-03-26 07:34:58 +01:00
|
|
|
memcpy(out->data + out->author_off, this->publisher, strlen(this->publisher) + 1);
|
2010-01-25 14:01:22 +01:00
|
|
|
memcpy(out->data + out->name_off, this->name, strlen(this->name) + 1);
|
2010-01-30 17:04:42 +01:00
|
|
|
memcpy(out->data + out->filename_off, this->filename, strlen(this->filename) + 1);
|
2010-03-28 14:42:19 +02:00
|
|
|
memcpy(out->data + out->creator_off, this->creator, strlen(this->creator) + 1);
|
|
|
|
memcpy(out->data + out->musician_off, this->musician, strlen(this->musician) + 1);
|
|
|
|
memcpy(out->data + out->graphics_artist_off, this->graphics_artist, strlen(this->graphics_artist) + 1);
|
2010-01-25 14:01:22 +01:00
|
|
|
memcpy(out->data + out->screenshot_off, png_data, png_sz);
|
|
|
|
|
2010-03-27 08:33:06 +01:00
|
|
|
*out_sz = out->sz;
|
2010-01-30 20:21:01 +01:00
|
|
|
/* Marshall it all */
|
2010-01-25 14:01:22 +01:00
|
|
|
out->sz = htonl(out->sz);
|
|
|
|
out->author_off = htons(out->author_off);
|
|
|
|
out->version_magic = htons(out->version_magic);
|
|
|
|
out->name_off = htons(out->name_off);
|
2010-01-30 17:04:42 +01:00
|
|
|
out->filename_off = htons(out->filename_off);
|
2010-03-28 14:42:19 +02:00
|
|
|
out->creator_off = htons(out->creator_off);
|
|
|
|
out->musician_off = htons(out->musician_off);
|
|
|
|
out->graphics_artist_off = htons(out->graphics_artist_off);
|
2010-01-25 14:01:22 +01:00
|
|
|
out->screenshot_off = htons(out->screenshot_off);
|
2010-01-30 20:21:01 +01:00
|
|
|
out->score = htons(out->score);
|
2010-01-31 08:58:48 +01:00
|
|
|
out->year = htons(out->year);
|
2010-01-25 14:01:22 +01:00
|
|
|
|
2010-03-27 08:33:06 +01:00
|
|
|
return (void *)out;
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GameInfo::fromDump(struct game_info *gi)
|
|
|
|
{
|
2010-03-28 09:14:01 +02:00
|
|
|
bool ret;
|
|
|
|
|
|
|
|
this->freeAll();
|
2010-01-25 14:01:22 +01:00
|
|
|
|
2010-03-28 09:14:01 +02:00
|
|
|
/* Demarshal and convert */
|
|
|
|
switch (ntohs(gi->version_magic))
|
2010-01-30 21:03:17 +01:00
|
|
|
{
|
|
|
|
case VERSION(0):
|
2010-03-28 09:14:01 +02:00
|
|
|
ret = from_v0(this, (struct game_info_v0 *)gi); break;
|
2010-01-30 21:03:17 +01:00
|
|
|
case VERSION(1):
|
2010-03-28 09:14:01 +02:00
|
|
|
ret = from_v1(this, (struct game_info_v1 *)gi); break;
|
2010-03-18 13:23:11 +01:00
|
|
|
case VERSION(2):
|
2010-03-28 09:14:01 +02:00
|
|
|
ret = from_v2(this, (struct game_info_v2 *)gi); break;
|
2010-01-30 21:03:17 +01:00
|
|
|
default:
|
|
|
|
/* Garbage, let's return */
|
|
|
|
warning("game info garbage magic: %2x\n",
|
2010-03-28 09:14:01 +02:00
|
|
|
ntohs(gi->version_magic));
|
2010-01-30 21:03:17 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-28 09:14:01 +02:00
|
|
|
return ret;
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GameInfo *GameInfo::loadFromFile(const char *fileName)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
struct game_info *p;
|
|
|
|
GameInfo *out = NULL;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
if (stat(fileName, &st) < 0)
|
|
|
|
return NULL;
|
|
|
|
if (st.st_size <= (signed)sizeof(struct game_info))
|
|
|
|
{
|
|
|
|
warning("Size of %s is too small: %d vs minimum %d bytes\n",
|
|
|
|
fileName, (int)st.st_size, (signed)sizeof(struct game_info) + 4);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (st.st_size % 4 != 0)
|
|
|
|
{
|
|
|
|
warning("Size of %s is unreasonable: %d\n", fileName, (int)st.st_size);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fp = fopen(fileName, "r");
|
|
|
|
if (!fp)
|
|
|
|
return NULL;
|
|
|
|
p = (struct game_info*)xmalloc(st.st_size);
|
|
|
|
if (fread(p, 1, st.st_size, fp) == (unsigned)st.st_size)
|
|
|
|
{
|
|
|
|
out = new GameInfo();
|
|
|
|
if (out->fromDump(p) == false)
|
|
|
|
{
|
|
|
|
warning("Converting %s to GameInfo failed\n",
|
|
|
|
fileName);
|
|
|
|
delete out;
|
|
|
|
out = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
warning("Could not read %s\n", fileName);
|
|
|
|
|
|
|
|
free(p);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2010-03-28 17:59:56 +02:00
|
|
|
void GameInfo::setGeneric(const char **what, const char *who)
|
2010-01-25 14:01:22 +01:00
|
|
|
{
|
2010-03-28 17:59:56 +02:00
|
|
|
if (strlen(who) == 0)
|
|
|
|
who = " ";
|
|
|
|
free((void*)*what);
|
|
|
|
*what = xstrdup(who);
|
|
|
|
if (strcmp(who, " ") != 0)
|
2010-01-30 20:06:18 +01:00
|
|
|
this->score++;
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
2010-03-28 17:59:56 +02:00
|
|
|
void GameInfo::setAuthor(const char *who)
|
|
|
|
{
|
|
|
|
this->setGeneric(&this->publisher, who);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameInfo::setCreator(const char *who)
|
|
|
|
{
|
|
|
|
this->setGeneric(&this->creator, who);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameInfo::setMusician(const char *who)
|
|
|
|
{
|
|
|
|
this->setGeneric(&this->musician, who);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameInfo::setGraphicsArtist(const char *who)
|
|
|
|
{
|
|
|
|
this->setGeneric(&this->graphics_artist, who);
|
|
|
|
}
|
|
|
|
|
2010-01-31 08:58:48 +01:00
|
|
|
void GameInfo::setYear(uint16_t year)
|
|
|
|
{
|
|
|
|
this->year = year;
|
|
|
|
this->score++;
|
|
|
|
}
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
void GameInfo::setName(const char *name)
|
|
|
|
{
|
2010-01-31 08:58:48 +01:00
|
|
|
if (strlen(name) == 0)
|
|
|
|
name = " ";
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
free((void*)this->name);
|
|
|
|
this->name = xstrdup(name);
|
2010-01-30 20:06:18 +01:00
|
|
|
if (strcmp(name, " ") != 0)
|
|
|
|
this->score++;
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
2010-01-30 20:03:10 +01:00
|
|
|
|
|
|
|
void GameInfo::setScreenshot(SDL_Surface *scr)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(this->screenshot);
|
|
|
|
this->screenshot = scr;
|
2010-01-30 20:06:18 +01:00
|
|
|
if (scr != NULL)
|
|
|
|
this->score++;
|
2010-01-30 20:03:10 +01:00
|
|
|
}
|