Пример #1
0
/**
 * \brief Load the configuration.
 */
void bf::path_configuration::load()
{
    if ( create_config_file() )
    {
        const std::string path( get_config_directory() + s_config_file_name );
        std::ifstream f( path.c_str() );

        if (f)
        {
            claw::configuration_file config(f);

            claw::configuration_file::const_file_iterator it_file;
            for ( it_file = config.file_begin();
                    it_file != config.file_end(); ++it_file )
            {
                m_workspaces[*it_file].clear();

                claw::configuration_file::const_field_iterator it;

                for ( it = config.field_begin(*it_file, s_items_directory_field);
                        it != config.field_end(*it_file, s_items_directory_field);
                        ++it)
                    m_workspaces[*it_file].add_item_class_path( *it );

                for ( it = config.field_begin(*it_file, s_data_directory_field);
                        it != config.field_end(*it_file, s_data_directory_field);
                        ++it)
                    m_workspaces[*it_file].add_data_path( *it );
            }
        }
    }
} // path_configuration::load()
Пример #2
0
/**
 * \brief Create the directory containing the configuration file, if it does not
 *        exists.
 * \return true if the directory already exists or if it has been created.
 */
bool bf::path_configuration::create_config_directory() const
{
    bool result = false;

    boost::filesystem::path path( get_config_directory() );

    if ( boost::filesystem::exists( path ) )
        result = boost::filesystem::is_directory( path );
    else
        result = boost::filesystem::create_directory( path );

    return result;
} // path_configuration::create_config_directory()
Пример #3
0
Файл: main.c Проект: analani/tg
void running_for_first_time (void) {
  check_type_sizes ();
  if (config_filename) {
    return; // Do not create custom config file
  }
  tasprintf (&config_filename, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, CONFIG_FILE);
  config_filename = make_full_path (config_filename);

  int config_file_fd;
  char *config_directory = get_config_directory ();
  //char *downloads_directory = get_downloads_directory ();

  if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
    if (!disable_output) {
      printf ("[%s] created\n", config_directory);
    }
  }

  tfree_str (config_directory);
  config_directory = NULL;
  // see if config file is there
  if (access (config_filename, R_OK) != 0) {
    // config file missing, so touch it
    config_file_fd = open (config_filename, O_CREAT | O_RDWR, 0600);
    if (config_file_fd == -1)  {
      perror ("open[config_file]");
      exit (EXIT_FAILURE);
    }
    if (write (config_file_fd, DEFAULT_CONFIG_CONTENTS, strlen (DEFAULT_CONFIG_CONTENTS)) <= 0) {
      perror ("write[config_file]");
      exit (EXIT_FAILURE);
    }
    close (config_file_fd);
    /*int auth_file_fd = open (get_auth_key_filename (), O_CREAT | O_RDWR, 0600);
    int x = -1;
    assert (write (auth_file_fd, &x, 4) == 4);
    close (auth_file_fd);

    printf ("[%s] created\n", config_filename);*/
  
    /* create downloads directory */
    /*if (mkdir (downloads_directory, 0755) !=0) {
      perror ("creating download directory");
      exit (EXIT_FAILURE);
    }*/
  }
}
Пример #4
0
void running_for_first_time (void) {
  check_type_sizes ();
  if (!str_empty (config_filename)) {
    return; // Do not create custom config file
  }
  if (str_empty (config_directory)) {
    config_directory = get_config_directory ();
  }
  tasprintf (&config_filename, "%s/%s", config_directory, CONFIG_FILE);
  config_filename = make_full_path (config_filename);
  if (!disable_output) {
    printf ("I: config dir=[%s]\n", config_directory);
  }
  // printf ("I: config file=[%s]\n", config_filename);

  int config_file_fd;
  //char *config_directory = get_config_directory ();
  //char *downloads_directory = get_downloads_directory ();

  if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
    if (!disable_output) {
      printf ("[%s] created\n", config_directory);
    }
  }

  tfree_str (config_directory);
  config_directory = NULL;
  // see if config file is there
  if (access (config_filename, R_OK) != 0) {
    // config file missing, so touch it
    config_file_fd = open (config_filename, O_CREAT | O_RDWR, 0600);
    if (config_file_fd == -1)  {
      perror ("open[config_file]");
      printf ("I: config_file=[%s]\n", config_filename);
      exit (EXIT_FAILURE);
    }
    if (write (config_file_fd, DEFAULT_CONFIG_CONTENTS, strlen (DEFAULT_CONFIG_CONTENTS)) <= 0) {
      perror ("write[config_file]");
      exit (EXIT_FAILURE);
    }
    close (config_file_fd);
  }
}
Пример #5
0
/**
 * \brief Create the configuration file, if it does not exists.
 * \return true if the file already exists or if it has been created.
 */
bool bf::path_configuration::create_config_file() const
{
    bool result = false;

    if ( create_config_directory() )
    {
        boost::filesystem::path path
        ( get_config_directory() + s_config_file_name );

        if ( !boost::filesystem::exists( path ) )
        {
            std::ofstream f( path.string().c_str() );
            f << s_comment << " Configuration file for Bear Factory\n\n";
        }

        if ( boost::filesystem::exists( path ) )
            result = !boost::filesystem::is_directory( path );
    }

    return result;
} // path_configuration::create_config_file()
Пример #6
0
/**
 * \brief Save the configuration.
 */
void bf::path_configuration::save() const
{
    if ( create_config_file() )
    {
        const std::string path( get_config_directory() + s_config_file_name );
        std::ofstream f( path.c_str() );

        if (f)
        {
            f << s_comment
              << " Path to the directory containing XML item class files\n";

            workspaces_const_iterator it_map;

            for ( it_map = m_workspaces.begin();
                    it_map != m_workspaces.end(); ++it_map )
            {
                f << s_section_left << it_map->first << s_section_right << '\n';
                std::list<std::string>::const_iterator it;

                for ( it = it_map->second.item_class_begin();
                        it != it_map->second.item_class_end(); ++it )
                    f << s_items_directory_field << ' ' << s_field_assign
                      << ' ' << *it << '\n';

                f << '\n' << s_comment
                  << " Path to the directory containing the data of the game\n";

                for ( it = it_map->second.data_begin();
                        it != it_map->second.data_end(); ++it )
                    f << s_data_directory_field << ' ' << s_field_assign
                      << ' ' << *it << '\n';
            }
        }
    }
} // path_configuration::save()