LCOV - code coverage report
Current view: top level - muse/framework/update/internal - appupdateservice.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 3 3
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) 2025 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              : 
      23              : #pragma once
      24              : 
      25              : #include "update/iappupdateservice.h"
      26              : #include "global/modularity/ioc.h"
      27              : #include "global/async/asyncable.h"
      28              : 
      29              : #include "global/io/ifilesystem.h"
      30              : #include "global/iapplication.h"
      31              : #include "global/isysteminfo.h"
      32              : 
      33              : #include "network/inetworkmanagercreator.h"
      34              : #include "ui/iuiconfiguration.h"
      35              : #include "update/iupdateconfiguration.h"
      36              : #include "update/iupdaterequestparamsprovider.h"
      37              : #include "update/iupdateinstaller.h"
      38              : 
      39              : namespace muse::update {
      40              : class AppUpdateService : public IAppUpdateService, public Contextable, public async::Asyncable
      41              : {
      42              :     GlobalInject<io::IFileSystem> fileSystem;
      43              :     GlobalInject<ISystemInfo> systemInfo;
      44              :     GlobalInject<IUpdateConfiguration> configuration;
      45              :     GlobalInject<IUpdateRequestParamsProvider> requestParamsProvider;
      46              :     GlobalInject<network::INetworkManagerCreator> networkManagerCreator;
      47              :     GlobalInject<IApplication> application;
      48              :     GlobalInject<IUpdateInstaller> updateInstaller;
      49              :     GlobalInject<muse::ui::IUiConfiguration> uiConfiguration;
      50              : 
      51              : public:
      52           26 :     AppUpdateService(const modularity::ContextPtr& iocCtx)
      53           26 :         : Contextable(iocCtx) {}
      54              : 
      55              :     void init();
      56              : 
      57              :     async::Promise<RetVal<ReleaseInfo> > checkForUpdate() override;
      58              :     const RetVal<ReleaseInfo>& lastCheckResult() const override;
      59              :     RetVal<Progress> downloadRelease() override;
      60              : 
      61              :     bool canAutoInstall() const override;
      62              :     Ret installUpdate() override;
      63              : 
      64              :     bool isReleaseReadyToInstall() const override;
      65              :     muse::io::path_t downloadedReleasePath() const override;
      66              :     void removeDownloadedRelease() override;
      67              : 
      68              : private:
      69              :     friend class AppUpdateServiceTests;
      70              : 
      71              :     struct UpdateRequestHistory {
      72              :         QDate installedWeekBeginning;
      73              :         QDate previousRequestDay;
      74           14 :         bool isValid() const { return installedWeekBeginning.isValid() && previousRequestDay.isValid(); }
      75              :     };
      76              : 
      77              :     network::RequestHeaders prepareHeaders(const UpdateRequestHistory& history) const;
      78              :     RetVal<UpdateRequestHistory> readUpdateRequestHistory(const io::path_t& path) const;
      79              :     Ret writeUpdateRequestHistory(const io::path_t& path, const UpdateRequestHistory& updateRequestHistory);
      80              : 
      81              :     RetVal<ReleaseInfo> parseRelease(const QByteArray& json) const;
      82              : 
      83              :     enum class DiskSpaceFor {
      84              :         Download,   //!< package (minus already downloaded bytes) + unpack room if auto-install
      85              :         Unpack      //!< staging of an already downloaded package
      86              :     };
      87              :     Ret checkDiskSpace(DiskSpaceFor purpose, uint64_t packageSize, uint64_t downloadedBytes = 0) const;
      88              : 
      89              :     void prepareUpdate(const muse::io::path_t& packagePath);
      90              :     muse::io::path_t preparedUpdatePath() const;
      91              :     void resetPreparedUpdate();
      92              : 
      93              :     InstallProgressUi makeInstallProgressUi() const;
      94              : 
      95              :     //! Ordered list of acceptable asset suffixes for this platform, most
      96              :     //! preferred first.
      97              :     std::vector<std::string> platformFileSuffixes() const;
      98              :     QJsonObject resolveReleaseAsset(const QJsonObject& release) const;
      99              : 
     100              :     void cleanupStalePackages(const std::string& keepFileName);
     101              :     muse::io::path_t packagesDir() const;
     102              : 
     103              :     using PrevReleaseNotesCallback = std::function<void (const PrevReleasesNotesList&)>;
     104              :     void downloadPreviousReleasesNotes(const Version& updateVersion, const PrevReleaseNotesCallback& finished);
     105              : 
     106              :     void clear();
     107              : 
     108              :     RetVal<ReleaseInfo> m_lastCheckResult;
     109              :     network::INetworkManagerPtr m_networkManager;
     110              :     Progress m_updateProgress;
     111              : 
     112              :     bool m_downloadInProgress = false;
     113              :     muse::io::path_t m_preparedPackagePath;
     114              :     muse::io::path_t m_preparedPath;
     115              : };
     116              : }
        

Generated by: LCOV version 2.0-1