Пример #1
0
GnomeVFSResult
mn_vfs_write_entire_file_uri (GnomeVFSURI *uri,
			      gsize file_size,
			      const char *file_contents,
			      gboolean exclusive,
			      unsigned int perms)
{
  GnomeVFSHandle *handle;
  GnomeVFSResult result;
  GnomeVFSFileSize bytes_written = 0;

  result = gnome_vfs_create_uri(&handle, uri, GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE, exclusive, perms);
  if (result != GNOME_VFS_OK)
    return result;

  while (bytes_written < file_size)
    {
      GnomeVFSFileSize this_bytes_written;

      result = gnome_vfs_write(handle, file_contents + bytes_written, file_size - bytes_written, &this_bytes_written);
      if (result != GNOME_VFS_OK)
	{
	  gnome_vfs_close(handle);
	  return result;
	}

      bytes_written += this_bytes_written;
    }

  return gnome_vfs_close(handle);
}
Пример #2
0
gboolean file_copy(gchar *source, gchar *dest) {
	GnomeVFSHandle *read_handle, *write_handle;
	GnomeVFSFileSize bytes_read, bytes_written;
	guint buffer[BYTES_TO_PROCESS];
	GnomeVFSResult result;
	gchar *OnDiEn_source, *OnDiEn_dest;
	OnDiEn_source = get_filename_on_disk_encoding(source);
	OnDiEn_dest = get_filename_on_disk_encoding(dest);
	
	result = gnome_vfs_open(&read_handle, OnDiEn_source, GNOME_VFS_OPEN_READ);
	g_free(OnDiEn_source);
	if (result != GNOME_VFS_OK) return FALSE;
	result = gnome_vfs_create(&write_handle, OnDiEn_dest, GNOME_VFS_OPEN_WRITE, FALSE, 0644);
	g_free(OnDiEn_dest);
	if (result != GNOME_VFS_OK) {
		gnome_vfs_close(read_handle);
		return FALSE;
	}
	result = gnome_vfs_read (read_handle, buffer, BYTES_TO_PROCESS, &bytes_read);
	while (result == GNOME_VFS_OK) {
		result = gnome_vfs_write (write_handle, buffer, bytes_read, &bytes_written);
		if (result != GNOME_VFS_OK || bytes_written != bytes_read) {
			DEBUG_MSG("file_copy, return FALSE, write result=%d, written=%ld, read=%ld\n",result,(long)bytes_written,(long)bytes_read);
			gnome_vfs_close(write_handle);
			gnome_vfs_close(read_handle);
			return FALSE;
		}
		result = gnome_vfs_read(read_handle, buffer, BYTES_TO_PROCESS, &bytes_read);
	}
	gnome_vfs_close(write_handle);
	gnome_vfs_close(read_handle);
	return TRUE;
}
Пример #3
0
static gboolean
gst_gnome_vfs_src_stop (GstBaseSrc * basesrc)
{
  GstGnomeVFSSrc *src;

  src = GST_GNOME_VFS_SRC (basesrc);

  gst_gnome_vfs_src_pop_callbacks (src);

  if (src->own_handle) {
    GnomeVFSResult res;

    res = gnome_vfs_close (src->handle);
    if (res != GNOME_VFS_OK) {
      GST_ELEMENT_ERROR (src, RESOURCE, CLOSE, (NULL),
          ("Could not close vfs handle: %s", gnome_vfs_result_to_string (res)));
    }
    src->handle = NULL;
  }
  src->curoffset = 0;
  src->interrupted = FALSE;
  gnome_vfs_context_free (src->context);
  src->context = NULL;

  return TRUE;
}
Пример #4
0
gboolean
parse_ram (const gchar *path)
{
    gchar **lines, **alternatives;
    guint i, nalt;
    GnomeVFSHandle *h;
    char buf[4];
    GnomeVFSFileSize read, left;

    g_message ("parsing ram: %s", path);

    if (gnome_vfs_open (&h, path, GNOME_VFS_OPEN_READ))
        return FALSE;

    left = 4;
    while (left &&
           gnome_vfs_read (h, buf + (4 - left), left, &read) == GNOME_VFS_OK)
        left -= read;

    gnome_vfs_close (h);

    if (left) return FALSE;

    /* from gxine:
       if this is true, then its an actual stream, not a playlist file */
    if (buf[0] == '.' && buf[1] == 'R' && buf[2] == 'M' && buf[3] == 'F')
        return TRUE;

    if ((lines = read_file (path))) {

        alternatives = g_new (gchar*, 1);
        alternatives[0] = NULL;
        nalt = 0;

        for (i = 0; lines[i]; ++i) {
            lines[i] = g_strstrip (lines[i]);
            if (strlen (lines[i])) {

                /* comment */
                if (lines[i][0] == '#') continue;

                /* --stop-- lines */
                if (strstr (lines[i], "--stop--")) break;

                /* from gxine:
                   Either it's a rtsp, or a pnm mrl, but we also match http
                   mrls here.
                */
                if (g_str_has_prefix (lines[i], "rtsp://") ||
                    g_str_has_prefix (lines[i], "pnm://") ||
                    g_str_has_prefix (lines[i], "http://"))
                {
                    alternatives = g_renew (gchar*, alternatives, nalt+2);
                    alternatives[nalt] = g_strdup (lines[i]);
                    alternatives[nalt+1] = NULL;
                    ++nalt;
                }
            }
        }
Пример #5
0
int
main (int argc, char **argv)
{
	GnomeVFSResult    result;
	GnomeVFSHandle   *handle;
	gchar             buffer[1024];
	GnomeVFSFileSize  bytes_read;
	GnomeVFSURI 	 *uri;
	gchar            *text_uri;

	if (argc != 2) {
		printf ("Usage: %s <uri>\n", argv[0]);
		return 1;
	}

	if (! gnome_vfs_init ()) {
		fprintf (stderr, "Cannot initialize gnome-vfs.\n");
		return 1;
	}

	uri = gnome_vfs_uri_new (argv[1]);
	if (uri == NULL) {
		fprintf (stderr, "URI not valid.\n");
		return 1;
	}

	text_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);

	result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
	show_result (result, "open", text_uri);

	while( result==GNOME_VFS_OK && !feof(stdin)) {
		GnomeVFSFileSize temp;

		bytes_read = fread(buffer, 1, sizeof buffer - 1, stdin);
		if(!bytes_read) break;
		buffer[bytes_read] = 0;
		result = gnome_vfs_write (handle, buffer, bytes_read,
				 	&temp);
		show_result (result, "write", text_uri);
	
	}

	result = gnome_vfs_close (handle);
	show_result (result, "close", text_uri);

	g_free (text_uri);

	return 0;
}
Пример #6
0
void
bookmarks_load_from_disk (Bookmarks *bookmarks)
{
	GnomeVFSResult  result;
	GnomeVFSHandle *handle;
	char           *uri;
	char            line [MAX_LINE_LENGTH];

	g_return_if_fail (bookmarks != NULL);

	bookmarks_free_data (bookmarks);
	if (bookmarks->rc_filename == NULL)
		return;

	uri = g_strconcat (get_home_uri (),
			   "/",
			   bookmarks->rc_filename,
			   NULL);
	result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
	g_free (uri);

	if (result != GNOME_VFS_OK)
		return;

	while (_gnome_vfs_read_line (handle,
				     line,
				     MAX_LINE_LENGTH,
				     NULL) == GNOME_VFS_OK) {
		char *path;

		if (line[0] != '"')
			continue;

		line[strlen (line) - 1] = 0;
		path = line + 1;

		bookmarks->list = g_list_prepend (bookmarks->list, g_strdup (path));
		my_insert (bookmarks->names,
			   path,
			   get_uri_display_name (path));
		my_insert (bookmarks->tips,
			   path,
			   get_menu_item_tip (path));
	}

	gnome_vfs_close (handle);

	bookmarks->list = g_list_reverse (bookmarks->list);
}
Пример #7
0
/*--------------------------------------------------------------------------*/
static void close_remote_file_callback( GnomeVFSAsyncHandle *handle,
					GnomeVFSResult result,
					gpointer callback_data )
{
	DownloadCallbackData *data = (DownloadCallbackData *)callback_data;
	GnomeVFSFileInfo     *info;
	GnomeVFSURI          *file_uri;

	gb_debug (DEBUG_UPDATE, "START");

	if ( data->local_handle ) {
		gnome_vfs_close( data->local_handle );
		data->local_handle = NULL;
	}

	if ( update_cancel_flag ) {
		gtk_widget_destroy( update_window );
		update_window = NULL;
		gb_debug (DEBUG_UPDATE, "END -- CANCEL");
		return;
	}

	if (result != GNOME_VFS_OK) {
		g_warning( "Close failed: %s", gnome_vfs_result_to_string(result) );
	}

	data->i++;
	data->p = data->p->next;
	if ( data->p ) {
		info = (GnomeVFSFileInfo *)data->p->data;
		gb_debug (DEBUG_UPDATE, "Opening %s", info->name );
		file_uri = gnome_vfs_uri_append_file_name( data->uri, info->name );
		gb_debug (DEBUG_UPDATE, " URI = %s",
			  gnome_vfs_uri_to_string (file_uri, 0) );
		gnome_vfs_async_cancel (handle);
		gnome_vfs_async_open_uri (&remote_file_handle,
					  file_uri,
					  GNOME_VFS_OPEN_READ,
					  0,
					  open_remote_file_callback,
					  data);
	}
	else {
		download_done( data );
	}

	gb_debug (DEBUG_UPDATE, "END");
}
Пример #8
0
void
bookmarks_write_to_disk (Bookmarks *bookmarks)
{
	GnomeVFSResult  result;
	GnomeVFSHandle *handle;
	char           *uri;
	int             lines;
	GList          *scan;

	g_return_if_fail (bookmarks != NULL);

	if (bookmarks->rc_filename == NULL)
		return;

	uri = g_strconcat (get_home_uri (),
			   "/",
			   bookmarks->rc_filename,
			   NULL);
	result = gnome_vfs_create (&handle, uri, GNOME_VFS_OPEN_WRITE, FALSE, FILE_PERMISSIONS);
	g_free (uri);

	if (result != GNOME_VFS_OK)
		return;

	/* write the file list. */

	lines = 0;
	scan = bookmarks->list;
	while (((bookmarks->max_lines < 0) || (lines < bookmarks->max_lines))
	       && (scan != NULL)) {
		if (_gnome_vfs_write_line (handle,
					   "\"%s\"",
					   (char*) scan->data) != GNOME_VFS_OK) {
			g_print ("ERROR saving to bookmark file\n");
			break;
		}
		lines++;
		scan = scan->next;
	}

	gnome_vfs_close (handle);
}
Пример #9
0
static void
gst_gnome_vfs_sink_close_file (GstGnomeVFSSink * sink)
{
    GnomeVFSResult result;

    if (sink->own_handle) {
        /* close the file */
        result = gnome_vfs_close (sink->handle);

        if (result != GNOME_VFS_OK) {
            gchar *filename = gnome_vfs_uri_to_string (sink->uri,
                              GNOME_VFS_URI_HIDE_PASSWORD);

            GST_ELEMENT_ERROR (sink, RESOURCE, CLOSE,
                               (_("Could not close vfs file \"%s\"."), filename), GST_ERROR_SYSTEM);
            g_free (filename);
        }

        sink->own_handle = FALSE;
        sink->handle = NULL;
    }
}
NS_IMETHODIMP
nsGnomeVFSInputStream::Close()
{
  if (mHandle)
  {
    gnome_vfs_close(mHandle);
    mHandle = nsnull;
  }

  if (mDirList)
  {
    // Destroy the list of GnomeVFSFileInfo objects...
    g_list_foreach(mDirList, (GFunc) gnome_vfs_file_info_unref, nsnull);
    g_list_free(mDirList);
    mDirList = nsnull;
    mDirListPtr = nsnull;
  }

  if (mChannel)
  {
    nsresult rv = NS_OK;

    nsCOMPtr<nsIThread> thread = do_GetMainThread();
    if (thread)
      rv = NS_ProxyRelease(thread, mChannel);

    NS_ASSERTION(thread && NS_SUCCEEDED(rv), "leaking channel reference");
    mChannel = nsnull;
  }

  mSpec.Truncate(); // free memory

  // Prevent future reads from re-opening the handle.
  if (NS_SUCCEEDED(mStatus))
    mStatus = NS_BASE_STREAM_CLOSED;

  return NS_OK;
}
Пример #11
0
static gboolean
copy_uri (const gchar  *src_uri,
          const gchar  *dest_uri,
          const gchar  *copying_format_str,
          const gchar  *copied_format_str,
          GError      **error)
{
  GnomeVFSHandle   *read_handle;
  GnomeVFSHandle   *write_handle;
  GnomeVFSFileInfo *src_info;
  GnomeVFSFileSize  file_size  = 0;
  GnomeVFSFileSize  bytes_read = 0;
  guchar            buffer[BUFSIZE];
  GnomeVFSResult    result;
  gchar            *memsize;
  GTimeVal          last_time = { 0, 0 };

  gimp_progress_init (_("Connecting to server"));

  src_info = gnome_vfs_file_info_new ();
  result = gnome_vfs_get_file_info (src_uri, src_info, 0);

  /*  ignore errors here, they will be noticed below  */
  if (result == GNOME_VFS_OK &&
      (src_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE))
    {
      file_size = src_info->size;
    }

  gnome_vfs_file_info_unref (src_info);

  result = gnome_vfs_open (&read_handle, src_uri, GNOME_VFS_OPEN_READ);

  if (result != GNOME_VFS_OK)
    {
      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                   _("Could not open '%s' for reading: %s"),
                   src_uri, gnome_vfs_result_to_string (result));
      return FALSE;
    }

  result = gnome_vfs_create (&write_handle, dest_uri,
                             GNOME_VFS_OPEN_WRITE, FALSE, 0644);

  if (result != GNOME_VFS_OK)
    {
      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                   _("Could not open '%s' for writing: %s"),
                   dest_uri, gnome_vfs_result_to_string (result));
      gnome_vfs_close (read_handle);
      return FALSE;
    }

  memsize = g_format_size_for_display (file_size);

  gimp_progress_init_printf (file_size > 0 ?
                             copying_format_str : copied_format_str,
                             memsize);

  g_free (memsize);

  while (TRUE)
    {
      GnomeVFSFileSize  chunk_read;
      GnomeVFSFileSize  chunk_written;
      GTimeVal          now;

      result = gnome_vfs_read (read_handle, buffer, sizeof (buffer),
                               &chunk_read);

      if (chunk_read == 0)
        {
          if (result != GNOME_VFS_ERROR_EOF)
            {
              memsize = g_format_size_for_display (sizeof (buffer));
              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                           _("Failed to read %s from '%s': %s"),
                           memsize, src_uri,
                           gnome_vfs_result_to_string (result));
              g_free (memsize);

              gnome_vfs_close (read_handle);
              gnome_vfs_close (write_handle);
              return FALSE;
            }
          else
            {
              gimp_progress_update (1.0);
              break;
            }
        }

      bytes_read += chunk_read;

      /*  update the progress only up to 10 times a second  */

      g_get_current_time (&now);

      if (((now.tv_sec - last_time.tv_sec) * 1000 +
           (now.tv_usec - last_time.tv_usec) / 1000) > 100)
        {
          if (file_size > 0)
            {
              gimp_progress_update ((gdouble) bytes_read / (gdouble) file_size);
            }
          else
            {
              memsize = g_format_size_for_display (bytes_read);

              gimp_progress_set_text_printf (copied_format_str, memsize);
              gimp_progress_pulse ();

              g_free (memsize);
            }

          last_time = now;
        }

      result = gnome_vfs_write (write_handle, buffer, chunk_read,
                                &chunk_written);

      if (chunk_written < chunk_read)
        {
          memsize = g_format_size_for_display (chunk_read);
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("Failed to write %s to '%s': %s"),
                       memsize, dest_uri,
                       gnome_vfs_result_to_string (result));
          g_free (memsize);

          gnome_vfs_close (read_handle);
          gnome_vfs_close (write_handle);
          return FALSE;
        }
    }

  gnome_vfs_close (read_handle);
  gnome_vfs_close (write_handle);

  return TRUE;
}
static gboolean
write_theme_to_disk (GnomeThemeMetaInfo  *theme_info,
		     const gchar         *theme_name,
		     const gchar         *theme_description,
		     gboolean		  save_background,
		     GError             **error)
{
  gchar *dir, *theme_name_dir;
  GnomeVFSURI *uri;
  GnomeVFSURI *target_uri;
  GnomeVFSHandle *handle = NULL;
  GnomeVFSFileSize bytes_written;
  gchar *str, *current_background;
  GConfClient *client;
  const gchar *theme_header =
      "[Desktop Entry]\n"
      "Name=%s\n"
      "Type=X-GNOME-Metatheme\n"
      "Comment=%s\n"
      "\n"
      "[X-GNOME-Metatheme]\n"
      "GtkTheme=%s\n"
      "MetacityTheme=%s\n"
      "IconTheme=%s\n";

  theme_name_dir = str_remove_slash (theme_name);
  dir = g_build_filename (g_get_home_dir (), ".themes", theme_name_dir, "index.theme~", NULL);
  g_free (theme_name_dir);

  uri = gnome_vfs_uri_new (dir);
  dir [strlen (dir) - 1] = '\000';
  target_uri = gnome_vfs_uri_new (dir);
  g_free (dir);
  gnome_vfs_create_uri (&handle, uri, GNOME_VFS_OPEN_READ | GNOME_VFS_OPEN_WRITE, FALSE, 0644);

  gnome_vfs_truncate_handle (handle, 0);

  /* start making the theme file */
  str = g_strdup_printf (theme_header, theme_name, theme_description,
			 theme_info->gtk_theme_name,
			 theme_info->metacity_theme_name,
			 theme_info->icon_theme_name);
  gnome_vfs_write (handle, str, strlen (str), &bytes_written);
  g_free (str);

  if (theme_info->gtk_color_scheme) {
    gchar *a, *tmp;
    tmp = g_strdup (theme_info->gtk_color_scheme);
    for (a = tmp; *a != '\0'; a++)
      if (*a == '\n')
        *a = ',';
    str = g_strdup_printf ("GtkColorScheme=%s\n", tmp);
    gnome_vfs_write (handle, str, strlen (str), &bytes_written);
    g_free (str);
    g_free (tmp);
  }

  if (theme_info->cursor_theme_name) {
#ifdef HAVE_XCURSOR
    str = g_strdup_printf ("CursorTheme=%s\n"
                           "CursorSize=%i\n",
                           theme_info->cursor_theme_name,
                           theme_info->cursor_size);
#else
    str = g_strdup_printf ("CursorFont=%s\n", theme_info->cursor_theme_name);
#endif
    gnome_vfs_write (handle, str, strlen (str), &bytes_written);
    g_free (str);
  }

  if (save_background) {
    client = gconf_client_get_default ();
    current_background = gconf_client_get_string (client, BACKGROUND_KEY, NULL);

    if (current_background != NULL) {
      str = g_strdup_printf ("BackgroundImage=%s\n", current_background);

      gnome_vfs_write (handle, str, strlen (str), &bytes_written);

      g_free (current_background);
      g_free (str);
    }
    g_object_unref (client);
  }

  gnome_vfs_close (handle);

  gnome_vfs_move_uri (uri, target_uri, TRUE);
  gnome_vfs_uri_unref (uri);
  gnome_vfs_uri_unref (target_uri);

  return TRUE;
}