From d55cf9a34dca6c39ba845b9e6cf047917fe89c85 Mon Sep 17 00:00:00 2001 From: Avery King Date: Sat, 24 Dec 2022 16:59:26 -0800 Subject: [PATCH] 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 --- libraries/lib-project/ProjectFormatVersion.cpp | 6 ++++-- libraries/lib-project/ProjectFormatVersion.h | 13 +++++++++++-- src/ProjectFileIO.cpp | 6 ++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libraries/lib-project/ProjectFormatVersion.cpp b/libraries/lib-project/ProjectFormatVersion.cpp index dafb092f9..84232f8a6 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 = { - AUDACITY_VERSION, AUDACITY_RELEASE, AUDACITY_REVISION, AUDACITY_MODLEVEL + AUDACITY_VERSION, AUDACITY_RELEASE, AUDACITY_REVISION, AUDACITY_MODLEVEL, true }; -const ProjectFormatVersion BaseProjectFormatVersion = { 3, 0, 0, 0 }; +const ProjectFormatVersion SupportedAudacityProjectFormatVersion = { 3, 1, 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 f8baf4c12..2eac2beea 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,15 @@ 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 with the value (3, 0, 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 with the value (1, 3, 0, 0). PROJECT_API extern const ProjectFormatVersion BaseProjectFormatVersion; + +/// This is a helper constant for the "most compatible" project version created +// with Audacity with the value {3, 0, 0, 0}. +PROJECT_API extern const ProjectFormatVersion BaseAudacityProjectFormatVersion; diff --git a/src/ProjectFileIO.cpp b/src/ProjectFileIO.cpp index b8698af5c..c74e8d333 100644 --- a/src/ProjectFileIO.cpp +++ b/src/ProjectFileIO.cpp @@ -678,10 +678,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 version of Audacity (or a derivate) that is not supported by Tenacity.\n\nYou will need to use that version 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; }