void LDAPConnectionTest::ConnectionTest() { StartTrace(LDAPConnectionTest.ConnectionTest); ROAnything cConfig; AnyExtensions::Iterator<ROAnything> aEntryIterator(GetTestCaseConfig()); while ( aEntryIterator.Next(cConfig) ) { for ( long l = 0; l < cConfig["NumberOfConnects"].AsLong(1); l++ ) { Anything params; params["Server"] = cConfig["LDAPServer"].AsString(); params["Port"] = cConfig["LDAPPort"].AsLong(); params["Timeout"] = cConfig["LDAPTimeout"].AsLong(); params["ConnectionTimeout"] = cConfig["LDAPConnectionTimeout"].AsLong(0); params["BindName"] = cConfig["LDAPBindName"].AsString(); params["BindPW"] = cConfig["LDAPBindPW"].AsString(); params["PooledConnections"] = cConfig["LDAPPooledConnections"].AsLong(0L); params["RebindTimeout"] = cConfig["LDAPRebindTimeout"].AsLong(3600L); params["TryAutoRebind"] = cConfig["LDAPTryAutoRebind"].AsLong(0L); params["MaxConnections"] = cConfig["LDAPMaxConnections"].AsLong(2L); Context ctx; ParameterMapper pm("ConnectionTestParameterMapper"); ResultMapper rm("ConnectionTestResultMapper"); pm.Initialize("ParameterMapper"); rm.Initialize("ResultMapper"); String da("DataAccess_"); da << aEntryIterator.Index(); LDAPErrorHandler eh(ctx, &pm, &rm, da); eh.PutConnectionParams(params); // connect LDAPConnection lc(params); LDAPConnection::EConnectState eConnectState = lc.DoConnect(params, eh); String result(LDAPConnection::ConnectRetToString(eConnectState)); Trace("Connect result: " << result); // check for errors Anything error; if ( !eh.GetError(error) ) { Trace("No error reported."); } else { TraceAny(error, "Error description:"); } // compare result and expected error assertEqual(cConfig["ConnectRet"].AsString(), result); bool ret = LDAPConnection::IsConnectOk(eConnectState); assertEqual(cConfig["ConnectIsOk"].AsBool(1), ret); if (!ret) { String where; aEntryIterator.SlotName(where); assertAnyCompareEqual(cConfig["Error"], error, String(getConfigFileName()) << ":" << where, '.',':'); } // now release sema and lock lc.ReleaseHandleInfo(); } } }
int writeConfValue(const string& name, const string& value) { std::string confFileName = getConfigFileName(); std::string conf = std::string(readFile(const_cast<char*> (confFileName.c_str()))); conf = replaceValue(conf, name, value); int res = writeFile(confFileName, conf, false); return res; }
bool AppConfig::save() { DataTree cfg; cfg.rootNode()->setName("cubicsdr_config"); if (winW.load() && winH.load()) { DataNode *window_node = cfg.rootNode()->newChild("window"); *window_node->newChild("x") = winX.load(); *window_node->newChild("y") = winY.load(); *window_node->newChild("w") = winW.load(); *window_node->newChild("h") = winH.load(); *window_node->newChild("max") = winMax.load(); *window_node->newChild("theme") = themeId.load(); *window_node->newChild("snap") = snap.load(); *window_node->newChild("center_freq") = centerFreq.load(); *window_node->newChild("waterfall_lps") = waterfallLinesPerSec.load(); *window_node->newChild("spectrum_avg") = spectrumAvgSpeed.load(); } DataNode *devices_node = cfg.rootNode()->newChild("devices"); std::map<std::string, DeviceConfig *>::iterator device_config_i; for (device_config_i = deviceConfig.begin(); device_config_i != deviceConfig.end(); device_config_i++) { DataNode *device_node = devices_node->newChild("device"); device_config_i->second->save(device_node); } if (manualDevices.size()) { DataNode *manual_node = cfg.rootNode()->newChild("manual_devices"); for (std::vector<SDRManualDef>::const_iterator i = manualDevices.begin(); i != manualDevices.end(); i++) { DataNode *rig_node = manual_node->newChild("device"); *rig_node->newChild("factory") = i->factory; *rig_node->newChild("params") = i->params; } } #ifdef USE_HAMLIB DataNode *rig_node = cfg.rootNode()->newChild("rig"); *rig_node->newChild("model") = rigModel.load(); *rig_node->newChild("rate") = rigRate.load(); *rig_node->newChild("port") = rigPort; #endif std::string cfgFileName = getConfigFileName(); if (!cfg.SaveToFileXML(cfgFileName)) { std::cout << "Error saving :: configuration file '" << cfgFileName << "' is not writable!" << std::endl; return false; } return true; }
char* readConfValue(const string& name, const char* def) { std::string confFileName = getConfigFileName(); char* conf = readFile(const_cast<char*> (confFileName.c_str())); char* res = readValue(string(conf), name); if (strlen(res) == 0) { free(res); res = strcpy(def); } free(conf); return res; }
wxFileConfig* Config::getConfig() const { if (!configM) { wxFileName configFileName = getConfigFileName(); if (!wxDirExists(configFileName.GetPath())) wxMkdir(configFileName.GetPath()); configM = new wxFileConfig("", "", configFileName.GetFullPath(), "", wxCONFIG_USE_LOCAL_FILE); configM->SetExpandEnvVars(false); } return configM; }
HINSTANCE initConfig(){ HINSTANCE l_rc = 0; DWORD dw_rc; DWORD dwSize; HINSTANCE hSetupAPI = LoadLibrary(_T("SETUPAPI.DLL")); if (hSetupAPI == 0){ return 0;//abort } lpfnLPSETUPDIOPENDEVREGKEY = reinterpret_cast<SETUPDIOPENDEVREGKEY*>(GetProcAddress(hSetupAPI, "SetupDiOpenDevRegKey")); lpfnSETUPDIGETCLASSDEVS = reinterpret_cast<SETUPDIGETCLASSDEVS*>(GetProcAddress(hSetupAPI, "SetupDiGetClassDevsA")); lpfnSETUPDIDESTROYDEVICEINFOLIST = reinterpret_cast<SETUPDIDESTROYDEVICEINFOLIST*>(GetProcAddress(hSetupAPI, "SetupDiDestroyDeviceInfoList")); lpfnSETUPDIENUMDEVICEINFO = reinterpret_cast<SETUPDIENUMDEVICEINFO*>(GetProcAddress(hSetupAPI, "SetupDiEnumDeviceInfo")); lpfnSETUPDICLASSGUIDSFROMNAME = reinterpret_cast<SETUPDICLASSGUIDSFROMNAME*>(GetProcAddress(hSetupAPI, "SetupDiClassGuidsFromNameA")); lpfnSETUPDIGETDEVICEREGISTRYPROPERTY = reinterpret_cast<SETUPDIGETDEVICEREGISTRYPROPERTY*>(GetProcAddress(hSetupAPI, "SetupDiGetDeviceRegistryPropertyA")); if (lpfnLPSETUPDIOPENDEVREGKEY ==0 || lpfnSETUPDIGETCLASSDEVS==0 || lpfnSETUPDIDESTROYDEVICEINFOLIST==0|| lpfnSETUPDIENUMDEVICEINFO==0|| lpfnSETUPDICLASSGUIDSFROMNAME==0|| lpfnSETUPDIGETDEVICEREGISTRYPROPERTY==0){ hSetupAPI = 0; } libApiDLL = hSetupAPI; l_rc = (HINSTANCE)1; if (hSetupAPI){//last step was ok //get the directory of this executable dwSize = sizeof(modulePath)/sizeof(TCHAR); dw_rc = GetModuleFileNameW(0,modulePath,dwSize); if (dw_rc == (dwSize-1)){//buffer could be to small l_rc =0;//error } if (GetLastError()==ERROR_INSUFFICIENT_BUFFER){//buffer to small, log it l_rc =0;//error } if (dw_rc ==0){//error log it l_rc =0;//error } if (l_rc ==0){//application dialog error MessageBox(NULL,_T("The application could not determine the location of the working directory of this executable"),_T("FATAL ERROR!"),MB_ICONHAND|MB_APPLMODAL); } getLogFileName(); getConfigFileName(); reOpenFiles(); cacheConfigFile(); } return l_rc; }
//---- NewRendererTest ---------------------------------------------------------------- void NewRendererTest::TestCases() { StartTrace(NewRendererTest.TestCases); if (t_assertm( !GetTestCaseConfig().IsNull(), "no Tests configured!" )) { Server *theServer = Server::FindServer("Server"); t_assert(theServer != NULL); Context ctx; Session theSession("TestSession"); Page *thePage = Page::FindPage("TestPage"); t_assert(thePage != NULL); Role *theRole = Role::FindRole("TestRole"); t_assert(theRole != NULL); theSession.Init("TestSession", ctx); AnyExtensions::Iterator<ROAnything, ROAnything, TString> aEntryIterator(GetTestCaseConfig()); ROAnything roaCaseConfig; t_assertm( GetConfig()["RunOnly"].GetSize() == 0L, "running only subset of tests"); TraceAny(GetConfig()["RunOnly"], "run only config") while (aEntryIterator.Next(roaCaseConfig)) { TString slotToCheck; aEntryIterator.SlotName(slotToCheck); Trace("current testslot [" << slotToCheck << "]"); if ((GetConfig()["RunOnly"].GetSize() == 0L) || GetConfig()["RunOnly"].Contains((const char *) slotToCheck)) { std::cerr << "."; TString message; message << getConfigFileName() << ".any:0 at " << name(); if (slotToCheck.Length()) { message << "." << slotToCheck; } else { message << ":" << aEntryIterator.Index(); } Context c(GetConfig()["EnvForAllCases"].DeepClone(), roaCaseConfig["Env"].DeepClone(), theServer, &theSession, theRole, thePage); coast::testframework::PutInStore(roaCaseConfig["TmpStore"], c.GetTmpStore()); coast::testframework::PutInStore(roaCaseConfig["SessionStore"], c.GetSessionStore()); TraceAny(roaCaseConfig["Renderer"], "running renderer at [" << slotToCheck << "]"); String result("["); String expected("["); expected << roaCaseConfig["Expected"].AsCharPtr("") << "]"; { OStringStream reply(result); Renderer::Render(reply, c, roaCaseConfig["Renderer"]); reply.flush(); } result.Append(']'); // message << ":\n" << result; assertEqualm(expected, result, message); } } }
unsigned int ccsAddConfigWatch (CCSContext *context, FileWatchCallbackProc callback) { unsigned int ret; char *fileName; fileName = getConfigFileName(); if (!fileName) return 0; ret = ccsAddFileWatch (fileName, TRUE, callback, context); free (fileName); return ret; }
static IniDictionary* getConfigFile (void) { char *fileName; IniDictionary *iniFile; fileName = getConfigFileName(); if (!fileName) return NULL; iniFile = ccsIniOpen (fileName); free (fileName); return iniFile; }
bool AppConfig::save() { DataTree cfg; cfg.rootNode()->setName("cubicsdr_config"); if (winW.load() && winH.load()) { DataNode *window_node = cfg.rootNode()->newChild("window"); *window_node->newChild("x") = winX.load(); *window_node->newChild("y") = winY.load(); *window_node->newChild("w") = winW.load(); *window_node->newChild("h") = winH.load(); *window_node->newChild("max") = winMax.load(); *window_node->newChild("theme") = themeId.load(); *window_node->newChild("snap") = snap.load(); *window_node->newChild("center_freq") = centerFreq.load(); } DataNode *devices_node = cfg.rootNode()->newChild("devices"); std::map<std::string, DeviceConfig *>::iterator device_config_i; for (device_config_i = deviceConfig.begin(); device_config_i != deviceConfig.end(); device_config_i++) { DataNode *device_node = devices_node->newChild("device"); device_config_i->second->save(device_node); } std::string cfgFileName = getConfigFileName(); if (!cfg.SaveToFileXML(cfgFileName)) { std::cout << "Error saving :: configuration file '" << cfgFileName << "' is not writable!" << std::endl; return false; } return true; }
void PGLoader::load(const string& p_data /*= Util::emptyString*/) { string l_data; const string l_url = SETTING(URL_IPTRUST); bool l_is_download = false; CFlyLog l_IPTrust_log("[IPTrust]"); if (p_data.empty()) { if (!l_url.empty()) { try { const string l_log_message = STRING(DOWNLOAD) + ": " + l_url; if (Util::getDataFromInet(true, l_url, l_data, 0) == 0) { l_IPTrust_log.step(l_log_message + " [" + STRING(ERROR_STRING) + ']'); } else { l_IPTrust_log.step(l_log_message + " [OK]"); // "распарсим" ответ (TODO - перейти на regexp) { string::size_type linestart = 0; string::size_type lineend = 0; for (;;) { lineend = l_data.find('\n', linestart); if (lineend == string::npos) break; const string line = l_data.substr(linestart, lineend - linestart - 1); int u1, u2, u3, u4, u5, u6, u7, u8; int iItems = sscanf_s(line.c_str(), "%u.%u.%u.%u - %u.%u.%u.%u", &u1, &u2, &u3, &u4, &u5, &u6, &u7, &u8); if (iItems == 8 || iItems == 4) { l_is_download = true; break; } iItems = sscanf_s(line.c_str(), "#%u.%u.%u.%u - %u.%u.%u.%u", &u1, &u2, &u3, &u4, &u5, &u6, &u7, &u8); if (iItems == 8 || iItems == 4) { l_is_download = true; break; } linestart = lineend + 1; } } if (l_is_download) { const auto l_IPTrust_ini = getConfigFileName(); File(l_IPTrust_ini, File::WRITE, File::CREATE | File::TRUNCATE).write(l_data); l_IPTrust_log.step(l_IPTrust_ini + " [" + STRING(SAVE) + ']'); } } } catch (const FileException& e) { l_IPTrust_log.step("Can't write IPTrust.ini file: " + e.getError()); dcdebug("IPTrust::save: %s\n", e.getError().c_str()); } } if (l_data.empty()) { const string l_IPTrust_ini = getConfigFileName(); if (File::isExist(l_IPTrust_ini)) { try { l_data = File(l_IPTrust_ini, File::READ, File::OPEN).read(); } catch (const FileException& e) { l_IPTrust_log.step("Can't read IPTrust.ini file: " + e.getError()); dcdebug("IPTrust::load: %s\n", e.getError().c_str()); } } else { Util::WriteTextResourceToFile(IDR_IPTRUST_EXAMPLE, Text::toT(l_IPTrust_ini)); l_IPTrust_log.step("IPTrust.ini restored from internal resources"); } } } else { l_data = p_data; } CFlyFastLock(g_cs); l_IPTrust_log.step("parse IPTrust.ini"); g_ipTrustListAllow.clear(); g_ipTrustListBlock.clear(); if (!l_data.empty()) { string::size_type linestart = 0; string::size_type lineend = 0; for (;;) { lineend = l_data.find('\n', linestart); if (lineend == string::npos) { string l_line = l_data.substr(linestart); addLine(l_line, l_IPTrust_log); break; } else { string l_line = l_data.substr(linestart, lineend - linestart - 1); addLine(l_line, l_IPTrust_log); linestart = lineend + 1; } } } l_IPTrust_log.step("parse IPTrust.ini done"); }
void Config::save() const { char filename[MAX_STRING_SIZE]; getConfigFileName(filename, MAX_STRING_SIZE); saveConfig(filename); }
void Config::init() { maxstringsize = MAX_STRING_SIZE; //for ui //defaults cfg.SampleRate = 44100; cfg.SoundBufferSize = 256; cfg.OscilSize = 1024; cfg.SwapStereo = 0; cfg.oss_devs.linux_wave_out = new char[MAX_STRING_SIZE]; snprintf(cfg.oss_devs.linux_wave_out, MAX_STRING_SIZE, "/dev/dsp"); cfg.oss_devs.linux_seq_in = new char[MAX_STRING_SIZE]; snprintf(cfg.oss_devs.linux_seq_in, MAX_STRING_SIZE, "/dev/sequencer"); cfg.WindowsWaveOutId = 0; cfg.WindowsMidiInId = 0; cfg.BankUIAutoClose = 0; cfg.GzipCompression = 3; cfg.Interpolation = 0; cfg.CheckPADsynth = 1; cfg.IgnoreProgramChange = 0; cfg.UserInterfaceMode = 0; cfg.VirKeybLayout = 1; winwavemax = 1; winmidimax = 1; //try to find out how many input midi devices are there winmididevices = new winmidionedevice[winmidimax]; for(int i = 0; i < winmidimax; ++i) { winmididevices[i].name = new char[MAX_STRING_SIZE]; for(int j = 0; j < MAX_STRING_SIZE; ++j) winmididevices[i].name[j] = '\0'; } //get the midi input devices name cfg.currentBankDir = "./testbnk"; char filename[MAX_STRING_SIZE]; getConfigFileName(filename, MAX_STRING_SIZE); readConfig(filename); if(cfg.bankRootDirList[0].empty()) { //banks cfg.bankRootDirList[0] = "~/banks"; cfg.bankRootDirList[1] = "./"; cfg.bankRootDirList[2] = "/usr/share/zynaddsubfx/banks"; cfg.bankRootDirList[3] = "/usr/local/share/zynaddsubfx/banks"; #ifdef __APPLE__ cfg.bankRootDirList[4] = "../Resources/banks"; #else cfg.bankRootDirList[4] = "../banks"; #endif cfg.bankRootDirList[5] = "banks"; } if(cfg.presetsDirList[0].empty()) { //presets cfg.presetsDirList[0] = "./"; #ifdef __APPLE__ cfg.presetsDirList[1] = "../Resources/presets"; #else cfg.presetsDirList[1] = "../presets"; #endif cfg.presetsDirList[2] = "presets"; cfg.presetsDirList[3] = "/usr/share/zynaddsubfx/presets"; cfg.presetsDirList[4] = "/usr/local/share/zynaddsubfx/presets"; } cfg.LinuxALSAaudioDev = "default"; cfg.nameTag = ""; }
bool AppConfig::load() { DataTree cfg; std::string cfgFileDir = getConfigDir(); std::string cfgFileName = getConfigFileName(); wxFileName cfgFile = wxFileName(cfgFileName); if (!cfgFile.Exists()) { if (configName.length()) { wxFileName baseConfig = wxFileName(getConfigFileName(true)); if (baseConfig.Exists()) { std::string baseConfigFileName = baseConfig.GetFullPath(wxPATH_NATIVE).ToStdString(); std::cout << "Creating new configuration file '" << cfgFileName << "' by copying '" << baseConfigFileName << "'.."; wxCopyFile(baseConfigFileName, cfgFileName); if (!cfgFile.Exists()) { std::cout << "failed." << std::endl; return true; } std::cout << "ok." << std::endl; } else { return true; } } else { return true; } } if (cfgFile.IsFileReadable()) { std::cout << "Loading:: configuration file '" << cfgFileName << "'" << std::endl; cfg.LoadFromFileXML(cfgFileName); } else { std::cout << "Error loading:: configuration file '" << cfgFileName << "' is not readable!" << std::endl; return false; } if (cfg.rootNode()->hasAnother("window")) { int x,y,w,h; int max; DataNode *win_node = cfg.rootNode()->getNext("window"); if (win_node->hasAnother("w") && win_node->hasAnother("h") && win_node->hasAnother("x") && win_node->hasAnother("y")) { win_node->getNext("x")->element()->get(x); win_node->getNext("y")->element()->get(y); win_node->getNext("w")->element()->get(w); win_node->getNext("h")->element()->get(h); winX.store(x); winY.store(y); winW.store(w); winH.store(h); } if (win_node->hasAnother("max")) { win_node->getNext("max")->element()->get(max); winMax.store(max?true:false); } if (win_node->hasAnother("theme")) { int theme; win_node->getNext("theme")->element()->get(theme); themeId.store(theme); } if (win_node->hasAnother("snap")) { long long snapVal; win_node->getNext("snap")->element()->get(snapVal); snap.store(snapVal); } if (win_node->hasAnother("center_freq")) { long long freqVal; win_node->getNext("center_freq")->element()->get(freqVal); centerFreq.store(freqVal); } } if (cfg.rootNode()->hasAnother("devices")) { DataNode *devices_node = cfg.rootNode()->getNext("devices"); while (devices_node->hasAnother("device")) { DataNode *device_node = devices_node->getNext("device"); if (device_node->hasAnother("id")) { std::string deviceId; device_node->getNext("id")->element()->get(deviceId); getDevice(deviceId)->load(device_node); } } } return true; }
Bool ccsWriteConfig (ConfigOption option, char *value) { IniDictionary *iniFile; char *entry = NULL; char *section; char *fileName; char *curVal; Bool changed = TRUE; /* don't change config if nothing changed */ if (ccsReadConfig (option, &curVal)) { changed = (strcmp (value, curVal) != 0); free (curVal); } if (!changed) return TRUE; iniFile = getConfigFile(); if (!iniFile) return FALSE; switch (option) { case OptionProfile: entry = "profile"; break; case OptionBackend: entry = "backend"; break; case OptionIntegration: entry = "integration"; break; case OptionAutoSort: entry = "plugin_list_autosort"; break; default: break; } if (!entry) { ccsIniClose (iniFile); return FALSE; } section = getSectionName(); ccsIniSetString (iniFile, section, entry, value); free (section); fileName = getConfigFileName(); if (!fileName) { ccsIniClose (iniFile); return FALSE; } ccsIniSave (iniFile, fileName); ccsIniClose (iniFile); free (fileName); return TRUE; }
bool AppConfig::load() { DataTree cfg; std::string cfgFileDir = getConfigDir(); std::string cfgFileName = getConfigFileName(); wxFileName cfgFile = wxFileName(cfgFileName); if (!cfgFile.Exists()) { if (configName.length()) { wxFileName baseConfig = wxFileName(getConfigFileName(true)); if (baseConfig.Exists()) { std::string baseConfigFileName = baseConfig.GetFullPath(wxPATH_NATIVE).ToStdString(); std::cout << "Creating new configuration file '" << cfgFileName << "' by copying '" << baseConfigFileName << "'.."; wxCopyFile(baseConfigFileName, cfgFileName); if (!cfgFile.Exists()) { std::cout << "failed." << std::endl; return true; } std::cout << "ok." << std::endl; } else { return true; } } else { return true; } } if (cfgFile.IsFileReadable()) { std::cout << "Loading:: configuration file '" << cfgFileName << "'" << std::endl; cfg.LoadFromFileXML(cfgFileName); } else { std::cout << "Error loading:: configuration file '" << cfgFileName << "' is not readable!" << std::endl; return false; } if (cfg.rootNode()->hasAnother("window")) { int x,y,w,h; int max; DataNode *win_node = cfg.rootNode()->getNext("window"); if (win_node->hasAnother("w") && win_node->hasAnother("h") && win_node->hasAnother("x") && win_node->hasAnother("y")) { win_node->getNext("x")->element()->get(x); win_node->getNext("y")->element()->get(y); win_node->getNext("w")->element()->get(w); win_node->getNext("h")->element()->get(h); winX.store(x); winY.store(y); winW.store(w); winH.store(h); } if (win_node->hasAnother("max")) { win_node->getNext("max")->element()->get(max); winMax.store(max?true:false); } if (win_node->hasAnother("theme")) { int theme; win_node->getNext("theme")->element()->get(theme); themeId.store(theme); } if (win_node->hasAnother("snap")) { long long snapVal; win_node->getNext("snap")->element()->get(snapVal); snap.store(snapVal); } if (win_node->hasAnother("center_freq")) { long long freqVal; win_node->getNext("center_freq")->element()->get(freqVal); centerFreq.store(freqVal); } if (win_node->hasAnother("waterfall_lps")) { int lpsVal; win_node->getNext("waterfall_lps")->element()->get(lpsVal); waterfallLinesPerSec.store(lpsVal); } if (win_node->hasAnother("spectrum_avg")) { float avgVal; win_node->getNext("spectrum_avg")->element()->get(avgVal); spectrumAvgSpeed.store(avgVal); } } if (cfg.rootNode()->hasAnother("devices")) { DataNode *devices_node = cfg.rootNode()->getNext("devices"); while (devices_node->hasAnother("device")) { DataNode *device_node = devices_node->getNext("device"); if (device_node->hasAnother("id")) { std::string deviceId = device_node->getNext("id")->element()->toString(); getDevice(deviceId)->load(device_node); } } } if (cfg.rootNode()->hasAnother("manual_devices")) { DataNode *manuals_node = cfg.rootNode()->getNext("manual_devices"); while (manuals_node->hasAnother("device")) { DataNode *manual_node = manuals_node->getNext("device"); if (manual_node->hasAnother("factory") && manual_node->hasAnother("params")) { SDRManualDef mdef; mdef.factory = manual_node->getNext("factory")->element()->toString(); mdef.params = manual_node->getNext("params")->element()->toString(); manualDevices.push_back(mdef); } } } #ifdef USE_HAMLIB if (cfg.rootNode()->hasAnother("rig")) { DataNode *rig_node = cfg.rootNode()->getNext("rig"); if (rig_node->hasAnother("model")) { int loadModel; rig_node->getNext("model")->element()->get(loadModel); rigModel.store(loadModel?loadModel:1); } if (rig_node->hasAnother("rate")) { int loadRate; rig_node->getNext("rate")->element()->get(loadRate); rigRate.store(loadRate?loadRate:57600); } if (rig_node->hasAnother("port")) { rigPort = rig_node->getNext("port")->element()->toString(); } } #endif return true; }
int getUserDirs( std::map<CollectionItemType const, std::string> * const userDirs, KIM::Log * const log) { std::vector<std::string> configFile(getConfigFileName()); std::ifstream cfl; cfl.open(configFile[0].c_str(), std::ifstream::in); if (!cfl) { // unable to open file; create with default locations size_t const pos = configFile[0].find_last_of('/'); std::string const path = configFile[0].substr(0, pos); // std::string const name = configFile[0].substr(pos+1); // NOT USED std::ofstream fl; if (makeDirWrapper(path.c_str(), 0755)) return true; (*userDirs)[KIM_MODEL_DRIVERS] = ProcessConfigFileDirectoryString( KIM_USER_MODEL_DRIVER_PLURAL_DIR_DEFAULT); (*userDirs)[KIM_MODELS] = ProcessConfigFileDirectoryString(KIM_USER_MODEL_PLURAL_DIR_DEFAULT); (*userDirs)[KIM_SIMULATOR_MODELS] = ProcessConfigFileDirectoryString( KIM_USER_SIMULATOR_MODEL_PLURAL_DIR_DEFAULT); if (makeDirWrapper((*userDirs)[KIM_MODEL_DRIVERS].c_str(), 0755)) return true; if (makeDirWrapper((*userDirs)[KIM_MODELS].c_str(), 0755)) return true; if (makeDirWrapper((*userDirs)[KIM_SIMULATOR_MODELS].c_str(), 0755)) return true; fl.open(configFile[0].c_str(), std::ofstream::out); fl << KIM_MODEL_DRIVER_PLURAL_DIR_IDENTIFIER " = " KIM_USER_MODEL_DRIVER_PLURAL_DIR_DEFAULT "\n"; fl << KIM_MODEL_PLURAL_DIR_IDENTIFIER " = " KIM_USER_MODEL_PLURAL_DIR_DEFAULT "\n"; fl << KIM_SIMULATOR_MODEL_PLURAL_DIR_IDENTIFIER " = " KIM_USER_SIMULATOR_MODEL_PLURAL_DIR_DEFAULT "\n"; fl.close(); } else { char line[LINELEN]; if ((!cfl.getline(line, LINELEN)) || (ProcessConfigFileLine(line, configFile[0], KIM_MODEL_DRIVER_PLURAL_DIR_IDENTIFIER, (*userDirs)[KIM_MODEL_DRIVERS], log))) goto cleanUp; if ((!cfl.getline(line, LINELEN)) || (ProcessConfigFileLine(line, configFile[0], KIM_MODEL_PLURAL_DIR_IDENTIFIER, (*userDirs)[KIM_MODELS], log))) goto cleanUp; if ((!cfl.getline(line, LINELEN)) || (ProcessConfigFileLine(line, configFile[0], KIM_SIMULATOR_MODEL_PLURAL_DIR_IDENTIFIER, (*userDirs)[KIM_SIMULATOR_MODELS], log))) goto cleanUp; cleanUp: cfl.close(); } return false; }
void Config::init(){ maxstringsize=MAX_STRING_SIZE;//for ui //defaults cfg.SampleRate=44100; cfg.SoundBufferSize=256; cfg.OscilSize=512; cfg.SwapStereo=0; cfg.LinuxOSSWaveOutDev=new char[MAX_STRING_SIZE]; snprintf(cfg.LinuxOSSWaveOutDev,MAX_STRING_SIZE,"/dev/dsp"); cfg.LinuxOSSSeqInDev=new char[MAX_STRING_SIZE]; snprintf(cfg.LinuxOSSSeqInDev,MAX_STRING_SIZE,"/dev/sequencer"); cfg.DumpFile=new char[MAX_STRING_SIZE]; snprintf(cfg.DumpFile,MAX_STRING_SIZE,"zynaddsubfx_dump.txt"); cfg.WindowsWaveOutId=0; cfg.WindowsMidiInId=0; cfg.BankUIAutoClose=0; cfg.DumpNotesToFile=0; cfg.DumpAppend=1; cfg.GzipCompression=3; cfg.Interpolation=0; cfg.CheckPADsynth=1; cfg.UserInterfaceMode=0; cfg.VirKeybLayout=1; winwavemax=1;winmidimax=1; //try to find out how many input midi devices are there #ifdef WINMIDIIN winmidimax=midiInGetNumDevs(); if (winmidimax==0) winmidimax=1; #endif winmididevices=new winmidionedevice[winmidimax]; for (int i=0;i<winmidimax;i++) { winmididevices[i].name=new char[MAX_STRING_SIZE]; for (int j=0;j<MAX_STRING_SIZE;j++) winmididevices[i].name[j]='\0'; }; //get the midi input devices name #ifdef WINMIDIIN MIDIINCAPS midiincaps; for (int i=0;i<winmidimax;i++){ if (! midiInGetDevCaps(i,&midiincaps,sizeof(MIDIINCAPS))) snprintf(winmididevices[i].name,MAX_STRING_SIZE,"%s",midiincaps.szPname); }; #endif for (int i=0;i<MAX_BANK_ROOT_DIRS;i++) cfg.bankRootDirList[i]=NULL; cfg.currentBankDir=new char[MAX_STRING_SIZE]; sprintf(cfg.currentBankDir,"./testbnk"); for (int i=0;i<MAX_BANK_ROOT_DIRS;i++) cfg.presetsDirList[i]=NULL; char filename[MAX_STRING_SIZE]; getConfigFileName(filename,MAX_STRING_SIZE); readConfig(filename); if (cfg.bankRootDirList[0]==NULL){ #if defined(OS_LINUX) //banks cfg.bankRootDirList[0]=new char[MAX_STRING_SIZE]; sprintf(cfg.bankRootDirList[0],"~/banks"); cfg.bankRootDirList[1]=new char[MAX_STRING_SIZE]; sprintf(cfg.bankRootDirList[1],"./"); cfg.bankRootDirList[2]=new char[MAX_STRING_SIZE]; sprintf(cfg.bankRootDirList[2],"/usr/share/zynaddsubfx/banks"); cfg.bankRootDirList[3]=new char[MAX_STRING_SIZE]; sprintf(cfg.bankRootDirList[3],"/usr/local/share/zynaddsubfx/banks"); cfg.bankRootDirList[4]=new char[MAX_STRING_SIZE]; sprintf(cfg.bankRootDirList[4],"../banks"); cfg.bankRootDirList[5]=new char[MAX_STRING_SIZE]; sprintf(cfg.bankRootDirList[5],"banks"); #else //banks cfg.bankRootDirList[0]=new char[MAX_STRING_SIZE]; sprintf(cfg.bankRootDirList[0],"./"); #ifdef VSTAUDIOOUT cfg.bankRootDirList[1]=new char[MAX_STRING_SIZE]; sprintf(cfg.bankRootDirList[1],"c:/Program Files/ZynAddSubFX/banks"); #else cfg.bankRootDirList[1]=new char[MAX_STRING_SIZE]; sprintf(cfg.bankRootDirList[1],"../banks"); #endif cfg.bankRootDirList[2]=new char[MAX_STRING_SIZE]; sprintf(cfg.bankRootDirList[2],"banks"); #endif }; if (cfg.presetsDirList[0]==NULL){ #if defined(OS_LINUX) //presets cfg.presetsDirList[0]=new char[MAX_STRING_SIZE]; sprintf(cfg.presetsDirList[0],"./"); cfg.presetsDirList[1]=new char[MAX_STRING_SIZE]; sprintf(cfg.presetsDirList[1],"../presets"); cfg.presetsDirList[2]=new char[MAX_STRING_SIZE]; sprintf(cfg.presetsDirList[2],"presets"); cfg.presetsDirList[3]=new char[MAX_STRING_SIZE]; sprintf(cfg.presetsDirList[3],"/usr/share/zynaddsubfx/presets"); cfg.presetsDirList[4]=new char[MAX_STRING_SIZE]; sprintf(cfg.presetsDirList[4],"/usr/local/share/zynaddsubfx/presets"); #else //presets cfg.presetsDirList[0]=new char[MAX_STRING_SIZE]; sprintf(cfg.presetsDirList[0],"./"); #ifdef VSTAUDIOOUT cfg.presetsDirList[1]=new char[MAX_STRING_SIZE]; sprintf(cfg.presetsDirList[1],"c:/Program Files/ZynAddSubFX/presets"); #else cfg.presetsDirList[1]=new char[MAX_STRING_SIZE]; sprintf(cfg.presetsDirList[1],"../presets"); #endif cfg.presetsDirList[2]=new char[MAX_STRING_SIZE]; sprintf(cfg.presetsDirList[2],"presets"); #endif }; };
bool AppConfig::load() { DataTree cfg; std::string cfgFileDir = getConfigDir(); std::string cfgFileName = getConfigFileName(); wxFileName cfgFile = wxFileName(cfgFileName); if (!cfgFile.Exists()) { if (configName.length()) { wxFileName baseConfig = wxFileName(getConfigFileName(true)); if (baseConfig.Exists()) { std::string baseConfigFileName = baseConfig.GetFullPath(wxPATH_NATIVE).ToStdString(); std::cout << "Creating new configuration file '" << cfgFileName << "' by copying '" << baseConfigFileName << "'.."; wxCopyFile(baseConfigFileName, cfgFileName); if (!cfgFile.Exists()) { std::cout << "failed." << std::endl; return true; } std::cout << "ok." << std::endl; } else { return true; } } else { return true; } } if (cfgFile.IsFileReadable()) { std::cout << "Loading:: configuration file '" << cfgFileName << "'" << std::endl; cfg.LoadFromFileXML(cfgFileName); } else { std::cout << "Error loading:: configuration file '" << cfgFileName << "' is not readable!" << std::endl; return false; } if (cfg.rootNode()->hasAnother("window")) { int x = 0 ,y = 0 ,w = 0 ,h = 0; int max = 0 ,tips = 0 ,perf_mode = 0 ,mpc = 0; DataNode *win_node = cfg.rootNode()->getNext("window"); if (win_node->hasAnother("w") && win_node->hasAnother("h") && win_node->hasAnother("x") && win_node->hasAnother("y")) { win_node->getNext("x")->element()->get(x); win_node->getNext("y")->element()->get(y); win_node->getNext("w")->element()->get(w); win_node->getNext("h")->element()->get(h); winX.store(x); winY.store(y); winW.store(w); winH.store(h); } if (win_node->hasAnother("max")) { win_node->getNext("max")->element()->get(max); winMax.store(max?true:false); } if (win_node->hasAnother("tips")) { win_node->getNext("tips")->element()->get(tips); showTips.store(tips?true:false); } // default: perfMode.store(PERF_NORMAL); if (win_node->hasAnother("perf_mode")) { win_node->getNext("perf_mode")->element()->get(perf_mode); if (perf_mode == (int)PERF_LOW) { perfMode.store(PERF_LOW); } else if (perf_mode == (int)PERF_HIGH) { perfMode.store(PERF_HIGH); } } if (win_node->hasAnother("theme")) { int theme; win_node->getNext("theme")->element()->get(theme); themeId.store(theme); } if (win_node->hasAnother("font_scale")) { int fscale; win_node->getNext("font_scale")->element()->get(fscale); fontScale.store(fscale); } if (win_node->hasAnother("snap")) { long long snapVal; win_node->getNext("snap")->element()->get(snapVal); snap.store(snapVal); } if (win_node->hasAnother("center_freq")) { long long freqVal; win_node->getNext("center_freq")->element()->get(freqVal); centerFreq.store(freqVal); } if (win_node->hasAnother("waterfall_lps")) { int lpsVal; win_node->getNext("waterfall_lps")->element()->get(lpsVal); waterfallLinesPerSec.store(lpsVal); } if (win_node->hasAnother("spectrum_avg")) { float avgVal; win_node->getNext("spectrum_avg")->element()->get(avgVal); spectrumAvgSpeed.store(avgVal); } if (win_node->hasAnother("modemprops_collapsed")) { win_node->getNext("modemprops_collapsed")->element()->get(mpc); modemPropsCollapsed.store(mpc?true:false); } if (win_node->hasAnother("db_offset")) { DataNode *offset_node = win_node->getNext("db_offset"); int offsetValue = 0; offset_node->element()->get(offsetValue); setDBOffset(offsetValue); } if (win_node->hasAnother("main_split")) { float gVal; win_node->getNext("main_split")->element()->get(gVal); mainSplit.store(gVal); } if (win_node->hasAnother("vis_split")) { float gVal; win_node->getNext("vis_split")->element()->get(gVal); visSplit.store(gVal); } if (win_node->hasAnother("bookmark_split")) { float gVal; win_node->getNext("bookmark_split")->element()->get(gVal); bookmarkSplit.store(gVal); } if (win_node->hasAnother("bookmark_visible")) { int bVal; win_node->getNext("bookmark_visible")->element()->get(bVal); bookmarksVisible.store(bVal); } } //Recording settings: if (cfg.rootNode()->hasAnother("recording")) { DataNode *rec_node = cfg.rootNode()->getNext("recording"); if (rec_node->hasAnother("path")) { DataNode *rec_path = rec_node->getNext("path"); recordingPath = rec_path->element()->toString(); } if (rec_node->hasAnother("squelch")) { DataNode *rec_squelch = rec_node->getNext("squelch"); rec_squelch->element()->get(recordingSquelchOption); } if (rec_node->hasAnother("file_time_limit")) { DataNode *rec_file_time_limit = rec_node->getNext("file_time_limit"); rec_file_time_limit->element()->get(recordingFileTimeLimitSeconds); } } if (cfg.rootNode()->hasAnother("devices")) { DataNode *devices_node = cfg.rootNode()->getNext("devices"); while (devices_node->hasAnother("device")) { DataNode *device_node = devices_node->getNext("device"); if (device_node->hasAnother("id")) { std::string deviceId = device_node->getNext("id")->element()->toString(); getDevice(deviceId)->load(device_node); } } } if (cfg.rootNode()->hasAnother("manual_devices")) { DataNode *manuals_node = cfg.rootNode()->getNext("manual_devices"); while (manuals_node->hasAnother("device")) { DataNode *manual_node = manuals_node->getNext("device"); if (manual_node->hasAnother("factory") && manual_node->hasAnother("params")) { SDRManualDef mdef; mdef.factory = manual_node->getNext("factory")->element()->toString(); mdef.params = manual_node->getNext("params")->element()->toString(); manualDevices.push_back(mdef); } } } #ifdef USE_HAMLIB if (cfg.rootNode()->hasAnother("rig")) { DataNode *rig_node = cfg.rootNode()->getNext("rig"); if (rig_node->hasAnother("enabled")) { int loadEnabled; rig_node->getNext("enabled")->element()->get(loadEnabled); rigEnabled.store(loadEnabled?true:false); } if (rig_node->hasAnother("model")) { int loadModel; rig_node->getNext("model")->element()->get(loadModel); rigModel.store(loadModel?loadModel:1); } if (rig_node->hasAnother("rate")) { int loadRate; rig_node->getNext("rate")->element()->get(loadRate); rigRate.store(loadRate?loadRate:57600); } if (rig_node->hasAnother("port")) { rigPort = rig_node->getNext("port")->element()->toString(); } if (rig_node->hasAnother("control")) { int loadControl; rig_node->getNext("control")->element()->get(loadControl); rigControlMode.store(loadControl?true:false); } if (rig_node->hasAnother("follow")) { int loadFollow; rig_node->getNext("follow")->element()->get(loadFollow); rigFollowMode.store(loadFollow?true:false); } if (rig_node->hasAnother("center_lock")) { int loadCenterLock; rig_node->getNext("center_lock")->element()->get(loadCenterLock); rigCenterLock.store(loadCenterLock?true:false); } if (rig_node->hasAnother("follow_modem")) { int loadFollow; rig_node->getNext("follow_modem")->element()->get(loadFollow); rigFollowModem.store(loadFollow?true:false); } } #endif return true; }
bool AppConfig::save() { DataTree cfg; cfg.rootNode()->setName("cubicsdr_config"); if (winW.load() && winH.load()) { DataNode *window_node = cfg.rootNode()->newChild("window"); *window_node->newChild("x") = winX.load(); *window_node->newChild("y") = winY.load(); *window_node->newChild("w") = winW.load(); *window_node->newChild("h") = winH.load(); *window_node->newChild("max") = winMax.load(); *window_node->newChild("tips") = showTips.load(); *window_node->newChild("perf_mode") = (int)perfMode.load(); *window_node->newChild("theme") = themeId.load(); *window_node->newChild("font_scale") = fontScale.load(); *window_node->newChild("snap") = snap.load(); *window_node->newChild("center_freq") = centerFreq.load(); *window_node->newChild("waterfall_lps") = waterfallLinesPerSec.load(); *window_node->newChild("spectrum_avg") = spectrumAvgSpeed.load(); *window_node->newChild("modemprops_collapsed") = modemPropsCollapsed.load();; *window_node->newChild("db_offset") = dbOffset.load(); *window_node->newChild("main_split") = mainSplit.load(); *window_node->newChild("vis_split") = visSplit.load(); *window_node->newChild("bookmark_split") = bookmarkSplit.load(); *window_node->newChild("bookmark_visible") = bookmarksVisible.load(); } //Recording settings: DataNode *rec_node = cfg.rootNode()->newChild("recording"); *rec_node->newChild("path") = recordingPath; *rec_node->newChild("squelch") = recordingSquelchOption; *rec_node->newChild("file_time_limit") = recordingFileTimeLimitSeconds; DataNode *devices_node = cfg.rootNode()->newChild("devices"); std::map<std::string, DeviceConfig *>::iterator device_config_i; for (device_config_i = deviceConfig.begin(); device_config_i != deviceConfig.end(); device_config_i++) { DataNode *device_node = devices_node->newChild("device"); device_config_i->second->save(device_node); } if (manualDevices.size()) { DataNode *manual_node = cfg.rootNode()->newChild("manual_devices"); for (std::vector<SDRManualDef>::const_iterator i = manualDevices.begin(); i != manualDevices.end(); i++) { DataNode *rig_node = manual_node->newChild("device"); *rig_node->newChild("factory") = i->factory; *rig_node->newChild("params") = i->params; } } #ifdef USE_HAMLIB DataNode *rig_node = cfg.rootNode()->newChild("rig"); *rig_node->newChild("enabled") = rigEnabled.load()?1:0; *rig_node->newChild("model") = rigModel.load(); *rig_node->newChild("rate") = rigRate.load(); *rig_node->newChild("port") = rigPort; *rig_node->newChild("control") = rigControlMode.load()?1:0; *rig_node->newChild("follow") = rigFollowMode.load()?1:0; *rig_node->newChild("center_lock") = rigCenterLock.load()?1:0; *rig_node->newChild("follow_modem") = rigFollowModem.load()?1:0; #endif std::string cfgFileName = getConfigFileName(); if (!cfg.SaveToFileXML(cfgFileName)) { std::cout << "Error saving :: configuration file '" << cfgFileName << "' is not writable!" << std::endl; return false; } return true; }