Skip to content

Commit

Permalink
improve startup time on first restart after internal updating
Browse files Browse the repository at this point in the history
  • Loading branch information
mhogomchungu committed Sep 6, 2024
1 parent 49b4e74 commit 2cbf683
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
11 changes: 10 additions & 1 deletion src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,13 @@ QSettings& settings::bk()
void settings::init_done()
{
utils::qthread::run( this,&settings::clearFlatPakTemps ) ;

const auto& m = m_options.pathToOldUpdatedVersion() ;

if( !m.isEmpty() ){

utils::qthread::run( [ & ](){ QDir( m ).removeRecursively() ; } ) ;
}
}

void settings::setTabNumber( int s )
Expand Down Expand Up @@ -500,7 +507,7 @@ const QString& settings::windowsOnly3rdPartyBinPath()

const QString& settings::windowsOnlyExeBinPath()
{
return m_options.m_exePath ;
return m_options.windowsOnlyExePath() ;
}

const QString& settings::windowsOnlyDefaultPortableVersionDownloadFolder()
Expand Down Expand Up @@ -1135,6 +1142,8 @@ settings::options::options( const utility::cliArguments& args,const QString& app

if( args.runningUpdated() ){

m_pathToOldUpdatedVersion = args.pathToOldUpdatedVersion() ;

m_dataPath = args.dataPath() ;

m_defaultPortableVersionDownloadFolder = args.originalPath() + "/Downloads" ;
Expand Down
11 changes: 9 additions & 2 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ class settings

QString downloadLocation() ;

struct options
class options
{
public:
options( const utility::cliArguments&,const QString& ) ;

const QString& dataPath() const
Expand All @@ -348,7 +349,7 @@ class settings
{
return m_exe3PartyBinPath ;
}
const QString windowsOnlyExePath() const
const QString& windowsOnlyExePath() const
{
return m_exePath ;
}
Expand All @@ -360,10 +361,16 @@ class settings
{
return m_portableVersion ;
}
const QString& pathToOldUpdatedVersion() const
{
return m_pathToOldUpdatedVersion ;
}
private:
QString m_dataPath ;
QString m_exePath ;
QString m_exe3PartyBinPath ;
QString m_defaultPortableVersionDownloadFolder ;
QString m_pathToOldUpdatedVersion ;
bool m_portableVersion ;
} ;

Expand Down
48 changes: 37 additions & 11 deletions src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1573,40 +1573,54 @@ bool utility::startedUpdatedVersion( settings& s,const utility::cliArguments& ca

auto ew = cpath.endsWith( "/" ) ;

const auto m = ew ? cpath + "update_new" : cpath + "/update_new" ;
const auto mm = ew ? cpath + "update" : cpath + "/update" ;
const auto update_new = ew ? cpath + "update_new" : cpath + "/update_new" ;
const auto update = ew ? cpath + "update" : cpath + "/update" ;

if( QFile::exists( m ) ){
QString updated_old ;

QDir dir( mm ) ;
if( QFile::exists( update_new ) ){

dir.removeRecursively() ;
dir.rename( m,mm ) ;
QDir dir ;

if( QFile::exists( update ) ){

updated_old = update + ".old" ;

if( QFile::exists( updated_old ) ){

QDir( updated_old ).removeRecursively() ;
}

dir.rename( update,updated_old ) ;
}

dir.rename( update_new,update ) ;
}

QString exePath = mm + "/media-downloader.exe" ;
QString exePath = update + "/media-downloader.exe" ;

if( QFile::exists( exePath ) && !cargs.runningUpdated() ){

auto env = QProcessEnvironment::systemEnvironment() ;

auto exeDirPath = utility::windowsApplicationDirPath() ;

if( !QFile::exists( mm + "/platforms" ) ){
if( !QFile::exists( update + "/platforms" ) ){

env.insert( "PATH",exeDirPath + ";" + env.value( "PATH" ) ) ;
env.insert( "QT_PLUGIN_PATH",exeDirPath ) ;
}

util::version uv = _get_process_version( mm,exePath,env ) ;
util::version uv = _get_process_version( update,exePath,env ) ;

util::version cv = utility::runningVersionOfMediaDownloader() ;

if( uv.valid() ){

if( cv < uv ){

auto args = cargs.arguments( cpath,exeDirPath,s.portableVersion() ) ;
auto e = s.portableVersion() ;
auto args = cargs.arguments( cpath,exeDirPath,updated_old,e ) ;

QProcess exe ;

Expand All @@ -1616,7 +1630,7 @@ bool utility::startedUpdatedVersion( settings& s,const utility::cliArguments& ca

return _start_updated( exe ) ;
}else{
QDir( mm ).removeRecursively() ;
QDir( update ).removeRecursively() ;
}
}
}
Expand Down Expand Up @@ -1906,6 +1920,11 @@ QString utility::cliArguments::originalVersion() const
return this->value( "--running-version" ) ;
}

QString utility::cliArguments::pathToOldUpdatedVersion() const
{
return this->value( "--path-to-old-updated-version" ) ;
}

QString utility::cliArguments::value( const char * m ) const
{
for( auto it = m_args.begin() ; it != m_args.end() ; it++ ){
Expand All @@ -1926,6 +1945,7 @@ QString utility::cliArguments::value( const char * m ) const

QStringList utility::cliArguments::arguments( const QString& cpath,
const QString& exeDirPath,
const QString& oldVersionPath,
bool portableVersion ) const
{
auto args = m_args ;
Expand All @@ -1945,6 +1965,12 @@ QStringList utility::cliArguments::arguments( const QString& cpath,
args.append( "--portable" ) ;
}

if( !oldVersionPath.isEmpty() ){

args.append( "--path-to-old-updated-version" ) ;
args.append( oldVersionPath ) ;
}

args.append( "--exe-org-path" ) ;
args.append( exeDirPath ) ;

Expand Down
3 changes: 2 additions & 1 deletion src/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,9 @@ namespace utility
QString dataPath() const ;
QString originalPath() const ;
QString originalVersion() const ;
QString pathToOldUpdatedVersion() const ;
QString value( const char * ) const ;
QStringList arguments( const QString&,const QString&,bool ) const ;
QStringList arguments( const QString&,const QString&,const QString&,bool ) const ;
const QStringList& arguments() const ;
private:
QStringList m_args ;
Expand Down

0 comments on commit 2cbf683

Please sign in to comment.