bygfoot/src/xml.c

226 lines
6.5 KiB
C
Raw Normal View History

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"
gint
xml_get_tag_from_name(const gchar *element_name)
{
gchar buf[SMALL];
misc_truncate_string(element_name, buf, -1);
return (gint)g_ascii_strtod(buf, NULL);
}
void
xml_load_users(const gchar *dirname, const gchar *basename)
{
gint i;
gchar buf[SMALL];
free_users(TRUE);
xml_loadsave_users_read(dirname, basename);
for(i=0;i<users->len;i++)
{
sprintf(buf, "%s/%s___user_%02d_options", dirname, basename, i);
file_load_opt_file(buf, &usr(i).options);
sprintf(buf, "%s/%s___user_%02d_live_game.xml", dirname, basename, i);
xml_loadsave_live_game_read(buf, &usr(i).live_game);
}
}
void
xml_load_leagues(const gchar *dirname, const gchar *basename)
{
gint i;
gchar buf[SMALL];
GPtrArray *dir_contents = NULL;
sprintf(buf, "%s___league_", basename);
dir_contents = file_dir_get_contents(dirname, buf, ".xml");
free_leagues_array(&ligs, TRUE);
for(i=0;i<dir_contents->len;i++)
if(!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_table.xml") &&
!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_fixtures.xml") &&
!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_teams.xml") &&
2005-04-30 15:57:58 +02:00
!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_stat.xml") &&
2005-04-09 21:18:28 +02:00
!query_misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_promcup"))
2005-04-06 00:14:39 +02:00
xml_load_league(dirname, ((GString*)g_ptr_array_index(dir_contents, i))->str,
dir_contents);
free_g_string_array(&dir_contents);
}
void
xml_load_league(const gchar *dirname, const gchar *basename, const GPtrArray *dir_contents)
{
gint i;
gchar buf[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);
sprintf(buf, "%s/%s", dirname, basename);
xml_loadsave_league_read(buf, &new);
g_array_append_val(ligs, new);
sprintf(buf, "Loading league: %s",
new.name->str);
gui_show_progress(
gtk_progress_bar_get_fraction(
GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar"))), buf);
sprintf(buf, "%s/%s_teams.xml", dirname, prefix);
xml_loadsave_teams_read(buf, lig(ligs->len - 1).teams);
sprintf(buf, "%s/%s_fixtures.xml", dirname, prefix);
xml_loadsave_fixtures_read(buf, lig(ligs->len - 1).fixtures);
sprintf(buf, "%s/%s_table.xml", dirname, prefix);
xml_loadsave_table_read(buf, &lig(ligs->len - 1).table);
2005-04-30 15:57:58 +02:00
sprintf(buf, "%s/%s_stat.xml", dirname, prefix);
xml_loadsave_league_stat_read(buf, &lig(ligs->len - 1).stats);
2005-04-14 21:07:25 +02:00
if(league_has_prom_games((&lig(ligs->len - 1))))
2005-04-06 00:14:39 +02:00
{
2005-04-14 21:07:25 +02:00
lig(ligs->len - 1).prom_rel.prom_games_cup = cup_new(FALSE);
2005-04-06 00:14:39 +02:00
sprintf(buf, "%s_promcup", prefix);
for(i=0;i<dir_contents->len;i++)
if(g_str_has_prefix(((GString*)g_ptr_array_index(dir_contents, i))->str, buf) &&
2005-04-09 21:18:28 +02:00
!query_misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_table") &&
2005-04-06 00:14:39 +02:00
!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_fixtures.xml") &&
!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_teams.xml"))
{
2005-04-14 21:07:25 +02:00
xml_load_cup(&lig(ligs->len - 1).prom_rel.prom_games_cup,
dirname, ((GString*)g_ptr_array_index(dir_contents, i))->str,
dir_contents);
2005-04-06 00:14:39 +02:00
break;
}
}
g_free(prefix);
}
void
xml_load_cups(const gchar *dirname, const gchar *basename)
{
gint i;
gchar buf[SMALL];
GPtrArray *dir_contents = NULL;
2005-04-14 21:07:25 +02:00
Cup new_cup;
2005-04-06 00:14:39 +02:00
sprintf(buf, "%s___cup_", basename);
dir_contents = file_dir_get_contents(dirname, buf, ".xml");
free_cups_array(&cps, TRUE);
2005-04-14 21:07:25 +02:00
free_cups_array(&scps, TRUE);
2005-04-06 00:14:39 +02:00
for(i=0;i<dir_contents->len;i++)
{
2005-04-09 21:18:28 +02:00
if(!query_misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_table") &&
2005-04-06 00:14:39 +02:00
!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_fixtures.xml") &&
!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_teams.xml"))
2005-04-14 21:07:25 +02:00
{
new_cup = cup_new(FALSE);
xml_load_cup(&new_cup, dirname, ((GString*)g_ptr_array_index(dir_contents, i))->str,
2005-04-06 00:14:39 +02:00
dir_contents);
2005-04-14 21:07:25 +02:00
}
2005-04-06 00:14:39 +02:00
}
free_g_string_array(&dir_contents);
}
void
2005-04-14 21:07:25 +02:00
xml_load_cup(Cup *cup, const gchar *dirname, const gchar *basename, const GPtrArray *dir_contents)
2005-04-06 00:14:39 +02:00
{
gint i, j;
2005-04-06 00:14:39 +02:00
Table new_table;
gchar buf[SMALL];
2005-04-06 00:14:39 +02:00
gchar *prefix = g_strndup(basename, strlen(basename) - 4);
2005-04-14 21:07:25 +02:00
Cup *local_cup = cup;
2005-04-06 00:14:39 +02:00
sprintf(buf, "%s/%s", dirname, basename);
2005-04-14 21:07:25 +02:00
xml_loadsave_cup_read(buf, cup);
2005-04-06 00:14:39 +02:00
2005-04-14 21:07:25 +02:00
if(cup->id < ID_PROM_CUP_START)
{
g_array_append_val(cps, *cup);
local_cup = &cp(cps->len - 1);
}
else if(cup->id >= ID_SUPERCUP_START)
{
g_array_append_val(scps, *cup);
local_cup = &scp(scps->len - 1);
}
2005-04-06 00:14:39 +02:00
sprintf(buf, "Loading cup: %s",
2005-04-14 21:07:25 +02:00
local_cup->name->str);
2005-04-06 00:14:39 +02:00
gui_show_progress(
gtk_progress_bar_get_fraction(
GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar"))), buf);
2005-04-14 21:07:25 +02:00
if(local_cup->type == CUP_TYPE_INTERNATIONAL)
2005-04-06 00:14:39 +02:00
{
sprintf(buf, "%s/%s_teams.xml", dirname, prefix);
2005-04-14 21:07:25 +02:00
xml_loadsave_teams_read(buf, local_cup->teams);
2005-04-06 00:14:39 +02:00
}
sprintf(buf, "%s/%s_fixtures.xml", dirname, prefix);
2005-04-14 21:07:25 +02:00
xml_loadsave_fixtures_read(buf, local_cup->fixtures);
2005-04-06 00:14:39 +02:00
for(i=0;i<local_cup->rounds->len;i++)
for(j=0;j<dir_contents->len;j++)
2005-04-06 00:14:39 +02:00
{
sprintf(buf, "%s_round_%02d_table", prefix, i);
if(g_str_has_prefix(((GString*)g_ptr_array_index(dir_contents, j))->str,
buf))
{
sprintf(buf, "%s/%s", dirname, ((GString*)g_ptr_array_index(dir_contents, j))->str);
new_table = table_new();
xml_loadsave_table_read(buf, &new_table);
g_array_append_val(g_array_index(local_cup->rounds, CupRound, i).tables, new_table);
}
2005-04-06 00:14:39 +02:00
}
g_free(prefix);
}
void
xml_load_transfers(const gchar *dirname, const gchar *basename)
{
gchar buf[SMALL];
sprintf(buf, "%s/%s___transfer_list.xml", dirname, basename);
free_g_array(&transfer_list);
transfer_list = g_array_new(FALSE, FALSE, sizeof(Transfer));
xml_loadsave_transfers_read(buf);
}