1 //------------------------------------------------------------------------------
\r
3 // System.IO.FileInfo.cs
\r
5 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
\r
7 // Author: Jim Richardson, develop@wtfo-guru.com
\r
8 // Created: Monday, August 13, 2001
\r
10 //------------------------------------------------------------------------------
\r
13 using System.Private;
\r
14 using System.IO.Private;
15 using System.Diagnostics;
16 using System.Security.Permissions;
23 public sealed class FileInfo : FileSystemInfo
\r
25 public FileInfo(string fileName)
\r
27 CheckArgument.Path(fileName, false);
28 //LAMESPEC: Does not throw security exception in constructor
29 OriginalPath = fileName;
32 private bool existsOnDisk(bool exNotFound, bool exIsDirectory)
39 if((getAttributes() & FileAttributes.Directory) != 0)
43 throw new UnauthorizedAccessException();
52 catch(ArgumentException ex)
54 Debug.WriteLine(ex); // eliminates not used warning
57 throw new FileNotFoundException();
64 public override bool Exists
\r
68 return existsOnDisk(false, false);
72 public override string Name
\r
76 return Path.GetFileName(getPathName());
\r
81 /// Gets the parent directory info
\r
83 public DirectoryInfo Directory
\r
87 return new DirectoryInfo(Path.GetDirectoryName(getPathName()));
\r
92 /// Get the path of the file
\r
94 public string DirectoryName
\r
98 return Path.GetDirectoryName(getPathName());
\r
103 /// Get the length of the file
\r
113 catch(ArgumentException ex)
115 Debug.WriteLine(ex); // eliminates not used compiler warning
116 throw new FileNotFoundException();
118 return status.st_size;
122 public StreamWriter AppendText()
\r
123 { // TODO: verify using correct FileMode here might be Create & Append
124 return new StreamWriter(Open(FileMode.Append, FileAccess.Write));
127 public FileStream Create()
\r
129 // TODO: verify using correct FileMode here
130 return Open(FileMode.OpenOrCreate, FileAccess.ReadWrite);
\r
133 public StreamWriter CreateText()
\r
134 { //TODO: According to doc even CreateText throws a file not found ex
135 // sounds suspicious so i'll have to check it out later
136 //existsOnDisk(true, true); // throw not found, is directory
137 return new StreamWriter(Open(FileMode.Create, FileAccess.Write));
140 public FileStream Open(FileMode mode)
\r
142 return Open(mode, FileAccess.ReadWrite);
\r
145 public FileStream Open(FileMode mode, FileAccess access)
\r
147 return Open(mode, access, FileShare.None);
\r
150 public FileStream Open(FileMode mode, FileAccess access, FileShare share)
\r
152 bool bExists = existsOnDisk(false, true); // throw is directory;
153 string path = getPathName();
154 CheckPermission.ModeAccess(mode, access, path, bExists);
\r
155 return new FileStream(path, mode, access, share);
\r
158 public FileStream OpenRead()
\r
159 { // TODO: find out what default share should be
\r
160 return Open(FileMode.Open, FileAccess.Read, FileShare.Read);
\r
163 public StreamReader OpenText()
\r
164 { // TODO: verify mode and access values
165 return new StreamReader(Open(FileMode.OpenOrCreate, FileAccess.ReadWrite));
168 public FileStream OpenWrite()
\r
170 return Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
\r
173 public FileInfo CopyTo(string destFile)
\r
175 return CopyTo(destFile, false);
\r
178 public FileInfo CopyTo(string destFile, bool bOverwrite)
\r
179 { // TODO: Implement
\r
183 public override void Delete()
\r
185 existsOnDisk(true, true); // throw not found, is directory
186 CheckPermission.Demand(FileIOPermissionAccess.AllAccess, getPathName());
187 Wrapper.unlink(getPathName());
190 public void MoveTo(string destName)
\r
191 { // TODO: Implement
\r