2016-10-03 04:25:54 +05:30
|
|
|
#include "InstanceCopyTask.h"
|
|
|
|
#include "settings/INISettingsObject.h"
|
|
|
|
#include "FileSystem.h"
|
|
|
|
#include "NullInstance.h"
|
|
|
|
#include "pathmatcher/RegexpMatcher.h"
|
2016-10-26 21:42:33 +05:30
|
|
|
#include <QtConcurrentRun>
|
2016-10-03 04:25:54 +05:30
|
|
|
|
2022-10-23 08:34:36 +05:30
|
|
|
InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, const InstanceCopyPrefs& prefs)
|
2016-10-03 04:25:54 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
m_origInstance = origInstance;
|
2022-10-29 10:25:33 +05:30
|
|
|
m_keepPlaytime = prefs.isKeepPlaytimeEnabled();
|
2018-07-15 18:21:05 +05:30
|
|
|
|
2022-10-26 09:50:36 +05:30
|
|
|
QString filters = prefs.getSelectedFiltersAsRegex();
|
|
|
|
if (!filters.isEmpty())
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
2022-10-26 09:50:36 +05:30
|
|
|
// Set regex filter:
|
|
|
|
// FIXME: get this from the original instance type...
|
|
|
|
auto matcherReal = new RegexpMatcher(filters);
|
|
|
|
matcherReal->caseSensitive(false);
|
|
|
|
m_matcher.reset(matcherReal);
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
2016-12-09 02:28:31 +05:30
|
|
|
}
|
2016-10-03 04:25:54 +05:30
|
|
|
|
2016-12-09 02:28:31 +05:30
|
|
|
void InstanceCopyTask::executeTask()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
setStatus(tr("Copying instance %1").arg(m_origInstance->name()));
|
2017-09-06 03:08:17 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath);
|
2022-10-23 02:55:14 +05:30
|
|
|
folderCopy.followSymlinks(false).matcher(m_matcher.get());
|
2016-10-26 21:42:33 +05:30
|
|
|
|
2022-10-23 03:06:47 +05:30
|
|
|
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [&folderCopy]{
|
|
|
|
return folderCopy();
|
|
|
|
});
|
2018-07-15 18:21:05 +05:30
|
|
|
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::finished, this, &InstanceCopyTask::copyFinished);
|
|
|
|
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::canceled, this, &InstanceCopyTask::copyAborted);
|
|
|
|
m_copyFutureWatcher.setFuture(m_copyFuture);
|
2016-10-26 21:42:33 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceCopyTask::copyFinished()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
auto successful = m_copyFuture.result();
|
|
|
|
if(!successful)
|
|
|
|
{
|
|
|
|
emitFailed(tr("Instance folder copy failed."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// FIXME: shouldn't this be able to report errors?
|
|
|
|
auto instanceSettings = std::make_shared<INISettingsObject>(FS::PathCombine(m_stagingPath, "instance.cfg"));
|
|
|
|
|
|
|
|
InstancePtr inst(new NullInstance(m_globalSettings, instanceSettings, m_stagingPath));
|
2022-07-15 00:43:23 +05:30
|
|
|
inst->setName(name());
|
2018-07-15 18:21:05 +05:30
|
|
|
inst->setIconKey(m_instIcon);
|
2020-01-09 20:01:32 +05:30
|
|
|
if(!m_keepPlaytime) {
|
|
|
|
inst->resetTimePlayed();
|
|
|
|
}
|
2018-07-15 18:21:05 +05:30
|
|
|
emitSucceeded();
|
2016-10-03 04:25:54 +05:30
|
|
|
}
|
2016-10-26 21:42:33 +05:30
|
|
|
|
|
|
|
void InstanceCopyTask::copyAborted()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
emitFailed(tr("Instance folder copy has been aborted."));
|
|
|
|
return;
|
2016-10-26 21:42:33 +05:30
|
|
|
}
|