MCPcopy Create free account
hub / github.com/cemu-project/Cemu / UpdateThread

Method UpdateThread

src/gui/DownloadGraphicPacksWindow.cpp:111–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111void DownloadGraphicPacksWindow::UpdateThread()
112{
113 // get github url
114 std::string githubAPIUrl;
115 curlDownloadFileState_t tempDownloadState;
116 std::string queryUrl("https://cemu.info/api2/query_graphicpack_url.php?");
117 char temp[64];
118 sprintf(temp, "version=%d.%d.%d", EMULATOR_VERSION_MAJOR, EMULATOR_VERSION_MINOR, EMULATOR_VERSION_PATCH);
119 queryUrl.append(temp);
120 queryUrl.append("&");
121 sprintf(temp, "t=%u", (uint32)std::chrono::seconds(std::time(NULL)).count()); // add a dynamic part to the url to bypass overly aggressive caching (like some proxies do)
122 queryUrl.append(temp);
123 if (curlDownloadFile(queryUrl.c_str(), &tempDownloadState) && boost::starts_with((const char*)tempDownloadState.fileData.data(), "http"))
124 {
125 // convert downloaded data to url string
126 githubAPIUrl.assign(tempDownloadState.fileData.cbegin(), tempDownloadState.fileData.cend());
127 }
128 else
129 {
130 // cemu api request failed, use hardcoded github url
131 cemuLog_log(LogType::Force, "Graphic pack update request failed or returned invalid URL. Using default repository URL instead");
132 githubAPIUrl = "https://api.github.com/repos/cemu-project/cemu_graphic_packs/releases/latest";
133 }
134 // github API request
135 if (curlDownloadFile(githubAPIUrl.c_str(), &tempDownloadState) == false)
136 {
137 wxMessageBox( _("Error"), _(L"Failed to connect to server"), wxOK | wxCENTRE | wxICON_ERROR, this);
138 m_threadState = ThreadError;
139 return;
140 }
141 // parse json result
142 rapidjson::Document d;
143 d.Parse((const char*)tempDownloadState.fileData.data(), tempDownloadState.fileData.size());
144 if (d.HasParseError())
145 {
146 m_threadState = ThreadError;
147 return;
148 }
149 auto& jsonName = d["name"];
150 if (jsonName.IsString() == false)
151 {
152 m_threadState = ThreadError;
153 return;
154 }
155 const char* assetName = jsonName.GetString(); // name includes version
156 if( d.IsObject() == false)
157 {
158 m_threadState = ThreadError;
159 return;
160 }
161 auto& jsonAssets = d["assets"];
162 if (jsonAssets.IsArray() == false || jsonAssets.GetArray().Size() == 0)
163 {
164 m_threadState = ThreadError;
165 return;
166 }
167 auto& jsonAsset0 = jsonAssets.GetArray()[0];
168 if (jsonAsset0.IsObject() == false)

Callers

nothing calls this directly

Calls 15

starts_withFunction · 0.85
cemuLog_logFunction · 0.50
appendMethod · 0.45
countMethod · 0.45
c_strMethod · 0.45
dataMethod · 0.45
assignMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45

Tested by

no test coverage detected