From 533e01ea5a7decffbe991fb81920204d112dae95 Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 9 Oct 2016 15:09:30 +0200 Subject: [PATCH] Changed: Created and used isDirectoryWritable() function --HG-- branch : develop --- .../client/ryzom_installer/src/installdialog.cpp | 11 +---------- .../client/ryzom_installer/src/migratedialog.cpp | 11 +---------- .../tools/client/ryzom_installer/src/utils.cpp | 15 +++++++++++++++ .../tools/client/ryzom_installer/src/utils.h | 1 + 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/installdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/installdialog.cpp index 513cf1044..7198962ac 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/installdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/installdialog.cpp @@ -118,16 +118,7 @@ void CInstallDialog::accept() if (succeedsToWrite) { // check if directory is writable by current user - QFile file(m_dstDirectory + "/writable_test_for_ryzom_installer.txt"); - - if (file.open(QFile::WriteOnly)) - { - file.close(); - - // remove it - file.remove(); - } - else + if (!isDirectoryWritable(m_dstDirectory)) { succeedsToWrite = false; } diff --git a/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp index 0527bca1f..22e4f0ad2 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp @@ -133,16 +133,7 @@ void CMigrateDialog::accept() if (succeedsToWrite) { // check if directory is writable by current user - QFile file(m_dstDirectory + "/writable_test_for_ryzom_installer.txt"); - - if (file.open(QFile::WriteOnly)) - { - file.close(); - - // remove it - file.remove(); - } - else + if (!isDirectoryWritable(m_dstDirectory)) { succeedsToWrite = false; } diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp index c83ecdd62..de967b4f8 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp @@ -102,6 +102,21 @@ bool isDirectoryEmpty(const QString &directory, bool recursize) return res; } +bool isDirectoryWritable(const QString &directory) +{ + // check if directory is writable by current user + QFile file(directory + "/writable_test_for_ryzom_installer.txt"); + + if (!file.open(QFile::WriteOnly)) return false; + + file.close(); + + // remove it + file.remove(); + + return true; +} + qint64 getDirectorySize(const QString &directory, bool recursize) { qint64 size = 0; diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.h b/code/ryzom/tools/client/ryzom_installer/src/utils.h index f28d923ec..296c439fd 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.h +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.h @@ -32,6 +32,7 @@ QString qBytesToHumanReadable(qint64 bytes); QString nameToId(const QString &name); bool isDirectoryEmpty(const QString &directory, bool recursize); +bool isDirectoryWritable(const QString &directory); qint64 getDirectorySize(const QString &directory, bool recursize);