Clone
ixen <ixen@copyhandler.com>
committed
on 15 Jul 14
Bugfix: CH exits when no configuration file exists (CH-123).
LoggerImprovements + 5 more
src/libchcore/TConfig.cpp (+8 -6)
60 60
61 61 TConfig& TConfig::operator=(const TConfig& rSrc)
62 62 {
63 63         if(this != &rSrc)
64 64                 *m_pImpl = *rSrc.m_pImpl;
65 65
66 66         return *this;
67 67 }
68 68
69 69 TConfig::~TConfig()
70 70 {
71 71         delete m_pImpl;
72 72 }
73 73
74 74 // read/write
75 75 void TConfig::Read(PCTSTR pszFile)
76 76 {
77 77         if(!pszFile)
78 78                 THROW(_T("Invalid argument"), 0, 0, 0);
79 79
  80         {
  81                 boost::unique_lock<boost::shared_mutex> lock(GetImpl()->m_lock);
  82                 // Note: we need to store filename for later use BEFORE trying to open a file
  83                 //       since it might be nonexistent, but we still would like to store config to this file later
  84                 ClearNL();
  85                 GetImpl()->m_strFilePath = pszFile;
  86         }
  87
80 88         // convert our underlying data to a property tree (currently probably the easiest way to convert data to xml
81 89         boost::property_tree::wiptree tPropertyTree;
82 90
83 91         std::wifstream ifs(pszFile, std::ios_base::in);
84 92         boost::property_tree::xml_parser::read_xml(ifs, tPropertyTree);
85 93
86 94         boost::unique_lock<boost::shared_mutex> lock(GetImpl()->m_lock);
87  
88           // Note: we need to store filename for later use BEFORE trying to open a file
89           //       since it might be nonexistent, but we still would like to store config to this file later
90           ClearNL();
91           GetImpl()->m_strFilePath = pszFile;
92  
93 95         GetImpl()->ImportFromPropertyTree(tPropertyTree, lock);
94 96 }
95 97
96 98 void TConfig::Write()
97 99 {
98 100         // NOTE: locking is done inside ExportToPropertyTree()
99 101         boost::property_tree::wiptree tPropertyTree;
100 102         GetImpl()->ExportToPropertyTree(tPropertyTree);
101 103
102 104         std::wofstream ofs(GetImpl()->m_strFilePath.c_str(), std::ios_base::out);
103 105         boost::property_tree::xml_parser::write_xml(ofs, tPropertyTree);
104 106 }
105 107
106 108 void TConfig::ReadFromString(const TString& strInput)
107 109 {
108 110         if(strInput.IsEmpty())
109 111                 THROW(_T("Invalid argument"), 0, 0, 0);
110 112
111 113         boost::property_tree::wiptree tPropertyTree;
112 114