Make sure we don't try to delete the input file when running in "overwrite existing file" mode and the input/output happen to be identical.

This commit is contained in:
LoRd_MuldeR 2014-05-28 16:49:58 +02:00
parent e365edaafd
commit 4accd22659
5 changed files with 45 additions and 42 deletions

View File

@ -2945,47 +2945,47 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="488"/> <location filename="../../src/Thread_Process.cpp" line="491"/>
<source>Unknown File Name</source> <source>Unknown File Name</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="490"/> <location filename="../../src/Thread_Process.cpp" line="493"/>
<source>Unknown Title</source> <source>Unknown Title</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="491"/> <location filename="../../src/Thread_Process.cpp" line="494"/>
<source>Unknown Artist</source> <source>Unknown Artist</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="492"/> <location filename="../../src/Thread_Process.cpp" line="495"/>
<source>Unknown Album</source> <source>Unknown Album</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="494"/> <location filename="../../src/Thread_Process.cpp" line="497"/>
<source>Unknown Comment</source> <source>Unknown Comment</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="444"/> <location filename="../../src/Thread_Process.cpp" line="443"/>
<source>Target output file already exists, going to skip this file:</source> <source>Target output file already exists, going to skip this file:</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="445"/> <location filename="../../src/Thread_Process.cpp" line="444"/>
<source>If you don&apos;t want existing files to be skipped, please change the overwrite mode!</source> <source>If you don&apos;t want existing files to be skipped, please change the overwrite mode!</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="452"/> <location filename="../../src/Thread_Process.cpp" line="453"/>
<source>Target output file already exists, going to delete existing file:</source> <source>Target output file already exists, going to delete existing file:</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="462"/> <location filename="../../src/Thread_Process.cpp" line="464"/>
<source>Failed to delete existing target file, will save to another file name!</source> <source>Failed to delete existing target file, will save to another file name!</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -2962,47 +2962,47 @@
<translation type="unfinished">Nie można zapisać do lokalizacji docelowej:</translation> <translation type="unfinished">Nie można zapisać do lokalizacji docelowej:</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="488"/> <location filename="../../src/Thread_Process.cpp" line="491"/>
<source>Unknown File Name</source> <source>Unknown File Name</source>
<translation type="unfinished">Nieznana nazwa pliku</translation> <translation type="unfinished">Nieznana nazwa pliku</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="490"/> <location filename="../../src/Thread_Process.cpp" line="493"/>
<source>Unknown Title</source> <source>Unknown Title</source>
<translation type="unfinished">Nieznany Tytuł</translation> <translation type="unfinished">Nieznany Tytuł</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="491"/> <location filename="../../src/Thread_Process.cpp" line="494"/>
<source>Unknown Artist</source> <source>Unknown Artist</source>
<translation type="unfinished">Nieznany Artysta</translation> <translation type="unfinished">Nieznany Artysta</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="492"/> <location filename="../../src/Thread_Process.cpp" line="495"/>
<source>Unknown Album</source> <source>Unknown Album</source>
<translation type="unfinished">Nieznany Album</translation> <translation type="unfinished">Nieznany Album</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="494"/> <location filename="../../src/Thread_Process.cpp" line="497"/>
<source>Unknown Comment</source> <source>Unknown Comment</source>
<translation type="unfinished">Nieznany Komentarz</translation> <translation type="unfinished">Nieznany Komentarz</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="444"/> <location filename="../../src/Thread_Process.cpp" line="443"/>
<source>Target output file already exists, going to skip this file:</source> <source>Target output file already exists, going to skip this file:</source>
<translation type="unfinished">Plik wynikowy już istnieje, zostanie pominięty plik:</translation> <translation type="unfinished">Plik wynikowy już istnieje, zostanie pominięty plik:</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="445"/> <location filename="../../src/Thread_Process.cpp" line="444"/>
<source>If you don&apos;t want existing files to be skipped, please change the overwrite mode!</source> <source>If you don&apos;t want existing files to be skipped, please change the overwrite mode!</source>
<translation type="unfinished">Jeśli nie chcesz aby istniejące pliki były pomijane, zmień tryb nadpisywania!</translation> <translation type="unfinished">Jeśli nie chcesz aby istniejące pliki były pomijane, zmień tryb nadpisywania!</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="452"/> <location filename="../../src/Thread_Process.cpp" line="453"/>
<source>Target output file already exists, going to delete existing file:</source> <source>Target output file already exists, going to delete existing file:</source>
<translation type="unfinished">Plik wynikowy już istnieje, zostanie usunięty plik:</translation> <translation type="unfinished">Plik wynikowy już istnieje, zostanie usunięty plik:</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="462"/> <location filename="../../src/Thread_Process.cpp" line="464"/>
<source>Failed to delete existing target file, will save to another file name!</source> <source>Failed to delete existing target file, will save to another file name!</source>
<translation type="unfinished">Usuwanie istniejącego pliku zakończone niepowodzeniem, nowy plik zostanie zapisany pod inną nazwą!</translation> <translation type="unfinished">Usuwanie istniejącego pliku zakończone niepowodzeniem, nowy plik zostanie zapisany pod inną nazwą!</translation>
</message> </message>

View File

@ -2955,47 +2955,47 @@
<translation>Målmappen är INTE skrivbar:</translation> <translation>Målmappen är INTE skrivbar:</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="488"/> <location filename="../../src/Thread_Process.cpp" line="491"/>
<source>Unknown File Name</source> <source>Unknown File Name</source>
<translation>Okänt filnamn</translation> <translation>Okänt filnamn</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="490"/> <location filename="../../src/Thread_Process.cpp" line="493"/>
<source>Unknown Title</source> <source>Unknown Title</source>
<translation>Okänd titel</translation> <translation>Okänd titel</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="491"/> <location filename="../../src/Thread_Process.cpp" line="494"/>
<source>Unknown Artist</source> <source>Unknown Artist</source>
<translation>Okänd artist</translation> <translation>Okänd artist</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="492"/> <location filename="../../src/Thread_Process.cpp" line="495"/>
<source>Unknown Album</source> <source>Unknown Album</source>
<translation>Okänt album</translation> <translation>Okänt album</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="494"/> <location filename="../../src/Thread_Process.cpp" line="497"/>
<source>Unknown Comment</source> <source>Unknown Comment</source>
<translation>Okänd kommentar</translation> <translation>Okänd kommentar</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="444"/> <location filename="../../src/Thread_Process.cpp" line="443"/>
<source>Target output file already exists, going to skip this file:</source> <source>Target output file already exists, going to skip this file:</source>
<translation>Målfilen finns redan! Den här filen hoppas över:</translation> <translation>Målfilen finns redan! Den här filen hoppas över:</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="445"/> <location filename="../../src/Thread_Process.cpp" line="444"/>
<source>If you don&apos;t want existing files to be skipped, please change the overwrite mode!</source> <source>If you don&apos;t want existing files to be skipped, please change the overwrite mode!</source>
<translation>Om du inte vill att befintliga filer hoppas över, måste du ändra överskrivningsläge!</translation> <translation>Om du inte vill att befintliga filer hoppas över, måste du ändra överskrivningsläge!</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="452"/> <location filename="../../src/Thread_Process.cpp" line="453"/>
<source>Target output file already exists, going to delete existing file:</source> <source>Target output file already exists, going to delete existing file:</source>
<translation>Målfilen finns redan! Befintlig fil kommer att tas bort:</translation> <translation>Målfilen finns redan! Befintlig fil kommer att tas bort:</translation>
</message> </message>
<message> <message>
<location filename="../../src/Thread_Process.cpp" line="462"/> <location filename="../../src/Thread_Process.cpp" line="464"/>
<source>Failed to delete existing target file, will save to another file name!</source> <source>Failed to delete existing target file, will save to another file name!</source>
<translation>Kunde inte ta bort befintlig målfil. Sparar med annat filnamn!</translation> <translation>Kunde inte ta bort befintlig målfil. Sparar med annat filnamn!</translation>
</message> </message>

View File

@ -35,7 +35,7 @@
#define VER_LAMEXP_MINOR_LO 0 #define VER_LAMEXP_MINOR_LO 0
#define VER_LAMEXP_TYPE RC #define VER_LAMEXP_TYPE RC
#define VER_LAMEXP_PATCH 1 #define VER_LAMEXP_PATCH 1
#define VER_LAMEXP_BUILD 1550 #define VER_LAMEXP_BUILD 1551
#define VER_LAMEXP_CONFG 1528 #define VER_LAMEXP_CONFG 1528
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -376,7 +376,7 @@ int ProcessThread::generateOutFileName(QString &outFileName)
//Make sure the source file exists //Make sure the source file exists
QFileInfo sourceFile(m_audioFile.filePath()); QFileInfo sourceFile(m_audioFile.filePath());
if(!sourceFile.exists() || !sourceFile.isFile()) if(!(sourceFile.exists() && sourceFile.isFile()))
{ {
handleMessage(QString("%1\n%2").arg(tr("The source audio file could not be found:"), sourceFile.absoluteFilePath())); handleMessage(QString("%1\n%2").arg(tr("The source audio file could not be found:"), sourceFile.absoluteFilePath()));
return 0; return 0;
@ -428,7 +428,6 @@ int ProcessThread::generateOutFileName(QString &outFileName)
} }
else else
{ {
writeTest.close();
writeTest.remove(); writeTest.remove();
} }
@ -447,26 +446,30 @@ int ProcessThread::generateOutFileName(QString &outFileName)
} }
//Delete file, if target file exists (optional!) //Delete file, if target file exists (optional!)
if(m_overwriteReplacesExisting && QFileInfo(outFileName).exists()) if(m_overwriteReplacesExisting && QFileInfo(outFileName).exists() && QFileInfo(outFileName).isFile())
{ {
handleMessage(QString("%1\n%2\n").arg(tr("Target output file already exists, going to delete existing file:"), QDir::toNativeSeparators(outFileName))); if(sourceFile.canonicalFilePath().compare(QFileInfo(outFileName).absoluteFilePath(), Qt::CaseInsensitive) != 0)
bool bOkay = false;
for(int i = 0; i < 16; i++)
{ {
bOkay = QFile::remove(outFileName); handleMessage(QString("%1\n%2\n").arg(tr("Target output file already exists, going to delete existing file:"), QDir::toNativeSeparators(outFileName)));
if(bOkay) break; for(int i = 0; i < 16; i++)
lamexp_sleep(125); {
} if(QFile::remove(outFileName))
if(QFileInfo(outFileName).exists() || (!bOkay)) {
{ break;
handleMessage(QString("%1\n").arg(tr("Failed to delete existing target file, will save to another file name!"))); }
lamexp_sleep(125);
}
if(QFileInfo(outFileName).exists())
{
handleMessage(QString("%1\n").arg(tr("Failed to delete existing target file, will save to another file name!")));
}
} }
} }
int n = 1; int n = 1;
//Generate final name //Generate final name
while(QFileInfo(outFileName).exists()) while(QFileInfo(outFileName).exists() && (n < (INT_MAX/2)))
{ {
outFileName = QString("%1/%2 (%3).%4").arg(targetDir.canonicalPath(), fileName, QString::number(++n), m_encoder->extension()); outFileName = QString("%1/%2 (%3).%4").arg(targetDir.canonicalPath(), fileName, QString::number(++n), m_encoder->extension());
} }