00001 /* 00002 Free Download Manager Copyright (c) 2003-2007 FreeDownloadManager.ORG 00003 */ 00004 00005 #include "StdAfx.h" 00006 00007 #include "Windows/FileName.h" 00008 #include "Common/Wildcard.h" 00009 00010 namespace NWindows { 00011 namespace NFile { 00012 namespace NName { 00013 00014 static const wchar_t kDiskDelimiter = L':'; 00015 00016 void NormalizeDirPathPrefix(CSysString &dirPath) 00017 { 00018 if (dirPath.IsEmpty()) 00019 return; 00020 if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1) 00021 dirPath += kDirDelimiter; 00022 } 00023 00024 #ifndef _UNICODE 00025 void NormalizeDirPathPrefix(UString &dirPath) 00026 { 00027 if (dirPath.IsEmpty()) 00028 return; 00029 if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1) 00030 dirPath += wchar_t(kDirDelimiter); 00031 } 00032 #endif 00033 00034 namespace NPathType 00035 { 00036 EEnum GetPathType(const UString &path) 00037 { 00038 if (path.Length() <= 2) 00039 return kLocal; 00040 if (path[0] == kDirDelimiter && path[1] == kDirDelimiter) 00041 return kUNC; 00042 return kLocal; 00043 } 00044 } 00045 00046 void CParsedPath::ParsePath(const UString &path) 00047 { 00048 int curPos = 0; 00049 switch (NPathType::GetPathType(path)) 00050 { 00051 case NPathType::kLocal: 00052 { 00053 int posDiskDelimiter = path.Find(kDiskDelimiter); 00054 if(posDiskDelimiter >= 0) 00055 { 00056 curPos = posDiskDelimiter + 1; 00057 if (path.Length() > curPos) 00058 if(path[curPos] == kDirDelimiter) 00059 curPos++; 00060 } 00061 break; 00062 } 00063 case NPathType::kUNC: 00064 { 00065 int curPos = path.Find(kDirDelimiter, 2); 00066 if(curPos < 0) 00067 curPos = path.Length(); 00068 else 00069 curPos++; 00070 } 00071 } 00072 Prefix = path.Left(curPos); 00073 SplitPathToParts(path.Mid(curPos), PathParts); 00074 } 00075 00076 UString CParsedPath::MergePath() const 00077 { 00078 UString result = Prefix; 00079 for(int i = 0; i < PathParts.Size(); i++) 00080 { 00081 if (i != 0) 00082 result += kDirDelimiter; 00083 result += PathParts[i]; 00084 } 00085 return result; 00086 } 00087 00088 const wchar_t kExtensionDelimiter = L'.'; 00089 00090 void SplitNameToPureNameAndExtension(const UString &fullName, 00091 UString &pureName, UString &extensionDelimiter, UString &extension) 00092 { 00093 int index = fullName.ReverseFind(kExtensionDelimiter); 00094 if (index < 0) 00095 { 00096 pureName = fullName; 00097 extensionDelimiter.Empty(); 00098 extension.Empty(); 00099 } 00100 else 00101 { 00102 pureName = fullName.Left(index); 00103 extensionDelimiter = kExtensionDelimiter; 00104 extension = fullName.Mid(index + 1); 00105 } 00106 } 00107 00108 }}}
1.5.6