MCPcopy Create free account
hub / github.com/ddnet/ddnet / InitAndroid

Function InitAndroid

src/android/android_main.cpp:161–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161const char *InitAndroid()
162{
163 // Change current working directory to our external storage location
164 const char *pPath = SDL_AndroidGetExternalStoragePath();
165 if(pPath == nullptr)
166 {
167 return "The external storage is not available.";
168 }
169 if(fs_chdir(pPath) != 0)
170 {
171 return "Failed to change current directory to external storage.";
172 }
173 log_info("android", "Changed current directory to '%s'", pPath);
174
175 if(fs_makedir("data") != 0 || fs_makedir("user") != 0)
176 {
177 return "Failed to create 'data' and 'user' directories in external storage.";
178 }
179
180 if(EqualIntegrityFiles(INTEGRITY_INDEX, INTEGRITY_INDEX_SAVE))
181 {
182 return nullptr;
183 }
184
185 if(!UnpackAsset(INTEGRITY_INDEX))
186 {
187 return "Failed to unpack the integrity index file. Consider reinstalling the app.";
188 }
189
190 std::vector<CIntegrityFileLine> vIntegrityLines = ReadIntegrityFile(INTEGRITY_INDEX);
191 if(vIntegrityLines.empty())
192 {
193 return "Failed to load the integrity index file. Consider reinstalling the app.";
194 }
195
196 std::vector<CIntegrityFileLine> vIntegritySaveLines = ReadIntegrityFile(INTEGRITY_INDEX_SAVE);
197
198 // The remaining lines of each integrity file list all assets and their hashes
199 for(size_t i = 1; i < vIntegrityLines.size(); ++i)
200 {
201 const CIntegrityFileLine &IntegrityLine = vIntegrityLines[i];
202
203 // Check if the asset is unchanged from the last unpacking
204 const auto IntegritySaveLine = std::find_if(vIntegritySaveLines.begin(), vIntegritySaveLines.end(), [&](const CIntegrityFileLine &Line) {
205 return str_comp(Line.m_aFilename, IntegrityLine.m_aFilename) == 0;
206 });
207 if(IntegritySaveLine != vIntegritySaveLines.end() && IntegritySaveLine->m_Sha256 == IntegrityLine.m_Sha256)
208 {
209 continue;
210 }
211
212 if(fs_makedir_rec_for(IntegrityLine.m_aFilename) != 0 || !UnpackAsset(IntegrityLine.m_aFilename))
213 {
214 return "Failed to unpack game assets, consider reinstalling the app.";
215 }
216 }
217
218 for(size_t i = 1; i < vIntegritySaveLines.size(); ++i)

Callers 1

mainFunction · 0.85

Calls 11

fs_chdirFunction · 0.85
fs_makedirFunction · 0.85
EqualIntegrityFilesFunction · 0.85
UnpackAssetFunction · 0.85
ReadIntegrityFileFunction · 0.85
str_compFunction · 0.85
fs_makedir_rec_forFunction · 0.85
fs_removeFunction · 0.85
fs_renameFunction · 0.85
beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected