| 82 | } |
| 83 | |
| 84 | ExportTask ExportTaskBuilder::Build(AudacityProject& project) |
| 85 | { |
| 86 | //File rename stuff should be moved out to somewhere else... |
| 87 | auto filename = mFileName; |
| 88 | |
| 89 | //For safety, if the file already exists we use temporary filename |
| 90 | //and replace original one export succeeded |
| 91 | int suffix = 0; |
| 92 | while (filename.FileExists()) { |
| 93 | filename.SetName(mFileName.GetName() + |
| 94 | wxString::Format(wxT("%d"), suffix)); |
| 95 | suffix++; |
| 96 | } |
| 97 | |
| 98 | auto processor = mPlugin->CreateProcessor(mFormat); |
| 99 | if(!processor->Initialize(project, |
| 100 | mParameters, |
| 101 | mFileName.GetFullPath(), |
| 102 | mT0, mT1, mSelectedOnly, |
| 103 | mSampleRate, mMixerSpec ? mMixerSpec->GetNumChannels() : mNumChannels, |
| 104 | mMixerSpec, |
| 105 | mTags)) |
| 106 | { |
| 107 | return ExportTask([](ExportProcessorDelegate&){ return ExportResult::Cancelled; }); |
| 108 | } |
| 109 | |
| 110 | return ExportTask([actualFilename = filename, |
| 111 | targetFilename = mFileName, |
| 112 | processor = std::shared_ptr<ExportProcessor>(processor.release())] |
| 113 | (ExportProcessorDelegate& delegate) |
| 114 | { |
| 115 | auto result = ExportResult::Error; |
| 116 | auto cleanup = finally( [&] { |
| 117 | if(result == ExportResult::Success || result == ExportResult::Stopped) |
| 118 | { |
| 119 | if (actualFilename != targetFilename) |
| 120 | { |
| 121 | //may fail... |
| 122 | ::wxRenameFile(actualFilename.GetFullPath(), |
| 123 | targetFilename.GetFullPath(), |
| 124 | true); |
| 125 | } |
| 126 | } |
| 127 | else |
| 128 | ::wxRemoveFile(actualFilename.GetFullPath()); |
| 129 | } ); |
| 130 | result = processor->Process(delegate); |
| 131 | return result; |
| 132 | }); |
| 133 | } |
| 134 | |
| 135 | void ShowDiskFullExportErrorDialog(const wxFileNameWrapper &fileName) |
| 136 | { |
no test coverage detected