1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "installdialog.h"
19 #include "configfile.h"
22 #include "nel/misc/system_info.h"
23 #include "nel/misc/common.h"
24 #include "nel/misc/debug.h"
30 CInstallDialog::CInstallDialog():QDialog()
32 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint
);
36 // update default destination
37 onDestinationDefaultButtonClicked();
40 // only 64 bits for OS X
41 clientArchGroupBox
->setVisible(false);
42 clientArch64RadioButton
->setChecked(true);
43 clientArch32RadioButton
->setChecked(false);
44 #elif defined(Q_OS_WIN32)
45 // both 32 and 64 bits are working under Windows 64 bits
47 // check whether OS architecture is 32 or 64 bits
48 if (CConfigFile::has64bitsOS())
50 // 64 bits enbabled by default
51 clientArchGroupBox
->setVisible(true);
52 clientArch64RadioButton
->setChecked(true);
53 clientArch32RadioButton
->setChecked(false);
57 // only 32 bits is available
58 clientArchGroupBox
->setVisible(false);
59 clientArch64RadioButton
->setChecked(false);
60 clientArch32RadioButton
->setChecked(true);
63 // only use the current architecture for Linux
65 clientArchGroupBox
->setVisible(false);
68 // only 64 bits is available
69 clientArch64RadioButton
->setChecked(true);
70 clientArch32RadioButton
->setChecked(false);
72 // only 32 bits is available
73 clientArch64RadioButton
->setChecked(false);
74 clientArch32RadioButton
->setChecked(true);
79 const CServer
&server
= CConfigFile::getInstance()->getServer();
81 destinationGroupBox
->setTitle(tr("Files will be installed to (requires %1):").arg(qBytesToHumanReadable(server
.dataUncompressedSize
)));
83 connect(destinationDefaultButton
, SIGNAL(clicked()), SLOT(onDestinationDefaultButtonClicked()));
84 connect(destinationBrowseButton
, SIGNAL(clicked()), SLOT(onDestinationBrowseButtonClicked()));
86 // TODO: if found a folder with initial data, get its total size and check if at least that size is free on the disk
88 // by default, advanced parameters are hidden
89 onShowAdvancedParameters(Qt::Unchecked
);
91 connect(advancedCheckBox
, SIGNAL(stateChanged(int)), SLOT(onShowAdvancedParameters(int)));
96 CInstallDialog::~CInstallDialog()
100 void CInstallDialog::onShowAdvancedParameters(int state
)
102 advancedFrame
->setVisible(state
!= Qt::Unchecked
);
107 void CInstallDialog::onDestinationDefaultButtonClicked()
109 m_dstDirectory
= CConfigFile::getNewInstallationDirectory();
111 updateDestinationText();
114 void CInstallDialog::onDestinationBrowseButtonClicked()
116 QString directory
= QFileDialog::getExistingDirectory(this, tr("Please choose directory to install Ryzom in"), m_dstDirectory
);
118 if (directory
.isEmpty()) return;
120 m_dstDirectory
= directory
;
122 updateDestinationText();
125 void CInstallDialog::updateDestinationText()
127 destinationLabel
->setText(m_dstDirectory
);
130 void CInstallDialog::accept()
132 // check free disk space
133 qint64 freeSpace
= CConfigFile::getInstance()->ignoreFreeDiskSpaceChecks() ? 0:NLMISC::CSystemInfo::availableHDSpace(m_dstDirectory
.toUtf8().constData());
138 int error
= NLMISC::getLastError();
140 nlwarning("Error '%s' (%d) occurred when trying to check free disk space on %s, continue anyway", NLMISC::formatErrorMessage(error
).c_str(), error
, Q2C(m_dstDirectory
));
143 const CServer
&server
= CConfigFile::getInstance()->getServer();
145 // compare with exact size of current directory
146 if (freeSpace
&& freeSpace
< server
.dataUncompressedSize
)
148 QMessageBox::StandardButton res
= QMessageBox::warning(this, tr("Not enough free disk space"), tr("You don't have enough free space on this disk, please make more space or choose a directory on another disk."));
152 // create directory if doesn't exist
153 bool succeedsToWrite
= QDir().mkpath(m_dstDirectory
);
155 // if unable to create directory, don't expect to write a file in it
158 // check if directory is writable by current user
159 if (!isDirectoryWritable(m_dstDirectory
))
161 succeedsToWrite
= false;
165 if (!succeedsToWrite
)
167 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."));
171 // if reinstalling in same directory, don't check if directory is empty
172 if (m_dstDirectory
!= CConfigFile::getInstance()->getNewInstallationDirectory())
174 if (!isDirectoryEmpty(m_dstDirectory
, true))
176 QMessageBox::StandardButton res
= QMessageBox::warning(this, tr("Directory not empty"), tr("This directory is not empty, please choose another one."));
181 // always download data
182 CConfigFile::getInstance()->setSrcServerDirectory("");
184 CConfigFile::getInstance()->setInstallationDirectory(m_dstDirectory
);
185 CConfigFile::getInstance()->setUse64BitsClient(clientArch64RadioButton
->isChecked());
186 CConfigFile::getInstance()->save();