2004-11-05 17:40:03 +00:00
|
|
|
// Vfs.cs - Generic gnome-vfs method bindings.
|
2004-10-29 20:33:07 +00:00
|
|
|
//
|
2004-11-05 17:40:03 +00:00
|
|
|
// Authors: Jeroen Zwartepoorte <jeroen@xs4all.nl>
|
2004-10-29 20:33:07 +00:00
|
|
|
//
|
2004-11-05 17:40:03 +00:00
|
|
|
// Copyright (c) 2004 Jeroen Zwartepoorte
|
2004-10-29 20:33:07 +00:00
|
|
|
//
|
2004-11-05 17:40:03 +00:00
|
|
|
// 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.
|
2004-10-29 20:33:07 +00:00
|
|
|
//
|
2004-11-05 17:40:03 +00:00
|
|
|
// 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.
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
namespace Gnome.Vfs {
|
|
|
|
public class Vfs {
|
2004-12-21 12:52:49 +00:00
|
|
|
private Vfs () {}
|
|
|
|
|
2004-10-29 20:33:07 +00:00
|
|
|
[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")]
|
2004-12-27 20:02:33 +00:00
|
|
|
static extern void gnome_vfs_shutdown ();
|
2004-10-29 20:33:07 +00:00
|
|
|
|
2004-12-27 20:02:33 +00:00
|
|
|
public static void Shutdown ()
|
2004-10-29 20:33:07 +00:00
|
|
|
{
|
2004-12-27 20:02:33 +00:00
|
|
|
gnome_vfs_shutdown ();
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
|
|
|
private static extern Result gnome_vfs_move (string old_uri, string new_uri, bool force_replace);
|
|
|
|
|
2004-12-27 20:02:33 +00:00
|
|
|
public static Result Move (string source, string dest, bool force_replace)
|
2004-10-29 20:33:07 +00:00
|
|
|
{
|
2004-12-27 20:02:33 +00:00
|
|
|
return gnome_vfs_move (source, dest, force_replace);
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
|
|
|
private static extern IntPtr gnome_vfs_result_to_string (int result);
|
|
|
|
|
|
|
|
public static string ResultToString (Result result)
|
|
|
|
{
|
|
|
|
return ResultToString ((int)result);
|
|
|
|
}
|
|
|
|
|
2004-12-27 20:02:33 +00:00
|
|
|
internal static string ResultToString (int result)
|
2004-10-29 20:33:07 +00:00
|
|
|
{
|
|
|
|
IntPtr ptr = gnome_vfs_result_to_string (result);
|
|
|
|
return Marshal.PtrToStringAnsi (ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2004-12-20 15:20:58 +00:00
|
|
|
throw new VfsException (result);
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-28 09:14:15 +00:00
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
|
|
|
private static extern string gnome_vfs_format_file_size_for_display (long size);
|
|
|
|
|
|
|
|
public static string FormatFileSizeForDisplay (long size)
|
|
|
|
{
|
|
|
|
return gnome_vfs_format_file_size_for_display (size);
|
|
|
|
}
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
}
|