2005-10-20 17:45:00 +02:00
|
|
|
/*
|
2005-11-26 17:52:51 +01:00
|
|
|
xml.c
|
|
|
|
|
2005-10-20 17:45:00 +02:00
|
|
|
Bygfoot Football Manager -- a small and simple GTK2-based
|
|
|
|
football management game.
|
|
|
|
|
|
|
|
http://bygfoot.sourceforge.net
|
|
|
|
|
|
|
|
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
#include "cup.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "free.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "league.h"
|
|
|
|
#include "misc.h"
|
2005-05-02 16:39:30 +02:00
|
|
|
#include "option.h"
|
2005-04-06 00:14:39 +02:00
|
|
|
#include "support.h"
|
|
|
|
#include "table.h"
|
|
|
|
#include "transfer_struct.h"
|
|
|
|
#include "user.h"
|
|
|
|
#include "variables.h"
|
|
|
|
#include "xml.h"
|
|
|
|
#include "xml_loadsave_cup.h"
|
|
|
|
#include "xml_loadsave_fixtures.h"
|
|
|
|
#include "xml_loadsave_league.h"
|
2005-04-30 15:57:58 +02:00
|
|
|
#include "xml_loadsave_league_stat.h"
|
2005-04-06 00:14:39 +02:00
|
|
|
#include "xml_loadsave_live_game.h"
|
|
|
|
#include "xml_loadsave_table.h"
|
|
|
|
#include "xml_loadsave_teams.h"
|
|
|
|
#include "xml_loadsave_transfers.h"
|
|
|
|
#include "xml_loadsave_users.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
xml_load_users(const gchar *dirname, const gchar *basename)
|
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_load_users\n");
|
|
|
|
#endif
|
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
gint i;
|
|
|
|
gchar buf[SMALL];
|
|
|
|
|
|
|
|
free_users(TRUE);
|
|
|
|
|
|
|
|
xml_loadsave_users_read(dirname, basename);
|
|
|
|
|
|
|
|
for(i=0;i<users->len;i++)
|
|
|
|
{
|
2006-01-07 21:01:03 +01:00
|
|
|
sprintf(buf, "%s%s%s___user_%02d_options",
|
|
|
|
dirname, G_DIR_SEPARATOR_S, basename, i);
|
2009-03-10 21:58:34 +01:00
|
|
|
file_load_opt_file(buf, &usr(i).options, FALSE);
|
2005-04-06 00:14:39 +02:00
|
|
|
|
2006-01-07 21:01:03 +01:00
|
|
|
sprintf(buf, "%s%s%s___user_%02d_live_game.xml",
|
|
|
|
dirname, G_DIR_SEPARATOR_S, basename, i);
|
2005-04-06 00:14:39 +02:00
|
|
|
xml_loadsave_live_game_read(buf, &usr(i).live_game);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-02-06 20:25:45 +01:00
|
|
|
xml_load_league(Bygfoot *bygfoot, GArray *league_list, const gchar *dirname, const gchar *basename)
|
2005-04-06 00:14:39 +02:00
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_load_league\n");
|
|
|
|
#endif
|
|
|
|
|
2008-11-21 18:00:47 +01:00
|
|
|
gchar buf[SMALL], team_file[SMALL];
|
2005-04-14 21:07:25 +02:00
|
|
|
League new = league_new(FALSE);
|
2005-04-06 00:14:39 +02:00
|
|
|
gchar *prefix = g_strndup(basename, strlen(basename) - 4);
|
2021-02-06 20:25:45 +01:00
|
|
|
League *league = NULL;
|
2005-04-06 00:14:39 +02:00
|
|
|
|
2021-02-06 20:25:45 +01:00
|
|
|
g_array_append_val(league_list, new);
|
|
|
|
league = &g_array_index(league_list, League, league_list->len - 1);
|
2005-04-06 00:14:39 +02:00
|
|
|
|
2008-11-21 18:00:47 +01:00
|
|
|
sprintf(buf, "%s%s%s", dirname, G_DIR_SEPARATOR_S, basename);
|
|
|
|
sprintf(team_file, "%s%s%s_teams.xml", dirname, G_DIR_SEPARATOR_S, prefix);
|
2021-02-06 20:25:45 +01:00
|
|
|
xml_loadsave_league_read(buf, team_file, league);
|
2008-11-21 18:00:47 +01:00
|
|
|
|
2021-02-06 20:25:45 +01:00
|
|
|
sprintf(buf, _("Loading league: %s"), league->name);
|
2006-01-07 21:01:03 +01:00
|
|
|
|
2020-12-28 06:09:02 +01:00
|
|
|
bygfoot_show_progress(bygfoot, bygfoot_get_progress_bar_fraction(bygfoot), buf,
|
2009-01-11 11:23:55 +01:00
|
|
|
PIC_TYPE_LOAD);
|
2005-04-06 00:14:39 +02:00
|
|
|
|
2005-08-16 14:49:45 +02:00
|
|
|
if(debug > 80)
|
2005-12-14 15:05:59 +01:00
|
|
|
g_print("%s\n", buf);
|
2005-08-16 14:49:45 +02:00
|
|
|
|
2005-10-24 22:50:48 +02:00
|
|
|
sprintf(buf, "%s%s%s_fixtures.xml", dirname, G_DIR_SEPARATOR_S, prefix);
|
2021-02-06 20:25:45 +01:00
|
|
|
xml_loadsave_fixtures_read(buf, league->fixtures);
|
2005-04-06 00:14:39 +02:00
|
|
|
|
2005-10-24 22:50:48 +02:00
|
|
|
sprintf(buf, "%s%s%s_stat.xml", dirname, G_DIR_SEPARATOR_S, prefix);
|
2021-02-06 20:25:45 +01:00
|
|
|
xml_loadsave_league_stat_read(buf, &league->stats);
|
2005-04-30 15:57:58 +02:00
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
g_free(prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-12-28 06:09:02 +01:00
|
|
|
xml_load_cup(Bygfoot *bygfoot, Cup *cup, const gchar *dirname, const gchar *basename)
|
2005-04-06 00:14:39 +02:00
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_load_cup\n");
|
|
|
|
#endif
|
|
|
|
|
2005-04-22 17:17:39 +02:00
|
|
|
gchar buf[SMALL];
|
2005-04-06 00:14:39 +02:00
|
|
|
gchar *prefix = g_strndup(basename, strlen(basename) - 4);
|
|
|
|
|
2005-10-24 22:50:48 +02:00
|
|
|
sprintf(buf, "%s%s%s", dirname, G_DIR_SEPARATOR_S, basename);
|
2005-04-14 21:07:25 +02:00
|
|
|
xml_loadsave_cup_read(buf, cup);
|
2005-04-06 00:14:39 +02:00
|
|
|
|
2005-06-18 16:45:29 +02:00
|
|
|
sprintf(buf, _("Loading cup: %s"),
|
2005-10-09 11:35:44 +02:00
|
|
|
cup->name);
|
2020-12-28 06:09:02 +01:00
|
|
|
bygfoot_show_progress(bygfoot, bygfoot_get_progress_bar_fraction(bygfoot), buf,
|
2009-01-11 11:23:55 +01:00
|
|
|
PIC_TYPE_LOAD);
|
2005-04-06 00:14:39 +02:00
|
|
|
|
2005-08-16 14:49:45 +02:00
|
|
|
if(debug > 80)
|
2005-12-14 15:05:59 +01:00
|
|
|
g_print("%s\n", buf);
|
2005-08-16 14:49:45 +02:00
|
|
|
|
2005-10-24 22:50:48 +02:00
|
|
|
sprintf(buf, "%s%s%s_fixtures.xml", dirname, G_DIR_SEPARATOR_S, prefix);
|
2005-05-08 19:56:26 +02:00
|
|
|
xml_loadsave_fixtures_read(buf, cup->fixtures);
|
2005-04-06 00:14:39 +02:00
|
|
|
|
|
|
|
g_free(prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xml_load_transfers(const gchar *dirname, const gchar *basename)
|
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_load_transfers\n");
|
|
|
|
#endif
|
|
|
|
|
2005-04-06 00:14:39 +02:00
|
|
|
gchar buf[SMALL];
|
|
|
|
|
2005-10-24 22:50:48 +02:00
|
|
|
sprintf(buf, "%s%s%s___transfer_list.xml", dirname, G_DIR_SEPARATOR_S, basename);
|
2005-04-06 00:14:39 +02:00
|
|
|
|
|
|
|
free_g_array(&transfer_list);
|
|
|
|
transfer_list = g_array_new(FALSE, FALSE, sizeof(Transfer));
|
|
|
|
|
|
|
|
xml_loadsave_transfers_read(buf);
|
|
|
|
}
|
2005-10-15 18:49:04 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
xml_write_string(FILE *fil, const gchar *string, gint tag, const gchar* indent)
|
|
|
|
{
|
2008-11-25 14:50:07 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("xml_write_string\n");
|
|
|
|
#endif
|
|
|
|
|
2005-10-15 18:49:04 +02:00
|
|
|
if(string == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(fil, "%s<_%d>%s</_%d>\n", indent, tag, string, tag);
|
|
|
|
}
|