int main (int argc, char **argv) { OSG::osgInit(argc, argv); OSG::FieldContainerUnrecPtr pFile = NULL; if(argc > 1) { pFile = OSG::OSGSceneFileType::the().readContainer(argv[1], NULL); } OSG::commitChanges(); if(pFile != NULL) { fprintf(stderr, "===================== GOP ========================\n"); #if 1 #if 0 const char *outFileName = "/tmp/foo1.osg"; OSG::IndentFileOutStream outFileStream(outFileName); if( !outFileStream ) { std::cerr << "Can not open output stream to file: " << outFileName << std::endl; return -1; } std::cerr << "STARTING PRINTOUT:" << std::endl; OSG::OSGWriter writer( outFileStream, 4 ); #endif OSG::OSGSceneFileType::the().writeContainer(pFile, "/tmp/foo1.osg"); // outFileStream.close(); // OSG::SceneFileHandler::the()->write(pFile, "/tmp/foo.osb"); // OSG::SceneFileHandler::the()->write(pFile, "/tmp/foo.wrl"); #endif } pFile = NULL; OSG::osgExit(); return 0; }
void ClusterServer::doRender(RenderActionBase *action) { #if 0 OSG::IndentFileOutStream outFileStream("/tmp/cluster.osg"); if(outFileStream) { //std::cerr << "STARTING PRINTOUT:" << std::endl; OSG::OSGWriter writer(outFileStream, 4); writer.write(_clusterWindow); outFileStream.close(); } #endif _clusterWindow->serverRender(_window, _serverId, action); }
int init(int argc, char **argv) { OSG::osgInit(argc,argv); // GLUT init glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); int winid = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); // glEnable( GL_DEPTH_TEST ); // glEnable( GL_LIGHTING ); // glEnable( GL_LIGHT0 ); // glFrontFace(GL_CW); glEnable(GL_CULL_FACE); // OSG OSG::SceneFileHandler::the()->print(); // create the graph // beacon for camera and light OSG::NodeUnrecPtr b1n = OSG::Node::create(); OSG::GroupUnrecPtr b1 = OSG::Group::create(); b1n->setCore( b1 ); // transformation OSG::NodeUnrecPtr t1n = OSG::Node::create(); OSG::TransformUnrecPtr t1 = OSG::Transform::create(); t1n->setCore( t1 ); t1n->addChild( b1n ); cam_trans = t1; // light OSG::NodeUnrecPtr dlight = OSG::Node::create(); OSG::DirectionalLightUnrecPtr dl = OSG::DirectionalLight::create(); dlight->setCore( dl ); // dlight->setCore( Group::create() ); dl->setAmbient( .0, .0, .0, 1 ); dl->setDiffuse( .8f, .8f, .8f, 1.f ); dl->setDirection(0,0,1); dl->setBeacon( b1n); // root root = OSG::Node::create(); OSG::GroupUnrecPtr gr1 = OSG::Group::create(); root->setCore( gr1 ); root->addChild( t1n ); root->addChild( dlight ); // Load the file OSG::NodeUnrecPtr file = NULL; if(argc > 1) file = OSG::SceneFileHandler::the()->read(argv[1], NULL); if ( file == NULL ) { std::cerr << "Couldn't load file, ignoring" << std::endl; file = OSG::makeSphere(4, 2.0); } #if 0 OSG::GeometryPtr pGeo = cast_dynamic<OSG::GeometryPtr>(file->getCore()); if(pGeo == NULL && file->getNChildren() != 0) { pGeo = cast_dynamic<OSG::GeometryPtr>(file->getChild(0)->getCore()); } if(pGeo == NULL) { fprintf(stderr, "no geo\n"); } #endif // OSG::GraphOpRefPtr op = OSG::GraphOpFactory::the()->create("Stripe"); // op->traverse(file); // createOptimizedPrimitives(pGeo); // createSharedIndex(pGeo); OSG::Thread::getCurrentChangeList()->commitChanges(); // file->dump(); file->updateVolume(); #if 0 const char *outFileName = "/tmp/foo1.osg"; OSG::IndentFileOutStream outFileStream(outFileName); if( !outFileStream ) { std::cerr << "Can not open output stream to file: " << outFileName << std::endl; return -1; } std::cerr << "STARTING PRINTOUT:" << std::endl; OSGWriter writer( outFileStream, 4 ); writer.write( file ); outFileStream.close(); OSG::SceneFileHandler::the()->write(file, "/tmp/foo.osb"); #endif // return 0; OSG::Vec3f min,max; file->getVolume().getBounds( min, max ); std::cout << "Volume: from " << min << " to " << max << std::endl; OSG::MultiCoreUnrecPtr pMCore = OSG::MultiCore::create(); pCOver = OSG::ChunkOverrideGroup::create(); scene_trans = OSG::Transform::create(); pMCore->addCore(scene_trans); pMCore->addCore(pCOver ); OSG::NodeUnrecPtr sceneTrN = OSG::Node::create(); sceneTrN->setCore(pMCore); sceneTrN->addChild(file); dlight->addChild(sceneTrN); std::cerr << "Tree: " << std::endl; // root->dump(); // Camera cam = OSG::PerspectiveCamera::create(); cam->setBeacon( b1n ); cam->setFov( OSG::osgDegree2Rad( 90 ) ); cam->setNear( 0.1f ); cam->setFar( 100000 ); // Background OSG::SolidBackgroundUnrecPtr bkgnd = OSG::SolidBackground::create(); bkgnd->setColor(OSG::Color3f(1,0,0)); // Viewport vp = OSG::Viewport::create(); vp->setCamera( cam ); vp->setBackground( bkgnd ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); #if 0 OSG::UInt8 imgdata[] = { 64,64,64, 128,128,128, 192,192,192, 255,255,255 }; #endif pImg = OSG::Image::create(); pImg->set(OSG::Image::OSG_RGB_PF, 128, 128); //, 1, 1, 1, 0.0, imgdata); tx1o = OSG::TextureObjChunk::create(); tx1e = OSG::TextureEnvChunk::create(); tx1o->setImage (pImg ); tx1o->setMinFilter(GL_LINEAR ); tx1o->setMagFilter(GL_LINEAR ); tx1o->setWrapS (GL_CLAMP ); tx1o->setWrapT (GL_CLAMP ); tx1e->setEnvMode (GL_REPLACE); OSG::SimpleMaterialUnrecPtr mat = OSG::SimpleMaterial::create(); mat->setDiffuse(OSG::Color3f(1,1,1)); mat->setLit (false ); mat->addChunk (tx1o ); mat->addChunk (tx1e ); OSG::PolygonForegroundUnrecPtr pFG = OSG::PolygonForeground::create(); pFG->setMaterial(mat); OSG::MFPnt2f *pPos = pFG->editMFPositions(); OSG::MFVec3f *pTex = pFG->editMFTexCoords(); pPos->push_back(OSG::Pnt2f(0.0f, 0.0f)); pPos->push_back(OSG::Pnt2f(0.3f, 0.0f)); pPos->push_back(OSG::Pnt2f(0.3f, 0.3f)); pPos->push_back(OSG::Pnt2f(0.0f, 0.3f)); pTex->push_back(OSG::Vec3f(0.0f, 1.0f, 0.0f)); pTex->push_back(OSG::Vec3f(1.0f, 1.0f, 0.0f)); pTex->push_back(OSG::Vec3f(1.0f, 0.0f, 0.0f)); pTex->push_back(OSG::Vec3f(0.0f, 0.0f, 0.0f)); vp->addForeground(pFG); OSG::SimpleMaterialUnrecPtr matFgCheck = OSG::SimpleMaterial::create(); matFgCheck->setDiffuse(OSG::Color3f(0,1,0)); matFgCheck->setLit (false ); OSG::PolygonForegroundUnrecPtr pFGCheck = OSG::PolygonForeground::create(); pFGCheck->setMaterial(matFgCheck); pPos = pFGCheck->editMFPositions(); pPos->push_back(OSG::Pnt2f(0.6f, 0.0f)); pPos->push_back(OSG::Pnt2f(0.9f, 0.0f)); pPos->push_back(OSG::Pnt2f(0.9f, 0.3f)); pPos->push_back(OSG::Pnt2f(0.6f, 0.3f)); vp->addForeground(pFG); vp->addForeground(pFGCheck); // vp->dump(); // Background OSG::SolidBackgroundUnrecPtr bkgndFBO = OSG::SolidBackground::create(); bkgndFBO->setColor(OSG::Color3f(1.0,0.5,0.5)); // Viewport vpFBO = OSG::FBOViewport::create(); vpFBO->setCamera (cam ); vpFBO->setBackground(bkgndFBO ); vpFBO->setRoot (root ); vpFBO->setSize (0, 0, 1, 1); vpFBO->addForeground(pFGCheck); OSG::FrameBufferObjectUnrecPtr pFBO = OSG::FrameBufferObject::create(); pTexBuffer = OSG::TextureBuffer::create(); OSG::RenderBufferUnrecPtr pDepthBuffer = OSG::RenderBuffer ::create(); pDepthBuffer->setInternalFormat(GL_DEPTH_COMPONENT24 ); pTexBuffer->setTexture(tx1o); pFBO->setSize(128, 128); pFBO->setColorAttachment(pTexBuffer, 0); pFBO->setDepthAttachment(pDepthBuffer ); pFBO->editMFDrawBuffers()->clear(); pFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT); vpFBO->setFrameBufferObject(pFBO); // Window std::cout << "GLUT winid: " << winid << std::endl; GLint glvp[4]; glGetIntegerv( GL_VIEWPORT, glvp ); gwin = OSG::GLUTWindow::create(); gwin->setGlutId(winid); gwin->setSize( glvp[2], glvp[3] ); win = gwin; win->addPort(vpFBO ); win->addPort(vp ); win->init(); // Action rentravact = OSG::RenderAction::create(); // renact->setFrustumCulling(false); // tball OSG::Vec3f pos; pos.setValues(min[0] + ((max[0] - min[0]) * 0.5), min[1] + ((max[1] - min[1]) * 0.5), max[2] + ( max[2] - min[2] ) * 1.5 ); float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6; OSG::Pnt3f tCenter(min[0] + (max[0] - min[0]) / 2, min[1] + (max[1] - min[1]) / 2, min[2] + (max[2] - min[2]) / 2); fprintf(stderr, "Startpos : %f %f %f\n", pos[0], pos[1], pos[2]); tball.setMode( OSG::Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( OSG::Trackball::OSGFree ); tball.setTranslationScale(scale); tball.setRotationCenter(tCenter); // run... pPoly = OSG::PolygonChunk::create(); pCOver->subChunk(pPoly); return 0; }
ProMan::RegistryCodes FilePushProfile(wxFileConfig *cfg) { wxFileName configFileName; wxString tcPath; cfg->Read(PRO_CFG_TC_ROOT_FOLDER, &tcPath); if ( cfg->Exists(INT_CONFIG_FILE_LOCATION) ) { wxString configFileNameString; if (cfg->Read(INT_CONFIG_FILE_LOCATION, &configFileNameString)) { configFileName.Assign(configFileNameString); } else { wxLogError(_T("Unable to retrieve Config File location even though config says key exists")); return ProMan::UnknownError; } } else { configFileName = GetPlatformDefaultConfigFilePath(tcPath); } wxASSERT_MSG( configFileName.Normalize(), wxString::Format(_T("Unable to normalize PlatformDefaultConfigFilePath (%s)"), configFileName.GetFullPath().c_str())); if ( !configFileName.FileExists() && configFileName.DirExists() ) { // was given a directory name configFileName.SetFullName(FSO_CONFIG_FILENAME); } wxFFileInputStream configFileInputStream(configFileName.GetFullPath()); wxStringInputStream configBlankInputStream(_T("")); // in case ini file doesn't exist wxInputStream* configInputStreamPtr = &configFileInputStream; if (!configFileInputStream.IsOk()) { wxLogDebug(_T("Could not read from ini file %s, writing new file"), configFileName.GetFullPath().c_str()); configInputStreamPtr = &configBlankInputStream; } wxFileConfig outConfig(*configInputStreamPtr, wxMBConvUTF8()); bool ret; // most settings are written to "Default" folder outConfig.SetPath(REG_KEY_DEFAULT_FOLDER_CFG); // Video int width, height, bitdepth; cfg->Read(PRO_CFG_VIDEO_RESOLUTION_WIDTH, &width, DEFAULT_VIDEO_RESOLUTION_WIDTH); cfg->Read(PRO_CFG_VIDEO_RESOLUTION_HEIGHT, &height, DEFAULT_VIDEO_RESOLUTION_HEIGHT); cfg->Read(PRO_CFG_VIDEO_BIT_DEPTH, &bitdepth, DEFAULT_VIDEO_BIT_DEPTH); wxString videocardValue = wxString::Format(_T("OGL -(%dx%d)x%d bit"), width, height, bitdepth); ret = outConfig.Write(REG_KEY_VIDEO_RESOLUTION_DEPTH, videocardValue); ReturnChecker(ret, __LINE__); wxString filterMethod; cfg->Read(PRO_CFG_VIDEO_TEXTURE_FILTER, &filterMethod, DEFAULT_VIDEO_TEXTURE_FILTER); int filterMethodValue = ( filterMethod.StartsWith(_T("Bilinear"))) ? 0 : 1; ret = outConfig.Write(REG_KEY_VIDEO_TEXTURE_FILTER, filterMethodValue); ReturnChecker(ret, __LINE__); int oglAnisotropicFilter; cfg->Read(PRO_CFG_VIDEO_ANISOTROPIC, &oglAnisotropicFilter, DEFAULT_VIDEO_ANISOTROPIC); // Caution: FSO expects anisotropic values to be a string, // but since we're writing to an .ini file, we can write it out as an int ret = outConfig.Write(REG_KEY_VIDEO_ANISOTROPIC, oglAnisotropicFilter); ReturnChecker(ret, __LINE__); int oglAntiAliasSample; cfg->Read(PRO_CFG_VIDEO_ANTI_ALIAS, &oglAntiAliasSample, DEFAULT_VIDEO_ANTI_ALIAS); ret = outConfig.Write(REG_KEY_VIDEO_ANTI_ALIAS, oglAntiAliasSample); ReturnChecker(ret, __LINE__); // Audio wxString soundDevice; cfg->Read(PRO_CFG_OPENAL_DEVICE, &soundDevice, DEFAULT_AUDIO_OPENAL_DEVICE); ret = outConfig.Write(REG_KEY_AUDIO_OPENAL_DEVICE, soundDevice); ReturnChecker(ret, __LINE__); // new sound code settings are written to "Sound" folder outConfig.SetPath(REG_KEY_AUDIO_FOLDER_CFG); wxString playbackDevice; cfg->Read( PRO_CFG_OPENAL_DEVICE, &playbackDevice, DEFAULT_AUDIO_OPENAL_PLAYBACK_DEVICE); ret = outConfig.Write(REG_KEY_AUDIO_OPENAL_PLAYBACK_DEVICE, playbackDevice); ReturnChecker(ret, __LINE__); wxString captureDevice; bool hasEntry = cfg->Read( PRO_CFG_OPENAL_CAPTURE_DEVICE, &captureDevice, DEFAULT_AUDIO_OPENAL_CAPTURE_DEVICE); if (hasEntry) { ret = outConfig.Write(REG_KEY_AUDIO_OPENAL_CAPTURE_DEVICE, captureDevice); ReturnChecker(ret, __LINE__); } int enableEFX; hasEntry = cfg->Read(PRO_CFG_OPENAL_EFX, &enableEFX, DEFAULT_AUDIO_OPENAL_EFX); if (hasEntry) { ret = outConfig.Write(REG_KEY_AUDIO_OPENAL_EFX, enableEFX); ReturnChecker(ret, __LINE__); } int sampleRate; cfg->Read( PRO_CFG_OPENAL_SAMPLE_RATE, &sampleRate, DEFAULT_AUDIO_OPENAL_SAMPLE_RATE); if (sampleRate != DEFAULT_AUDIO_OPENAL_SAMPLE_RATE) { ret = outConfig.Write(REG_KEY_AUDIO_OPENAL_SAMPLE_RATE, sampleRate); ReturnChecker(ret, __LINE__); } outConfig.SetPath(REG_KEY_DEFAULT_FOLDER_CFG); // Speech #if IS_WIN32 // speech is currently not supported in OS X or Linux (although Windows doesn't use this code) int speechVoice; cfg->Read(PRO_CFG_SPEECH_VOICE, &speechVoice, DEFAULT_SPEECH_VOICE); ret = outConfig.Write(REG_KEY_SPEECH_VOICE, speechVoice); ReturnChecker(ret, __LINE__); int speechVolume; cfg->Read(PRO_CFG_SPEECH_VOLUME, &speechVolume, DEFAULT_SPEECH_VOLUME); ret = outConfig.Write(REG_KEY_SPEECH_VOLUME, speechVolume); ReturnChecker(ret, __LINE__); int inTechroom, inBriefings, inGame, inMulti; cfg->Read(PRO_CFG_SPEECH_IN_TECHROOM, &inTechroom, DEFAULT_SPEECH_IN_TECHROOM); cfg->Read(PRO_CFG_SPEECH_IN_BRIEFINGS, &inBriefings, DEFAULT_SPEECH_IN_BRIEFINGS); cfg->Read(PRO_CFG_SPEECH_IN_GAME, &inGame, DEFAULT_SPEECH_IN_GAME); cfg->Read(PRO_CFG_SPEECH_IN_MULTI, &inMulti, DEFAULT_SPEECH_IN_MULTI); ret = outConfig.Write(REG_KEY_SPEECH_IN_TECHROOM, inTechroom); ReturnChecker(ret, __LINE__); ret = outConfig.Write(REG_KEY_SPEECH_IN_BRIEFINGS, inBriefings); ReturnChecker(ret, __LINE__); ret = outConfig.Write(REG_KEY_SPEECH_IN_GAME, inGame); ReturnChecker(ret, __LINE__); ret = outConfig.Write(REG_KEY_SPEECH_IN_MULTI, inMulti); ReturnChecker(ret, __LINE__); #endif // Joystick int currentJoystick; cfg->Read(PRO_CFG_JOYSTICK_ID, ¤tJoystick, DEFAULT_JOYSTICK_ID); ret = outConfig.Write(REG_KEY_JOYSTICK_ID, currentJoystick); ReturnChecker(ret, __LINE__); int joystickForceFeedback; cfg->Read( PRO_CFG_JOYSTICK_FORCE_FEEDBACK, &joystickForceFeedback, DEFAULT_JOYSTICK_FORCE_FEEDBACK); ret = outConfig.Write(REG_KEY_JOYSTICK_FORCE_FEEDBACK, joystickForceFeedback); ReturnChecker(ret, __LINE__); int joystickHit; cfg->Read(PRO_CFG_JOYSTICK_DIRECTIONAL, &joystickHit, DEFAULT_JOYSTICK_DIRECTIONAL); ret = outConfig.Write(REG_KEY_JOYSTICK_DIRECTIONAL, joystickHit); ReturnChecker(ret, __LINE__); // Network wxString networkConnectionValue; cfg->Read(PRO_CFG_NETWORK_TYPE, &networkConnectionValue, DEFAULT_NETWORK_TYPE); ret = outConfig.Write(REG_KEY_NETWORK_TYPE, networkConnectionValue); ReturnChecker(ret, __LINE__); wxString connectionSpeedValue; cfg->Read(PRO_CFG_NETWORK_SPEED, &connectionSpeedValue, DEFAULT_NETWORK_SPEED); ret = outConfig.Write(REG_KEY_NETWORK_SPEED, connectionSpeedValue); ReturnChecker(ret, __LINE__); int forcedport; cfg->Read(PRO_CFG_NETWORK_PORT, &forcedport, DEFAULT_NETWORK_PORT); if (forcedport != DEFAULT_NETWORK_PORT) { ret = outConfig.Write(REG_KEY_NETWORK_PORT, forcedport); ReturnChecker(ret, __LINE__); } else if (outConfig.Exists(REG_KEY_NETWORK_PORT)) { ret = outConfig.DeleteEntry(REG_KEY_NETWORK_PORT, false); ReturnChecker(ret, __LINE__); } // custom IP is written to "Network" folder outConfig.SetPath(REG_KEY_NETWORK_FOLDER_CFG); wxString networkIP; cfg->Read(PRO_CFG_NETWORK_IP, &networkIP, DEFAULT_NETWORK_IP); if (networkIP != DEFAULT_NETWORK_IP) { ret = outConfig.Write(REG_KEY_NETWORK_IP, networkIP); ReturnChecker(ret, __LINE__); } else if (outConfig.Exists(REG_KEY_NETWORK_IP)) { ret = outConfig.DeleteEntry(REG_KEY_NETWORK_IP, false); ReturnChecker(ret, __LINE__); } outConfig.SetPath(REG_KEY_DEFAULT_FOLDER_CFG); wxLogDebug(_T("Writing fs2_open.ini to %s"), configFileName.GetFullPath().c_str()); wxFFileOutputStream outFileStream(configFileName.GetFullPath()); outConfig.Save(outFileStream); return PushCmdlineFSO(cfg); }
bool MigrateOldConfig() { if (!(FlagListManager::GetFlagListManager()->GetBuildCaps() & FlagListManager::BUILD_CAPS_SDL)) { // Nothing to do, we have an old build return true; } wxFileName newName = GetPlatformDefaultConfigFilePathNew(); newName.SetFullName(FSO_CONFIG_FILENAME); if (wxFile::Exists(newName.GetFullPath())) { // New file already exists, nothing to do here return true; } wxLogStatus(_T("Migrating old configuration...")); #if IS_WIN32 // On Windows this is implemented by iterating through the registry and copying the values to the config file wxString keyName; HKEY useKey = GetRegistryKeyname(keyName); LONG ret = ERROR_SUCCESS; HKEY regHandle = 0; ret = RegOpenKeyExW(useKey, keyName.wc_str(), 0, KEY_READ, ®Handle ); if (ret != ERROR_SUCCESS) { // Key does not exists or some other error, assume it doesn't exist return true; // No old config, nothing to do here } wxStringInputStream configBlankInputStream(_T("")); wxFileConfig outConfig(configBlankInputStream, wxMBConvUTF8()); copyValuesIntoConfig(regHandle, outConfig, REG_KEY_DEFAULT_FOLDER_CFG); for (DWORD i = 0;; ++i) { WCHAR subkey[255]; DWORD subkeyLen = 255; LONG res = RegEnumKeyExW(regHandle, i, subkey, &subkeyLen, NULL, NULL, NULL, NULL); if (res != ERROR_SUCCESS) break; HKEY handle; res = RegOpenKeyExW(regHandle, subkey, 0, KEY_READ, &handle); if (res != ERROR_SUCCESS) { continue; } wxString sectionName(subkey, subkeyLen); sectionName = wxString::FromAscii("/") + sectionName; copyValuesIntoConfig(handle, outConfig, sectionName); RegCloseKey(handle); } RegCloseKey(regHandle); wxLogStatus(_T("Writing fs2_open.ini to %s"), newName.GetFullPath().c_str()); wxFFileOutputStream outFileStream(newName.GetFullPath()); outConfig.Save(outFileStream, wxMBConvUTF8()); #else wxFileName oldName = GetPlatformDefaultConfigFilePathOld(); oldName.SetFullName(FSO_CONFIG_FILENAME); if (!wxFile::Exists(oldName.GetFullPath())) { // Old file does not exist, probably first run. return true; } if (!wxCopyFile(oldName.GetFullPath(), newName.GetFullPath())) { wxLogError(_T("Failed to copy old configuration file to new location!")); return false; } #endif wxLogStatus(_T("Migration finished.")); return true; }
void CTaskConfigDialog::on_saveButton_clicked() { //get NS3 path QFile infile("Config"); if(!infile.exists()) { QMessageBox::critical(this, tr("Error"), "Can not find Config file!",QMessageBox::Ok); return; } if(!infile.open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox::critical(this, tr("Error"), "Can not open Config file!",QMessageBox::Ok); return; } QTextStream fileStream(&infile); m_NS3Path = fileStream.readAll(); m_NS3Path.replace("\n",""); infile.close(); QFile outFile(m_NS3Path + "/data/Task"); if(outFile.exists()) { outFile.remove(); } if(!outFile.open(QIODevice::ReadWrite | QIODevice::Text)) { QMessageBox::critical(this, tr("Error"), "Can not write to task file!",QMessageBox::Ok); return; } QTextStream outFileStream(&outFile); //format: //类型\t个数\t源端\t源IP\t终端\t终端IP\t任务 /*save task*/ int taskNum = m_task.size(); for ( int i = 0; i < taskNum; ++i ) { if(m_task[i][0] == "0")//Echo Application { if(m_task[i][1] == "0")//single { outFileStream<<m_task[i][0]<<"\t1\t" <<m_taskStructVec[i][0].srcDevice<<"\t" <<m_taskStructVec[i][0].srcIP<<"\t" <<ui->taskTable->item(i,2)->text()<<"\t" <<ui->taskTable->item(i,3)->text()<<"\t"; outFileStream<<m_task[i][2]<<"\t" <<m_task[i][3]<<"\t" <<m_task[i][4]<<"\t" <<m_task[i][5]<<"\t" <<m_task[i][6]<<"\t" <<m_task[i][7]<<"\t" <<m_task[i][8]<<endl; } else //many & all { QString desDevice = ui->taskTable->item(i,2)->text(); QString desIP = ui->taskTable->item(i,3)->text(); for ( size_t j = 0; j < m_taskStructVec[i].size(); ++j ) { outFileStream<<m_task[i][0]<<"\t"<<m_taskStructVec[i].size()<<"\t" <<m_taskStructVec[i][j].srcDevice<<"\t" <<m_taskStructVec[i][j].srcIP<<"\t" <<desDevice<<"\t" <<desIP<<"\t"; outFileStream<<m_task[i][2]<<"\t" <<m_task[i][3]<<"\t" <<m_task[i][4]<<"\t" <<m_task[i][5]<<"\t" <<m_task[i][6]<<"\t" <<m_task[i][7]<<"\t" <<m_task[i][8]<<endl; } } } else if(m_task[i][0] == "1")//On-Off Application { if(m_task[i][1] == "0")//single { outFileStream<<m_task[i][0]<<"\t1\t" <<m_taskStructVec[i][0].srcDevice<<"\t" <<m_taskStructVec[i][0].srcIP<<"\t" <<ui->taskTable->item(i,2)->text()<<"\t" <<ui->taskTable->item(i,3)->text()<<"\t"; outFileStream<<m_task[i][2]<<"\t" <<m_task[i][3]<<"\t" <<m_task[i][4]<<"\t" <<m_task[i][5]<<"\t" <<m_task[i][6]<<"\t" <<m_task[i][7]<<"\t" <<m_task[i][8]<<"\t" <<m_task[i][9]<<"\t" <<m_task[i][10]<<endl; } else //many & all { QString desDevice = ui->taskTable->item(i,2)->text(); QString desIP = ui->taskTable->item(i,3)->text(); for ( size_t j = 0; j < m_taskStructVec[i].size(); ++j ) { outFileStream<<m_task[i][0]<<"\t"<<m_taskStructVec[i].size()<<"\t" <<m_taskStructVec[i][j].srcDevice<<"\t" <<m_taskStructVec[i][j].srcIP<<"\t" <<desDevice<<"\t" <<desIP<<"\t"; outFileStream<<m_task[i][2]<<"\t" <<m_task[i][3]<<"\t" <<m_task[i][4]<<"\t" <<m_task[i][5]<<"\t" <<m_task[i][6]<<"\t" <<m_task[i][7]<<"\t" <<m_task[i][8]<<"\t" <<m_task[i][9]<<"\t" <<m_task[i][10]<<endl; } } } else if(m_task[i][0] == "2")//BulkSend Application { if(m_task[i][1] == "0")//single { outFileStream<<m_task[i][0]<<"\t1\t" <<m_taskStructVec[i][0].srcDevice<<"\t" <<m_taskStructVec[i][0].srcIP<<"\t" <<ui->taskTable->item(i,2)->text()<<"\t" <<ui->taskTable->item(i,3)->text()<<"\t"; outFileStream<<m_task[i][2]<<"\t" <<m_task[i][3]<<"\t" <<m_task[i][4]<<"\t" <<m_task[i][5]<<"\t" <<m_task[i][6]<<"\t" <<m_task[i][7]<<endl; } else //many & all { QString desDevice = ui->taskTable->item(i,2)->text(); QString desIP = ui->taskTable->item(i,3)->text(); for ( size_t j = 0; j < m_taskStructVec[i].size(); ++j ) { outFileStream<<m_task[i][0]<<"\t"<<m_taskStructVec[i].size()<<"\t" <<m_taskStructVec[i][j].srcDevice<<"\t" <<m_taskStructVec[i][j].srcIP<<"\t" <<desDevice<<"\t" <<desIP<<"\t"; outFileStream<<m_task[i][2]<<"\t" <<m_task[i][3]<<"\t" <<m_task[i][4]<<"\t" <<m_task[i][5]<<"\t" <<m_task[i][6]<<"\t" <<m_task[i][7]<<endl; } } } } outFile.close(); accept(); }
nsresult nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow, nsIUrlListener *aUrlListener, nsIMsgFolder *aMsgFolder, nsIMovemailIncomingServer *movemailServer, nsIURI ** aURL) { LOG(("nsMovemailService::GetNewMail")); nsresult rv = NS_OK; nsCOMPtr<nsIMsgIncomingServer> in_server = do_QueryInterface(movemailServer); if (!in_server) return NS_MSG_INVALID_OR_MISSING_SERVER; mMsgWindow = aMsgWindow; // Attempt to locate the mail spool file nsCAutoString spoolPath; rv = LocateSpoolFile(spoolPath); if (NS_FAILED(rv) || spoolPath.IsEmpty()) { Error(MOVEMAIL_SPOOL_FILE_NOT_FOUND, nsnull, 0); return NS_ERROR_FAILURE; } // Create an input stream for the spool file nsCOMPtr<nsILocalFile> spoolFile; rv = NS_NewNativeLocalFile(spoolPath, PR_TRUE, getter_AddRefs(spoolFile)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIInputStream> spoolInputStream; rv = NS_NewLocalFileInputStream(getter_AddRefs(spoolInputStream), spoolFile); if (NS_FAILED(rv)) { const PRUnichar *params[] = { NS_ConvertUTF8toUCS2(spoolPath).get() }; Error(MOVEMAIL_CANT_OPEN_SPOOL_FILE, params, 1); return rv; } // Get a line input interface for the spool file nsCOMPtr<nsILineInputStream> lineInputStream = do_QueryInterface(spoolInputStream, &rv); if (!lineInputStream) return rv; nsCOMPtr<nsIFileSpec> mailDirectory; rv = in_server->GetLocalPath(getter_AddRefs(mailDirectory)); NS_ENSURE_SUCCESS(rv, rv); nsFileSpec fileSpec; mailDirectory->GetFileSpec(&fileSpec); fileSpec += "Inbox"; nsIOFileStream outFileStream(fileSpec); outFileStream.seek(fileSpec.GetFileSize()); nsCOMPtr<nsIMsgFolder> serverFolder; nsCOMPtr<nsIMsgFolder> inbox; nsCOMPtr<nsIMsgFolder> rootMsgFolder; // create a new mail parser nsRefPtr<nsParseNewMailState> newMailParser = new nsParseNewMailState; if (newMailParser == nsnull) return NS_ERROR_OUT_OF_MEMORY; rv = in_server->GetRootFolder(getter_AddRefs(serverFolder)); NS_ENSURE_SUCCESS(rv, rv); rootMsgFolder = do_QueryInterface(serverFolder, &rv); if (!rootMsgFolder) return rv; PRUint32 numFolders; rv = rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, &numFolders, getter_AddRefs(inbox)); NS_ENSURE_SUCCESS(rv, rv); rv = newMailParser->Init(serverFolder, inbox, fileSpec, &outFileStream, nsnull, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); in_server->SetServerBusy(PR_TRUE); // Try and obtain the lock for the spool file if (!ObtainSpoolLock(spoolPath.get(), 5)) { nsAutoString lockFile = NS_ConvertUTF8toUCS2(spoolPath); lockFile.AppendLiteral(".lock"); const PRUnichar *params[] = { lockFile.get() }; Error(MOVEMAIL_CANT_CREATE_LOCK, params, 1); return NS_ERROR_FAILURE; } // MIDDLE of the FUN : consume the mailbox data. PRBool isMore = PR_TRUE; nsCAutoString buffer; while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(buffer, &isMore))) { // If first string is empty and we're now at EOF then abort parsing. if (buffer.IsEmpty() && !isMore) { LOG(("Empty spool file")); break; } buffer += MSG_LINEBREAK; newMailParser->HandleLine(buffer.BeginWriting(), buffer.Length()); outFileStream << buffer.get(); // 'From' lines delimit messages if (isMore && !strncmp(buffer.get(), "From ", 5)) { buffer.AssignLiteral("X-Mozilla-Status: 8000" MSG_LINEBREAK); newMailParser->HandleLine(buffer.BeginWriting(), buffer.Length()); outFileStream << buffer.get(); buffer.AssignLiteral("X-Mozilla-Status2: 00000000" MSG_LINEBREAK); newMailParser->HandleLine(buffer.BeginWriting(), buffer.Length()); outFileStream << buffer.get(); } } outFileStream.flush(); newMailParser->OnStopRequest(nsnull, nsnull, NS_OK); newMailParser->SetDBFolderStream(nsnull); // stream is going away if (outFileStream.is_open()) outFileStream.close(); // Truncate the spool file rv = spoolFile->SetFileSize(0); if (NS_FAILED(rv)) { const PRUnichar *params[] = { NS_ConvertUTF8toUCS2(spoolPath).get() }; Error(MOVEMAIL_CANT_TRUNCATE_SPOOL_FILE, params, 1); } if (!YieldSpoolLock(spoolPath.get())) { nsAutoString spoolLock = NS_ConvertUTF8toUCS2(spoolPath); spoolLock.AppendLiteral(".lock"); const PRUnichar *params[] = { spoolLock.get() }; Error(MOVEMAIL_CANT_DELETE_LOCK, params, 1); } in_server->SetServerBusy(PR_FALSE); LOG(("GetNewMail returning rv=%d", rv)); return rv; }