Beispiel #1
0
//! Copies and deletes files in \a dest such that it matches the files in \a this.
bool Dir::sync( Dir &dest ) const
{
  if ( !dest.exists() )
    dest.create( mode() );
//  else
//    dest.mode( mode() );

  // Remove files in dest which aren't in src (or which have a different type)
  for ( Iterator f = dest.begin(); f != dest.end(); ++f ) {
    File s( *this, f->name() );
    if ( !s.exists() || (s.isRegularFile() != f->isRegularFile()) )
      if ( ! (f->isRegularFile() ? f->erase() : Dir(*f).erase(true)) )
        return false;
  }

  // Sync all source files/directories to dest
  for ( Iterator f = begin(); f != end(); ++f ) {
    if ( f->isDir() ) {
      Dir d( dest, f->name() );
      if ( !Dir(*f).sync(d) )
        return false;
    } else {
      File d( dest, f->name() );
      if ( !f->sync(d) )
        return false;
    }
  }

  return true;
}
Beispiel #2
0
void Mods::scan_mods_dir (const ustring& path, vector<ustring>& files) {
    logger.fineln ("searching for mods in %s", path.c_str ());
    try {
        Dir dir (path);
        for (DirIterator it = dir.begin (); it != dir.end (); it++) {
            if ((*it)[0] == '.')
                continue;
            files.push_back (path + (*it));
        }
    } catch (FileError fe) {
    }
}
Beispiel #3
0
void AudioOpenAL::scan_music_dir (const ustring& path,
        vector<MusicFile>& files, MusicType type) {
    double len;
    ustring file_path;
    MusicFile entry;

    logger.fineln ("searching %s for music files", path.c_str ());
    try {

        Dir dir (path);

        for (DirIterator it = dir.begin (); it != dir.end (); it++) {
            if ((*it)[0] == '.')
                continue;

            file_path = path + (*it);

            MplayerDecoder dec;
            len = dec.get_length (file_path);

            if (len <= 0)
                continue;
            if (type == MT_GameShort && len > 150) {
                continue;
            }
            if (type == MT_GameLong && len <= 150) {
                continue;
            }

            logger.fineln ("found music file %s", file_path.c_str ());
            entry.filename = file_path;
            entry.played = false;
            files.push_back (entry);
        }

    } catch (FileError) {
    }
}
Beispiel #4
0
/* read data directory */
bool AGG::Cache::ReadDataDir(void)
{
    const Settings & conf = Settings::Get();
    Dir dir;

    dir.Read(conf.DataDirectory(), ".agg", false);
    dir.Read(conf.LocalPrefix() + SEPARATOR + conf.DataDirectory(), ".agg", false);

    // not found agg, exit
    if(0 == dir.size()) return false;

    // attach agg files
    for(Dir::const_iterator itd = dir.begin(); itd != dir.end(); ++itd)
    {
	std::string lower = *itd;
	String::Lower(lower);
	if(std::string::npos != lower.find("heroes2.agg") && !heroes2_agg.isGood()) heroes2_agg.Open(*itd);
	if(std::string::npos != lower.find("heroes2x.agg") && !heroes2x_agg.isGood()) heroes2x_agg.Open(*itd);
    }

    if(heroes2x_agg.isGood()) Settings::Get().SetPriceLoyaltyVersion();

    return heroes2_agg.isGood();
}