2016-05-16 09:11:40 +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"
# include "operationdialog.h"
# include "downloader.h"
# include "profilesdialog.h"
# include "configfile.h"
# include "config.h"
# include "profilesmodel.h"
2016-06-18 20:40:02 +00:00
# include "utils.h"
2016-06-19 19:02:17 +00:00
# include "nel/misc/path.h"
2016-05-16 09:11:40 +00:00
# include "filescopier.h"
# include "filesextractor.h"
# include "filescleaner.h"
# include "seven_zip.h"
# if defined(Q_OS_WIN32) && defined(QT_WINEXTRAS_LIB)
# include <QtWinExtras/QWinTaskbarProgress>
# include <QtWinExtras/QWinTaskbarButton>
# endif
2016-05-25 21:26:40 +00:00
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
2016-05-16 09:11:40 +00:00
# ifdef DEBUG_NEW
# define new DEBUG_NEW
# endif
2016-10-03 08:01:30 +00:00
COperationDialog : : COperationDialog ( QWidget * parent ) : QDialog ( parent ) , m_aborting ( false ) , m_operation ( OperationNone ) ,
m_operationStep ( DisplayNoServerError ) , m_operationStepCounter ( 0 )
2016-05-16 09:11:40 +00:00
{
setupUi ( this ) ;
2016-05-16 12:50:15 +00:00
setWindowFlags ( windowFlags ( ) & ~ Qt : : WindowContextHelpButtonHint ) ;
2016-05-16 09:11:40 +00:00
# if defined(Q_OS_WIN32) && defined(QT_WINEXTRAS_LIB)
m_button = new QWinTaskbarButton ( this ) ;
# endif
// downloader
2016-06-12 12:11:58 +00:00
m_downloader = new CDownloader ( this , this ) ;
2016-05-16 09:11:40 +00:00
2016-06-18 17:52:51 +00:00
connect ( m_downloader , SIGNAL ( downloadPrepared ( ) ) , SLOT ( onDownloadPrepared ( ) ) ) ;
connect ( m_downloader , SIGNAL ( downloadDone ( ) ) , SLOT ( onDownloadDone ( ) ) ) ;
2016-05-16 09:11:40 +00:00
connect ( operationButtonBox , SIGNAL ( clicked ( QAbstractButton * ) ) , SLOT ( onAbortClicked ( ) ) ) ;
// operations
connect ( this , SIGNAL ( prepare ( ) ) , SLOT ( onProgressPrepare ( ) ) ) ;
connect ( this , SIGNAL ( init ( qint64 , qint64 ) ) , SLOT ( onProgressInit ( qint64 , qint64 ) ) ) ;
connect ( this , SIGNAL ( start ( ) ) , SLOT ( onProgressStart ( ) ) ) ;
connect ( this , SIGNAL ( stop ( ) ) , SLOT ( onProgressStop ( ) ) ) ;
connect ( this , SIGNAL ( progress ( qint64 , QString ) ) , SLOT ( onProgressProgress ( qint64 , QString ) ) ) ;
connect ( this , SIGNAL ( success ( qint64 ) ) , SLOT ( onProgressSuccess ( qint64 ) ) ) ;
connect ( this , SIGNAL ( fail ( QString ) ) , SLOT ( onProgressFail ( QString ) ) ) ;
2016-05-16 12:52:47 +00:00
connect ( this , SIGNAL ( done ( ) ) , SLOT ( onDone ( ) ) ) ;
2016-05-16 09:11:40 +00:00
2016-09-28 21:27:15 +00:00
adjustSize ( ) ;
// fix height
setFixedHeight ( height ( ) ) ;
2016-09-21 07:55:49 +00:00
raise ( ) ;
2016-05-16 09:11:40 +00:00
}
COperationDialog : : ~ COperationDialog ( )
{
}
2016-06-14 17:39:39 +00:00
void COperationDialog : : setOperation ( OperationType operation )
2016-05-29 18:34:43 +00:00
{
m_operation = operation ;
}
2016-06-19 19:02:17 +00:00
void COperationDialog : : setUninstallComponents ( const SComponents & components )
2016-06-04 17:57:50 +00:00
{
2016-06-19 19:02:17 +00:00
m_removeComponents = components ;
2016-06-04 17:57:50 +00:00
}
2016-05-16 09:11:40 +00:00
void COperationDialog : : processNextStep ( )
2016-05-29 18:34:43 +00:00
{
2016-06-19 19:05:14 +00:00
if ( operationShouldStop ( ) )
{
2016-09-14 06:12:49 +00:00
rejectDelayed ( ) ;
2016-06-19 19:05:14 +00:00
return ;
}
2016-05-29 18:34:43 +00:00
switch ( m_operation )
{
case OperationMigrate :
2016-06-14 17:53:44 +00:00
case OperationInstall :
processInstallNextStep ( ) ;
2016-05-29 18:34:43 +00:00
break ;
2016-06-12 11:54:47 +00:00
case OperationUpdateProfiles :
2016-06-12 12:12:07 +00:00
processUpdateProfilesNextStep ( ) ;
2016-06-12 11:54:47 +00:00
break ;
2016-05-29 18:34:43 +00:00
case OperationUninstall :
processUninstallNextStep ( ) ;
break ;
default :
break ;
}
}
2016-06-14 17:53:44 +00:00
void COperationDialog : : processInstallNextStep ( )
2016-05-16 09:11:40 +00:00
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-05-16 12:54:24 +00:00
// long operations are done in a thread
2016-06-14 17:53:44 +00:00
OperationStep step = config - > getInstallNextStep ( ) ;
2016-05-16 12:54:24 +00:00
2016-10-03 08:01:30 +00:00
if ( step = = m_operationStep )
{
+ + m_operationStepCounter ;
}
else
{
m_operationStep = step ;
m_operationStepCounter = 0 ;
}
if ( m_operationStepCounter > 10 )
{
qDebug ( ) < < " possible infinite loop " < < m_operationStep < < m_operationStepCounter ;
}
2016-05-16 12:54:24 +00:00
switch ( step )
2016-05-16 09:11:40 +00:00
{
2016-06-14 17:39:39 +00:00
case DownloadData :
2016-05-16 12:49:18 +00:00
downloadData ( ) ;
2016-05-16 09:11:40 +00:00
break ;
2016-06-14 17:39:39 +00:00
case ExtractDownloadedData :
QtConcurrent : : run ( this , & COperationDialog : : extractDownloadedData ) ;
2016-05-16 09:11:40 +00:00
break ;
2016-06-14 17:39:39 +00:00
case DownloadClient :
2016-05-16 12:49:18 +00:00
downloadClient ( ) ;
2016-05-16 09:11:40 +00:00
break ;
2016-06-14 17:39:39 +00:00
case ExtractDownloadedClient :
QtConcurrent : : run ( this , & COperationDialog : : extractDownloadedClient ) ;
2016-05-16 09:11:40 +00:00
break ;
2016-06-14 17:39:39 +00:00
case CopyDataFiles :
QtConcurrent : : run ( this , & COperationDialog : : copyDataFiles ) ;
2016-05-16 09:11:40 +00:00
break ;
2016-06-14 17:39:39 +00:00
case CopyProfileFiles :
2016-05-16 09:11:40 +00:00
QtConcurrent : : run ( this , & COperationDialog : : copyProfileFiles ) ;
break ;
2016-06-14 17:39:39 +00:00
case CleanFiles :
2016-05-29 18:34:43 +00:00
QtConcurrent : : run ( this , & COperationDialog : : cleanFiles ) ;
break ;
2016-06-14 17:39:39 +00:00
case ExtractBnpClient :
2016-05-16 09:11:40 +00:00
QtConcurrent : : run ( this , & COperationDialog : : extractBnpClient ) ;
break ;
2016-06-14 17:39:39 +00:00
case CopyInstaller :
2016-05-29 18:34:43 +00:00
QtConcurrent : : run ( this , & COperationDialog : : copyInstaller ) ;
2016-05-26 17:30:18 +00:00
break ;
2016-06-14 17:39:39 +00:00
case UninstallOldClient :
2016-05-29 18:34:43 +00:00
uninstallOldClient ( ) ;
2016-05-16 09:11:40 +00:00
break ;
2016-06-14 17:39:39 +00:00
case CreateProfile :
2016-05-16 09:11:40 +00:00
createDefaultProfile ( ) ;
break ;
2016-07-25 16:31:11 +00:00
case CreateProfileShortcuts :
createProfileShortcuts ( 0 ) ;
2016-05-16 09:11:40 +00:00
break ;
2016-06-14 17:39:39 +00:00
case CreateAddRemoveEntry :
2016-05-26 17:34:15 +00:00
createAddRemoveEntry ( ) ;
break ;
2016-06-14 17:39:39 +00:00
case Done :
2016-09-14 06:12:49 +00:00
acceptDelayed ( ) ;
2016-05-16 12:53:19 +00:00
break ;
2016-05-16 09:11:40 +00:00
default :
// cases already managed in main.cpp
2016-06-14 17:39:39 +00:00
qDebug ( ) < < " Shouldn't happen, step " < < step ;
2016-05-16 09:11:40 +00:00
break ;
}
}
2016-06-19 19:02:17 +00:00
void COperationDialog : : updateAddRemoveComponents ( )
2016-06-12 11:54:47 +00:00
{
2016-06-14 17:51:28 +00:00
QStringList serversToUpdate ;
2016-06-19 19:02:17 +00:00
2016-06-14 17:51:28 +00:00
QStringList profilesToDelete ;
2016-06-19 19:02:17 +00:00
QStringList profilesToAdd ;
2016-06-14 17:51:28 +00:00
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-06-19 19:02:17 +00:00
foreach ( const CProfile & profile , config - > getProfiles ( ) )
{
// append all new profiles
profilesToAdd < < profile . id ;
}
2016-06-14 17:51:28 +00:00
foreach ( const CProfile & profile , config - > getBackupProfiles ( ) )
{
2016-06-19 19:02:17 +00:00
// append all old profiles
profilesToDelete < < profile . id ;
// remove profiles that didn't exist
profilesToAdd . removeAll ( profile . id ) ;
2016-10-04 17:27:29 +00:00
// delete all shortcuts, we'll recreate them later
profile . deleteShortcuts ( ) ;
2016-06-14 17:51:28 +00:00
}
const CServer & defaultServer = config - > getServer ( ) ;
foreach ( const CProfile & profile , config - > getProfiles ( ) )
{
const CServer & server = config - > getServer ( profile . server ) ;
QString serverDirectory = server . getDirectory ( ) ;
// check if Ryzom is installed in new server directory
if ( server . id ! = defaultServer . id & & ! config - > isRyzomInstalledIn ( serverDirectory ) & & serversToUpdate . indexOf ( server . id ) = = - 1 )
{
serversToUpdate < < server . id ;
}
// remove profiles that still exist
profilesToDelete . removeAll ( profile . id ) ;
2016-07-25 16:36:03 +00:00
// delete all shortcuts, they'll be recreated later
profile . deleteShortcuts ( ) ;
2016-06-14 17:51:28 +00:00
}
2016-06-19 19:02:17 +00:00
// update components to remove
m_removeComponents . profiles < < profilesToDelete ;
m_removeComponents . installer = false ;
2016-06-26 17:41:33 +00:00
m_removeComponents . downloadedFiles = false ;
2016-06-19 19:02:17 +00:00
// update components to add
m_addComponents . profiles < < profilesToAdd ;
m_addComponents . servers < < serversToUpdate ;
m_addComponents . installer = false ;
2016-06-26 17:41:33 +00:00
m_addComponents . downloadedFiles = false ;
2016-06-19 19:02:17 +00:00
}
void COperationDialog : : processUpdateProfilesNextStep ( )
{
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Updating profiles... " ) ;
2016-09-14 06:12:49 +00:00
2016-06-19 19:02:17 +00:00
// for "update profiles" operations, we set installer to false when components are updated,
// since we're not using this variable
if ( m_addComponents . installer & & m_removeComponents . installer )
2016-06-14 17:51:28 +00:00
{
2016-06-19 19:02:17 +00:00
updateAddRemoveComponents ( ) ;
}
2016-07-25 16:36:03 +00:00
2016-06-19 19:02:17 +00:00
// TODO: check all servers are downloaded
// TODO: delete profiles directories that are not used anymore
2016-06-14 17:51:28 +00:00
2016-06-19 19:02:17 +00:00
if ( ! m_removeComponents . profiles . isEmpty ( ) )
{
2016-06-14 17:51:28 +00:00
// delete profiles in another thread
QtConcurrent : : run ( this , & COperationDialog : : deleteComponentsProfiles ) ;
2016-06-19 19:02:17 +00:00
return ;
}
2016-06-14 17:51:28 +00:00
2016-06-19 19:02:17 +00:00
if ( ! m_addComponents . profiles . isEmpty ( ) )
{
// add profiles in another thread
QtConcurrent : : run ( this , & COperationDialog : : addComponentsProfiles ) ;
2016-06-14 17:51:28 +00:00
return ;
}
2016-07-25 16:36:03 +00:00
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-06-19 19:02:17 +00:00
if ( ! m_addComponents . servers . isEmpty ( ) )
2016-06-14 17:51:28 +00:00
{
2016-06-19 19:02:17 +00:00
const CServer & defaultServer = config - > getServer ( ) ;
2016-06-14 17:51:28 +00:00
2016-06-19 19:02:17 +00:00
// servers files to download/update
foreach ( const QString & serverId , m_addComponents . servers )
2016-06-14 17:51:28 +00:00
{
2016-06-19 19:02:17 +00:00
const CServer & server = config - > getServer ( serverId ) ;
2016-06-14 17:51:28 +00:00
2016-06-19 19:02:17 +00:00
// data
if ( ! config - > areRyzomDataInstalledIn ( server . getDirectory ( ) ) )
2016-06-14 17:51:28 +00:00
{
2016-06-19 19:02:17 +00:00
QString dataFile = config - > getInstallationDirectory ( ) + " / " + server . dataDownloadFilename ;
// archive already downloaded
if ( QFile : : exists ( dataFile ) )
{
// make server current
m_currentServerId = server . id ;
// uncompress it
QtConcurrent : : run ( this , & COperationDialog : : extractDownloadedData ) ;
return ;
}
// data download URLs are different, can't copy data from default server
if ( server . dataDownloadUrl ! = defaultServer . dataDownloadUrl )
{
// download it
downloadData ( ) ;
return ;
}
2016-06-14 17:51:28 +00:00
2016-06-19 19:02:17 +00:00
// same data used
2016-06-14 17:51:28 +00:00
2016-06-19 19:02:17 +00:00
// copy them
2016-06-14 17:51:28 +00:00
// TODO
return ;
}
2016-06-19 19:02:17 +00:00
// client
if ( ! config - > isRyzomClientInstalledIn ( server . getDirectory ( ) ) )
2016-06-14 17:51:28 +00:00
{
2016-06-19 19:02:17 +00:00
// client download URLs are different, can't copy client from default server
if ( server . clientDownloadUrl = = defaultServer . clientDownloadUrl )
{
if ( QFile : : exists ( " " ) )
2016-10-11 16:02:55 +00:00
{
2016-06-19 19:02:17 +00:00
downloadData ( ) ;
2016-10-11 16:02:55 +00:00
return ;
}
2016-06-19 19:02:17 +00:00
}
}
else
{
QString clientFile = config - > getInstallationDirectory ( ) + " / " + config - > expandVariables ( server . clientDownloadFilename ) ;
2016-06-14 17:51:28 +00:00
}
}
}
2016-06-19 19:02:17 +00:00
2016-10-04 17:27:29 +00:00
// recreate all shortcuts
2016-07-25 16:36:03 +00:00
foreach ( const CProfile & profile , config - > getProfiles ( ) )
{
profile . createShortcuts ( ) ;
}
2016-06-19 19:02:17 +00:00
updateAddRemoveEntry ( ) ;
2016-09-14 06:12:49 +00:00
acceptDelayed ( ) ;
2016-05-29 18:34:43 +00:00
}
void COperationDialog : : processUninstallNextStep ( )
{
2016-06-04 17:57:50 +00:00
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-06-19 19:02:17 +00:00
if ( ! m_removeComponents . servers . isEmpty ( ) )
2016-06-04 17:57:50 +00:00
{
QtConcurrent : : run ( this , & COperationDialog : : deleteComponentsServers ) ;
}
2016-06-19 19:02:17 +00:00
else if ( ! m_removeComponents . profiles . isEmpty ( ) )
2016-06-04 17:57:50 +00:00
{
QtConcurrent : : run ( this , & COperationDialog : : deleteComponentsProfiles ) ;
}
2016-06-26 17:41:33 +00:00
else if ( m_removeComponents . downloadedFiles )
{
QtConcurrent : : run ( this , & COperationDialog : : deleteComponentsDownloadedFiles ) ;
}
2016-06-19 19:02:17 +00:00
else if ( m_removeComponents . installer )
2016-06-04 17:57:50 +00:00
{
QtConcurrent : : run ( this , & COperationDialog : : deleteComponentsInstaller ) ;
}
else
{
// done
2016-09-14 06:12:49 +00:00
acceptDelayed ( ) ;
2016-06-04 17:57:50 +00:00
}
2016-05-29 18:34:43 +00:00
}
2016-05-16 09:11:40 +00:00
void COperationDialog : : showEvent ( QShowEvent * e )
{
# if defined(Q_OS_WIN32) && defined(QT_WINEXTRAS_LIB)
m_button - > setWindow ( windowHandle ( ) ) ;
# endif
e - > accept ( ) ;
processNextStep ( ) ;
}
void COperationDialog : : closeEvent ( QCloseEvent * e )
{
if ( e - > spontaneous ( ) )
{
e - > ignore ( ) ;
onAbortClicked ( ) ;
}
}
void COperationDialog : : onAbortClicked ( )
{
if ( m_downloader - > isDownloading ( ) )
{
if ( ! m_downloader - > supportsResume ( ) )
{
QMessageBox : : StandardButton res = QMessageBox : : question ( this , tr ( " Confirmation " ) , tr ( " Warning, this server doesn't support resume! If you stop download now, you won't be able to resume it later. \n Are you sure to abort download? " ) ) ;
if ( res ! = QMessageBox : : Yes ) return ;
}
}
QMutexLocker locker ( & m_abortingMutex ) ;
m_aborting = true ;
}
2016-06-18 17:52:51 +00:00
void COperationDialog : : onDownloadPrepared ( )
{
// actually download the file
m_downloader - > getFile ( ) ;
}
void COperationDialog : : onDownloadDone ( )
{
renamePartFile ( ) ;
emit done ( ) ;
}
2016-05-16 09:11:40 +00:00
void COperationDialog : : onProgressPrepare ( )
{
operationProgressBar - > setFormat ( tr ( " %p% (%v/%m KiB) " ) ) ;
operationProgressBar - > setMinimum ( 0 ) ;
operationProgressBar - > setMaximum ( 0 ) ;
operationProgressBar - > setValue ( 0 ) ;
operationLabel - > setText ( m_currentOperation ) ;
}
void COperationDialog : : onProgressInit ( qint64 current , qint64 total )
{
operationProgressBar - > setMinimum ( 0 ) ;
operationProgressBar - > setMaximum ( total / 1024 ) ;
operationProgressBar - > setValue ( current / 1024 ) ;
# if defined(Q_OS_WIN32) && defined(QT_WINEXTRAS_LIB)
m_button - > progress ( ) - > setMinimum ( 0 ) ;
m_button - > progress ( ) - > setMaximum ( total / 1024 ) ;
m_button - > progress ( ) - > setValue ( current / 1024 ) ;
# endif
}
void COperationDialog : : onProgressStart ( )
{
# if defined(Q_OS_WIN32) && defined(QT_WINEXTRAS_LIB)
m_button - > progress ( ) - > show ( ) ;
# endif
}
void COperationDialog : : onProgressStop ( )
{
# if defined(Q_OS_WIN32) && defined(QT_WINEXTRAS_LIB)
m_button - > progress ( ) - > hide ( ) ;
# endif
2016-09-14 06:12:49 +00:00
rejectDelayed ( ) ;
2016-05-16 09:11:40 +00:00
}
void COperationDialog : : onProgressProgress ( qint64 current , const QString & filename )
{
2016-09-28 10:22:27 +00:00
operationProgressLabel - > setText ( filename ) ;
2016-05-16 09:11:40 +00:00
operationProgressBar - > setValue ( current / 1024 ) ;
# if defined(Q_OS_WIN32) && defined(QT_WINEXTRAS_LIB)
m_button - > progress ( ) - > setValue ( current / 1024 ) ;
# endif
}
void COperationDialog : : onProgressSuccess ( qint64 total )
{
operationProgressBar - > setValue ( total / 1024 ) ;
# if defined(Q_OS_WIN32) && defined(QT_WINEXTRAS_LIB)
m_button - > progress ( ) - > hide ( ) ;
# endif
}
void COperationDialog : : onProgressFail ( const QString & error )
{
QMessageBox : : critical ( this , tr ( " Error " ) , error ) ;
2016-09-22 09:38:32 +00:00
{
QMutexLocker locker ( & m_abortingMutex ) ;
m_aborting = true ;
}
processNextStep ( ) ;
2016-05-16 09:11:40 +00:00
}
void COperationDialog : : onDone ( )
{
2016-06-19 19:05:14 +00:00
processNextStep ( ) ;
2016-05-16 12:49:18 +00:00
}
void COperationDialog : : downloadData ( )
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-06-14 17:54:51 +00:00
const CServer & server = config - > getServer ( m_currentServerId ) ;
2016-05-16 12:49:18 +00:00
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Downloading data required by server %1... " ) . arg ( server . name ) ;
2016-05-16 12:49:18 +00:00
m_downloader - > prepareFile ( config - > expandVariables ( server . dataDownloadUrl ) , config - > getInstallationDirectory ( ) + " / " + config - > expandVariables ( server . dataDownloadFilename ) + " .part " ) ;
}
2016-06-14 17:39:39 +00:00
void COperationDialog : : extractDownloadedData ( )
{
2016-06-18 17:53:19 +00:00
CConfigFile * config = CConfigFile : : getInstance ( ) ;
const CServer & server = config - > getServer ( m_currentServerId ) ;
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Extracting data required by server %1... " ) . arg ( server . name ) ;
2016-06-18 17:53:19 +00:00
2016-10-09 17:50:06 +00:00
QString dest = server . getDirectory ( ) ;
# ifdef Q_OS_MAC
// under OS X, data should be uncompressed in Ryzom.app/Contents/Resources
dest + = " /Ryzom.app/Contents/Resources " ;
# endif
2016-06-18 17:53:19 +00:00
CFilesExtractor extractor ( this ) ;
extractor . setSourceFile ( config - > getInstallationDirectory ( ) + " / " + server . dataDownloadFilename ) ;
2016-10-09 17:50:06 +00:00
extractor . setDestinationDirectory ( dest ) ;
2016-06-18 17:53:19 +00:00
2016-10-11 16:02:20 +00:00
if ( ! extractor . exec ( ) ) return ;
2016-06-18 17:53:19 +00:00
emit done ( ) ;
2016-06-14 17:39:39 +00:00
}
2016-05-16 12:49:18 +00:00
void COperationDialog : : downloadClient ( )
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-06-14 17:54:51 +00:00
const CServer & server = config - > getServer ( m_currentServerId ) ;
2016-05-16 12:49:18 +00:00
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Downloading client required by server %1... " ) . arg ( server . name ) ;
2016-05-16 12:49:18 +00:00
m_downloader - > prepareFile ( config - > expandVariables ( server . clientDownloadUrl ) , config - > getInstallationDirectory ( ) + " / " + config - > expandVariables ( server . clientDownloadFilename ) + " .part " ) ;
2016-05-16 09:11:40 +00:00
}
2016-06-14 17:50:19 +00:00
void COperationDialog : : extractDownloadedClient ( )
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
const CServer & server = config - > getServer ( m_currentServerId ) ;
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Extracting client required by server %1... " ) . arg ( server . name ) ;
2016-06-14 17:50:19 +00:00
2016-09-20 15:40:14 +00:00
QString destinationDirectory = server . getDirectory ( ) ;
2016-06-14 17:50:19 +00:00
CFilesExtractor extractor ( this ) ;
2016-06-18 17:50:26 +00:00
extractor . setSourceFile ( config - > getInstallationDirectory ( ) + " / " + config - > expandVariables ( server . clientDownloadFilename ) ) ;
2016-09-20 15:40:14 +00:00
extractor . setDestinationDirectory ( destinationDirectory ) ;
2016-06-14 17:50:19 +00:00
2016-10-11 16:02:20 +00:00
if ( ! extractor . exec ( ) ) return ;
2016-06-14 17:50:19 +00:00
2016-09-20 15:40:14 +00:00
launchUpgradeScript ( destinationDirectory , server . clientFilename ) ;
2016-06-14 17:50:19 +00:00
emit done ( ) ;
}
void COperationDialog : : copyDataFiles ( )
2016-05-16 09:11:40 +00:00
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
// default server
2016-06-14 17:54:51 +00:00
const CServer & server = config - > getServer ( m_currentServerId ) ;
2016-05-16 09:11:40 +00:00
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Copying data required by server %1... " ) . arg ( server . name ) ;
2016-05-16 09:11:40 +00:00
QStringList serverFiles ;
serverFiles < < " cfg " ;
serverFiles < < " data " ;
serverFiles < < " examples " ;
serverFiles < < " patch " ;
serverFiles < < " unpack " ;
CFilesCopier copier ( this ) ;
copier . setSourceDirectory ( config - > getSrcServerDirectory ( ) ) ;
2016-06-14 17:45:29 +00:00
copier . setDestinationDirectory ( server . getDirectory ( ) ) ;
2016-05-16 09:11:40 +00:00
copier . setIncludeFilter ( serverFiles ) ;
2016-10-11 16:02:20 +00:00
if ( ! copier . exec ( ) ) return ;
2016-05-16 12:52:47 +00:00
emit done ( ) ;
2016-05-16 09:11:40 +00:00
}
void COperationDialog : : copyProfileFiles ( )
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
// default server
const CServer & server = config - > getServer ( ) ;
// default profile
const CProfile & profile = config - > getProfile ( ) ;
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Copying old profile to new location... " ) ;
2016-05-16 12:50:53 +00:00
2016-05-16 09:11:40 +00:00
QStringList profileFiles ;
profileFiles < < " cache " ;
profileFiles < < " save " ;
profileFiles < < " user " ;
profileFiles < < " screenshots " ;
profileFiles < < " client.cfg " ;
profileFiles < < " *.log " ;
CFilesCopier copier ( this ) ;
copier . setSourceDirectory ( config - > getSrcProfileDirectory ( ) ) ;
2016-06-14 17:45:29 +00:00
copier . setDestinationDirectory ( profile . getDirectory ( ) ) ;
2016-05-16 09:11:40 +00:00
copier . setIncludeFilter ( profileFiles ) ;
2016-10-11 16:02:20 +00:00
if ( ! copier . exec ( ) ) return ;
2016-05-16 12:52:47 +00:00
2016-09-21 07:56:16 +00:00
// correct path to client_default.cfg
profile . createClientConfig ( ) ;
2016-05-16 12:52:47 +00:00
emit done ( ) ;
2016-05-16 09:11:40 +00:00
}
void COperationDialog : : extractBnpClient ( )
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
// default server
const CServer & server = config - > getServer ( ) ;
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Extracting client to new location... " ) ;
2016-05-16 12:50:53 +00:00
2016-06-14 17:45:29 +00:00
QString destinationDirectory = server . getDirectory ( ) ;
2016-05-16 09:11:40 +00:00
CFilesExtractor extractor ( this ) ;
extractor . setSourceFile ( config - > getSrcServerClientBNPFullPath ( ) ) ;
2016-06-14 17:36:26 +00:00
extractor . setDestinationDirectory ( destinationDirectory ) ;
2016-10-11 16:02:20 +00:00
if ( ! extractor . exec ( ) ) return ;
2016-05-16 12:52:16 +00:00
2016-09-20 15:40:14 +00:00
launchUpgradeScript ( destinationDirectory , server . clientFilename ) ;
emit done ( ) ;
}
void COperationDialog : : launchUpgradeScript ( const QString & directory , const QString & executable )
{
QString upgradeScript = directory + " /upgd_nl. " ;
2016-05-16 12:52:16 +00:00
# ifdef Q_OS_WIN
upgradeScript + = " bat " ;
# else
upgradeScript + = " sh " ;
# endif
if ( QFile : : exists ( upgradeScript ) )
{
QProcess process ;
QProcessEnvironment env = QProcessEnvironment : : systemEnvironment ( ) ;
2016-09-20 15:40:14 +00:00
env . insert ( " RYZOM_CLIENT " , QDir : : toNativeSeparators ( directory + " / " + executable ) ) ;
env . insert ( " UNPACKPATH " , QDir : : toNativeSeparators ( directory + " /unpack " ) ) ;
env . insert ( " ROOTPATH " , QDir : : toNativeSeparators ( directory ) ) ;
2016-05-16 12:52:16 +00:00
env . insert ( " STARTUPPATH " , " " ) ;
process . setProcessEnvironment ( env ) ;
2016-06-12 12:19:39 +00:00
// permissions to execute script
QFileDevice : : Permissions permissions ;
permissions | = QFileDevice : : ExeOther ;
permissions | = QFileDevice : : ExeOwner ;
permissions | = QFileDevice : : ExeUser ;
permissions | = QFileDevice : : ReadOther ;
permissions | = QFileDevice : : ReadOwner ;
permissions | = QFileDevice : : ReadUser ;
permissions | = QFileDevice : : WriteOwner ;
if ( ! QFile : : setPermissions ( upgradeScript , permissions ) )
{
qDebug ( ) < < " Unable to set executable flag to " < < upgradeScript ;
}
2016-05-16 12:52:16 +00:00
process . start ( upgradeScript ) ;
while ( process . waitForFinished ( ) )
{
qDebug ( ) < < " waiting " ;
}
}
2016-05-16 09:11:40 +00:00
}
2016-05-29 18:34:43 +00:00
void COperationDialog : : copyInstaller ( )
2016-05-26 17:30:18 +00:00
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Copying installer to new location... " ) ;
2016-05-26 17:30:18 +00:00
QString destinationDirectory = config - > getInstallationDirectory ( ) ;
// rename old client to installer
2016-10-16 15:26:05 +00:00
QString oldInstallerFullPath = QApplication : : applicationFilePath ( ) ;
QString newInstallerFullPath = config - > getInstallerInstalledFilePath ( ) ;
2016-05-26 17:30:18 +00:00
2016-10-16 15:26:05 +00:00
if ( ! newInstallerFullPath . isEmpty ( ) )
{
2016-08-14 10:49:39 +00:00
// always copy new installers
CFilesCopier copier ( this ) ;
copier . setIncludeFilter ( config - > getInstallerRequiredFiles ( ) ) ;
copier . addFile ( oldInstallerFullPath ) ;
copier . setSourceDirectory ( config - > getSrcServerDirectory ( ) . isEmpty ( ) ? QApplication : : applicationDirPath ( ) : config - > getSrcServerDirectory ( ) ) ;
copier . setDestinationDirectory ( config - > getInstallationDirectory ( ) ) ;
copier . exec ( ) ;
// copied file
oldInstallerFullPath = config - > getInstallationDirectory ( ) + " / " + QFileInfo ( oldInstallerFullPath ) . fileName ( ) ;
// rename old filename if different
if ( oldInstallerFullPath ! = newInstallerFullPath )
2016-05-26 17:30:18 +00:00
{
2016-08-14 10:49:39 +00:00
// delete previous installer
QFile : : remove ( newInstallerFullPath ) ;
// rename new installer with final name
QFile : : rename ( oldInstallerFullPath , newInstallerFullPath ) ;
2016-05-26 17:30:18 +00:00
}
2016-06-19 19:06:49 +00:00
// create menu directory if defined
QString path = config - > getMenuDirectory ( ) ;
2016-10-03 15:18:48 +00:00
if ( ! path . isEmpty ( ) & & ! QDir ( ) . mkpath ( path ) )
2016-06-19 19:06:49 +00:00
{
2016-10-03 15:18:48 +00:00
qDebug ( ) < < " Unable to create directory " < < path ;
2016-06-19 19:06:49 +00:00
}
// create installer link in menu
QString executable = newInstallerFullPath ;
2016-10-03 07:59:19 +00:00
QString shortcut = config - > getInstallerMenuShortcutFullPath ( ) ;
2016-07-25 16:36:45 +00:00
QString name = " Ryzom Installer " ;
QString icon ;
2016-06-19 19:06:49 +00:00
2016-07-25 16:36:45 +00:00
# ifdef Q_OS_WIN32
2016-07-26 16:22:18 +00:00
// under Windows, icon is included in executable
2016-07-25 16:36:45 +00:00
icon = executable ;
2016-10-09 13:08:37 +00:00
# elif defined(Q_OS_MAC)
// everything is in bundle
2016-07-25 16:36:45 +00:00
# else
2016-07-26 16:22:18 +00:00
// icon is in the same directory as installer
icon = config - > getInstallationDirectory ( ) + " /ryzom_installer.png " ;
2016-10-09 13:10:15 +00:00
// create icon if not exists
if ( ! QFile : : exists ( icon ) & & ! writeResource ( " :/icons/ryzom.png " , icon ) )
{
qDebug ( ) < < " Unable to create " < < icon ;
}
2016-07-25 16:36:45 +00:00
# endif
2016-10-03 07:59:19 +00:00
createShortcut ( shortcut , name , executable , " " , icon , " " ) ;
2016-05-26 17:30:18 +00:00
}
emit done ( ) ;
}
2016-05-29 18:32:33 +00:00
void COperationDialog : : uninstallOldClient ( )
{
# ifdef Q_OS_WIN
# ifdef Q_OS_WIN64
// use WOW6432Node in 64 bits (64 bits OS and 64 bits Installer) because Ryzom old installer was in 32 bits
QSettings settings ( " HKEY_LOCAL_MACHINE \\ SOFTWARE \\ WOW6432Node \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Ryzom " , QSettings : : NativeFormat ) ;
# else
QSettings settings ( " HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Ryzom " , QSettings : : NativeFormat ) ;
# endif
// check if Ryzom 2.1.0 is installed
if ( settings . contains ( " UninstallString " ) )
{
QString uninstaller = settings . value ( " UninstallString " ) . toString ( ) ;
if ( ! uninstaller . isEmpty ( ) & & QFile : : exists ( uninstaller ) )
{
QMessageBox : : StandardButtons button = QMessageBox : : question ( this , tr ( " Uninstall old client " ) , tr ( " An old version of Ryzom has been detected on this system, would you like to uninstall it to save space disk? " ) ) ;
if ( button = = QMessageBox : : Yes )
{
2016-09-19 12:35:29 +00:00
// to not ask twice
CConfigFile : : getInstance ( ) - > setUninstallingOldClient ( true ) ;
2016-09-14 06:13:20 +00:00
// remember the choice
2016-05-29 18:32:33 +00:00
CConfigFile : : getInstance ( ) - > setShouldUninstallOldClient ( true ) ;
2016-09-14 06:13:20 +00:00
// launch old uninstaller
2016-05-29 18:32:33 +00:00
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( uninstaller ) ) ;
}
else
{
// don't ask this question anymore
CConfigFile : : getInstance ( ) - > setShouldUninstallOldClient ( false ) ;
}
2016-08-14 10:52:22 +00:00
// save the choice
CConfigFile : : getInstance ( ) - > save ( ) ;
2016-05-29 18:32:33 +00:00
}
}
# endif
emit done ( ) ;
}
2016-05-16 09:11:40 +00:00
void COperationDialog : : cleanFiles ( )
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
// default server
const CServer & server = config - > getServer ( ) ;
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Cleaning obsolete files... " ) ;
2016-05-16 09:11:40 +00:00
CFilesCleaner cleaner ( this ) ;
2016-06-14 17:45:29 +00:00
cleaner . setDirectory ( server . getDirectory ( ) ) ;
2016-05-16 09:11:40 +00:00
cleaner . exec ( ) ;
2016-05-16 12:49:50 +00:00
emit done ( ) ;
}
bool COperationDialog : : createDefaultProfile ( )
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-06-14 17:55:56 +00:00
CServer server = config - > getServer ( ) ;
2016-05-16 12:49:50 +00:00
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Creating default profile... " ) ;
2016-05-16 12:49:50 +00:00
CProfile profile ;
profile . id = " 0 " ;
profile . name = QString ( " Ryzom (%1) " ) . arg ( server . name ) ;
profile . server = server . id ;
profile . comments = " Default profile created by Ryzom Installer " ;
2016-06-18 20:40:02 +00:00
profile . desktopShortcut = false ;
profile . menuShortcut = false ;
2016-05-16 12:49:50 +00:00
# ifdef Q_OS_WIN32
2016-06-18 20:40:02 +00:00
QStringList paths ;
// desktop
// Windows XP
paths < < " C:/Documents and Settings/All Users/Desktop " ;
// since Windows Vista
paths < < " C:/Users/Public/Desktop " ;
// new location
paths < < QStandardPaths : : writableLocation ( QStandardPaths : : DesktopLocation ) ;
foreach ( const QString & path , paths )
{
if ( QFile : : exists ( path + " /Ryzom.lnk " ) ) profile . desktopShortcut = true ;
}
paths . clear ( ) ;
// start menu
2016-05-16 12:49:50 +00:00
2016-06-18 20:40:02 +00:00
// Windows XP
paths < < " C:/Documents and Settings/All Users/Start Menu/Programs " ;
// since Windows Vista
paths < < " C:/ProgramData/Microsoft/Windows/Start Menu/Programs " ;
// new location
paths < < QStandardPaths : : writableLocation ( QStandardPaths : : ApplicationsLocation ) ;
foreach ( const QString & path , paths )
{
if ( QFile : : exists ( path + " /Ryzom/Ryzom.lnk " ) ) profile . menuShortcut = true ;
}
# endif
2016-05-16 12:49:50 +00:00
config - > addProfile ( profile ) ;
config - > save ( ) ;
emit done ( ) ;
return true ;
}
2016-07-25 16:31:11 +00:00
bool COperationDialog : : createProfileShortcuts ( const QString & profileId )
2016-05-16 12:49:50 +00:00
{
2016-06-14 17:56:10 +00:00
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-06-19 19:07:51 +00:00
const CProfile & profile = config - > getProfile ( profileId ) ;
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Creating shortcuts for profile %1... " ) . arg ( profile . id ) ;
2016-06-19 19:07:51 +00:00
2016-07-25 16:31:11 +00:00
profile . createShortcuts ( ) ;
2016-06-14 17:56:10 +00:00
2016-05-16 12:49:50 +00:00
emit done ( ) ;
return true ;
2016-05-16 09:11:40 +00:00
}
2016-05-25 21:26:40 +00:00
bool COperationDialog : : createAddRemoveEntry ( )
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-10-16 15:26:05 +00:00
QString newInstallerFullPath = config - > getInstallerInstalledFilePath ( ) ;
2016-05-25 21:26:40 +00:00
2016-10-16 15:26:05 +00:00
if ( ! newInstallerFullPath . isEmpty ( ) & & QFile : : exists ( newInstallerFullPath ) )
2016-05-25 21:26:40 +00:00
{
2016-05-26 17:34:15 +00:00
# ifdef Q_OS_WIN
2016-10-16 15:26:05 +00:00
QSettings settings ( " HKEY_CURRENT_USER \\ SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Ryzom " , QSettings : : NativeFormat ) ;
QString nativeFullPath = QDir : : toNativeSeparators ( newInstallerFullPath ) ;
settings . setValue ( " Comments " , config - > getProductComments ( ) ) ;
settings . setValue ( " DisplayIcon " , nativeFullPath + " ,0 " ) ;
settings . setValue ( " DisplayName " , QApplication : : applicationName ( ) ) ;
settings . setValue ( " InstallDate " , QDateTime : : currentDateTime ( ) . toString ( " Ymd " ) ) ;
settings . setValue ( " InstallLocation " , config - > getInstallationDirectory ( ) ) ;
settings . setValue ( " NoModify " , 0 ) ;
settings . setValue ( " NoRemove " , 0 ) ;
settings . setValue ( " NoRepair " , 0 ) ;
if ( ! config - > getProductPublisher ( ) . isEmpty ( ) ) settings . setValue ( " Publisher " , config - > getProductPublisher ( ) ) ;
settings . setValue ( " QuietUninstallString " , nativeFullPath + " -u -s " ) ;
settings . setValue ( " UninstallString " , nativeFullPath + " -u " ) ;
if ( ! config - > getProductUpdateUrl ( ) . isEmpty ( ) ) settings . setValue ( " URLUpdateInfo " , config - > getProductUpdateUrl ( ) ) ;
if ( ! config - > getProductAboutUrl ( ) . isEmpty ( ) ) settings . setValue ( " URLInfoAbout " , config - > getProductAboutUrl ( ) ) ;
if ( ! config - > getProductHelpUrl ( ) . isEmpty ( ) ) settings . setValue ( " HelpLink " , config - > getProductHelpUrl ( ) ) ;
// ModifyPath
2016-05-26 17:34:15 +00:00
# endif
2016-05-25 21:26:40 +00:00
}
2016-10-03 15:20:25 +00:00
updateAddRemoveEntry ( ) ;
2016-05-26 17:34:15 +00:00
emit done ( ) ;
2016-05-25 21:26:40 +00:00
return true ;
}
2016-06-19 19:08:23 +00:00
bool COperationDialog : : updateAddRemoveEntry ( )
{
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-10-16 15:26:05 +00:00
QString newInstallerFullPath = config - > getInstallerInstalledFilePath ( ) ;
2016-06-19 19:08:23 +00:00
2016-10-16 15:26:05 +00:00
if ( ! newInstallerFullPath . isEmpty ( ) & & QFile : : exists ( newInstallerFullPath ) )
2016-06-19 19:08:23 +00:00
{
2016-10-16 15:26:05 +00:00
QString newInstallerFilename = config - > getInstallerFilename ( ) ;
2016-06-19 19:08:23 +00:00
# ifdef Q_OS_WIN
2016-10-16 15:26:05 +00:00
QSettings settings ( " HKEY_CURRENT_USER \\ SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Ryzom " , QSettings : : NativeFormat ) ;
2016-06-19 19:08:23 +00:00
2016-10-16 15:26:05 +00:00
QString version = QApplication : : applicationVersion ( ) ;
2016-10-03 15:19:41 +00:00
2016-10-16 15:26:05 +00:00
settings . setValue ( " DisplayVersion " , version ) ;
settings . setValue ( " EstimatedSize " , ( quint32 ) ( getDirectorySize ( config - > getInstallationDirectory ( ) , true ) / 1024 ) ) ; // size if in KiB
2016-10-03 15:19:41 +00:00
2016-10-16 15:26:05 +00:00
QStringList versionTokens = version . split ( ' . ' ) ;
settings . setValue ( " MajorVersion " , versionTokens [ 0 ] . toInt ( ) ) ;
settings . setValue ( " MinorVersion " , versionTokens [ 1 ] . toInt ( ) ) ;
2016-06-19 19:08:23 +00:00
# endif
}
return true ;
}
2016-06-07 11:24:26 +00:00
bool COperationDialog : : deleteAddRemoveEntry ( )
{
# ifdef Q_OS_WIN
QSettings settings ( " HKEY_CURRENT_USER \\ SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Ryzom " , QSettings : : NativeFormat ) ;
settings . remove ( " " ) ;
# endif
return true ;
}
2016-06-04 17:57:50 +00:00
void COperationDialog : : deleteComponentsServers ( )
{
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Deleting client... " ) ;
2016-06-04 17:57:50 +00:00
2016-06-07 11:24:26 +00:00
emit prepare ( ) ;
2016-06-19 19:02:17 +00:00
emit init ( 0 , m_removeComponents . servers . size ( ) ) ;
2016-06-07 11:24:26 +00:00
emit start ( ) ;
2016-06-04 17:57:50 +00:00
CConfigFile * config = CConfigFile : : getInstance ( ) ;
2016-06-07 11:24:26 +00:00
int i = 0 ;
2016-06-19 19:02:17 +00:00
foreach ( const QString & serverId , m_removeComponents . servers )
2016-06-04 17:57:50 +00:00
{
2016-06-07 11:24:26 +00:00
if ( operationShouldStop ( ) )
{
emit stop ( ) ;
return ;
}
2016-06-14 17:43:45 +00:00
const CServer & server = config - > getServer ( serverId ) ;
2016-06-04 17:57:50 +00:00
2016-06-07 11:24:26 +00:00
emit progress ( i + + , server . name ) ;
2016-06-14 17:45:29 +00:00
QString path = server . getDirectory ( ) ;
2016-06-04 17:57:50 +00:00
2016-06-14 17:49:03 +00:00
if ( ! path . isEmpty ( ) )
2016-06-04 17:57:50 +00:00
{
2016-06-14 17:49:03 +00:00
QDir dir ( path ) ;
if ( dir . exists ( ) & & ! dir . removeRecursively ( ) )
{
emit fail ( tr ( " Unable to delete files for client %1 " ) . arg ( server . name ) ) ;
return ;
}
2016-06-04 17:57:50 +00:00
}
2016-07-25 16:36:03 +00:00
// delete all links to clients
for ( int i = 0 ; i < config - > getProfilesCount ( ) ; + + i )
{
const CProfile & profile = config - > getProfile ( i ) ;
if ( profile . server = = serverId )
{
profile . deleteShortcuts ( ) ;
}
}
2016-06-04 17:57:50 +00:00
}
2016-06-19 19:02:17 +00:00
emit success ( m_removeComponents . servers . size ( ) ) ;
// clear list of all servers to uninstall
m_removeComponents . servers . clear ( ) ;
2016-10-09 13:09:54 +00:00
// delete Ryzom directory if all files have been deleted
if ( isDirectoryEmpty ( config - > getInstallationDirectory ( ) , true ) ) QDir ( config - > getInstallationDirectory ( ) ) . removeRecursively ( ) ;
2016-06-04 17:57:50 +00:00
emit done ( ) ;
}
2016-06-19 19:08:49 +00:00
void COperationDialog : : addComponentsProfiles ( )
{
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Adding profiles... " ) ;
2016-06-19 19:08:49 +00:00
CConfigFile * config = CConfigFile : : getInstance ( ) ;
foreach ( const QString & profileId , m_addComponents . profiles )
{
2016-06-27 09:51:30 +00:00
const CProfile & profile = config - > getProfile ( profileId ) ;
2016-06-19 19:08:49 +00:00
2016-07-25 16:31:11 +00:00
profile . createShortcuts ( ) ;
2016-09-20 15:39:29 +00:00
profile . createClientConfig ( ) ;
2016-06-19 19:08:49 +00:00
}
2016-09-21 15:19:00 +00:00
// clear list of all servers to uninstall
m_addComponents . profiles . clear ( ) ;
emit done ( ) ;
2016-06-19 19:08:49 +00:00
}
2016-06-04 17:57:50 +00:00
void COperationDialog : : deleteComponentsProfiles ( )
{
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Deleting profiles... " ) ;
2016-06-07 11:24:26 +00:00
emit prepare ( ) ;
2016-06-19 19:02:17 +00:00
emit init ( 0 , m_removeComponents . servers . size ( ) ) ;
2016-06-07 11:24:26 +00:00
CConfigFile * config = CConfigFile : : getInstance ( ) ;
int i = 0 ;
2016-06-19 19:02:17 +00:00
foreach ( const QString & profileId , m_removeComponents . profiles )
2016-06-07 11:24:26 +00:00
{
if ( operationShouldStop ( ) )
{
emit stop ( ) ;
return ;
}
2016-06-14 17:43:45 +00:00
const CProfile & profile = config - > getProfile ( profileId ) ;
2016-06-07 11:24:26 +00:00
emit progress ( i + + , profile . name ) ;
2016-06-14 17:45:29 +00:00
QString path = profile . getDirectory ( ) ;
2016-06-07 11:24:26 +00:00
2016-06-14 17:49:03 +00:00
if ( ! path . isEmpty ( ) )
2016-06-07 11:24:26 +00:00
{
2016-06-14 17:49:03 +00:00
QDir dir ( path ) ;
if ( dir . exists ( ) & & ! dir . removeRecursively ( ) )
{
emit fail ( tr ( " Unable to delete files for profile %1 " ) . arg ( profile . name ) ) ;
return ;
}
2016-06-07 11:24:26 +00:00
}
2016-06-14 17:46:18 +00:00
2016-07-25 16:36:03 +00:00
profile . deleteShortcuts ( ) ;
2016-06-19 19:02:17 +00:00
2016-06-14 17:46:18 +00:00
// delete profile
config - > removeProfile ( profileId ) ;
2016-06-07 11:24:26 +00:00
}
2016-06-19 19:02:17 +00:00
emit success ( m_removeComponents . profiles . size ( ) ) ;
2016-06-14 17:55:41 +00:00
// clear list of all profiles to uninstall
2016-06-19 19:02:17 +00:00
m_removeComponents . profiles . clear ( ) ;
2016-06-14 17:55:41 +00:00
2016-10-09 13:09:54 +00:00
// delete profiles directory if all files have been deleted
if ( isDirectoryEmpty ( config - > getProfileDirectory ( ) , true ) ) QDir ( config - > getProfileDirectory ( ) ) . removeRecursively ( ) ;
2016-06-04 17:57:50 +00:00
emit done ( ) ;
}
void COperationDialog : : deleteComponentsInstaller ( )
{
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Deleting installer... " ) ;
2016-06-07 11:24:26 +00:00
CConfigFile * config = CConfigFile : : getInstance ( ) ;
deleteAddRemoveEntry ( ) ;
2016-06-19 19:06:00 +00:00
// delete menu
QString path = config - > getMenuDirectory ( ) ;
if ( ! path . isEmpty ( ) )
{
QDir dir ( path ) ;
dir . removeRecursively ( ) ;
}
2016-10-16 15:26:05 +00:00
path = config - > getInstallerInstalledDirPath ( ) ;
2016-07-27 09:55:31 +00:00
QStringList files = config - > getInstallerRequiredFiles ( ) ;
foreach ( const QString & file , files )
{
QString fullPath = path + " / " + file ;
// delete file
2016-08-14 11:35:46 +00:00
if ( QFile : : exists ( fullPath ) & & ! QFile : : remove ( fullPath ) )
2016-07-27 09:55:31 +00:00
{
# ifdef Q_OS_WIN32
// under Windows, a running executable is locked, so we need to delete it later
MoveFileExW ( qToWide ( QDir : : toNativeSeparators ( fullPath ) ) , NULL , MOVEFILE_DELAY_UNTIL_REBOOT ) ;
# endif
}
}
2016-06-19 19:06:00 +00:00
2016-10-03 07:59:19 +00:00
// delete installer shortcuts
removeShortcut ( config - > getInstallerMenuShortcutFullPath ( ) ) ;
removeShortcut ( config - > getInstallerDesktopShortcutFullPath ( ) ) ;
2016-09-29 18:47:03 +00:00
// delete configuration file
config - > remove ( ) ;
2016-06-26 17:41:33 +00:00
// reset it once it's done
m_removeComponents . installer = false ;
2016-10-09 13:09:54 +00:00
// delete Ryzom directory if all files have been deleted
if ( isDirectoryEmpty ( config - > getInstallationDirectory ( ) , true ) ) QDir ( config - > getInstallationDirectory ( ) ) . removeRecursively ( ) ;
2016-10-03 15:20:43 +00:00
emit success ( 1 ) ;
2016-06-26 17:41:33 +00:00
emit done ( ) ;
}
void COperationDialog : : deleteComponentsDownloadedFiles ( )
{
2016-09-28 10:22:27 +00:00
m_currentOperation = tr ( " Deleting downloaded files... " ) ;
2016-06-26 17:41:33 +00:00
CConfigFile * config = CConfigFile : : getInstance ( ) ;
QString path = config - > getInstallationDirectory ( ) ;
QDir dir ( path ) ;
QStringList filter ;
2016-09-20 19:57:41 +00:00
filter < < " *.log " ;
2016-06-26 17:41:33 +00:00
filter < < " *.7z " ;
filter < < " *.bnp " ;
filter < < " *.zip " ;
filter < < " *.part " ;
2016-09-20 19:57:41 +00:00
filter < < " ryzom_installer_uninstalling_old_client " ;
2016-06-26 17:41:33 +00:00
QStringList files = dir . entryList ( filter , QDir : : Files ) ;
foreach ( const QString & file , files )
{
2016-09-20 19:57:41 +00:00
if ( ! QFile : : remove ( dir . filePath ( file ) ) )
2016-06-26 17:41:33 +00:00
{
qDebug ( ) < < " Unable to delete " < < file ;
}
}
// reset it once it's done
m_removeComponents . downloadedFiles = false ;
2016-10-09 13:09:54 +00:00
// delete Ryzom directory if all files have been deleted
if ( isDirectoryEmpty ( config - > getInstallationDirectory ( ) , true ) ) QDir ( config - > getInstallationDirectory ( ) ) . removeRecursively ( ) ;
2016-10-03 15:20:43 +00:00
emit success ( 1 ) ;
2016-06-04 17:57:50 +00:00
emit done ( ) ;
}
2016-05-16 09:11:40 +00:00
void COperationDialog : : operationPrepare ( )
{
emit prepare ( ) ;
}
void COperationDialog : : operationInit ( qint64 current , qint64 total )
{
emit init ( current , total ) ;
}
void COperationDialog : : operationStart ( )
{
emit start ( ) ;
}
void COperationDialog : : operationStop ( )
{
emit stop ( ) ;
}
void COperationDialog : : operationProgress ( qint64 current , const QString & filename )
{
emit progress ( current , filename ) ;
}
void COperationDialog : : operationSuccess ( qint64 total )
{
emit success ( total ) ;
}
void COperationDialog : : operationFail ( const QString & error )
{
emit fail ( error ) ;
}
bool COperationDialog : : operationShouldStop ( )
{
QMutexLocker locker ( & m_abortingMutex ) ;
return m_aborting ;
}
2016-06-18 17:52:51 +00:00
void COperationDialog : : renamePartFile ( )
{
QString partFile = m_downloader - > getFileFullPath ( ) ;
QString finalFile = partFile ;
finalFile . remove ( " .part " ) ;
if ( partFile ! = finalFile )
{
QFile : : rename ( partFile , finalFile ) ;
}
}
2016-09-14 06:12:49 +00:00
void COperationDialog : : acceptDelayed ( )
{
// wait 500ms before to call accept()
QTimer : : singleShot ( 500 , this , SLOT ( accept ( ) ) ) ;
}
void COperationDialog : : rejectDelayed ( )
{
// wait 500ms before to call reject()
QTimer : : singleShot ( 500 , this , SLOT ( reject ( ) ) ) ;
}