FileSystemInfo.cs 2.5 KB

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