diff --git a/defines.hpp b/defines.hpp index 2d61c60a48..9a3bdda103 100644 --- a/defines.hpp +++ b/defines.hpp @@ -21,13 +21,13 @@ #define PACKED_POLYGONS_FILE "packed_polygons.bin" #define PACKED_POLYGONS_INFO_TAG "info" -#define DEFAULT_AUTO_UPDATES_ENABLED true - /// How many langs we're supporting on indexing stage #define MAX_SUPPORTED_LANGUAGES 64 #ifdef OMIM_PRODUCTION - #error "Please define production server url" + #define URL_SERVERS_LIST "http://mapswithme-metaserver.appspot.com/server_data/active_servers" + #define DEFAULT_SERVERS_JSON "[\"http://1st.default.server/\",\"http://2nd.default.server/\"]" #else - #define URL_SERVERS_LIST "http://melnichek.ath.cx:34568/download.php" + #define URL_SERVERS_LIST "http://mwm-dev.appspot.com/server_data/active_servers" + #define DEFAULT_SERVERS_JSON "[\"http://svobodu404popugajam.mapswithme.com:34568/maps/\",\"http://svobodu404popugajam.mapswithme.com:34568/maps/\"]" #endif diff --git a/storage/storage.cpp b/storage/storage.cpp index 865c5b35cb..f0d8c737e2 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -8,6 +8,7 @@ #include "../indexer/data_factory.hpp" #include "../platform/platform.hpp" +#include "../platform/settings.hpp" #include "../coding/file_writer.hpp" #include "../coding/file_reader.hpp" @@ -23,7 +24,7 @@ #include "../3party/jansson/myjansson.hpp" -#define SERVER_LIST_FILE "servers.txt" +#define SETTINGS_SERVERS_KEY "LastBaseUrls" using namespace downloader; @@ -64,11 +65,6 @@ namespace storage m_updateRect = updateRectFunc; } - string Storage::UpdateBaseUrl() const - { - return "http://svobodu404popugajam.mapswithme.com:34568/maps/" OMIM_OS_NAME "/" + strings::to_string(m_currentVersion) + "/"; - } - CountriesContainerT const & NodeFromIndex(CountriesContainerT const & root, TIndex const & index) { // complex logic to avoid [] out_of_bounds exceptions @@ -182,16 +178,6 @@ namespace storage } }; - static string CreateServersListRequest(string const & id, uint32_t version, - string const & file, uint32_t fileSize) - { - ostringstream stream; - stream << "{\"ID\":\"" << id << "\",\"Cmd\":\"Download\",\"Params\":{"; - stream << "\"Version\":" << version << ",\"File\":\"" << file << "\","; - stream << "\"Size\":" << fileSize << "}}"; - return stream.str(); - } - void Storage::DownloadNextCountryFromQueue() { while (!m_queue.empty()) @@ -202,10 +188,8 @@ namespace storage { if (!IsFileDownloaded(*it)) { - string const postBody = CreateServersListRequest(GetPlatform().UniqueClientId(), - m_currentVersion, - it->GetFileWithExt(), - it->m_remoteSize); + // send Country name for statistics + string const postBody = it->m_fileName; m_request.reset(HttpRequest::PostJson(URL_SERVERS_LIST, postBody, bind(&Storage::OnServerListDownloaded, this, _1))); @@ -386,37 +370,17 @@ namespace storage } } - static void SaveDefaultServerList(string data) - { - FileWriter f(GetPlatform().WritablePathForFile(SERVER_LIST_FILE)); - f.Write(data.data(), data.size()); - } - - static void LoadDefaultServerList(string & data) - { - try - { - ReaderPtr r = GetPlatform().GetReader(SERVER_LIST_FILE); - r.ReadAsString(data); - } - catch (std::exception const & e) - { - LOG(LERROR, ("Can't load default server list file", e.what())); - } - } - - static bool ParseServerList(string const & jsonStr, string const & file, vector & outUrls) + static bool ParseServerList(string const & jsonStr, vector & outUrls) { outUrls.clear(); try { my::Json root(jsonStr.c_str()); - json_t * urlsArray = json_object_get(root, "Urls"); - for (size_t i = 0; i < json_array_size(urlsArray); ++i) + for (size_t i = 0; i < json_array_size(root); ++i) { - char const * url = json_string_value(json_array_get(urlsArray, i)); + char const * url = json_string_value(json_array_get(root, i)); if (url) - outUrls.push_back(url + file); + outUrls.push_back(url); } } catch (std::exception const & e) @@ -439,15 +403,21 @@ namespace storage vector urls; if (request.Status() == HttpRequest::ECompleted - && ParseServerList(request.Data(), file.GetFileWithExt(), urls)) - SaveDefaultServerList(request.Data()); + && ParseServerList(request.Data(), urls)) + Settings::Set(SETTINGS_SERVERS_KEY, request.Data()); else { string serverList; - LoadDefaultServerList(serverList); - ParseServerList(request.Data(), file.GetFileWithExt(), urls); + if (!Settings::Get(SETTINGS_SERVERS_KEY, serverList)) + serverList = DEFAULT_SERVERS_JSON; + VERIFY(ParseServerList(request.Data(), urls), ()); } + // append actual version and file name + for (size_t i = 0; i < urls.size(); ++i) + urls[i] = urls[i] + OMIM_OS_NAME "/" + + strings::to_string(m_currentVersion) + "/" + file.GetFileWithExt(); + m_request.reset(HttpRequest::GetFile(urls, GetPlatform().WritablePathForFile(file.GetFileWithExt()), file.m_remoteSize, diff --git a/storage/storage.hpp b/storage/storage.hpp index b3a0d1b471..d2f8b9df09 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -93,7 +93,6 @@ namespace storage void DownloadNextCountryFromQueue(); Country const & CountryByIndex(TIndex const & index) const; - string UpdateBaseUrl() const; public: Storage() {}