LCOV - code coverage report
Current view: top level - muse/framework/update/internal - updateconfiguration.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 67 0
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : #include "updateconfiguration.h"
      23              : 
      24              : #include "global/configreader.h"
      25              : 
      26              : #include "settings.h"
      27              : 
      28              : using namespace muse;
      29              : using namespace muse::update;
      30              : 
      31              : static const std::string module_name("update");
      32              : 
      33              : static const Settings::Key CHECK_FOR_UPDATE_KEY(module_name, "application/checkForUpdate");
      34              : static const Settings::Key ALLOW_UPDATE_ON_PRERELEASE(module_name, "application/allowUpdateOnPreRelease");
      35              : static const Settings::Key SKIPPED_VERSION_KEY(module_name, "application/skippedVersion");
      36              : static const Settings::Key INSTALLING_VERSION_KEY(module_name, "application/installingVersion");
      37              : static const Settings::Key LAST_DOWNLOADED_PACKAGE_KEY(module_name, "application/lastDownloadedPackage");
      38              : static const Settings::Key AUTO_UPDATE_KEY(module_name, "application/autoUpdate");
      39              : 
      40            0 : void UpdateConfiguration::init()
      41              : {
      42            0 :     m_config = ConfigReader::read(":/configs/update.cfg");
      43              : 
      44            0 :     settings()->setDefaultValue(CHECK_FOR_UPDATE_KEY, Val(isAppUpdatable()));
      45            0 :     settings()->valueChanged(CHECK_FOR_UPDATE_KEY).onReceive(this, [this](const Val&) {
      46            0 :         m_needCheckForUpdateChanged.notify();
      47            0 :     });
      48              : 
      49            0 :     bool allowUpdateOnPreRelease = false;
      50              : #ifdef MUSESCORE_ALLOW_UPDATE_ON_PRERELEASE
      51              :     allowUpdateOnPreRelease = true;
      52              : #else
      53            0 :     allowUpdateOnPreRelease = false;
      54              : #endif
      55            0 :     settings()->setDefaultValue(ALLOW_UPDATE_ON_PRERELEASE, Val(allowUpdateOnPreRelease));
      56              : 
      57            0 :     settings()->setDefaultValue(AUTO_UPDATE_KEY, Val(true));
      58            0 : }
      59              : 
      60            0 : bool UpdateConfiguration::isAppUpdatable() const
      61              : {
      62            0 :     return true;
      63              : }
      64              : 
      65            0 : bool UpdateConfiguration::allowUpdateOnPreRelease() const
      66              : {
      67            0 :     return settings()->value(ALLOW_UPDATE_ON_PRERELEASE).toBool();
      68              : }
      69              : 
      70            0 : void UpdateConfiguration::setAllowUpdateOnPreRelease(bool allow)
      71              : {
      72            0 :     settings()->setSharedValue(ALLOW_UPDATE_ON_PRERELEASE, Val(allow));
      73            0 : }
      74              : 
      75            0 : bool UpdateConfiguration::needCheckForUpdate() const
      76              : {
      77            0 :     return settings()->value(CHECK_FOR_UPDATE_KEY).toBool();
      78              : }
      79              : 
      80            0 : void UpdateConfiguration::setNeedCheckForUpdate(bool needCheck)
      81              : {
      82            0 :     settings()->setSharedValue(CHECK_FOR_UPDATE_KEY, Val(needCheck));
      83            0 : }
      84              : 
      85            0 : async::Notification UpdateConfiguration::needCheckForUpdateChanged() const
      86              : {
      87            0 :     return m_needCheckForUpdateChanged;
      88              : }
      89              : 
      90            0 : bool UpdateConfiguration::autoUpdateEnabled() const
      91              : {
      92            0 :     return settings()->value(AUTO_UPDATE_KEY).toBool();
      93              : }
      94              : 
      95            0 : void UpdateConfiguration::setAutoUpdateEnabled(bool enabled)
      96              : {
      97            0 :     settings()->setSharedValue(AUTO_UPDATE_KEY, Val(enabled));
      98            0 : }
      99              : 
     100            0 : std::string UpdateConfiguration::skippedReleaseVersion() const
     101              : {
     102            0 :     return settings()->value(SKIPPED_VERSION_KEY).toString();
     103              : }
     104              : 
     105            0 : void UpdateConfiguration::setSkippedReleaseVersion(const std::string& version)
     106              : {
     107            0 :     settings()->setSharedValue(SKIPPED_VERSION_KEY, Val(version));
     108            0 : }
     109              : 
     110            0 : std::string UpdateConfiguration::installingReleaseVersion() const
     111              : {
     112            0 :     return settings()->value(INSTALLING_VERSION_KEY).toString();
     113              : }
     114              : 
     115            0 : void UpdateConfiguration::setInstallingReleaseVersion(const std::string& version)
     116              : {
     117            0 :     settings()->setSharedValue(INSTALLING_VERSION_KEY, Val(version));
     118            0 : }
     119              : 
     120            0 : muse::io::path_t UpdateConfiguration::lastDownloadedPackagePath() const
     121              : {
     122            0 :     return settings()->value(LAST_DOWNLOADED_PACKAGE_KEY).toPath();
     123              : }
     124              : 
     125            0 : void UpdateConfiguration::setLastDownloadedPackagePath(const muse::io::path_t& path)
     126              : {
     127            0 :     settings()->setSharedValue(LAST_DOWNLOADED_PACKAGE_KEY, Val(path));
     128            0 : }
     129              : 
     130            0 : std::string UpdateConfiguration::checkForAppUpdateUrl() const
     131              : {
     132            0 :     return !allowUpdateOnPreRelease()
     133            0 :            ? m_config.value("latest").toString()
     134            0 :            : m_config.value("latest.test").toString();
     135              : }
     136              : 
     137            0 : std::string UpdateConfiguration::previousAppReleasesNotesUrl() const
     138              : {
     139            0 :     return !allowUpdateOnPreRelease()
     140            0 :            ? m_config.value("all").toString()
     141            0 :            : m_config.value("all.test").toString();
     142              : }
     143              : 
     144            0 : muse::network::RequestHeaders UpdateConfiguration::updateHeaders() const
     145              : {
     146            0 :     return networkConfiguration()->defaultHeaders();
     147              : }
     148              : 
     149            0 : std::string UpdateConfiguration::appWebSiteUrl() const
     150              : {
     151            0 :     return m_config.value("app_website_url").toString();
     152              : }
     153              : 
     154            0 : std::string UpdateConfiguration::privacyPolicyUrl() const
     155              : {
     156            0 :     return m_config.value("privacy_policy_url").toString();
     157              : }
     158              : 
     159            0 : muse::io::path_t UpdateConfiguration::updateDataPath() const
     160              : {
     161            0 :     return globalConfiguration()->userAppDataPath() + "/update";
     162              : }
     163              : 
     164            0 : muse::io::path_t UpdateConfiguration::downloadsPath() const
     165              : {
     166            0 :     return globalConfiguration()->downloadsPath();
     167              : }
     168              : 
     169            0 : muse::io::path_t UpdateConfiguration::updateRequestHistoryJsonPath() const
     170              : {
     171            0 :     return globalConfiguration()->userAppDataPath() + "/update_request_history.json";
     172              : }
     173              : 
     174            0 : muse::io::path_t UpdateConfiguration::helperLogPath() const
     175              : {
     176            0 :     return globalConfiguration()->userAppDataPath() + "/logs/museupdater.log";
     177              : }
        

Generated by: LCOV version 2.0-1