Moved from System.Web.Utils to System.Web.Util
[mono.git] / mcs / class / System.Web / System.Web.Util / FilePathParser.cs
1 /**\r
2  * Namespace: System.Web.Util\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 using System.IO;\r
14 \r
15 namespace System.Web.Util\r
16 {\r
17         internal class FilePathParser\r
18         {\r
19                 private static char[] pathSeparators = {\r
20                         Path.DirectorySeparatorChar,\r
21                         Path.AltDirectorySeparatorChar\r
22                 };\r
23                 \r
24                 private string dirName;\r
25                 private string fileName;\r
26                 private string shortDirName;\r
27                 private string shortFileName;\r
28                 \r
29                 private bool   exists;\r
30                 \r
31                 [MonoTODO]\r
32                 public FilePathParser(string path, bool isFile, bool getShortNames)\r
33                 {\r
34                         path = path.Trim();\r
35                         if(Path.GetPathRoot(path).Length < path.Length)\r
36                         {\r
37                                 path = path.TrimEnd(pathSeparators);\r
38                         }\r
39                         if(!isFile)\r
40                         {\r
41                                 dirName = GetBaseDirOrRoot(path);\r
42                         } else\r
43                         {\r
44                                 dirName = path;\r
45                         }\r
46                         if(getShortNames)\r
47                         {\r
48                                 if(!Directory.Exists(dirName))\r
49                                 {\r
50                                         dirName = null;\r
51                                         return;\r
52                                 }\r
53                                 shortDirName = GetShortPathName(dirName);\r
54                                 if(shortDirName==null)\r
55                                 {\r
56                                         dirName = null;\r
57                                         return;\r
58                                 }\r
59                                 if(shortDirName == dirName)\r
60                                 {\r
61                                         shortDirName = null;\r
62                                 } else\r
63                                 {\r
64                                         throw new NotImplementedException();\r
65                                 }\r
66                         }\r
67                 }\r
68                 \r
69                 public static string GetBaseDirOrRoot(string file)\r
70                 {\r
71                         string bDir = Path.GetDirectoryName(file);\r
72                         return ( bDir!=null ? bDir : Path.GetPathRoot(file));\r
73                 }\r
74                 \r
75                 [MonoTODO("Native_Call_Required")]\r
76                 public static string GetShortPathName(string path)\r
77                 {\r
78                         //TODO: Native calls required, it's in kernel32.dll for windows\r
79                         throw new NotImplementedException();\r
80                 }\r
81         }\r
82 }\r