static void _retrieve_available_languages(void) { int ret; struct al_ffblk info; _free_available_languages(); _available_languages = m_xmalloc(sizeof(char*)); TRACE("Entering retrieve section\n"); if (!(ret = al_findfirst("??text.cfg", &info, 0))) { while (!ret) { char lang_code[3]; char *lang_name = _get_lang_name_from_file(info.name, lang_code); TRACE("Found file %s\n", info.name); if (lang_name) { TRACE(" code %s, name %s\n", lang_code, lang_name); _available_languages = m_xrealloc(_available_languages, ((_num_available_languages + 1) * 2) * sizeof(char*)); _available_languages[_num_available_languages*2] = m_strdup(lang_code); _available_languages[_num_available_languages*2+1] = lang_name; _num_available_languages++; } ret = al_findnext(&info); } al_findclose(&info); } }
int scan_importfolder(char *subdir) { for(int i=0;i<127;i++) { sprintf(list_import_files[i],""); } struct al_ffblk f; bool isSomeone; int nrbe_de_fichiers=0; sprintf(rep,"%s\\import_export\\%s",mondirectory,subdir); chdir(rep); if(!al_findfirst("*.*",&f,-1)) { while(!al_findnext(&f)) { isSomeone=true; // we've found a directory! if(isSomeone && nrbe_de_fichiers<127) { sprintf(list_import_files[nrbe_de_fichiers],f.name); nrbe_de_fichiers++; } } } al_findclose(&f); //REROLL sprintf(rep,"%s\\",mondirectory); chdir (rep); return(0); }
bool FileSystemModule::dirExists(const base::string& path) { struct al_ffblk info; int ret; base::string path2 = base::join_path(path, "*.*"); ret = al_findfirst(path2.c_str(), &info, FA_ALL); al_findclose(&info); return (ret == 0); }
/* *** SCRIPT SYMBOL: [ListBox] ListBox::FillDirList^1 *** */ void ListBox_FillDirList(GUIListBox *listbox, const char *filemask) { char searchPath[MAX_PATH]; validate_user_file_path(filemask, searchPath, false); listbox->Clear(); al_ffblk dfb; int dun = al_findfirst(searchPath, &dfb, FA_SEARCH); while (!dun) { listbox->AddItem(dfb.name); dun = al_findnext(&dfb); } al_findclose(&dfb); guis_need_update = 1; }
// Dateisuchfunktionen in verschiedenen Variationen void find_files( const Filename& fn_where, const std::string& what, DoStr dostr, void* from ) { std::string where = fn_where.get_rootful(); al_ffblk info; std::string search_for = where + what; if (al_findfirst(search_for.c_str(), &info, FA_RDONLY | FA_HIDDEN | FA_LABEL | FA_ARCH) == 0) { do { // Gefundene Datei zum Vektor hinzuf�gen Filename fn_result(where + info.name); dostr(fn_result, from); } while (al_findnext(&info) == 0); al_findclose(&info); } }
std::vector<std::string> World::createDungeonList() { std::vector<std::string> result; al_ffblk findResult; std::string pattern = ResourceHandler::getInstance()->getRealFilename("dungeons/*.txt"); if (al_findfirst(pattern.c_str(), &findResult, FA_ALL) != 0) { return result; } do { result.push_back(findResult.name); } while (al_findnext(&findResult) == 0); al_findclose(&findResult); return result; }
void find_dirs(const Filename& fn_where, DoStr dostr, void* from) { al_ffblk info; std::string where = fn_where.get_rootful(); if (where[where.size()-1] != '/') where += '/'; if (where[where.size()-1] != '*') where += '*'; if (al_findfirst(where.c_str(), &info, FA_RDONLY | FA_HIDDEN | FA_LABEL | FA_DIREC | FA_ARCH) == 0) { do { // Gefundenes Verzeichnis hinzuf�gen if ((info.attrib & FA_DIREC) == FA_DIREC && info.name[0] != '.') { std::string s = where; s.resize(s.size() -1 ); // * von der Maske abschnibbeln s += info.name; s += '/'; Filename fn_result(s); dostr(fn_result, from); } } while (al_findnext(&info) == 0); al_findclose(&info); } }
int scan_savesfolder() { struct al_ffblk f; bool isDir; int nbre_de_shows=0; sprintf(rep,"%s\\saves",mondirectory); chdir(rep); if(!al_findfirst("*.*",&f,-1)) { while(!al_findnext(&f)) { isDir=true; // check if it's a dir or a file for(int a=0;a<strlen(f.name);a++) { if(f.name[a]=='.') { isDir=false; break; } } // we've found a directory! if(isDir) { sprintf(list_save_files[nbre_de_shows],f.name); nbre_de_shows++; } } } al_findclose(&f); //reroll sprintf(rep,"%s\\",mondirectory); chdir (rep); return(0); }
void find_tree (const Filename& fn_where, const std::string& what, DoStr dostr, void* from) { std::string where = fn_where.get_rootful(); // Nach Verzeichnissen suchen al_ffblk info; if (where[where.size()-1] != '/') where += '/'; std::string search_for = where + '*'; if (al_findfirst(search_for.c_str(), &info, FA_RDONLY | FA_HIDDEN | FA_LABEL | FA_DIREC | FA_ARCH) == 0) { do { // Dies nur f�r jedes Verzeichnis au�er . und .. ausf�hren: // Neue Suche mit gleichem Vektor im gefundenen Verzeichnis if ((info.attrib & FA_DIREC) == FA_DIREC && info.name[0] != '.') { Filename fn_recurs(where + info.name + '/'); find_tree(fn_recurs, what, dostr, from); } } while (al_findnext(&info) == 0); al_findclose(&info); } // Nach Dateien suchen, die dem Suchkriterium entsprechen Filename fn_where_with_slash(where); find_files(fn_where_with_slash, what, dostr, from); }
/* al_findfirst: * Initiates a directory search. */ int al_findfirst(AL_CONST char *pattern, struct al_ffblk *info, int attrib) { struct FF_DATA *ff_data; struct stat s; int actual_attrib; char tmp[1024]; char *p; /* allocate ff_data structure */ ff_data = _AL_MALLOC(sizeof(struct FF_DATA)); if (!ff_data) { *allegro_errno = ENOMEM; return -1; } memset(ff_data, 0, sizeof *ff_data); info->ff_data = (void *) ff_data; /* if the pattern contains no wildcard, we use stat() */ if (!ustrpbrk(pattern, uconvert("?*", U_ASCII, tmp, U_CURRENT, sizeof(tmp)))) { /* start the search */ errno = *allegro_errno = 0; if (stat(uconvert(pattern, U_CURRENT, tmp, U_UTF8, sizeof(tmp)), &s) == 0) { /* get file attributes */ actual_attrib = ff_get_attrib(ff_get_filename(uconvert(pattern, U_CURRENT, tmp, U_UTF8, sizeof(tmp))), &s); /* does it match ? */ if ((actual_attrib & ~attrib) == 0) { info->attrib = actual_attrib; info->time = s.st_mtime; info->size = s.st_size; /* overflows at 2GB */ ff_data->size = s.st_size; ustrzcpy(info->name, sizeof(info->name), get_filename(pattern)); return 0; } } _AL_FREE(ff_data); info->ff_data = NULL; *allegro_errno = (errno ? errno : ENOENT); return -1; } ff_data->attrib = attrib; do_uconvert(pattern, U_CURRENT, ff_data->dirname, U_UTF8, sizeof(ff_data->dirname)); p = ff_get_filename(ff_data->dirname); _al_sane_strncpy(ff_data->pattern, p, sizeof(ff_data->pattern)); if (p == ff_data->dirname) _al_sane_strncpy(ff_data->dirname, "./", FF_MAXPATHLEN); else *p = 0; /* nasty bodge, but gives better compatibility with DOS programs */ if (strcmp(ff_data->pattern, "*.*") == 0) _al_sane_strncpy(ff_data->pattern, "*", FF_MAXPATHLEN); /* start the search */ errno = *allegro_errno = 0; ff_data->dir = opendir(ff_data->dirname); if (!ff_data->dir) { *allegro_errno = (errno ? errno : ENOENT); _AL_FREE(ff_data); info->ff_data = NULL; return -1; } if (al_findnext(info) != 0) { al_findclose(info); return -1; } return 0; }
/* al_findfirst: * Initiates a directory search. */ int al_findfirst(AL_CONST char *pattern, struct al_ffblk *info, int attrib) { struct FF_DATA *ff_data; char tmp[1024]; /* allocate ff_data structure */ ff_data = _AL_MALLOC(sizeof(struct FF_DATA)); if (!ff_data) { *allegro_errno = ENOMEM; return -1; } /* attach it to the info structure */ info->ff_data = (void *) ff_data; /* Windows defines specific flags for NTFS permissions: * FA_TEMPORARY 0x0100 * FA_SPARSE_FILE 0x0200 * FA_REPARSE_POINT 0x0400 * FA_COMPRESSED 0x0800 * FA_OFFLINE 0x1000 * FA_NOT_CONTENT_INDEXED 0x2000 * FA_ENCRYPTED 0x4000 * so we must set them in the mask by default; moreover, * in order to avoid problems with flags added in the * future, we simply set all bits past the first byte. */ ff_data->attrib = attrib | 0xFFFFFF00; /* start the search */ errno = *allegro_errno = 0; if (get_filename_encoding() != U_UNICODE) { ff_data->handle = _findfirst(uconvert(pattern, U_CURRENT, tmp, U_ASCII, sizeof(tmp)), &ff_data->data.a); if (ff_data->handle < 0) { *allegro_errno = errno; _AL_FREE(ff_data); info->ff_data = NULL; return -1; } if (ff_data->data.a.attrib & ~ff_data->attrib) { if (al_findnext(info) != 0) { al_findclose(info); return -1; } else return 0; } } else { ff_data->handle = _wfindfirst((wchar_t*)uconvert(pattern, U_CURRENT, tmp, U_UNICODE, sizeof(tmp)), &ff_data->data.w); if (ff_data->handle < 0) { *allegro_errno = errno; _AL_FREE(ff_data); info->ff_data = NULL; return -1; } if (ff_data->data.w.attrib & ~ff_data->attrib) { if (al_findnext(info) != 0) { al_findclose(info); return -1; } else return 0; } } fill_ffblk(info); return 0; }
/* *** SCRIPT SYMBOL: [ListBox] ListBox::FillSaveGameList^0 *** */ int ListBox_FillSaveGameList(GUIListBox *listbox) { listbox->Clear(); int numsaves=0; int bufix=0; al_ffblk ffb; long filedates[MAXSAVEGAMES]; char buff[200]; char searchPath[260]; sprintf(searchPath, "%s""agssave.*", saveGameDirectory); int don = al_findfirst(searchPath, &ffb, FA_SEARCH); while (!don) { bufix=0; if (numsaves >= MAXSAVEGAMES) break; // only list games .000 to .099 (to allow higher slots for other perposes) if (strstr(ffb.name,".0")==NULL) { don = al_findnext(&ffb); continue; } const char *numberExtension = strstr(ffb.name, ".0") + 1; int saveGameSlot = atoi(numberExtension); GetSaveSlotDescription(saveGameSlot, buff); listbox->AddItem(buff); listbox->saveGameIndex[numsaves] = saveGameSlot; filedates[numsaves]=(long int)ffb.time; numsaves++; don = al_findnext(&ffb); } al_findclose(&ffb); int nn; for (nn=0;nn<numsaves-1;nn++) { for (int kk=0;kk<numsaves-1;kk++) { // Date order the games if (filedates[kk] < filedates[kk+1]) { // swap them round char*tempptr = listbox->items[kk]; listbox->items[kk] = listbox->items[kk+1]; listbox->items[kk+1] = tempptr; int numtem = listbox->saveGameIndex[kk]; listbox->saveGameIndex[kk] = listbox->saveGameIndex[kk+1]; listbox->saveGameIndex[kk+1] = numtem; long numted=filedates[kk]; filedates[kk]=filedates[kk+1]; filedates[kk+1]=numted; } } } // update the global savegameindex[] array for backward compatibilty for (nn = 0; nn < numsaves; nn++) { play.filenumbers[nn] = listbox->saveGameIndex[nn]; } guis_need_update = 1; listbox->exflags |= GLF_SGINDEXVALID; if (numsaves >= MAXSAVEGAMES) return 1; return 0; }