| 159 | } |
| 160 | |
| 161 | const 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) |
no test coverage detected