mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-06 03:00:43 +00:00
Added progress bar to migration routine
This commit is contained in:
parent
abd2389772
commit
98811bca15
@ -14,6 +14,7 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <QProgressDialog>
|
||||||
|
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
@ -21,6 +22,9 @@
|
|||||||
#include "SleepLib/profiles.h"
|
#include "SleepLib/profiles.h"
|
||||||
#include "translation.h"
|
#include "translation.h"
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
// Gah! I must add the real darn plugin system one day.
|
// Gah! I must add the real darn plugin system one day.
|
||||||
#include "SleepLib/loader_plugins/prs1_loader.h"
|
#include "SleepLib/loader_plugins/prs1_loader.h"
|
||||||
#include "SleepLib/loader_plugins/cms50_loader.h"
|
#include "SleepLib/loader_plugins/cms50_loader.h"
|
||||||
@ -42,8 +46,27 @@ MainWindow *mainwin = nullptr;
|
|||||||
|
|
||||||
int compareVersion(QString version);
|
int compareVersion(QString version);
|
||||||
|
|
||||||
bool copyRecursively(QString sourceFolder, QString destFolder)
|
int numFilesCopied = 0;
|
||||||
{
|
|
||||||
|
// Count the number of files in this directory and all subdirectories
|
||||||
|
int countRecursively(QString sourceFolder) {
|
||||||
|
QDir sourceDir(sourceFolder);
|
||||||
|
|
||||||
|
if(!sourceDir.exists())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int numFiles = sourceDir.count();
|
||||||
|
|
||||||
|
QStringList dirs = sourceDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
||||||
|
for(int i = 0; i< dirs.count(); i++) {
|
||||||
|
QString srcName = sourceFolder + QDir::separator() + dirs[i];
|
||||||
|
numFiles += countRecursively(srcName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return numFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool copyRecursively(QString sourceFolder, QString destFolder, QProgressDialog& progress) {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
QDir sourceDir(sourceFolder);
|
QDir sourceDir(sourceFolder);
|
||||||
|
|
||||||
@ -59,18 +82,22 @@ bool copyRecursively(QString sourceFolder, QString destFolder)
|
|||||||
QString srcName = sourceFolder + QDir::separator() + files[i];
|
QString srcName = sourceFolder + QDir::separator() + files[i];
|
||||||
QString destName = destFolder + QDir::separator() + files[i];
|
QString destName = destFolder + QDir::separator() + files[i];
|
||||||
success = QFile::copy(srcName, destName);
|
success = QFile::copy(srcName, destName);
|
||||||
|
numFilesCopied++;
|
||||||
|
if ((numFilesCopied % 20) == 1) { // Update progress bar every 20 files
|
||||||
|
progress.setValue(numFilesCopied);
|
||||||
|
QCoreApplication::processEvents();
|
||||||
|
}
|
||||||
if(!success)
|
if(!success)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
files.clear();
|
files.clear();
|
||||||
files = sourceDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
files = sourceDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
||||||
for(int i = 0; i< files.count(); i++)
|
for(int i = 0; i< files.count(); i++) {
|
||||||
{
|
|
||||||
QString srcName = sourceFolder + QDir::separator() + files[i];
|
QString srcName = sourceFolder + QDir::separator() + files[i];
|
||||||
QString destName = destFolder + QDir::separator() + files[i];
|
QString destName = destFolder + QDir::separator() + files[i];
|
||||||
// qDebug() << "Copy from "+srcName+" to "+destName;
|
// qDebug() << "Copy from "+srcName+" to "+destName;
|
||||||
success = copyRecursively(srcName, destName);
|
success = copyRecursively(srcName, destName, progress);
|
||||||
if(!success)
|
if(!success)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -140,6 +167,8 @@ bool migrateFromSH(QString destDir) {
|
|||||||
QString datadir;
|
QString datadir;
|
||||||
bool selectingFolder = true;
|
bool selectingFolder = true;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
// long int startTime, countDone, allDone;
|
||||||
|
|
||||||
if (destDir.isEmpty()) {
|
if (destDir.isEmpty()) {
|
||||||
qDebug() << "Migration path is empty string";
|
qDebug() << "Migration path is empty string";
|
||||||
return success;
|
return success;
|
||||||
@ -173,7 +202,19 @@ bool migrateFromSH(QString destDir) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
success = copyRecursively(datadir, destDir);
|
auto startTime = std::chrono::steady_clock::now();
|
||||||
|
int numFiles = countRecursively(datadir); // count number of files to be copied
|
||||||
|
auto countDone = std::chrono::steady_clock::now();
|
||||||
|
qDebug() << "Number of files to migrate: " << numFiles;
|
||||||
|
|
||||||
|
QProgressDialog progress (QObject::tr("Migrating ") + QString::number(numFiles) + QObject::tr(" files")+"\n"+
|
||||||
|
QObject::tr("from ") + QDir(datadir).dirName() + "\n"+QObject::tr("to ") +
|
||||||
|
QDir(destDir).dirName(), QString(), 0, numFiles, 0, Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
|
||||||
|
progress.setValue(0);
|
||||||
|
progress.setMinimumWidth(300);
|
||||||
|
progress.show();
|
||||||
|
|
||||||
|
success = copyRecursively(datadir, destDir, progress);
|
||||||
if (success) {
|
if (success) {
|
||||||
qDebug() << "Finished copying " + datadir;
|
qDebug() << "Finished copying " + datadir;
|
||||||
}
|
}
|
||||||
@ -186,11 +227,17 @@ bool migrateFromSH(QString destDir) {
|
|||||||
success = process_a_Profile( destDir+"/Profiles/"+names[i] );
|
success = process_a_Profile( destDir+"/Profiles/"+names[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progress.setValue(numFiles);
|
||||||
|
auto allDone = std::chrono::steady_clock::now();
|
||||||
|
auto elapsedCount = std::chrono::duration_cast<std::chrono::microseconds>(countDone - startTime);
|
||||||
|
auto elapsedCopy = std::chrono::duration_cast<std::chrono::microseconds>(allDone - countDone);
|
||||||
|
qDebug() << "Counting files took " << elapsedCount.count() << " microsecs";
|
||||||
|
qDebug() << "Migrating files took " << elapsedCopy.count() << " microsecs";
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) {
|
||||||
{
|
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
XInitThreads();
|
XInitThreads();
|
||||||
#endif
|
#endif
|
||||||
@ -513,7 +560,9 @@ int main(int argc, char *argv[])
|
|||||||
Q_UNUSED(dont_load_profile)
|
Q_UNUSED(dont_load_profile)
|
||||||
|
|
||||||
#ifndef NO_UPDATER
|
#ifndef NO_UPDATER
|
||||||
if (check_updates) { mainwin->CheckForUpdates(); }
|
if (check_updates) {
|
||||||
|
mainwin->CheckForUpdates();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mainwin->SetupGUI();
|
mainwin->SetupGUI();
|
||||||
|
@ -75,7 +75,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(logger, SIGNAL(outputLog(QString)), this, SLOT(logMessage(QString)));
|
connect(logger, SIGNAL(outputLog(QString)), this, SLOT(logMessage(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise oscr app registry stuff
|
// Bring window to top (useful when language is changed) - GTS 3/31/2019
|
||||||
|
this->activateWindow();
|
||||||
|
this->raise();
|
||||||
|
|
||||||
|
// Initialise oscar app registry stuff
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
// Load previous Window geometry
|
// Load previous Window geometry
|
||||||
|
Loading…
Reference in New Issue
Block a user