Index: sources/cloudsync/CloudSyncController.cpp =================================================================== diff -u -r6d76149dca70e879f33bf6ed44203d0d06bc523a -r6c6f1f5d466badd9b4fd67be7c907234c342b2a2 --- sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 6d76149dca70e879f33bf6ed44203d0d06bc523a) +++ sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 6c6f1f5d466badd9b4fd67be7c907234c342b2a2) @@ -103,6 +103,9 @@ connect(&_ApplicationController , SIGNAL(didPOSTCloudSync(bool)), this , SLOT( onPOSTCloudSync(bool))); + connect(&_DeviceController , SIGNAL(didCryptSetupMount(bool)), + this , SLOT( onCryptSetupMount(bool))); + connect(&_DeviceController , SIGNAL(didWatchFileChange (const QString &)), this , SLOT( onWatchFileChange (const QString &))); connect(&_MessageDispatcher , SIGNAL(didActionReceive (GuiActionType , const QVariantList &)), @@ -193,10 +196,20 @@ void CloudSyncController::onPOSTCloudSync(bool vPass) { _postPass = vPass; - testReady(); } /*! + * \brief CloudSyncController::onCryptSetupMount + * \details This the handler for the DeviceController::onCryptSetupMount() + */ +void CloudSyncController::onCryptSetupMount(bool vPass) +{ + if ( vPass ) { + testReady(); + } +} + +/*! * \brief CloudSyncController::onWatchFileChange * \details This slot will be called when the Device Controller identifies any changes in the watched files. * \param vFile - watched file @@ -347,9 +360,8 @@ case eError_LogFolder : text = tr( "CS The log folder cannot be created." ) ; break; case eError_LogFileInp : text = tr( "CS Error writing to the input file." ) ; break; case eError_CredentialFile : text = tr( "CS The credentials file does not exist." ) ; break; - case eError_CredentialMake : text = tr( "CS The credentials folder make failed." ) ; break; - case eError_CredentialCopy : text = tr( "CS The credentials file copy failed." ) ; break; - case eError_CredentialRemove: text = tr( "CS The credentials file remove failed." ) ; break; + case eError_CredentialPath : text = tr( "CS The credentials folder is incorrect." ) ; break; + case eError_CredentialCount : text = tr( "CS No credential file name provided." ) ; break; case eError_CredentialEmpty : text = tr( "CS The credentials folder is empty." ) ; break; case eError_TxCodeNoParam : text = tr( "CS No Treatment Code provided." ) ; break; case eError_TxCodeEmpty : text = tr( "CS The provided Treatment Code is empty." ) ; break; @@ -392,9 +404,8 @@ case eError_LogFolder : ; break; case eError_LogFileInp : ; break; case eError_CredentialFile : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_CredentialMake : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_CredentialCopy : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_CredentialRemove: info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_CredentialPath : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_CredentialCount : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; case eError_CredentialEmpty : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; case eError_TxCodeNoParam : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; case eError_TxCodeEmpty : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; @@ -528,11 +539,17 @@ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // writing the message into the buffer. LOG_APPED_UI( vInpBuff ); + if(!QFile::exists(_date_inp_File)){ + Storage::FileHandler::makeFolder(_location); + } if ( ! Storage::FileHandler::write(_date_inp_File, vInpBuff + "\n") ) { error = eError_LogFileInp; args = { _date_inp_File }; ok = false; goto lErr; } return ok; lErr: - toLog(error, args); + // don't send the error back to the CS + // it calls this same function if the error is in this function + // and creates a loop + LOG_DEBUG(toText(error) + " " + toInfo(error, args)); return ok; } @@ -668,8 +685,6 @@ qint32 messageID = UI2CS(static_cast( eMessageID_TxReport )); if ( ! isRegistered() ) { error = eError_NotRegistered ; args = { vFileName }; ok = false; goto lErr; } - - sendCredentialsSend(); // TODO: This has to be removed later, it is a workaround for Cloud issue, during our talk with KBM. sendUIBuff(makeUIBuff( messageID , { vFileName } )); return; @@ -692,7 +707,6 @@ case eMessageID_DeviceInfo : ok = sendDeviceInfo ( ); break; case eMessageID_CredentialsSave : ok = sendCredentialsSave( vMessage ); break; - case eMessageID_CredentialsSend : ok = sendCredentialsSend( ); break; case eMessageID_ResetFactory : ok = sendResetFactory ( ); break; case eMessageID_DeviceState : ok = sendDeviceState ( ); break; @@ -726,7 +740,6 @@ bool CloudSyncController::sendDeviceState() { bool ok = false; - sendCredentialsSend(); // TODO: This has to be removed later, it is a workaround for Cloud issue, during our talk with KBM. ok = sendUIHistory(eMessageID_DeviceState); return ok; } @@ -764,37 +777,24 @@ /*! * \brief CloudSyncController::sendCredentialsSave - * \details saves the credentials files which their location have been sent. + * \details validates the credentials files which their sent location. * \param vMessage - the message received from CloudSync - * \return true on successfully saving the files. + * \return true on successfully validate the files. */ bool CloudSyncController::sendCredentialsSave( const Message &vMessage) { bool ok = true; QString destination = QString(Storage::CloudSync_Base_Path_Name) + Storage::CloudSync_Credentials_Folder_Name; - // create the destination folder if does not exist. - if ( ! Storage::FileHandler::makeFolder( destination ) ) { toLog(eError_CredentialMake , { }); ok = false; goto lOut; } - // file existence has been separated from copy remove to avoid partial copy. + if ( ! vMessage.params.count() ) { toLog(eError_CredentialCount , { }); ok = false; goto lOut; } for ( auto fileName : vMessage.params ) { - if ( ! QFileInfo::exists(fileName) ) { toLog(eError_CredentialFile , {fileName }); ok = false; goto lOut; } + QFileInfo fileinfo(fileName); + if ( ! fileinfo.exists() ) { toLog(eError_CredentialFile , {fileName }); ok = false; goto lOut; } + if ( fileinfo.absolutePath() != destination ) { toLog(eError_CredentialPath , {fileName }); ok = false; goto lOut; } } + // no need to call for isRegistered() function, we are testing for the count, location, and existence. - if ( ok ) { - for ( auto sourceFile : vMessage.params ) { - QString fileName = QFileInfo(sourceFile).fileName(); - // NOTE: If a file with the name newName already exists, copy() returns false (i.e., QFile will not overwrite it). - // For the current scenario it is ideal, since that folder will turn RO after the successful registration and copying the files and reboot. - if ( ! QFile::copy (sourceFile, destination + fileName) ) { toLog(eError_CredentialCopy , {fileName }); ok = false; goto lOut; } - } - // if all the copies are successful then remove them. - for ( auto sourceFile : vMessage.params ) { - QString fileName = QFileInfo(sourceFile).fileName(); - if ( ! QFile::remove(sourceFile ) ) { toLog(eError_CredentialRemove , {fileName }); ok = false; goto lOut; } - } - } - lOut: if ( ok ) sendCredentialsResponse(); emit didRegisterDone(ok); @@ -803,27 +803,6 @@ } /*! - * \brief CloudSyncController::sendSaveCredentials - * \details saves the credentials files which their location have been sent. - * \param vMessage - the message received from CloudSync - * \return true on successfully saving the files. - */ -bool CloudSyncController::sendCredentialsSend() -{ - bool ok = true; - qint32 messageID = UI2CS(eMessageID_CredentialsSend); - QString source = QString(Storage::CloudSync_Base_Path_Name) + Storage::CloudSync_Credentials_Folder_Name; - QString destination = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/" + Storage::CloudSync_Credentials_Folder_Name; - - if ( Storage::FileHandler::copyFolder(source, destination) != 0 ) { toLog(eError_CredentialCopy , {destination }); ok = false; goto lOut; } - ok = sendUIBuff({QString("%1").arg( messageID ), "1", destination}); - -lOut: - emit didRegisterStart(ok); - return ok; -} - -/*! * \brief CloudSyncController::sendCredentialsResponse * \return send the confirmation of the credential save on the device from UI to CS to let CS know when to delete them. */ @@ -854,7 +833,7 @@ if ( mTxCode.isEmpty() ) { toLog(eError_TxCodeEmpty , {}); ok = false; goto lOut; } emit didTxCodeReceive ( mTxCode ); - qDebug() << " ---------- " << mTxCode; + //DEBUG qDebug() << " ---------- " << mTxCode; lOut: return ok;