Fixed issue #702. Valentina produces broken shortcut (.lnk) files on Windows.

(grafted from 1dd5ef5924bf7d78c5c3eeae884e7f4e41bb688d)

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-06-05 16:18:38 +03:00
parent d37618ba08
commit 9be7403919
2 changed files with 35 additions and 21 deletions

View File

@ -16,6 +16,7 @@
- [#696] Wrong grainline position on layout. - [#696] Wrong grainline position on layout.
- [#697] Incomplete Internal Path for Waist Dart. - [#697] Incomplete Internal Path for Waist Dart.
- [#698] Problem typing in new axis point for new piece. - [#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 # Version 0.5.0 May 9, 2017
- [#581] User can now filter input lists by keyword in function wizard. - [#581] User can now filter input lists by keyword in function wizard.

View File

@ -89,7 +89,7 @@ const QString VCommonSettings::unixStandardSharePath = QStringLiteral("/usr/shar
namespace namespace
{ {
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool replaceOnConflit) void SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool replaceOnConflit)
{ {
QDir dir; QDir dir;
dir.setPath(fromDir); dir.setPath(fromDir);
@ -97,16 +97,39 @@ bool SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool
foreach (QString copyFile, dir.entryList(QDir::Files)) foreach (QString copyFile, dir.entryList(QDir::Files))
{ {
const QString from = fromDir + QDir::separator() + copyFile; 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 (QFile::exists(to))
{ {
if (replaceOnConflit) if (replaceOnConflit)
{ {
if (QFile::remove(to) == false) QFile::remove(to);
{
return false;
}
} }
else else
{ {
@ -114,10 +137,7 @@ bool SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool
} }
} }
if (QFile::link(from, to) == false) QFile::link(from, to);
{
return false;
}
} }
foreach (QString copyDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) foreach (QString copyDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
@ -127,17 +147,12 @@ bool SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool
if (dir.mkpath(to) == false) if (dir.mkpath(to) == false)
{ {
return false; return;
} }
if (SymlinkCopyDirRecursive(from, to, replaceOnConflit) == false) SymlinkCopyDirRecursive(from, to, replaceOnConflit);
{
return false;
} }
} }
return true;
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -207,7 +222,7 @@ void VCommonSettings::PrepareStandardTemplates(const QString & currentPath)
{ {
QDir standardPath(VCommonSettings::StandardTemplatesPath()); QDir standardPath(VCommonSettings::StandardTemplatesPath());
const QDir localdata (VCommonSettings::GetDefPathTemplate()); const QDir localdata (VCommonSettings::GetDefPathTemplate());
if (currentPath == VCommonSettings::GetDefPathTemplate() && standardPath.exists() && not localdata.exists()) if (currentPath == VCommonSettings::GetDefPathTemplate() && standardPath.exists())
{ {
if (localdata.mkpath(".")) if (localdata.mkpath("."))
{ {
@ -222,9 +237,7 @@ void VCommonSettings::PrepareStandardTables(const QString &currentPath)
{ {
QDir standardPath(VCommonSettings::StandardTablesPath()); QDir standardPath(VCommonSettings::StandardTablesPath());
const QDir localdata (VCommonSettings::GetDefPathStandardMeasurements()); const QDir localdata (VCommonSettings::GetDefPathStandardMeasurements());
if (currentPath == VCommonSettings::GetDefPathStandardMeasurements() if (currentPath == VCommonSettings::GetDefPathStandardMeasurements() && standardPath.exists())
&& standardPath.exists()
&& not localdata.exists())
{ {
if (localdata.mkpath(".")) if (localdata.mkpath("."))
{ {