|
1 // Windows/FileName.cpp |
|
2 |
|
3 #include "StdAfx.h" |
|
4 |
|
5 #include "Windows/FileName.h" |
|
6 #include "Common/Wildcard.h" |
|
7 |
|
8 namespace NWindows { |
|
9 namespace NFile { |
|
10 namespace NName { |
|
11 |
|
12 static const wchar_t kDiskDelimiter = L':'; |
|
13 |
|
14 /* |
|
15 static bool IsCharAPrefixDelimiter(wchar_t c) |
|
16 { return (c == kDirDelimiter || c == kDiskDelimiter); } |
|
17 */ |
|
18 |
|
19 void NormalizeDirPathPrefix(CSysString &dirPath) |
|
20 { |
|
21 if (dirPath.IsEmpty()) |
|
22 return; |
|
23 if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1) |
|
24 dirPath += kDirDelimiter; |
|
25 } |
|
26 |
|
27 #ifndef _UNICODE |
|
28 void NormalizeDirPathPrefix(UString &dirPath) |
|
29 { |
|
30 if (dirPath.IsEmpty()) |
|
31 return; |
|
32 if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1) |
|
33 dirPath += wchar_t(kDirDelimiter); |
|
34 } |
|
35 #endif |
|
36 |
|
37 namespace NPathType |
|
38 { |
|
39 EEnum GetPathType(const UString &path) |
|
40 { |
|
41 if (path.Length() <= 2) |
|
42 return kLocal; |
|
43 if (path[0] == kDirDelimiter && path[1] == kDirDelimiter) |
|
44 return kUNC; |
|
45 return kLocal; |
|
46 } |
|
47 } |
|
48 |
|
49 void CParsedPath::ParsePath(const UString &path) |
|
50 { |
|
51 int curPos = 0; |
|
52 switch (NPathType::GetPathType(path)) |
|
53 { |
|
54 case NPathType::kLocal: |
|
55 { |
|
56 int posDiskDelimiter = path.Find(kDiskDelimiter); |
|
57 if(posDiskDelimiter >= 0) |
|
58 { |
|
59 curPos = posDiskDelimiter + 1; |
|
60 if (path.Length() > curPos) |
|
61 if(path[curPos] == kDirDelimiter) |
|
62 curPos++; |
|
63 } |
|
64 break; |
|
65 } |
|
66 case NPathType::kUNC: |
|
67 { |
|
68 int curPos = path.Find(kDirDelimiter, 2); |
|
69 if(curPos < 0) |
|
70 curPos = path.Length(); |
|
71 else |
|
72 curPos++; |
|
73 } |
|
74 } |
|
75 Prefix = path.Left(curPos); |
|
76 SplitPathToParts(path.Mid(curPos), PathParts); |
|
77 } |
|
78 |
|
79 UString CParsedPath::MergePath() const |
|
80 { |
|
81 UString result = Prefix; |
|
82 for(int i = 0; i < PathParts.Size(); i++) |
|
83 { |
|
84 if (i != 0) |
|
85 result += kDirDelimiter; |
|
86 result += PathParts[i]; |
|
87 } |
|
88 return result; |
|
89 } |
|
90 |
|
91 const wchar_t kExtensionDelimiter = L'.'; |
|
92 |
|
93 void SplitNameToPureNameAndExtension(const UString &fullName, |
|
94 UString &pureName, UString &extensionDelimiter, UString &extension) |
|
95 { |
|
96 int index = fullName.ReverseFind(kExtensionDelimiter); |
|
97 if (index < 0) |
|
98 { |
|
99 pureName = fullName; |
|
100 extensionDelimiter.Empty(); |
|
101 extension.Empty(); |
|
102 } |
|
103 else |
|
104 { |
|
105 pureName = fullName.Left(index); |
|
106 extensionDelimiter = kExtensionDelimiter; |
|
107 extension = fullName.Mid(index + 1); |
|
108 } |
|
109 } |
|
110 |
|
111 }}} |