Exemplo n.º 1
0
INIFile LoadIni(const char *filename)
{
	INIFile theINI;
	char  *value, *temp;
	std::string section;
	char buffer[MAX_INI_LINE];
	std::fstream file(filename, std::ios::in);
	
	while(file.good())
	{
		memset(buffer, 0, sizeof(buffer));
		file.getline(buffer, sizeof(buffer));
		if((temp = strchr(buffer, '\n')))
			*temp = '\0';		// cut off at newline
		if((temp = strchr(buffer, '\r')))
			*temp = '\0';		// cut off at linefeeds
		if((buffer[0] == '[') && (temp = strrchr(buffer, ']')))
		{     // if line is like -->   [section name]
			*temp = '\0';   // chop off the trailing ']';
			section = &buffer[1];
			PutIniSetting(theINI, &buffer[1]);	 // start new section
		}
		else if(buffer[0] && (value = strchr(buffer, '=')))
		{
			*value++ = '\0'; // assign whatever follows = sign to value, chop at "=" 
			PutIniSetting(theINI, section.c_str(), buffer, value); 	// and add both sides to INISection
		}
		else if(buffer[0])
			PutIniSetting(theINI, section.c_str(), buffer, ""); 	// must be a comment or something
	}
	return theINI;
}
Exemplo n.º 2
0
void CSettings::SetFlagIniSet ( QDomDocument&  xmlFile,
                                const QString& strSection,
                                const QString& strKey,
                                const bool     bValue )
{
    // we encode true -> "1" and false -> "0"
    if ( bValue == true )
    {
        PutIniSetting ( xmlFile, strSection, strKey, "1" );
    }
    else
    {
        PutIniSetting ( xmlFile, strSection, strKey, "0" );
    }
}
Exemplo n.º 3
0
void CSettings::SetNumericIniSet ( QDomDocument&  xmlFile,
                                   const QString& strSection,
                                   const QString& strKey,
                                   const int      iValue )
{
    // convert input parameter which is an integer to string and store
    PutIniSetting ( xmlFile, strSection, strKey, QString("%1").arg(iValue) );
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
		// read an INI.  If file doesn't exist, that's OK.
		INIFile ini = LoadIni("test.ini");
		if(ini.size())
		{
			// Note that existing INIs will be added to, though if any of the keys
			// listed below already exist, this program will modify them.
			cout << "About to modify test.ini, which presently contains:\n";
			DumpIni(ini);
		}
	   
		cout << "\nLoading INI with the following information, plus comments\n\n";
		cout <<"[Favorites]\ncolor=blue\nfood=pizza\nbeer=homebrew\n\n";
		cout << "[Computing]\nOperating System=Linux\nToolkit=FLTK\nComment=Now isn't this fun?\n\n";

		PutIniSetting(ini, "", "; This is a comment about the whole INI file");
		PutIniSetting(ini, "Favorites", "; This is a list of favorites");
		PutIniSetting(ini, "Favorites", "color", "blue");
		PutIniSetting(ini, "Favorites", "food", "pizza");
		PutIniSetting(ini, "Favorites", "beer", "homebrew");
		PutIniSetting(ini, "Computing", "; Information about computing preferences");
		PutIniSetting(ini, "Computing", "Operating System", "Linux");
		PutIniSetting(ini, "Computing", "Toolkit", "FLTK");
		PutIniSetting(ini, "Computing", "Comment", "This will be replaced in next line.");
		PutIniSetting(ini, "Computing", "Comment", "Now isn't this fun?");

		cout << "\nINI Ready, saving to disk\n\n";
		SaveIni(ini, "test.ini");

		cout << "Loading from disk to verify.\n\n";
		INIFile ini2 = LoadIni("test.ini");
		
		cout << "Contents of ini just read\n\n";
		DumpIni(ini2);
		
		cout << "\nChecking single value for section Computing, key Comment:\n";
		cout << "Value is: " << GetIniSetting(ini2, "Computing", "Comment") << std::endl;
		
		cout << "\nChecking unset value for section Computing, \nkey Distribution, with default of \"RedHat\"\n";
		cout << "Value is: " << GetIniSetting(ini2, "Computing", "Distribution",  "RedHat") << "\n\nDone\n\n";
		return (0);
}
Exemplo n.º 5
0
void CSettings::Save()
{
    int iIdx;

    // create XML document for storing initialization parameters
    QDomDocument IniXMLDocument;


    // Actual settings data ---------------------------------------------------
    if ( bIsClient )
    {
        // client:

        // IP addresses
        for ( iIdx = 0; iIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIdx++ )
        {
            PutIniSetting ( IniXMLDocument, "client",
                            QString ( "ipaddress%1" ).arg ( iIdx ),
                            pClient->vstrIPAddress[iIdx] );
        }

        // stored fader tags
        for ( iIdx = 0; iIdx < MAX_NUM_STORED_FADER_LEVELS; iIdx++ )
        {
            PutIniSetting ( IniXMLDocument, "client",
                            QString ( "storedfadertag%1" ).arg ( iIdx ),
                            pClient->vecStoredFaderTags[iIdx] );
        }

        // stored fader levels
        for ( iIdx = 0; iIdx < MAX_NUM_STORED_FADER_LEVELS; iIdx++ )
        {
            SetNumericIniSet ( IniXMLDocument, "client",
                               QString ( "storedfaderlevel%1" ).arg ( iIdx ),
                               pClient->vecStoredFaderLevels[iIdx] );
        }

        // name
        PutIniSetting ( IniXMLDocument, "client", "name",
            pClient->ChannelInfo.strName );

        // instrument
        SetNumericIniSet ( IniXMLDocument, "client", "instrument",
            pClient->ChannelInfo.iInstrument );

        // audio fader
        SetNumericIniSet ( IniXMLDocument, "client", "audfad",
            pClient->GetAudioInFader() );

        // reverberation level
        SetNumericIniSet ( IniXMLDocument, "client", "revlev",
            pClient->GetReverbLevel() );

        // reverberation channel assignment
        SetFlagIniSet ( IniXMLDocument, "client", "reverblchan",
            pClient->IsReverbOnLeftChan() );

        // sound card selection
        SetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
            pClient->GetSndCrdDev() );

        // sound card left input channel mapping
        SetNumericIniSet ( IniXMLDocument, "client", "sndcrdinlch",
            pClient->GetSndCrdLeftInputChannel() );

        // sound card right input channel mapping
        SetNumericIniSet ( IniXMLDocument, "client", "sndcrdinrch",
            pClient->GetSndCrdRightInputChannel() );

        // sound card left output channel mapping
        SetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutlch",
            pClient->GetSndCrdLeftOutputChannel() );

        // sound card right output channel mapping
        SetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutrch",
            pClient->GetSndCrdRightOutputChannel() );

        // sound card preferred buffer size index
        SetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx",
            pClient->GetSndCrdPrefFrameSizeFactor() );

        // automatic network jitter buffer size setting
        SetFlagIniSet ( IniXMLDocument, "client", "autojitbuf",
            pClient->GetDoAutoSockBufSize() );

        // network jitter buffer size
        SetNumericIniSet ( IniXMLDocument, "client", "jitbuf",
            pClient->GetSockBufNumFrames() );

        // network jitter buffer size for server
        SetNumericIniSet ( IniXMLDocument, "client", "jitbufserver",
            pClient->GetServerSockBufNumFrames() );

        // flag whether the chat window shall be opened on a new chat message
        SetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage",
            pClient->GetOpenChatOnNewMessage() );

        // GUI design
        SetNumericIniSet ( IniXMLDocument, "client", "guidesign",
            static_cast<int> ( pClient->GetGUIDesign() ) );

        // audio quality
        SetNumericIniSet ( IniXMLDocument, "client", "audioquality",
            static_cast<int> ( pClient->GetAudioQuality() ) );

        // flag whether stereo mode is used
        SetFlagIniSet ( IniXMLDocument, "client", "stereoaudio",
            pClient->GetUseStereo() );

        // central server address
        PutIniSetting ( IniXMLDocument, "client", "centralservaddr",
            pClient->GetServerListCentralServerAddress() );

        // use default central server address flag
        SetFlagIniSet ( IniXMLDocument, "client", "defcentservaddr",
            pClient->GetUseDefaultCentralServerAddress() );

        // window position of the main window
        PutIniSetting ( IniXMLDocument, "client", "winposmain",
            QString().fromLatin1 ( pClient->vecWindowPosMain.toBase64() ) );

        // window position of the settings window
        PutIniSetting ( IniXMLDocument, "client", "winposset",
            QString().fromLatin1 ( pClient->vecWindowPosSettings.toBase64() ) );

        // window position of the chat window
        PutIniSetting ( IniXMLDocument, "client", "winposchat",
            QString().fromLatin1 ( pClient->vecWindowPosChat.toBase64() ) );

        // window position of the connect window
        PutIniSetting ( IniXMLDocument, "client", "winposcon",
            QString().fromLatin1 ( pClient->vecWindowPosConnect.toBase64() ) );

        // visibility state of the settings window
        SetFlagIniSet ( IniXMLDocument, "client", "winvisset",
            pClient->bWindowWasShownSettings );

        // visibility state of the chat window
        SetFlagIniSet ( IniXMLDocument, "client", "winvischat",
            pClient->bWindowWasShownChat );

        // visibility state of the connect window
        SetFlagIniSet ( IniXMLDocument, "client", "winviscon",
            pClient->bWindowWasShownConnect );
    }
    else
    {
        // server:

        // central server address
        PutIniSetting ( IniXMLDocument, "server", "centralservaddr",
            pServer->GetServerListCentralServerAddress() );

        // use default central server address flag
        SetFlagIniSet ( IniXMLDocument, "server", "defcentservaddr",
            pServer->GetUseDefaultCentralServerAddress() );

        // server list enabled flag
        SetFlagIniSet ( IniXMLDocument, "server", "servlistenabled",
            pServer->GetServerListEnabled() );

        // name
        PutIniSetting ( IniXMLDocument, "server", "name",
            pServer->GetServerName() );

        // city
        PutIniSetting ( IniXMLDocument, "server", "city",
            pServer->GetServerCity() );

        // country
        SetNumericIniSet ( IniXMLDocument, "server", "country",
            static_cast<int> ( pServer->GetServerCountry() ) );

        // start minimized on OS start
        SetFlagIniSet ( IniXMLDocument, "server", "autostartmin",
            pServer->GetAutoRunMinimized() );
    }

    // prepare file name for storing initialization data in XML file and store
    // XML data in file
    QFile file ( strFileName );
    if ( file.open ( QIODevice::WriteOnly ) )
    {
        QTextStream out ( &file );
        out << IniXMLDocument.toString();

        file.close();
    }
}