moved all the xml-files into the resources. This make it much easier to handle if musrWiz is not locally installed.
This commit is contained in:
parent
ceaf7d0c6a
commit
c17924a742
@ -888,7 +888,6 @@ bool PMusrWizDefaultXMLParser::fatalError( const QXmlParseException & exception
|
|||||||
PAdmin::PAdmin() : QObject()
|
PAdmin::PAdmin() : QObject()
|
||||||
{
|
{
|
||||||
QString path, fln, pathFln;
|
QString path, fln, pathFln;
|
||||||
bool found = false;
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
fValid = true;
|
fValid = true;
|
||||||
@ -900,51 +899,30 @@ PAdmin::PAdmin() : QObject()
|
|||||||
// 2nd: check $HOME/.musrfit/musrWiz/musrWiz.xml
|
// 2nd: check $HOME/.musrfit/musrWiz/musrWiz.xml
|
||||||
path = std::getenv("HOME");
|
path = std::getenv("HOME");
|
||||||
pathFln = path + "/.musrfit/musrWiz/musrWiz.xml";
|
pathFln = path + "/.musrfit/musrWiz/musrWiz.xml";
|
||||||
if (QFile::exists(pathFln)) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
if (found) {
|
|
||||||
if (loadMusrWizDefault(pathFln)) {
|
if (loadMusrWizDefault(pathFln)) {
|
||||||
QMessageBox::warning(0, "WARNING", "Couldn't find musrWiz.xml file.");
|
QMessageBox::warning(0, "WARNING", "Couldn't find musrWiz.xml file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// load musrfit funcs
|
// load musrfit funcs
|
||||||
found = false;
|
|
||||||
// 1st: check local directory
|
// 1st: check local directory
|
||||||
pathFln = QString("./musrfit_funcs.xml");
|
pathFln = QString("./musrfit_funcs.xml");
|
||||||
if (!QFile::exists(pathFln)) {
|
if (!QFile::exists(pathFln)) {
|
||||||
// 2nd: check $HOME/.musrfit/musrWiz/musrfit_funcs.xml
|
// 2nd: check $HOME/.musrfit/musrWiz/musrfit_funcs.xml
|
||||||
path = std::getenv("HOME");
|
path = std::getenv("HOME");
|
||||||
pathFln = path + "/.musrfit/musrWiz/musrfit_funcs.xml";
|
pathFln = path + "/.musrfit/musrWiz/musrfit_funcs.xml";
|
||||||
if (QFile::exists(pathFln)) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
fValid = false;
|
|
||||||
QMessageBox::critical(0, "FATAL ERROR", "Couldn't find musrfit_funcs.xml.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (loadMusrfitFunc(pathFln)) {
|
if (loadMusrfitFunc(pathFln)) {
|
||||||
fValid = false;
|
fValid = false;
|
||||||
QMessageBox::critical(0, "FATAL ERROR", "Couldn't find any musrfit function definitions.");
|
QMessageBox::critical(0, "FATAL ERROR", "Couldn't find any musrfit function definitions.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// load instrument definitions
|
// load instrument definitions
|
||||||
found = false;
|
|
||||||
|
|
||||||
QStringList instStr;
|
QStringList instStr;
|
||||||
instStr << "psi" << "triumf" << "isis" << "jparc";
|
instStr << "psi" << "triumf" << "isis" << "jparc";
|
||||||
|
|
||||||
for (int i=0; i<instStr.size(); i++) {
|
for (int i=0; i<instStr.size(); i++) {
|
||||||
found = false;
|
|
||||||
// XML Parser part
|
// XML Parser part
|
||||||
// 1st: check local directory
|
// 1st: check local directory
|
||||||
path = QString("./");
|
path = QString("./");
|
||||||
@ -953,18 +931,12 @@ PAdmin::PAdmin() : QObject()
|
|||||||
if (!QFile::exists(pathFln)) {
|
if (!QFile::exists(pathFln)) {
|
||||||
// 2nd: check $HOME/.musrfit/musrWiz/instrument_def_XXX.xml
|
// 2nd: check $HOME/.musrfit/musrWiz/instrument_def_XXX.xml
|
||||||
path = std::getenv("HOME");
|
path = std::getenv("HOME");
|
||||||
pathFln = path + "/.musrfit/musrWiz/" + fln;
|
path += "/.musrfit/musrWiz/";
|
||||||
if (QFile::exists(pathFln)) {
|
if (loadInstrumentDef(path, fln)) {
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
if (found) {
|
|
||||||
count++;
|
|
||||||
if (loadInstrumentDef(pathFln)) {
|
|
||||||
fValid = false;
|
fValid = false;
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1248,6 +1220,31 @@ PInstrument *PAdmin::getInstrument(QString institute, QString instrument)
|
|||||||
*/
|
*/
|
||||||
int PAdmin::loadMusrWizDefault(QString fln)
|
int PAdmin::loadMusrWizDefault(QString fln)
|
||||||
{
|
{
|
||||||
|
// check if fln already exists
|
||||||
|
if (!QFile::exists(fln)) {
|
||||||
|
QFile file(":/musrWiz.xml");
|
||||||
|
if (file.exists()) {
|
||||||
|
// get $HOME
|
||||||
|
QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment();
|
||||||
|
QString pathName = procEnv.value("HOME", "");
|
||||||
|
pathName += "/.musrfit/musrWiz";
|
||||||
|
// check if the directory $HOME/.musrfit/musrWiz exists if not create it
|
||||||
|
QDir dir(pathName);
|
||||||
|
if (!dir.exists()) {
|
||||||
|
// directory $HOME/.musrfit/musredit does not exist hence create it
|
||||||
|
dir.mkpath(pathName);
|
||||||
|
}
|
||||||
|
pathName += "/musrWiz.xml";
|
||||||
|
if (file.copy(pathName)) {
|
||||||
|
cout << "**INFO** '" << pathName.toLatin1().data() << "' did not exist, hence it is created." << endl;
|
||||||
|
} else {
|
||||||
|
QString msg = QString("Couldn't create '%1'. Please check.").arg(pathName);
|
||||||
|
QMessageBox::critical(0, "ERROR", msg);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PMusrWizDefaultXMLParser handler(this);
|
PMusrWizDefaultXMLParser handler(this);
|
||||||
QFile xmlFile(fln);
|
QFile xmlFile(fln);
|
||||||
QXmlInputSource source( &xmlFile );
|
QXmlInputSource source( &xmlFile );
|
||||||
@ -1267,6 +1264,24 @@ int PAdmin::loadMusrWizDefault(QString fln)
|
|||||||
*/
|
*/
|
||||||
int PAdmin::loadMusrfitFunc(QString fln)
|
int PAdmin::loadMusrfitFunc(QString fln)
|
||||||
{
|
{
|
||||||
|
// check if fln already exists
|
||||||
|
if (!QFile::exists(fln)) {
|
||||||
|
QFile file(":/func_defs/musrfit_funcs.xml");
|
||||||
|
if (file.exists()) {
|
||||||
|
// get $HOME
|
||||||
|
QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment();
|
||||||
|
QString pathName = procEnv.value("HOME", "");
|
||||||
|
pathName += "/.musrfit/musrWiz/musrfit_funcs.xml";
|
||||||
|
if (file.copy(pathName)) {
|
||||||
|
cout << "**INFO** '" << pathName.toLatin1().data() << "' did not exist, hence it is created." << endl;
|
||||||
|
} else {
|
||||||
|
QString msg = QString("Couldn't create '%1'. Please check.").arg(pathName);
|
||||||
|
QMessageBox::critical(0, "ERROR", msg);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PFuncXMLParser handler(this);
|
PFuncXMLParser handler(this);
|
||||||
QFile xmlFile(fln);
|
QFile xmlFile(fln);
|
||||||
QXmlInputSource source( &xmlFile );
|
QXmlInputSource source( &xmlFile );
|
||||||
@ -1283,18 +1298,41 @@ int PAdmin::loadMusrfitFunc(QString fln)
|
|||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief PAdmin::loadInstrumentDef
|
* @brief PAdmin::loadInstrumentDef
|
||||||
|
* @param path
|
||||||
* @param fln
|
* @param fln
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int PAdmin::loadInstrumentDef(QString fln)
|
int PAdmin::loadInstrumentDef(QString path, QString fln)
|
||||||
{
|
{
|
||||||
|
// check if fln already exists
|
||||||
|
QString pathFln = path+fln;
|
||||||
|
if (!QFile::exists(pathFln)) {
|
||||||
|
QString resFln = QString(":/instrument_defs/%1").arg(fln);
|
||||||
|
QFile file(resFln);
|
||||||
|
if (file.exists()) {
|
||||||
|
// get $HOME
|
||||||
|
QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment();
|
||||||
|
QString pathName = procEnv.value("HOME", "");
|
||||||
|
pathName += "/.musrfit/musrWiz/" + fln;
|
||||||
|
if (file.copy(pathName)) {
|
||||||
|
cout << "**INFO** '" << pathName.toLatin1().data() << "' did not exist, hence it is created." << endl;
|
||||||
|
} else {
|
||||||
|
QString msg = QString("Couldn't create '%1'. Please check.").arg(pathName);
|
||||||
|
QMessageBox::critical(0, "ERROR", msg);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PInstrumentDefXMLParser handler(this);
|
PInstrumentDefXMLParser handler(this);
|
||||||
QFile xmlFile(fln);
|
QFile xmlFile(pathFln);
|
||||||
QXmlInputSource source( &xmlFile );
|
QXmlInputSource source( &xmlFile );
|
||||||
QXmlSimpleReader reader;
|
QXmlSimpleReader reader;
|
||||||
reader.setContentHandler( &handler );
|
reader.setContentHandler( &handler );
|
||||||
if (!reader.parse(source)) {
|
if (!reader.parse(source)) {
|
||||||
QString errMsg = QString("Error parsing %1 instrument def file.").arg(fln);
|
QString errMsg = QString("Error parsing %1 instrument def file.").arg(pathFln);
|
||||||
QMessageBox::critical(0, "ERROR", errMsg);
|
QMessageBox::critical(0, "ERROR", errMsg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ class PAdmin : public QObject
|
|||||||
|
|
||||||
int loadMusrWizDefault(QString fln);
|
int loadMusrWizDefault(QString fln);
|
||||||
int loadMusrfitFunc(QString fln);
|
int loadMusrfitFunc(QString fln);
|
||||||
int loadInstrumentDef(QString fln);
|
int loadInstrumentDef(QString path, QString fln);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _PADMIN_H_
|
#endif // _PADMIN_H_
|
||||||
|
@ -31,36 +31,6 @@ win32:target.path = c:/musrfit/bin
|
|||||||
|
|
||||||
INSTALLS += target
|
INSTALLS += target
|
||||||
|
|
||||||
# install path for the XML instrument def file
|
|
||||||
unix:instrumendDef.path = $$(HOME)/.musrfit/musrWiz
|
|
||||||
macx:instrumendDef.path = $$(HOME)/.musrfit/musrWiz
|
|
||||||
instrumendDef.files = instrument_defs/instrument_def_psi.xml
|
|
||||||
exists( $$(HOME)/.musrfit/musrWiz/instrument_def_psi.xml ) {
|
|
||||||
unix:instrumendDef.extra = mv $$(HOME)/.musrfit/musrWiz/instrument_def_psi.xml $$(HOME)/.musrfit/musrWiz/instrument_def_psi.xml.backup
|
|
||||||
macx:instrumendDef.extra = mv $$(HOME)/.musrfit/musrWiz/instrument_def_psi.xml $$(HOME)/.musrfit/musrWiz/instrument_def_psi.xml.backup
|
|
||||||
}
|
|
||||||
INSTALLS += instrumendDef
|
|
||||||
|
|
||||||
# install path for the XML musrfit funcs file
|
|
||||||
unix:musrfitFunc.path = $$(HOME)/.musrfit/musrWiz
|
|
||||||
macx:musrfitFunc.path = $$(HOME)/.musrfit/musrWiz
|
|
||||||
musrfitFunc.files = func_defs/musrfit_funcs.xml
|
|
||||||
exists( $$(HOME)/.musrfit/musrWiz/musrfit_funcs.xml ) {
|
|
||||||
unix:musrfitFunc.extra = mv $$(HOME)/.musrfit/musrWiz/musrfit_funcs.xml $$(HOME)/.musrfit/musrWiz/musrfit_funcs.xml.backup
|
|
||||||
macx:musrfitFunc.extra = mv $$(HOME)/.musrfit/musrWiz/musrfit_funcs.xml $$(HOME)/.musrfit/musrWiz/musrfit_funcs.xml.backup
|
|
||||||
}
|
|
||||||
INSTALLS += musrfitFunc
|
|
||||||
|
|
||||||
# install path for the musrWiz defaults XML
|
|
||||||
unix:musrWizDefault.path = $$(HOME)/.musrfit/musrWiz
|
|
||||||
macx:musrWizDefault.path = $$(HOME)/.musrfit/musrWiz
|
|
||||||
musrWizDefault.files = musrWiz.xml
|
|
||||||
exists( $$(HOME)/.musrfit/musrWiz/musrWiz.xml ) {
|
|
||||||
unix:musrWizDefault.extra = mv $$(HOME)/.musrfit/musrWiz/musrWiz.xml $$(HOME)/.musrfit/musrWiz/musrWiz.xml.backup
|
|
||||||
macx:musrWizDefault.extra = mv $$(HOME)/.musrfit/musrWiz/musrWiz.xml $$(HOME)/.musrfit/musrWiz/musrWiz.xml.backup
|
|
||||||
}
|
|
||||||
INSTALLS += musrWizDefault
|
|
||||||
|
|
||||||
CONFIG += qt \
|
CONFIG += qt \
|
||||||
warn_on \
|
warn_on \
|
||||||
release
|
release
|
||||||
|
@ -4,5 +4,9 @@
|
|||||||
<file>icons/musrWiz-22x22-dark.svg</file>
|
<file>icons/musrWiz-22x22-dark.svg</file>
|
||||||
<file>icons/musrWiz-32x32.svg</file>
|
<file>icons/musrWiz-32x32.svg</file>
|
||||||
<file>icons/musrWiz-32x32-dark.svg</file>
|
<file>icons/musrWiz-32x32-dark.svg</file>
|
||||||
|
<file>musrWiz.xml</file>
|
||||||
|
<file>func_defs/musrfit_funcs.xml</file>
|
||||||
|
<file>instrument_defs/instrument_def_psi.xml</file>
|
||||||
|
<file>instrument_defs/instrument_def_isis.xml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user