1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-16 08:34:10 +02:00

Bug 1507 - Project may be overwritten by new project without warning

This commit is contained in:
James Crook 2016-09-08 17:47:04 +01:00
parent b973698fdf
commit bf06b0485f
2 changed files with 23 additions and 11 deletions

View File

@ -877,7 +877,8 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
mFrequencySelectionFormatName(gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT(""))), mFrequencySelectionFormatName(gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT(""))),
mBandwidthSelectionFormatName(gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT(""))), mBandwidthSelectionFormatName(gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT(""))),
mUndoManager(std::make_unique<UndoManager>()), mUndoManager(std::make_unique<UndoManager>()),
mViewInfo(0.0, 1.0, ZoomInfo::GetDefaultZoom()) mViewInfo(0.0, 1.0, ZoomInfo::GetDefaultZoom()),
mbLoadedFromAup( false )
{ {
// Note that the first field of the status bar is a dummy, and it's width is set // Note that the first field of the status bar is a dummy, and it's width is set
// to zero latter in the code. This field is needed for wxWidgets 2.8.12 because // to zero latter in the code. This field is needed for wxWidgets 2.8.12 because
@ -1381,6 +1382,7 @@ void AudacityProject::SetProjectTitle( int number)
// If we are not showing numbers, then <untitled> shows as 'Audacity'. // If we are not showing numbers, then <untitled> shows as 'Audacity'.
else if( name.IsEmpty() ) else if( name.IsEmpty() )
{ {
mbLoadedFromAup = false;
name = wxT("Audacity"); name = wxT("Audacity");
} }
@ -2947,6 +2949,7 @@ void AudacityProject::OpenFile(const wxString &fileNameArg, bool addtohistory)
/// ///
mFileName = fileName; mFileName = fileName;
mbLoadedFromAup = true;
mRecoveryAutoSaveDataDir = wxT(""); mRecoveryAutoSaveDataDir = wxT("");
mIsRecovered = false; mIsRecovered = false;
@ -3284,6 +3287,7 @@ bool AudacityProject::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
realFileName += wxT(".aup"); realFileName += wxT(".aup");
projPath = realFileDir.GetFullPath(); projPath = realFileDir.GetFullPath();
mFileName = wxFileName(projPath, realFileName).GetFullPath(); mFileName = wxFileName(projPath, realFileName).GetFullPath();
mbLoadedFromAup = true;
projName = value; projName = value;
} }
@ -3989,6 +3993,7 @@ void AudacityProject::AddImportedTracks(const wxString &fileName,
if (initiallyEmpty && mDirManager->GetProjectName() == wxT("")) { if (initiallyEmpty && mDirManager->GetProjectName() == wxT("")) {
wxString name = fileName.AfterLast(wxFILE_SEP_PATH).BeforeLast(wxT('.')); wxString name = fileName.AfterLast(wxFILE_SEP_PATH).BeforeLast(wxT('.'));
mFileName =::wxPathOnly(fileName) + wxFILE_SEP_PATH + name + wxT(".aup"); mFileName =::wxPathOnly(fileName) + wxFILE_SEP_PATH + name + wxT(".aup");
mbLoadedFromAup = false;
SetProjectTitle(); SetProjectTitle();
} }
@ -4095,10 +4100,11 @@ bool AudacityProject::SaveAs(const wxString & newFileName, bool bWantSaveCompres
{ {
wxString oldFileName = mFileName; wxString oldFileName = mFileName;
bool bOwnsNewAupName = mbLoadedFromAup && (mFileName==newFileName);
//check to see if the NEW project file already exists. //check to see if the NEW project file already exists.
//We should only overwrite it if this project already has the same name, where the user //We should only overwrite it if this project already has the same name, where the user
//simply chose to use the save as command although the save command would have the effect. //simply chose to use the save as command although the save command would have the effect.
if(mFileName!=newFileName && wxFileExists(newFileName)) { if( !bOwnsNewAupName && wxFileExists(newFileName)) {
wxMessageDialog m( wxMessageDialog m(
NULL, NULL,
_("The project was not saved because the file name provided would overwrite another project.\nPlease try again and select an original name."), _("The project was not saved because the file name provided would overwrite another project.\nPlease try again and select an original name."),
@ -4109,7 +4115,8 @@ bool AudacityProject::SaveAs(const wxString & newFileName, bool bWantSaveCompres
} }
mFileName = newFileName; mFileName = newFileName;
SetProjectTitle(); //Don't change the title, unless we succeed.
//SetProjectTitle();
bool success = Save(false, true, bWantSaveCompressed); bool success = Save(false, true, bWantSaveCompressed);
@ -4118,8 +4125,10 @@ bool AudacityProject::SaveAs(const wxString & newFileName, bool bWantSaveCompres
} }
if (!success || bWantSaveCompressed) // bWantSaveCompressed doesn't actually change current project. if (!success || bWantSaveCompressed) // bWantSaveCompressed doesn't actually change current project.
{ {
// Reset file name on error // Restore file name on error
mFileName = oldFileName; mFileName = oldFileName;
} else {
mbLoadedFromAup = true;
SetProjectTitle(); SetProjectTitle();
} }
@ -4180,10 +4189,11 @@ For an audio file that will open in other apps, use 'Export'.\n"),
filename.SetExt(wxT("aup")); filename.SetExt(wxT("aup"));
fName = filename.GetFullPath(); fName = filename.GetFullPath();
bool bOwnsNewAupName = mbLoadedFromAup && (mFileName==fName);
//check to see if the NEW project file already exists. //check to see if the NEW project file already exists.
//We should only overwrite it if this project already has the same name, where the user //We should only overwrite it if this project already has the same name, where the user
//simply chose to use the save as command although the save command would have the effect. //simply chose to use the save as command although the save command would have the effect.
if (mFileName != fName && filename.FileExists()) { if (!bOwnsNewAupName && filename.FileExists()) {
wxMessageDialog m( wxMessageDialog m(
NULL, NULL,
_("The project was not saved because the file name provided would overwrite another project.\nPlease try again and select an original name."), _("The project was not saved because the file name provided would overwrite another project.\nPlease try again and select an original name."),
@ -4195,7 +4205,6 @@ For an audio file that will open in other apps, use 'Export'.\n"),
wxString oldFileName = mFileName; wxString oldFileName = mFileName;
mFileName = fName; mFileName = fName;
SetProjectTitle();
bool success = Save(false, true, bWantSaveCompressed); bool success = Save(false, true, bWantSaveCompressed);
@ -4206,9 +4215,12 @@ For an audio file that will open in other apps, use 'Export'.\n"),
{ {
// Reset file name on error // Reset file name on error
mFileName = oldFileName; mFileName = oldFileName;
} else {
mbLoadedFromAup = true;
SetProjectTitle(); SetProjectTitle();
} }
return(success); return(success);
} }
@ -5505,17 +5517,16 @@ bool AudacityProject::SaveFromTimerRecording(wxFileName fnFile) {
} }
mFileName = sNewFileName; mFileName = sNewFileName;
SetProjectTitle();
bool bSuccess = Save(false, true, false); bool bSuccess = Save(false, true, false);
if (bSuccess) { if (bSuccess) {
wxGetApp().AddFileToHistory(mFileName); wxGetApp().AddFileToHistory(mFileName);
} else mbLoadedFromAup = true;
{
// Reset file name on error
mFileName = sOldFilename;
SetProjectTitle(); SetProjectTitle();
} else {
// Restore file name on error
mFileName = sOldFilename;
} }
return bSuccess; return bSuccess;

View File

@ -547,6 +547,7 @@ public:
// The project's name and file info // The project's name and file info
wxString mFileName; wxString mFileName;
bool mbLoadedFromAup;
std::shared_ptr<DirManager> mDirManager; // MM: DirManager now created dynamically std::shared_ptr<DirManager> mDirManager; // MM: DirManager now created dynamically
double mRate; double mRate;