예제 #1
0
file find_filename(char *s)
{
    int hash_value = hash_filename(s);
    file f;

    for (f = file_hash_table(hash_value); f != NULL; f = flink)
    {
        if (strcmp(f->fname, s) == SAME){
            return f;
        }
    }

    f = allocate_file(s);
    f->flink = file_hash_table[hash_value];
    file_hash_table[hash_value] = f;
    return f;
}
예제 #2
0
파일: update.c 프로젝트: rlaager/gbonds-pkg
/*--------------------------------------------------------------------------*/
static void
download_done( DownloadCallbackData *data )
{
	GList            *p;
	GnomeVFSFileInfo *info, tmp_info = {0};
	gchar            *hash_name;
	gchar            *hash_path, *hash_text_uri;
	gchar            *file_path, *file_text_uri;
	gchar            *date_min, *date_max, *finish_msg;
	gchar            *data_dir;
	gbTableModel     *table_model;

	gb_debug (DEBUG_UPDATE, "START");

	/* Rename downloaded files (undo name hash) */
	data_dir = gb_util_get_home_data_dir();
	for ( p=data->list; p != NULL; p=p->next ) {
		info = (GnomeVFSFileInfo *)p->data;
		hash_name = hash_filename( info->name );
		hash_path = g_build_filename( data_dir, hash_name, NULL );
		hash_text_uri = gnome_vfs_get_uri_from_local_path( hash_path );
		file_path = g_build_filename( data_dir, info->name, NULL );
		file_text_uri = gnome_vfs_get_uri_from_local_path( file_path );
		gnome_vfs_get_file_info (hash_text_uri, &tmp_info, GNOME_VFS_FILE_INFO_DEFAULT);
		if ( info->size == tmp_info.size ) {
			gnome_vfs_move( hash_text_uri, file_text_uri, FALSE );
		} else {
			g_warning ("%s: Temporary file size (%"
				   GNOME_VFS_OFFSET_FORMAT_STR
				   ") does not match remote size (%"
				   GNOME_VFS_OFFSET_FORMAT_STR
				   ").",
				   info->name, tmp_info.size, info->size);
			gnome_vfs_unlink (hash_text_uri);
		}
		g_free( hash_name );
		g_free( hash_path );
		g_free( hash_text_uri );
		g_free( file_path );
		g_free( file_text_uri );
	}
	g_free( data_dir );

	/* Now reread redemption tables */
	table_model = gb_table_get_model ();
	gb_table_model_update (table_model);

	/* customize finish page for this outcome */
	gnome_druid_page_edge_set_title( GNOME_DRUID_PAGE_EDGE(finish_page),
					 _( "Download done" ) );
	date_min = gb_date_fmt (gb_table_model_get_rdate_min (table_model));
	date_max = gb_date_fmt (gb_table_model_get_rdate_max (table_model));
	finish_msg = g_strdup_printf(
		_( "GBonds has successfully downloaded "
		   "%d new redemption files.\n\n"
		   "GBonds is now configured with redemption data\n"
		   "for %s - %s.\n" ),
		data->n, date_min, date_max );
	gnome_druid_page_edge_set_text( GNOME_DRUID_PAGE_EDGE(finish_page), finish_msg );
	g_free( date_min );
	g_free( date_max );
	g_free( finish_msg );

	remote_dir_handle = NULL;

	/* Now jump to the finish page */
	gnome_druid_set_page( GNOME_DRUID(update_druid),
			      GNOME_DRUID_PAGE(finish_page) );

	gb_debug (DEBUG_UPDATE, "END");
}
예제 #3
0
파일: update.c 프로젝트: rlaager/gbonds-pkg
/*--------------------------------------------------------------------------*/
static void open_remote_file_callback( GnomeVFSAsyncHandle *handle,
				       GnomeVFSResult result,
				       gpointer callback_data )
{
	DownloadCallbackData *data = (DownloadCallbackData *)callback_data;
	GnomeVFSFileInfo     *info = (GnomeVFSFileInfo *)data->p->data;
	gchar                *local_path, *local_text_uri, *local_name;
	GnomeVFSHandle       *local_handle;
	gchar                *status_string;
	GnomeVFSResult        ret;

	gb_debug (DEBUG_UPDATE, "START");

	if ( update_cancel_flag ) {
		gnome_vfs_async_close( handle, close_remote_file_callback, data );
		gb_debug (DEBUG_UPDATE, "END -- CANCEL");
		return;
	}

	switch (result) {

	case GNOME_VFS_OK:
		data->file_bytes_read = 0;
		data->file_bytes      = info->size;

		status_string = g_strdup_printf( _("File: \"%s\" (%d of %d)"),
						 info->name, (data->i+1), data->n );
		gtk_label_set_text( GTK_LABEL(file_label), status_string );
		g_free( status_string );

		update_progress_bar (GTK_PROGRESS_BAR(file_progress),
				     0,
				     data->file_bytes);
		update_progress_bar (GTK_PROGRESS_BAR(total_progress),
				     data->total_bytes_read,
				     data->total_bytes);
    
		local_name = hash_filename( info->name );
		local_path = g_build_filename (gb_util_get_home_data_dir(),
					       local_name,
					       NULL);
		local_text_uri = gnome_vfs_get_uri_from_local_path( local_path );
		ret = gnome_vfs_create( &local_handle, local_text_uri,
					GNOME_VFS_OPEN_WRITE, FALSE, 0664 );
		if ( ret != GNOME_VFS_OK ) {
			g_warning( "error opening local file %s, %s\n", local_path,
				   gnome_vfs_result_to_string(ret) );
		}
		else {
			data->local_handle = local_handle;
			gnome_vfs_async_read( handle, data->buffer, data->buffer_length,
					      read_remote_file_callback, data );
		}
		g_free( local_name );
		g_free( local_path );
		g_free( local_text_uri );
		break;

	default:
		g_warning( "Open failed: %s.\n", gnome_vfs_result_to_string(result) );
		break;

	}

	gb_debug (DEBUG_UPDATE, "END");
}