Пример #1
0
void QuickSaves::delete_surplus_saves(size_t max_saves)
{
    if (max_saves < 1)
        return;     // unlimited saves, no need to prune
    clear();
    
    // Check the directory to count the saves. If there
    // are fewer than the max, no need to go further.
    vector<dir_entry> entries;
    DirectorySpecifier path;
    path.SetToQuickSavesDir();
    if (path.ReadDirectory(entries)) {
        if (entries.size() <= max_saves)
            return;
    }
    
    // We might have too many unnamed saves; load and
    // count them, deleting any extras.
    enumerate();
    size_t unnamed_saves = 0;
    for (std::vector<QuickSave>::iterator it = begin(); it != end(); ++it) {
        if (it->name.length())
            continue;
        if (++unnamed_saves > max_saves)
            delete_quick_save(*it);
    }
    clear();
}
Пример #2
0
static bool _ParseMMLDirectory(DirectorySpecifier& dir)
{
	// Get sorted list of files in directory
	vector<dir_entry> de;
	if (!dir.ReadDirectory(de))
		return false;
	sort(de.begin(), de.end());
	
	// Parse each file
	vector<dir_entry>::const_iterator i, end = de.end();
	for (i=de.begin(); i!=end; i++) {
		if (i->is_directory)
			continue;
		if (i->name[i->name.length() - 1] == '~')
			continue;
		// people stick Lua scripts in Scripts/
		if (boost::algorithm::ends_with(i->name, ".lua"))
			continue;
		
		// Construct full path name
		FileSpecifier file_name = dir + i->name;
		
		// Parse file
		ParseMMLFromFile(file_name);
	}
	
	return true;
}
bool FileFinder::Find(DirectorySpecifier &dir, Typecode type, bool recursive)
{
	// Get list of entries in directory
	vector<dir_entry> entries;
	if (!dir.ReadDirectory(entries))
		return false;
	sort(entries.begin(), entries.end());

	// Iterate through entries
	vector<dir_entry>::const_iterator i, end = entries.end();
	for (i = entries.begin(); i != end; i++) {

		// Construct full specifier of file/dir
		FileSpecifier file = dir + i->name;

		if (i->is_directory) {

			// Recurse into directory
			if (recursive)
				if (Find(file, type, recursive))
					return true;

		} else {

			// Check file type and call found() function
			if (type == WILDCARD_TYPE || type == file.GetType())
				if (found(file))
					return true;
		}
	}
	return false;
}
Пример #4
0
bool FileFinder::Find(DirectorySpecifier &dir, Typecode type, bool recursive)
{
  // Get list of entries in directory
  vector<dir_entry> entries;
  if (!dir.ReadDirectory(entries)) {
    return false;
  }
  sort(entries.begin(), entries.end());

  // Iterate through entries
  vector<dir_entry>::const_iterator i, end = entries.end();
  for (i = entries.begin(); i != end; i++) {
    // Construct full specifier of file/dir
    FileSpecifier file = dir + i->name;

    // DJB Skip our texture directories
    if ( dir.GetPathString().find ( "SpriteTextures" ) != string::npos
        || dir.GetPathString().find ( "TTEP" ) != string::npos ) {
      // Don't go down these paths
      return false;
    }
    
    if (i->is_directory) {
      // Recurse into directory
      if (recursive) {
        if (Find(file, type, recursive)) {
          return true;
        }
      }
    }
    else {
      // Check file type and call found() function
      if (type == WILDCARD_TYPE || type == file.GetType()) {
        if (found(file)) {
          return true;
        }
      }
    }
  }
  return false;
}