Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 359 lines (318 sloc) 9.291 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
// FileInfo.cs - Class wrapping the GnomeVFSFileInfo struct.
//
// 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.Runtime.InteropServices;

namespace Gnome.Vfs {
public class FileInfo {
[StructLayout(LayoutKind.Sequential)]
internal struct FileInfoNative {
public IntPtr name;
public FileInfoFields valid_fields;
public FileType type;
public FilePermissions permissions;
public FileFlags flags;
public long dev_t;
public long inode;
public uint link_count;
public uint uid;
public uint gid;
public long size;
public long block_count;
public uint io_block_size;
public IntPtr atime;
public IntPtr mtime;
public IntPtr ctime;
public IntPtr symlink_name;
public IntPtr mime_type;
public uint refcount;
public IntPtr reserved1;
public IntPtr reserved2;
public IntPtr reserved3;
public IntPtr reserved4;
public IntPtr reserved5;
}

IntPtr handle;
bool needs_dispose = false;

[DllImport ("gnomevfs-2")]
private static extern void gnome_vfs_file_info_unref (IntPtr handle);

~FileInfo ()
{
if (needs_dispose)
gnome_vfs_file_info_unref (Handle);
}
[DllImport ("gnomevfs-2")]
private static extern IntPtr gnome_vfs_file_info_new ();

public FileInfo ()
{
needs_dispose = true;
handle = gnome_vfs_file_info_new ();
}

public FileInfo (IntPtr handle)
{
this.handle = handle;
}

public FileInfo (string uri) : this (uri, FileInfoOptions.Default) {}

public FileInfo (string uri, FileInfoOptions options) : this (new Uri (uri), options) {}

public FileInfo (Uri uri) : this (uri, FileInfoOptions.Default) {}
[DllImport ("gnomevfs-2")]
private static extern Result gnome_vfs_get_file_info_uri (IntPtr uri, IntPtr info, int options);

public FileInfo (Uri uri, FileInfoOptions options) : this ()
{
Result result = gnome_vfs_get_file_info_uri (uri.Handle, Handle, (int) options);
Vfs.ThrowException (uri, result);
}

FileInfoNative Native {
get {
return (FileInfoNative) Marshal.PtrToStructure (handle, typeof (FileInfoNative));
}
}

public IntPtr Handle {
get {
return handle;
}
}

public string Name {
get {
FileInfoNative info = Native;
if (info.name != IntPtr.Zero)
return GLib.Marshaller.Utf8PtrToString (info.name);
else
return null;
}
}

public FileInfoFields ValidFields {
get {
return Native.valid_fields;
}
}

public FileType Type {
get {
if ((ValidFields & FileInfoFields.Type) != 0)
return Native.type;
else
throw new ArgumentException ("Type is not set");
}
}

public FilePermissions Permissions {
get {
if ((ValidFields & FileInfoFields.Permissions) != 0)
return Native.permissions;
else
throw new ArgumentException ("Permissions is not set");
}
}

public FileFlags Flags {
get {
if ((ValidFields & FileInfoFields.Flags) != 0)
return Native.flags;
else
throw new ArgumentException ("Flags is not set");
}
}

public long Device {
get {
if ((ValidFields & FileInfoFields.Device) != 0)
return Native.dev_t;
else
throw new ArgumentException ("Device is not set");
}
}

public long Inode {
get {
if ((ValidFields & FileInfoFields.Inode) != 0)
return Native.inode;
else
throw new ArgumentException ("Inode is not set");
}
}

public uint LinkCount {
get {
if ((ValidFields & FileInfoFields.LinkCount) != 0)
return Native.link_count;
else
throw new ArgumentException ("LinkCount is not set");
}
}

public uint Uid {
get {
return Native.uid;
}
}

public uint Gid {
get {
return Native.gid;
}
}

public long Size {
get {
if ((ValidFields & FileInfoFields.Size) != 0)
return Native.size;
else
throw new ArgumentException ("Size is not set");
}
}

public long BlockCount {
get {
if ((ValidFields & FileInfoFields.BlockCount) != 0)
return Native.block_count;
else
throw new ArgumentException ("BlockCount is not set");
}
}

public uint IoBlockSize {
get {
if ((ValidFields & FileInfoFields.IoBlockSize) != 0)
return Native.io_block_size;
else
throw new ArgumentException ("IoBlockSize is not set");
}
}

public System.DateTime Atime {
get {
if ((ValidFields & FileInfoFields.Atime) != 0)
return GLib.Marshaller.time_tToDateTime (Native.atime);
else
throw new ArgumentException ("Atime is not set");
}
}

public System.DateTime Mtime {
get {
if ((ValidFields & FileInfoFields.Mtime) != 0)
return GLib.Marshaller.time_tToDateTime (Native.mtime);
else
throw new ArgumentException ("Mtime is not set");
}
}

public System.DateTime Ctime {
get {
if ((ValidFields & FileInfoFields.Ctime) != 0)
return GLib.Marshaller.time_tToDateTime (Native.ctime);
else
throw new ArgumentException ("Ctime is not set");
}
}

public string SymlinkName {
get {
FileInfoNative info = Native;
if ((ValidFields & FileInfoFields.SymlinkName) != 0 &&
info.symlink_name != IntPtr.Zero)
return GLib.Marshaller.Utf8PtrToString (info.symlink_name);
else
throw new ArgumentException ("SymlinkName is not set");
}
}

public string MimeType {
get {
FileInfoNative info = Native;
if ((ValidFields & FileInfoFields.MimeType) != 0 &&
info.mime_type != IntPtr.Zero)
return GLib.Marshaller.Utf8PtrToString (info.mime_type);
else
throw new ArgumentException ("MimeType is not set");
}
}

public bool IsSymlink {
get {
FileFlags flags = Flags;
return (flags & FileFlags.Symlink) != 0;
}
}

public bool IsLocal {
get {
FileFlags flags = Flags;
return (flags & FileFlags.Local) != 0;
}
}

public bool HasSuid {
get {
FilePermissions perms = Permissions;
return (perms & FilePermissions.Suid) != 0;
}
}

public bool HasSgid {
get {
FilePermissions perms = Permissions;
return (perms & FilePermissions.Sgid) != 0;
}
}

public bool IsSticky {
get {
FilePermissions perms = Permissions;
return (perms & FilePermissions.Sticky) != 0;
}
}

[DllImport ("gnomevfs-2")]
private static extern void gnome_vfs_file_info_clear (IntPtr info);

public void Clear ()
{
gnome_vfs_file_info_clear (Handle);
}

public override String ToString ()
{
FileInfoNative info = Native;
string result = "Name = " + Name + "\n" +
"ValidFields = " + info.valid_fields + "\n";
if ((ValidFields & FileInfoFields.Type) != 0)
result += "Type = " + info.type + "\n";
if ((ValidFields & FileInfoFields.Permissions) != 0)
result += "Permissions = " + info.permissions + "\n";
if ((ValidFields & FileInfoFields.Flags) != 0) {
result += "Flags = ";
bool flag = false;
if (Flags == FileFlags.None) {
result += "None";
flag = true;
}
if ((Flags & FileFlags.Symlink) != 0) {
result += flag ? ", Symlink" : "Symlink";
flag = true;
}
if ((Flags & FileFlags.Local) != 0)
result += flag ? ", Local" : "Local";
result += "\n";
}
if ((ValidFields & FileInfoFields.Device) != 0)
result += "Device = " + info.dev_t + "\n";
if ((ValidFields & FileInfoFields.Inode) != 0)
result += "Inode = " + info.inode + "\n";
if ((ValidFields & FileInfoFields.LinkCount) != 0)
result += "LinkCount = " + info.link_count + "\n";
result += "Uid = " + info.uid + "\n";
result += "Gid = " + info.gid + "\n";
if ((ValidFields & FileInfoFields.Size) != 0)
result += "Size = " + info.size + "\n";
if ((ValidFields & FileInfoFields.BlockCount) != 0)
result += "BlockCount = " + info.block_count + "\n";
if ((ValidFields & FileInfoFields.IoBlockSize) != 0)
result += "IoBlockSize = " + info.io_block_size + "\n";
if ((ValidFields & FileInfoFields.Atime) != 0)
result += "Atime = " + Atime + "\n";
if ((ValidFields & FileInfoFields.Mtime) != 0)
result += "Mtime = " + Mtime + "\n";
if ((ValidFields & FileInfoFields.Ctime) != 0)
result += "Ctime = " + Ctime + "\n";
if ((ValidFields & FileInfoFields.SymlinkName) != 0)
result += "SymlinkName = " + SymlinkName + "\n";
if ((ValidFields & FileInfoFields.MimeType) != 0)
result += "MimeType = " + MimeType + "\n";
return result;
}
}
}
Something went wrong with that request. Please try again.