1 //------------------------------------------------------------------------------
3 // System.IO.FileSystemInfo.cs
5 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
7 // Author: Jim Richardson, develop@wtfo-guru.com
8 // Created: Monday, August 13, 2001
10 //------------------------------------------------------------------------------
19 public abstract class FileSystemInfo : MarshalByRefObject
21 // protected stat status;
24 protected string FullPath;
25 protected string OriginalPath;
27 protected FileSystemInfo()
41 FullPath = OriginalPath = String.Empty;
44 public FileAttributes Attributes
48 return getAttributes();
56 public DateTime CreationTime
64 // TODO: fix next line as far as my research has taken me so far, Unix/Linux don't
65 // have a creation time and according to my man the ctime if the last time
66 // one of the chmod flags was changed
67 return c2csharpTime(10);//status.st_ctime);
75 public abstract bool Exists {get;}
76 public abstract string Name {get;}
77 public abstract void Delete();
80 /// Get the extension of this item
82 public string Extension
86 return Path.GetExtension(getPathName());
90 public string FullName
98 public DateTime LastAccessTime
106 return c2csharpTime(1);//status.st_atime);
115 public DateTime LastWriteTime
123 return c2csharpTime(1);//status.st_mtime);
130 public override int GetHashCode()
132 return getPathName().GetHashCode();
135 public override bool Equals(object obj)
140 new public static bool Equals(object obj1, object obj2)
145 public void Refresh()
151 unsafe private void update()
155 int nRetCode = Wrapper.stat(getPathName(), &fs);
162 case Wrapper.ENOTDIR:
163 throw new ArgumentException("File not found");
164 //break; generates warning CS0162 unreachable code
166 throw new IOException();
167 //break; generates warning CS0162 unreachable code
173 private DateTime c2csharpTime(double seconds)
174 { // TODO: determine if UTC time which the
175 // calculation below is in is correct
176 DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
177 dt.AddSeconds(seconds);
181 protected string getPathName()
183 if(FullPath == String.Empty)
185 FullPath = Path.GetFullPath(OriginalPath);
190 protected FileAttributes getAttributes()
197 // TODO: lots more attribute work needed
199 FileAttributes attrib = 0;
201 if(((status.st_mode & Wrapper.S_IFMT) & Wrapper.S_IFDIR) != 0)
203 attrib |= FileAttributes.Directory;
207 attrib |= FileAttributes.Normal;