Skip to content

Commit

Permalink
Completely block opening files from newer versions
Browse files Browse the repository at this point in the history
Basically remove the "Open anyway" button
  • Loading branch information
cbjeukendrup committed Jul 4, 2023
1 parent 4012e0a commit 0b1c292
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/engraving/engravingerrors.h
Expand Up @@ -81,8 +81,7 @@ inline Ret make_ret(Err err, const io::path_t& filePath = "")
break;
case Err::FileTooNew:
text = mtrc("engraving", "This file was saved using a newer version of MuseScore. "
"Visit the <a href=\"%1\">MuseScore website</a> to obtain the latest version.")
.arg(u"https://musescore.org");
"Please visit <a href=\"https://musescore.org\">musescore.org</a> to obtain the latest version.");
break;
case Err::FileOld300Format:
text = mtrc("engraving", "This file was last saved in a development version of 3.0.");
Expand Down
19 changes: 14 additions & 5 deletions src/project/internal/projectactionscontroller.cpp
Expand Up @@ -238,7 +238,7 @@ RetVal<INotationProjectPtr> ProjectActionsController::loadProject(const io::path
return ret;
}

if (checkCanIgnoreError(ret, io::filename(loadPath).toString())) {
if (checkCanIgnoreError(ret, loadPath)) {
ret = project->load(loadPath, "" /*stylePath*/, true /*forceMode*/, format);
}

Expand Down Expand Up @@ -1375,21 +1375,23 @@ void ProjectActionsController::showScoreDownloadError(const Ret& ret)
interactive()->warning(title, message);
}

bool ProjectActionsController::checkCanIgnoreError(const Ret& ret, const String& projectName)
bool ProjectActionsController::checkCanIgnoreError(const Ret& ret, const io::path_t& filepath)
{
if (ret) {
return true;
}

switch (static_cast<engraving::Err>(ret.code())) {
case engraving::Err::FileTooOld:
case engraving::Err::FileTooNew:
case engraving::Err::FileOld300Format:
return askIfUserAgreesToOpenProjectWithIncompatibleVersion(ret.text());
case engraving::Err::FileTooNew:
warnFileTooNew(filepath);
return false;
case engraving::Err::FileCorrupted:
return askIfUserAgreesToOpenCorruptedProject(projectName, ret.text());
return askIfUserAgreesToOpenCorruptedProject(io::filename(filepath).toString(), ret.text());
default:
warnProjectCannotBeOpened(projectName, ret.text());
warnProjectCannotBeOpened(io::filename(filepath).toString(), ret.text());
return false;
}
}
Expand All @@ -1406,6 +1408,13 @@ bool ProjectActionsController::askIfUserAgreesToOpenProjectWithIncompatibleVersi
return btn == openAnywayBtn.btn;
}

void ProjectActionsController::warnFileTooNew(const io::path_t& filepath)
{
interactive()->error(qtrc("project", "Cannot read file %1").arg(filepath.toQString()).toStdString(),
trc("project", "This file was saved using a newer version of MuseScore. "
"Please visit <a href=\"https://musescore.org\">musescore.org</a> to obtain the latest version."));
}

bool ProjectActionsController::askIfUserAgreesToOpenCorruptedProject(const String& projectName, const std::string& errorText)
{
std::string title = mtrc("project", "File “%1” is corrupted").arg(projectName).toStdString();
Expand Down
3 changes: 2 additions & 1 deletion src/project/internal/projectactionscontroller.h
Expand Up @@ -103,8 +103,9 @@ class ProjectActionsController : public IProjectFilesController, public QObject,

void showScoreDownloadError(const Ret& ret);

bool checkCanIgnoreError(const Ret& ret, const String& projectName);
bool checkCanIgnoreError(const Ret& ret, const io::path_t& filepath);
bool askIfUserAgreesToOpenProjectWithIncompatibleVersion(const std::string& errorText);
void warnFileTooNew(const io::path_t& filepath);
bool askIfUserAgreesToOpenCorruptedProject(const String& projectName, const std::string& errorText);
void warnProjectCannotBeOpened(const String& projectName, const std::string& errorText);

Expand Down

0 comments on commit 0b1c292

Please sign in to comment.