2016-05-25 21:23:48 +00:00
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "stdpch.h"
2016-06-12 13:40:38 +00:00
# include "migratedialog.h"
2016-10-21 10:53:10 +00:00
# ifdef Q_OS_WIN32
2016-05-25 21:23:48 +00:00
# include "configfile.h"
# include "utils.h"
# include "nel/misc/system_info.h"
# include "nel/misc/common.h"
# ifdef DEBUG_NEW
# define new DEBUG_NEW
# endif
2016-06-12 13:40:38 +00:00
CMigrateDialog : : CMigrateDialog ( ) : QDialog ( )
2016-05-25 21:23:48 +00:00
{
setWindowFlags ( windowFlags ( ) & ~ Qt : : WindowContextHelpButtonHint ) ;
setupUi ( this ) ;
// if launched from current directory, it means we just patched files
m_currentDirectory = CConfigFile : : getInstance ( ) - > getCurrentDirectory ( ) ;
if ( ! CConfigFile : : getInstance ( ) - > isRyzomInstalledIn ( m_currentDirectory ) )
{
// Ryzom is in the same directory as Ryzom Installer
2016-10-17 09:16:34 +00:00
m_currentDirectory = CConfigFile : : getInstance ( ) - > getInstallerCurrentDirPath ( ) ;
2016-05-25 21:23:48 +00:00
if ( ! CConfigFile : : getInstance ( ) - > isRyzomInstalledIn ( m_currentDirectory ) )
{
m_currentDirectory . clear ( ) ;
}
}
2016-09-29 14:54:50 +00:00
// update default destination
onDestinationDefaultButtonClicked ( ) ;
2016-05-25 21:23:48 +00:00
2016-10-13 17:50:11 +00:00
// both 32 and 64 bits are working under Windows 64 bits
2016-05-25 21:23:48 +00:00
// check whether OS architecture is 32 or 64 bits
if ( CConfigFile : : has64bitsOS ( ) )
{
2016-10-10 18:47:15 +00:00
// 64 bits enbabled by default
2016-05-25 21:23:48 +00:00
clientArchGroupBox - > setVisible ( true ) ;
clientArch64RadioButton - > setChecked ( true ) ;
2016-10-10 18:47:15 +00:00
clientArch32RadioButton - > setChecked ( false ) ;
2016-05-25 21:23:48 +00:00
}
else
{
2016-10-10 18:47:15 +00:00
// only 32 bits is available
2016-05-25 21:23:48 +00:00
clientArchGroupBox - > setVisible ( false ) ;
2016-10-10 18:47:15 +00:00
clientArch64RadioButton - > setChecked ( false ) ;
2016-05-25 21:23:48 +00:00
clientArch32RadioButton - > setChecked ( true ) ;
}
const CServer & server = CConfigFile : : getInstance ( ) - > getServer ( ) ;
destinationGroupBox - > setTitle ( tr ( " Files will be installed to (requires %1): " ) . arg ( qBytesToHumanReadable ( server . dataUncompressedSize ) ) ) ;
2016-09-29 14:54:50 +00:00
connect ( destinationDefaultButton , SIGNAL ( clicked ( ) ) , SLOT ( onDestinationDefaultButtonClicked ( ) ) ) ;
2016-05-25 21:23:48 +00:00
connect ( destinationBrowseButton , SIGNAL ( clicked ( ) ) , SLOT ( onDestinationBrowseButtonClicked ( ) ) ) ;
connect ( continueButton , SIGNAL ( clicked ( ) ) , SLOT ( accept ( ) ) ) ;
connect ( quitButton , SIGNAL ( clicked ( ) ) , SLOT ( reject ( ) ) ) ;
// TODO: if found a folder with initial data, get its total size and check if at least that size is free on the disk
// by default, advanced parameters are hidden
onShowAdvancedParameters ( Qt : : Unchecked ) ;
connect ( advancedCheckBox , SIGNAL ( stateChanged ( int ) ) , SLOT ( onShowAdvancedParameters ( int ) ) ) ;
2016-09-21 07:55:49 +00:00
raise ( ) ;
2016-05-25 21:23:48 +00:00
}
2016-06-12 13:40:38 +00:00
CMigrateDialog : : ~ CMigrateDialog ( )
2016-05-25 21:23:48 +00:00
{
}
2016-06-12 13:40:38 +00:00
void CMigrateDialog : : onShowAdvancedParameters ( int state )
2016-05-25 21:23:48 +00:00
{
advancedFrame - > setVisible ( state ! = Qt : : Unchecked ) ;
adjustSize ( ) ;
}
2016-09-29 14:54:50 +00:00
void CMigrateDialog : : onDestinationDefaultButtonClicked ( )
{
m_dstDirectory = CConfigFile : : getNewInstallationDirectory ( ) ;
updateDestinationText ( ) ;
}
2016-06-12 13:40:38 +00:00
void CMigrateDialog : : onDestinationBrowseButtonClicked ( )
2016-05-25 21:23:48 +00:00
{
2016-09-29 15:03:59 +00:00
QString directory = QFileDialog : : getExistingDirectory ( this , tr ( " Please choose directory to install Ryzom in " ) , m_dstDirectory ) ;
2016-05-25 21:23:48 +00:00
if ( directory . isEmpty ( ) ) return ;
m_dstDirectory = directory ;
updateDestinationText ( ) ;
}
2016-06-12 13:40:38 +00:00
void CMigrateDialog : : updateDestinationText ( )
2016-05-25 21:23:48 +00:00
{
destinationLabel - > setText ( m_dstDirectory ) ;
}
2016-06-12 13:40:38 +00:00
void CMigrateDialog : : accept ( )
2016-05-25 21:23:48 +00:00
{
// check free disk space
qint64 freeSpace = NLMISC : : CSystemInfo : : availableHDSpace ( m_dstDirectory . toUtf8 ( ) . constData ( ) ) ;
2016-10-20 11:07:18 +00:00
// shouldn't happen
2016-10-18 18:34:25 +00:00
if ( freeSpace = = 0 )
{
2016-10-20 11:07:18 +00:00
int error = NLMISC : : getLastError ( ) ;
2016-10-18 18:34:25 +00:00
2016-10-20 11:07:18 +00:00
nlwarning ( " Error '%s' (%d) occured when trying to check free disk space on %s, continue anyway " , NLMISC : : formatErrorMessage ( error ) . c_str ( ) , error , Q2C ( m_dstDirectory ) ) ;
2016-10-18 18:34:25 +00:00
}
2016-10-01 11:07:18 +00:00
// compare with exact size of current directory
2016-10-20 11:07:18 +00:00
if ( freeSpace & & freeSpace < getDirectorySize ( m_currentDirectory , true ) )
2016-05-25 21:23:48 +00:00
{
2016-10-04 09:58:51 +00:00
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. " ) ) ;
2016-05-25 21:23:48 +00:00
return ;
}
2016-09-29 15:05:20 +00:00
// 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
2016-10-09 13:09:30 +00:00
if ( ! isDirectoryWritable ( m_dstDirectory ) )
2016-09-29 15:05:20 +00:00
{
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 ;
}
2016-10-04 09:58:51 +00:00
// if reinstalling in same directory, don't check if directory is empty
if ( m_dstDirectory ! = CConfigFile : : getInstance ( ) - > getNewInstallationDirectory ( ) )
2016-09-29 15:05:20 +00:00
{
2016-10-04 09:58:51 +00:00
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 ;
}
2016-09-29 15:05:20 +00:00
}
2016-05-25 21:23:48 +00:00
CConfigFile : : getInstance ( ) - > setSrcServerDirectory ( m_currentDirectory ) ;
CConfigFile : : getInstance ( ) - > setInstallationDirectory ( m_dstDirectory ) ;
CConfigFile : : getInstance ( ) - > setUse64BitsClient ( clientArch64RadioButton - > isChecked ( ) ) ;
CConfigFile : : getInstance ( ) - > save ( ) ;
QDialog : : accept ( ) ;
}
2016-10-21 10:53:10 +00:00
# endif