FileSystemInfo.cs 3.7 KB

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