Logo Search packages:      
Sourcecode: fgrun version File versions  Download package

void AirportBrowser::airports_idle_proc (  ) [private]

Scan FlightGear Scenery directory and sub-directories for airport files. Airpots ICAO ids are saved in a cache file.

Definition at line 653 of file AirportBrowser.cxx.

References airports_dirs, airports_loaded_cb_, installed_airports_, and installed_dirs_.

{
    if (airports_dirs.empty())
    {
      Fl::remove_idle( airports_idle_proc, this );

        for (std::set<string>::iterator i = installed_dirs_.begin(); i != installed_dirs_.end(); ++i)
        {
            for (size_t j = 0; j < airports_by_tiles_[ *i ].size(); ++j)
            {
                string s = airports_by_tiles_[ *i ][ j ];
              const apt_dat_t* apt = find( airports_by_tiles_[ *i ][ j ] );
              if ( apt != 0 && ( apt->type_ == 16 || apt->type_ == 17 ) )
              {
                installed_airports_.insert( apt->id_ );
              }
            }
        }

      // Save airports ids to the cache file.
      if (!airports_cache_.str().empty())
      {
          std::ofstream ofs( airports_cache_.str().c_str() );
          if (ofs)  // !ofs.fail()
          {
            std::copy( installed_airports_.begin(),
                     installed_airports_.end(),
                     std::ostream_iterator<string>( ofs, "\n" ) );
                ofs << "--dirs--" << std::endl;
            std::copy( installed_dirs_.begin(),
                     installed_dirs_.end(),
                     std::ostream_iterator<string>( ofs, "\n" ) );
          }
      }

      airports_loaded_ = true;
      if (airports_loaded_cb_ != 0)
          airports_loaded_cb_( this, airports_loaded_cb_data_ );

      return;
    }

    string cwd( airports_dirs.front() );

    // mingw requires a trailing slash on directory names.
    if (cwd[ cwd.length() - 1 ] != '/')
      cwd.append( "/" );

    dirent** files;
    int n = fl_filename_list( cwd.c_str(), &files, fl_numericsort );
    if (n > 0)
    {
        bool dir_added = false;
      for (int i = 0; i < n; ++i)
      {
          if (fl_filename_match( files[i]->d_name,
                           "[ew][01][0-9][0-9][ns][0-9][0-9]") ||
            fl_filename_match( files[i]->d_name,
                           "[ew][01][0-9][0-9][ns][0-9][0-9]/"))
          {
            // Found a scenery sub-directory.
            string d(cwd);
            d.append( files[i]->d_name );
            if (fl_filename_isdir( d.c_str() ) )
            {
                airports_dirs.push_back( d );
            }
          }
          else if (fl_filename_match( files[i]->d_name,
                              "???.btg.gz" ) ||
                 fl_filename_match( files[i]->d_name,
                              "????.btg.gz" ))
          {
            char* p = strstr( files[i]->d_name, ".btg" );
            if (p != 0)
                *p = 0;
            installed_airports_.insert( string( files[i]->d_name ) );

                if ( !dir_added )
                {
                    string d( cwd );
                    if (d[ d.length() - 1 ] == '/')
                      d.erase( d.length() - 1 );
                    string::size_type p = d.rfind( "/" );
                    if ( p != string::npos )
                        installed_dirs_.insert( d.substr( p + 1 ) );
                    dir_added = true;
                }
          }

          free( files[i] );
      }

      free( files );
    }

    airports_dirs.pop_front();
}

Generated by  Doxygen 1.6.0   Back to index