From e269b1d6d4cf42815bea157b931c79a8f91d18a4 Mon Sep 17 00:00:00 2001 From: woblight Date: Sun, 22 Jul 2018 16:36:11 +0200 Subject: [PATCH] Uninstall before update --- .gitlab-ci.yml | 6 ++++-- CI.mk | 12 ++++++++++-- control.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b31d874..ee88d6d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,10 +7,11 @@ Linux_x64: stage: build script: - zypper -q install -y libgit2-devel make gcc gcc-c++ libQt5Concurrent-devel libQt5Core-devel libQt5Gui-devel libQt5QuickControls2-devel libqt5-qtbase-devel libqt5-qtdeclarative-devel - - make -f CI.mk build + - make -f CI.mk linuxdeploy + - make -f CI.mk finalize artifacts: paths: - - GitAddonsManager/GitAddonsManager + - GitAddonsManager name: "GitAddonsManager_Linux_x64-$CI_COMMIT_SHA" Win32: @@ -24,6 +25,7 @@ Win32: script: - zypper -q install -y wine-staging wine-staging-32bit wget make p7zip tar - make -f CI.mk windeploy + - make -f CI.mk finalize artifacts: paths: - GitAddonsManager diff --git a/CI.mk b/CI.mk index a047ac2..a99f330 100644 --- a/CI.mk +++ b/CI.mk @@ -10,9 +10,17 @@ WINEPATH=WINEPATH='C:\Program Files (x86)\CMake\bin;$(shell $(winepath) -w "$(pw qmake_opts="QMAKE_INCDIR+=Z:$(pwd)/libgit2-0.27.2/include Z:$(pwd)/quazip/quazip" "QMAKE_LIBDIR+=Z:$(pwd)/libgit2-0.27.2/build/ Z:$(pwd)/quazip/build/release Z:$(pwd)/libz/build" -spec win32-g++ LIBS+=-lquazip qmake=$(wine) $(pwd)/Qt/5.11.1/mingw53_32/bin/qmake.exe -.PHONY: build winbuild windeploy +.PHONY: build winbuild windeploy linuxdeploy finalize + +finalize: + cd GitAddonsManager && echo "# DO NOT EDIT" > .installedFiles && find ! -path . >> .installedFiles + build: - mkdir -p GitAddonsManager && cd GitAddonsManager && qmake-qt5 .. -spec linux-g++ DEFINES+='GAM_BUILD_NAME=\\\"Linux_x64\\\"' LIBS+=-lquazip5 INCLUDEPATH+=/usr/include/quazip5 && make + mkdir -p build && cd build && qmake-qt5 .. -spec linux-g++ DEFINES+='GAM_BUILD_NAME=\\\"Linux_x64\\\"' LIBS+=-lquazip5 INCLUDEPATH+=/usr/include/quazip5 && make + +linuxdeploy: build + mkdir GitAddonsManager + cp build/GitAddonsManager -f GitAddonsManager/GitAddonsManager cmake-3.12.0-rc3-win32-x86.msi: wget https://cmake.org/files/v3.12/cmake-3.12.0-rc3-win32-x86.msi diff --git a/control.cpp b/control.cpp index 1747771..2053c4a 100644 --- a/control.cpp +++ b/control.cpp @@ -187,6 +187,34 @@ void Control::completeUpdate(const QString &path) QDir root(QApplication::applicationDirPath()); QDir newRoot(path); if (!newRoot.mkpath(newRoot.absolutePath())) return false; + QFile oldFilesList(newRoot.absoluteFilePath(".installedFiles")); + if (oldFilesList.exists()) { + oldFilesList.open(QFile::ReadOnly); + QString line; + QStringList oldFiles; + QStringList oldDirs; + while (!(line = oldFilesList.readLine()).isEmpty()) { + if (line.startsWith('#') || line.startsWith('\n')) continue; + oldFiles << line.chopped(1); + } + oldFilesList.close(); + setTotal(oldFiles.size()); + int count = 0; + foreach (const QString &file, oldFiles) { + QFileInfo info(newRoot.absoluteFilePath(file)); + if (info.exists() && (info.isFile() || info.isSymLink())) { + newRoot.remove(file); + setProgress(++count); + } + else if (info.isDir()) + oldDirs << file; + } + for (auto i = oldDirs.rbegin(); i != oldDirs.rend(); i++) + newRoot.rmdir(*i); + + setProgress(0); + setTotal(-1); + } walkFoldersIf({root.absolutePath()},[&newRoot, &files, &root, &oldFiles](const QFileInfo &info){ QFileInfo dest(newRoot.absoluteFilePath(root.relativeFilePath(info.absoluteFilePath()))); files << info.absoluteFilePath(); @@ -200,6 +228,7 @@ void Control::completeUpdate(const QString &path) return !dest.exists() ? 1 : dest.isDir() && info.isDir() && !info.isSymLink() && !dest.isSymLink() ? -1 : 1; }); setTotal(files.size() + oldFiles.size()); + qDebug() << oldFiles.size(); int count = 0; bool success = true; foreach (auto file, oldFiles) {