From eadde51587d798239746d85e2e37cf34dc77d7ee Mon Sep 17 00:00:00 2001 From: apo Date: Fri, 10 Feb 2006 14:12:44 +0000 Subject: [PATCH] Final fix for Bug GVIEW10647 Crash saving the model (to avoid usage of the temporary directory during the saving) --- src/VISU_I/VISU_Gen_i.cc | 91 ++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/src/VISU_I/VISU_Gen_i.cc b/src/VISU_I/VISU_Gen_i.cc index ff03f9f2..f4cdedbe 100644 --- a/src/VISU_I/VISU_Gen_i.cc +++ b/src/VISU_I/VISU_Gen_i.cc @@ -299,58 +299,69 @@ namespace VISU //=========================================================================== SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, const char* theURL, - bool isMultiFile) + bool theIsMultiFile) { Mutex mt(myMutex); - string aDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir(); - TCollection_AsciiString aTmpDir (const_cast(aDir.c_str())); + string aTmpDir = theURL; if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<GetStudy(); - - //CORBA::Boolean anIsValidScript; - //Engines::TMPFile_var aDump = DumpPython(aStudy,false,anIsValidScript); + + typedef std::vector TFileNames; + TFileNames aFileNames; + TFileNames aFiles; - SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent); - for (; itBig->More(); itBig->Next()) { - SALOMEDS::SObject_var gotBranch = itBig->Value(); + SALOMEDS::Study_var aStudy = theComponent->GetStudy(); + SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent); + for (; anIter->More(); anIter->Next()) { + SALOMEDS::SObject_var gotBranch = anIter->Value(); CORBA::Object_var anObj = SObjectToObject(gotBranch); if(CORBA::is_nil(anObj)) continue; - if(Result_i* pResult = dynamic_cast(GetServant(anObj).in())){ - switch(pResult->GetCreationId()){ + if(Result_i* aResult = dynamic_cast(GetServant(anObj).in())){ + switch(aResult->GetCreationId()){ case Result_i::eImportFile: case Result_i::eCopyAndImportFile: { - const QFileInfo& aFileInfo = pResult->GetFileInfo(); - QString aPrefix(""); - if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str(); - QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str(); - static QString aCommand; - aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1()); - - int aRes = system(aCommand); - if(aRes){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<URL()) + aFileName; + + std::ostringstream aStream; + aStream<<"cp "< 0){ - SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; - aSeq->length(aFileNames.Length()); - for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--) - aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString()); - aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); - if(!isMultiFile) - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + + if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.size() - "<length(aFileNames.size()); + for(int aCounter = aFileNames.size(); aCounter > 0; aCounter--) + aListOfFileNames[aCounter-1] = aFileNames[aCounter-1].c_str(); } + + SALOMEDS::ListOfFileNames_var aListOfFiles = new SALOMEDS::ListOfFileNames; + aListOfFiles->length(aFiles.size()); + if(!aFiles.empty()){ + for(int aCounter = aFileNames.size(); aCounter > 0; aCounter--) + aListOfFiles[aCounter-1] = aFiles[aCounter-1].c_str(); + } + + SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0); + if(theIsMultiFile) + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aListOfFiles.in(), theIsMultiFile); + else + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aListOfFiles.in(), aListOfFileNames.in()); + return aStreamFile._retn(); } -- 2.39.2