From f236ba666254f70d84e63c56156e842e3db74dc5 Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 24 Sep 2012 08:31:43 +0000 Subject: [PATCH] 0021781: [CEA 616] Suppress . in the user's config files --- src/Qtx/QtxResourceMgr.cxx | 6 ++- src/SUIT/SUIT_ResourceMgr.cxx | 45 ++++++++++-------- src/Session/SALOME_Session_Server.cxx | 66 ++++++++++++++++++++++++--- 3 files changed, 89 insertions(+), 28 deletions(-) diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 946374411..51a9630df 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -2860,7 +2860,11 @@ QString QtxResourceMgr::userFileName( const QString& appName, const bool /*for_l #ifdef WIN32 fileName = QString( "%1.%2" ).arg( appName ).arg( currentFormat() ); #else - fileName = QString( ".%1rc" ).arg( appName ); + fileName = QString( "%1rc" ).arg( appName ); + // VSR 24/09/2012: issue 0021781: do not prepend filename with "." + // when user file is stored in ~/.config/ directory + if ( cfgAppName.isEmpty() ) + fileName.prepend( "." ); #endif if ( !fileName.isEmpty() ) diff --git a/src/SUIT/SUIT_ResourceMgr.cxx b/src/SUIT/SUIT_ResourceMgr.cxx index b2fa90dcf..dc7d2aedc 100755 --- a/src/SUIT/SUIT_ResourceMgr.cxx +++ b/src/SUIT/SUIT_ResourceMgr.cxx @@ -125,40 +125,45 @@ QString SUIT_ResourceMgr::findAppropriateUserFile( const QString& fname ) const 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(); - for( QStringList::const_iterator anIt = l.begin(), aLast = l.end(); anIt!=aLast; anIt++ ) - { - id = userFileId( *anIt ); - if ( id < 0 ) - continue; - if( appr < 0 || qAbs( id-id0 ) < qAbs( appr-id0 ) ) - { - appr = id; - appr_file = d.absoluteFilePath( *anIt ); - } - } + 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 ) + continue; - for( QStringList::const_iterator anIt = l.begin(), aLast = l.end(); anIt!=aLast; anIt++ ) + if( appr < 0 || qAbs( id-id0 ) < qAbs( appr-id0 ) ) { - id = userFileId( *anIt ); - if ( id < 0 ) - continue; - if( appr < 0 || qAbs( id-id0 ) < qAbs( appr-id0 ) ) - { - appr = id; + appr = id; + 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 ); - } } } diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 3dfee002d..f94e9a639 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -178,14 +178,59 @@ protected: virtual long userFileId( const QString& _fname ) const { + ////////////////////////////////////////////////////////////////////////////////////////////// + // In SALOME and SALOME-based applications the user preferences file is named as + // - .xml. on Windows + // - rc. on Linux + // where + // * AppName is application name, default SalomeApp (can be customized in SALOME-based + // applications + // * AppVersion is application version + // + // Since version 6.5.0 of SALOME, user file is situated in the ~/.config/salome + // directory. For backward compatibility, when user preferences from nearest + // version of application is searched, user home directory is also looked through, + // with lower priority. + // + // Since version 6.6.0 of SALOME, user file name on Linux is no more prefixed by dot + // symbol since it is situated in hidden ~/.config/salome directory. Files with dot + // prefix also though taken into account (with lower priority) for backward compatibility. + // + // Notes: + // - Currently the following format of version number is supported: + // [.[.[]]] + // Parts in square brackets are considered optional. Here: + // * major - major version id + // * minor - minor version id + // * release - maintenance version id + // * type - dev or patch marker; it can be either one alphabetical symbol (from 'a' to 'z') + // or 'rc' to point release candidate (case-insensitive) + // * dev - dev version or patch number + // All numerical values must be of range [1-99]. + // Examples: 1.0, 6.5.0, 1.2.0a1, 3.3.3rc3 (release candidate 3), 11.0.0p1 (patch 1) + // + // - Versioning approach can be customized by implementing and using own resource manager class, + // see QtxResurceMgr, SUIT_ResourceMgr classes. + ////////////////////////////////////////////////////////////////////////////////////////////// long id = -1; if ( !myExtAppName.isEmpty() ) { #ifdef WIN32 - QRegExp exp( QString( "%1\\.%2\\.([a-zA-Z0-9.]+)$" ).arg( myExtAppName ).arg( currentFormat() ) ); + // On Windows, user file name is something like SalomeApp.xml.6.5.0 where + // - SalomeApp is an application name (can be customized) + // - xml is a file format (xml or ini) + // - 6.5.0 is an application version, can include alfa/beta/rc marks, e.g. 6.5.0a3, 6.5.0rc1 + QRegExp exp( QString( "%1\\.%2\\.([a-zA-Z0-9.]+)" ).arg( myExtAppName ).arg( currentFormat() ) ); #else - QRegExp exp( QString( "\\.%1rc\\.([a-zA-Z0-9.]+)$" ).arg( myExtAppName ) ); + // On Linux, user file name is something like SalomeApprc.6.5.0 where + // - SalomeApp is an application name (can be customized) + // - 6.5.0 is an application version, can include alfa/beta/rc marks, e.g. 6.5.0a3, 6.5.0rc1 + + // 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 + QRegExp exp( QString( "\\.?%1rc\\.([a-zA-Z0-9.]+)" ).arg( myExtAppName ) ); #endif - QRegExp vers_exp( "^([0-9]+)([A-Za-z]?)([0-9]*)$" ); + QRegExp vers_exp( "^([0-9]+)([A-Z]|RC)?([0-9]*)", Qt::CaseInsensitive ); QString fname = QFileInfo( _fname ).fileName(); if( exp.exactMatch( fname ) ) { @@ -195,10 +240,17 @@ protected: if ( vers.count() > 0 ) major = vers[0].toInt(); if ( vers.count() > 1 ) minor = vers[1].toInt(); if ( vers.count() > 2 ) { - if( vers_exp.indexIn( vers[2] ) != -1 ) { + if ( vers_exp.indexIn( vers[2] ) != -1 ) { release = vers_exp.cap( 1 ).toInt(); - dev1 = vers_exp.cap( 2 )[ 0 ].toLatin1(); - dev2 = vers_exp.cap( 3 ).toInt(); + QString tag = vers_exp.cap( 2 ).toLower(); + if ( !tag.isEmpty() ) { + if ( tag == "rc" ) // release candidate + dev1 = 49; // 'rc'=49 + else // a, b, c, ... + dev1 = (int)( tag[ 0 ].toLatin1() ) - (int)( QChar('a').toLatin1() ) + 1; // 'a'=1, 'b'=2, ..., 'z'=26 + } + if ( !vers_exp.cap( 3 ).isEmpty() ) + dev2 = vers_exp.cap( 3 ).toInt(); } } @@ -207,7 +259,7 @@ protected: id*=100; id+=minor; id*=100; id+=release; id*=10000; - if ( dev > 0 ) id+=dev-10000; + if ( dev > 0 ) id-=dev; } } return id; -- 2.39.2