updated portable update

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-09-28 21:24:31 +03:00
parent 606c12ffeb
commit 742384909f
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318

View File

@ -27,20 +27,20 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <QAccessible>
#include <QCommandLineParser>
#include <QNetworkReply>
#include <QDebug> #include <QDebug>
#include <QAccessible>
#include <QCommandLineParser>
#include <QFileInfo>
#include <QMessageBox> #include <QMessageBox>
#include <QNetworkProxy> #include <QNetworkProxy>
#include <QNetworkReply>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QProcess> #include <QProcess>
#include <QProgressDialog>
#include <memory> #include <memory>
#include <sys.h> #include <sys.h>
#include <QProgressDialog>
#if defined Q_OS_WIN32 #if defined Q_OS_WIN32
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
@ -660,28 +660,42 @@ void PrismUpdaterApp::moveAndFinishUpdate(QDir target)
bool error = false; bool error = false;
QProgressDialog progress(tr("Backing up install at %1").arg(m_rootPath), "", 0, file_list.length()); QProgressDialog progress(tr("Installing from %1").arg(m_rootPath), "", 0, file_list.length());
progress.setCancelButton(nullptr); progress.setCancelButton(nullptr);
progress.setMinimumWidth(400); progress.setMinimumWidth(400);
progress.adjustSize(); progress.adjustSize();
progress.show(); progress.show();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
logUpdate(tr("Installing from %1").arg(m_rootPath));
auto copy = [this, app_dir, target](QString to_install_file) {
auto rel_path = app_dir.relativeFilePath(to_install_file);
auto install_path = FS::PathCombine(target.absolutePath(), rel_path);
logUpdate(tr("Installing %1 from %2").arg(install_path).arg(to_install_file));
FS::ensureFilePathExists(install_path);
auto result = FS::copy(to_install_file, install_path).overwrite(true)();
if (!result) {
logUpdate(tr("Failed copy %1 to %2").arg(to_install_file).arg(install_path));
return true;
}
return false;
};
int i = 0; int i = 0;
for (auto glob : file_list) { for (auto glob : file_list) {
QDirIterator iter(m_rootPath, QStringList({ glob }), QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); QDirIterator iter(m_rootPath, QStringList({ glob }), QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
progress.setValue(i); progress.setValue(i);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
while (iter.hasNext()) { if (!iter.hasNext() && !glob.isEmpty()) {
auto to_install_file = iter.next(); if (auto file_info = QFileInfo(FS::PathCombine(m_rootPath, glob)); file_info.exists()) {
auto rel_path = app_dir.relativeFilePath(to_install_file); error |= copy(file_info.absoluteFilePath());
auto install_path = FS::PathCombine(target.absolutePath(), rel_path); } else {
logUpdate(tr("Installing %1 from %2").arg(install_path).arg(to_install_file)); logUpdate(tr("File doesn't exist, ignoring: %1").arg(FS::PathCombine(m_rootPath, glob)));
FS::ensureFilePathExists(install_path); }
auto result = FS::copy(to_install_file, install_path).overwrite(true)(); } else {
if (!result) { while (iter.hasNext()) {
error = true; error |= copy(iter.next());
logUpdate(tr("Failed copy %1 to %2").arg(to_install_file).arg(install_path));
} }
} }
i++; i++;
@ -1124,23 +1138,37 @@ void PrismUpdaterApp::backupAppDir()
progress.adjustSize(); progress.adjustSize();
progress.show(); progress.show();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
logUpdate(tr("Backing up install at %1").arg(m_rootPath));
auto copy = [this, app_dir, backup_dir](QString to_bak_file) {
auto rel_path = app_dir.relativeFilePath(to_bak_file);
auto bak_path = FS::PathCombine(backup_dir, rel_path);
logUpdate(tr("Backing up and then removing %1").arg(to_bak_file));
FS::ensureFilePathExists(bak_path);
auto result = FS::copy(to_bak_file, bak_path).overwrite(true)();
if (!result) {
logUpdate(tr("Failed to backup %1 to %2").arg(to_bak_file).arg(bak_path));
} else {
if (!FS::deletePath(to_bak_file))
logUpdate(tr("Failed to remove %1").arg(to_bak_file));
}
};
int i = 0; int i = 0;
for (auto glob : file_list) { for (auto glob : file_list) {
QDirIterator iter(app_dir.absolutePath(), QStringList({ glob }), QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); QDirIterator iter(app_dir.absolutePath(), QStringList({ glob }), QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
progress.setValue(i); progress.setValue(i);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
while (iter.hasNext()) { if (!iter.hasNext() && !glob.isEmpty()) {
auto to_bak_file = iter.next(); if (auto file_info = QFileInfo(FS::PathCombine(m_rootPath, glob)); file_info.exists()) {
auto rel_path = app_dir.relativeFilePath(to_bak_file); copy(file_info.absoluteFilePath());
auto bak_path = FS::PathCombine(backup_dir, rel_path);
logUpdate(tr("Backing up and then removing %1").arg(to_bak_file));
FS::ensureFilePathExists(bak_path);
auto result = FS::copy(to_bak_file, bak_path).overwrite(true)();
if (!result) {
logUpdate(tr("Failed to backup %1 to %2").arg(to_bak_file).arg(bak_path));
} else { } else {
if (!FS::deletePath(to_bak_file)) logUpdate(tr("File doesn't exist, ignoring: %1").arg(FS::PathCombine(m_rootPath, glob)));
logUpdate(tr("Failed to remove %1").arg(to_bak_file)); }
} else {
while (iter.hasNext()) {
copy(iter.next());
} }
} }
i++; i++;