Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong corruption message #26053

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/engraving/compat/mscxcompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using namespace muse;
using namespace muse::io;
using namespace mu::engraving;

Ret mu::engraving::compat::mscxToMscz(const String& mscxFilePath, ByteArray* msczData)
Ret mu::engraving::compat::mscxToMscz(const io::path_t& mscxFilePath, ByteArray* msczData)
{
File mscxFile(mscxFilePath);
if (!mscxFile.open(IODevice::ReadOnly)) {
Expand All @@ -56,16 +56,18 @@ Ret mu::engraving::compat::mscxToMscz(const String& mscxFilePath, ByteArray* msc
return muse::make_ok();
}

Ret mu::engraving::compat::loadMsczOrMscx(MasterScore* score, const String& path, bool ignoreVersionError)
Ret mu::engraving::compat::loadMsczOrMscx(MasterScore* score, const io::path_t& path, bool ignoreVersionError)
{
std::string suffix = io::suffix(path);

ByteArray msczData;
if (path.endsWith(u".mscx", muse::CaseInsensitive)) {
if (suffix == MSCX) {
//! NOTE Convert mscx -> mscz
Ret ret = mscxToMscz(path, &msczData);
if (!ret) {
return ret;
}
} else if (path.endsWith(u".mscz", muse::CaseInsensitive)) {
} else if (suffix == MSCZ) {
File msczFile(path);
if (!msczFile.open(IODevice::ReadOnly)) {
return make_ret(Err::FileOpenError, path);
Expand All @@ -92,18 +94,18 @@ Ret mu::engraving::compat::loadMsczOrMscx(MasterScore* score, const String& path
return scoreReader.loadMscz(score, reader, audioSettings, ignoreVersionError);
}

Ret mu::engraving::compat::loadMsczOrMscx(EngravingProjectPtr project, const String& path, bool ignoreVersionError)
Ret mu::engraving::compat::loadMsczOrMscx(EngravingProjectPtr project, const io::path_t& path, bool ignoreVersionError)
{
std::string suffix = io::suffix(path);

ByteArray msczData;
String filePath = path;
if (path.endsWith(u".mscx", muse::CaseInsensitive)) {
if (suffix == MSCX) {
//! NOTE Convert mscx -> mscz

Ret ret = mscxToMscz(path, &msczData);
if (!ret) {
return ret;
}
} else if (path.endsWith(u".mscz", muse::CaseInsensitive)) {
} else if (suffix == MSCZ) {
File msczFile(path);
if (!msczFile.open(IODevice::ReadOnly)) {
return make_ret(Err::FileOpenError, path);
Expand All @@ -119,7 +121,7 @@ Ret mu::engraving::compat::loadMsczOrMscx(EngravingProjectPtr project, const Str
Buffer msczBuf(&msczData);
MscReader::Params params;
params.device = &msczBuf;
params.filePath = filePath;
params.filePath = path;
params.mode = MscIoMode::Zip;

MscReader reader(params);
Expand Down
6 changes: 3 additions & 3 deletions src/engraving/compat/mscxcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#include "../engravingproject.h"

namespace mu::engraving::compat {
muse::Ret mscxToMscz(const muse::String& mscxFilePath, muse::ByteArray* msczData);
muse::Ret loadMsczOrMscx(MasterScore* score, const muse::String& path, bool ignoreVersionError = false);
muse::Ret loadMsczOrMscx(EngravingProjectPtr project, const muse::String& path, bool ignoreVersionError = false);
muse::Ret mscxToMscz(const muse::io::path_t& mscxFilePath, muse::ByteArray* msczData);
muse::Ret loadMsczOrMscx(MasterScore* score, const muse::io::path_t& path, bool ignoreVersionError = false);
muse::Ret loadMsczOrMscx(EngravingProjectPtr project, const muse::io::path_t& path, bool ignoreVersionError = false);
}

#endif // MU_ENGRAVING_MSCXCOMPAT_H
7 changes: 6 additions & 1 deletion src/engraving/engravingerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ enum class Err {
IgnoreError = 2012
};

inline muse::Ret make_ret(Err err, const muse::io::path_t& filePath = "")
inline muse::Ret make_ret(Err err, const muse::String& text)
{
return muse::Ret(static_cast<int>(err), text.toStdString());
}

inline muse::Ret make_ret(Err err, const muse::io::path_t& filePath = {})
{
muse::String text;

Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rw/ireader.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class IReader
public:
virtual ~IReader() = default;

virtual Err readScore(Score* score, XmlReader& xml, rw::ReadInOutData* out) = 0;
virtual muse::Ret readScore(Score* score, XmlReader& xml, rw::ReadInOutData* out) = 0;

using Supported = std::variant<std::monostate,
Accidental*,
Expand Down
9 changes: 4 additions & 5 deletions src/engraving/rw/mscloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ Ret MscLoader::loadMscz(MasterScore* masterScore, const MscReader& mscReader, Se
break;
}

Err err = reader.val->readScore(partScore, xml, &partReadInData);
ret = make_ret(err);
ret = reader.val->readScore(partScore, xml, &partReadInData);
if (!ret) {
break;
}
Expand Down Expand Up @@ -258,15 +257,15 @@ Ret MscLoader::readMasterScore(MasterScore* score, XmlReader& e, bool ignoreVers
score->checkChordList();
}

Err err = reader.val->readScore(score, e, out);
Ret ret = reader.val->readScore(score, e, out);

score->setExcerptsChanged(false);

return make_ret(err);
return ret;
} else {
e.unknown();
}
}

return Ret(static_cast<int>(Err::FileCorrupted), e.errorString().toStdString());
return make_ret(Err::FileCriticallyCorrupted, e.errorString());
}
8 changes: 4 additions & 4 deletions src/engraving/rw/read114/read114.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2722,10 +2722,10 @@ static void readStyle(MStyle* style, XmlReader& e, ReadChordListHook& readChordL
// import old version <= 1.3 files
//---------------------------------------------------------

Err Read114::readScore(Score* score, XmlReader& e, ReadInOutData* out)
muse::Ret Read114::readScore(Score* score, XmlReader& e, ReadInOutData* out)
{
IF_ASSERT_FAILED(score->isMaster()) {
return Err::FileUnknownError;
return make_ret(Err::FileUnknownError);
}

ReadContext ctx(score);
Expand Down Expand Up @@ -2915,7 +2915,7 @@ Err Read114::readScore(Score* score, XmlReader& e, ReadInOutData* out)

if (e.error() != muse::XmlStreamReader::NoError) {
LOGD() << e.lineNumber() << " " << e.columnNumber() << ": " << e.errorString();
return Err::FileBadFormat;
return make_ret(Err::FileBadFormat, e.errorString());
}

for (Staff* s : masterScore->staves()) {
Expand Down Expand Up @@ -3172,7 +3172,7 @@ Err Read114::readScore(Score* score, XmlReader& e, ReadInOutData* out)
score->removeElement(invalidSpanner);
}

return Err::NoError;
return muse::make_ok();
}

bool Read114::pasteStaff(XmlReader&, Segment*, staff_idx_t, Fraction)
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rw/read114/read114.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Read114 : public rw::IReader
// read114
// import old version <= 1.3 files
//---------------------------------------------------------
Err readScore(Score* masterScore, XmlReader& e, rw::ReadInOutData* out) override;
muse::Ret readScore(Score* masterScore, XmlReader& e, rw::ReadInOutData* out) override;

bool pasteStaff(XmlReader& e, Segment* dst, staff_idx_t dstStaff, Fraction scale) override;
void pasteSymbols(XmlReader& e, ChordRest* dst) override;
Expand Down
9 changes: 6 additions & 3 deletions src/engraving/rw/read206/read206.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3413,7 +3413,7 @@ bool Read206::readScore206(Score* score, XmlReader& e, ReadContext& ctx)
return true;
}

Err Read206::readScore(Score* score, XmlReader& e, ReadInOutData* out)
Ret Read206::readScore(Score* score, XmlReader& e, ReadInOutData* out)
{
ReadContext ctx(score);
if (out && out->overriddenSpatium.has_value()) {
Expand All @@ -3434,7 +3434,10 @@ Err Read206::readScore(Score* score, XmlReader& e, ReadInOutData* out)
score->setMscoreRevision(e.readInt(nullptr, 16));
} else if (tag == "Score") {
if (!readScore206(score, e, ctx)) {
return Err::FileBadFormat;
if (e.error() == muse::XmlStreamReader::CustomError) {
return make_ret(Err::FileCriticallyCorrupted, e.errorString());
}
return make_ret(Err::FileBadFormat, e.errorString());
}

if (ctx.overrideSpatium() && out) {
Expand Down Expand Up @@ -3494,7 +3497,7 @@ Err Read206::readScore(Score* score, XmlReader& e, ReadInOutData* out)

compat::CompatUtils::doCompatibilityConversions(score->masterScore());

return Err::NoError;
return make_ok();
}

bool Read206::pasteStaff(XmlReader&, Segment*, staff_idx_t, Fraction)
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rw/read206/read206.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Read206 : public rw::IReader
// read206
// import old version > 1.3 and < 3.x files
//---------------------------------------------------------
Err readScore(Score* score, XmlReader& e, rw::ReadInOutData* out) override;
muse::Ret readScore(Score* score, XmlReader& e, rw::ReadInOutData* out) override;

bool pasteStaff(XmlReader& e, Segment* dst, staff_idx_t dstStaff, Fraction scale) override;
void pasteSymbols(XmlReader& e, ChordRest* dst) override;
Expand Down
8 changes: 4 additions & 4 deletions src/engraving/rw/read302/read302.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ bool Read302::readScore302(Score* score, XmlReader& e, ReadContext& ctx)
return true;
}

Err Read302::readScore(Score* score, XmlReader& e, ReadInOutData* out)
muse::Ret Read302::readScore(Score* score, XmlReader& e, ReadInOutData* out)
{
ReadContext ctx(score);
if (out && out->overriddenSpatium.has_value()) {
Expand All @@ -274,9 +274,9 @@ Err Read302::readScore(Score* score, XmlReader& e, ReadInOutData* out)
} else if (tag == "Score") {
if (!readScore302(score, e, ctx)) {
if (e.error() == muse::XmlStreamReader::CustomError) {
return Err::FileCriticallyCorrupted;
return make_ret(Err::FileCriticallyCorrupted, e.errorString());
}
return Err::FileBadFormat;
return make_ret(Err::FileBadFormat, e.errorString());
}

if (ctx.overrideSpatium() && out) {
Expand All @@ -287,7 +287,7 @@ Err Read302::readScore(Score* score, XmlReader& e, ReadInOutData* out)
}
}

return Err::NoError;
return muse::make_ok();
}

void Read302::fixInstrumentId(Instrument* instrument)
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rw/read302/read302.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Read302 : public rw::IReader
{
public:

Err readScore(Score* score, XmlReader& e, rw::ReadInOutData* out) override;
muse::Ret readScore(Score* score, XmlReader& e, rw::ReadInOutData* out) override;

bool pasteStaff(XmlReader& e, Segment* dst, staff_idx_t dstStaff, Fraction scale) override;
void pasteSymbols(XmlReader& e, ChordRest* dst) override;
Expand Down
20 changes: 7 additions & 13 deletions src/engraving/rw/read400/measurerw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,18 @@ void MeasureRead::readMeasure(Measure* measure, XmlReader& e, ReadContext& ctx,
measure->m_mstaves.push_back(s);
}

bool irregular;
bool irregular = false;
if (e.hasAttribute("len")) {
StringList sl = e.attribute("len").split(u'/');
if (sl.size() == 2) {
measure->m_len = Fraction(sl.at(0).toInt(), sl.at(1).toInt());
} else {
LOGD("illegal measure size <%s>", muPrintable(e.attribute("len")));
}
irregular = true;
if (measure->m_len.numerator() <= 0 || measure->m_len.denominator() <= 0 || measure->m_len.denominator() > 128) {
e.raiseError(muse::mtrc("engraving",
"MSCX error at line %1: invalid measure length: %2").arg(e.lineNumber()).arg(measure->m_len.toString()));
bool ok = true;
measure->m_len = Fraction::fromString(e.attribute("len"), &ok);
if (!ok || measure->m_len < Fraction(1, 128)) {
e.raiseError(muse::mtrc("engraving", "MSCX error at line %1: invalid measure length: %2")
.arg(e.lineNumber()).arg(e.attribute("len")));
return;
}
irregular = true;
ctx.compatTimeSigMap()->add(measure->tick().ticks(), SigEvent(measure->m_len, measure->m_timesig));
ctx.compatTimeSigMap()->add((measure->tick() + measure->ticks()).ticks(), SigEvent(measure->m_timesig));
} else {
irregular = false;
}

while (e.readNextStartElement()) {
Expand Down
8 changes: 4 additions & 4 deletions src/engraving/rw/read400/read400.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
using namespace mu::engraving;
using namespace mu::engraving::read400;

Err Read400::readScore(Score* score, XmlReader& e, rw::ReadInOutData* data)
muse::Ret Read400::readScore(Score* score, XmlReader& e, rw::ReadInOutData* data)
{
ReadContext ctx(score);
if (data && data->overriddenSpatium.has_value()) {
Expand Down Expand Up @@ -83,9 +83,9 @@ Err Read400::readScore(Score* score, XmlReader& e, rw::ReadInOutData* data)
} else if (tag == "Score") {
if (!readScore400(score, e, ctx)) {
if (e.error() == muse::XmlStreamReader::CustomError) {
return Err::FileCriticallyCorrupted;
return make_ret(Err::FileCriticallyCorrupted, e.errorString());
}
return Err::FileBadFormat;
return make_ret(Err::FileBadFormat, e.errorString());
}
} else if (tag == "museScore") {
// pass
Expand All @@ -106,7 +106,7 @@ Err Read400::readScore(Score* score, XmlReader& e, rw::ReadInOutData* data)
data->settingsCompat = ctx.settingCompat();
}

return Err::NoError;
return muse::make_ok();
}

bool Read400::readScore400(Score* score, XmlReader& e, ReadContext& ctx)
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rw/read400/read400.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Read400 : public rw::IReader
{
public:

Err readScore(Score* score, XmlReader& e, rw::ReadInOutData* data) override;
muse::Ret readScore(Score* score, XmlReader& e, rw::ReadInOutData* data) override;

static bool readScore400(Score* score, XmlReader& e, ReadContext& ctx);

Expand Down
20 changes: 7 additions & 13 deletions src/engraving/rw/read410/measureread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,18 @@ void MeasureRead::readMeasure(Measure* measure, XmlReader& e, ReadContext& ctx,
measure->m_mstaves.push_back(s);
}

bool irregular;
bool irregular = false;
if (e.hasAttribute("len")) {
StringList sl = e.attribute("len").split(u'/');
if (sl.size() == 2) {
measure->m_len = Fraction(sl.at(0).toInt(), sl.at(1).toInt());
} else {
LOGD("illegal measure size <%s>", muPrintable(e.attribute("len")));
}
irregular = true;
if (measure->m_len.numerator() <= 0 || measure->m_len.denominator() <= 0 || measure->m_len.denominator() > 128) {
e.raiseError(muse::mtrc("engraving",
"MSCX error at line %1: invalid measure length: %2").arg(e.lineNumber()).arg(measure->m_len.toString()));
bool ok = true;
measure->m_len = Fraction::fromString(e.attribute("len"), &ok);
if (!ok || measure->m_len < Fraction(1, 128)) {
e.raiseError(muse::mtrc("engraving", "MSCX error at line %1: invalid measure length: %2")
.arg(e.lineNumber()).arg(e.attribute("len")));
return;
}
irregular = true;
ctx.compatTimeSigMap()->add(measure->tick().ticks(), SigEvent(measure->m_len, measure->m_timesig));
ctx.compatTimeSigMap()->add((measure->tick() + measure->ticks()).ticks(), SigEvent(measure->m_timesig));
} else {
irregular = false;
}

while (e.readNextStartElement()) {
Expand Down
8 changes: 4 additions & 4 deletions src/engraving/rw/read410/read410.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
using namespace mu::engraving;
using namespace mu::engraving::read410;

Err Read410::readScore(Score* score, XmlReader& e, rw::ReadInOutData* data)
muse::Ret Read410::readScore(Score* score, XmlReader& e, rw::ReadInOutData* data)
{
ReadContext ctx(score);
if (data && data->overriddenSpatium.has_value()) {
Expand Down Expand Up @@ -89,9 +89,9 @@ Err Read410::readScore(Score* score, XmlReader& e, rw::ReadInOutData* data)
} else if (tag == "Score") {
if (!readScore410(score, e, ctx)) {
if (e.error() == muse::XmlStreamReader::CustomError) {
return Err::FileCriticallyCorrupted;
return make_ret(Err::FileCriticallyCorrupted, e.errorString());
}
return Err::FileBadFormat;
return make_ret(Err::FileBadFormat, e.errorString());
}
} else if (tag == "museScore") {
// pass
Expand All @@ -112,7 +112,7 @@ Err Read410::readScore(Score* score, XmlReader& e, rw::ReadInOutData* data)
data->settingsCompat = ctx.settingCompat();
}

return Err::NoError;
return muse::make_ok();
}

bool Read410::readScore410(Score* score, XmlReader& e, ReadContext& ctx)
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rw/read410/read410.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Read410 : public rw::IReader
{
public:

Err readScore(Score* score, XmlReader& e, rw::ReadInOutData* data) override;
muse::Ret readScore(Score* score, XmlReader& e, rw::ReadInOutData* data) override;

static bool readScore410(Score* score, XmlReader& e, ReadContext& ctx);

Expand Down
Loading