1 //------------------------------------------------------------------------------
3 // System.IO.FileSystemInfo.cs
5 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
7 // Author: Jim Richardson, develop@wtfo-guru.com
8 // Dan Lewis (dihlewis@yahoo.co.uk)
9 // Created: Monday, August 13, 2001
11 //------------------------------------------------------------------------------
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using System.Runtime.InteropServices;
38 using System.Runtime.Serialization;
43 public abstract class FileSystemInfo : MarshalByRefObject, ISerializable {
44 #region Implementation of ISerializable
47 public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
49 info.AddValue ("OriginalPath", OriginalPath, typeof(string));
50 info.AddValue ("FullPath", FullPath, typeof(string));
53 #endregion Implementation of ISerializable
57 public abstract bool Exists { get; }
59 public abstract string Name { get; }
61 public virtual string FullName {
67 public string Extension {
69 return Path.GetExtension (Name);
73 public FileAttributes Attributes {
76 return stat.Attributes;
82 if (!MonoIO.SetFileAttributes (FullName,
85 throw MonoIO.GetException (FullName,
91 public DateTime CreationTime {
94 return DateTime.FromFileTime (stat.CreationTime);
98 long filetime = value.ToFileTime ();
102 if (!MonoIO.SetFileTime (FullName, filetime,
104 throw MonoIO.GetException (FullName,
111 public DateTime CreationTimeUtc {
113 return CreationTime.ToUniversalTime ();
117 CreationTime = value.ToLocalTime ();
121 public DateTime LastAccessTime {
124 return DateTime.FromFileTime (stat.LastAccessTime);
128 long filetime = value.ToFileTime ();
132 if (!MonoIO.SetFileTime (FullName, -1,
135 throw MonoIO.GetException (FullName,
142 public DateTime LastAccessTimeUtc {
145 return LastAccessTime.ToUniversalTime ();
149 LastAccessTime = value.ToLocalTime ();
153 public DateTime LastWriteTime {
156 return DateTime.FromFileTime (stat.LastWriteTime);
160 long filetime = value.ToFileTime ();
164 if (!MonoIO.SetFileTime (FullName, -1, -1,
165 filetime, out error))
166 throw MonoIO.GetException (FullName,
173 public DateTime LastWriteTimeUtc {
176 return LastWriteTime.ToUniversalTime ();
180 LastWriteTime = value.ToLocalTime ();
186 public abstract void Delete ();
188 public void Refresh ()
195 protected FileSystemInfo ()
198 this.FullPath = null;
201 protected FileSystemInfo (SerializationInfo info, StreamingContext context)
205 throw new ArgumentNullException("info");
208 FullPath = info.GetString("FullPath");
209 OriginalPath = info.GetString("OriginalPath");
212 protected string FullPath;
213 protected string OriginalPath;
217 internal void Refresh (bool force)
224 MonoIO.GetFileStat (FullName, out stat, out error);
225 /* Don't throw on error here, too much other
226 * stuff relies on it not doing so...
234 internal virtual void InternalRefresh ()
238 internal void CheckPath (string path)
241 throw new ArgumentNullException ();
243 if (path.Length == 0)
244 throw new ArgumentException ("empty path");
246 if (path.IndexOfAny (Path.InvalidPathChars) != -1)
247 throw new ArgumentException ("Invalid characters in path.");
250 internal MonoIOStat stat;