| 196 | } // namespace |
| 197 | |
| 198 | bool BuildPostcodePointsWithInfoGetter(std::string const & path, storage::CountryId const & country, |
| 199 | PostcodePointsDatasetType type, std::string const & datasetPath, |
| 200 | bool forceRebuild, storage::CountryInfoGetter const & infoGetter) |
| 201 | { |
| 202 | auto const filename = base::JoinPath(path, country + DATA_FILE_EXTENSION); |
| 203 | Platform & platform = GetPlatform(); |
| 204 | FilesContainerR readContainer(platform.GetReader(filename, "f")); |
| 205 | if (readContainer.IsExist(POSTCODE_POINTS_FILE_TAG) && !forceRebuild) |
| 206 | return true; |
| 207 | |
| 208 | auto const postcodesFilePath = filename + "." + POSTCODE_POINTS_FILE_TAG EXTENSION_TMP; |
| 209 | // Temporary file used to reverse trie part of postcodes section. |
| 210 | auto const trieTmpFilePath = filename + "." + POSTCODE_POINTS_FILE_TAG + "_trie" + EXTENSION_TMP; |
| 211 | SCOPE_GUARD(postcodesFileGuard, std::bind(&FileWriter::DeleteFileX, postcodesFilePath)); |
| 212 | SCOPE_GUARD(trieTmpFileGuard, std::bind(&FileWriter::DeleteFileX, trieTmpFilePath)); |
| 213 | |
| 214 | try |
| 215 | { |
| 216 | FileWriter writer(postcodesFilePath); |
| 217 | if (!BuildPostcodePointsImpl(readContainer, storage::CountryId(country), type, datasetPath, trieTmpFilePath, |
| 218 | infoGetter, writer)) |
| 219 | { |
| 220 | // No postcodes for country. |
| 221 | return true; |
| 222 | } |
| 223 | |
| 224 | LOG(LINFO, ("Postcodes section size =", writer.Size())); |
| 225 | FilesContainerW writeContainer(readContainer.GetFileName(), FileWriter::OP_WRITE_EXISTING); |
| 226 | writeContainer.Write(postcodesFilePath, POSTCODE_POINTS_FILE_TAG); |
| 227 | } |
| 228 | catch (Reader::Exception const & e) |
| 229 | { |
| 230 | LOG(LERROR, ("Error while reading file:", e.Msg())); |
| 231 | return false; |
| 232 | } |
| 233 | catch (Writer::Exception const & e) |
| 234 | { |
| 235 | LOG(LERROR, ("Error writing file:", e.Msg())); |
| 236 | return false; |
| 237 | } |
| 238 | |
| 239 | return true; |
| 240 | } |
| 241 | |
| 242 | bool BuildPostcodePoints(std::string const & path, storage::CountryId const & country, PostcodePointsDatasetType type, |
| 243 | std::string const & datasetPath, bool forceRebuild) |