MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / executeTask

Method executeTask

launcher/InstanceCopyTask.cpp:39–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected