comparison Core/Toolbox.cpp @ 1145:0479d02c6778

Plugins can retrieve the path to Orthanc and to its configuration file
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Sep 2014 13:06:16 +0200
parents 929bf8c2123d
children 6e7e5ed91c2d
comparison
equal deleted inserted replaced
1144:fef79a477e09 1145:0479d02c6778
492 result = base64_decode(data); 492 result = base64_decode(data);
493 } 493 }
494 494
495 495
496 #if defined(_WIN32) 496 #if defined(_WIN32)
497 std::string Toolbox::GetPathToExecutable() 497 static std::string GetPathToExecutableInternal()
498 { 498 {
499 // Yes, this is ugly, but there is no simple way to get the 499 // Yes, this is ugly, but there is no simple way to get the
500 // required buffer size, so we use a big constant 500 // required buffer size, so we use a big constant
501 std::vector<char> buffer(32768); 501 std::vector<char> buffer(32768);
502 /*int bytes =*/ GetModuleFileNameA(NULL, &buffer[0], static_cast<DWORD>(buffer.size() - 1)); 502 /*int bytes =*/ GetModuleFileNameA(NULL, &buffer[0], static_cast<DWORD>(buffer.size() - 1));
503 return std::string(&buffer[0]); 503 return std::string(&buffer[0]);
504 } 504 }
505 505
506 #elif defined(__linux) || defined(__FreeBSD_kernel__) 506 #elif defined(__linux) || defined(__FreeBSD_kernel__)
507 std::string Toolbox::GetPathToExecutable() 507 static std::string GetPathToExecutableInternal()
508 { 508 {
509 std::vector<char> buffer(PATH_MAX + 1); 509 std::vector<char> buffer(PATH_MAX + 1);
510 ssize_t bytes = readlink("/proc/self/exe", &buffer[0], buffer.size() - 1); 510 ssize_t bytes = readlink("/proc/self/exe", &buffer[0], buffer.size() - 1);
511 if (bytes == 0) 511 if (bytes == 0)
512 { 512 {
515 515
516 return std::string(&buffer[0]); 516 return std::string(&buffer[0]);
517 } 517 }
518 518
519 #elif defined(__APPLE__) && defined(__MACH__) 519 #elif defined(__APPLE__) && defined(__MACH__)
520 std::string Toolbox::GetPathToExecutable() 520 static std::string GetPathToExecutableInternal()
521 { 521 {
522 char pathbuf[PATH_MAX + 1]; 522 char pathbuf[PATH_MAX + 1];
523 unsigned int bufsize = static_cast<int>(sizeof(pathbuf)); 523 unsigned int bufsize = static_cast<int>(sizeof(pathbuf));
524 524
525 _NSGetExecutablePath( pathbuf, &bufsize); 525 _NSGetExecutablePath( pathbuf, &bufsize);
530 #else 530 #else
531 #error Support your platform here 531 #error Support your platform here
532 #endif 532 #endif
533 533
534 534
535 std::string Toolbox::GetPathToExecutable()
536 {
537 boost::filesystem::path p(GetPathToExecutableInternal());
538 return boost::filesystem::absolute(p).string();
539 }
540
541
535 std::string Toolbox::GetDirectoryOfExecutable() 542 std::string Toolbox::GetDirectoryOfExecutable()
536 { 543 {
537 boost::filesystem::path p(GetPathToExecutable()); 544 boost::filesystem::path p(GetPathToExecutableInternal());
538 return p.parent_path().string(); 545 return boost::filesystem::absolute(p.parent_path()).string();
539 } 546 }
540 547
541 548
542 std::string Toolbox::ConvertToUtf8(const std::string& source, 549 std::string Toolbox::ConvertToUtf8(const std::string& source,
543 const Encoding sourceEncoding) 550 const Encoding sourceEncoding)