From f628980d7d3b8c192bb23fd9b2f5274b404920e1 Mon Sep 17 00:00:00 2001 From: Avery King Date: Sat, 24 Dec 2022 16:59:26 -0800 Subject: [PATCH] Reapply commit d55cf9a34d NOTE: I made some changes to comments here, so it's not a full 1:1 reapplication. However, this still fixes an issue with Tenacity failing to open projects created in older versions of itself. -------------------- Restore compatibility with Audacity-created projects PR #84 introduced new project compatibility code taken from upstream. However, this project compatibility code was geared towards focusing on dealing with newer and older versions of Audacity, not Tenacity. This resulted in Tenacity failing to open projects it created in prior versions because of incorrectly assuming that the project was created in a newer version of Tenacity when this was not the case. To fix this, the following was introduced: 1. Add new version constants to represent Tenacity's version. 2. Check the project version against the Audacity version constants. This will succeed even if the project was created or updated in Tenacity. While the solution is not ideal, it provides a temporary fix. Unfortunately, we do not have a clear way of distinguising ourselves from Audacity projects right now, but there might be ways that we can distinguish ourselves from Audacity projects in the future. Signed-off-by: Avery King (cherry picked from commit d55cf9a34dca6c39ba845b9e6cf047917fe89c85) Signed-off-by: Avery King --- libraries/lib-project-file-io/ProjectFileIO.cpp | 10 ++++++---- libraries/lib-project/ProjectFormatVersion.cpp | 6 ++++-- libraries/lib-project/ProjectFormatVersion.h | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/libraries/lib-project-file-io/ProjectFileIO.cpp b/libraries/lib-project-file-io/ProjectFileIO.cpp index c5383f546..0ace696a4 100644 --- a/libraries/lib-project-file-io/ProjectFileIO.cpp +++ b/libraries/lib-project-file-io/ProjectFileIO.cpp @@ -774,10 +774,12 @@ bool ProjectFileIO::CheckVersion() // Project file version is higher than ours. We will refuse to // process it since we can't trust anything about it. - if (SupportedProjectFormatVersion < version) + // TODO: use the SupportedProjectFormatVersion instead and make a way to + // clearly distinguish projects created by either Audacity or Tenacity. + if (SupportedAudacityProjectFormatVersion < version) { SetError( - XO("This project was created with a newer version of Audacity.\n\nYou will need to upgrade to open it.") + XO("This project was created with a version of Audacity that is not supported by Tenacity.\n\nYou will need to use that version to open it.") ); return false; } @@ -785,8 +787,8 @@ bool ProjectFileIO::CheckVersion() using namespace BasicUI; wxString currentVersionStr = wxString::Format("%u.%u", BaseProjectFormatVersion.Major, BaseProjectFormatVersion.Minor); bool updateVersion = (MessageBoxResult::Yes == ShowMessageBox( - XO("This project was created using an older Audacity version. " - "Once saved, the project can only be opened with Audacity version %s or newer.").Format(currentVersionStr), + XO("This project was created using an older Tenacity version. " + "Once saved, the project can only be opened with Tenacity version %s or newer.").Format(currentVersionStr), MessageBoxOptions{} .Caption(XO("Project update required")))); } diff --git a/libraries/lib-project/ProjectFormatVersion.cpp b/libraries/lib-project/ProjectFormatVersion.cpp index be8da409a..03dcb54ee 100644 --- a/libraries/lib-project/ProjectFormatVersion.cpp +++ b/libraries/lib-project/ProjectFormatVersion.cpp @@ -50,7 +50,9 @@ bool ProjectFormatVersion::IsValid() const noexcept } const ProjectFormatVersion SupportedProjectFormatVersion = { - TENACITY_VERSION, TENACITY_RELEASE, TENACITY_REVISION, 0 + TENACITY_VERSION, TENACITY_RELEASE, TENACITY_REVISION, 0, true }; -const ProjectFormatVersion BaseProjectFormatVersion = { TENACITY_VERSION, TENACITY_RELEASE, 0, 0 }; +const ProjectFormatVersion SupportedAudacityProjectFormatVersion = { 3, 7, 0, 0, false }; +const ProjectFormatVersion BaseProjectFormatVersion = { 1, 3, 0, 0, true }; +const ProjectFormatVersion BaseAudacityProjectFormatVersion = { 3, 0, 0, 0, false }; diff --git a/libraries/lib-project/ProjectFormatVersion.h b/libraries/lib-project/ProjectFormatVersion.h index 2c88353f5..14d987dfc 100644 --- a/libraries/lib-project/ProjectFormatVersion.h +++ b/libraries/lib-project/ProjectFormatVersion.h @@ -24,6 +24,7 @@ struct PROJECT_API ProjectFormatVersion final uint8_t Minor { 0 }; uint8_t Revision { 0 }; uint8_t ModLevel { 0 }; + bool IsTenacity { false }; // Create ProjectFormatVersion from the uint32_t value static ProjectFormatVersion FromPacked(uint32_t) noexcept; @@ -38,7 +39,16 @@ PROJECT_API bool operator==(ProjectFormatVersion lhs, ProjectFormatVersion rhs) PROJECT_API bool operator!=(ProjectFormatVersion lhs, ProjectFormatVersion rhs) noexcept; PROJECT_API bool operator<(ProjectFormatVersion lhs, ProjectFormatVersion rhs) noexcept; -//! This constant represents the current version of Audacity +/// This constant represents the current version of Tenacity. PROJECT_API extern const ProjectFormatVersion SupportedProjectFormatVersion; -//! This is a helper constant for the "most compatible" project version which is the current MAJ.MIN.0.0 + +/// This constant represents the maximum supported Audacity project version. +PROJECT_API extern const ProjectFormatVersion SupportedAudacityProjectFormatVersion; + +/// This is a helper constant for the "most compatible" project version created +/// by Tenacity with the value (MAJ, MIN, 0, 0). PROJECT_API extern const ProjectFormatVersion BaseProjectFormatVersion; + +/// This is a helper constant for the "most compatible" project version created +/// by Audacity with the value {AUD_MAJ, AUD_MIN, 0, 0}. +PROJECT_API extern const ProjectFormatVersion BaseAudacityProjectFormatVersion;