+
+ //do safe backup according to user preferences
+ DB( g_print(" user pref backup\n") );
+ if( PREFS->bak_is_automatic == TRUE )
+ {
+ bakfilename = hb_filename_new_for_backup(GLOBALS->xhb_filepath);
+ if( g_file_test(bakfilename, G_FILE_TEST_EXISTS) == FALSE )
+ {
+ homebank_file_copy (GLOBALS->xhb_filepath, bakfilename);
+ }
+ g_free(bakfilename);
+
+ //delete any offscale backup
+ DB( g_print(" clean old backup\n") );
+ array = hb_filename_backup_list(GLOBALS->xhb_filepath);
+
+ DB( g_print(" found %d match\n", array->len) );
+
+ gchar *dirname = g_path_get_dirname(GLOBALS->xhb_filepath);
+
+ for(i=0;i<(gint)array->len;i++)
+ {
+ gchar *offscalefilename = g_ptr_array_index(array, i);
+
+ DB( g_print(" %d : '%s'\n", i, offscalefilename) );
+ if( i >= PREFS->bak_max_num_copies )
+ {
+ gchar *bakdelfilepath = g_build_filename(dirname, offscalefilename, NULL);
+
+ DB( g_print(" - should delete '%s'\n", bakdelfilepath) );
+
+ homebank_file_delete_existing(bakdelfilepath);
+
+ g_free(bakdelfilepath);
+ }
+ }
+ g_ptr_array_free(array, TRUE);
+
+ g_free(dirname);
+ }
+