comparison Core/DicomParsing/FromDcmtkBridge.cpp @ 3302:8ed445e94486

Fix issue #126 (Orthanc and DCMDICTPATH)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 24 Feb 2019 09:30:13 +0100
parents cf8cbeb35f33
children b3bdd6dc10f2
comparison
equal deleted inserted replaced
3301:6ce10c3b1eb7 3302:8ed445e94486
139 "Cannot read embedded dictionary. Under Windows, make sure that " 139 "Cannot read embedded dictionary. Under Windows, make sure that "
140 "your TEMP directory does not contain special characters."); 140 "your TEMP directory does not contain special characters.");
141 } 141 }
142 #endif 142 #endif
143 } 143 }
144
145 #else
146 static void LoadExternalDictionary(DcmDataDictionary& dictionary,
147 const std::string& directory,
148 const std::string& filename)
149 {
150 boost::filesystem::path p = directory;
151 p = p / filename;
152
153 LOG(WARNING) << "Loading the external DICOM dictionary " << p;
154
155 if (!dictionary.loadDictionary(p.string().c_str()))
156 {
157 throw OrthancException(ErrorCode_InternalError);
158 }
159 }
160 #endif 144 #endif
161 145
162 146
163 namespace 147 namespace
164 { 148 {
272 else 256 else
273 { 257 {
274 LOG(INFO) << "The dictionary of private tags has not been loaded"; 258 LOG(INFO) << "The dictionary of private tags has not been loaded";
275 } 259 }
276 260
277 #elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__) 261 #else
278 std::string path = DCMTK_DICTIONARY_DIR; 262 std::vector<std::string> dictionaries;
279 263
280 const char* env = std::getenv(DCM_DICT_ENVIRONMENT_VARIABLE); 264 const char* env = std::getenv(DCM_DICT_ENVIRONMENT_VARIABLE);
281 if (env != NULL) 265 if (env != NULL)
282 { 266 {
283 path = std::string(env); 267 // This mimics the behavior of DCMTK:
284 } 268 // https://support.dcmtk.org/docs/file_envvars.html
285 269 #if defined(_WIN32)
286 LoadExternalDictionary(*locker, path, "dicom.dic"); 270 Toolbox::TokenizeString(dictionaries, std::string(env), ';');
287 271 #else
288 if (loadPrivateDictionary) 272 Toolbox::TokenizeString(dictionaries, std::string(env), ':');
289 { 273 #endif
290 LoadExternalDictionary(*locker, path, "private.dic");
291 } 274 }
292 else 275 else
293 { 276 {
294 LOG(INFO) << "The dictionary of private tags has not been loaded"; 277 boost::filesystem::path base = DCMTK_DICTIONARY_DIR;
295 } 278 dictionaries.push_back((base / "dicom.dic").string());
296 279 dictionaries.push_back((base / "private.dic").string());
297 #else 280 }
298 #error Support your platform here 281
282 for (size_t i = 0; i < dictionaries.size(); i++)
283 {
284 LOG(WARNING) << "Loading external DICOM dictionary: \"" << dictionaries[i] << "\"";
285
286 if (!locker->loadDictionary(dictionaries[i].c_str()))
287 {
288 throw OrthancException(ErrorCode_InexistentFile);
289 }
290 }
291
299 #endif 292 #endif
300 } 293 }
301 294
302 /* make sure data dictionary is loaded */ 295 /* make sure data dictionary is loaded */
303 if (!dcmDataDict.isDictionaryLoaded()) 296 if (!dcmDataDict.isDictionaryLoaded())