string Platform::UniqueClientId() const { string machineFile = "/var/lib/dbus/machine-id"; if (IsFileExistsByFullPath("/etc/machine-id")) machineFile = "/etc/machine-id"; if (IsFileExistsByFullPath(machineFile)) { string content; FileReader(machineFile).ReadAsString(content); return content.substr(0, 32); } return "n0dbus0n0lsb00000000000000000000"; }
ModelReader * Platform::GetReader(string const & file, string const & searchScope) const { string const ext = my::GetFileExtension(file); ASSERT(!ext.empty(), ()); uint32_t const logPageSize = (ext == DATA_FILE_EXTENSION) ? READER_CHUNK_LOG_SIZE : 10; uint32_t const logPageCount = (ext == DATA_FILE_EXTENSION) ? READER_CHUNK_LOG_COUNT : 4; SourceT sources[SOURCE_COUNT]; size_t n = 0; if (searchScope.empty()) { // Default behaviour - use predefined scope for resource files and writable path for all others. if (IsResource(file, ext)) n = GetSearchSources(file, m_androidDefResScope, sources); else { // Add source for map files and other dynamic stored data. sources[n++] = WRITABLE_PATH; sources[n++] = FULL_PATH; } } else { // Use passed scope as client wishes. n = GetSearchSources(file, searchScope, sources); } #ifdef DEBUG DbgLogger logger(file); #endif for (size_t i = 0; i < n; ++i) { #ifdef DEBUG logger.SetSource(sources[i]); #endif switch (sources[i]) { case EXTERNAL_RESOURCE: for (size_t j = 0; j < m_extResFiles.size(); ++j) { try { return new ZipFileReader(m_extResFiles[j], file, logPageSize, logPageCount); } catch (Reader::OpenException const &) { } } break; case WRITABLE_PATH: { string const path = m_writableDir + file; if (IsFileExistsByFullPath(path)) return new FileReader(path, logPageSize, logPageCount); break; } case SETTINGS_PATH: { string const path = m_settingsDir + file; if (IsFileExistsByFullPath(path)) return new FileReader(path, logPageSize, logPageCount); break; } case FULL_PATH: if (IsFileExistsByFullPath(file)) return new FileReader(file, logPageSize, logPageCount); break; case RESOURCE: ASSERT_EQUAL(file.find("assets/"), string::npos, ()); try { return new ZipFileReader(m_resourcesDir, "assets/" + file, logPageSize, logPageCount); } catch (Reader::OpenException const &) { } break; default: CHECK(false, ("Unsupported source:", sources[i])); break; } } LOG(LWARNING, ("Can't get reader for:", file)); MYTHROW(FileAbsentException, ("File not found", file)); return 0; }
void Platform::GetSystemFontNames(FilesList & res) const { #if defined(OMIM_OS_MAC) || defined(OMIM_OS_IPHONE) #else char const * fontsWhitelist[] = { "Roboto-Medium.ttf", "DroidSansFallback.ttf", "DroidSansFallbackFull.ttf", "DroidSans.ttf", "DroidSansArabic.ttf", "DroidSansSemc.ttf", "DroidSansSemcCJK.ttf", "DroidNaskh-Regular.ttf", "Lohit-Bengali.ttf", "Lohit-Devanagari.ttf", "Lohit-Tamil.ttf", "PakType Naqsh.ttf", "wqy-microhei.ttc", "Jomolhari.ttf", "Jomolhari-alpha3c-0605331.ttf", "Padauk.ttf", "KhmerOS.ttf", "Umpush.ttf", "DroidSansThai.ttf", "DroidSansArmenian.ttf", "DroidSansEthiopic-Regular.ttf", "DroidSansGeorgian.ttf", "DroidSansHebrew-Regular.ttf", "DroidSansHebrew.ttf", "DroidSansJapanese.ttf", "LTe50872.ttf", "LTe50259.ttf", "DevanagariOTS.ttf", "FreeSans.ttf", "DejaVuSans.ttf", "arial.ttf", "AbyssinicaSIL-R.ttf", }; char const * systemFontsPath[] = { "/system/fonts/", #ifdef OMIM_OS_LINUX "/usr/share/fonts/truetype/roboto/", "/usr/share/fonts/truetype/droid/", "/usr/share/fonts/truetype/ttf-dejavu/", "/usr/share/fonts/truetype/wqy/", "/usr/share/fonts/truetype/freefont/", "/usr/share/fonts/truetype/padauk/", "/usr/share/fonts/truetype/dzongkha/", "/usr/share/fonts/truetype/ttf-khmeros-core/", "/usr/share/fonts/truetype/tlwg/", "/usr/share/fonts/truetype/abyssinica/", "/usr/share/fonts/truetype/paktype/", "/usr/share/fonts/truetype/mapsme/", #endif }; const uint64_t fontSizeBlacklist[] = { 183560, // Samsung Duos DroidSans 7140172, // Serif font without Emoji 14416824 // Serif font with Emoji }; uint64_t fileSize = 0; for (size_t i = 0; i < ARRAY_SIZE(fontsWhitelist); ++i) { for (size_t j = 0; j < ARRAY_SIZE(systemFontsPath); ++j) { string const path = string(systemFontsPath[j]) + fontsWhitelist[i]; if (IsFileExistsByFullPath(path)) { if (GetFileSizeByName(path, fileSize)) { uint64_t const * end = fontSizeBlacklist + ARRAY_SIZE(fontSizeBlacklist); if (find(fontSizeBlacklist, end, fileSize) == end) { res.push_back(path); LOG(LINFO, ("Found usable system font", path, "with file size", fileSize)); } } } } } #endif }
Platform::Platform() { // Init directories. string path; CHECK(GetBinaryDir(path), ("Can't retrieve path to executable")); char const * homePath = ::getenv("HOME"); string const home(homePath ? homePath : ""); m_settingsDir = my::JoinFoldersToPath({home, ".config"}, "MapsWithMe"); if (!IsFileExistsByFullPath(my::JoinFoldersToPath(m_settingsDir, SETTINGS_FILE_NAME))) { MkDir(my::JoinFoldersToPath(home, ".config")); MkDir(m_settingsDir.c_str()); } m_writableDir = my::JoinFoldersToPath({home, ".local", "share"}, "MapsWithMe"); MkDir(my::JoinFoldersToPath(home, ".local")); MkDir(my::JoinFoldersToPath({home, ".local"}, "share")); MkDir(m_writableDir); char const * resDir = ::getenv("MWM_RESOURCES_DIR"); if (resDir) { m_resourcesDir = resDir; } else { string const devBuildWithSymlink = my::JoinFoldersToPath({path, "..", ".."}, "data"); string const devBuildWithoutSymlink = my::JoinFoldersToPath({path, "..", "..", "..", "omim"}, "data"); string const installedVersionWithPackages = my::JoinFoldersToPath({path, ".."}, "share"); string const installedVersionWithoutPackages = my::JoinFoldersToPath({path, ".."}, "MapsWithMe"); string const customInstall = path; if (IsEulaExist(devBuildWithSymlink)) { m_resourcesDir = devBuildWithSymlink; m_writableDir = m_resourcesDir; } else if (IsEulaExist(devBuildWithoutSymlink)) { m_resourcesDir = devBuildWithoutSymlink; m_writableDir = m_resourcesDir; } else if (IsEulaExist(installedVersionWithPackages)) { m_resourcesDir = installedVersionWithPackages; } else if (IsEulaExist(installedVersionWithoutPackages)) { m_resourcesDir = installedVersionWithoutPackages; } else if (IsEulaExist(customInstall)) { m_resourcesDir = path; } } m_resourcesDir += '/'; m_settingsDir += '/'; m_writableDir += '/'; char const * tmpDir = ::getenv("TMPDIR"); if (tmpDir) m_tmpDir = tmpDir; else m_tmpDir = "/tmp"; m_tmpDir += '/'; LOG(LDEBUG, ("Resources directory:", m_resourcesDir)); LOG(LDEBUG, ("Writable directory:", m_writableDir)); LOG(LDEBUG, ("Tmp directory:", m_tmpDir)); LOG(LDEBUG, ("Settings directory:", m_settingsDir)); LOG(LDEBUG, ("Client ID:", UniqueClientId())); }