Ejemplo n.º 1
0
CSimpleIniCaseA *getIniFile()
{
	static bool inited = false;
	static CSimpleIniCaseA ini;
	if (inited == false)
	{
		ini.SetUnicode(true);
		ini.LoadFile(DEF_CONFIG_NAME);
		inited = true;
	}
	return &ini;
}
Ejemplo n.º 2
0
Archivo: Ini.cpp Proyecto: Bigpet/rpcs3
//TODO: make thread safe/remove static singleton
CSimpleIniCaseA *getIniFile()
{
	static bool inited = false;
	static CSimpleIniCaseA ini;
	if (inited == false)
	{
		ini.SetUnicode(true);
		ini.LoadFile(std::string(rPlatform::getConfigDir() + DEF_CONFIG_NAME).c_str());
		inited = true;
	}
	return &ini;
}
Ejemplo n.º 3
0
void config_init(const std::string& path)
{
	config.SetSpaces(true);

	if (config.LoadFile(path.c_str()) == SI_OK) {
		long value = config.GetLongValue("General", "DataSource");
		config_DataSource = (value ? INPUT_FILE : INPUT_SERIAL);

		config_InputFile = config.GetValue("General", "InputFile");
		config_SerialPort = config.GetValue("General", "SerialPort");
		config_AgmRawOutput = config.GetBoolValue("General", "AgmRawOutput");
		config_AgmRawOutputFile = config.GetValue("General", "AgmRawOutputFile");
		config_AgmCalibOutput = config.GetBoolValue("General", "AgmCalibOutput");
		config_AgmCalibOutputFile = config.GetValue("General", "AgmCalibOutputFile");
		config_YprOutput = config.GetBoolValue("General", "YprOutput");
		config_YprOutputFile = config.GetValue("General", "YprOutputFile");
		config_SocketOutput = config.GetBoolValue("General", "SocketOutput");
		config_SocketOutputPort = config.GetLongValue("General", "SocketOutputPort");

		std::cout << "Configuration file '" << path << "' loaded." << std::endl;
	}
	else {
		// Generate a default configuration file.
		config.SetLongValue("General", "DataSource", 1, "; 0: Serial port. 1: Text file.");
		config.SetValue("General", "InputFile", "..\\etc\\data\\video_AGM_RAW.txt");
		config.SetValue("General", "SerialPort", "COM6");
		config.SetValue("General", "AgmRawOutputFile", "auto", "; 'auto' for automatic naming.");
		config.SetValue("General", "AgmCalibOutputFile", "auto");
		config.SetValue("General", "YprOutputFile", "auto");
		config.SetBoolValue("General", "AgmRawOutput", true);
		config.SetBoolValue("General", "AgmCalibOutput", false);
		config.SetBoolValue("General", "YprOutput", true);
		config.SetBoolValue("General", "SocketOutput", false);
		config.SetLongValue("General", "SocketOutputPort", 2042);
		config.SaveFile(path.c_str());
		config.Reset();

		std::cout << "Configuration file '" << path << "' NOT FOUND. Default created." << std::endl;
		return config_init(path); // Call itself again; now it will find the config file.
	}

	/*std::cout << "DataSource: " << config_DataSource << std::endl;
	std::cout << "InputFile: " << config_InputFile << std::endl;
	std::cout << "SerialPort: " << config_SerialPort << std::endl;*/
}
Ejemplo n.º 4
0
    void
    config::load (const std::string& path)
    {
      CSimpleIniCaseA ini (false, true, true);

      std::string checked_path;

      if (rld::path::check_file (path))
      {
        checked_path = path;
      }
      else
      {
        bool found = false;
        for (rld::path::paths::const_iterator spi = search.begin ();
             spi != search.end ();
             ++spi)
        {
          rld::path::path_join (*spi, path, checked_path);
          if (rld::path::check_file (checked_path))
          {
            found = true;
            break;
          }
        }
        if (!found)
          throw rld::error ("Not found.", "load config: " + path);
      }

      if (ini.LoadFile (checked_path.c_str ()) != SI_OK)
        throw rld::error (::strerror (errno), "load config: " + path);

      paths_.push_back (checked_path);

      /*
       * Merge the loaded configuration into our configuration.
       */

      CSimpleIniCaseA::TNamesDepend skeys;

      ini.GetAllSections(skeys);

      for (CSimpleIniCaseA::TNamesDepend::const_iterator si = skeys.begin ();
           si != skeys.end ();
           ++si)
      {
        section sec;

        sec.name = (*si).pItem;

        CSimpleIniCaseA::TNamesDepend rkeys;

        ini.GetAllKeys((*si).pItem, rkeys);

        for (CSimpleIniCaseA::TNamesDepend::const_iterator ri = rkeys.begin ();
             ri != rkeys.end ();
             ++ri)
        {
          record rec;

          rec.name = (*ri).pItem;

          CSimpleIniCaseA::TNamesDepend vals;

          ini.GetAllValues((*si).pItem, (*ri).pItem, vals);

          for (CSimpleIniCaseA::TNamesDepend::const_iterator vi = vals.begin ();
               vi != vals.end ();
               ++vi)
          {
            rec.items_.push_back (item ((*vi).pItem));
          }

          sec.recs.push_back (rec);
        }

        secs.push_back (sec);

        if (sec.name == "includes")
          includes(sec);
      }
    }