| 972 | } |
| 973 | |
| 974 | ExportResult ExportAudioDialog::DoExport(const ExportPlugin& plugin, |
| 975 | int formatIndex, |
| 976 | const ExportProcessor::Parameters& parameters, |
| 977 | const wxFileName& filename, |
| 978 | int channels, |
| 979 | double t0, double t1, bool selectedOnly, |
| 980 | const Tags& tags, |
| 981 | FilePaths& exportedFiles) |
| 982 | { |
| 983 | wxFileName name; |
| 984 | |
| 985 | wxLogDebug(wxT("Doing multiple Export: File name \"%s\""), (filename.GetFullName())); |
| 986 | wxLogDebug(wxT("Channels: %i, Start: %lf, End: %lf "), channels, t0, t1); |
| 987 | if (selectedOnly) |
| 988 | wxLogDebug(wxT("Selected Region Only")); |
| 989 | else |
| 990 | wxLogDebug(wxT("Whole Project")); |
| 991 | |
| 992 | wxFileName backup; |
| 993 | if (mOverwriteExisting->GetValue()) { |
| 994 | name = filename; |
| 995 | backup.Assign(name); |
| 996 | |
| 997 | int suffix = 0; |
| 998 | do { |
| 999 | backup.SetName(name.GetName() + |
| 1000 | wxString::Format(wxT("%d"), suffix)); |
| 1001 | ++suffix; |
| 1002 | } |
| 1003 | while (backup.FileExists()); |
| 1004 | ::wxRenameFile(filename.GetFullPath(), backup.GetFullPath()); |
| 1005 | } |
| 1006 | else { |
| 1007 | name = filename; |
| 1008 | int i = 2; |
| 1009 | wxString base(name.GetName()); |
| 1010 | while (name.FileExists()) { |
| 1011 | name.SetName(wxString::Format(wxT("%s-%d"), base, i++)); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | bool success{false}; |
| 1016 | const wxString fullPath{name.GetFullPath()}; |
| 1017 | |
| 1018 | auto cleanup = finally( [&] { |
| 1019 | if (backup.IsOk()) { |
| 1020 | if ( success ) |
| 1021 | // Remove backup |
| 1022 | ::wxRemoveFile(backup.GetFullPath()); |
| 1023 | else { |
| 1024 | // Restore original |
| 1025 | ::wxRemoveFile(fullPath); |
| 1026 | ::wxRenameFile(backup.GetFullPath(), fullPath); |
| 1027 | } |
| 1028 | } |
| 1029 | else { |
| 1030 | if ( ! success ) |
| 1031 | // Remove any new, and only partially written, file. |
nothing calls this directly
no test coverage detected