X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSUIT%2FSUIT_ResourceMgr.cxx;h=dd2d9024f1e497208006f7f08dc5e7530d7fcd43;hb=bad17fa10a9ee5177948f9494855cd49e5e7c958;hp=b076babd36c82b23d1856034151a91f3e22334fe;hpb=f830c97c748d8f8a6a7eccc8e3a58e19066a1181;p=modules%2Fgui.git diff --git a/src/SUIT/SUIT_ResourceMgr.cxx b/src/SUIT/SUIT_ResourceMgr.cxx index b076babd3..dd2d9024f 100755 --- a/src/SUIT/SUIT_ResourceMgr.cxx +++ b/src/SUIT/SUIT_ResourceMgr.cxx @@ -1,27 +1,35 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include "SUIT_ResourceMgr.h" -#include -#include -#include -#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#endif /*! Constructor @@ -66,9 +74,6 @@ QString SUIT_ResourceMgr::loadDoc( const QString& prefix, const QString& id ) co return path( docSection, prefix, id ); } -#ifndef WIN32 -#include -#endif /*! Returns the user file name for specified application */ @@ -76,13 +81,14 @@ QString SUIT_ResourceMgr::userFileName( const QString& appName, const bool for_l { QString pathName; + QStringList arguments = QApplication::arguments(); // Try config file, given in arguments - for (int i = 1; i < qApp->argc(); i++) { + for (int i = 1; i < arguments.count(); i++) { QRegExp rx ("--resources=(.+)"); - if ( rx.search( QString(qApp->argv()[i]) ) >= 0 && rx.capturedTexts().count() > 1 ) { - QString file = rx.capturedTexts()[1]; + if ( rx.indexIn( arguments[i] ) >= 0 && rx.numCaptures() > 0 ) { + QString file = rx.cap(1); QFileInfo fi (file); - pathName = fi.absFilePath(); + pathName = fi.absoluteFilePath(); } } @@ -110,33 +116,64 @@ QString SUIT_ResourceMgr::userFileName( const QString& appName, const bool for_l */ QString SUIT_ResourceMgr::findAppropriateUserFile( const QString& fname ) const { - QDir d( QFileInfo( fname ).dir( true ) ); - d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks ); - QStringList l = d.entryList(); QString appr_file; - int id0 = userFileId( fname ), id, appr=-1; - if( id0<0 ) + + // calculate default file id from user file name + long id0 = userFileId( fname ); + if ( id0 < 0 ) // can't calculate file id from user file name, no further processing return appr_file; - for( QStringList::const_iterator anIt = l.begin(), aLast = l.end(); anIt!=aLast; anIt++ ) + long id, appr = -1; + + QStringList all_files; + + // get all files from the same dir where use file is (should be) situated + QDir d( QFileInfo( fname ).dir() ); + if ( d.exists() ) { + d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks ); + QStringList l = d.entryList(); + foreach( QString ll, l ) + all_files << d.absoluteFilePath( ll ); + } + // backward compatibility: check also user's home directory (if it differs from above one) + QDir home = QDir::home(); + if ( home.exists() && d.canonicalPath() != home.canonicalPath() ) { + home.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks ); + QStringList l = home.entryList(); + foreach( QString ll, l ) + all_files << home.absoluteFilePath( ll ); + } + + for( QStringList::const_iterator anIt = all_files.begin(), aLast = all_files.end(); anIt!=aLast; anIt++ ) { id = userFileId( *anIt ); - if( id<0 ) + if ( id < 0 ) continue; - if( appr < 0 || abs( id-id0 ) < abs( appr-id0 ) ) + if( appr < 0 || qAbs( id-id0 ) < qAbs( appr-id0 ) ) { appr = id; - appr_file = d.absFilePath( *anIt ); + appr_file = d.absoluteFilePath( *anIt ); + } + else if ( qAbs( id-id0 ) == qAbs( appr-id0 ) ) { + // appr == id that means that another file with equal version id is detected + // this can happen, e.g. if one file begins with "." and other one - not + // ... + // VSR 24/09/2012: issue 0021781: since version 6.6.0 user filename is not prepended with "." + // when it is stored in the ~/.config/ directory; + // for backward compatibility we also check files prepended with "." with lower priority + if ( !QFileInfo( *anIt ).fileName().startsWith(".") ) + appr_file = home.absoluteFilePath( *anIt ); } } + return appr_file; } /*! Calculates integer extended version number by user file name for comparing */ -int SUIT_ResourceMgr::userFileId( const QString& ) const +long SUIT_ResourceMgr::userFileId( const QString& ) const { return -1; }