mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-10 01:09:50 +00:00
Changed: New checks after selecting a directory (must be empty and write permissions)
This commit is contained in:
parent
fc6e939cd2
commit
296f4cdbd5
4 changed files with 101 additions and 0 deletions
|
@ -158,6 +158,40 @@ void CInstallDialog::accept()
|
|||
return;
|
||||
}
|
||||
|
||||
// create directory if doesn't exist
|
||||
bool succeedsToWrite = QDir().mkpath(m_dstDirectory);
|
||||
|
||||
// if unable to create directory, don't expect to write a file in it
|
||||
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
|
||||
{
|
||||
succeedsToWrite = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!succeedsToWrite)
|
||||
{
|
||||
QMessageBox::StandardButton res = QMessageBox::warning(this, tr("Unable to write in directory"), tr("You don't have the permission to write in this directory with your current user account, please choose another directory."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isDirectoryEmpty(m_dstDirectory, true))
|
||||
{
|
||||
QMessageBox::StandardButton res = QMessageBox::warning(this, tr("Directory not empty"), tr("This directory is not empty, please choose another one."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldDirectoryRadioButton->isChecked())
|
||||
{
|
||||
CConfigFile::getInstance()->setSrcServerDirectory(m_oldDirectory);
|
||||
|
|
|
@ -127,6 +127,40 @@ void CMigrateDialog::accept()
|
|||
return;
|
||||
}
|
||||
|
||||
// create directory if doesn't exist
|
||||
bool succeedsToWrite = QDir().mkpath(m_dstDirectory);
|
||||
|
||||
// if unable to create directory, don't expect to write a file in it
|
||||
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
|
||||
{
|
||||
succeedsToWrite = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!succeedsToWrite)
|
||||
{
|
||||
QMessageBox::StandardButton res = QMessageBox::warning(this, tr("Unable to write in directory"), tr("You don't have the permission to write in this directory with your current user account, please choose another directory."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isDirectoryEmpty(m_dstDirectory, true))
|
||||
{
|
||||
QMessageBox::StandardButton res = QMessageBox::warning(this, tr("Directory not empty"), tr("This directory is not empty, please choose another one."));
|
||||
return;
|
||||
}
|
||||
|
||||
CConfigFile::getInstance()->setSrcServerDirectory(m_currentDirectory);
|
||||
CConfigFile::getInstance()->setInstallationDirectory(m_dstDirectory);
|
||||
CConfigFile::getInstance()->setUse64BitsClient(clientArch64RadioButton->isChecked());
|
||||
|
|
|
@ -38,6 +38,37 @@ QString qBytesToHumanReadable(qint64 bytes)
|
|||
return QString::fromUtf8(NLMISC::bytesToHumanReadableUnits(bytes, units).c_str());
|
||||
}
|
||||
|
||||
bool isDirectoryEmpty(const QString &directory, bool recursize)
|
||||
{
|
||||
bool res = true;
|
||||
|
||||
if (!directory.isEmpty())
|
||||
{
|
||||
QDir dir(directory);
|
||||
|
||||
if (dir.exists())
|
||||
{
|
||||
QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot);
|
||||
|
||||
for (int i = 0; i < list.size(); ++i)
|
||||
{
|
||||
QFileInfo fileInfo = list.at(i);
|
||||
|
||||
if (fileInfo.isDir())
|
||||
{
|
||||
if (recursize) if (!isDirectoryEmpty(fileInfo.absoluteFilePath(), true)) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
qint64 getDirectorySize(const QString &directory, bool recursize)
|
||||
{
|
||||
qint64 size = 0;
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
|
||||
QString qBytesToHumanReadable(qint64 bytes);
|
||||
|
||||
bool isDirectoryEmpty(const QString &directory, bool recursize);
|
||||
|
||||
qint64 getDirectorySize(const QString &directory, bool recursize);
|
||||
|
||||
// Convert a UTF-8 string to QString
|
||||
|
|
Loading…
Reference in a new issue