Skip to content

Commit

Permalink
fix: Use temp wav file on "Save As" for mp3 files (#54)
Browse files Browse the repository at this point in the history
* fix: Disable File SaveAs for mp3 files

* fix: rename mp3

* chore: Check temp file is available

* fix: Use original filename

* fix: Re-use original filename
  • Loading branch information
darcywong00 authored Mar 3, 2022
1 parent 482be0b commit a5601ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Src/SA/SA_View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11611,7 +11611,28 @@ void CSaView::OnFileSaveAs() {
// get the current view caption string
path = doc.GetFilenameFromTitle().c_str();
}
path = FileUtils::ReplaceExtension((LPCTSTR)path, L".wav").c_str();

if (FileUtils::EndsWith((LPCTSTR)path, L".mp3")) {
// If path is mp3 file, use the temporary converted wavefile already in use:
CString tempConvertedWav = doc.GetConvertedWaveFilename().c_str();
if (!doc.CheckWaveFormatForOpen(tempConvertedWav)) {
app.ErrorMessage(IDS_ERROR_CANT_READ_WAVE_FILE, (LPCTSTR)tempConvertedWav);
return;
}

// Reuse the original filename for the new filename
wstring originalFilename = FileUtils::GetFilename((LPCTSTR)path);
wstring tempFilename = FileUtils::ReplaceExtension((LPCTSTR)originalFilename.c_str(), L".wav");
wstring tempFolder = FileUtils::GetParentFolder(doc.GetConvertedWaveFilename().c_str());
wstring temp = tempFolder;
temp.append(tempFilename.c_str());
FileUtils::Copy(doc.GetConvertedWaveFilename().c_str(), temp.c_str());
path = (CString)temp.c_str();

//path = doc.GetConvertedWaveFilename().c_str();
} else {
path = FileUtils::ReplaceExtension((LPCTSTR)path, L".wav").c_str();
}
docname = path;
}

Expand Down
4 changes: 4 additions & 0 deletions Src/SA/Sa_Doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7994,6 +7994,10 @@ wstring CSaDoc::GetFilenameFromTitle() {
return result;
}

wstring CSaDoc::GetConvertedWaveFilename() {
return m_szTempConvertedWave;
}

wstring CSaDoc::GetTranscriptionFilename() {
// a prerecorded file
wstring result = GetPathName();
Expand Down
1 change: 1 addition & 0 deletions Src/SA/Sa_Doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class CSaDoc : public CUndoRedoDoc, public ISaDoc {
bool IsTempFile();
bool CanEdit();
wstring GetFilenameFromTitle();
wstring GetConvertedWaveFilename();

// wave helper functions
// get a copy of the format parameters structure
Expand Down

0 comments on commit a5601ce

Please sign in to comment.