static void BuildFileList0(const TCHAR *config_dir, bool warn_duplicates) { WIN32_FIND_DATA find_obj; HANDLE find_handle; TCHAR find_string[MAX_PATH]; TCHAR subdir_table[MAX_CONFIG_SUBDIRS][MAX_PATH]; TCHAR fullpath[MAX_PATH]; int subdirs = 0; int i; _sntprintf_0(find_string, _T("%s\\*"), config_dir); find_handle = FindFirstFile(find_string, &find_obj); if (find_handle == INVALID_HANDLE_VALUE) return; /* Loop over each config file in main config dir */ do { if (o.num_configs >= MAX_CONFIGS) { ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); break; } match_t match_type = match(&find_obj, o.ext_string); if (match_type == match_file) { _sntprintf_0(fullpath, _T("%s\\%s"), config_dir, find_obj.cFileName); if (ConfigAlreadyExists(find_obj.cFileName)) { if (warn_duplicates) ShowLocalizedMsg(IDS_ERR_CONFIG_EXIST, find_obj.cFileName); continue; } if (CheckReadAccess (fullpath)) AddConfigFileToList(o.num_configs++, find_obj.cFileName, config_dir); } else if (match_type == match_dir) { if (_tcsncmp(find_obj.cFileName, _T("."), _tcslen(find_obj.cFileName)) != 0 && _tcsncmp(find_obj.cFileName, _T(".."), _tcslen(find_obj.cFileName)) != 0 && subdirs < MAX_CONFIG_SUBDIRS) { /* Add dir to dir_table */ _sntprintf_0(subdir_table[subdirs], _T("%s\\%s"), config_dir, find_obj.cFileName); subdirs++; } } } while (FindNextFile(find_handle, &find_obj)); FindClose(find_handle); /* Loop over each config file in every subdir */ for (i = 0; i < subdirs; ++i) { _sntprintf_0(find_string, _T("%s\\*"), subdir_table[i]); find_handle = FindFirstFile (find_string, &find_obj); if (find_handle == INVALID_HANDLE_VALUE) continue; do { if (o.num_configs >= MAX_CONFIGS) { ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); FindClose(find_handle); return; } /* does file have the correct type and extension? */ if (match(&find_obj, o.ext_string) != match_file) continue; if (ConfigAlreadyExists(find_obj.cFileName)) { if (warn_duplicates) ShowLocalizedMsg(IDS_ERR_CONFIG_EXIST, find_obj.cFileName); continue; } AddConfigFileToList(o.num_configs++, find_obj.cFileName, subdir_table[i]); } while (FindNextFile(find_handle, &find_obj)); FindClose(find_handle); } }
int BuildFileList() { WIN32_FIND_DATA find_obj; HANDLE find_handle; BOOL more_files; char find_string[MAX_PATH]; int i; char subdir_table[MAX_CONFIG_SUBDIRS][MAX_PATH]; int subdir=0; int subdir_counter=0; /* Reset config counter */ o.num_configs=0; mysnprintf (find_string, "%s\\*", o.config_dir); find_handle = FindFirstFile (find_string, &find_obj); if (find_handle == INVALID_HANDLE_VALUE) { return(true); } /* * Loop over each config file in main config dir */ do { if (o.num_configs >= MAX_CONFIGS) { /* too many configs */ ShowLocalizedMsg(GUI_NAME, ERR_TO_MANY_CONFIGS, MAX_CONFIGS); break; } /* does file have the correct type and extension? */ if (match (&find_obj, o.ext_string) == MATCH_FILE) { /* Add config file to list */ AddConfigFileToList(o.num_configs, find_obj.cFileName, o.config_dir); o.num_configs++; } if (match (&find_obj, o.ext_string) == MATCH_DIR) { if ((strncmp(find_obj.cFileName, ".", strlen(find_obj.cFileName)) != 0) && (strncmp(find_obj.cFileName, "..", strlen(find_obj.cFileName)) != 0) && (subdir < MAX_CONFIG_SUBDIRS)) { /* Add dir to dir_table */ mysnprintf(subdir_table[subdir], "%s\\%s", o.config_dir, find_obj.cFileName); subdir++; } } /* more files to process? */ more_files = FindNextFile (find_handle, &find_obj); } while (more_files); FindClose (find_handle); /* * Loop over each config file in every subdir */ for (subdir_counter=0; subdir_counter < subdir; subdir_counter++) { mysnprintf (find_string, "%s\\*", subdir_table[subdir_counter]); find_handle = FindFirstFile (find_string, &find_obj); if (find_handle == INVALID_HANDLE_VALUE) continue; do { if (o.num_configs >= MAX_CONFIGS) { /* too many configs */ ShowLocalizedMsg(GUI_NAME, ERR_TO_MANY_CONFIGS, MAX_CONFIGS); FindClose (find_handle); return(true); } /* does file have the correct type and extension? */ if (match (&find_obj, o.ext_string) == MATCH_FILE) { if (!ConfigAlreadyExists(find_obj.cFileName)) { /* Add config file to list */ AddConfigFileToList(o.num_configs, find_obj.cFileName, subdir_table[subdir_counter]); o.num_configs++; } else { /* Config filename already exists */ ShowLocalizedMsg(GUI_NAME, ERR_CONFIG_ALREADY_EXIST, find_obj.cFileName); } } /* more files to process? */ more_files = FindNextFile (find_handle, &find_obj); } while (more_files); FindClose (find_handle); } return (true); }