diff --git a/ChangeLog.txt b/ChangeLog.txt index 82dd878d7..696a5b6d9 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -16,6 +16,7 @@ - [#696] Wrong grainline position on layout. - [#697] Incomplete Internal Path for Waist Dart. - [#698] Problem typing in new axis point for new piece. +- [#702] Valentina produces broken shortcut (.lnk) files on Windows. # Version 0.5.0 May 9, 2017 - [#581] User can now filter input lists by keyword in function wizard. diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 6e583c687..ccb02edc4 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -89,7 +89,7 @@ const QString VCommonSettings::unixStandardSharePath = QStringLiteral("/usr/shar namespace { //--------------------------------------------------------------------------------------------------------------------- -bool SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool replaceOnConflit) +void SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool replaceOnConflit) { QDir dir; dir.setPath(fromDir); @@ -97,16 +97,39 @@ bool SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool foreach (QString copyFile, dir.entryList(QDir::Files)) { const QString from = fromDir + QDir::separator() + copyFile; - const QString to = toDir + QDir::separator() + copyFile; + QString to = toDir + QDir::separator() + copyFile; + +#ifdef Q_OS_WIN + { + // To fix issue #702 check each not symlink if it is actually broken symlink. + // Also trying to mimic Unix symlink. If a file eaxists do not create a symlink and remove it if exists. + QFile fileTo(to); + if (fileTo.exists()) + { + if (not fileTo.rename(to + QLatin1String(".lnk"))) + { + QFile::remove(to + QLatin1String(".lnk")); + fileTo.rename(to + QLatin1String(".lnk")); + } + + QFileInfo info(to + QLatin1String(".lnk")); + if (info.symLinkTarget().isEmpty()) + { + fileTo.copy(to); + fileTo.remove(); + continue; // The file already exists, skip creating shortcut + } + } + } + + to = to + QLatin1String(".lnk"); +#endif if (QFile::exists(to)) { if (replaceOnConflit) { - if (QFile::remove(to) == false) - { - return false; - } + QFile::remove(to); } else { @@ -114,10 +137,7 @@ bool SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool } } - if (QFile::link(from, to) == false) - { - return false; - } + QFile::link(from, to); } foreach (QString copyDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) @@ -127,16 +147,11 @@ bool SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool if (dir.mkpath(to) == false) { - return false; + return; } - if (SymlinkCopyDirRecursive(from, to, replaceOnConflit) == false) - { - return false; - } + SymlinkCopyDirRecursive(from, to, replaceOnConflit); } - - return true; } } @@ -207,7 +222,7 @@ void VCommonSettings::PrepareStandardTemplates(const QString & currentPath) { QDir standardPath(VCommonSettings::StandardTemplatesPath()); const QDir localdata (VCommonSettings::GetDefPathTemplate()); - if (currentPath == VCommonSettings::GetDefPathTemplate() && standardPath.exists() && not localdata.exists()) + if (currentPath == VCommonSettings::GetDefPathTemplate() && standardPath.exists()) { if (localdata.mkpath(".")) { @@ -222,9 +237,7 @@ void VCommonSettings::PrepareStandardTables(const QString ¤tPath) { QDir standardPath(VCommonSettings::StandardTablesPath()); const QDir localdata (VCommonSettings::GetDefPathStandardMeasurements()); - if (currentPath == VCommonSettings::GetDefPathStandardMeasurements() - && standardPath.exists() - && not localdata.exists()) + if (currentPath == VCommonSettings::GetDefPathStandardMeasurements() && standardPath.exists()) { if (localdata.mkpath(".")) {