| 922 | } |
| 923 | |
| 924 | AudacityProject *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, |
nothing calls this directly
no test coverage detected