| 178 | } |
| 179 | |
| 180 | static PlaylistFileContents |
| 181 | LoadPlaylistFile(Path path_fs) |
| 182 | try { |
| 183 | PlaylistFileContents contents; |
| 184 | |
| 185 | assert(!path_fs.IsNull()); |
| 186 | |
| 187 | FileLineReader file{path_fs}; |
| 188 | |
| 189 | char *s; |
| 190 | while ((s = file.ReadLine()) != nullptr) { |
| 191 | if (*s == 0 || *s == PLAYLIST_COMMENT) |
| 192 | continue; |
| 193 | |
| 194 | #ifdef _UNICODE |
| 195 | /* on Windows, playlists always contain UTF-8, because |
| 196 | its "narrow" charset (i.e. CP_ACP) is incapable of |
| 197 | storing all Unicode paths */ |
| 198 | const auto path = AllocatedPath::FromUTF8(s); |
| 199 | if (path.IsNull()) |
| 200 | continue; |
| 201 | #else |
| 202 | const Path path = Path::FromFS(s); |
| 203 | #endif |
| 204 | |
| 205 | std::string uri_utf8; |
| 206 | |
| 207 | if (!uri_has_scheme(s)) { |
| 208 | #ifdef ENABLE_DATABASE |
| 209 | uri_utf8 = map_fs_to_utf8(path); |
| 210 | if (uri_utf8.empty()) { |
| 211 | if (path.IsAbsolute()) { |
| 212 | uri_utf8 = path.ToUTF8(); |
| 213 | if (uri_utf8.empty()) |
| 214 | continue; |
| 215 | } else |
| 216 | continue; |
| 217 | } |
| 218 | #else |
| 219 | continue; |
| 220 | #endif |
| 221 | } else { |
| 222 | uri_utf8 = path.ToUTF8(); |
| 223 | if (uri_utf8.empty()) |
| 224 | continue; |
| 225 | } |
| 226 | |
| 227 | contents.emplace_back(std::move(uri_utf8)); |
| 228 | if (contents.size() >= playlist_max_length) |
| 229 | break; |
| 230 | } |
| 231 | |
| 232 | return contents; |
| 233 | } catch (const std::system_error &e) { |
| 234 | if (IsFileNotFound(e)) |
| 235 | throw PlaylistError::NoSuchList(); |
| 236 | throw; |
| 237 | } |
no test coverage detected