if user agreed to open corrupted/old score then we'll try to load it again but with ignoring non-critical errors

This commit is contained in:
Roman Pudashkin 2021-06-21 14:16:38 +02:00
parent b665f8c114
commit 39711be1b5
4 changed files with 24 additions and 15 deletions

View file

@ -40,7 +40,7 @@ public:
virtual Meta metaInfo() const = 0;
virtual void setMetaInfo(const Meta& meta) = 0;
virtual Ret load(const io::path& path, const io::path& stylePath = io::path()) = 0;
virtual Ret load(const io::path& path, const io::path& stylePath = io::path(), bool forceMode = false) = 0;
virtual io::path path() const = 0;
virtual Ret createNew(const ScoreCreateOptions& scoreInfo) = 0;

View file

@ -77,7 +77,7 @@ void MasterNotation::setMetaInfo(const Meta& meta)
Notation::setMetaInfo(meta);
}
mu::Ret MasterNotation::load(const io::path& path, const io::path& stylePath)
mu::Ret MasterNotation::load(const io::path& path, const io::path& stylePath, bool forceMode)
{
TRACEFUNC;
@ -90,7 +90,7 @@ mu::Ret MasterNotation::load(const io::path& path, const io::path& stylePath)
return make_ret(Err::FileUnknownType, path);
}
return load(path, stylePath, reader);
return load(path, stylePath, reader, forceMode);
}
Ms::MasterScore* MasterNotation::masterScore() const
@ -98,14 +98,14 @@ Ms::MasterScore* MasterNotation::masterScore() const
return dynamic_cast<Ms::MasterScore*>(score());
}
mu::Ret MasterNotation::load(const io::path& path, const io::path& stylePath, const INotationReaderPtr& reader)
mu::Ret MasterNotation::load(const io::path& path, const io::path& stylePath, const INotationReaderPtr& reader, bool forceMode)
{
TRACEFUNC;
Ms::ScoreLoad sl;
Ms::MasterScore* score = new Ms::MasterScore(scoreGlobal()->baseStyle());
Ret ret = doLoadScore(score, path, reader);
Ret ret = doLoadScore(score, path, reader, forceMode);
if (ret) {
setScore(score);
@ -125,14 +125,20 @@ mu::Ret MasterNotation::load(const io::path& path, const io::path& stylePath, co
mu::Ret MasterNotation::doLoadScore(Ms::MasterScore* score,
const io::path& path,
const std::shared_ptr<INotationReader>& reader) const
const std::shared_ptr<INotationReader>& reader,
bool forceMode) const
{
QFileInfo fi(path.toQString());
score->setName(fi.completeBaseName());
score->setImportedFilePath(fi.filePath());
score->setMetaTag("originalFormat", fi.suffix().toLower());
Ret ret = reader->read(score, path);
INotationReader::Options options;
if (forceMode) {
options[INotationReader::OptionKey::ForceMode] = forceMode;
}
Ret ret = reader->read(score, path, options);
if (!ret) {
return ret;
}

View file

@ -50,7 +50,7 @@ public:
Meta metaInfo() const override;
void setMetaInfo(const Meta& meta) override;
Ret load(const io::path& path, const io::path& stylePath = io::path()) override;
Ret load(const io::path& path, const io::path& stylePath = io::path(), bool forceMode = false) override;
io::path path() const override;
Ret createNew(const ScoreCreateOptions& scoreOptions) override;
@ -72,8 +72,8 @@ private:
Ms::MasterScore* masterScore() const;
Ret load(const io::path& path, const io::path& stylePath, const INotationReaderPtr& reader);
Ret doLoadScore(Ms::MasterScore* score, const io::path& path, const INotationReaderPtr& reader) const;
Ret load(const io::path& path, const io::path& stylePath, const INotationReaderPtr& reader, bool forceMode = false);
Ret doLoadScore(Ms::MasterScore* score, const io::path& path, const INotationReaderPtr& reader, bool forceMode = false) const;
mu::RetVal<Ms::MasterScore*> newScore(const ScoreCreateOptions& scoreInfo);
void doSetExcerpts(ExcerptNotationList excerpts);

View file

@ -268,10 +268,6 @@ void FileScoreController::saveOnline()
bool FileScoreController::checkCanIgnoreError(const Ret& ret)
{
if (ret) {
return true;
}
static const QList<Err> ignorableErrors {
Err::FileTooOld,
Err::FileTooNew,
@ -352,7 +348,14 @@ Ret FileScoreController::doOpenScore(const io::path& filePath)
}
Ret ret = notation->load(filePath);
if (!checkCanIgnoreError(ret)) {
if (!ret && checkCanIgnoreError(ret)) {
constexpr auto NO_STYLE = "";
constexpr bool FORCE_MODE = true;
ret = notation->load(filePath, NO_STYLE, FORCE_MODE);
}
if (!ret) {
return ret;
}