Get all caption file names from the Captions directories; we will use this to populate the dropdown in the Accessibility settings menu.
| 273 | // Get all caption file names from the Captions directories; we will use this to populate the |
| 274 | // dropdown in the Accessibility settings menu. |
| 275 | void findCaptionFiles() |
| 276 | { |
| 277 | // First we check the User Documents directory for custom subtitle files added by the user. |
| 278 | char docsCaptionsDir[TFE_MAX_PATH]; |
| 279 | const char* docsDir = TFE_Paths::getPath(PATH_USER_DOCUMENTS); |
| 280 | sprintf(docsCaptionsDir, "%sCaptions/", docsDir); |
| 281 | if (!FileUtil::directoryExits(docsCaptionsDir)) |
| 282 | { |
| 283 | FileUtil::makeDirectory(docsCaptionsDir); |
| 284 | } |
| 285 | s_captionFileList.addFiles(docsCaptionsDir, "txt", filterCaptionFile); |
| 286 | |
| 287 | // Then we check the Program directory for subtitle files that shipped with TFE. |
| 288 | char programCaptionsDir[TFE_MAX_PATH]; |
| 289 | const char* programDir = TFE_Paths::getPath(PATH_PROGRAM); |
| 290 | sprintf(programCaptionsDir, "%s", "Captions/"); |
| 291 | if (!TFE_Paths::mapSystemPath(programCaptionsDir)) |
| 292 | sprintf(programCaptionsDir, "%sCaptions/", programDir); |
| 293 | s_captionFileList.addFiles(programCaptionsDir, "txt", filterCaptionFile); |
| 294 | |
| 295 | // Try to load captions for the previously selected language. |
| 296 | string search = toFileName(TFE_Settings::getA11ySettings()->language); |
| 297 | vector<string>* captionFilePaths = s_captionFileList.getFilePaths(); |
| 298 | for (size_t i = 0; i < captionFilePaths->size(); i++) |
| 299 | { |
| 300 | string path = captionFilePaths->at(i); |
| 301 | if (path.find(search) != string::npos) { |
| 302 | loadCaptions(path); |
| 303 | break; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | // If the language didn't load, default to English. |
| 308 | if (s_captionsStatus != CC_LOADED) |
| 309 | { |
| 310 | string fileName = programCaptionsDir + toFileName("en"); |
| 311 | loadCaptions(fileName); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | bool filterCaptionFile(const string fileName) |
| 316 | { |
no test coverage detected