bool GetFileInfo(const AString& FileName, FILE_INFO *file) { struct dirent ent; strcpy(ent.d_name, FileName.FilePart()); return SetFileData(FileName.PathPart(), ent, file); }
bool CreateDirectory(const AString& dir) { AString parentdir = dir.PathPart(); FILE_INFO file; bool success = true; if (parentdir.Valid() && (parentdir != "/") && !::GetFileInfo(parentdir, &file)) success = CreateDirectory(parentdir); if (success && (dir.FilePart().Valid()) && !::GetFileInfo(dir, &file)) { #ifdef __LINUX__ success = (mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH) == 0); #else success = ::CreateDirectoryA(dir.str(), NULL); #endif } return success; }
void ADVBConfig::ListUsers(AList& list) const { AHash users(10); AList userpatterns; AString filepattern = GetUserPatternsPattern(); AString filepattern_parsed = ParseRegex(filepattern); AString _users = GetConfigItem("users"); AStdFile fp; uint_t i, n = _users.CountColumns(); //debug("Reading users from config %s\n", config.GetFilename().str()); for (i = 0; i < n; i++) { AString user = _users.Column(i).Words(0); if (!users.Exists(user)) { users.Insert(user, 0); list.Add(new AString(user)); } } if (fp.open(GetPatternsFile())) { AString line; while (line.ReadLn(fp) >= 0) { AString user; int p; if ((p = line.PosNoCase(" user:="******"user:=") == 0) user = line.Mid(6).Word(0).DeQuotify(); if (user.Valid() && !users.Exists(user)) { users.Insert(user, 0); list.Add(new AString(user)); } } fp.close(); } ::CollectFiles(filepattern.PathPart(), filepattern.FilePart(), 0, userpatterns); const AString *file = AString::Cast(userpatterns.First()); while (file) { AString user; ADataList regions; if (MatchRegex(*file, filepattern_parsed, regions)) { const REGEXREGION *region = (const REGEXREGION *)regions[0]; if (region) { user = file->Mid(region->pos, region->len); if (!users.Exists(user)) { users.Insert(user, 0); list.Add(new AString(user)); } } } file = file->Next(); } list.Sort(&AString::AlphaCompareCase); }
bool Recurse(const AString& PathPattern, uint_t nSubDirs, bool (*fn)(const FILE_INFO *file, void *Context), void *Context) { return ::Recurse(PathPattern.PathPart(), PathPattern.FilePart(), nSubDirs, fn, Context); }