mirror of
https://github.com/tstellar/bygfoot.git
synced 2025-02-03 09:17:29 +01:00
delete autosave files with the same autosave number
This commit is contained in:
parent
cd4a2283d7
commit
89bba29615
320
src/load_save.c
320
src/load_save.c
@ -61,24 +61,24 @@ load_save_save_game(const gchar *filename)
|
|||||||
|
|
||||||
gchar buf[SMALL];
|
gchar buf[SMALL];
|
||||||
gchar *prefix = (g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ?
|
gchar *prefix = (g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ?
|
||||||
g_strndup(filename, strlen(filename) - strlen(const_str("string_fs_save_suffix"))) :
|
g_strndup(filename, strlen(filename) - strlen(const_str("string_fs_save_suffix"))) :
|
||||||
g_strdup(filename);
|
g_strdup(filename);
|
||||||
GString *fullname = g_string_new("");
|
GString *fullname = g_string_new("");
|
||||||
|
|
||||||
g_string_append(fullname,(g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ?
|
g_string_append(fullname,(g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ?
|
||||||
g_strdup(filename) :
|
g_strdup(filename) :
|
||||||
g_strdup_printf("%s%s", filename, const_str("string_fs_save_suffix")));
|
g_strdup_printf("%s%s", filename, const_str("string_fs_save_suffix")));
|
||||||
|
|
||||||
misc_string_assign(&save_file, fullname->str);
|
misc_string_assign(&save_file, fullname->str);
|
||||||
|
|
||||||
if(g_file_test(fullname->str, G_FILE_TEST_EXISTS))
|
if(g_file_test(fullname->str, G_FILE_TEST_EXISTS))
|
||||||
g_remove(fullname->str);
|
g_remove(fullname->str);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_save options\n");
|
g_print("load_save_save options\n");
|
||||||
|
|
||||||
gui_show_progress(0, _("Saving options..."),
|
gui_show_progress(0, _("Saving options..."),
|
||||||
PIC_TYPE_SAVE);
|
PIC_TYPE_SAVE);
|
||||||
|
|
||||||
sprintf(buf, "%s___options", prefix);
|
sprintf(buf, "%s___options", prefix);
|
||||||
file_save_opt_file(buf, &options);
|
file_save_opt_file(buf, &options);
|
||||||
@ -86,97 +86,97 @@ load_save_save_game(const gchar *filename)
|
|||||||
file_save_opt_file(buf, &settings);
|
file_save_opt_file(buf, &settings);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_save leagues/cups \n");
|
g_print("load_save_save leagues/cups \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Saving leagues and cups..."),
|
_("Saving leagues and cups..."),
|
||||||
PIC_TYPE_SAVE);
|
PIC_TYPE_SAVE);
|
||||||
|
|
||||||
xml_loadsave_leagues_cups_write(prefix);
|
xml_loadsave_leagues_cups_write(prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_save users \n");
|
g_print("load_save_save users \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Saving users..."),
|
_("Saving users..."),
|
||||||
PIC_TYPE_SAVE);
|
PIC_TYPE_SAVE);
|
||||||
|
|
||||||
xml_loadsave_users_write(prefix);
|
xml_loadsave_users_write(prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_save transfers \n");
|
g_print("load_save_save transfers \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Saving transfer list..."),
|
_("Saving transfer list..."),
|
||||||
PIC_TYPE_SAVE);
|
PIC_TYPE_SAVE);
|
||||||
|
|
||||||
xml_loadsave_transfers_write(prefix);
|
xml_loadsave_transfers_write(prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_save stats \n");
|
g_print("load_save_save stats \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Saving season stats..."),
|
_("Saving season stats..."),
|
||||||
PIC_TYPE_SAVE);
|
PIC_TYPE_SAVE);
|
||||||
|
|
||||||
xml_loadsave_season_stats_write(prefix);
|
xml_loadsave_season_stats_write(prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_save jobs \n");
|
g_print("load_save_save jobs \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
/* The 'job exchange' is a list of teams looking for a manager. */
|
/* The 'job exchange' is a list of teams looking for a manager. */
|
||||||
_("Saving job exchange..."),
|
_("Saving job exchange..."),
|
||||||
PIC_TYPE_SAVE);
|
PIC_TYPE_SAVE);
|
||||||
|
|
||||||
xml_loadsave_jobs_write(prefix);
|
xml_loadsave_jobs_write(prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_save newspaper \n");
|
g_print("load_save_save newspaper \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Saving newspaper..."),
|
_("Saving newspaper..."),
|
||||||
PIC_TYPE_SAVE);
|
PIC_TYPE_SAVE);
|
||||||
|
|
||||||
xml_loadsave_newspaper_write(prefix);
|
xml_loadsave_newspaper_write(prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_save misc \n");
|
g_print("load_save_save misc \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Saving miscellaneous..."),
|
_("Saving miscellaneous..."),
|
||||||
PIC_TYPE_SAVE);
|
PIC_TYPE_SAVE);
|
||||||
|
|
||||||
xml_loadsave_misc_write(prefix);
|
xml_loadsave_misc_write(prefix);
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Compressing savegame..."),
|
_("Compressing savegame..."),
|
||||||
PIC_TYPE_SAVE);
|
PIC_TYPE_SAVE);
|
||||||
|
|
||||||
sprintf(buf, "%s___", prefix);
|
sprintf(buf, "%s___", prefix);
|
||||||
file_compress_files(fullname->str, buf);
|
file_compress_files(fullname->str, buf);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_save done \n");
|
g_print("load_save_save done \n");
|
||||||
|
|
||||||
gui_show_progress(1, _("Done."),
|
gui_show_progress(1, _("Done."),
|
||||||
PIC_TYPE_SAVE);
|
PIC_TYPE_SAVE);
|
||||||
|
|
||||||
file_store_text_in_saves("last_save", fullname->str);
|
file_store_text_in_saves("last_save", fullname->str);
|
||||||
|
|
||||||
g_free(prefix);
|
g_free(prefix);
|
||||||
g_string_free(fullname, TRUE);
|
g_string_free(fullname, TRUE);
|
||||||
|
|
||||||
gui_show_progress(-1, "",
|
gui_show_progress(-1, "",
|
||||||
PIC_TYPE_SAVE);
|
PIC_TYPE_SAVE);
|
||||||
setsav1;
|
setsav1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,52 +191,52 @@ load_save_load_game(const gchar* filename, gboolean create_main_window)
|
|||||||
|
|
||||||
GString *buf = g_string_new("");
|
GString *buf = g_string_new("");
|
||||||
gchar *fullname = (g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ?
|
gchar *fullname = (g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ?
|
||||||
g_strdup(filename) :
|
g_strdup(filename) :
|
||||||
g_strdup_printf("%s%s", filename, const_str("string_fs_save_suffix"));
|
g_strdup_printf("%s%s", filename, const_str("string_fs_save_suffix"));
|
||||||
gchar *basename = g_path_get_basename(fullname),
|
gchar *basename = g_path_get_basename(fullname),
|
||||||
*dirname = g_path_get_dirname(fullname);
|
*dirname = g_path_get_dirname(fullname);
|
||||||
gchar *prefix = (g_str_has_suffix(basename, const_str("string_fs_save_suffix"))) ?
|
gchar *prefix = (g_str_has_suffix(basename, const_str("string_fs_save_suffix"))) ?
|
||||||
g_strndup(basename, strlen(basename) - strlen(const_str("string_fs_save_suffix"))) :
|
g_strndup(basename, strlen(basename) - strlen(const_str("string_fs_save_suffix"))) :
|
||||||
g_strdup(basename);
|
g_strdup(basename);
|
||||||
gchar *pwd = g_get_current_dir();
|
gchar *pwd = g_get_current_dir();
|
||||||
|
|
||||||
if(g_str_has_suffix(filename, "last_save"))
|
if(g_str_has_suffix(filename, "last_save"))
|
||||||
{
|
{
|
||||||
g_free(basename);
|
g_free(basename);
|
||||||
g_free(dirname);
|
g_free(dirname);
|
||||||
g_free(prefix);
|
g_free(prefix);
|
||||||
g_free(fullname);
|
g_free(fullname);
|
||||||
|
|
||||||
basename = file_load_text_from_saves("last_save");
|
basename = file_load_text_from_saves("last_save");
|
||||||
|
|
||||||
if(basename != NULL)
|
if(basename != NULL)
|
||||||
{
|
{
|
||||||
load_save_load_game(basename, create_main_window);
|
load_save_load_game(basename, create_main_window);
|
||||||
g_free(basename);
|
g_free(basename);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
game_gui_show_warning(_("Last save file not found."));
|
game_gui_show_warning(_("Last save file not found."));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(window.main != NULL)
|
if(window.main != NULL)
|
||||||
gtk_widget_hide(window.main);
|
gtk_widget_hide(window.main);
|
||||||
|
|
||||||
gui_show_progress(0, _("Uncompressing savegame..."),
|
gui_show_progress(0, _("Uncompressing savegame..."),
|
||||||
PIC_TYPE_LOAD);
|
PIC_TYPE_LOAD);
|
||||||
|
|
||||||
file_decompress(fullname);
|
file_decompress(fullname);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_load options\n");
|
g_print("load_save_load options\n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Loading options..."),
|
_("Loading options..."),
|
||||||
PIC_TYPE_LOAD);
|
PIC_TYPE_LOAD);
|
||||||
|
|
||||||
g_string_sprintf(buf, "%s%s%s___options", dirname, G_DIR_SEPARATOR_S, prefix);
|
g_string_sprintf(buf, "%s%s%s___options", dirname, G_DIR_SEPARATOR_S, prefix);
|
||||||
file_load_opt_file(buf->str, &options, FALSE);
|
file_load_opt_file(buf->str, &options, FALSE);
|
||||||
@ -245,91 +245,92 @@ load_save_load_game(const gchar* filename, gboolean create_main_window)
|
|||||||
language_set(language_get_code_index(opt_str("string_opt_language_code")) + 1);
|
language_set(language_get_code_index(opt_str("string_opt_language_code")) + 1);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_load leagues \n");
|
g_print("load_save_load leagues \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Loading leagues and cups..."),
|
_("Loading leagues and cups..."),
|
||||||
PIC_TYPE_LOAD);
|
PIC_TYPE_LOAD);
|
||||||
|
|
||||||
xml_loadsave_leagues_cups_read(dirname, prefix);
|
xml_loadsave_leagues_cups_read(dirname, prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_load users \n");
|
g_print("load_save_load users \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Loading users..."),
|
_("Loading users..."),
|
||||||
PIC_TYPE_LOAD);
|
PIC_TYPE_LOAD);
|
||||||
|
|
||||||
xml_load_users(dirname, prefix);
|
xml_load_users(dirname, prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_load transfers \n");
|
g_print("load_save_load transfers \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Loading transfer list..."),
|
_("Loading transfer list..."),
|
||||||
PIC_TYPE_LOAD);
|
PIC_TYPE_LOAD);
|
||||||
|
|
||||||
xml_load_transfers(dirname, prefix);
|
xml_load_transfers(dirname, prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_load stats \n");
|
g_print("load_save_load stats \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Loading season stats..."),
|
_("Loading season stats..."),
|
||||||
PIC_TYPE_LOAD);
|
PIC_TYPE_LOAD);
|
||||||
|
|
||||||
xml_loadsave_season_stats_read(dirname, prefix);
|
xml_loadsave_season_stats_read(dirname, prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_load jobs \n");
|
g_print("load_save_load jobs \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
/* The 'job exchange' is a list of teams looking for a manager. */
|
/* The 'job exchange' is a list of teams looking for a manager. */
|
||||||
_("Loading job exchange..."),
|
_("Loading job exchange..."),
|
||||||
PIC_TYPE_LOAD);
|
PIC_TYPE_LOAD);
|
||||||
|
|
||||||
xml_loadsave_jobs_read(dirname, prefix);
|
xml_loadsave_jobs_read(dirname, prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_load newspaper \n");
|
g_print("load_save_load newspaper \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Loading newspaper..."),
|
_("Loading newspaper..."),
|
||||||
PIC_TYPE_LOAD);
|
PIC_TYPE_LOAD);
|
||||||
|
|
||||||
xml_loadsave_newspaper_read(dirname, prefix);
|
xml_loadsave_newspaper_read(dirname, prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_load misc \n");
|
g_print("load_save_load misc \n");
|
||||||
|
|
||||||
gui_show_progress(
|
gui_show_progress(
|
||||||
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
|
||||||
_("Loading miscellaneous..."),
|
_("Loading miscellaneous..."),
|
||||||
PIC_TYPE_LOAD);
|
PIC_TYPE_LOAD);
|
||||||
|
|
||||||
xml_loadsave_misc_read(dirname, prefix);
|
xml_loadsave_misc_read(dirname, prefix);
|
||||||
|
|
||||||
if(debug > 60)
|
if(debug > 60)
|
||||||
g_print("load_save_load done \n");
|
g_print("load_save_load done \n");
|
||||||
|
|
||||||
gui_show_progress(1, _("Done."),
|
gui_show_progress(1, _("Done."),
|
||||||
PIC_TYPE_LOAD);
|
PIC_TYPE_LOAD);
|
||||||
|
|
||||||
chdir(dirname);
|
chdir(dirname);
|
||||||
GPtrArray *files = file_dir_get_contents(dirname, prefix, "");
|
GPtrArray *files = file_dir_get_contents(dirname, prefix, "");
|
||||||
// Remove the zipfile from the list
|
// Remove the zipfile from the list
|
||||||
gint i;
|
gint i;
|
||||||
for(i=0;i<files->len;i++)
|
for(i=0; i<files->len; i++)
|
||||||
{
|
{
|
||||||
if (g_strcmp0((gchar*)g_ptr_array_index(files, i),basename)==0){
|
if (g_strcmp0((gchar*)g_ptr_array_index(files, i),basename)==0)
|
||||||
g_ptr_array_remove_index_fast(files, i);
|
{
|
||||||
}
|
g_ptr_array_remove_index_fast(files, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
file_remove_files(files);
|
file_remove_files(files);
|
||||||
chdir(pwd);
|
chdir(pwd);
|
||||||
@ -342,20 +343,20 @@ load_save_load_game(const gchar* filename, gboolean create_main_window)
|
|||||||
file_store_text_in_saves("last_save", fullname);
|
file_store_text_in_saves("last_save", fullname);
|
||||||
|
|
||||||
gui_show_progress(-1, "",
|
gui_show_progress(-1, "",
|
||||||
PIC_TYPE_LOAD);
|
PIC_TYPE_LOAD);
|
||||||
|
|
||||||
if(create_main_window)
|
if(create_main_window)
|
||||||
{
|
{
|
||||||
window_create(WINDOW_MAIN);
|
window_create(WINDOW_MAIN);
|
||||||
on_button_back_to_main_clicked(NULL, NULL);
|
on_button_back_to_main_clicked(NULL, NULL);
|
||||||
}
|
}
|
||||||
else if(window.main != NULL)
|
else if(window.main != NULL)
|
||||||
{
|
{
|
||||||
gtk_widget_show(window.main);
|
gtk_widget_show(window.main);
|
||||||
window_main_load_geometry();
|
window_main_load_geometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
g_string_free(buf, TRUE);
|
g_string_free(buf, TRUE);
|
||||||
|
|
||||||
g_free(basename);
|
g_free(basename);
|
||||||
g_free(dirname);
|
g_free(dirname);
|
||||||
@ -374,39 +375,52 @@ load_save_autosave(void)
|
|||||||
printf("load_save_autosave\n");
|
printf("load_save_autosave\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gchar buf[SMALL], name[SMALL];
|
gchar buf[SMALL], name[SMALL], directory[SMALL], prefix[SMALL];
|
||||||
const gchar *home = g_get_home_dir();
|
const gchar *home = g_get_home_dir();
|
||||||
FILE *fil = NULL;
|
FILE *fil = NULL;
|
||||||
|
gchar *pwd = g_get_current_dir();
|
||||||
if(!opt_int("int_opt_autosave") ||
|
|
||||||
!query_user_games_this_week_round())
|
if(!opt_int("int_opt_autosave"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
counters[COUNT_AUTOSAVE] = (counters[COUNT_AUTOSAVE] + 1) % opt_int("int_opt_autosave_interval");
|
counters[COUNT_AUTOSAVE] = (counters[COUNT_AUTOSAVE] + 1) % opt_int("int_opt_autosave_interval");
|
||||||
|
|
||||||
if(counters[COUNT_AUTOSAVE] != 0)
|
if(counters[COUNT_AUTOSAVE] != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
load_save_write_autosave_name(name);
|
load_save_write_autosave_name(name);
|
||||||
|
|
||||||
if(os_is_unix)
|
if(os_is_unix)
|
||||||
sprintf(buf, "%s%s%s%ssaves%s%s_%02d.zip", home, G_DIR_SEPARATOR_S,
|
sprintf(directory, "%s%s%s%ssaves", home, G_DIR_SEPARATOR_S, HOMEDIRNAME, G_DIR_SEPARATOR_S);
|
||||||
HOMEDIRNAME, G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S,
|
|
||||||
name, counters[COUNT_AUTOSAVE_FILE]);
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gchar *pwd = g_get_current_dir();
|
sprintf(directory, "%s%ssaves", pwd, G_DIR_SEPARATOR_S);
|
||||||
sprintf(buf, "%s%ssaves%s%s_%02d.zip", pwd, G_DIR_SEPARATOR_S,
|
g_free(pwd);
|
||||||
G_DIR_SEPARATOR_S, name, counters[COUNT_AUTOSAVE_FILE]);
|
|
||||||
g_free(pwd);
|
|
||||||
}
|
}
|
||||||
|
sprintf(name, "%s.zip", name);
|
||||||
|
sprintf(buf, "%s%s%s", directory, G_DIR_SEPARATOR_S, name);
|
||||||
|
|
||||||
if(!file_my_fopen(buf, "w", &fil, FALSE))
|
if(!file_my_fopen(buf, "w", &fil, FALSE))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fclose(fil);
|
fclose(fil);
|
||||||
|
sprintf(prefix, "autosave_%02d_", counters[COUNT_AUTOSAVE_FILE]);
|
||||||
load_save_save_game(buf);
|
load_save_save_game(buf);
|
||||||
|
chdir(directory);
|
||||||
|
GPtrArray *files = file_dir_get_contents(directory, prefix, ".zip");
|
||||||
|
// Remove the zipfile from the list
|
||||||
|
gint i;
|
||||||
|
for(i=0; i<files->len; i++)
|
||||||
|
{
|
||||||
|
if (g_strcmp0((gchar*)g_ptr_array_index(files, i),name)==0)
|
||||||
|
{
|
||||||
|
g_ptr_array_remove_index_fast(files, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_remove_files(files);
|
||||||
|
chdir(pwd);
|
||||||
|
g_free(pwd);
|
||||||
|
free_gchar_array(&files);
|
||||||
|
|
||||||
|
|
||||||
counters[COUNT_AUTOSAVE_FILE] = (counters[COUNT_AUTOSAVE_FILE] + 1) % opt_int("int_opt_autosave_files");
|
counters[COUNT_AUTOSAVE_FILE] = (counters[COUNT_AUTOSAVE_FILE] + 1) % opt_int("int_opt_autosave_files");
|
||||||
@ -423,14 +437,14 @@ load_save_write_autosave_name(gchar *filename)
|
|||||||
while(usr(0).tm->name[i] != '\0')
|
while(usr(0).tm->name[i] != '\0')
|
||||||
{
|
{
|
||||||
teamname[i] = (isspace(usr(0).tm->name[i]) == 0) ?
|
teamname[i] = (isspace(usr(0).tm->name[i]) == 0) ?
|
||||||
usr(0).tm->name[i] : '_';
|
usr(0).tm->name[i] : '_';
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
teamname[i] = '\0';
|
teamname[i] = '\0';
|
||||||
|
|
||||||
sprintf(filename, "autosave_%s_%s_%s_S%02d_W%02d",
|
sprintf(filename, "autosave_%02d_%s_%s_%s_S%02d_W%02d",
|
||||||
usr(0).name, country.name, teamname, season, week);
|
counters[COUNT_AUTOSAVE_FILE], usr(0).name, country.name, teamname, season, week);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Try to load a savegame given on the command line. */
|
/** Try to load a savegame given on the command line. */
|
||||||
@ -442,40 +456,40 @@ load_game_from_command_line(const gchar *filename)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
gchar *fullname = NULL,
|
gchar *fullname = NULL,
|
||||||
*support_file_name = NULL;
|
*support_file_name = NULL;
|
||||||
|
|
||||||
if(strcmp(filename, "last_save") == 0)
|
if(strcmp(filename, "last_save") == 0)
|
||||||
return load_save_load_game(filename, TRUE);
|
return load_save_load_game(filename, TRUE);
|
||||||
|
|
||||||
fullname = (g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ?
|
fullname = (g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ?
|
||||||
g_strdup(filename) :
|
g_strdup(filename) :
|
||||||
g_strdup_printf("%s%s", filename, const_str("string_fs_save_suffix"));
|
g_strdup_printf("%s%s", filename, const_str("string_fs_save_suffix"));
|
||||||
|
|
||||||
if(g_file_test(fullname, G_FILE_TEST_EXISTS))
|
if(g_file_test(fullname, G_FILE_TEST_EXISTS))
|
||||||
{
|
{
|
||||||
if(load_save_load_game(fullname, TRUE))
|
if(load_save_load_game(fullname, TRUE))
|
||||||
{
|
{
|
||||||
g_free(fullname);
|
g_free(fullname);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
support_file_name = file_find_support_file(fullname, FALSE);
|
support_file_name = file_find_support_file(fullname, FALSE);
|
||||||
|
|
||||||
if(g_file_test(support_file_name, G_FILE_TEST_EXISTS))
|
if(g_file_test(support_file_name, G_FILE_TEST_EXISTS))
|
||||||
{
|
{
|
||||||
if(load_save_load_game(support_file_name, TRUE))
|
if(load_save_load_game(support_file_name, TRUE))
|
||||||
{
|
{
|
||||||
g_free(fullname);
|
g_free(fullname);
|
||||||
g_free(support_file_name);
|
g_free(support_file_name);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_print_message("Could not find file %s.\n", fullname);
|
debug_print_message("Could not find file %s.\n", fullname);
|
||||||
g_free(fullname);
|
g_free(fullname);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user