MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / executeTask

Method executeTask

launcher/InstanceCopyTask.cpp:38–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38void InstanceCopyTask::executeTask()
39{
40 setStatus(tr("Copying instance %1").arg(m_origInstance->name()));
41
42 m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [this] {
43 if (m_useClone) {
44 FS::clone folderClone(m_origInstance->instanceRoot(), m_stagingPath);
45 folderClone.matcher(m_matcher);
46
47 folderClone(true);
48 setProgress(0, folderClone.totalCloned());
49 connect(&folderClone, &FS::clone::fileCloned,
50 [this](QString src, QString dst) { setProgress(m_progress + 1, m_progressTotal); });
51 return folderClone();
52 }
53 if (m_useLinks || m_useHardLinks) {
54 std::unique_ptr<FS::copy> savesCopy;
55 if (m_copySaves) {
56 QFileInfo mcDir(FS::PathCombine(m_stagingPath, "minecraft"));
57 QFileInfo dotMCDir(FS::PathCombine(m_stagingPath, ".minecraft"));
58
59 QString staging_mc_dir;
60 if (dotMCDir.exists() && !mcDir.exists())
61 staging_mc_dir = dotMCDir.filePath();
62 else
63 staging_mc_dir = mcDir.filePath();
64
65 savesCopy = std::make_unique<FS::copy>(FS::PathCombine(m_origInstance->gameRoot(), "saves"),
66 FS::PathCombine(staging_mc_dir, "saves"));
67 (*savesCopy)(true);
68 setProgress(0, savesCopy->totalCopied());
69 connect(savesCopy.get(), &FS::copy::fileCopied, [this](QString src) { setProgress(m_progress + 1, m_progressTotal); });
70 }
71 FS::create_link folderLink(m_origInstance->instanceRoot(), m_stagingPath);
72 int depth = m_linkRecursively ? -1 : 0; // we need to at least link the top level instead of the instance folder
73 folderLink.linkRecursively(true).setMaxDepth(depth).useHardLinks(m_useHardLinks).matcher(m_matcher);
74
75 folderLink(true);
76 setProgress(0, m_progressTotal + folderLink.totalToLink());
77 connect(&folderLink, &FS::create_link::fileLinked,
78 [this](QString src, QString dst) { setProgress(m_progress + 1, m_progressTotal); });
79 bool there_were_errors = false;
80
81 if (!folderLink()) {
82#if defined Q_OS_WIN32
83 if (!m_useHardLinks) {
84 setProgress(0, m_progressTotal);
85 qDebug() << "EXPECTED: Link failure, Windows requires permissions for symlinks";
86
87 qDebug() << "attempting to run with privelage";
88
89 QEventLoop loop;
90 bool got_priv_results = false;
91
92 connect(&folderLink, &FS::create_link::finishedPrivileged, this, [&got_priv_results, &loop](bool gotResults) {
93 if (!gotResults) {
94 qDebug() << "Privileged run exited without results!";
95 }

Callers

nothing calls this directly

Calls 15

runFunction · 0.85
PathCombineFunction · 0.85
instanceRootMethod · 0.80
matcherMethod · 0.80
totalClonedMethod · 0.80
filePathMethod · 0.80
totalCopiedMethod · 0.80
setMaxDepthMethod · 0.80
linkRecursivelyMethod · 0.80
totalToLinkMethod · 0.80
quitMethod · 0.80
getResultsMethod · 0.80

Tested by

no test coverage detected