예제 #1
0
bool
CServerApp::loadConfig(const CString& pathname)
{
	try {
		// load configuration
		LOG((CLOG_DEBUG "opening configuration \"%s\"", pathname.c_str()));
		std::ifstream configStream(pathname.c_str());
		if (!configStream.is_open()) {
			// report failure to open configuration as a debug message
			// since we try several paths and we expect some to be
			// missing.
			LOG((CLOG_DEBUG "cannot open configuration \"%s\"",
				pathname.c_str()));
			return false;
		}
		configStream >> *args().m_config;
		LOG((CLOG_DEBUG "configuration read successfully"));
		return true;
	}
	catch (XConfigRead& e) {
		// report error in configuration file
		LOG((CLOG_ERR "cannot read configuration \"%s\": %s",
			pathname.c_str(), e.what()));
	}
	return false;
}
예제 #2
0
void Config::readConfigFile()
{
    std::string line;
    std::fstream configStream("config.ini", std::fstream::in);
    if(!configStream.is_open())
        throw "config.ini could not be opened.";
    while(!configStream.eof()) {
        getline(configStream, line);
        Config::variables.insert(std::make_pair(
            line.substr(0, line.find('=')),
            std::atoi(line.substr(line.find('=') + 1, line.length()).c_str())
        ));
    }
    configStream.close();
}
예제 #3
0
파일: settings.cpp 프로젝트: ppmanager/ppm
bool Config::save()
{
	int size;
	int i;
	
	size = ::strlen(config.vcPath);
	for(i = 0; i < size; ++i)
		if(config.vcPath[i] == ' ')
			config.vcPath[i] = CONFIG_TRANSFORM_SYMBOL;
		
	char path[strlen(CONFIG_SAVE_FILE) + strlen(appRoot) + 2];
	sprintf(path, "%s\\%s", appRoot, CONFIG_SAVE_FILE);
	
	std::ofstream configStream(path, std::ios::binary);
	configStream << config.vcPath << " ";
	configStream.close();
}
예제 #4
0
void CliConfigBase::loadOptions(const boost::program_options::options_description &options,
                                const std::string &configFile)
{
    namespace po = boost::program_options;

    std::ifstream configStream(configFile.c_str());
    po::parsed_options configFileOptions = po::parse_config_file(configStream, options, true);
    po::store(configFileOptions, configVars);
    unregConfigFileOptions = po::collect_unrecognized(configFileOptions.options, po::include_positional);

    // FIXME: Proper handling of required options is not available in Boost 1.41
    /*if (!(configVars.count(CmdLine_Help) || configVars.count(CmdLine_Version)))
        po::notify(configVars);*/

    std::ostringstream ostr;
    ostr << options;
    configUsage = ostr.str();
}
예제 #5
0
파일: settings.cpp 프로젝트: ppmanager/ppm
bool Config::load()
{
	char path[strlen(CONFIG_SAVE_FILE) + strlen(appRoot) + 2];
	sprintf(path, "%s\\%s", appRoot, CONFIG_SAVE_FILE);
	
	struct stat info;
	bool fileExists = !stat(path, &info);
	
	if(fileExists)
	{ // Load from file
		int size;
		int i;
		
		std::ifstream configStream(path, std::ios::binary);
		configStream >> config.vcPath;
		configStream.close();
		
		size = ::strlen(config.vcPath);
		for(i = 0; i < size; ++i)
			if(config.vcPath[i] == CONFIG_TRANSFORM_SYMBOL)
				config.vcPath[i] = ' ';
	}
	else
	{ // Default values
예제 #6
0
int main() {
  #if MFluidSolver_LOG_LEVEL <= MFluidSolver_LOG_INFO
  // Print version info
  std::cout << "INFO: Version " <<
    MFluidSolver_VERSION_MAJOR << "." <<
    MFluidSolver_VERSION_MINOR << std::endl;
  #endif

  // Initialize GLFW
  if (!glfwInit()) {
    #if MFluidSolver_LOG_LEVEL <= MFluidSolver_LOG_ERROR
    std::cerr << "FATAL: Failed to initiaize GLFW" << std::endl;
    #endif

    getchar(); // Wait for key before quit
    return -1;
  }

  // Seed randomness
  std::time_t seed = std::time(NULL);
  std::srand(seed);
  #if MFluidSolver_LOG_LEVEL <= MFluidSolver_LOG_INFO
  // Only affects particle visualization selection
  std::cout << "INFO: std::rand seed: " << seed << std::endl;
  #endif

  // Initialize non-OpenGL
  #if MFluidSolver_USE_OPENVDB
  openvdb::initialize();
  #endif
  #if MFluidSolver_USE_TBB
  tbb::task_scheduler_init init(tbb::task_scheduler_init::automatic);
  #endif

  // Set JSON file location
  std::string configJSON = MFluidSolver_DEFAULT_CONFIG_FILE;
  #if MFluidSolver_LOG_LEVEL <= MFluidSolver_LOG_INFO
  std::cout << "INFO: Loading config file: " << configJSON << std::endl;
  #endif

  // Open JSON file
  Json::Reader reader;
  Json::Value root;
  std::ifstream configStream(configJSON, std::ifstream::binary);
  bool success = reader.parse(configStream, root, false);
  if (!success) {
    #if MFluidSolver_LOG_LEVEL <= MFluidSolver_LOG_ERROR
    std::cerr << "ERROR: Failed to parse config file " <<
      configJSON.c_str() << std::endl;
    #endif
  }

  // Parse JSON
  std::string sceneJSON = root.get(
    "sceneJSON", MFluidSolver_DEFAULT_SCENE_FILE).asString();
  std::string wireVShader = root.get(
    "wireVShader", MFluidSolver_DEFAULT_WIRE_VERT_FILE).asString();
  std::string wireFShader = root.get(
    "wireFShader", MFluidSolver_DEFAULT_WIRE_FRAG_FILE).asString();
  std::string particleVShader = root.get(
    "particleVShader", MFluidSolver_DEFAULT_PARTICLE_VERT_FILE).asString();
  std::string particleFShader = root.get(
    "particleFShader", MFluidSolver_DEFAULT_PARTICLE_FRAG_FILE).asString();
  std::string particleTexture = root.get(
    "particleTexture", MFluidSolver_DEFAULT_PARTICLE_TEX_FILE).asString();
  bool autoRender = root.get(
    "autoRender", MFluidSolver_DEFAULT_AUTORENDER).asBool();
  unsigned int renderSkip = root.get(
    "renderSkip", MFluidSolver_DEFAULT_RENDERSKIP).asInt();

  // Initialize project objects
  Viewer viewer;
  Input::viewer = &viewer;
  try {
    viewer.init();
  } catch (std::exception &e) {
    #if MFluidSolver_LOG_LEVEL <= MFluidSolver_LOG_FATAL
    std::cerr << "FATAL: " << e.what() << std::endl;
    #endif
    return -1;
  }

  // Print OpenGL info
  #if MFluidSolver_LOG_LEVEL <= MFluidSolver_LOG_INFO
  std::cout << "INFO: OpenGL Version " << glGetString(GL_VERSION) << std::endl;
  #endif

  // Set a few settings/modes in OpenGL rendering
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LESS);
  glEnable(GL_LINE_SMOOTH);
  glEnable(GL_POLYGON_SMOOTH);
  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);

  // Set the size with which points should be rendered
  glPointSize(MFluidSolver_DEFAULT_POINT_SIZE);

  // Set background color
  glClearColor(MFluidSolver_DEFAULT_BG_COLOR_R,
               MFluidSolver_DEFAULT_BG_COLOR_G,
               MFluidSolver_DEFAULT_BG_COLOR_B,
               0.0f);

  // Bind vertex array object
  GLuint vaoID;
  glGenVertexArrays(1, &vaoID);
  glBindVertexArray(vaoID);

  // After vertex array object init
  viewer.wireShader = new ShaderProgram(wireVShader, wireFShader);
  viewer.particleShader =
    new ParticleShaderProgram(&(viewer.scene.solver),
      particleVShader, particleFShader, particleTexture);
  viewer.scene.solver.loadConfig(configJSON);
  viewer.configureScreenshot(autoRender, renderSkip);

  // Run! Catch and print exceptions as necessary
  int returnCode = 0;
  #if MFluidSolver_MAIN_CATCH_EXCEPTIONS
  try {
  #endif
    viewer.scene.loadJSON(sceneJSON);
    viewer.particleShader->init();
    viewer.run();
  #if MFluidSolver_MAIN_CATCH_EXCEPTIONS
  } catch (std::exception &e) {
    #if MFluidSolver_LOG_LEVEL <= MFluidSolver_LOG_FATAL
    std::cerr << "FATAL: " << e.what() << std::endl;
    #endif
    returnCode = -1;
  }
  #endif

  // Performance
  #if MFluidSolver_RECORD_PERFORMANCE
  viewer.scene.solver.endSimulation();
  viewer.scene.solver.printPerformanceStats();
  #endif

  // Cleanup
  glDeleteVertexArrays(1, &vaoID);

  return returnCode;
}
예제 #7
0
    /**
     * Module initialization function. The initialization arguments string should
     * provide the path of a module configuration file that defines what files 
     * are interesting. If the empty string is passed to this function, the module
     * assumes a default config file is present in the output directory.
     *
     * @param args Path of the configuration file that defines what files are 
     * interesting, may be set to the empty string.
     * @return TskModule::OK on success, TskModule::FAIL otherwise. 
     */
    TSK_MODULE_EXPORT TskModule::Status initialize(const char* arguments)
    {
        TskModule::Status status = TskModule::OK;

        const std::string MSG_PREFIX = "InterestingFilesModule::initialize : ";
        try
        {
            // Make sure the file sets are cleared in case initialize() is called more than once.
            fileSets.clear();

            configFilePath.assign(arguments);
            if (configFilePath.empty())
            {
                // Use the default config file path.
                Poco::Path configurationFilePath(Poco::Path::forDirectory(GetSystemProperty(TskSystemProperties::MODULE_CONFIG_DIR)));
                configurationFilePath.pushDirectory(MODULE_NAME);
                configurationFilePath.setFileName(DEFAULT_CONFIG_FILE_NAME);
                configFilePath = configurationFilePath.toString();
            }

            // Compile the contents of the config file into interesting file set definitions.
            Poco::File configFile = Poco::File(configFilePath);
            if (configFile.exists())
            {
                std::ifstream configStream(configFile.path().c_str());
                if (configStream)
                {
                    Poco::XML::InputSource inputSource(configStream);
                    Poco::AutoPtr<Poco::XML::Document> configDoc = Poco::XML::DOMParser().parse(&inputSource);

                    Poco::XML::Element * rootElement = configDoc->documentElement();
                    if (rootElement == NULL)
                    {
                        std::ostringstream msg;
                        msg << MSG_PREFIX << "Root element of config file is NULL.";
                        throw TskException(msg.str());
                    }

                    const std::string& ignoreKnownValue = Poco::XML::fromXMLString(rootElement->getAttribute(IGNORE_KNOWN_TAG));

                    if (!ignoreKnownValue.empty())
                    {
                        knownType = parseKnownType(ignoreKnownValue);
                        ignoreKnown = true;
                    }

                    Poco::AutoPtr<Poco::XML::NodeList> fileSetDefinitions = configDoc->getElementsByTagName(INTERESTING_FILE_SET_ELEMENT_TAG);
                    for (unsigned long i = 0; i < fileSetDefinitions->length(); ++i) 
                    {
                        compileInterestingFilesSet(fileSetDefinitions->item(i));
                    }
                }
                else
                {
                    std::ostringstream msg;
                    msg << MSG_PREFIX << "failed to open config file '" << configFilePath << "'";
                    throw TskException(msg.str());
                }
            }
            else
            {
                std::ostringstream msg;
                msg << MSG_PREFIX << "config file'" << configFilePath << "' does not exist";
                LOGERROR(msg.str());
            }

            // Log the configuration.
            std::ostringstream msg;
            msg << MSG_PREFIX << "configured with " << fileSets.size() << " interesting file set definitions from '" << configFilePath << "'";
            LOGINFO(msg.str());
        }
        catch (TskException &ex)
        {
            status = TskModule::FAIL;
            configFilePath.clear();
            std::ostringstream msg;
            msg << MSG_PREFIX << "TskException: " << ex.message();
            LOGERROR(msg.str());
        }
        catch (Poco::Exception &ex)
        {
            status = TskModule::FAIL;
            configFilePath.clear();
            std::ostringstream msg;
            msg << MSG_PREFIX << "Poco::Exception: " << ex.displayText();
            LOGERROR(msg.str());
        }
        catch (std::exception &ex)
        {
            status = TskModule::FAIL;
            configFilePath.clear();
            std::ostringstream msg;
            msg << MSG_PREFIX << "std::exception: " << ex.what();
            LOGERROR(msg.str());
        }
        catch (...)
        {
            status = TskModule::FAIL;
            configFilePath.clear();
            LOGERROR(MSG_PREFIX + "unrecognized exception");
        }

        return status;
    }