FileSystemInfo.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //------------------------------------------------------------------------------
  2. //
  3. // System.IO.FileSystemInfo.cs
  4. //
  5. // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
  6. //
  7. // Author: Jim Richardson, [email protected]
  8. // Created: Monday, August 13, 2001
  9. //
  10. //------------------------------------------------------------------------------
  11. using System;
  12. namespace System.IO
  13. {
  14. /// <summary>
  15. ///
  16. /// </summary>
  17. public abstract class FileSystemInfo : MarshalByRefObject
  18. {
  19. // protected stat status;
  20. private bool inited;
  21. protected string FullPath;
  22. protected string OriginalPath;
  23. protected FileSystemInfo ()
  24. {
  25. /*
  26. status.st_dev = 0;
  27. status.st_mode = 0;
  28. status.st_nlink = 0;
  29. status.st_uid = 0;
  30. status.st_gid = 0;
  31. status.st_size = 0;
  32. status.st_atime = 0;
  33. status.st_mtime = 0;
  34. status.st_ctime = 0;
  35. */
  36. FullPath = OriginalPath = String.Empty;
  37. }
  38. [MonoTODO]
  39. public FileAttributes Attributes
  40. {
  41. get
  42. {
  43. return getAttributes ();
  44. }
  45. set
  46. {
  47. //TODO: Implement
  48. }
  49. }
  50. [MonoTODO]
  51. public DateTime CreationTime
  52. {
  53. get
  54. {
  55. if (!inited)
  56. {
  57. update ();
  58. }
  59. // TODO: fix next line as far as my research has taken me so far, Unix/Linux don't
  60. // have a creation time and according to my man the ctime if the last time
  61. // one of the chmod flags was changed
  62. return c2csharpTime (10);//status.st_ctime);
  63. }
  64. set
  65. {
  66. //TODO: Implement
  67. }
  68. }
  69. public abstract bool Exists {get;}
  70. public abstract string Name {get;}
  71. public abstract void Delete ();
  72. /// <summary>
  73. /// Get the extension of this item
  74. /// </summary>
  75. public string Extension
  76. {
  77. get
  78. {
  79. return Path.GetExtension (getPathName ());
  80. }
  81. }
  82. public string FullName
  83. {
  84. get
  85. {
  86. return getPathName ();
  87. }
  88. }
  89. [MonoTODO]
  90. public DateTime LastAccessTime
  91. {
  92. get
  93. {
  94. if (!inited)
  95. {
  96. update ();
  97. }
  98. return c2csharpTime (1);//status.st_atime);
  99. }
  100. set
  101. {
  102. // TODO: Implement
  103. }
  104. }
  105. [MonoTODO]
  106. public DateTime LastWriteTime
  107. { // TODO: Implement
  108. get
  109. {
  110. if (!inited)
  111. {
  112. update ();
  113. }
  114. return c2csharpTime (1);//status.st_mtime);
  115. }
  116. set
  117. { // TODO: Implement
  118. }
  119. }
  120. public override int GetHashCode ()
  121. {
  122. return getPathName ().GetHashCode ();
  123. }
  124. [MonoTODO]
  125. public override bool Equals (object obj)
  126. { // TODO: Implement
  127. return false;
  128. }
  129. [MonoTODO]
  130. new public static bool Equals (object obj1, object obj2)
  131. { // TODO: Implement
  132. return false;
  133. }
  134. public void Refresh ()
  135. {
  136. update ();
  137. }
  138. unsafe private void update ()
  139. {
  140. /*
  141. stat fs;
  142. int nRetCode = Wrapper.stat (getPathName (), &fs);
  143. status = fs;
  144. switch (nRetCode)
  145. {
  146. case 0:
  147. break;
  148. case Wrapper.ENOENT:
  149. case Wrapper.ENOTDIR:
  150. throw new ArgumentException ("File not found");
  151. //break; generates warning CS0162 unreachable code
  152. default:
  153. throw new IOException ();
  154. //break; generates warning CS0162 unreachable code
  155. }
  156. */
  157. inited = true;
  158. }
  159. [MonoTODO]
  160. private DateTime c2csharpTime (double seconds)
  161. { // TODO: determine if UTC time which the
  162. // calculation below is in is correct
  163. DateTime dt = new DateTime (1970, 1, 1, 0, 0, 0);
  164. dt.AddSeconds (seconds);
  165. return dt;
  166. }
  167. protected string getPathName ()
  168. {
  169. if (FullPath == String.Empty)
  170. FullPath = Path.GetFullPath (OriginalPath);
  171. return FullPath;
  172. }
  173. [MonoTODO]
  174. protected FileAttributes getAttributes ()
  175. {
  176. if (!inited)
  177. {
  178. update ();
  179. }
  180. // TODO: lots more attribute work needed
  181. FileAttributes attrib = 0;
  182. /*
  183. if (((status.st_mode & Wrapper.S_IFMT) & Wrapper.S_IFDIR) != 0)
  184. {
  185. attrib |= FileAttributes.Directory;
  186. }
  187. else
  188. {
  189. attrib |= FileAttributes.Normal;
  190. }
  191. */
  192. return attrib;
  193. }
  194. }
  195. }