| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- //------------------------------------------------------------------------------
- //
- // System.IO.FileSystemInfo.cs
- //
- // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
- //
- // Author: Jim Richardson, [email protected]
- // Dan Lewis ([email protected])
- // Created: Monday, August 13, 2001
- //
- //------------------------------------------------------------------------------
- using System;
- namespace System.IO {
-
- [Serializable]
- public abstract class FileSystemInfo : MarshalByRefObject {
- // public properties
- public abstract bool Exists { get; }
- public abstract string Name { get; }
- public virtual string FullName {
- get {
- return FullPath;
- }
- }
- public string Extension {
- get {
- return Path.GetExtension (Name);
- }
- }
- public FileAttributes Attributes {
- get {
- Refresh (false);
- return stat.Attributes;
- }
- set {
- MonoIOError error;
-
- if (!MonoIO.SetFileAttributes (FullName,
- value,
- out error))
- throw MonoIO.GetException (error);
- }
- }
- public DateTime CreationTime {
- get {
- Refresh (false);
- return DateTime.FromFileTime (stat.CreationTime);
- }
- set {
- long filetime = value.ToFileTime ();
-
- MonoIOError error;
-
- if (!MonoIO.SetFileTime (FullName, filetime,
- -1, -1, out error))
- throw MonoIO.GetException (error);
- }
- }
- public DateTime LastAccessTime {
- get {
- Refresh (false);
- return DateTime.FromFileTime (stat.LastAccessTime);
- }
- set {
- long filetime = value.ToFileTime ();
- MonoIOError error;
-
- if (!MonoIO.SetFileTime (FullName, -1,
- filetime, -1,
- out error))
- throw MonoIO.GetException (error);
- }
- }
- public DateTime LastWriteTime {
- get {
- Refresh (false);
- return DateTime.FromFileTime (stat.LastWriteTime);
- }
- set {
- long filetime = value.ToFileTime ();
- MonoIOError error;
-
- if (!MonoIO.SetFileTime (FullName, -1, -1,
- filetime, out error))
- throw MonoIO.GetException (error);
- }
- }
- // public methods
- public abstract void Delete ();
- public void Refresh ()
- {
- Refresh (true);
- }
- // protected
- protected FileSystemInfo ()
- {
- this.valid = false;
- this.FullPath = null;
- }
- protected string FullPath;
- protected string OriginalPath;
- // internal
- internal void Refresh (bool force)
- {
- if (valid && !force)
- return;
- MonoIOError error;
-
- MonoIO.GetFileStat (FullName, out stat, out error);
- valid = true;
- }
- internal void CheckPath (string path)
- {
- if (path == null)
- throw new ArgumentNullException ();
- if (path.IndexOfAny (Path.InvalidPathChars) != -1)
- throw new ArgumentException ("Invalid characters in path.");
- }
- internal MonoIOStat stat;
- internal bool valid;
- }
- }
|