diff --git a/src/settings.cpp b/src/settings.cpp index 95976056..aaf23978 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -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 ) @@ -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() @@ -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" ; diff --git a/src/settings.h b/src/settings.h index 4d4febe3..9d320c02 100644 --- a/src/settings.h +++ b/src/settings.h @@ -336,8 +336,9 @@ class settings QString downloadLocation() ; - struct options + class options { + public: options( const utility::cliArguments&,const QString& ) ; const QString& dataPath() const @@ -348,7 +349,7 @@ class settings { return m_exe3PartyBinPath ; } - const QString windowsOnlyExePath() const + const QString& windowsOnlyExePath() const { return m_exePath ; } @@ -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 ; } ; diff --git a/src/utility.cpp b/src/utility.cpp index 565f9640..77f33b4a 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -1573,18 +1573,31 @@ 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() ){ @@ -1592,13 +1605,13 @@ bool utility::startedUpdatedVersion( settings& s,const utility::cliArguments& ca 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() ; @@ -1606,7 +1619,8 @@ bool utility::startedUpdatedVersion( settings& s,const utility::cliArguments& ca 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 ; @@ -1616,7 +1630,7 @@ bool utility::startedUpdatedVersion( settings& s,const utility::cliArguments& ca return _start_updated( exe ) ; }else{ - QDir( mm ).removeRecursively() ; + QDir( update ).removeRecursively() ; } } } @@ -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++ ){ @@ -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 ; @@ -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 ) ; diff --git a/src/utility.h b/src/utility.h index 7b792ad4..883948c3 100644 --- a/src/utility.h +++ b/src/utility.h @@ -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 ;