Skip to content

Commit

Permalink
Merge pull request musescore#18358 from cbjeukendrup/block_too_new_files
Browse files Browse the repository at this point in the history
Completely block opening files from newer versions
  • Loading branch information
RomanPudashkin committed Jul 5, 2023
2 parents ab0b70d + 1f4647d commit 2356fe2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/engraving/engravingerrors.h
Original file line number Diff line number Diff line change
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
13 changes: 13 additions & 0 deletions src/framework/global/io/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
*/
#include "path.h"

#ifndef NO_QT_SUPPORT
#include <QDir>
#endif

#include "stringutils.h"
#include "fileinfo.h"

Expand Down Expand Up @@ -273,3 +277,12 @@ std::string mu::io::pathsToString(const paths_t& ps, const std::string& delim)

return result;
}

path_t mu::io::toNativeSeparators(const path_t& path)
{
#ifndef NO_QT_SUPPORT
return QDir::toNativeSeparators(path.toQString());
#else
return path;
#endif
}
2 changes: 2 additions & 0 deletions src/framework/global/io/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ bool isAbsolute(const path_t& path);
bool isAllowedFileName(const path_t& fn);
path_t escapeFileName(const path_t& fn);

path_t toNativeSeparators(const path_t& path);

paths_t pathsFromString(const std::string& str, const std::string& delim = ";");
std::string pathsToString(const paths_t& ps, const std::string& delim = ";");
}
Expand Down
19 changes: 14 additions & 5 deletions src/project/internal/projectactionscontroller.cpp
Original file line number Diff line number Diff line change
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(io::toNativeSeparators(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
Original file line number Diff line number Diff line change
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 2356fe2

Please sign in to comment.