bool CSettings::GetFlagIniSet ( const QDomDocument& xmlFile, const QString& strSection, const QString& strKey, bool& bValue ) { // init return value bool bReturn = false; const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey ); if ( !strGetIni.isEmpty() ) { if ( strGetIni.toInt() ) { bValue = true; } else { bValue = false; } bReturn = true; } return bReturn; }
CString Util::GetRootPath() { // return ::FuncGetInstallRootPath(); // return "/home/siteview/chenxing/monitor"; string path=::GetSiteViewRootPath(); return path.c_str(); char buf[100]={0}; strcpy(buf,"siteview.ini"); INIFile inf=LoadIni(buf); std::string name=GetIniSetting(inf,"InstallPath","RootPath",""); if(name.empty()) return "D:\\v70"; else return name.c_str(); return "/usr/local"; return "/usr/local"; }
bool Cmd_GetStringIniSetting_Execute(COMMAND_ARGS) { char settingName[kMaxMessageLength] = { 0 }; *result = -1; if (ExtractArgs(EXTRACT_ARGS, &settingName)) { Setting* setting; if (GetIniSetting(settingName, &setting)) { char val[kMaxMessageLength] = { 0 }; if (const char * pVal = setting->Get()) { strcpy_s(val, kMaxMessageLength, pVal); AssignToStringVar(PASS_COMMAND_ARGS, val); if (IsConsoleMode()) Console_Print("GetStringIniSetting >> %s", val); } } else if (IsConsoleMode()) Console_Print("GetStringIniSetting >> SETTING NOT FOUND"); } return true; }
bool CSettings::GetNumericIniSet ( const QDomDocument& xmlFile, const QString& strSection, const QString& strKey, const int iRangeStart, const int iRangeStop, int& iValue ) { // init return value bool bReturn = false; const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey ); // check if it is a valid parameter if ( !strGetIni.isEmpty() ) { // convert string from init file to integer iValue = strGetIni.toInt(); // check range if ( ( iValue >= iRangeStart ) && ( iValue <= iRangeStop ) ) { bReturn = true; } } return bReturn; }
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); }
bool Util::SendMsgToWsServer(string szId, string szText) { bool bRet = true; string errorMsg = ""; if(sendmsg == NULL) { //Init(); char buf[1024]={0}; sprintf(buf,"%s/fcgi-bin/MonitorScheduleWeb.dll",GetRootPath().getText()); //strPath = ".\\MonitorScheduleWeb.dll"; //puts(strPath); HMODULE m_hWebDll=::LoadLibrary(buf); if(m_hWebDll==NULL) throw MSException("Load MonitorScheduleWeb.dll failed"); sendmsg = (SendMsg)::GetProcAddress(m_hWebDll, "SendMsg"); if(sendmsg == NULL) { puts(" 获取dll函数失败, Failed to GetProcAddress: MonitorScheduleWeb.dll 's SendMsg; "); } sprintf(buf,"%s/fcgi-bin/WebECC.ini",GetRootPath().getText()); INIFile inf=LoadIni(buf); szServer=GetIniSetting(inf,"WebECC","WebService",""); szPort=GetIniSetting(inf,"WebECC","WebPort",""); //puts(szServer.c_str()); //puts(szPort.c_str()); } bRet = sendmsg(szId, szText, szServer, szPort, errorMsg); if(bRet) { puts("sendmsg sucess\n"); } else { puts("sendmsg failed\n"); puts(errorMsg.c_str()); } return bRet; }
CString Util::GetSVMQAddress() { char buf[1024]={0}; // strcpy(buf,"siteview.ini"); sprintf(buf,"%s/MonitorManager/siteview.ini",GetRootPath().getText()); INIFile inf=LoadIni(buf); std::string name=GetIniSetting(inf,"InstallPath","SVMQAddress",""); if(name.empty()) return "127.0.0.1"; else return name.c_str(); }
static bool Cmd_GetStringIniSetting_Execute(COMMAND_ARGS) { char settingName[kMaxMessageLength] = { 0 }; const char* settingString = ""; if (ExtractFormatStringArgs(0, settingName, paramInfo, arg1, opcodeOffsetPtr, scriptObj, eventList, SIZEOF_FMT_STRING_PARAMS)) { INISettingEntry* entry = GetIniSetting(settingName); if (entry && (entry->data->name[0] == 'S' || entry->data->name[0] == 's')) settingString = entry->data->s; } AssignToStringVar(PASS_COMMAND_ARGS, settingString); return true; }
static bool Cmd_SetNumericINISetting_Execute(COMMAND_ARGS) { *result = 0; char settingName[256] = { 0 }; float settingData = 0; if(!ExtractArgs(paramInfo, arg1, opcodeOffsetPtr, thisObj, arg3, scriptObj, eventList, &settingName, &settingData)) return true; INISettingEntry* entry = GetIniSetting(settingName); if (entry) { INISettingEntry::Data* data = entry->data; *result = 1; switch(data->name[0]) { case 'i': // int data->i = settingData; break; case 'f': // float data->f = settingData; break; case 'u': // unsigned data->u = settingData; break; case 'b': // bool data->b = (settingData != 0); break; default: *result = 0; break; } } return true; }
bool Cmd_GetNumericINISetting_Execute(COMMAND_ARGS) { *result = 0; char settingName[256] = { 0 }; if(!ExtractArgs(paramInfo, arg1, opcodeOffsetPtr, thisObj, arg3, scriptObj, eventList, &settingName)) return true; INISettingEntry* entry = GetIniSetting(settingName); if (entry) { INISettingEntry::Data * data = entry->data; if(data && data->name && !_stricmp(settingName, data->name)) { switch(data->name[0]) { case 'i': // int *result = data->i; break; case 'f': // float *result = data->f; break; case 'u': // unsigned *result = data->u; break; case 'b': // bool *result = data->b ? 1 : 0; break; default: *result = 0; break; } } } return true; }
bool Cmd_SetNumericIniSetting_Execute(COMMAND_ARGS) { char settingName[512] = { 0 }; float newVal = 0; *result = 0; if (ExtractArgs(EXTRACT_ARGS, &settingName, &newVal)) { Setting* setting; if (GetIniSetting(settingName, &setting)) { if (setting->Set(newVal)) *result = 1; } else if (IsConsoleMode()) Console_Print("SetNumericIniSetting >> NOT FOUND"); } return true; }
bool GetNumericIniSetting(char * settingName, double * result) { bool bResult = false; *result = -1; if (strlen(settingName)) { Setting* setting; if (GetIniSetting(settingName, &setting)) { double val; if (setting->Get(val)) { *result = val; bResult = true; } }; } return bResult; }
static bool Cmd_SetStringIniSetting_Execute(COMMAND_ARGS) { char stringArg[kMaxMessageLength] = { 0 }; if (ExtractFormatStringArgs(0, stringArg, paramInfo, arg1, opcodeOffsetPtr, scriptObj, eventList, SIZEOF_FMT_STRING_PARAMS)) { char* strtokContext = NULL; char* settingName = strtok_s(stringArg, GetSeparatorChars(scriptObj), &strtokContext); char* settingVal = strtok_s(NULL, GetSeparatorChars(scriptObj), &strtokContext); if (settingName && settingVal) { INISettingEntry* entry = GetIniSetting(settingName); if (entry && (entry->data->name[0] == 'S' || entry->data->name[0] == 's')) { UInt32 valLen = strlen(settingVal) + 1; entry->data->s = new char[valLen]; // this leaks. INI string alloc'd where? strcpy_s(entry->data->s, valLen, settingVal); } } } return true; }
// setting name included in format string i.e. "sSomeSetting|newSettingValue" bool Cmd_SetStringGameSettingEX_Execute(COMMAND_ARGS) { char fmtString[kMaxMessageLength] = { 0 }; *result = 0; if (ExtractFormatStringArgs(0, fmtString, PASS_FMTSTR_ARGS, kCommandInfo_SetStringGameSettingEX.numParams)) { UInt32 pipePos = std::string(fmtString).find(GetSeparatorChar(scriptObj)); if (pipePos != -1) { fmtString[pipePos] = 0; char* newValue = fmtString + pipePos + 1; Setting* setting = NULL; if (GetIniSetting(fmtString, &setting)) { setting->Set(newValue);; *result = 1; } } } return true; }
bool Option::LoadOption() { if(g_strRootPath.IsEmpty()) return false; printf("\n"); char filepath[1024]={0}; sprintf(filepath,"%s/fcgi-bin/mc.config",g_strRootPath.getText()); string svalue; INIFile inif=LoadIni(filepath); svalue=GetIniSetting(inif,"MonitorSchedule","DemoMode",""); if(!svalue.empty()) m_isDemo= (svalue=="true") ? true :false; printf("DemoMode:%d\n",m_isDemo); svalue.clear(); svalue=GetIniSetting(inif,"MonitorSchedule","PreLoadLibrary",""); if(!svalue.empty()) m_PreLoadLibrary+=svalue+","; svalue.clear(); svalue=GetIniSetting(inif,"MonitorSchedule","DemoLibrary",""); if(!svalue.empty()) m_DemoDLL=svalue; svalue.clear(); svalue=GetIniSetting(inif,"MonitorSchedule","DemoFunction",""); if(!svalue.empty()) m_DemoFunction=svalue; svalue.clear(); svalue=GetIniSetting(inif,"MonitorSchedule","SEID",""); if(!svalue.empty()) { m_seid=atoi(svalue.c_str()); Univ::seid= m_seid; } printf("SEID:%d\n",m_seid); svalue.clear(); svalue=GetIniSetting(inif,"MonitorSchedule","EnableAppendMassRecord",""); if(!svalue.empty()) Univ::enablemass=(atoi(svalue.c_str())!=0); printf("Enable AppendMass:%d\n",Univ::enablemass); svalue.clear(); svalue=GetIniSetting(inif,"MonitorSchedule","MilliSecondBetweenAppend",""); if(!svalue.empty()) Univ::msappend=atoi(svalue.c_str()); printf("MilliSecond Between AppendMass:%d\n",Univ::msappend); svalue.clear(); svalue=GetIniSetting(inif,"MonitorSchedule","MonitorTreadPlusCount",""); if(!svalue.empty()) Univ::pluscount=atoi(svalue.c_str()); printf("Monitor Tread Plus Count:%d\n",Univ::pluscount); svalue.clear(); svalue=GetIniSetting(inif,"information","CheckTime",""); if(!svalue.empty()) m_checktime=atoi(svalue.c_str()); printf("CheckTime:%d\n",m_checktime); svalue.clear(); svalue=GetIniSetting(inif,"MonitorSchedule","UseLocalBuffer",""); //char aaa[2000]={0}; //sprintf(aaa,"file is %s, UseLocalBuffer is %s\n", filepath,svalue.c_str()); //OutputDebugString(aaa); if(!svalue.empty()) m_UseLocalBuffer=(svalue=="true")? true : false; printf("UseLocalBuffer:%d\n",m_UseLocalBuffer); svalue.clear(); svalue=GetIniSetting(inif,"MonitorSchedule","ServerHost",""); if(!svalue.empty()) m_ServerAddress=svalue; printf("ServerHost:%s\n",m_ServerAddress.c_str()); svalue.clear(); string svdbHostAddr=GetSvdbAddr(); printf("SvdbHostAddr:%s\n",svdbHostAddr.c_str()); printf("PreLoadLibrary: %s\n",m_PreLoadLibrary.c_str()); printf("\n"); return true; }
/* Implementation *************************************************************/ void CSettings::Load() { int iIdx; int iValue; bool bValue; QDomDocument IniXMLDocument; // prepare file name for loading initialization data from XML file and read // data from file if possible QFile file ( strFileName ); if ( file.open ( QIODevice::ReadOnly ) ) { QTextStream in ( &file ); IniXMLDocument.setContent ( in.readAll(), false ); file.close(); } // Actual settings data --------------------------------------------------- if ( bIsClient ) { // client: // IP addresses for ( iIdx = 0; iIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIdx++ ) { QString sDefaultIP = ""; // use default only for first entry if ( iIdx == 0 ) { sDefaultIP = DEFAULT_SERVER_ADDRESS; } pClient->vstrIPAddress[iIdx] = GetIniSetting ( IniXMLDocument, "client", QString ( "ipaddress%1" ).arg ( iIdx ), sDefaultIP ); } // stored fader tags for ( iIdx = 0; iIdx < MAX_NUM_STORED_FADER_LEVELS; iIdx++ ) { pClient->vecStoredFaderTags[iIdx] = GetIniSetting ( IniXMLDocument, "client", QString ( "storedfadertag%1" ).arg ( iIdx ), "" ); } // stored fader levels for ( iIdx = 0; iIdx < MAX_NUM_STORED_FADER_LEVELS; iIdx++ ) { if ( GetNumericIniSet ( IniXMLDocument, "client", QString ( "storedfaderlevel%1" ).arg ( iIdx ), 0, AUD_MIX_FADER_MAX, iValue ) ) { pClient->vecStoredFaderLevels[iIdx] = iValue; } } // name pClient->ChannelInfo.strName = GetIniSetting ( IniXMLDocument, "client", "name" ); // instrument if ( GetNumericIniSet ( IniXMLDocument, "client", "instrument", 0, CInstPictures::GetNumAvailableInst() - 1, iValue ) ) { pClient->ChannelInfo.iInstrument = iValue; } // audio fader if ( GetNumericIniSet ( IniXMLDocument, "client", "audfad", AUD_FADER_IN_MIN, AUD_FADER_IN_MAX, iValue ) ) { pClient->SetAudioInFader ( iValue ); } // reverberation level if ( GetNumericIniSet ( IniXMLDocument, "client", "revlev", 0, AUD_REVERB_MAX, iValue ) ) { pClient->SetReverbLevel ( iValue ); } // reverberation channel assignment if ( GetFlagIniSet ( IniXMLDocument, "client", "reverblchan", bValue ) ) { pClient->SetReverbOnLeftChan ( bValue ); } // sound card selection // special case with this setting: the sound card initialization depends // on this setting call, therefore, if no setting file parameter could // be retrieved, the sound card is initialized with a default setting // defined here if ( GetNumericIniSet ( IniXMLDocument, "client", "auddevidx", 1, MAX_NUMBER_SOUND_CARDS, iValue ) ) { pClient->SetSndCrdDev ( iValue ); } else { // use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that // no device selection was done previously pClient->SetSndCrdDev ( INVALID_SNC_CARD_DEVICE ); } // sound card channel mapping settings: make sure these settings are // set AFTER the sound card device is set, otherwise the settings are // overwritten by the defaults // // sound card left input channel mapping if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdinlch", 0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) ) { pClient->SetSndCrdLeftInputChannel ( iValue ); } // sound card right input channel mapping if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdinrch", 0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) ) { pClient->SetSndCrdRightInputChannel ( iValue ); } // sound card left output channel mapping if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutlch", 0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) ) { pClient->SetSndCrdLeftOutputChannel ( iValue ); } // sound card right output channel mapping if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutrch", 0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) ) { pClient->SetSndCrdRightOutputChannel ( iValue ); } // sound card preferred buffer size index if ( GetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx", FRAME_SIZE_FACTOR_PREFERRED, FRAME_SIZE_FACTOR_SAFE, iValue ) ) { // additional check required since only a subset of factors are // defined if ( ( iValue == FRAME_SIZE_FACTOR_PREFERRED ) || ( iValue == FRAME_SIZE_FACTOR_DEFAULT ) || ( iValue == FRAME_SIZE_FACTOR_SAFE ) ) { pClient->SetSndCrdPrefFrameSizeFactor ( iValue ); } } // automatic network jitter buffer size setting if ( GetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", bValue ) ) { pClient->SetDoAutoSockBufSize ( bValue ); } // network jitter buffer size if ( GetNumericIniSet ( IniXMLDocument, "client", "jitbuf", MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL, iValue ) ) { pClient->SetSockBufNumFrames ( iValue ); } // network jitter buffer size for server if ( GetNumericIniSet ( IniXMLDocument, "client", "jitbufserver", MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL, iValue ) ) { pClient->SetServerSockBufNumFrames ( iValue ); } // flag whether the chat window shall be opened on a new chat message if ( GetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage", bValue ) ) { pClient->SetOpenChatOnNewMessage ( bValue ); } // GUI design if ( GetNumericIniSet ( IniXMLDocument, "client", "guidesign", 0, 1 /* GD_ORIGINAL */, iValue ) ) { pClient->SetGUIDesign ( static_cast<EGUIDesign> ( iValue ) ); } // audio quality if ( GetNumericIniSet ( IniXMLDocument, "client", "audioquality", 0, 2 /* AQ_HIGH */, iValue ) ) { pClient->SetAudioQuality ( static_cast<EAudioQuality> ( iValue ) ); } // flag whether stereo mode is used if ( GetFlagIniSet ( IniXMLDocument, "client", "stereoaudio", bValue ) ) { pClient->SetUseStereo ( bValue ); } // central server address pClient->SetServerListCentralServerAddress ( GetIniSetting ( IniXMLDocument, "client", "centralservaddr" ) ); // use default central server address flag if ( GetFlagIniSet ( IniXMLDocument, "client", "defcentservaddr", bValue ) ) { pClient->SetUseDefaultCentralServerAddress ( bValue ); } // window position of the main window pClient->vecWindowPosMain = QByteArray().fromBase64 ( GetIniSetting ( IniXMLDocument, "client", "winposmain" ).toLatin1() ); // window position of the settings window pClient->vecWindowPosSettings = QByteArray().fromBase64 ( GetIniSetting ( IniXMLDocument, "client", "winposset" ).toLatin1() ); // window position of the chat window pClient->vecWindowPosChat = QByteArray().fromBase64 ( GetIniSetting ( IniXMLDocument, "client", "winposchat" ).toLatin1() ); // window position of the connect window pClient->vecWindowPosConnect = QByteArray().fromBase64 ( GetIniSetting ( IniXMLDocument, "client", "winposcon" ).toLatin1() ); // visibility state of the settings window if ( GetFlagIniSet ( IniXMLDocument, "client", "winvisset", bValue ) ) { pClient->bWindowWasShownSettings = bValue; } // visibility state of the chat window if ( GetFlagIniSet ( IniXMLDocument, "client", "winvischat", bValue ) ) { pClient->bWindowWasShownChat = bValue; } // visibility state of the connect window if ( GetFlagIniSet ( IniXMLDocument, "client", "winviscon", bValue ) ) { pClient->bWindowWasShownConnect = bValue; } } else { // server: // central server address pServer->SetServerListCentralServerAddress ( GetIniSetting ( IniXMLDocument, "server", "centralservaddr" ) ); // use default central server address flag if ( GetFlagIniSet ( IniXMLDocument, "server", "defcentservaddr", bValue ) ) { pServer->SetUseDefaultCentralServerAddress ( bValue ); } // server list enabled flag if ( GetFlagIniSet ( IniXMLDocument, "server", "servlistenabled", bValue ) ) { pServer->SetServerListEnabled ( bValue ); } // name pServer->SetServerName ( GetIniSetting ( IniXMLDocument, "server", "name" ) ); // city pServer->SetServerCity ( GetIniSetting ( IniXMLDocument, "server", "city" ) ); // country if ( GetNumericIniSet ( IniXMLDocument, "server", "country", 0, static_cast<int> ( QLocale::LastCountry ), iValue ) ) { pServer->SetServerCountry ( static_cast<QLocale::Country> ( iValue ) ); } // start minimized on OS start if ( GetFlagIniSet ( IniXMLDocument, "server", "autostartmin", bValue ) ) { pServer->SetAutoRunMinimized ( bValue ); } } }