MCPcopy Create free account
hub / github.com/MultiMC/Launcher / loadComponent

Function loadComponent

launcher/minecraft/ComponentUpdateTask.cpp:72–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72static LoadResult loadComponent(ComponentPtr component, Task::Ptr& loadTask, Net::Mode netmode)
73{
74 if(component->m_loaded)
75 {
76 qDebug() << component->getName() << "is already loaded";
77 return LoadResult::LoadedLocal;
78 }
79
80 LoadResult result = LoadResult::Failed;
81 auto customPatchFilename = component->getFilename();
82 if(QFile::exists(customPatchFilename))
83 {
84 // if local file exists...
85
86 // check for uid problems inside...
87 bool fileChanged = false;
88 auto file = ProfileUtils::parseJsonFile(QFileInfo(customPatchFilename), false);
89 if(file->uid != component->m_uid)
90 {
91 file->uid = component->m_uid;
92 fileChanged = true;
93 }
94 if(fileChanged)
95 {
96 // FIXME: @QUALITY do not ignore return value
97 ProfileUtils::saveJsonFile(OneSixVersionFormat::versionFileToJson(file), customPatchFilename);
98 }
99
100 component->m_file = file;
101 component->m_loaded = true;
102 result = LoadResult::LoadedLocal;
103 }
104 else
105 {
106 auto metaVersion = APPLICATION->metadataIndex()->get(component->m_uid, component->m_version);
107 component->m_metaVersion = metaVersion;
108 if(metaVersion->isLoaded())
109 {
110 component->m_loaded = true;
111 result = LoadResult::LoadedLocal;
112 }
113 else
114 {
115 metaVersion->load(netmode);
116 loadTask = metaVersion->getCurrentTask();
117 if(loadTask)
118 result = LoadResult::RequiresRemote;
119 else if (metaVersion->isLoaded())
120 result = LoadResult::LoadedLocal;
121 else
122 result = LoadResult::Failed;
123 }
124 }
125 return result;
126}
127
128// FIXME: dead code. determine if this can still be useful?
129/*

Callers 1

loadComponentsMethod · 0.85

Calls 9

parseJsonFileFunction · 0.85
saveJsonFileFunction · 0.85
getNameMethod · 0.80
getFilenameMethod · 0.80
metadataIndexMethod · 0.80
getMethod · 0.45
isLoadedMethod · 0.45
loadMethod · 0.45
getCurrentTaskMethod · 0.45

Tested by

no test coverage detected