From 59ef213e51158f8b43d08b5ed8e2945e8eea4422 Mon Sep 17 00:00:00 2001 From: mhogomchungu Date: Thu, 26 Dec 2024 20:18:42 +0300 Subject: [PATCH] code improvements --- src/checkforupdates.cpp | 2 +- src/engines.cpp | 4 ++-- src/engines/cryptomator.cpp | 15 ++++++++++++--- src/engines/gocryptfs.cpp | 4 ++-- src/engines/securefs.cpp | 6 +----- src/utility.cpp | 27 ++++++++++++++++++--------- src/utility.h | 18 ++++++++++++++++-- 7 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/checkforupdates.cpp b/src/checkforupdates.cpp index 53fb6a4a..61c68b87 100644 --- a/src/checkforupdates.cpp +++ b/src/checkforupdates.cpp @@ -82,7 +82,7 @@ void checkUpdates::checkIfInstalled() { auto& s = settings::instance() ; - auto m = s.internallyManageBackEnds() && utility::canDownload() ; + auto m = s.internallyManageBackEnds() ; QStringList apps ; diff --git a/src/engines.cpp b/src/engines.cpp index dba2b995..837d5515 100644 --- a/src/engines.cpp +++ b/src/engines.cpp @@ -1103,9 +1103,9 @@ bool engines::engine::windowsCanUnlocInReadWriteMode() const return m_Options.windowsCanUnlockInReadWriteMode ; } -bool engines::engine::updatable( bool s ) const +bool engines::engine::updatable( bool ) const { - return s ; + return false ; } bool engines::engine::isInstalled() const diff --git a/src/engines/cryptomator.cpp b/src/engines/cryptomator.cpp index 183015fc..ec890586 100644 --- a/src/engines/cryptomator.cpp +++ b/src/engines/cryptomator.cpp @@ -98,13 +98,13 @@ bool cryptomator::updatable( bool s ) const { if( utility::platformIsFlatPak() ){ - return true ; + return utility::archInUseIsAnyOf( utility::arch::x64,utility::arch::aarch64 ) ; }else if( s ){ if( utility::platformIsWindows() ){ - return true ; + return utility::archInUse( utility::arch::x64 ) ; }else{ return false ; } @@ -134,7 +134,16 @@ bool cryptomator::onlineArchiveFileName( const QString& e ) const { if( utility::platformIsLinux() ){ - return e.endsWith( "linux-x64.zip" ) ; + if( utility::archInUse( utility::arch::x64 ) ){ + + return e.endsWith( "linux-x64.zip" ) ; + + }else if( utility::archInUse( utility::arch::aarch64 ) ){ + + return e.endsWith( "linux-aarch64.zip" ) ; + }else{ + return false ; + } }else if( utility::platformIsWindows() ){ diff --git a/src/engines/gocryptfs.cpp b/src/engines/gocryptfs.cpp index d1ecdb97..5d3e78cd 100644 --- a/src/engines/gocryptfs.cpp +++ b/src/engines/gocryptfs.cpp @@ -181,9 +181,9 @@ bool gocryptfs::updatable( bool s ) const return false ; - }else if( utility::canDownload() ){ + }else if( utility::platformIsLinux() ){ - return utility::platformIsLinux() ; + return utility::archInUse( utility::arch::x64 ) ; }else{ return false ; } diff --git a/src/engines/securefs.cpp b/src/engines/securefs.cpp index 476a1fbf..b22af5ca 100644 --- a/src/engines/securefs.cpp +++ b/src/engines/securefs.cpp @@ -92,12 +92,8 @@ bool securefs::updatable( bool s ) const if( utility::platformIsFlatPak() ){ return false ; - - }else if( utility::canDownload( utility::arch::x64 ) ){ - - return utility::platformIsLinux() || utility::platformIsWindows() ; }else{ - return false ; + return utility::archInUseIsAnyOf( utility::arch::x64 ) ; } }else{ return false ; diff --git a/src/utility.cpp b/src/utility.cpp index aa74a240..a6dcae1c 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -1739,23 +1739,32 @@ bool utility::copyFile( const QString& s,const QString& d,bool setExePermssion ) return false ; } -bool utility::canDownload( utility::arch arch ) +static QString _currentCpuArch() { #if QT_VERSION < QT_VERSION_CHECK( 5,4,0 ) - return false ; + return {} ; #else - auto m = QSysInfo::currentCpuArchitecture() ; + return QSysInfo::currentCpuArchitecture() ; +#endif +} + +bool utility::archInUse( utility::arch m ) +{ + auto e = _currentCpuArch() ; + + if( m == utility::arch::x64 ){ + + return e == "x86_64"; - if( arch == utility::arch::either ){ + }else if( m == utility::arch::x86 ){ - return m == "x86_64" || m == "i386" ; + return e == "i386" ; - }else if( arch == utility::arch::x64 ){ + }else if( m == utility::arch::aarch64 ){ - return m == "x86_64" ; + return e == "arm64" ; }else{ - return m == "i386" ; + return false ; } -#endif } diff --git a/src/utility.h b/src/utility.h index 8c0037ac..31eb2362 100644 --- a/src/utility.h +++ b/src/utility.h @@ -485,9 +485,23 @@ namespace utility void applicationStarted() ; - enum class arch{ x64,x86,either } ; + enum class arch{ x64,x86,aarch64 } ; - bool canDownload( utility::arch = utility::arch::either ) ; + bool archInUse( utility::arch ) ; + + template< typename ... T > + bool archInUseIsAnyOf( T ... m ) + { + for( const auto& it : { m ... } ){ + + if( utility::archInUse( it ) ){ + + return true ; + } + } + + return false ; + } QString removeOption( const QStringList&,const QString& option ) ; QString removeOption( const QString& commaSeparatedString,const QString& option ) ;