mac-update.cpp 2.3 KB

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