static void
hd_bookmark_widgets_constructed (GObject *object)
{
    HDBookmarkWidgetsPrivate *priv = HD_BOOKMARK_WIDGETS (object)->priv;
    gchar *user_bookmarks, *user_bookmarks_uri;
    GnomeVFSResult result;

    if (G_OBJECT_CLASS (hd_bookmark_widgets_parent_class)->constructed)
        G_OBJECT_CLASS (hd_bookmark_widgets_parent_class)->constructed (object);

    /* Create the bookmark paths if they do not exist yet */
    set_bookmark_files_path ();

    user_bookmarks = g_build_filename (g_get_home_dir (),
                                       MYBOOKMARKS,
                                       NULL);
    user_bookmarks_uri = gnome_vfs_get_uri_from_local_path (user_bookmarks);

    result = gnome_vfs_monitor_add (&priv->user_bookmarks_handle,
                                    user_bookmarks_uri,
                                    GNOME_VFS_MONITOR_FILE,
                                    hd_bookmark_widgets_bookmark_files_changed,
                                    object);
    if (result != GNOME_VFS_OK)
        g_debug ("Could not add monitor for user bookmark file. %s", gnome_vfs_result_to_string (result));

    priv->parse_idle_id = gdk_threads_add_idle ((GSourceFunc) hd_bookmark_widgets_parse_bookmark_files,
                          object);

    g_free (user_bookmarks);
    g_free (user_bookmarks_uri);
}
示例#2
0
文件: save.c 项目: dtzWill/supernes
void save_save(GtkWindow* parent)
{
	if (cur_save_uri) {
		const gchar * frz_file = game_state_get_frz_file();
		gchar * frz_uri = gnome_vfs_get_uri_from_local_path(frz_file);
		show_result(copy_file(frz_uri, cur_save_uri), parent, "Game saved");
		g_free(frz_uri);
	} else {
		save_save_as(parent);
	}
}
示例#3
0
文件: save.c 项目: dtzWill/supernes
void save_load(GtkWindow* parent)
{
	gchar * uri = show_dialog(parent, GTK_FILE_CHOOSER_ACTION_OPEN);

	if (uri) {
		const gchar * frz_file = game_state_get_frz_file();
		gchar * frz_uri = gnome_vfs_get_uri_from_local_path(frz_file);
		show_result(copy_file(uri, frz_uri), parent, "Game loaded");
		g_free(frz_uri);
	}

	if (cur_save_uri) {
		g_free(cur_save_uri);
	}
	cur_save_uri = uri;
}
示例#4
0
文件: save.c 项目: dtzWill/supernes
void save_save_as(GtkWindow* parent)
{
	gchar * uri = show_dialog(parent, GTK_FILE_CHOOSER_ACTION_SAVE);

	if (uri) {
		const gchar * frz_file = game_state_get_frz_file();
		gchar * frz_uri = gnome_vfs_get_uri_from_local_path(frz_file);
		gboolean res = show_result(copy_file(frz_uri, uri), parent, "Game saved");
		g_free(frz_uri);

		if (!res) return;

		if (cur_save_uri) {
			g_free(cur_save_uri);
		}
		cur_save_uri = uri;
	}
}
示例#5
0
/*--------------------------------------------------------------------------*/
static GList *
prune_list_from_dir( GList *remote_list, gint *n, const gchar *dirname )
{
	GnomeVFSFileInfo *local_info, *remote_info;
	GList            *local_list;
	GList            *p_remote, *p_local;
	gchar            *local_text_uri;
	GnomeVFSResult    ret;

	gb_debug (DEBUG_UPDATE, "START");

	if ( dirname == NULL ) return remote_list;

	local_text_uri = gnome_vfs_get_uri_from_local_path( dirname );
	if ( (ret = gnome_vfs_directory_list_load (&local_list,
						   local_text_uri,
						   GNOME_VFS_FILE_INFO_DEFAULT))
	     != GNOME_VFS_OK ) {
		return remote_list;
	}

	for ( p_local=local_list; p_local != NULL; p_local=p_local->next ) {
		local_info = (GnomeVFSFileInfo *)p_local->data;

		for ( p_remote=remote_list; p_remote != NULL; p_remote=p_remote->next ) {
			remote_info = (GnomeVFSFileInfo *)p_remote->data;
			if ( g_strcasecmp( local_info->name, remote_info->name ) == 0 ) {
				remote_list = g_list_remove_link( remote_list, p_remote );
				gnome_vfs_file_info_unref( remote_info );
				p_remote->data = remote_info = NULL;
				g_list_free_1( p_remote ); p_remote = NULL;
				*n -= 1;
				break;
			}
		}

	}
  
	g_free( local_text_uri );

	gb_debug (DEBUG_UPDATE, "END");

	return remote_list;
}
示例#6
0
文件: tcp.c 项目: girish946/g2ipmsg
static int
tcp_transfer_dir(tcp_con_t *con,const char *path){
  int rc;
  char *basename;
  GnomeVFSFileInfo *info;
  GnomeVFSResult res;
  gchar *dir_uri;

  if ( (!con) || (!path) )
    return -EINVAL;
  info=gnome_vfs_file_info_new();
  dir_uri=gnome_vfs_get_uri_from_local_path(path);

  rc=-ENOMEM;
  if (!dir_uri) 
    goto free_info_out;

  res=gnome_vfs_get_file_info(dir_uri,info,GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
  if (res != GNOME_VFS_OK) {
    rc=-res;
    goto free_info_out;
  }
  basename=g_path_get_basename(path);
    rc=-ENOMEM;
  if (!basename)
    goto free_info_out;

  rc=send_directory(con,path,basename,info);
  g_free(basename);
  if (!rc)
    rc=finalize_send_directory(con,path,info);
  else
    err_out("Send directory fail %s (%d)\n",
	    strerror(-rc),rc);
 free_info_out:
  gnome_vfs_file_info_unref(info);
  return rc;
}
static gboolean
invoke_full_auth (MountThreadInfo *info, char **password_out)
{
	GnomeVFSModuleCallbackFullAuthenticationIn in_args;
	GnomeVFSModuleCallbackFullAuthenticationOut out_args;
	gboolean invoked;

	*password_out = NULL;

	memset (&in_args, 0, sizeof (in_args));
	in_args.flags = GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION_NEED_PASSWORD;
	in_args.uri = gnome_vfs_get_uri_from_local_path (info->mount_point);
	in_args.protocol = "file";
	in_args.object = NULL;
	in_args.authtype = "password";
	in_args.domain = NULL;
	in_args.port = 0;
	in_args.server = (gchar*)info->device_path;
	in_args.username = NULL;

	memset (&out_args, 0, sizeof (out_args));

	invoked = invoke_async_auth (GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION,
				     &in_args, sizeof (in_args), &out_args, sizeof (out_args));

	if (invoked && !out_args.abort_auth) {
		*password_out = out_args.password;
		out_args.password = NULL;
	}

	g_free (in_args.uri);
	g_free (out_args.username);
	g_free (out_args.password);
	g_free (out_args.keyring);
	g_free (out_args.domain);

	return invoked && !out_args.abort_auth;
}
示例#8
0
文件: tcp.c 项目: girish946/g2ipmsg
static int
send_directory(tcp_con_t *con,const char *top_dir,const char *basename,GnomeVFSFileInfo *info){
  int rc;
  char *uri;
  GnomeVFSResult res;
  GnomeVFSDirectoryHandle *handle;
  char *next_dir;
  char *res_message;

  if ( (!top_dir) || (!info) || (!basename) )
    return -EINVAL;

  rc=create_response(IPMSG_FILE_DIR,info->name,info->size,top_dir,&res_message);
  
  if (rc<0)
    return rc;
  dbg_out("Send dir:%s (%s)\n",res_message,top_dir);
  rc=send_header(con,res_message);
  g_free(res_message);
  if (rc<0)
    return rc;

      
  uri=gnome_vfs_get_uri_from_local_path(top_dir);
  if (!uri)
    return -ENOMEM;
  /*
   *ファイルを送付
   */
  res=gnome_vfs_directory_open(&handle,uri,GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
  res=gnome_vfs_directory_read_next(handle,info);
  while (res==GNOME_VFS_OK) {
    read_directory_files(con,top_dir,info);
    res=gnome_vfs_directory_read_next(handle,info);
  }
  gnome_vfs_directory_close(handle); 
  /*
   *ディレクトリを送付
   */
  res=gnome_vfs_directory_open(&handle,uri,GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
  if (res!=GNOME_VFS_OK) {
    err_out("Can not open dir:%s %s (%d)\n",
	    top_dir,
	    gnome_vfs_result_to_string(res),
	    res);
    goto error_out;
  }
  res=gnome_vfs_directory_read_next(handle,info);
  if (res!=GNOME_VFS_OK) {
    if (res != GNOME_VFS_ERROR_EOF)
      err_out("Can not read next dir:%s %s (%d)\n",
	      top_dir,
	      gnome_vfs_result_to_string(res),
	      res);
    goto error_out;
  }
  while (res==GNOME_VFS_OK) {
    if ( (info->type==GNOME_VFS_FILE_TYPE_DIRECTORY) &&
	 ( (strcmp(info->name,"..")) && (strcmp(info->name,"."))) ){
      dbg_out("dir:%s\n",info->name);
      next_dir=g_build_filename(top_dir,info->name,NULL);
      if (!next_dir)
	goto error_out;
      rc=send_directory(con,next_dir,info->name,info);
      g_free(next_dir);
      if (rc<0)
	return rc;
      rc=create_response(IPMSG_FILE_RETPARENT,info->name,info->size,top_dir,&res_message);
      if (rc<0)
	return rc;
      dbg_out("Send ret parent:%s\n",res_message);
      rc=send_header(con,res_message);
      g_free(res_message);
      if (rc<0)
	return rc;
    }
    res=gnome_vfs_directory_read_next(handle,info);
    if (res!=GNOME_VFS_OK) {
      if (res != GNOME_VFS_ERROR_EOF)
	err_out("Can not read next dir:%s %s (%d)\n",
		top_dir,
		gnome_vfs_result_to_string(res),
		res);
      goto error_out;
    }
  }

 error_out:
  gnome_vfs_directory_close(handle); 
  g_free(uri);
  return rc;
}
示例#9
0
int
main (int argc, char **argv)
{
	GnomeVFSURI *uri;
	gboolean magic_only;
	gboolean suffix_only;
	gboolean dump_table;
	gboolean speed_test;
	const char *result;
	const char *table_path;
	char *uri_string;
	char *curdir;
	char *path;
	struct stat tmp;
	GTimer *timer;
	int i;

	table_path = NULL;
	magic_only = FALSE;
	dump_table = FALSE;
	speed_test = FALSE;
	suffix_only = FALSE;
	
	if (!gnome_vfs_init ()) {
		fprintf (stderr, "Cannot initialize gnome-vfs.\n");
		return 1;
	}

	if (argc == 1 || strcmp (argv[1], "--help") == 0) {
		fprintf (stderr, "Usage: %s [--magicOnly | --suffixOnly] [--dumpTable] "
			" [--loadTable <table path>] fileToCheck1 [fileToCheck2 ...] \n", *argv);
		return 1;
	}


	++argv;
	for (; *argv; argv++) {
		if (strcmp (*argv, "--magicOnly") == 0) {
			magic_only = TRUE;
		} else if (strcmp (*argv, "--suffixOnly") == 0) {
			suffix_only = TRUE;
		} else if (strcmp (*argv, "--dumpTable") == 0) {
			dump_table = TRUE;
		} else if (strcmp (*argv, "--speedTest") == 0) {
			speed_test = TRUE;
		} else if (strcmp (*argv, "--loadTable") == 0) {
			++argv;
			if (!*argv) {
				fprintf (stderr, "Table path expected.\n");
				return 1;
			}
			table_path = *argv;
			if (stat(table_path, &tmp) != 0) {
				fprintf (stderr, "Table path %s not found.\n", table_path);
				return 1;
			}
		} else {
			break;
		}
	}


	if (speed_test) {
		timer = g_timer_new ();
		g_timer_start (timer);
		for (i = 0; i < 100; i++) {
			gnome_vfs_mime_info_reload ();
		}
		fprintf (stderr, "Mime reload took %g(ms)\n",
			 g_timer_elapsed (timer, NULL) * 10.0);
	}

	for (; *argv != NULL; argv++) {
	        uri_string = g_strdup (*argv);
		if (is_uri (uri_string)) {
			uri = gnome_vfs_uri_new (*argv);
		} else {
			uri = NULL;
		}
		if (uri == NULL) {
			if (g_path_is_absolute (uri_string)) {
				path = uri_string;
			} else {
				curdir = g_get_current_dir ();
				path = g_build_filename (curdir,uri_string, NULL);
				g_free (uri_string);
				g_free (curdir);
			}
			uri_string = gnome_vfs_get_uri_from_local_path (path);
			g_free (path);
			uri = gnome_vfs_uri_new (uri_string);
		}
		if (uri == NULL) {
			printf ("%s is neither a full URI nor an absolute filename\n", *argv);
			continue;
		}

		if (magic_only) {
			result = gnome_vfs_get_mime_type_from_file_data (uri);
		} else if (suffix_only) {
			result = gnome_vfs_get_mime_type_from_uri (uri);
		} else {
			result = gnome_vfs_get_mime_type (uri_string);
		}
	
		printf ("looks like %s is %s\n", *argv, result);
		gnome_vfs_uri_unref (uri);
	}
	
	return 0;
}
示例#10
0
/*--------------------------------------------------------------------------*/
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");
}
示例#11
0
/*--------------------------------------------------------------------------*/
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");
}
GnomeVFSResult
gnome_vfs_find_directory_cancellable (GnomeVFSURI *near_uri,
				      GnomeVFSFindDirectoryKind kind,
				      GnomeVFSURI **result_uri,
				      gboolean create_if_needed,
				      gboolean find_if_needed,
				      guint permissions,
				      GnomeVFSContext *context)
{
	GnomeVFSResult result;
	GnomeVFSURI *resolved_uri;

	g_return_val_if_fail (result_uri != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);

	*result_uri = NULL;

	if (gnome_vfs_context_check_cancellation (context))
		return GNOME_VFS_ERROR_CANCELLED;

	if (near_uri != NULL) {
		gnome_vfs_uri_ref (near_uri);
	} else {
		char *text_uri;

		text_uri = gnome_vfs_get_uri_from_local_path (g_get_home_dir ());
		g_assert (text_uri != NULL);
		/* assume file: method and the home directory */
		near_uri = gnome_vfs_uri_new (text_uri);
		g_free (text_uri);
	}

	g_assert (near_uri != NULL);

	if (!VFS_METHOD_HAS_FUNC (near_uri->method, find_directory)) {
		/* skip file systems not supporting find_directory.
		 *
		 * TODO if we decide to introduce cross-method links (e.g. http allows
		 * arbitrary URIs), this could be slightly wrong, because the target
		 * method may support find_directory, so we'd also have to make sure
		 * that a method doesn't support cross-method links.
		 **/
		return GNOME_VFS_ERROR_NOT_SUPPORTED;
	}

	/* Need to expand the final symlink, since if the directory is a symlink
	 * we want to look at the device the symlink points to, not the one the
	 * symlink is stored on
	 */
	result = _gnome_vfs_uri_resolve_all_symlinks_uri (near_uri, &resolved_uri);
	if (result == GNOME_VFS_OK) {
		gnome_vfs_uri_unref (near_uri);
		near_uri = resolved_uri;
	} else
		return result;

	g_assert (near_uri != NULL);

	if (!VFS_METHOD_HAS_FUNC(near_uri->method, find_directory)) {
		gnome_vfs_uri_unref (near_uri);
		return GNOME_VFS_ERROR_NOT_SUPPORTED;
	}

	result = near_uri->method->find_directory (near_uri->method, near_uri, kind,
		result_uri, create_if_needed, find_if_needed, permissions, context);

	gnome_vfs_uri_unref (near_uri);
	return result;
}