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