Skip to content

Commit

Permalink
[file_qt4] Fix filename collision detection, broken on Windows
Browse files Browse the repository at this point in the history
Qt uses forward slashes as directory separators on Windows as well, but
the path to the last read file (i.e. to the currently loaded file) may be
stored with backslashes. In this case we failed to detect name collision and
didn't automatically append _edit to the basename.

Canonicalize paths before comparing to make filename collision detection
more robust.
  • Loading branch information
eumagga0x2a committed Dec 16, 2022
1 parent dff9dd5 commit 7ca8be0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions avidemux/qt4/ADM_userInterfaces/ADM_gui/file_qt4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ static QWidget *fileSelGetParent(void)
*/
static int fileSelWriteInternal(const char *label, char *target, uint32_t max, const char *location, const char *ext)
{
QString str,outputPath,outputExt=QString("");
QString fileName,dot=QString(".");
QString separator = QString("/");
QString str,outputPath,outputExt; // null strings
QString fileName,dot = ".";
QString separator = "/"; // Qt uses forward slash on Windows too
QString filterFile=QString::fromUtf8(QT_TRANSLATE_NOOP("qfile","All files (*.*)"));
QFileDialog::Options opts = QFileDialog::Options();
bool doFilter = !!(ext && strlen(ext));
Expand Down Expand Up @@ -106,18 +106,22 @@ static int fileSelWriteInternal(const char *label, char *target, uint32_t max, c
if(outputPath.isEmpty() || !QDir(outputPath).exists())
outputPath = QDir::homePath();

QString inputBaseName = QString("");
QString inputBaseName;
std::string lastRead;
admCoreUtils::getLastReadFile(lastRead);
if(lastRead.size())
{
inputBaseName = QFileInfo(QString::fromUtf8(lastRead.c_str())).completeBaseName();
str = outputPath+separator+inputBaseName+outputExt;
char *canonicalNew = ADM_PathCanonize(str.toUtf8().constData());
char *canonicalLast = ADM_PathCanonize(lastRead.c_str());

if(str==QString::fromUtf8(lastRead.c_str()))
if(!strcmp(canonicalNew, canonicalLast))
{ // try to avoid name collision when saving in the same directory as the currently loaded video
str = outputPath+separator+inputBaseName+QString("_edit")+outputExt;
}
delete [] canonicalNew;
delete [] canonicalLast;
}else
{
str = QDir::homePath()+separator+QString("out")+dot+outputExt;
Expand Down

0 comments on commit 7ca8be0

Please sign in to comment.