mac-update.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "update-helpers.hpp"
  2. #include "shared-update.hpp"
  3. #include "qt-wrappers.hpp"
  4. #include "mac-update.hpp"
  5. #include "obs-app.hpp"
  6. #include <string>
  7. #include <QMessageBox>
  8. /* ------------------------------------------------------------------------ */
  9. #ifndef MAC_BRANCHES_URL
  10. #define MAC_BRANCHES_URL "https://obsproject.com/update_studio/branches.json"
  11. #endif
  12. #ifndef MAC_DEFAULT_BRANCH
  13. #define MAC_DEFAULT_BRANCH "stable"
  14. #endif
  15. /* ------------------------------------------------------------------------ */
  16. bool GetBranch(std::string &selectedBranch)
  17. {
  18. const char *config_branch =
  19. config_get_string(GetGlobalConfig(), "General", "UpdateBranch");
  20. if (!config_branch)
  21. return true;
  22. bool found = false;
  23. for (const UpdateBranch &branch : App()->GetBranches()) {
  24. if (branch.name != config_branch)
  25. continue;
  26. /* A branch that is found but disabled will just silently fall back to
  27. * the default. But if the branch was removed entirely, the user should
  28. * be warned, so leave this false *only* if the branch was removed. */
  29. found = true;
  30. if (branch.is_enabled) {
  31. selectedBranch = branch.name.toStdString();
  32. }
  33. break;
  34. }
  35. return found;
  36. }
  37. /* ------------------------------------------------------------------------ */
  38. void MacUpdateThread::infoMsg(const QString &title, const QString &text)
  39. {
  40. OBSMessageBox::information(App()->GetMainWindow(), title, text);
  41. }
  42. void MacUpdateThread::info(const QString &title, const QString &text)
  43. {
  44. QMetaObject::invokeMethod(this, "infoMsg", Qt::BlockingQueuedConnection,
  45. Q_ARG(QString, title), Q_ARG(QString, text));
  46. }
  47. void MacUpdateThread::run()
  48. try {
  49. std::string text;
  50. std::string branch = MAC_DEFAULT_BRANCH;
  51. /* ----------------------------------- *
  52. * get branches from server */
  53. if (FetchAndVerifyFile("branches", "obs-studio/updates/branches.json",
  54. MAC_BRANCHES_URL, &text))
  55. App()->SetBranchData(text);
  56. /* ----------------------------------- *
  57. * Validate branch selection */
  58. if (!GetBranch(branch)) {
  59. config_set_string(GetGlobalConfig(), "General", "UpdateBranch",
  60. MAC_DEFAULT_BRANCH);
  61. info(QTStr("Updater.BranchNotFound.Title"),
  62. QTStr("Updater.BranchNotFound.Text"));
  63. }
  64. emit Result(QString::fromStdString(branch), manualUpdate);
  65. } catch (std::string &text) {
  66. blog(LOG_WARNING, "%s: %s", __FUNCTION__, text.c_str());
  67. }