Removing old build files. NAnt doesn't use them.
[mono.git] / mcs / class / corlib / System.IO / FileSystemInfo.cs
1 //------------------------------------------------------------------------------
2 // 
3 // System.IO.FileSystemInfo.cs 
4 //
5 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
6 // 
7 // Author:         Jim Richardson, develop@wtfo-guru.com
8 // Created:        Monday, August 13, 2001 
9 //
10 //------------------------------------------------------------------------------
11
12 using System;
13
14 namespace System.IO
15 {
16         /// <summary>
17         /// 
18         /// </summary>
19         public abstract class FileSystemInfo : MarshalByRefObject
20         {
21                 // protected stat status;
22                 private bool inited;
23                 
24                 protected string FullPath;
25                 protected string OriginalPath;
26
27                 protected FileSystemInfo()
28                 {
29                         /*
30                         status.st_dev = 0;
31                         status.st_mode = 0;
32                         status.st_nlink = 0;
33                         status.st_uid = 0;
34                         status.st_gid = 0;
35                         status.st_size = 0;
36                         status.st_atime = 0;
37                         status.st_mtime = 0;
38                         status.st_ctime = 0;
39                         */
40
41                         FullPath = OriginalPath = String.Empty;
42                 }
43
44                 public FileAttributes Attributes
45                 { 
46                         get
47                         {
48                                 return getAttributes();
49                         }
50                         set
51                         {
52                                 //TODO: Implement 
53                         }
54                 }
55
56                 public DateTime CreationTime
57                 {
58                         get
59                         {
60                                 if(!inited)
61                                 {
62                                         update();
63                                 }
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);
68                         }
69                         set
70                         {
71                                 //TODO: Implement
72                         }
73                 }
74
75                 public abstract bool Exists {get;}
76                 public abstract string Name {get;}
77                 public abstract void Delete();
78
79                 /// <summary>
80                 /// Get the extension of this item
81                 /// </summary>
82                 public string Extension
83                 {
84                         get
85                         {
86                                 return Path.GetExtension(getPathName());
87                         }
88                 }
89
90                 public string FullName
91                 {
92                         get
93                         {
94                                 return getPathName();
95                         }
96                 }
97
98                 public DateTime LastAccessTime
99                 {
100                         get
101                         {
102                                 if(!inited)
103                                 {
104                                         update();
105                                 }
106                                 return c2csharpTime(1);//status.st_atime);
107                         }
108
109                         set
110                         {
111                                 // TODO: Implement
112                         }
113                 }
114
115                 public DateTime LastWriteTime
116                 {       // TODO: Implement
117                         get
118                         {
119                                 if(!inited)
120                                 {
121                                         update();
122                                 }
123                                 return c2csharpTime(1);//status.st_mtime);
124                         }
125                         set
126                         {       // TODO: Implement
127                         }
128                 }
129
130                 public override int GetHashCode()
131                 {
132                         return getPathName().GetHashCode();
133                 }
134
135                 public override bool Equals(object obj)
136                 {       // TODO: Implement
137                         return false;
138                 }
139
140                 new public static bool Equals(object obj1, object obj2)
141                 {       // TODO: Implement
142                         return false;
143                 }
144                                 
145                 public void Refresh()
146                 {
147                         update();
148                 }
149                 
150
151                 unsafe private void update()
152                 {
153                         /*
154                         stat fs;                        
155                         int nRetCode = Wrapper.stat(getPathName(), &fs);
156                         status = fs;
157                         switch(nRetCode)
158                         {
159                         case 0:
160                                 break;
161                         case Wrapper.ENOENT:
162                         case Wrapper.ENOTDIR:
163                                 throw new ArgumentException("File not found");  
164                                 //break; generates warning CS0162 unreachable code
165                         default:
166                                 throw new IOException();
167                            //break; generates warning CS0162 unreachable code
168                         }
169                         inited = true;
170                         */
171                 }
172
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);
178                    return dt;   
179                 }
180                 
181                 protected string getPathName()
182                 {
183                         if(FullPath == String.Empty)
184                         {
185                                 FullPath = Path.GetFullPath(OriginalPath);
186                         }
187                         return FullPath;
188                 } 
189                 
190                 protected FileAttributes getAttributes()
191                 {       
192                         if(!inited)
193                         {
194                                 update();
195                         }
196                         
197                         // TODO: lots more attribute work needed
198                                 
199                         FileAttributes attrib = 0;
200                         /*
201                         if(((status.st_mode & Wrapper.S_IFMT) & Wrapper.S_IFDIR) != 0)
202                         {
203                                 attrib |= FileAttributes.Directory;
204                         }
205                         else
206                         {
207                                 attrib |= FileAttributes.Normal;
208                         }
209                         */
210
211                         return attrib;
212                 }
213         }
214 }