Esempio n. 1
0
		void ResourceLoader::handleDirectoryChanged (const QString& path)
		{
			emit watchedDirectoriesChanged ();

			for (auto i = Entry2Paths_.begin (), end = Entry2Paths_.end (); i != end; ++i)
				i->removeAll (path);

			QFileInfo fi (path);
			if (fi.exists () &&
					fi.isDir () &&
					fi.isReadable ())
				ScanPath (path);

			QStringList toRemove;
			for (auto i = Entry2Paths_.begin (), end = Entry2Paths_.end (); i != end; ++i)
				if (i->isEmpty ())
					toRemove << i.key ();

			for (const auto& entry : toRemove)
			{
				Entry2Paths_.remove (entry);

				auto items = SubElemModel_->findItems (entry);
				for (auto item : SubElemModel_->findItems (entry))
					SubElemModel_->removeRow (item->row ());
			}
		}
/**
 * Scan for files with the given extention in the given search path.
 * @param extension the extension of files to search for.
 * @param directory the sub directory to search in.
 * @param recursive whether to search recursively
 * @return the number of found files, i.e. the number of times that
 *         AddFile returned true.
 */
uint FileScanner::Scan(const char *extension, const char *directory, bool recursive)
{
	char path[MAX_PATH];
	strecpy(path, directory, lastof(path));
	if (!AppendPathSeparator(path, lengthof(path))) return 0;
	return ScanPath(this, extension, path, strlen(path), recursive);
}
Esempio n. 3
0
void CFX_FolderFontInfo::ScanPath(CFX_ByteString& path)
{
    void* handle = FX_OpenFolder(path);
    if (handle == NULL) {
        return;
    }
    CFX_ByteString filename;
    FX_BOOL bFolder;
    while (FX_GetNextFile(handle, filename, bFolder)) {
        if (bFolder) {
            if (filename == "." || filename == "..") {
                continue;
            }
        } else {
            CFX_ByteString ext = filename.Right(4);
            ext.MakeUpper();
            if (ext != ".TTF" && ext != ".OTF" && ext != ".TTC") {
                continue;
            }
        }
        CFX_ByteString fullpath = path;
#if _FXM_PLATFORM_  == _FXM_PLATFORM_WINDOWS_
        fullpath += "\\";
#else
        fullpath += "/";
#endif
        fullpath += filename;
        if (bFolder) {
            ScanPath(fullpath);
        } else {
            ScanFile(fullpath);
        }
    }
    FX_CloseFolder(handle);
}
void CFPF_SkiaFontMgr::ScanPath(FX_BSTR path)
{
    void *handle = FX_OpenFolder(path.GetCStr());
    if (!handle) {
        return;
    }
    CFX_ByteString filename;
    FX_BOOL	bFolder = FALSE;
    while (FX_GetNextFile(handle, filename, bFolder)) {
        if (bFolder) {
            if (filename == FX_BSTRC(".") || filename == FX_BSTRC("..")) {
                continue;
            }
        } else {
            CFX_ByteString ext = filename.Right(4);
            ext.MakeLower();
            if (ext != FX_BSTRC(".ttf") && ext != FX_BSTRC(".ttc")) {
                continue;
            }
        }
        CFX_ByteString fullpath = path;
        fullpath += "/";
        fullpath += filename;
        if (bFolder) {
            ScanPath(fullpath);
        } else {
            ScanFile(fullpath);
        }
    }
    FX_CloseFolder(handle);
}
Esempio n. 5
0
FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper)
{
    m_pMapper = pMapper;
    for (int i = 0; i < m_PathList.GetSize(); i ++) {
        ScanPath(m_PathList[i]);
    }
    return TRUE;
}
Esempio n. 6
0
void CFPF_SkiaFontMgr::LoadSystemFonts() {
  if (m_bLoaded) {
    return;
  }
  ScanPath("/system/fonts");
  OutputSystemFonts();
  m_bLoaded = TRUE;
}
/**
 * Scan a single directory (and recursively its children) and add
 * any graphics sets that are found.
 * @param fs              the file scanner to add the files to
 * @param extension       the extension of files to search for.
 * @param path            full path we're currently at
 * @param basepath_length from where in the path are we 'based' on the search path
 * @param recursive       whether to recursively search the sub directories
 */
static uint ScanPath(FileScanner *fs, const char *extension, const char *path, size_t basepath_length, bool recursive)
{
	extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);

	uint num = 0;
	struct stat sb;
	struct dirent *dirent;
	DIR *dir;

	if (path == NULL || (dir = ttd_opendir(path)) == NULL) return 0;

	while ((dirent = readdir(dir)) != NULL) {
		const char *d_name = FS2OTTD(dirent->d_name);
		char filename[MAX_PATH];

		if (!FiosIsValidFile(path, dirent, &sb)) continue;

		snprintf(filename, lengthof(filename), "%s%s", path, d_name);

		if (S_ISDIR(sb.st_mode)) {
			/* Directory */
			if (!recursive) continue;
			if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue;
			if (!AppendPathSeparator(filename, lengthof(filename))) continue;
			num += ScanPath(fs, extension, filename, basepath_length, recursive);
		} else if (S_ISREG(sb.st_mode)) {
			/* File */
			if (extension != NULL) {
				char *ext = strrchr(filename, '.');

				/* If no extension or extension isn't .grf, skip the file */
				if (ext == NULL) continue;
				if (strcasecmp(ext, extension) != 0) continue;
			}

			if (fs->AddFile(filename, basepath_length)) num++;
		}
	}

	closedir(dir);

	return num;
}
Esempio n. 8
0
/**
 * Scan for files with the given extention in the given search path.
 * @param extension the extension of files to search for.
 * @param sd        the sub directory to search in.
 * @param tars      whether to search in the tars too.
 * @param recursive whether to search recursively
 * @return the number of found files, i.e. the number of times that
 *         AddFile returned true.
 */
uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars, bool recursive)
{
	Searchpath sp;
	char path[MAX_PATH];
	TarFileList::iterator tar;
	uint num = 0;

	FOR_ALL_SEARCHPATHS(sp) {
		FioAppendDirectory(path, MAX_PATH, sp, sd);
		num += ScanPath(this, extension, path, strlen(path), recursive);
	}

	if (tars) {
		FOR_ALL_TARS(tar) {
			num += ScanTar(this, extension, tar);
		}
	}

	return num;
}
/**
 * Scan for files with the given extention in the given search path.
 * @param extension the extension of files to search for.
 * @param sd        the sub directory to search in.
 * @param tars      whether to search in the tars too.
 * @param recursive whether to search recursively
 * @return the number of found files, i.e. the number of times that
 *         AddFile returned true.
 */
uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars, bool recursive)
{
	Searchpath sp;
	char path[MAX_PATH];
	TarFileList::iterator tar;
	uint num = 0;

	FOR_ALL_SEARCHPATHS(sp) {
		/* Don't search in the working directory */
		if (sp == SP_WORKING_DIR && !_do_scan_working_directory) continue;

		FioAppendDirectory(path, MAX_PATH, sp, sd);
		num += ScanPath(this, extension, path, strlen(path), recursive);
	}

	if (tars) {
		FOR_ALL_TARS(tar) {
			num += ScanTar(this, extension, tar);
		}
	}

	return num;
}