Exemple #1
0
//----------------------------------------------------------------//
bool 
CSettings::LoadSettings() {

	std::string fileName = GetConfigFileName();
	
	LOG4CPLUS_INFO(ProviderLog, _T("ConfigurationFile: ") << fileName.c_str());

	if (fileName.length() > 0) {
		
		IniReader config_reader(fileName);
		
		IniReader::Section activ_settings("ACTIV");
		config_reader.read_section(activ_settings);
		
		activ_settings.get_value("UserID", m_UserID, "");
		activ_settings.get_value("Password", m_Password, "");
		activ_settings.get_value("ServiceLocationINI", m_ServiceLocationINI, "");
		
		IniReader::Section db_settings("DATABASE");
		config_reader.read_section(db_settings);
		db_settings.get_value("ConnectionString", m_DBConnectionString, "");

		m_ACTIVSettings.m_enableUiService = false;
		m_ACTIVSettings.m_createSystemLog = false;
		m_ACTIVSettings.m_systemLogMode = AgentApplication::Settings::SYSTEM_LOG_MODE_OFF;
		m_ACTIVSettings.m_serviceLocationIniFile = m_ServiceLocationINI;

		return true;
	}
	return false;
};
Exemple #2
0
MyConfig *OCPNPlatform::GetConfigObject()
{
    MyConfig *result = NULL;

    result = new MyConfig( wxString( _T("") ), wxString( _T("") ), GetConfigFileName() );

    return result;
}
Exemple #3
0
void Config::save(Config *settings)
{
FILE *fpo;
char *name;
uint32 type;
int32 i, count;
char *filename;
BString line("", 128);

	filename = GetConfigFileName();
	if (!filename) return;
	
	fpo = fopen(filename, "wb");
	if (!fpo) return;
	
	for(i=0; settings->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i++)
	{
		switch(type)
		{
			case B_STRING_TYPE:
			{
				const char *strData = "";
				settings->FindString(name, &strData);
				
				line = "$";
				line.Append(name);
				line.Append(" = ");
				line.Append(strData);
			}
			break;
			
			case B_INT32_TYPE:
			{
				int32 num = 0;
				char strData[64];
				
				settings->FindInt32(name, &num);
				sprintf(strData, "%d", num);
				
				line = "%";
				line.Append(name);
				line.Append(" = ");
				line.Append(strData);
			}
			break;
			
			default: continue;
		}
		
		fprintf(fpo, "%s\n", line.String());
	}
	
	fclose(fpo);
}
//
// 从配置文件中装入自定义颜色
//
void
LoadCustomColors( void )
{
	string strConfigFile;
	GetConfigFileName( strConfigFile );

	char szName[256];
	for( int i = 0; i < CUSTOMCOLOR_COUNT; i++ )
	{
		sprintf( szName, "Color%d", i + 1 );
		g_CustomColors[i] = GetPrivateProfileInt( "CustomColors", szName, 0, strConfigFile.c_str() );
	}
}
//
// 将自定义颜色保存到配置文件中
//
void
SaveCustomColors( void )
{
	string strConfigFile;
	GetConfigFileName( strConfigFile );

	char szName[256], szColor[16];
	for( int i = 0; i < CUSTOMCOLOR_COUNT; i++ )
	{
		sprintf( szName, "Color%d", i + 1 );
		sprintf( szColor, "%d", g_CustomColors[i] );
		WritePrivateProfileString( "CustomColors", szName, szColor, strConfigFile.c_str() );
	}
}
//
// 将模板保存到配置文件中
//
void
SaveTemplate( int nIndex, string &strName, string &strFormat )
{
	string strConfigFile;
	GetConfigFileName( strConfigFile );

	char szName[256];
	
	sprintf( szName, "Name%d", nIndex + 1 );
	WritePrivateProfileString( "Templates", szName, strName.c_str(), strConfigFile.c_str() );
	
	sprintf( szName, "Format%d", nIndex + 1 );
	WritePrivateProfileString( "Templates", szName, strFormat.c_str(), strConfigFile.c_str() );
}
bool RobotConfig::LoadConfig() {
	std::string fileName;

	GetConfigFileName(fileName);
	std::ifstream configFile(fileName.c_str());
	if (configFile.good() == false)
	{
		std::printf("2135: ERROR: RobotConfig -- No such file %s\n", fileName.c_str());
		return false;
	}

    m_configMap.clear();

    std::printf("2135: RobotConfig -- Loading File %s\n", fileName.c_str());
	while (configFile.eof() == false) {
		std::string name;
		std::string valueStr;
		std::string delimiter = "=";
		std::string line;

		while(getline(configFile, line)) {
			name = "";			// Reset
			trimWhitespace(line);
			if (line[0] == '#') {	// Skipping comment line
				continue;
			}
			size_t pos = 0;
			if ((pos = line.find(delimiter)) != std::string::npos) {
				name = line.substr(0, pos);
				trimWhitespace(name);
				line.erase(0, pos + delimiter.length());
				trimWhitespace(line);
				valueStr = line;
			}

			if (!name.empty())
			{
				m_configMap[name] = valueStr;
			}

			if (configFile.bad() == true)
			{
				std::printf("2135: ERROR: RobotConfig -- configFile %s bad\n", fileName.c_str());
				return false;
			}
		}
	}

	return true;
}
Exemple #8
0
Config *Config::load()
{
FILE *fpi;
char *filename;
char line[1024];
char *equ, *ptr;

	settings = (Config *)(new BMessage(M_SETTINGS));
	
	filename = GetConfigFileName();
	if (!filename) return settings;
	
	fpi = fopen(filename, "rb");
	if (!fpi) return settings;
	
	while(!feof(fpi))
	{
		fgetline(fpi, line, sizeof(line) - 1);
		
		equ = strchr(line, '=');
		if (!equ) continue;
		
		*equ = 0;
		ptr = equ-1;
		while(ptr > line && (*ptr == ' ')) { *ptr = 0; ptr--; }
		equ++;
		while(*equ == ' ') equ++;
		
		switch(line[0])
		{
			case '%':
				settings->AddInt32(line+1, atoi(equ));
			break;
			
			case '$':
				settings->AddString(line+1, equ);
			break;
		}
	}


	fclose(fpi);
	return settings;
}
Exemple #9
0
/*
 * readConfigFile - get the name of the config file that we are to read
 */
static void readConfigFile( void )
{
    char        cname[FILENAME_MAX];
    //char      str[MAX_STR]; // not used if not prompting for new cfg files
    char        *cfgname;
    struct stat cfg;
    int         rc;
    DWORD       new_cfgtime = 0;

    cfgTime = getProfileLong( keyCfgTime );
    cfgname = GetConfigFileName();
    GetFromEnv( cfgname, cname );
    if( cname[0] != '\0' ) {
        stat( cname, &cfg );
        new_cfgtime = cfg.st_mtime;
        if( cfgTime == 0 ) {
            cfgTime = new_cfgtime;
        }
    }

    if( access( cfgFile, R_OK ) != -1 ) {
        rc = IDNO;
#if 0
        // don't prompt for newer config files
        if( new_cfgtime > cfgTime ) {
            MySprintf( str, "The configuration file \"%s\" is newer than your .INI file, do you wish to use the new configuration?",
                       cname );
            rc = MessageBox( NO_WINDOW, str, EditorName, MB_YESNO | MB_TASKMODAL );
            if( rc == IDYES ) {
                cfgTime = new_cfgtime;
            }

        }
#endif
        if( rc == IDNO ) {
            SetConfigFileName( cfgFile );
        }
    } else {
        cfgTime = new_cfgtime;
    }
    saveConfig = getProfileLong( keySaveConfig );

} /* readConfigFile */
//
// 从配置文件中装入指定的模板,如果配置不存在就使用预制模板
//
void
LoadTemplate( int nIndex, string &strName, string &strFormat )
{
	string strConfigFile;
	GetConfigFileName( strConfigFile );

	char szName[256], szValue[256];

	memset( szValue, 0, sizeof( szValue ) );
	sprintf( szName, "Name%d", nIndex + 1 );
	GetPrivateProfileString( "Templates", szName, GetAppName(), szValue, sizeof( szValue ), strConfigFile.c_str() );
	if( 0 == stricmp( szValue, GetAppName() ) )
	{
		LoadDefaultTemplate( nIndex, strName, strFormat );
		return;
	}
	strName = szValue;

	memset( szValue, 0, sizeof( szValue ) );
	sprintf( szName, "Format%d", nIndex + 1 );
	GetPrivateProfileString( "Templates", szName, NULL, szValue, sizeof( szValue ), strConfigFile.c_str() );
	strFormat = szValue;
}
Exemple #11
0
Fichier : Init.c Projet : aosm/X11
/*
 * BuildPrinterDb - reads the config file if it exists, and if necessary
 * executes a command such as lpstat to generate a list of printers.
 * XXX
 * XXX BuildPrinterDb must be rewritten to allow 16-bit characters in 
 * XXX printer names.  The will involve replacing the use of strtok() and its
 * XXX related functions.
 * XXX At the same time, BuildPrinterDb and it's support routines should have
 * XXX allocation error checking added.
 * XXX
 */
static PrinterDbPtr
BuildPrinterDb(void)
{
    Bool defaultAugment = TRUE, freeConfigFileName;

    if(configFileName && access(configFileName, R_OK) != 0)
    {
	ErrorF("Xp Extension: Can't open file %s\n", configFileName);
    }
    if(!configFileName && (configFileName = GetConfigFileName()))
	freeConfigFileName = TRUE;
    else
	freeConfigFileName = FALSE;

    if(configFileName != (char *)NULL && access(configFileName, R_OK) == 0)
    {
	char line[256];
	FILE *fp = fopen(configFileName, "r");

	while(fgets(line, 256, fp) != (char *)NULL)
	{
	    char *tok, *ptr;
	    if((tok = strtok(line, " \t\012")) != (char *)NULL)
	    {
		if(tok[0] == (char)'#') continue;
		if(strcmp(tok, "Printer") == 0)
		{
		    while((tok = strtok((char *)NULL, " \t")) != (char *)NULL)
		    {
		        if ((ptr = MbStrchr(tok, '\012')) != 0)
		            *ptr = (char)'\0';
			AddPrinterDbName(tok);
		    }
		}
		else if(strcmp(tok, "Map") == 0)
		{
		    char *name, *qualifier;

		    if((tok = strtok((char *)NULL, " \t\012")) == (char *)NULL)
			continue;
		    name = strdup(tok);
		    if((tok = strtok((char *)NULL, " \t\012")) == (char *)NULL)
		    {
			xfree(name);
			continue;
		    }
		    qualifier = strdup(tok);
		    AddNameMap(name, qualifier);
		}
		else if(strcmp(tok, "Augment_Printer_List") == 0)
		{
		    if((tok = strtok((char *)NULL, " \t\012")) == (char *)NULL)
			continue;

		    if(strcmp(tok, "%default%") == 0)
			continue;
		    defaultAugment = FALSE;
		    if(strcmp(tok, "%none%") == 0)
			continue;
		    AugmentPrinterDb(tok);
		}
		else
		    break; /* XXX Generate an error? */
	    }
	}
	fclose(fp);
    }

    if(defaultAugment == TRUE)
    {
	AugmentPrinterDb(LIST_QUEUES);
    }

    MergeNameMap();
    FreeNameMap();

    /* Create the attribute stores for all printers */
    CreatePrinterAttrs();

    /*
     * Find the drivers for each printers, and store the driver names
     * in the printerDb
     */
    StoreDriverNames();

    if(freeConfigFileName)
    {
	xfree(configFileName);
	configFileName = (char *)NULL;
    }

    return printerDb;
}
Settings::Settings(HINSTANCE instance)
  : config_filename_(GetConfigFileName(instance)) {
    Load();
    PopulateDefaults();
}