static bool saveXML(pugi::xml_document& document, const std::string& outputFile) { pugi::xml_node decl = document.prepend_child(pugi::node_declaration); decl.append_attribute("version").set_value("1.0"); decl.append_attribute("encoding").set_value("utf-8"); if(!document.save_file(outputFile.c_str(), " ", 1U, pugi::encoding_utf8)) { return false; } return true; }
int InitConfig(pugi::xml_document& config) { //check folders, create in dont exist wstring appDataPath = AppPath(); wstring logPath; wstring rawCurrentPath; wstring logDailyPath; //config wstring configFile = appDataPath + L"\\etc\\sdr.xml"; //because service runs at windows/System32 folder //we forced to use absolute path pugi::xml_parse_result result = config.load_file(configFile.data()); if (result.status != pugi::status_ok) { return status_config_file_not_found; } //first install build directory tree logPath = L"\\log"; rawCurrentPath = logPath + L"\\current\\"; logDailyPath = logPath + L"\\daily\\"; config.select_single_node(L"/sdr/recording/logs/base").node().attribute( L"path").set_value(logPath.data()); config.select_single_node(L"/sdr/recording/logs/current").node().attribute( L"path").set_value(rawCurrentPath.data()); config.select_single_node(L"/sdr/recording/logs/daily").node().attribute( L"path").set_value(logDailyPath.data()); config.save_file(configFile.data()); logPath = appDataPath + logPath; rawCurrentPath = appDataPath + rawCurrentPath; logDailyPath = appDataPath + logDailyPath; //create config folderst CreateDirectory(logPath.data(), 0); if (GetLastError() == ERROR_PATH_NOT_FOUND) return status_path_not_found; CreateDirectory(rawCurrentPath.data(), 0); if (GetLastError() == ERROR_PATH_NOT_FOUND) return status_path_not_found; CreateDirectory(logDailyPath.data(), 0); if (GetLastError() == ERROR_PATH_NOT_FOUND) return status_path_not_found; return status_ok; }