changed the check for is a file using stat and not looking for a dot in file name

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@117 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
l_maliakal_d
2012-11-26 15:54:22 +00:00
parent 95741a1c33
commit 0b8f6cc925
3 changed files with 64 additions and 48 deletions

View File

@ -129,29 +129,30 @@ void qActionsWidget::SetScriptFile(){
cout << "Setting\taction:" << id << "\tscript:" << fName.toAscii().constData() << endl; cout << "Setting\taction:" << id << "\tscript:" << fName.toAscii().constData() << endl;
#endif #endif
bool set = false; bool set = false;
struct stat st_buf;
//blank //blank
if(fName.isEmpty()) set = true; if(fName.isEmpty())
else if(!fName.compare("none")) set = true; set = true;
else if(!fName.compare("none"))
set = true;
//not blank //not blank
else{ else{
QString file = dispScript->text().section('/',-1); //path doesnt exist
//is a file if(stat(fName.toAscii().constData(),&st_buf)){
if(file.contains('.')){ qDefs::Message(qDefs::WARNING,"The script file entered does not exist","ActionsWidget");
//check if it exists and set the script file dispScript->setText(QString(myDet->getActionScript(id).c_str()));
if(QFile::exists(fName)) set = true; }
//if the file doesnt exist, set it to what it was before //if its not a file
else{ else if (!S_ISREG (st_buf.st_mode)) {
qDefs::Message(qDefs::WARNING,"The script file entered does not exist","ActionsWidget");
dispScript->setText(QString(myDet->getActionScript(id).c_str()));
}
}//not a file, set it to what it was before
else {
qDefs::Message(qDefs::WARNING,"The script file path entered is not a file","ActionsWidget"); qDefs::Message(qDefs::WARNING,"The script file path entered is not a file","ActionsWidget");
dispScript->setText(QString(myDet->getActionScript(id).c_str())); dispScript->setText(QString(myDet->getActionScript(id).c_str()));
} }
else
set=true;
} }
//if blank or valid file //if blank or valid file
if(set){ if(set){
//scan and positions wouldnt get here //scan and positions wouldnt get here

View File

@ -285,12 +285,24 @@ void qDetectorMain::LoadConfigFile(const string fName){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Loading config file at start up:" << fName << endl; cout << "Loading config file at start up:" << fName << endl;
#endif #endif
QString file = QString(fName.c_str());//.section('/',-1); struct stat st_buf;
if((file.contains('.'))&&(QFile::exists(file))){ QString file = QString(fName.c_str());
if(myDet->readConfigurationFile(fName)!=slsDetectorDefs::FAIL)
qDefs::Message(qDefs::INFORMATION,"<nobr>The Configuration Parameters have been loaded successfully at start up.</nobr>","Main"); //path doesnt exist
else qDefs::Message(qDefs::WARNING,string("<nobr>Could not load the Configuration Parameters at start up from file:</nobr><br><nobr>")+fName,"Main"); if(stat(fName.c_str(),&st_buf))
}else qDefs::Message(qDefs::WARNING,string("<nobr>Start up configuration failed to load. The following file does not exist:</nobr><br><nobr>")+fName,"Main"); qDefs::Message(qDefs::WARNING,string("<nobr>Start up configuration failed to load. The following file does not exist:</nobr><br><nobr>")+fName,"Main");
//not a file
else if (!S_ISREG (st_buf.st_mode))
qDefs::Message(qDefs::WARNING,string("<nobr>Start up configuration failed to load. The following file is not a recognized file format:</nobr><br><nobr>")+fName,"Main");
//could not load config file
else if(myDet->readConfigurationFile(fName)==slsDetectorDefs::FAIL)
qDefs::Message(qDefs::INFORMATION,"<nobr>The Configuration Parameters have been loaded successfully at start up.</nobr>","Main");
//successful
else
qDefs::Message(qDefs::INFORMATION,"<nobr>The Configuration Parameters have been loaded successfully at start up.</nobr>","Main");
} }

View File

@ -445,11 +445,12 @@ void qScanWidget::SetScriptFile(){
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cout << "Entering SetScriptFile()" << endl; cout << "Entering SetScriptFile()" << endl;
#endif #endif
QString fName = dispScript->text();bool set = false; QString fName = dispScript->text();
#ifdef VERBOSE #ifdef VERBOSE
cout << "Setting\tscan:" << id << "\tscript:" << fName.toAscii().constData() << endl; cout << "Setting\tscan:" << id << "\tscript:" << fName.toAscii().constData() << endl;
#endif #endif
bool set = false;
struct stat st_buf;
//blank //blank
if(fName.isEmpty()) if(fName.isEmpty())
@ -466,22 +467,18 @@ void qScanWidget::SetScriptFile(){
} }
//not blank and custom script mode //not blank and custom script mode
if(!set){ if(!set){
QString file = dispScript->text().section('/',-1); //path doesnt exist
//is a file if(stat(fName.toAscii().constData(),&st_buf)){
if(file.contains('.')){ qDefs::Message(qDefs::WARNING,"The script file entered does not exist","ScanWidget");
//check if it exists and set the script file dispScript->setText(QString(myDet->getScanScript(id).c_str()));
if(QFile::exists(fName)) }
set = true; //if its not a file
//if the file doesnt exist, set it to what it was before else if (!S_ISREG (st_buf.st_mode)) {
else{
qDefs::Message(qDefs::WARNING,"The script file entered does not exist","ScanWidget");
dispScript->setText(QString(myDet->getScanScript(id).c_str()));
}
}//not a file, set it to what it was before
else {
qDefs::Message(qDefs::WARNING,"The script file path entered is not a file","ScanWidget"); qDefs::Message(qDefs::WARNING,"The script file path entered is not a file","ScanWidget");
dispScript->setText(QString(myDet->getScanScript(id).c_str())); dispScript->setText(QString(myDet->getScanScript(id).c_str()));
} }
else
set=true;
} }
//if blank or valid file //if blank or valid file
@ -974,8 +971,10 @@ void qScanWidget::SetFileSteps(){
cout << "Setting\tscan:" << id << "\tfile\t:" << fName.toAscii().constData() << endl; cout << "Setting\tscan:" << id << "\tfile\t:" << fName.toAscii().constData() << endl;
#endif #endif
bool set = false; bool set = false;
struct stat st_buf;
if(fName.isEmpty()){ //blank //blank
if(fName.isEmpty()){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Empty file" << endl; cout << "Empty file" << endl;
#endif #endif
@ -983,21 +982,23 @@ void qScanWidget::SetFileSteps(){
radioFile->setText("Values from File:*"); radioFile->setText("Values from File:*");
QString errTip = fileTip + QString("<br><br><nobr><font color=\"red\">The file path is empty.</font></nobr>");; QString errTip = fileTip + QString("<br><br><nobr><font color=\"red\">The file path is empty.</font></nobr>");;
radioFile->setToolTip(errTip);dispFile->setToolTip(errTip);btnFile->setToolTip(errTip); radioFile->setToolTip(errTip);dispFile->setToolTip(errTip);btnFile->setToolTip(errTip);
}else{ }
//not a blank
else{
QString file = dispFile->text().section('/',-1); QString file = dispFile->text().section('/',-1);
if(file.contains('.')){ //is a file
//check if it exists and set the script file //path doesnt exist
if(QFile::exists(fName)) set = true; if(stat(file.toAscii().constData(),&st_buf)){
else{//if the file doesnt exist, set it to what it was before
#ifdef VERBOSE #ifdef VERBOSE
cout << "The file entered does not exist." << endl; cout << "The file entered does not exist." << endl;
#endif #endif
radioFile->setPalette(red); radioFile->setPalette(red);
radioFile->setText("Values from File:*"); radioFile->setText("Values from File:*");
QString errTip = fileTip + QString("<br><br><nobr><font color=\"red\">The file entered does not exist.</font></nobr>"); QString errTip = fileTip + QString("<br><br><nobr><font color=\"red\">The file entered does not exist.</font></nobr>");
radioFile->setToolTip(errTip);dispFile->setToolTip(errTip);btnFile->setToolTip(errTip); radioFile->setToolTip(errTip);dispFile->setToolTip(errTip);btnFile->setToolTip(errTip);
} }
} else {//not a file, set it to what it was before //if its not a file
else if (!S_ISREG (st_buf.st_mode)) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "The file path entered is not a file." << endl; cout << "The file path entered is not a file." << endl;
#endif #endif
@ -1006,6 +1007,8 @@ void qScanWidget::SetFileSteps(){
QString errTip = fileTip + QString("<br><br><nobr><font color=\"red\">The file path entered is not a file.</font></nobr>"); QString errTip = fileTip + QString("<br><br><nobr><font color=\"red\">The file path entered is not a file.</font></nobr>");
radioFile->setToolTip(errTip); dispFile->setToolTip(errTip);btnFile->setToolTip(errTip); radioFile->setToolTip(errTip); dispFile->setToolTip(errTip);btnFile->setToolTip(errTip);
} }
else
set = true;
} }
//if valid file //if valid file