From 0b1c292b1158f62dd2de6ab9d6960adbc764cd5f Mon Sep 17 00:00:00 2001 From: Casper Jeukendrup <48658420+cbjeukendrup@users.noreply.github.com> Date: Mon, 3 Jul 2023 01:28:44 +0200 Subject: [PATCH 1/2] Completely block opening files from newer versions Basically remove the "Open anyway" button --- src/engraving/engravingerrors.h | 3 +-- .../internal/projectactionscontroller.cpp | 19 ++++++++++++++----- .../internal/projectactionscontroller.h | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/engraving/engravingerrors.h b/src/engraving/engravingerrors.h index 459f6b0964cdb..1ac641775783d 100644 --- a/src/engraving/engravingerrors.h +++ b/src/engraving/engravingerrors.h @@ -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 MuseScore website to obtain the latest version.") - .arg(u"https://musescore.org"); + "Please visit musescore.org to obtain the latest version."); break; case Err::FileOld300Format: text = mtrc("engraving", "This file was last saved in a development version of 3.0."); diff --git a/src/project/internal/projectactionscontroller.cpp b/src/project/internal/projectactionscontroller.cpp index 8a6b53e3948d0..9925183afe104 100644 --- a/src/project/internal/projectactionscontroller.cpp +++ b/src/project/internal/projectactionscontroller.cpp @@ -238,7 +238,7 @@ RetVal 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); } @@ -1375,7 +1375,7 @@ 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; @@ -1383,13 +1383,15 @@ bool ProjectActionsController::checkCanIgnoreError(const Ret& ret, const String& switch (static_cast(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; } } @@ -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 musescore.org 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(); diff --git a/src/project/internal/projectactionscontroller.h b/src/project/internal/projectactionscontroller.h index 78f4dc188ae9c..c1bccef43c538 100644 --- a/src/project/internal/projectactionscontroller.h +++ b/src/project/internal/projectactionscontroller.h @@ -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); From 1f4647db8307d1515f5e309ae4bec385035263a8 Mon Sep 17 00:00:00 2001 From: Casper Jeukendrup <48658420+cbjeukendrup@users.noreply.github.com> Date: Tue, 4 Jul 2023 15:12:08 +0200 Subject: [PATCH 2/2] Show filepath using native separators (backslash on Windows) --- src/framework/global/io/path.cpp | 13 +++++++++++++ src/framework/global/io/path.h | 2 ++ src/project/internal/projectactionscontroller.cpp | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/framework/global/io/path.cpp b/src/framework/global/io/path.cpp index 7ed7831bc358a..069d743ac9e9f 100644 --- a/src/framework/global/io/path.cpp +++ b/src/framework/global/io/path.cpp @@ -21,6 +21,10 @@ */ #include "path.h" +#ifndef NO_QT_SUPPORT +#include +#endif + #include "stringutils.h" #include "fileinfo.h" @@ -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 +} diff --git a/src/framework/global/io/path.h b/src/framework/global/io/path.h index d5416f1b63fcc..17de5cc706b3c 100644 --- a/src/framework/global/io/path.h +++ b/src/framework/global/io/path.h @@ -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 = ";"); } diff --git a/src/project/internal/projectactionscontroller.cpp b/src/project/internal/projectactionscontroller.cpp index 9925183afe104..ff4c6ca273e0b 100644 --- a/src/project/internal/projectactionscontroller.cpp +++ b/src/project/internal/projectactionscontroller.cpp @@ -1410,7 +1410,7 @@ bool ProjectActionsController::askIfUserAgreesToOpenProjectWithIncompatibleVersi void ProjectActionsController::warnFileTooNew(const io::path_t& filepath) { - interactive()->error(qtrc("project", "Cannot read file %1").arg(filepath.toQString()).toStdString(), + 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 musescore.org to obtain the latest version.")); }