void DebugUtil::SaveState() { Poco::Path path; if (!GetPersistencePath(path)) return; path.setFileName(DEBUG_UTIL_XML); Poco::XML::Document* doc = new Poco::XML::Document(); Poco::XML::Element* debugutil = doc->createElement(DEBUGUTIL_TAG); doc->appendChild(debugutil)->release(); for (std::set<unsigned int>::const_iterator i = m_TracedObjects.begin(); i != m_TracedObjects.end(); ++i) { Poco::XML::Element* traceObject = doc->createElement(TRACEOBJECT_TAG); debugutil->appendChild(traceObject)->release(); std::stringstream ss; ss << *i; traceObject->setAttribute(ID_ATTR, ss.str()); } for (std::set<std::string>::const_iterator i = m_TracedClasses.begin(); i != m_TracedClasses.end(); ++i) { Poco::XML::Element* traceClass = doc->createElement(TRACECLASS_TAG); debugutil->appendChild(traceClass)->release(); traceClass->setAttribute(NAME_ATTR, *i); } try { Poco::FileOutputStream writer(path.toString()); Poco::XML::DOMWriter out; out.setOptions(3); //write declaration and pretty print out.writeNode(writer, doc); doc->release(); // save BreakpointManager path.setFileName(DebugBreakpointManager::BREAKPOINTS_XML); GetBreakpointManager()->SaveState(path); } catch (Poco::FileException& e) { BERRY_WARN << e.displayText(); } }
QStringList QtAssistantUtil::ExtractQCHFiles(const std::vector<IBundle::Pointer>& bundles) { QStringList result; for (std::size_t i = 0; i < bundles.size(); ++i) { std::vector<std::string> resourceFiles; bundles[i]->GetStorage().List("resources", resourceFiles); bool qchFileFound = false; for (std::size_t j = 0; j < resourceFiles.size(); ++j) { QString resource = QString::fromStdString(resourceFiles[j]); if (resource.endsWith(".qch")) { qchFileFound = true; Poco::Path qchPath = bundles[i]->GetPath(); qchPath.pushDirectory("resources"); qchPath.setFileName(resourceFiles[j]); result << QString::fromStdString(qchPath.toString()); } } if (qchFileFound) { registeredBundles.insert(QString::fromStdString(bundles[i]->GetSymbolicName())); } } return result; }
/* Traverse the hierarchy inside the container */ void TskL01Extract::traverse(ewf::libewf_file_entry_t *parent) { static Poco::Path currPath; TskL01Extract::ArchivedFile fileInfo; fileInfo.entry = parent; fileInfo.type = getFileType(parent); fileInfo.size = getFileSize(parent); fileInfo.ctime = getEntryChangeTime(parent); fileInfo.crtime = getCreationTime(parent); fileInfo.atime = getAccessTime(parent); fileInfo.mtime = getModifiedTime(parent); std::string name = getName(parent); bool saveDirectory = false; if ((fileInfo.type == 'd') && !name.empty()) { saveDirectory = true; } if (saveDirectory) { currPath.pushDirectory(name); fileInfo.path = currPath; m_archivedFiles.push_back(fileInfo); } else if (fileInfo.type == 'f') { Poco::Path tempPath = currPath; tempPath.setFileName(name); fileInfo.path = tempPath; m_archivedFiles.push_back(fileInfo); } int num = 0; ewf::libewf_error_t *ewfError = NULL; ewf::libewf_file_entry_get_number_of_sub_file_entries(parent, &num, &ewfError); if (num > 0) { //recurse for (int i=0; i < num; ++i) { ewf::libewf_file_entry_t *child = NULL; ewfError = NULL; if (ewf::libewf_file_entry_get_sub_file_entry(parent, i, &child, &ewfError) == -1) { throw TskException("TskL01Extract::traverse - Error with libewf_file_entry_get_sub_file_entry: "); } traverse(child); } } if (saveDirectory) { currPath.popDirectory(); } }
void ComputeApp::initialize(Application& self) { Application::initialize(self); Poco::Path appPath = commandPath(); appPath.setExtension(""); appPath.setFileName(""); exeDirectory = appPath.toString(); loadConfiguration(); }
const std::string OptionsPage::GenerateContent(const std::string &method, const std::map<std::string,QueryVar> &queryvars) { std::string content(""); std::string sql(""); if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="save" && ValidateFormPassword(queryvars)) { Option option(m_db); option.ClearCache(); std::vector<std::string> options; std::vector<std::string> oldvalues; std::vector<std::string> newvalues; CreateArgArray(queryvars,"option",options); CreateArgArray(queryvars,"oldvalue",oldvalues); CreateArgArray(queryvars,"value",newvalues); for(int i=0; i<options.size(); i++) { if(oldvalues[i]!=newvalues[i]) { option.Set(options[i],newvalues[i]); // load new language immediately if(options[i]=="Language") { Poco::Path tdir; tdir.pushDirectory(global::basepath+"translations"); tdir=tdir.makeAbsolute(); tdir.setFileName(newvalues[i]); m_trans->LoadLocalizedTranslation(tdir.toString()); } if(options[i]=="MessageDownloadMaxDaysBackward") { m_db->Execute("INSERT OR IGNORE\ INTO tblMessageRequests (IdentityID, Day, RequestIndex, Found)\ SELECT M.IdentityID, M.InsertDate, M.MessageIndex, 'true'\ FROM tblMessage M\ LEFT JOIN tblMessageRequests R\ ON M.IdentityID=R.IdentityID\ AND M.MessageIndex=R.RequestIndex\ AND M.InsertDate=R.Day\ WHERE R.IdentityID IS NULL\ AND M.IdentityID IS NOT NULL\ AND M.InsertDate >= date('now',(SELECT -MAX(OptionValue,0) FROM tblOption \ WHERE Option='MessageDownloadMaxDaysBackward')||' days');"); } }
void CloneMDWorkspace::doClone(const typename MDEventWorkspace<MDE, nd>::sptr ws) { std::string outWSName = getPropertyValue("OutputWorkspace"); Progress prog(this, 0.0, 10.0, 100); BoxController_sptr bc = ws->getBoxController(); if (!bc) throw std::runtime_error("Error with InputWorkspace: no BoxController!"); if (bc->isFileBacked()) { // Generate a new filename to copy to prog.report("Copying File"); std::string originalFile = bc->getFilename(); std::string outFilename = getPropertyValue("Filename"); if (outFilename.empty()) { // Auto-generated name Poco::Path path = Poco::Path(originalFile).absolute(); std::string newName = path.getBaseName() + "_clone." + path.getExtension(); path.setFileName(newName); outFilename = path.toString(); } // Perform the copying g_log.notice() << "Cloned workspace file being copied to: " << outFilename << std::endl; Poco::File(originalFile).copyTo(outFilename); g_log.information() << "File copied successfully." << std::endl; // Now load it back IAlgorithm_sptr alg = createSubAlgorithm("LoadMD", 0.5, 1.0, false); alg->setPropertyValue("Filename", outFilename); alg->setPropertyValue("FileBackEnd", "1"); alg->setPropertyValue("Memory", "0"); //TODO: How much memory? alg->setPropertyValue("OutputWorkspace", outWSName); alg->executeAsSubAlg(); // Set the output workspace to this IMDEventWorkspace_sptr outWS = alg->getProperty("OutputWorkspace"); this->setProperty("OutputWorkspace", outWS); } else { // Perform the clone in memory. boost::shared_ptr<MDEventWorkspace<MDE,nd> > outWS(new MDEventWorkspace<MDE,nd>(*ws)); this->setProperty("OutputWorkspace", boost::dynamic_pointer_cast<IMDEventWorkspace>(outWS) ); } }
/** * Module execution function. * * @returns TskModule::OK on success, TskModule::FAIL on error, or TskModule::STOP. */ TskModule::Status TSK_MODULE_EXPORT report() { std::ostringstream msgPrefix; msgPrefix << MODULE_NAME << "::report : "; try { // Create an output folder. Poco::Path outputFolderPath = Poco::Path::forDirectory(GetSystemProperty(TskSystemProperties::MODULE_OUT_DIR)); outputFolderPath.pushDirectory(MODULE_NAME); Poco::File(outputFolderPath).createDirectories(); // Generate the report. outputFolderPath.setFileName("SummaryReport.htm"); TskSummaryReport::generateReport(outputFolderPath.toString()); return TskModule::OK; } catch (TskException &ex) { std::ostringstream msg; msg << msgPrefix.str() << "TskException: " << ex.message(); LOGERROR(msg.str()); return TskModule::FAIL; } catch (Poco::Exception &ex) { std::ostringstream msg; msg << msgPrefix.str() << "Poco::Exception: " << ex.displayText(); LOGERROR(msg.str()); return TskModule::FAIL; } catch (std::exception &ex) { std::ostringstream msg; msg << msgPrefix.str() << "std::exception: " << ex.what(); LOGERROR(msg.str()); return TskModule::FAIL; } catch (...) { LOGERROR(msgPrefix.str() + "unrecognized exception"); return TskModule::FAIL; } }
Poco::Path SharedMemoryTest::findDataFile(const std::string& afile) { Poco::Path root; root.makeAbsolute(); Poco::Path result; while (!Poco::Path::find(root.toString(), "data", result)) { root.makeParent(); if (root.toString().empty() || root.toString() == "/") throw Poco::FileNotFoundException("Didn't find data subdir"); } result.makeDirectory(); result.setFileName(afile); Poco::File aFile(result.toString()); if (!aFile.exists() || (aFile.exists() && !aFile.isFile())) throw Poco::FileNotFoundException("Didn't find file " + afile); return result; }
Poco::Path XplDevice::GetConfigFileLocation() { Poco::Path p ( Poco::Path::home() ); p.pushDirectory ( ".xPL" ); File test = File(p); if (!test.exists()){ poco_debug ( devLog, "dir doesn't exist: " + p.toString() ); test.createDirectory(); } p.pushDirectory ( "xPLSDK_configs" ); test = File(p); if (!test.exists()){ poco_debug ( devLog, "dir doesn't exist: " + p.toString() ); test.createDirectory(); } p.setFileName ( GetCompleteId() + ".conf" ); test = File(p); if (!test.exists()){ poco_debug ( devLog, "file doesn't exist: " + p.toString() ); test.createFile(); } return p; }
void DebugUtil::RestoreState() { Poco::Path path; if (!GetPersistencePath(path)) return; path.setFileName(DEBUG_UTIL_XML); try { Poco::XML::DOMParser parser; Poco::FileInputStream reader(path.toString()); Poco::XML::InputSource source(reader); //source.setSystemId(baseDir); Poco::XML::Document* doc = parser.parse(&source); Poco::XML::Element* debugutil = doc->documentElement(); if (debugutil) { // restore traced objects Poco::XML::NodeList* elementList = debugutil->getElementsByTagName(TRACEOBJECT_TAG); for (std::size_t i = 0; i < elementList->length(); i++) { Poco::XML::Element* elem = dynamic_cast<Poco::XML::Element*> (elementList->item(static_cast<unsigned long>(i))); if (!elem->hasAttribute(ID_ATTR)) continue; const std::string& attr = elem->getAttribute(ID_ATTR); int traceId = 0; try { traceId = Poco::NumberParser::parse(attr); } catch (const Poco::SyntaxException& e) { BERRY_WARN << e.displayText(); } DebugUtil::TraceObject(traceId); } elementList->release(); // restore traced classes elementList = debugutil->getElementsByTagName(TRACECLASS_TAG); for (std::size_t i = 0; i < elementList->length(); i++) { Poco::XML::Element* elem = dynamic_cast<Poco::XML::Element*> (elementList->item(static_cast<unsigned long>(i))); if (!elem->hasAttribute(NAME_ATTR)) continue; const std::string& traceClass = elem->getAttribute(NAME_ATTR); if (!traceClass.empty()) DebugUtil::TraceClass(traceClass); } elementList->release(); } doc->release(); } catch (Poco::XML::SAXParseException& e) { BERRY_WARN << e.displayText(); } catch (Poco::FileNotFoundException&) { } catch (Poco::FileException& e) { BERRY_WARN << e.displayText(); } // restore BreakpointManager path.setFileName(DebugBreakpointManager::BREAKPOINTS_XML); GetBreakpointManager()->RestoreState(path); }
int main(int argc, char *argv[]) { std::string BuildVer(BUILD_VERSION); cout<<"FastCraft Minecraft Server"<<"\n"; cout<<"Version "<<BUILD_VERSION<<(BuildVer.compare("") == 0 ? "" : "-")<<FC_VERSION<<" for Minecraft "<<FC_SUPPORTED_MINCRAFTVERSION<<"\n"<<std::endl; Poco::Path pathRoot(argv[0]); pathRoot.setFileName(""); //Remove filename pathRoot.pushDirectory("Server"); Poco::File fileRootDirectory(pathRoot.toString()); if (!fileRootDirectory.exists()) { try { fileRootDirectory.createDirectories(); }catch(Poco::FileException& ex) { cout<<"Unable to create server directory ("<<ex.message()<<")"<<std::endl; } }else{ if ((!fileRootDirectory.canRead()) || (!fileRootDirectory.canWrite())) { cout<<"Unable to read or write FastCraft root directory"<<std::endl; Thread::sleep(3000); return 0; } } std::vector<MinecraftServer*> vpServer(0); std::vector<Poco::File> vFileList(0); fileRootDirectory.list(vFileList); if (vFileList.empty()) { cout<<"No server configurations found!"<<std::endl; Thread::sleep(3000); return 0; } Poco::Data::SQLite::Connector::registerConnector(); //Startup sqlite engine Constants::init(); //load constants MinecraftServer* pServer; Poco::Path pathTemp; int x; //Start all server for (x=0;x<=vFileList.size()-1;x++) { if (!vFileList[x].isDirectory()) {continue;} //Skip files if(!pathTemp.tryParse(vFileList[x].path())) { cout<<"Illegal path!"<<std::endl; Thread::sleep(3000); return 0; } try { cout<<"Starting "<<pathTemp[pathTemp.depth()]<<"\n"; pathTemp.pushDirectory(pathTemp[pathTemp.depth()]); pathTemp.setFileName(""); pServer = new MinecraftServer(pathTemp[pathTemp.depth()-1],pathTemp); }catch(Poco::RuntimeException& ex) { cout<<"Unable to start server ("<<ex.message()<<")"<<std::endl; Thread::sleep(3000); return 0; } vpServer.push_back(pServer); pathTemp.clear(); } cout<<"Loading done!\n"; bool fSomethingRuns = false; while(1) { Thread::sleep(1000); //Check if there is at least one server that runs fSomethingRuns=false; for (x=0;x<=vpServer.size()-1;x++) { if (vpServer[x]->isRunning()) { fSomethingRuns=true; break; } } if (!fSomethingRuns) {break;} } Poco::Data::SQLite::Connector::unregisterConnector(); return 1; }