| 369 | } |
| 370 | |
| 371 | String File::find(const String& filename, StringList directories) |
| 372 | { |
| 373 | // maybe we do not need to do anything?! |
| 374 | // This check is required since calling File::find(File::find("CHEMISTRY/unimod.xml")) will otherwise fail |
| 375 | // because the outer call receives an absolute path already |
| 376 | if (exists(filename)) |
| 377 | { |
| 378 | return filename; |
| 379 | } |
| 380 | String filename_new = filename; |
| 381 | |
| 382 | // empty string cannot be found, so throw Exception. |
| 383 | // The code below would return success on empty string, since a path is prepended and thus the location exists |
| 384 | if (filename_new.trim().empty()) |
| 385 | { |
| 386 | throw Exception::FileNotFound(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, filename); |
| 387 | } |
| 388 | //add data dir in OpenMS data path |
| 389 | directories.push_back(getOpenMSDataPath()); |
| 390 | |
| 391 | //add path suffix to all specified directories |
| 392 | String path = File::path(filename); |
| 393 | if (!path.empty()) |
| 394 | { |
| 395 | for (String& str : directories) |
| 396 | { |
| 397 | str.ensureLastChar('/'); |
| 398 | str += path; |
| 399 | } |
| 400 | filename_new = File::basename(filename); |
| 401 | } |
| 402 | |
| 403 | //look up file |
| 404 | for (const String& str : directories) |
| 405 | { |
| 406 | String loc = str; |
| 407 | loc.ensureLastChar('/'); |
| 408 | loc = loc + filename_new; |
| 409 | |
| 410 | if (exists(loc)) |
| 411 | { |
| 412 | return String(QDir::cleanPath(loc.toQString())); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | //if the file was not found, throw an exception |
| 417 | throw Exception::FileNotFound(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, filename); |
| 418 | } |
| 419 | |
| 420 | bool File::fileList(const String& dir, const String& file_pattern, StringList& output, bool full_path) |
| 421 | { |