Exemple #1
0
void Platform::GetFilesByRegExp(string const & directory, string const & regexp, FilesList & res)
{
  if (ZipFileReader::IsZip(directory))
  {
    // Get files list inside zip file
    typedef ZipFileReader::FileListT FilesT;
    FilesT fList;
    ZipFileReader::FilesList(directory, fList);

    regexp::RegExpT exp;
    regexp::Create(regexp, exp);

    for (FilesT::iterator it = fList.begin(); it != fList.end(); ++it)
    {
      string & name = it->first;
      if (regexp::IsExist(name, exp))
      {
        // Remove assets/ prefix - clean files are needed for fonts white/blacklisting logic
        size_t const ASSETS_LENGTH = 7;
        if (name.find("assets/") == 0)
          name.erase(0, ASSETS_LENGTH);

        res.push_back(name);
      }
    }
  }
  else
    pl::EnumerateFilesByRegExp(directory, regexp, res);
}
Exemple #2
0
void Platform::GetFilesByRegExp(string const & directory, string const & regexp, FilesList & outFiles)
{
  regex exp(regexp);

  QDir dir(QString::fromUtf8(directory.c_str()));
  int const count = dir.count();

  for (int i = 0; i < count; ++i)
  {
    string const name = dir[i].toUtf8().data();
    if (regex_search(name.begin(), name.end(), exp))
      outFiles.push_back(name);
  }
}
Exemple #3
0
void Platform::GetFilesByRegExp(string const & directory, string const & regexp, FilesList & outFiles)
{
  regexp::RegExpT exp;
  regexp::Create(regexp, exp);

  QDir dir(QString::fromUtf8(directory.c_str()));
  int const count = dir.count();

  for (int i = 0; i < count; ++i)
  {
    string const name = dir[i].toUtf8().data();
    if (regexp::IsExist(name, exp))
      outFiles.push_back(name);
  }
}
Exemple #4
0
	bool getFolderContent(shared_ptr<Path> folder)
	{
		WinDir dir(folder->path(), L"*");
		for (WinDir::iterator it = dir.begin(); it != dir.end(); ++it) {
			if (it.is_file()) {
				++Statistics::getInstance()->FoundFiles;
				Statistics::getInstance()->FoundFilesSize += it.size();
				if (SkipHidden && (it.attr() & FILE_ATTRIBUTE_HIDDEN)) {
					++Statistics::getInstance()->IgnoredHidden;
					{
						ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
						logDebug(L"File ignored [hidden]: ");
					}
					logDebug(L"\"%s\"\n", it.name());
				} else if (SkipSystem && (it.attr() & FILE_ATTRIBUTE_SYSTEM)) {
					++Statistics::getInstance()->IgnoredSystem;
					{
						ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
						logDebug(L"File ignored [system]: ");
					}
					logDebug(L"\"%s\"\n", it.name());
				} else if (it.size() == 0LL) {
					++Statistics::getInstance()->IgnoredZero;
					{
						ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
						logDebug(L"File ignored [zero]: ");
					}
					logDebug(L"\"%s\"\n", it.name());
				} else if (!LinkSmall && (it.size() < MIN_FILE_SIZE)) {
					++Statistics::getInstance()->IgnoredSmall;
					{
						ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
						logDebug(L"File ignored [small]: ");
					}
					logDebug(L"\"%s\"\n", it.name());
				} else {
					//logFile(info);
					data.push_back(shared_ptr < File > (new File(folder, it.name())));
				}
			} else {
				if (SkipJunct && it.is_link()) {
					++Statistics::getInstance()->IgnoredJunc;
					{
						ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
						logDebug(L"Dir  ignored [junction]: ");
					}
					logDebug(L"\"%s\"\n", it.name());
				} else {
					if (it.is_link())
						++Statistics::getInstance()->FoundJuncs;
					else
						++Statistics::getInstance()->FoundDirs;
//					logFile(info);
					if (recursive) {
						bool Result = getFolderContent(shared_ptr < Path > (new Path(folder, it.name())));
						if (!Result)
							return false;
					}
				}
			}
		}

//		WIN32_FIND_DATAW	info;
//		HANDLE	hFind = ::FindFirstFileW(mask.c_str(), &info);
//		if (hFind == INVALID_HANDLE_VALUE) {
//			logError(::GetLastError(), L"Unable to read folder \"%s\" content.\n", path.c_str());
//		} else {
//			do {
//				if (is_valid_filename(info.cFileName)) {
//					if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
//						uintmax_t	filesize = MyUI64(info.nFileSizeLow, info.nFileSizeHigh);
//						++Statistics::getInstance()->FoundFiles;
//						Statistics::getInstance()->FoundFilesSize += filesize;
//						if (SkipHidden && (info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) {
//							++Statistics::getInstance()->IgnoredHidden;
//							{
//								ConsoleColor	col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
//								logDebug(L"File ignored [hidden]: ");
//							}
//							logDebug(L"\"%s\"\n", info.cFileName);
//						} else if (SkipSystem && (info.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)) {
//							++Statistics::getInstance()->IgnoredSystem;
//							{
//								ConsoleColor	col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
//								logDebug(L"File ignored [system]: ");
//							}
//							logDebug(L"\"%s\"\n", info.cFileName);
//						} else if (filesize == 0LL) {
//							++Statistics::getInstance()->IgnoredZero;
//							{
//								ConsoleColor	col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
//								logDebug(L"File ignored [zero]: ");
//							}
//							logDebug(L"\"%s\"\n", info.cFileName);
//						} else if (!LinkSmall && (filesize < MIN_FILE_SIZE)) {
//							++Statistics::getInstance()->IgnoredSmall;
//							{
//								ConsoleColor	col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
//								logDebug(L"File ignored [small]: ");
//							}
//							logDebug(L"\"%s\"\n", info.cFileName);
//						} else {
//							logFile(info);
//							data.push_back(shared_ptr<File>(new File(folder, info.cFileName)));
//						}
//					} else {
//						if (SkipJunct && info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
//							++Statistics::getInstance()->IgnoredJunc;
//							{
//								ConsoleColor	col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
//								logDebug(L"Dir  ignored [junction]: ");
//							}
//							logDebug(L"\"%s\"\n", info.cFileName);
//						} else {
//							if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
//								++Statistics::getInstance()->FoundJuncs;
//							else
//								++Statistics::getInstance()->FoundDirs;
//							logFile(info);
//							if (recursive) {
//								bool	Result = getFolderContent(shared_ptr<Path>(new Path(folder, info.cFileName)));
//								if (!Result)
//									return	false;
//							}
//						}
//					}
//				}
//			} while (::FindNextFile(hFind, &info) != 0);
//			dwError = ::GetLastError();
//			::FindClose(hFind);
//			if (dwError != ERROR_NO_MORE_FILES) {
//				logError(dwError, L"FindNextFile error\n");
//				return	false;
//			}
//		}
		return true;
	}
Exemple #5
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
}