FilePathParser.cs 1.7 KB

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