forked from osmocom/wireshark
Qt: Fix profile zip import on Windows
Do not use QDir::separator() as a directory separator. QT internally uses "/" as separator on all systems, including Windows. The zip files were not unzipped into target directory because splitting path on QDir::separator() in ProfileModel::cleanName() returned only one part (there weren't any "\' in file name, only "/"). Qt documentation for QDir::separator() mentions: "You do not need to use this function to build file paths. If you always use "/", Qt will translate your paths to conform to the underlying operating system. If you want to display paths to the user using their operating system's separator use toNativeSeparators()." Bug: 16410 Change-Id: I9627684f58f4c1da24b6eec8958a2542fe07d915 Reviewed-on: https://code.wireshark.org/review/36237 Petri-Dish: Tomasz Moń <desowin@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
ab274af1ed
commit
c07a48b6d3
|
@ -239,7 +239,7 @@ void ExportObjectDialog::saveCurrentEntry(QString *tempFile)
|
|||
safe_filename->str);
|
||||
g_string_free(safe_filename, TRUE);
|
||||
} else {
|
||||
QString path = QDir::tempPath().append(QDir::separator()).append(entry_filename);
|
||||
QString path = QDir::tempPath().append("/").append(entry_filename);
|
||||
/* This means, the system must remove the file! */
|
||||
file_name = path;
|
||||
if (QFileInfo::exists(path))
|
||||
|
|
|
@ -224,7 +224,7 @@ void FilterListModel::saveList()
|
|||
{
|
||||
QString filename = (type_ == FilterListModel::Capture) ? CFILTER_FILE_NAME : DFILTER_FILE_NAME;
|
||||
|
||||
filename = QString("%1%2%3").arg(ProfileModel::activeProfilePath()).arg(QDir::separator()).arg(filename);
|
||||
filename = QString("%1%2%3").arg(ProfileModel::activeProfilePath()).arg("/").arg(filename);
|
||||
QFile file(filename);
|
||||
|
||||
if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
|
|
|
@ -499,7 +499,7 @@ QVariant ProfileModel::dataPath(const QModelIndex &index) const
|
|||
} else {
|
||||
profile_path = gchar_free_to_qstring(get_profiles_dir());
|
||||
}
|
||||
profile_path.append(QDir::separator()).append(prof->name);
|
||||
profile_path.append("/").append(prof->name);
|
||||
return profile_path;
|
||||
}
|
||||
case PROF_STAT_NEW:
|
||||
|
@ -950,7 +950,7 @@ bool ProfileModel::copyTempToProfile(QString tempPath, QString profilePath, bool
|
|||
foreach (QFileInfo finfo, files)
|
||||
{
|
||||
QString tempFile = finfo.absoluteFilePath();
|
||||
QString profileFile = profilePath + QDir::separator() + finfo.fileName();
|
||||
QString profileFile = profilePath + "/" + finfo.fileName();
|
||||
|
||||
if (! profile_files_.contains(finfo.fileName()))
|
||||
{
|
||||
|
@ -1076,7 +1076,7 @@ bool ProfileModel::exportProfiles(QString filename, QModelIndexList items, QStri
|
|||
return false;
|
||||
}
|
||||
|
||||
if (WiresharkZipHelper::zip(filename, files, gchar_free_to_qstring(get_profiles_dir()) + QDir::separator()) )
|
||||
if (WiresharkZipHelper::zip(filename, files, gchar_free_to_qstring(get_profiles_dir()) + "/") )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -1096,9 +1096,9 @@ bool ProfileModel::acceptFile(QString fileName, int fileSize)
|
|||
|
||||
QString ProfileModel::cleanName(QString fileName)
|
||||
{
|
||||
QStringList parts = fileName.split(QDir::separator());
|
||||
QStringList parts = fileName.split("/");
|
||||
QString temp = parts[parts.count() - 1].replace(QRegExp("[" + QRegExp::escape(illegalCharacters()) + "]"), QString("_") );
|
||||
temp = parts.join(QDir::separator());
|
||||
temp = parts.join("/");
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
@ -1146,7 +1146,7 @@ int ProfileModel::importProfilesFromDir(QString dirname, int * skippedCnt, bool
|
|||
|
||||
entryCount++;
|
||||
|
||||
QString profilePath = profileDir.absolutePath() + QDir::separator() + fentry.fileName();
|
||||
QString profilePath = profileDir.absolutePath() + "/" + fentry.fileName();
|
||||
QString tempPath = fentry.absoluteFilePath();
|
||||
|
||||
if (fentry.fileName().compare(DEFAULT_PROFILE, Qt::CaseInsensitive) == 0 || QFile::exists(profilePath))
|
||||
|
|
|
@ -656,7 +656,7 @@ void ProfileDialog::importFromDirectory()
|
|||
|
||||
int skipped = 0;
|
||||
QStringList import;
|
||||
int count = model_->importProfilesFromDir(importDir.append(QDir::separator()), &skipped, false, &import);
|
||||
int count = model_->importProfilesFromDir(importDir.append("/"), &skipped, false, &import);
|
||||
|
||||
finishImport(fi, count, skipped, import);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ bool WiresharkZipHelper::unzip(QString zipFile, QString directory, bool (*fileCh
|
|||
|
||||
if (di.exists())
|
||||
{
|
||||
QString fullPath = di.path() + QDir::separator() + fileInZip;
|
||||
QString fullPath = di.path() + "/" + fileInZip;
|
||||
QFileInfo fi(fullPath);
|
||||
QString dirPath = fi.absolutePath();
|
||||
|
||||
|
@ -94,7 +94,7 @@ bool WiresharkZipHelper::unzip(QString zipFile, QString directory, bool (*fileCh
|
|||
if (dirPath.length() == 0)
|
||||
continue;
|
||||
|
||||
fi = QFileInfo(dirPath + QDir::separator() + fi.fileName());
|
||||
fi = QFileInfo(dirPath + "/" + fi.fileName());
|
||||
fullPath = fi.absoluteFilePath();
|
||||
}
|
||||
if (fullPath.length() == 0)
|
||||
|
@ -234,7 +234,7 @@ bool WiresharkZipHelper::zip(QString fileName, QStringList files, QString relati
|
|||
QString fileInZip = sf.absoluteFilePath();
|
||||
fileInZip.replace(relativeTo, "");
|
||||
/* Windows cannot open zip files, if the filenames starts with a separator */
|
||||
while (fileInZip.length() > 0 && fileInZip.startsWith(QDir::separator()))
|
||||
while (fileInZip.length() > 0 && fileInZip.startsWith("/"))
|
||||
fileInZip = fileInZip.right(fileInZip.length() - 1);
|
||||
|
||||
WiresharkZipHelper::addFileToZip(zf, sf.absoluteFilePath(), fileInZip);
|
||||
|
|
Loading…
Reference in New Issue