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-2005 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.
36 using System.Runtime.InteropServices;
37 using System.Runtime.Serialization;
38 using System.Security.Permissions;
43 [FileIOPermission (SecurityAction.InheritanceDemand, Unrestricted = true)]
47 public abstract class FileSystemInfo : MarshalByRefObject, ISerializable {
48 #region Implementation of ISerializable
51 public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
53 info.AddValue ("OriginalPath", OriginalPath, typeof(string));
54 info.AddValue ("FullPath", FullPath, typeof(string));
57 #endregion Implementation of ISerializable
61 public abstract bool Exists { get; }
63 public abstract string Name { get; }
65 public virtual string FullName {
71 public string Extension {
73 return Path.GetExtension (Name);
77 public FileAttributes Attributes {
80 return stat.Attributes;
86 if (!MonoIO.SetFileAttributes (FullName,
89 throw MonoIO.GetException (FullName,
95 public DateTime CreationTime {
98 return DateTime.FromFileTime (stat.CreationTime);
102 long filetime = value.ToFileTime ();
106 if (!MonoIO.SetFileTime (FullName, filetime,
108 throw MonoIO.GetException (FullName,
115 public DateTime CreationTimeUtc {
117 return CreationTime.ToUniversalTime ();
121 CreationTime = value.ToLocalTime ();
125 public DateTime LastAccessTime {
128 return DateTime.FromFileTime (stat.LastAccessTime);
132 long filetime = value.ToFileTime ();
136 if (!MonoIO.SetFileTime (FullName, -1,
139 throw MonoIO.GetException (FullName,
146 public DateTime LastAccessTimeUtc {
149 return LastAccessTime.ToUniversalTime ();
153 LastAccessTime = value.ToLocalTime ();
157 public DateTime LastWriteTime {
160 return DateTime.FromFileTime (stat.LastWriteTime);
164 long filetime = value.ToFileTime ();
168 if (!MonoIO.SetFileTime (FullName, -1, -1,
169 filetime, out error))
170 throw MonoIO.GetException (FullName,
177 public DateTime LastWriteTimeUtc {
180 return LastWriteTime.ToUniversalTime ();
184 LastWriteTime = value.ToLocalTime ();
190 public abstract void Delete ();
192 public void Refresh ()
199 protected FileSystemInfo ()
202 this.FullPath = null;
205 protected FileSystemInfo (SerializationInfo info, StreamingContext context)
209 throw new ArgumentNullException("info");
212 FullPath = info.GetString("FullPath");
213 OriginalPath = info.GetString("OriginalPath");
216 protected string FullPath;
217 protected string OriginalPath;
221 internal void Refresh (bool force)
228 MonoIO.GetFileStat (FullName, out stat, out error);
229 /* Don't throw on error here, too much other
230 * stuff relies on it not doing so...
238 internal virtual void InternalRefresh ()
242 internal void CheckPath (string path)
245 throw new ArgumentNullException ("path");
247 if (path.Length == 0)
248 throw new ArgumentException ("path", Locale.GetText ("Empty path."));
250 if (path.IndexOfAny (Path.InvalidPathChars) != -1)
251 throw new ArgumentException ("path", Locale.GetText ("Invalid characters in path."));
254 internal MonoIOStat stat;