MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / findCaptionFiles

Function findCaptionFiles

TheForceEngine/TFE_A11y/accessibility.cpp:275–313  ·  view source on GitHub ↗

Get all caption file names from the Captions directories; we will use this to populate the dropdown in the Accessibility settings menu.

Source from the content-addressed store, hash-verified

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 {

Callers 1

findFilesFunction · 0.85

Calls 11

toFileNameFunction · 0.85
getA11ySettingsFunction · 0.85
loadCaptionsFunction · 0.85
addFilesMethod · 0.80
getFilePathsMethod · 0.80
atMethod · 0.80
getPathFunction · 0.50
directoryExitsFunction · 0.50
makeDirectoryFunction · 0.50
mapSystemPathFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected