GME  13
OperOptions.cpp
Go to the documentation of this file.
00001 #include "stdafx.h"
00002 #include <fstream>
00003 #include "OperOptions.h"
00004 #include "CoreXmlFile.h"
00005 
00006 // OperatingOptions
00007 OperatingOptions::OperatingOptions()
00008 : m_defCheckInOnSave( false)
00009 , m_autoCommit(false)
00010 , m_defCheckOutOnAction( false)
00011 , m_alwaysFullLock( false)
00012 , m_onDeleteAlwaysFullLock( false)
00013 , m_onLoadShowStatus( true)
00014 , m_measureTime( false)
00015 , m_createLog( false)
00016 , m_createSvnLog( false)
00017 , m_doRefTargetLock( true)
00018 , m_doConnEndPointLock( true)
00019 , m_doConnSegmentLock( true)
00020 , m_doModelParentLock( true)
00021 , m_doBaseTypeLock( true)
00022 , m_partialLoad( false)
00023 , m_useAccountInfo( false)
00024 , m_automaticLogin( false)
00025 , m_useAPIForSvn( false)
00026 , m_useBulkCommit( true )
00027 , m_dirNamesHashed( false)
00028 , m_dirNamesHashVal( 0)
00029 , m_purgeDelayFactor( 1.)
00030 , m_svnLogFileName()
00031 , m_nameParadigmFile()
00032 , m_defUserName()
00033 , m_defPassword()
00034 , m_prefUrl()
00035 , m_prefAccessMethod()
00036 {
00037         const char* userprofile = getenv("USERPROFILE");
00038         if (userprofile)
00039         {
00040                 loadSettings(userprofile, "GME_MU_config.opt");
00041         }
00042 }
00043 
00044 void OperatingOptions::reset()
00045 {
00046         m_defCheckInOnSave      = false;
00047         m_autoCommit = false;
00048         m_defCheckOutOnAction   = false;
00049         m_alwaysFullLock        = false;
00050         m_onDeleteAlwaysFullLock= false;
00051         m_onLoadShowStatus      = true;
00052         m_measureTime           = false;
00053         m_createLog             = false;
00054         m_createSvnLog          = false;
00055         m_doRefTargetLock       = true;
00056         m_doConnEndPointLock    = true;
00057         m_doConnSegmentLock     = true;
00058         m_doModelParentLock     = true;
00059         m_doBaseTypeLock        = true;
00060         m_partialLoad           = false;
00061         m_useAccountInfo        = false;
00062         m_automaticLogin        = false;
00063         m_useAPIForSvn          = false;
00064         m_useBulkCommit         = false;
00065         m_dirNamesHashed        = false;
00066         m_dirNamesHashVal       = 0;
00067         m_purgeDelayFactor      = 1.;
00068         m_svnLogFileName        = "";
00069         m_nameParadigmFile      = "";
00070         m_defUserName           = "";
00071         m_defPassword           = "";
00072         m_prefUrl               = "";
00073         m_prefAccessMethod      = "";
00074 }
00075 
00076 void OperatingOptions::load( const std::string& p_folder)
00077 {
00078         reset();
00079         const char* userprofile = getenv("USERPROFILE");
00080         if (userprofile)
00081         {
00082                 loadSettings(userprofile, "GME_MU_config.opt");
00083         }
00084         loadSettings( p_folder, m_sysConfName);
00085         loadSettings( p_folder, m_usrConfName);
00086 }
00087 
00088 bool OperatingOptions::parseBool( const std::string& p_line, const std::string& p_optStr)
00089 {
00090         bool truef  = p_line.find( "true" , p_optStr.length())  != std::string::npos; // look for 'true' after p_optStr.length() offset
00091         bool falsef = p_line.find( "false", p_optStr.length()) != std::string::npos;
00092         bool rv = true;
00093 
00094         if( truef && !falsef)
00095                 rv = true;
00096         else if( !truef && falsef)
00097                 rv = false;
00098         else if( !truef && !falsef) // value doesn't contain neither true, nor false, assume true
00099                 rv = true;
00100         else if( truef && falsef) // value might contain 'true' and 'false'
00101                 rv = true;
00102 
00103         return rv;
00104 }
00105 
00106 std::string OperatingOptions::parseStr( const std::string& p_line, const std::string& p_optStr)
00107 {
00108         std::string ret;
00109         size_t pos = p_line.find_first_not_of( "\t =", p_optStr.length()); // skip whitespaces, equal sign
00110         if( pos != std::string::npos) // found
00111         {
00112                 int cpos = p_line.find_first_of( "\t #", pos); // find comments at the end of line, skip whitespaces too
00113                 // value is between pos and cpos
00114                 ret = p_line.substr( pos, cpos - pos); // cpos == -1 case is tolerated too by substr
00115         }
00116 
00117         return ret;
00118 }
00119 
00120 void OperatingOptions::loadSettings( const std::string& p_folder, const std::string& p_fName)
00121 {
00122         std::ifstream options;
00123         options.open( ( p_folder + "\\" + p_fName).c_str(), std::ios_base::in);
00124         if( options.is_open())
00125         {
00126                 char buff[1024];
00127                 while( options.getline( buff, 1024))
00128                 {
00129                         std::string line( buff);
00130                         size_t valid_cont = line.find( '#');
00131                         if( valid_cont != std::string::npos) // line = line.substr( 0, valid_cont); // cut part behind #
00132                                 line.erase( valid_cont, std::string::npos); // cut part behind #
00133                         
00134                         if( line.empty())
00135                                 continue;
00136                         else if( 0 == line.find( "DefCheckInOnSave"))//=true"))
00137                         {
00138                                 m_defCheckInOnSave = parseBool( line, "DefCheckInOnSave");//m_defCheckInOnSave = true;
00139                         }
00140                         else if( 0 == line.find("AutoCommit"))//=true"))
00141                         {
00142                                 m_autoCommit = parseBool(line, "AutoCommit");
00143                         }
00144                         else if( 0 == line.find( "DefCheckOutOnAction"))//=true"))
00145                         {
00146                                 m_defCheckOutOnAction = parseBool( line, "DefCheckOutOnAction"); //m_defCheckOutOnAction = true;
00147                         }
00148                         else if( 0 == line.find( "PartialLoad"))//=true"))
00149                         {
00150                                 m_partialLoad = parseBool( line, "PartialLoad"); //m_partialLoad = true;
00151                         }
00152                         else if( 0 == line.find( "UseAccountInfo"))//=true"))
00153                         {
00154                                 m_useAccountInfo = parseBool( line, "UseAccountInfo"); //m_useAccountInfo = true;
00155                         }
00156                         else if( 0 == line.find( "AutomaticLogin"))//=true"))
00157                         {
00158                                 m_automaticLogin = parseBool( line, "AutomaticLogin"); //m_automaticLogin = true;
00159                         }
00160                         else if( 0 == line.find( "account"))
00161                         {
00162                                 //m_defUserName = line.substr( std::string( "account=").length());
00163                                 m_defUserName = parseStr( line, "account");
00164                         }
00165                         else if( 0 == line.find( "phrase"))
00166                         {
00167                                 //m_defPassword = line.substr( std::string( "phrase=").length());
00168                                 m_defPassword = parseStr( line, "phrase");
00169                         }
00170                         else if( 0 == line.find( "PreferredUrl"))
00171                         {
00172                                 m_prefUrl = parseStr( line, "PreferredUrl");
00173                         }
00174                         //else if( 0 == line.find( "AlwaysFullLock=true"))
00175                         //{
00176                         //      m_alwaysFullLock = true;
00177                         //}
00178                         //else if( 0 == line.find( "OnDeleteAlwaysFullLock=true"))
00179                         //{
00180                         //      m_onDeleteAlwaysFullLock = true;
00181                         //}
00182                         else if( 0 == line.find( "OnLoadShowStatus"))//=false"))
00183                         {
00184                                 m_onLoadShowStatus = parseBool( line, "OnLoadShowStatus"); //m_onLoadShowStatus = false;
00185                         }
00186                         else if( 0 == line.find( "MeasureTime"))//=true"))
00187                         {
00188                                 m_measureTime = parseBool( line, "MeasureTime"); //m_measureTime = true;
00189                         }
00190                         else if( 0 == line.find( "Log"))//=true"))
00191                         {
00192                                 m_createLog = parseBool( line, "Log"); //m_createLog = true;
00193                         }
00194                         else if( 0 == line.find( "DoSvnLog"))
00195                         {
00196                                 m_createSvnLog = parseBool( line, "DoSvnLog");
00197                         }
00198                         else if( 0 == line.find( "SvnLogFile"))
00199                         {
00200                                 m_svnLogFileName = parseStr( line, "SvnLogFile");
00201                         }
00202                         else if( 0 == line.find( "UseApiForSvn"))
00203                         {
00204                                 m_useAPIForSvn = parseBool( line, "UseApiForSvn");
00205                         }
00206                         else if( 0 == line.find( "UseBulkCommit"))
00207                         {
00208                                 m_useBulkCommit = parseBool( line, "UseBulkCommit");
00209                         }
00210                         else if( 0 == line.find( "DirNamesHashed"))
00211                         {
00212                                 m_dirNamesHashed = parseBool( line, "DirNamesHashed");
00213                         }
00214                         else if( 0 == line.find( "DirNamesHashedVal"))
00215                         {
00216                                 int stoi = 0;
00217                                 std::string v = parseStr( line, "DirNamesHashedVal");
00218                                 if( 1 == sscanf( v.c_str(), "%u", &stoi) && stoi >= 0)
00219                                         m_dirNamesHashVal = stoi;
00220                         }
00221                         else if( 0 == line.find( "PurgeDelayed"))
00222                         {
00223                                 float stor = 0.;
00224                                 std::string v = parseStr( line, "PurgeDelayed");
00225                                 if( 1 == sscanf( v.c_str(), "%f", &stor) && stor >= 0)
00226                                         m_purgeDelayFactor = stor;
00227                                 //const char * ptr = line.c_str();
00228                                 //if( 1 == sscanf( ptr + std::string( "PurgeDelayed=").length(), "%f", &stor) && stor >= 0)
00229                                 //      m_purgeDelayFactor = stor;
00230                         }
00231                         //else if( 0 == line.find( "DoRefTargetLock=false"))
00232                         //      m_doRefTargetLock = false;
00233                         //else if( 0 == line.find( "DoConnEndPointLock=false"))
00234                         //      m_doConnEndPointLock = false;
00235                         //else if( 0 == line.find( "DoConnSegmentLock=false"))
00236                         //      m_doConnSegmentLock = false;
00237                         //else if( 0 == line.find( "DoModelParentLock=false"))
00238                         //      m_doModelParentLock = false;
00239                         //else if( 0 == line.find( "DoBaseTypeLock=false"))
00240                         //      m_doBaseTypeLock = false;
00241                 }
00242                 options.close();
00243         }
00244 }
00245 
00246 void OperatingOptions::display( CCoreXmlFile * const parent)
00247 {
00248         parent->sendMsg( std::string( "User options loaded:") , MSG_INFO);
00249         parent->sendMsg( std::string( "DefCheckInOnSave=" )     + (m_defCheckInOnSave?"true":"false"), MSG_INFO );
00250         parent->sendMsg( std::string( "DefCheckOutOnAction=" )  + (m_defCheckOutOnAction?"true":"false"), MSG_INFO );
00251         //parent->sendMsg( std::string( "AlwaysFullLock=" )       + (m_alwaysFullLock?"true":"false"), MSG_INFO);
00252         //parent->sendMsg( std::string( "OnDeleteAlwaysFullLock=")+ (m_onDeleteAlwaysFullLock?"true":"false"), MSG_INFO);
00253         parent->sendMsg( std::string( "OnLoadShowStatus=")      + (m_onLoadShowStatus?"true":"false"), MSG_INFO);
00254         //parent->sendMsg( std::string( "[Debug]MeasureTime=")           + (m_measureTime?"true":"false"), MSG_INFO);
00255 #ifdef _DEBUG
00256         //parent->sendMsg( std::string( "[DebugMode]Log=")                   + (m_createLog?"true":"false"), MSG_INFO);
00257 #endif
00258         parent->sendMsg( std::string( "PartialLoad=")           + (m_partialLoad?"true":"false"), MSG_INFO);
00259         //parent->sendMsg( std::string( "Adv. Settings {RTgt, CEnd, CSeg, ModP, BasT}=") 
00260         //      + (m_doRefTargetLock?"{true,":"{false,")
00261         //      + (m_doConnEndPointLock?"true,":"false,")
00262         //      + (m_doConnSegmentLock?"true,":"false,")
00263         //      + (m_doModelParentLock?"true,":"false,")
00264         //      + (m_doBaseTypeLock?"true}":"false}"), MSG_INFO);
00265         char buff[250]; sprintf( buff, "%.2f, equal to %i minutes", m_purgeDelayFactor, (int)(m_purgeDelayFactor * 60));
00266         CTime back = CTime::GetCurrentTime() - CTimeSpan( 0, 0, (int)(m_purgeDelayFactor * 60), 0);
00267 
00268         parent->sendMsg( std::string( "PurgeDelayed=") + buff, MSG_INFO);
00269         if( m_purgeDelayFactor == 0.)
00270                 parent->sendMsg( std::string( "Purge events: Disabled."), MSG_INFO);
00271         else
00272                 parent->sendMsg( std::string( "Purge events older than ") + (LPCTSTR) back.Format( "[%Y-%m-%d %H:%M:%S]."), MSG_INFO);
00273 
00274         if( m_useAccountInfo)
00275                 parent->sendMsg( std::string( m_automaticLogin?"Auto":"Manual") + std::string(" login with account=\"") + m_defUserName + "\"", MSG_INFO);
00276         if( !m_prefUrl.empty())
00277                 parent->sendMsg( std::string( "PreferredUrl: ") + m_prefUrl, MSG_INFO);
00278 
00279         if( m_useBulkCommit)
00280                 parent->sendMsg( std::string( "Bulk commit will be used"), MSG_INFO);
00281 
00282         // some conf settings are protected
00283         // thus not publicized too much: "DoSvnLog", "SvnLogFile"
00284 }
00285