diff --git a/src/Dependencies.cpp b/src/Dependencies.cpp index be1b64d87..9f6fc6867 100644 --- a/src/Dependencies.cpp +++ b/src/Dependencies.cpp @@ -38,23 +38,6 @@ #include "ShuttleGui.h" #include "Track.h" - -class AliasedFile -{ -public: - AliasedFile(wxFileName fileName, wxLongLong byteCount, bool bOriginalExists) - { - mFileName = fileName; - mByteCount = byteCount; - mbOriginalExists = bOriginalExists; - }; - wxFileName mFileName; - wxLongLong mByteCount; // if stored as current default sample format - bool mbOriginalExists; -}; - -WX_DECLARE_OBJARRAY(AliasedFile, AliasedFileArray); - // Note, this #include must occur here, not up with the others! // It must be between the WX_DECLARE_OBJARRAY and WX_DEFINE_OBJARRAY. #include diff --git a/src/Dependencies.h b/src/Dependencies.h index aa2c4814b..d6b4e6c05 100644 --- a/src/Dependencies.h +++ b/src/Dependencies.h @@ -14,8 +14,27 @@ #ifndef __AUDACITY_DEPENDENCIES__ #define __AUDACITY_DEPENDENCIES__ +#include + class AudacityProject; +class AliasedFile +{ +public: + AliasedFile(wxFileName fileName, wxLongLong byteCount, bool bOriginalExists) + { + mFileName = fileName; + mByteCount = byteCount; + mbOriginalExists = bOriginalExists; + }; + wxFileName mFileName; + wxLongLong mByteCount; // if stored as current default sample format + bool mbOriginalExists; +}; + +WX_DECLARE_OBJARRAY(AliasedFile, AliasedFileArray); + + // Checks for alias block files, modifies the project if the // user requests it, and returns True if the user continues. // Returns false if the user clicks Cancel, meaning that they do @@ -23,4 +42,8 @@ class AudacityProject; bool ShowDependencyDialogIfNeeded(AudacityProject *project, bool isSaving); +// Returns a list of aliased files associated with a project. +void FindDependencies(AudacityProject *project, + AliasedFileArray *outAliasedFiles); + #endif diff --git a/src/export/Export.cpp b/src/export/Export.cpp index 065edb046..280e1b95e 100644 --- a/src/export/Export.cpp +++ b/src/export/Export.cpp @@ -73,6 +73,7 @@ #include "../widgets/Warning.h" #include "../AColor.h" #include "../TimeTrack.h" +#include "../Dependencies.h" // Callback to display format options static void ExportCallback(void *cbdata, int index) @@ -635,6 +636,29 @@ bool Exporter::GetFilename() continue; } + // Check to see if we are writing to a path that a missing aliased file existed at. + // This causes problems for the exporter, so we don't allow it. + // Overwritting non-missing aliased files is okay. + // Also, this can only happen for uncompressed audio. + size_t i; + bool overwritingMissingAlias; + overwritingMissingAlias = false; + for (size_t i = 0; i < gAudacityProjects.GetCount(); i++) { + AliasedFileArray aliasedFiles; + FindDependencies(gAudacityProjects[i], &aliasedFiles); + if (mFilename.GetFullPath() == aliasedFiles[i].mFileName.GetFullPath() && + !mFilename.FileExists()) { + // Warn and return to the dialog + wxMessageBox(_("You are attempting to overwrite an aliased file that is missing.\n\ +The file cannot be written because the path is needed to restore the original audio to the project.\n\ +You can see the missing files in File > Check Dependencies.\n\ +If you still wish to export, please choose a different filename.")); + overwritingMissingAlias = true; + } + } + if (overwritingMissingAlias) + continue; + if (mFilename.FileExists()) { wxString prompt;