| 14 | } |
| 15 | |
| 16 | std::string AudioFile::getOutputFileName() { |
| 17 | |
| 18 | std::string recPath = wxGetApp().getConfig()->getRecordingPath(); |
| 19 | |
| 20 | // Strip any invalid characters from the name |
| 21 | std::string stripChars("<>:\"/\\|?*"); |
| 22 | std::string filenameBaseSafe = filenameBase; |
| 23 | |
| 24 | for (size_t i = 0, iMax = filenameBaseSafe.length(); i < iMax; i++) { |
| 25 | if (stripChars.find(filenameBaseSafe[i]) != std::string::npos) { |
| 26 | filenameBaseSafe.replace(i,1,"_"); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | // Create output file name |
| 31 | std::stringstream outputFileName; |
| 32 | outputFileName << recPath << filePathSeparator << filenameBaseSafe; |
| 33 | |
| 34 | int idx = 0; |
| 35 | |
| 36 | // If the file exists; then find the next non-existing file in sequence. |
| 37 | std::string fileNameCandidate = outputFileName.str(); |
| 38 | |
| 39 | while (FILE *file = fopen((fileNameCandidate + "." + getExtension()).c_str(), "r")) { |
| 40 | fclose(file); |
| 41 | fileNameCandidate = outputFileName.str() + "-" + std::to_string(++idx); |
| 42 | } |
| 43 | |
| 44 | return fileNameCandidate + "." + getExtension(); |
| 45 | } |
| 46 |
nothing calls this directly
no test coverage detected