GtkSharp/gnomevfs/Vfs.cs
Jeroen Zwartepoorte e2fd0d5e42 2004-12-20 Jeroen Zwartepoorte <jeroen@xs4all.nl>
* gnomevfs/Makefile.am:
	* gnomevfs/ModuleCallback.cs: 
	* gnomevfs/ModuleCallbackAuthentication.cs:
	* gnomevfs/ModuleCallbackFullAuthentication.cs:
	* gnomevfs/Vfs.cs: Use a custom VfsException for Result errors.
	* gnomevfs/VfsException.cs: new custom Exception class.
	* sample/gnomevfs/Makefile.am:
	* sample/gnomevfs/TestCallback.cs:
	
	Implement custom bindings for the ModuleCallback mechanism. Atm, only
	the GNOME_VFS_MODULE_CALLBACK_AUTHENTICATION and
	GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION callbacks are implemented.
	Also added a test-case using the full authentication callback (tested
	using the sftp: method). [Partially fixes #70602]


svn path=/trunk/gtk-sharp/; revision=37972
2004-12-20 15:20:58 +00:00

129 lines
3.2 KiB
C#

// Vfs.cs - Generic gnome-vfs method bindings.
//
// Authors: Jeroen Zwartepoorte <jeroen@xs4all.nl>
//
// Copyright (c) 2004 Jeroen Zwartepoorte
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Gnome.Vfs {
public class Vfs {
[DllImport ("gnomevfs-2")]
static extern bool gnome_vfs_init ();
[DllImport ("gnomevfs-2")]
static extern bool gnome_vfs_initialized ();
public static bool Initialized {
get {
return gnome_vfs_initialized ();
}
}
static Vfs ()
{
if (!gnome_vfs_initialized ())
gnome_vfs_init ();
}
public static bool Initialize ()
{
return gnome_vfs_init ();
}
[DllImport ("gnomevfs-2")]
static extern bool gnome_vfs_shutdown ();
public static bool Shutdown ()
{
return gnome_vfs_shutdown ();
}
public static bool Exists (string textUri)
{
Uri uri = new Uri (textUri);
return uri.Exists;
}
[DllImport ("gnomevfs-2")]
private static extern Result gnome_vfs_move (string old_uri, string new_uri, bool force_replace);
public static Result Move (string old_uri, string new_uri, bool force_replace)
{
return gnome_vfs_move (old_uri, new_uri, force_replace);
}
[DllImport ("gnomevfs-2")]
private static extern Result gnome_vfs_unlink (string uri);
public static Result Unlink (string uri)
{
return gnome_vfs_unlink (uri);
}
[DllImport ("gnomevfs-2")]
private static extern IntPtr gnome_vfs_result_to_string (int result);
public static string ResultToString (Result result)
{
return ResultToString ((int)result);
}
public static string ResultToString (int result)
{
IntPtr ptr = gnome_vfs_result_to_string (result);
return Marshal.PtrToStringAnsi (ptr);
}
[DllImport ("gnomevfs-2")]
private static extern Result gnome_vfs_truncate (string uri, ulong length);
public static Result Truncate (string uri, ulong length)
{
return gnome_vfs_truncate (uri, length);
}
public static Result Truncate (Uri uri, ulong length)
{
return Truncate (uri.ToString (), length);
}
public static void ThrowException (Result result)
{
ThrowException ((string)null, result);
}
public static void ThrowException (Uri uri, Result result)
{
ThrowException (uri.ToString (), result);
}
public static void ThrowException (string uri, Result result)
{
switch (result) {
case Result.Ok:
return;
case Result.ErrorNotFound:
throw new FileNotFoundException (uri);
default:
throw new VfsException (result);
}
}
}
}