OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_path.h" | 5 #include "base/file_path.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #elif defined(OS_MACOSX) | 9 #elif defined(OS_MACOSX) |
10 #include <CoreFoundation/CoreFoundation.h> | 10 #include <CoreFoundation/CoreFoundation.h> |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 28 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
29 const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("\\/"); | 29 const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("\\/"); |
30 #else // FILE_PATH_USES_WIN_SEPARATORS | 30 #else // FILE_PATH_USES_WIN_SEPARATORS |
31 const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("/"); | 31 const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("/"); |
32 #endif // FILE_PATH_USES_WIN_SEPARATORS | 32 #endif // FILE_PATH_USES_WIN_SEPARATORS |
33 | 33 |
34 const FilePath::CharType FilePath::kCurrentDirectory[] = FILE_PATH_LITERAL("."); | 34 const FilePath::CharType FilePath::kCurrentDirectory[] = FILE_PATH_LITERAL("."); |
35 const FilePath::CharType FilePath::kParentDirectory[] = FILE_PATH_LITERAL(".."); | 35 const FilePath::CharType FilePath::kParentDirectory[] = FILE_PATH_LITERAL(".."); |
36 | 36 |
| 37 #if defined(OS_WIN) |
| 38 const FilePath::CharType FilePath::kExtendedPathPrefix[] = |
| 39 FILE_PATH_LITERAL("\\\\?\\"); |
| 40 |
| 41 const FilePath::CharType FilePath::kUNCExtendedPathPrefix[] = |
| 42 FILE_PATH_LITERAL("\\\\?\\UNC\\"); |
| 43 |
| 44 const FilePath::CharType FilePath::kSharePrefix[] = |
| 45 FILE_PATH_LITERAL("\\\\"); |
| 46 |
| 47 const int kSharePrefixLength = 2; |
| 48 #endif |
| 49 |
37 const FilePath::CharType FilePath::kExtensionSeparator = FILE_PATH_LITERAL('.'); | 50 const FilePath::CharType FilePath::kExtensionSeparator = FILE_PATH_LITERAL('.'); |
38 | 51 |
39 typedef FilePath::StringType StringType; | 52 typedef FilePath::StringType StringType; |
40 | 53 |
41 namespace { | 54 namespace { |
42 | 55 |
43 const char* kCommonDoubleExtensions[] = { "gz", "z", "bz2" }; | 56 const char* kCommonDoubleExtensions[] = { "gz", "z", "bz2" }; |
44 | 57 |
45 // If this FilePath contains a drive letter specification, returns the | 58 // If this FilePath contains a drive letter specification, returns the |
46 // position of the last character of the drive letter specification, | 59 // position of the last character of the drive letter specification, |
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 | 1196 |
1184 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 1197 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
1185 FilePath FilePath::NormalizeWindowsPathSeparators() const { | 1198 FilePath FilePath::NormalizeWindowsPathSeparators() const { |
1186 StringType copy = path_; | 1199 StringType copy = path_; |
1187 for (size_t i = 1; i < arraysize(kSeparators); ++i) { | 1200 for (size_t i = 1; i < arraysize(kSeparators); ++i) { |
1188 std::replace(copy.begin(), copy.end(), kSeparators[i], kSeparators[0]); | 1201 std::replace(copy.begin(), copy.end(), kSeparators[i], kSeparators[0]); |
1189 } | 1202 } |
1190 return FilePath(copy); | 1203 return FilePath(copy); |
1191 } | 1204 } |
1192 #endif | 1205 #endif |
| 1206 |
| 1207 #if defined(OS_WIN) |
| 1208 // TODO(kkanetkar): Taken from gears. Replace this when |
| 1209 // crbug.com/67384 is addressed. |
| 1210 StringType FilePath::ToLongFileNameHack(const StringType& path) const { |
| 1211 StringType long_path; |
| 1212 // This cast is for countering the compiler warning. |
| 1213 DWORD length_to_try = static_cast<DWORD>(path.length() * 2); |
| 1214 long_path.resize(length_to_try); |
| 1215 DWORD actual_length = GetLongPathName(path.c_str(), |
| 1216 &long_path.at(0), |
| 1217 length_to_try); |
| 1218 if (actual_length == 0) { |
| 1219 return path; |
| 1220 } else if (actual_length <= length_to_try) { |
| 1221 long_path.resize(actual_length); |
| 1222 return long_path; |
| 1223 } |
| 1224 |
| 1225 length_to_try = actual_length; |
| 1226 long_path.resize(length_to_try); |
| 1227 actual_length = GetLongPathName(path.c_str(), |
| 1228 &long_path.at(0), |
| 1229 length_to_try + 1); |
| 1230 if (actual_length > 0 && actual_length <= length_to_try) { |
| 1231 long_path.resize(actual_length); |
| 1232 return long_path; |
| 1233 } else { |
| 1234 return path; |
| 1235 } |
| 1236 } |
| 1237 |
| 1238 FilePath FilePath::GetLongPathHack() const { |
| 1239 if (StartsWith(path_, kExtendedPathPrefix, false) || |
| 1240 StartsWith(path_, kUNCExtendedPathPrefix, false)) { |
| 1241 return FilePath(path_); |
| 1242 } |
| 1243 |
| 1244 // Note that the 8.3 short file name can not be simply prefixed with the long |
| 1245 // path prefix. It has to be converted to long file name first. |
| 1246 if (StartsWith(path_, kSharePrefix, false)) { |
| 1247 return FilePath(kUNCExtendedPathPrefix + ToLongFileNameHack( |
| 1248 path_.substr(kSharePrefixLength))); |
| 1249 } else { |
| 1250 return FilePath(kExtendedPathPrefix + ToLongFileNameHack(path_)); |
| 1251 } |
| 1252 } |
| 1253 #endif |
OLD | NEW |