2001-12-22 Gaurav Vaish <gvaish@iitk.ac.in>
[mono.git] / mcs / class / System.Web / System.Web.Utils / FilePathParser.cs
1 /**\r
2  * Namespace: System.Web.Utils\r
3  * Class:     FilePathParser\r
4  *\r
5  * Author:  Gaurav Vaish\r
6  * Maintainer: gvaish@iitk.ac.in\r
7  * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>\r
8  * Implementation: yes\r
9  * Status:  ??%\r
10  *\r
11  * (C) Gaurav Vaish (2001)\r
12  */\r
13 \r
14 namespace System.Web.Utils\r
15 {\r
16         internal class FilePathParser\r
17         {\r
18                 private static char[] pathSeparators = {\r
19                         Path.DirectorySeparatorChar,\r
20                         Path.AltDirectorySeparatorChar\r
21                 };\r
22                 \r
23                 private string dirName;\r
24                 private string fileName;\r
25                 private string shortDirName;\r
26                 private string shortFileName;\r
27                 \r
28                 private bool   exists;\r
29                 \r
30                 public FilePathParser(string path, bool isFile, bool getShortNames)\r
31                 {\r
32                         path = path.Trim();\r
33                         if(Path.GetPathRoot(path).Length < path.Length)\r
34                         {\r
35                                 path = path.TrimEnd(pathSeparators);\r
36                         }\r
37                         if(!isFile)\r
38                         {\r
39                                 dirName = GetBaseDirOrRoot(path);\r
40                         } else\r
41                         {\r
42                                 dirName = path;\r
43                         }\r
44                         if(getShortNames)\r
45                         {\r
46                                 if(!Directory.Exists(dirName))\r
47                                 {\r
48                                         dirName = null;\r
49                                         return;\r
50                                 }\r
51                                 shortDirName = GetShortPathName(dirName);\r
52                                 if(shortDirName==null)\r
53                                 {\r
54                                         dirName = null;\r
55                                         return;\r
56                                 }\r
57                                 if(shortDirName == dirName)\r
58                                 {\r
59                                         shortDirName = null;\r
60                                 } else\r
61                                 {\r
62                                         throw new NotImplementedException();\r
63                                 }\r
64                         }\r
65                 }\r
66                 \r
67                 public static string GetBaseDirOrRoot(string file)\r
68                 {\r
69                         string bDir = Path.GetDirectoryName(file);\r
70                         return ( bDir!=null ? bDir : GetPathRoot(file));\r
71                 }\r
72                 \r
73                 public static string GetShortPathName(string path)\r
74                 {\r
75                         //TODO: Native calls required, it's in kernel32.dll for windows\r
76                         throw new NotImplementedException();\r
77                 }\r
78         }\r
79 }\r