AvatarLogger::AvatarLogger(EmberEntity& avatarEntity) : mChatLogger(nullptr) { assert(&avatarEntity); //Put log files in a "logs" subdirectory of the home directory. const std::string dir = EmberServices::getSingleton().getConfigService().getHomeDirectory() + "/logs/"; try { //make sure the directory exists oslink::directory osdir(dir); if (!osdir.isExisting()) { oslink::directory::mkdir(dir.c_str()); } //perform setup of the stream std::stringstream logFileSS; logFileSS << dir << "/" << avatarEntity.getName() << "_chatlog.log"; mChatLogger = std::unique_ptr<std::ofstream>(new std::ofstream(logFileSS.str().c_str(), std::ios::app)); S_LOG_VERBOSE("Chat Logging set to write in [ " << logFileSS.str() << " ]"); *mChatLogger << "-------------------------------------------------------" << std::endl; *mChatLogger << "Chat Logging Initialized at " << Time::getLocalTimeStr() << std::endl; *mChatLogger << "-------------------------------------------------------" << std::endl; //wait with connecting until everything has been properly set up GUIManager::getSingleton().AppendIGChatLine.connect(sigc::mem_fun(*this, &AvatarLogger::GUIManager_AppendIGChatLine)); } catch (const std::exception& ex) { S_LOG_FAILURE("Error when creating directory for logs." << ex); } }
bool OgreResourceLoader::isExistingDir(const std::string& path) const { bool exists = false; oslink::directory osdir(path); exists = osdir.isExisting(); if (!exists) { //perhaps it's a file? std::ifstream fin(path.c_str(), std::ios::in); exists = !fin.fail(); } return exists; }
bool AssetsManager::exportMesh(Ogre::MeshPtr mesh, const std::string& filePath) { if (filePath != "") { Ogre::MeshSerializer serializer; try { std::string dirname(filePath); size_t end = dirname.find_last_of("/\\"); if (end != std::string::npos) { dirname = dirname.substr(0, end); } oslink::directory osdir(dirname); if (!osdir.isExisting()) { oslink::directory::mkdir(dirname.c_str()); } serializer.exportMesh(mesh.get(), filePath); S_LOG_INFO("Exported mesh " << filePath); } catch (const Ogre::Exception& ex) { S_LOG_FAILURE("Error when exporting mesh " << mesh->getName() << "to path " << filePath <<"." << ex); return false; } return true; } return false; }
void Application::initializeServices() { // Initialize Ember services std::cout << "Initializing Ember services" << std::endl; mServices = new EmberServices(*mSession); // Initialize the Configuration Service ConfigService& configService = mServices->getConfigService(); configService.start(); if (mPrefix != "") { configService.setPrefix(mPrefix); } if (mHomeDir != "") { configService.setHomeDirectory(mHomeDir); std::cout << "Setting home directory to " << mHomeDir << std::endl; } //output all logging to ember.log std::string filename(configService.getHomeDirectory() + "/ember.log"); mLogOutStream = std::unique_ptr < std::ofstream > (new std::ofstream(filename.c_str())); //write to the log the version number *mLogOutStream << "Ember version " << VERSION << std::endl; mLogObserver = new ConfigBoundLogObserver(configService, *mLogOutStream); Log::addObserver(mLogObserver); //default to INFO, though this can be changed by the config file mLogObserver->setFilter(Log::INFO); // Change working directory const std::string& dirName = configService.getHomeDirectory(); oslink::directory osdir(dirName); if (!osdir) { oslink::directory::mkdir(dirName.c_str()); } int result = chdir(configService.getHomeDirectory().c_str()); if (result) { S_LOG_WARNING("Could not change directory to '"<< configService.getHomeDirectory().c_str() <<"'."); } //load the config file. Note that this will load the shared config file, and then the user config file if available (~/.ember/ember.conf) configService.loadSavedConfig("ember.conf", mConfigSettings); //Check if there's a user specific ember.conf file. If not, create an empty template one. std::string userConfigFilePath = configService.getHomeDirectory() + "/ember.conf"; struct stat tagStat; int ret = stat(userConfigFilePath.c_str(), &tagStat); if (ret == -1) { //Create empty template file. std::ofstream outstream(userConfigFilePath.c_str()); outstream << "#This is a user specific settings file. Settings here override those found in the application installed ember.conf file." << std::endl << std::flush; S_LOG_INFO("Created empty user specific settings file at '" << userConfigFilePath << "'."); } S_LOG_INFO("Using media from " << configService.getEmberMediaDirectory()); // Initialize the Sound Service S_LOG_INFO("Initializing sound service"); mServices->getSoundService().start(); // Initialize and start the Metaserver Service. S_LOG_INFO("Initializing metaserver service"); mServices->getMetaserverService().start(); //hoho, we get linking errors if we don't do some calls to the service mServices->getMetaserverService().getMetaServer(); // Initialize the Server Service S_LOG_INFO("Initializing server service"); mServices->getServerService().start(); S_LOG_INFO("Initializing input service"); mServices->getInputService().start(); mServices->getInputService().getInput().setMainLoopController(&mMainLoopController); S_LOG_INFO("Initializing scripting service"); mServices->getScriptingService().start(); S_LOG_INFO("Initializing wfut service"); mServices->getWfutService().start(); S_LOG_INFO("Initializing server settings service"); mServices->getServerSettingsService().start(); mServices->getServerService().GotView.connect(sigc::mem_fun(*this, &Application::Server_GotView)); mServices->getServerService().DestroyedView.connect(sigc::mem_fun(*this, &Application::Server_DestroyedView)); //register the lua scripting provider. The provider will be owned by the scripting service, so we don't need to keep the pointer reference. Lua::LuaScriptingProvider* luaProvider = new Lua::LuaScriptingProvider(); tolua_Lua_open(luaProvider->getLuaState()); tolua_Framework_open(luaProvider->getLuaState()); tolua_EmberOgre_open(luaProvider->getLuaState()); tolua_Eris_open(luaProvider->getLuaState()); tolua_EmberServices_open(luaProvider->getLuaState()); tolua_Helpers_open(luaProvider->getLuaState()); tolua_Ogre_open(luaProvider->getLuaState()); tolua_AtlasAdapters_open(luaProvider->getLuaState()); tolua_Adapters_open(luaProvider->getLuaState()); tolua_Representations_open(luaProvider->getLuaState()); tolua_Atlas_open(luaProvider->getLuaState()); tolua_Varconf_open(luaProvider->getLuaState()); tolua_ConnectorDefinitions_open(luaProvider->getLuaState()); tolua_Domain_open(luaProvider->getLuaState()); tolua_Cegui_open(luaProvider->getLuaState()); mServices->getScriptingService().registerScriptingProvider(luaProvider); Lua::ConnectorBase::setState(luaProvider->getLuaState()); mScriptingResourceProvider = new FileResourceProvider(mServices->getConfigService().getSharedDataDirectory() + "/scripting/"); mServices->getScriptingService().setResourceProvider(mScriptingResourceProvider); oldSignals[SIGSEGV] = signal(SIGSEGV, shutdownHandler); oldSignals[SIGABRT] = signal(SIGABRT, shutdownHandler); oldSignals[SIGILL] = signal(SIGILL, shutdownHandler); #ifndef _WIN32 oldSignals[SIGBUS] = signal(SIGBUS, shutdownHandler); #endif EventServicesInitialized.emit(); }
const std::string MainCamera::_takeScreenshot() { // retrieve current time time_t rawtime; struct tm* timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); // construct filename string // padding with 0 for single-digit values std::stringstream filename; filename << "screenshot_" << ((*timeinfo).tm_year + 1900); // 1900 is year "0" int month = ((*timeinfo).tm_mon + 1); // January is month "0" if(month <= 9) { filename << "0"; } filename << month; int day = (*timeinfo).tm_mday; if(day <= 9) { filename << "0"; } filename << day << "_"; int hour = (*timeinfo).tm_hour; if(hour <= 9) { filename << "0"; } filename << hour; int min = (*timeinfo).tm_min; if(min <= 9) { filename << "0"; } filename << min; int sec = (*timeinfo).tm_sec; if(sec <= 9) { filename << "0"; } filename << sec << ".jpg"; const std::string dir = EmberServices::getSingleton().getConfigService().getHomeDirectory() + "/screenshots/"; try { //make sure the directory exists oslink::directory osdir(dir); if (!osdir.isExisting()) { #ifdef __WIN32__ mkdir(dir.c_str()); #else mkdir(dir.c_str(), S_IRWXU); #endif } } catch (const std::exception& ex) { S_LOG_FAILURE("Error when creating directory for screenshots." << ex); throw Exception("Error when saving screenshot."); } try { // take screenshot mWindow.writeContentsToFile(dir + filename.str()); } catch (const std::exception& ex) { S_LOG_FAILURE("Could not write screenshot to disc." << ex); throw Exception("Error when saving screenshot."); } return dir + filename.str(); }
void XMLJesusSerializer::saveBlueprintToFile(Carpenter::BluePrint* blueprint, const std::string& filename, const std::string& name) { if (filename == "" || filename == "." || filename == "..") { return; } TiXmlDocument _XMLDoc; try { //make sure the directory exists std::string dir = EmberServices::getSingleton().getConfigService().getHomeDirectory() + "/carpenter/blueprints"; oslink::directory osdir(dir); if (!osdir) { #ifdef __WIN32__ mkdir((EmberServices::getSingleton().getConfigService().getHomeDirectory() + "carpenter").c_str()); mkdir(dir.c_str()); #else mkdir((EmberServices::getSingleton().getConfigService().getHomeDirectory() + "carpenter").c_str(), S_IRWXU); mkdir(dir.c_str(), S_IRWXU); #endif } TiXmlElement elem("blueprint"); elem.SetAttribute("startingblock", blueprint->getStartingBlock()->getName().c_str()); elem.SetAttribute("name", name.c_str()); TiXmlElement buildingBlocksElem("buildingblocks"); //now iterate over all building blocks const std::vector< Carpenter::BuildingBlock*> bblocks = blueprint->getAttachedBlocks(); std::vector< Carpenter::BuildingBlock*>::const_iterator I = bblocks.begin(); std::vector< Carpenter::BuildingBlock*>::const_iterator I_end = bblocks.end(); for (;I != I_end; ++I) { TiXmlElement buildingBlockElem("buildingblock"); buildingBlockElem.SetAttribute("blocktype", (*I)->getBuildingBlockSpec()->getName().c_str() ); buildingBlockElem.SetAttribute("name", (*I)->getName().c_str()); buildingBlocksElem.InsertEndChild(buildingBlockElem); } //iterate over the bindings TiXmlElement bindingsElem("bindings"); const std::list< Carpenter::BuildingBlockBinding>* bindings = blueprint->getBindings(); std::list< Carpenter::BuildingBlockBinding>::const_iterator J = bindings->begin(); std::list< Carpenter::BuildingBlockBinding>::const_iterator J_end = bindings->end(); for (;J != J_end; ++J) { TiXmlElement bindingElem("binding"); bindingElem.SetAttribute("block1", (*J).getBlock1()->getName().c_str()); bindingElem.SetAttribute("block2", (*J).getBlock2()->getName().c_str()); const Carpenter::AttachPoint* point1 = (*J).getAttachPoint1(); std::string point1Name = point1->getAttachPair()->getName() + "/" + point1->getName(); const Carpenter::AttachPoint* point2 = (*J).getAttachPoint2(); std::string point2Name = point2->getAttachPair()->getName() + "/" + point2->getName(); bindingElem.SetAttribute("point1", point1Name.c_str()); bindingElem.SetAttribute("point2", point2Name.c_str()); bindingsElem.InsertEndChild(bindingElem); } elem.InsertEndChild(bindingsElem); elem.InsertEndChild(buildingBlocksElem); _XMLDoc.InsertEndChild(elem); _XMLDoc.SaveFile(filename.c_str()); } catch (...) { S_LOG_FAILURE("An error occurred creating the document." ); } }
program() { //check command syntax //edit filename if (dcount(COMMAND,FM)<2) abort("Syntax is 'edic osfilename'"); var verbose=OPTIONS.ucase().index("V"); var editor=osgetenv("VISUAL"); var linenopattern="$LINENO "; if (not editor) editor.osgetenv("EDITOR"); //TODO simplify this editor finding code //enable edit at first error for crimson editor (no quotes around filename for cedt) if (editor.lcase().index("cedt") and not editor.index("$") ) editor^=" /L:$LINENO $FILENAME"; //look for installed nano //if (SLASH eq "\\" and not index(PLATFORM_,"x64")) { var nanopath=""; if (SLASH eq "\\") { //look for nano.exe next to edic.exe if (not editor) nanopath=EXECPATH.swap("edic","nano"); if (nanopath.osfile()) editor="nano $LINENO'$FILENAME'"; } //look for nano in parent bin if (not editor) { nanopath="..\\bin\\nano.exe"; if (nanopath.osfile()) editor="nano $LINENO'$FILENAME'"; } //look for nano in release directory during exodus development if (not editor) { nanopath="..\\..\\release\\cygwin\\bin\\nano.exe"; if (nanopath.osfile()) editor="..\\..\\release\\cygwin\\bin\\nano $LINENO'$FILENAME'"; else { nanopath="..\\"^nanopath; if (nanopath.osfile()) editor="..\\..\\..\\release\\cygwin\\bin\\nano $LINENO'$FILENAME'"; } } if (editor.index("nano")) linenopattern="+$LINENO "; //otherwise on windows try to locate CYGWIN nano or vi var cygwinpath=""; if (not editor and SLASH eq "\\") { //from environment variable cygwinpath=osgetenv("CYGWIN_BIN"); //else from current disk if (not cygwinpath) cygwinpath="\\cygwin\\bin\\"; //else from c: if (not osdir(cygwinpath)) cygwinpath="c:\\cygwin\\bin\\"; //else give up if (not osdir(cygwinpath)) cygwinpath=""; if (cygwinpath and cygwinpath[-1] ne SLASH) cygwinpath^=SLASH; //editor=cygwinpath^"bash --login -i -c \"/bin/"; editor=cygwinpath; if (osfile(cygwinpath^"nano.exe") or osfile("nano.exe")) { editor="nano $LINENO'$FILENAME'"; if (osfile(cygwinpath^"nano.exe")) editor.splicer(1,0,cygwinpath); //editor^="\""; linenopattern="+$LINENO "; } else if (osfile(cygwinpath^"vi.exe") or osfile("vi.exe")) { editor="vi -c \":$LINENO\" $FILENAME"; if (osfile(cygwinpath^"vi.exe")) editor.splicer(1,0,cygwinpath); //editor^="\""; } else editor=""; } if (SLASH eq "\\") { //configure nanorc (on windows) //TODO same for non-windows //nano on windows looks for nanorc config file as follows (probably merges all found) //C:\cygwin\usr\local\etc\nanorc //C:\cygwin\etc\nanorc (only if cygwin exists) //C:\Documents and Settings\USERNAME\.nanorc ($HOMEDRIVE$HOMEPATH) var nanorcfilename; if (cygwinpath) { nanorcfilename=cygwinpath.field(SLASH,1,dcount(cygwinpath,SLASH)-2) ^ SLASH ^ "etc" ^ SLASH ^ "nanorc"; } else { nanorcfilename=osgetenv("HOME"); if (not nanorcfilename) nanorcfilename=osgetenv("HOMEDRIVE") ^ osgetenv("HOMEPATH"); if (nanorcfilename[-1] ne SLASH) nanorcfilename^=SLASH; nanorcfilename^=".nanorc"; } if (not osfile(nanorcfilename)) { //var nanorctemplatefilename=EXECPATH.field(SLASH,1,dcount(EXECPATH,SLASH)-1) ^ SLASH ^ "nanorc"; var nanorctemplatefilename=nanopath.field(SLASH,1,dcount(nanopath,SLASH)-1) ^ SLASH ^ "nanorc"; if (not osfile(nanorctemplatefilename)) nanorctemplatefilename.swapper("release","..\\release"); //if (not osfile(nanorctemplatefilename)) // nanorctemplatefilename.swapper("release","..\\"^PLATFORM_^"\\release"); if (oscopy(nanorctemplatefilename,nanorcfilename)) { printl("Copied " ^ nanorctemplatefilename.quote() ^ " to " ^ nanorcfilename.quote()); var ().input("Note: nano c++ syntax highlighting has been installed. Press Enter ... "); } else { errputl("Could not copy " ^ nanorctemplatefilename.quote() ^ " to " ^ nanorcfilename.quote()); if (not osfile(nanorctemplatefilename)) errputl("nano syntax highlighting file is missing."); } } if(not osgetenv("HOME")) ossetenv("HOME",osgetenv("HOMEDRIVE") ^ osgetenv("HOMEPATH")); } if (not editor) { if (SLASH eq "/") editor="nano "; else editor="notepad"; printl("Environment EDITOR not set. Using " ^ editor); } //editor="vi"; editor.swapper("nano ", "nano --const --nowrap --autoindent --suspend "); if (editor.index("nano")) printl("http://www.nano-editor.org/dist/v2.1/nano.html"); //configure nano syntax highlighting var filenames=field(COMMAND,FM,2,99999); var nfiles=dcount(filenames,FM); var filen=0; while (filen<nfiles) { filen+=1; var filename=filenames.a(filen).unquote(); //split out trailing line number after : var startatlineno=field(filename,":",2); if (startatlineno.isnum()) filename=field(filename,":",1); else startatlineno=""; filename.trimmerb("."); if (not index(field2(filename,SLASH,-1),".")) filename^=".cpp"; var iscompilable=filename.field2(".",-1)[1].lcase() ne "h"; //make absolute in case EDITOR changes current working directory var editcmd=editor; if (editcmd.index("$ABSOLUTEFILENAME")) { editcmd.swapper("$ABSOLUTEFILENAME","$FILENAME"); filename=oscwd()^SLASH^filename; } //prepare a skeleton exodus cpp file var newfile=false; if (iscompilable and not osfile(filename)) { var basefilename=field2(filename,SLASH,-1); basefilename=basefilename.field(".",dcount(basefilename,".")-1); var progtype; var question="1=Normal Program, 2=External Subroutine or Function"; //question^="\n3=main(), 4=simple so/dll\n"; question^="\n"^basefilename.quote()^" does not exist. Create what? (1-2) "; while (true) { if (basefilename.substr(1,5).lcase() eq "dict_") progtype=5; else progtype.input(question); if (progtype eq 2) progtype="classlib"; else if (progtype eq 3) progtype="main"; else if (progtype eq 4) progtype="mainlib"; else if (progtype eq 1) progtype="class"; else if (progtype eq 5) progtype="dict"; else stop(); break; } newfile=true; var blankfile=""; if (progtype eq "main" or progtype eq "mainlib") { startatlineno="4,9"; blankfile^="#include <exodus/exodus.h>\n"; blankfile^="\n"; blankfile^="program() {\n"; blankfile^="\tprintl(\""^basefilename^" says 'Hello World!'\");\n"; if (progtype eq "mainlib") blankfile^="\treturn 0;\n"; blankfile^="}\n"; if (progtype eq "mainlib") blankfile.swapper("program()","function "^basefilename^"()"); } else if (progtype eq "class" or progtype eq "classlib") { startatlineno="6,9"; blankfile^="#include <exodus/program.h>\n"; //programinit() as 2nd line to avoid ppl in external functions before programinit //blankfile^="\n"; blankfile^="programinit()\n"; blankfile^="\n"; blankfile^="function main("; //the .h maker not able to parse this yet and is rather clumsy anyway //if (progtype eq "classlib") // blankfile^="/*in arg1, out arg2*/"; blankfile^=") {\n"; blankfile^="\tprintl(\""^basefilename^" says 'Hello World!'\");\n"; blankfile^="\treturn 0;\n"; blankfile^="}\n"; blankfile^="\nprogramexit()"; blankfile^="\n"; if (progtype eq "classlib") blankfile.swapper("program","library"); } else if (progtype eq "dict") { startatlineno="6,9"; blankfile^="#include <exodus/dict.h>\n\n"; //programinit() as 2nd line to avoid ppl in external functions before programinit //blankfile^="\n"; blankfile^="dict(EXAMPLEDICTID1) {\n"; blankfile^="\tANS=RECORD(1)^\"x\";\n"; blankfile^="}\n\n"; blankfile^="dict(EXAMPLEDICTID2) {\n"; blankfile^="\tANS=RECORD(2)^\"x\";\n"; blankfile^="}\n"; } if (blankfile[1] ne "\n") blankfile^="\n"; if (SLASH ne "/") blankfile.swapper("\n","\r\n"); if (not oswrite(blankfile,filename)) stop("Cannot create "^filename^". Invalid file name, or no rights here."); // startatlineno="4,9"; //startatlineno=""; } var editcmd0=editcmd; var linenopattern0=linenopattern; //keep editing and compiling until no errors while (true) { editcmd=editcmd0; linenopattern=linenopattern0; //record the current file update timestamp var fileinfo=osfile(filename); //build the edit command if (editcmd.index("$LINENO")) { if (not startatlineno) linenopattern=""; else linenopattern.swapper("$LINENO",startatlineno.field(",",1)); editcmd.swapper("$LINENO",linenopattern); } if (editcmd.index("$FILENAME")) editcmd.swapper("$FILENAME",filename); else editcmd ^= " " ^ filename; //call the editor if (verbose) printl(editcmd); osshell(editcmd); //if the file hasnt been updated var fileinfo2=osfile(filename); if (fileinfo2 ne fileinfo) newfile=false; else { //delete the skeleton printl("File unchanged. Not saving."); if (newfile) osdelete(filename); //move to the next file break; } //clear the screen (should be cls on win) if (SLASH eq "/") osshell("clear"); //else // osshell("cls"); if (not iscompilable) break; //build the compiler command var compiler="compile"; var compileoptions=""; var compilecmd=compiler ^ " " ^ filename.quote() ^ compileoptions; //capture the output var compileoutputfilename=filename ^ ".2"; if (SLASH eq "/") compilecmd ^= " 2>&1 | tee " ^ compileoutputfilename.quote(); else compilecmd ^= " > " ^ compileoutputfilename.quote() ^ " 2>&1"; //call the compiler if (verbose) printl(compilecmd); osshell(compilecmd); //var tt; //tt.inputl("Press Enter ..."); //if any errors then loop back to edit again var errors; if (osread(errors,compileoutputfilename)) { osdelete(compileoutputfilename); if (SLASH ne "/") print(errors); startatlineno=""; var charn; //gnu style error lines if (charn=index(errors, ": error:")) { startatlineno=errors.substr(charn-9,9); //printl(startatlineno); startatlineno=startatlineno.field2(":",2); //printl(startatlineno); //msvc style error lines //test.cpp(6) : error C2143: syntax error : missing ';' before '}' } else if (charn=index(errors,") : error ")) { startatlineno=errors.substr(charn-10,10).field2("(",2); } if (startatlineno) { print("Press any key to re-edit at line "^startatlineno^" ... "); var().input(""); continue; } } break; } } }