FileSystemInfo.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. // Dan Lewis ([email protected])
  9. // Created: Monday, August 13, 2001
  10. //
  11. //------------------------------------------------------------------------------
  12. using System;
  13. namespace System.IO {
  14. [Serializable]
  15. public abstract class FileSystemInfo : MarshalByRefObject {
  16. // public properties
  17. public abstract bool Exists { get; }
  18. public abstract string Name { get; }
  19. public virtual string FullName {
  20. get {
  21. return FullPath;
  22. }
  23. }
  24. public string Extension {
  25. get {
  26. return Path.GetExtension (Name);
  27. }
  28. }
  29. public FileAttributes Attributes {
  30. get {
  31. Refresh (false);
  32. return stat.Attributes;
  33. }
  34. set {
  35. if (!MonoIO.SetFileAttributes (FullName, value))
  36. throw MonoIO.GetException ();
  37. }
  38. }
  39. public DateTime CreationTime {
  40. get {
  41. Refresh (false);
  42. return DateTime.FromFileTime (stat.CreationTime);
  43. }
  44. set {
  45. long filetime = value.ToFileTime ();
  46. if (!MonoIO.SetFileTime (FullName, filetime, -1, -1))
  47. throw MonoIO.GetException ();
  48. }
  49. }
  50. public DateTime LastAccessTime {
  51. get {
  52. Refresh (false);
  53. return DateTime.FromFileTime (stat.LastAccessTime);
  54. }
  55. set {
  56. long filetime = value.ToFileTime ();
  57. if (!MonoIO.SetFileTime (FullName, -1, filetime, -1))
  58. throw MonoIO.GetException ();
  59. }
  60. }
  61. public DateTime LastWriteTime {
  62. get {
  63. Refresh (false);
  64. return DateTime.FromFileTime (stat.LastWriteTime);
  65. }
  66. set {
  67. long filetime = value.ToFileTime ();
  68. if (!MonoIO.SetFileTime (FullName, -1, -1, filetime))
  69. throw MonoIO.GetException ();
  70. }
  71. }
  72. // public methods
  73. public abstract void Delete ();
  74. public void Refresh ()
  75. {
  76. Refresh (true);
  77. }
  78. // protected
  79. protected FileSystemInfo ()
  80. {
  81. this.valid = false;
  82. this.FullPath = null;
  83. }
  84. protected string FullPath;
  85. protected string OriginalPath;
  86. // internal
  87. internal void Refresh (bool force)
  88. {
  89. if (valid && !force)
  90. return;
  91. MonoIO.GetFileStat (FullName, out stat);
  92. valid = true;
  93. }
  94. internal void CheckPath (string path)
  95. {
  96. if (path == null)
  97. throw new ArgumentNullException ();
  98. if (path.IndexOfAny (Path.InvalidPathChars) != -1)
  99. throw new ArgumentException ("Invalid characters in path.");
  100. }
  101. internal MonoIOStat stat;
  102. internal bool valid;
  103. }
  104. }