MCPcopy Create free account
hub / github.com/audacity/audacity / OpenFile

Method OpenFile

src/ProjectFileManager.cpp:924–1034  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

922}
923
924AudacityProject *ProjectFileManager::OpenFile( const ProjectChooserFn &chooser,
925 const FilePath &fileNameArg, bool addtohistory)
926{
927 // On Win32, we may be given a short (DOS-compatible) file name on rare
928 // occasions (e.g. stuff like "C:\PROGRA~1\AUDACI~1\PROJEC~1.AUP"). We
929 // convert these to long file name first.
930 auto fileName = PlatformCompatibility::GetLongFileName(fileNameArg);
931
932 // Make sure it isn't already open.
933 // Vaughan, 2011-03-25: This was done previously in AudacityProject::OpenFiles()
934 // and AudacityApp::MRUOpen(), but if you open an aup file by double-clicking it
935 // from, e.g., Win Explorer, it would bypass those, get to here with no check,
936 // then open a NEW project from the same data with no warning.
937 // This was reported in http://bugzilla.audacityteam.org/show_bug.cgi?id=137#c17,
938 // but is not really part of that bug. Anyway, prevent it!
939 if (IsAlreadyOpen(fileName))
940 return nullptr;
941
942 // Data loss may occur if users mistakenly try to open ".aup3.bak" files
943 // left over from an unsuccessful save or by previous versions of Audacity.
944 // So we always refuse to open such files.
945 if (fileName.Lower().EndsWith(wxT(".aup3.bak")))
946 {
947 AudacityMessageBox(
948 XO(
949"You are trying to open an automatically created backup file.\nDoing this may result in severe data loss.\n\nPlease open the actual Audacity project file instead."),
950 XO("Warning - Backup File Detected"),
951 wxOK | wxCENTRE,
952 nullptr);
953 return nullptr;
954 }
955
956 if (!::wxFileExists(fileName)) {
957 AudacityMessageBox(
958 XO("Could not open file: %s").Format( fileName ),
959 XO("Error Opening File"),
960 wxOK | wxCENTRE,
961 nullptr);
962 return nullptr;
963 }
964
965 // Following block covers cases other than a project file:
966 {
967 wxFFile ff(fileName, wxT("rb"));
968
969 auto cleanup = finally([&]
970 {
971 if (ff.IsOpened())
972 {
973 ff.Close();
974 }
975 });
976
977 if (!ff.IsOpened()) {
978 AudacityMessageBox(
979 XO("Could not open file: %s").Format( fileName ),
980 XO("Error opening file"),
981 wxOK | wxCENTRE,

Callers

nothing calls this directly

Calls 11

AudacityMessageBoxFunction · 0.85
finallyFunction · 0.85
GetFunction · 0.85
IsOpenedMethod · 0.80
DropFileMethod · 0.80
OpenProjectFileMethod · 0.80
CloseMethod · 0.45
ReadMethod · 0.45
ImportMethod · 0.45
IsSameAsMethod · 0.45

Tested by

no test coverage detected