LCOV - code coverage report
Current view: top level - src/engraving/infrastructure - mscreader.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 2 2
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-Studio-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              : #pragma once
      23              : 
      24              : #include "types/ret.h"
      25              : #include "types/string.h"
      26              : #include "io/path.h"
      27              : #include "io/iodevice.h"
      28              : #include "mscio.h"
      29              : 
      30              : namespace muse {
      31              : class ZipReader;
      32              : }
      33              : 
      34              : namespace mu::engraving {
      35              : class MscReader
      36              : {
      37              : public:
      38              : 
      39              :     struct Params
      40              :     {
      41              :         muse::io::IODevice* device = nullptr;
      42              :         muse::io::path_t filePath;
      43              :         muse::String mainFileName;
      44              :         MscIoMode mode = MscIoMode::Zip;
      45              :     };
      46              : 
      47            3 :     MscReader() = default;
      48              :     MscReader(const Params& params);
      49              :     ~MscReader();
      50              : 
      51              :     void setParams(const Params& params);
      52              :     const Params& params() const;
      53              : 
      54              :     muse::Ret open();
      55              :     void close();
      56              :     bool isOpened() const;
      57              :     bool isContainer() const;
      58              : 
      59              :     muse::ByteArray readStyleFile() const;
      60              :     muse::ByteArray readScoreFile() const;
      61              : 
      62              :     std::vector<muse::String> excerptFileNames() const;
      63              :     muse::ByteArray readExcerptStyleFile(const muse::String& excerptFileName) const;
      64              :     muse::ByteArray readExcerptFile(const muse::String& excerptFileName) const;
      65              : 
      66              :     muse::ByteArray readChordListFile() const;
      67              :     muse::ByteArray readThumbnailFile() const;
      68              : 
      69              :     std::vector<muse::String> imageFileNames() const;
      70              :     muse::ByteArray readImageFile(const muse::String& fileName) const;
      71              : 
      72              :     muse::ByteArray readAudioSettingsJsonFile(const muse::io::path_t& pathPrefix = "") const;
      73              :     muse::ByteArray readViewSettingsJsonFile(const muse::io::path_t& pathPrefix = "") const;
      74              :     muse::ByteArray readAutomationJsonFile() const;
      75              : 
      76              : private:
      77              : 
      78              :     struct IReader {
      79         1012 :         virtual ~IReader() = default;
      80              : 
      81              :         virtual muse::Ret open(muse::io::IODevice* device, const muse::io::path_t& filePath) = 0;
      82              :         virtual void close() = 0;
      83              :         virtual bool isOpened() const = 0;
      84              :         //! NOTE In the case of reading from a directory,
      85              :         //! it may happen that we are not reading a container (a directory with a certain structure),
      86              :         //! but only one file among others (`.mscx` from MU 3.x)
      87              :         virtual bool isContainer() const = 0;
      88              :         virtual muse::StringList fileList() const = 0;
      89              :         virtual bool fileExists(const muse::String& fileName) const = 0;
      90              :         virtual muse::ByteArray fileData(const muse::String& fileName) const = 0;
      91              :     };
      92              : 
      93              :     struct ZipFileReader : public IReader
      94              :     {
      95              :         ~ZipFileReader() override;
      96              :         muse::Ret open(muse::io::IODevice* device, const muse::io::path_t& filePath) override;
      97              :         void close() override;
      98              :         bool isOpened() const override;
      99              :         bool isContainer() const override;
     100              :         muse::StringList fileList() const override;
     101              :         bool fileExists(const muse::String& fileName) const override;
     102              :         muse::ByteArray fileData(const muse::String& fileName) const override;
     103              :     private:
     104              :         muse::io::IODevice* m_device = nullptr;
     105              :         bool m_selfDeviceOwner = false;
     106              :         muse::ZipReader* m_zip = nullptr;
     107              :     };
     108              : 
     109              :     struct DirReader : public IReader
     110              :     {
     111              :         muse::Ret open(muse::io::IODevice* device, const muse::io::path_t& filePath) override;
     112              :         void close() override;
     113              :         bool isOpened() const override;
     114              :         bool isContainer() const override;
     115              :         muse::StringList fileList() const override;
     116              :         bool fileExists(const muse::String& fileName) const override;
     117              :         muse::ByteArray fileData(const muse::String& fileName) const override;
     118              :     private:
     119              :         muse::io::path_t m_rootPath;
     120              :     };
     121              : 
     122              :     struct XmlFileReader : public IReader
     123              :     {
     124              :         muse::Ret open(muse::io::IODevice* device, const muse::io::path_t& filePath) override;
     125              :         void close() override;
     126              :         bool isOpened() const override;
     127              :         bool isContainer() const override;
     128              :         muse::StringList fileList() const override;
     129              :         bool fileExists(const muse::String& fileName) const override;
     130              :         muse::ByteArray fileData(const muse::String& fileName) const override;
     131              :     private:
     132              :         muse::io::IODevice* m_device = nullptr;
     133              :         bool m_selfDeviceOwner = false;
     134              :     };
     135              : 
     136              :     IReader* reader() const;
     137              :     bool fileExists(const muse::String& fileName) const;
     138              :     muse::ByteArray fileData(const muse::String& fileName) const;
     139              : 
     140              :     muse::String mainFileName() const;
     141              : 
     142              :     Params m_params;
     143              :     mutable IReader* m_reader = nullptr;
     144              : };
     145              : }
        

Generated by: LCOV version 2.0-1