News:

--

Main Menu

Patch for file selector bug on Windows

Started by jfx, January 22, 2013, 05:54:42 PM

Previous topic - Next topic

jfx

The following patch fixes the file selector bug on Windows causing the selector to always open at a system directory instead of the last used one.

Qt library returns paths with non-native separator / on Windows unless each call is wrapped by QDir::toNativeSeparators(). This bad design can cause various bugs like this one where ADM_PathStripName() expects the native Windows path separator.

It is not safe to use / as the separator on Windows. For example, the command "type c:\text.txt" works but "type c:/text.txt" does not.


Index: avidemux/qt4/ADM_userInterfaces/ADM_gui/file_qt4.cpp
===================================================================
--- avidemux/qt4/ADM_userInterfaces/ADM_gui/file_qt4.cpp (revision 8439)
+++ avidemux/qt4/ADM_userInterfaces/ADM_gui/file_qt4.cpp (working copy)
@@ -32,7 +32,7 @@
void GUI_FileSelSelect(const char *label, char **name, uint32_t access)
{
char *tmpname = NULL;
- char *str = NULL;
+ QString str;
options pref_entry = LASTFILES_LASTDIR_READ;

*name = NULL;
@@ -42,15 +42,11 @@

if (prefs->get(pref_entry,&tmpname))
{
- str = ADM_PathCanonize(tmpname);
- ADM_PathStripName(str);
+ str = QFileInfo(QString::fromUtf8(tmpname)).canonicalPath();

/* LASTDIR may have gone; then do nothing and use current dir instead (implied) */
if (!QDir(str).exists())
- {
- delete [] str;
- str = NULL;
- }
+ str.clear();
}

QString fileName;
@@ -67,9 +63,6 @@
*name = ADM_strdup(fileName.toUtf8().constData());
prefs->set(pref_entry, (char *)*name);
}
-
- if (str)
- delete [] str;
}

void GUI_FileSelRead(const char *label, char **name)

mean

Thanks committed
If you can, can you attached the diff to the post ?
Else i have to do it manually and it takes more time if the patch is long


jfx

QFileInfo::canonicalPath() for some reason returns root directory if the file does not exist. This patch fixes the bug.