OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_BASE_PATHUTILS_H__ | 11 #ifndef WEBRTC_BASE_PATHUTILS_H__ |
12 #define WEBRTC_BASE_PATHUTILS_H__ | 12 #define WEBRTC_BASE_PATHUTILS_H__ |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 // Temporary, until deprecated helpers are removed. | 15 |
16 #include "webrtc/base/fileutils.h" | 16 #include "webrtc/base/checks.h" |
17 | 17 |
18 namespace rtc { | 18 namespace rtc { |
19 | 19 |
20 /////////////////////////////////////////////////////////////////////////////// | 20 /////////////////////////////////////////////////////////////////////////////// |
21 // Pathname - parsing of pathnames into components, and vice versa. | 21 // Pathname - parsing of pathnames into components, and vice versa. |
22 // | 22 // |
23 // To establish consistent terminology, a filename never contains a folder | 23 // To establish consistent terminology, a filename never contains a folder |
24 // component. A folder never contains a filename. A pathname may include | 24 // component. A folder never contains a filename. A pathname may include |
25 // a folder and/or filename component. Here are some examples: | 25 // a folder and/or filename component. Here are some examples: |
26 // | 26 // |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 static bool GetDrive(char* drive, | 101 static bool GetDrive(char* drive, |
102 uint32_t bytes, | 102 uint32_t bytes, |
103 const std::string& pathname); | 103 const std::string& pathname); |
104 #endif | 104 #endif |
105 | 105 |
106 private: | 106 private: |
107 std::string folder_, basename_, extension_; | 107 std::string folder_, basename_, extension_; |
108 char folder_delimiter_; | 108 char folder_delimiter_; |
109 }; | 109 }; |
110 | 110 |
111 /////////////////////////////////////////////////////////////////////////////// | |
112 // Global Helpers (deprecated) | |
113 /////////////////////////////////////////////////////////////////////////////// | |
114 | |
115 inline void SetOrganizationName(const std::string& organization) { | |
116 Filesystem::SetOrganizationName(organization); | |
117 } | |
118 inline void SetApplicationName(const std::string& application) { | |
119 Filesystem::SetApplicationName(application); | |
120 } | |
121 inline void GetOrganizationName(std::string* organization) { | |
122 Filesystem::GetOrganizationName(organization); | |
123 } | |
124 inline void GetApplicationName(std::string* application) { | |
125 Filesystem::GetApplicationName(application); | |
126 } | |
127 inline bool CreateFolder(const Pathname& path) { | |
128 return Filesystem::CreateFolder(path); | |
129 } | |
130 inline bool FinishPath(Pathname& path, bool create, const std::string& append) { | |
131 if (!append.empty()) | |
132 path.AppendFolder(append); | |
133 return !create || CreateFolder(path); | |
134 } | |
135 // Note: this method uses the convention of <temp>/<appname> for the temporary | |
136 // folder. Filesystem uses <temp>/<exename>. We will be migrating exclusively | |
137 // to <temp>/<orgname>/<appname> eventually. Since these are temp folders, | |
138 // it's probably ok to orphan them during the transition. | |
139 inline bool GetTemporaryFolder(Pathname& path, bool create, | |
140 const std::string& append) { | |
141 std::string application_name; | |
142 Filesystem::GetApplicationName(&application_name); | |
143 ASSERT(!application_name.empty()); | |
144 return Filesystem::GetTemporaryFolder(path, create, &application_name) | |
145 && FinishPath(path, create, append); | |
146 } | |
147 inline bool GetAppDataFolder(Pathname& path, bool create, | |
148 const std::string& append) { | |
149 ASSERT(!create); // TODO: Support create flag on Filesystem::GetAppDataFolder. | |
150 return Filesystem::GetAppDataFolder(&path, true) | |
151 && FinishPath(path, create, append); | |
152 } | |
153 inline bool CleanupTemporaryFolder() { | |
154 Pathname path; | |
155 if (!GetTemporaryFolder(path, false, "")) | |
156 return false; | |
157 if (Filesystem::IsAbsent(path)) | |
158 return true; | |
159 if (!Filesystem::IsTemporaryPath(path)) { | |
160 ASSERT(false); | |
161 return false; | |
162 } | |
163 return Filesystem::DeleteFolderContents(path); | |
164 } | |
165 | |
166 /////////////////////////////////////////////////////////////////////////////// | |
167 | |
168 } // namespace rtc | 111 } // namespace rtc |
169 | 112 |
170 #endif // WEBRTC_BASE_PATHUTILS_H__ | 113 #endif // WEBRTC_BASE_PATHUTILS_H__ |
OLD | NEW |