integration.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #include "base/assertion.h"
  8. #include "base/integration.h"
  9. #include "base/platform/base_platform_file_utilities.h"
  10. #include "base/debug_log.h"
  11. #include <QtCore/QFileInfo>
  12. #include <QtCore/QDir>
  13. namespace base {
  14. namespace {
  15. Integration *IntegrationInstance = nullptr;
  16. } // namespace
  17. void Integration::Set(not_null<Integration*> instance) {
  18. IntegrationInstance = instance;
  19. }
  20. Integration &Integration::Instance() {
  21. Expects(IntegrationInstance != nullptr);
  22. return *IntegrationInstance;
  23. }
  24. bool Integration::Exists() {
  25. return (IntegrationInstance != nullptr);
  26. }
  27. Integration::Integration(int argc, char *argv[]) {
  28. const auto path = Platform::CurrentExecutablePath(argc, argv);
  29. if (path.isEmpty()) {
  30. return;
  31. }
  32. auto info = QFileInfo(path);
  33. if (!info.exists()) {
  34. return;
  35. }
  36. info = QFileInfo(info.canonicalFilePath());
  37. const auto dir = info.path();
  38. _executableDir = dir.endsWith('/') ? dir : (dir + '/');
  39. _executableName = info.fileName();
  40. }
  41. void Integration::logAssertionViolation(const QString &info) {
  42. logMessage("Assertion Failed! " + info);
  43. }
  44. void Integration::setCrashAnnotation(
  45. const std::string &key,
  46. const QString &value) {
  47. }
  48. QString Integration::executableDir() const {
  49. return _executableDir;
  50. }
  51. QString Integration::executableName() const {
  52. return _executableName;
  53. }
  54. QString Integration::executablePath() const {
  55. return _executableDir + _executableName;
  56. }
  57. } // namespace base