bool RandomSample::LoadSoundDir( RString sDir, int iMaxToLoad ) { if( sDir == "" ) return true; #if 0 /* (don't want to do this just yet) */ /* If this is actually a directory, add a backslash to the filename, * so we'll look for eg. themes\Default\sounds\sDir\*.mp3. Otherwise, * don't, so we'll look for all of the files starting with sDir, * eg. themes\Default\sounds\sDir*.mp3. */ if(IsADirectory(sDir) && sDir[sDir.size()-1] != "/" ) sDir += "/"; #else // make sure there's a slash at the end of this path if( sDir.Right(1) != "/" ) sDir += "/"; #endif vector<RString> arraySoundFiles; GetDirListing( sDir + "*.mp3", arraySoundFiles ); GetDirListing( sDir + "*.oga", arraySoundFiles ); GetDirListing( sDir + "*.ogg", arraySoundFiles ); GetDirListing( sDir + "*.wav", arraySoundFiles ); random_shuffle( arraySoundFiles.begin(), arraySoundFiles.end() ); arraySoundFiles.resize( min( arraySoundFiles.size(), (unsigned)iMaxToLoad ) ); for( unsigned i=0; i<arraySoundFiles.size(); i++ ) LoadSound( sDir + arraySoundFiles[i] ); return true; }
const char* FBDirectory::Normalize(const char* path) { static char newpath[MAXPATHLEN+1]; const char* buf; buf = InterpSlashSlash(path); buf = ElimDot(buf); buf = ElimDotDot(buf); buf = InterpTilde(buf); if (*buf == '\0') { strcpy(newpath, "./"); } else if (!DotSlash(buf) && !DotDotSlash(buf) && *buf != '/') { strcpy(newpath, "./"); strcat(newpath, buf); } else if (IsADirectory(buf) && buf[strlen(buf)-1] != '/') { strcpy(newpath, buf); strcat(newpath, "/"); } else { strcpy(newpath, buf); } return newpath; }
void AddLayersFromAniDir( CString sAniDir, vector<Actor*> &layersAddTo, bool Generic ) { if( sAniDir.empty() ) return; if( sAniDir.Right(1) != "/" ) sAniDir += "/"; ASSERT_M( IsADirectory(sAniDir), sAniDir + " isn't a directory" ); CString sPathToIni = sAniDir + "BGAnimation.ini"; IniFile ini; ini.ReadFile( sPathToIni ); { CString expr; if( ini.GetValue( "BGAnimation", "Condition", expr ) || ini.GetValue( "BGAnimation", "Cond", expr ) ) { if( !Lua::RunExpression( expr ) ) return; } } int i; for( i=0; i<MAX_LAYERS; i++ ) { CString sLayer = ssprintf("Layer%d",i+1); const IniFile::key* pKey = ini.GetKey( sLayer ); if( pKey == NULL ) continue; // skip CString sImportDir; if( ini.GetValue(sLayer, "Import", sImportDir) ) { CString expr; if( ini.GetValue(sLayer,"Condition",expr) ) { if( !Lua::RunExpression( expr ) ) continue; } // import a whole BGAnimation sImportDir = sAniDir + sImportDir; CollapsePath( sImportDir ); AddLayersFromAniDir( sImportDir, layersAddTo, Generic ); } else { // import as a single layer BGAnimationLayer* pLayer = new BGAnimationLayer( Generic ); pLayer->LoadFromIni( sAniDir, sLayer ); layersAddTo.push_back( pLayer ); } } }
void Transition::Load( CString sBGAniDir ) { if( IsADirectory(sBGAniDir) && sBGAniDir.Right(1) != "/" ) sBGAniDir += "/"; this->RemoveAllChildren(); m_sprTransition.Load( sBGAniDir ); m_sprTransition->PlayCommand( "On" ); this->AddChild( m_sprTransition ); m_fLengthSeconds = m_sprTransition->GetTweenTimeLeft(); m_State = waiting; // load sound from file specified by ini, or use the first sound in the directory if( IsADirectory(sBGAniDir) ) { IniFile ini; ini.ReadFile( sBGAniDir+"/BGAnimation.ini" ); CString sSoundFileName; if( ini.GetValue("BGAnimation","Sound", sSoundFileName) ) { FixSlashesInPlace( sSoundFileName ); CString sPath = sBGAniDir+sSoundFileName; CollapsePath( sPath ); m_sound.Load( sPath ); } else { m_sound.Load( sBGAniDir ); } } else if( GetExtension(sBGAniDir).CompareNoCase("xml") == 0 ) { CString sSoundFile; XNode xml; xml.LoadFromFile( sBGAniDir ); if( xml.GetAttrValue( "Sound", sSoundFile ) ) m_sound.Load( Dirname(sBGAniDir) + sSoundFile ); } }
const char* FBDirectory::ValidDirectories(const char* path) { static char buf[MAXPATHLEN+1]; strcpy(buf, path); int i = strlen(path); while (!IsADirectory(RealPath(buf)) && i >= 0) { for (--i; buf[i] != '/' && i >= 0; --i); buf[i+1] = '\0'; } return buf; }
static void DeleteEmptyDirectories( const CString &sDir ) { vector<CString> asNewDirs; GetDirListing( sDir + "/*", asNewDirs, false, true ); for( unsigned i = 0; i < asNewDirs.size(); ++i ) { ASSERT_M( IsADirectory(asNewDirs[i]), asNewDirs[i] ); DeleteEmptyDirectories( asNewDirs[i] ); } FILEMAN->Remove( sDir ); }
static void EmptyDir( CString dir ) { ASSERT(dir[dir.size()-1] == '/'); CStringArray asCacheFileNames; GetDirListing( dir, asCacheFileNames ); for( unsigned i=0; i<asCacheFileNames.size(); i++ ) { if( !IsADirectory(dir + asCacheFileNames[i]) ) FILEMAN->Remove( dir + asCacheFileNames[i] ); } }
void RageSound_OSS::CheckOSSVersion( int fd ) { int version = 0; #if defined(HAVE_OSS_GETVERSION) if( ioctl(fd, OSS_GETVERSION, &version) != 0 ) { LOG->Warn( "OSS_GETVERSION failed: %s", strerror(errno) ); version = 0; } #endif /* * Find out if /dev/dsp is really ALSA emulating it. ALSA's OSS emulation has * been buggy. If we got here, we probably failed to init ALSA. The only case * I've seen of this so far was not having access to /dev/snd devices. */ /* Reliable but only too recently available: if (ioctl(fd, OSS_ALSAEMULVER, &ver) == 0 && ver ) */ /* * Ack. We can't just check for /proc/asound, since a few systems have ALSA * loaded but actually use OSS. ALSA returns a specific version; check that, * too. It looks like that version is potentially a valid OSS version, so * check both. */ #ifndef FORCE_OSS #define ALSA_SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) if( version == ALSA_SNDRV_OSS_VERSION && IsADirectory("/proc/asound") ) { close( fd ); RageException::ThrowNonfatal( "RageSound_OSS: ALSA detected. ALSA OSS emulation is buggy; use ALSA natively."); } #endif if( version ) { int major, minor, rev; if( version < 361 ) { major = (version/100)%10; minor = (version/10) %10; rev = (version/1) %10; } else { major = (version/0x10000) % 0x100; minor = (version/0x00100) % 0x100; rev = (version/0x00001) % 0x100; } LOG->Info("OSS: %i.%i.%i", major, minor, rev ); } }
void ClassBuffer::Search (const char* path) { struct stat filestats; if (IsADirectory(path, filestats)) { if (_recursive) { SearchDirs(path); } else { SearchDir(path); } } else if (HeaderFile(path) || (_CPlusPlusFiles && CPlusPlusFile(path))) { SearchFile(path, filestats); } }
boolean FileBrowser::Acceptable(const char* name) { boolean dir1 = IsADirectory(name); int m = dir1 ? directory_mode : mode; Regexp* r = dir1 ? directory_regexp : regexp; boolean mode_ok, name_ok; if (m != 0) { struct stat st; mode_ok = stat((char*)name, &st) == 0 && (st.st_mode & m) != 0; } else { mode_ok = true; } if (r != nil) { name_ok = r->Match(name, strlen(name), 0) >= 0; } else { name_ok = true; } return mode_ok && name_ok; }
FileType ActorUtil::GetFileType( const RString &sPath ) { RString sExt = GetExtension( sPath ); sExt.MakeLower(); etft_cont_t::iterator conversion_entry= ExtensionToFileType.find(sExt); if(conversion_entry != ExtensionToFileType.end()) { return conversion_entry->second; } else if(sPath.size() > 0 && sPath[sPath.size()-1] == '/') { return FT_Directory; } /* Do this last, to avoid the IsADirectory in most cases. */ else if(IsADirectory(sPath)) { return FT_Directory; } return FileType_Invalid; }
RString LoadALSA() { /* If /proc/asound/ doesn't exist, chances are we're on an OSS system. We shouldn't * touch ALSA at all, since many OSS systems have old, broken versions of ALSA lying * around; we're likely to crash if we go near it. Do this first, before loading * the ALSA library, since making any ALSA calls may load ALSA core modules. * * It's vaguely possible that a module autoloader would load the entire ALSA module set * on use, and this would prevent that from happening. I don't know if anyone actually * does that, though: they're often configured to load snd (the core module) if ALSA * devices are accessed, but hardware drivers are typically loaded on boot. */ if( !IsADirectory("/rootfs/proc/asound/") ) return "/proc/asound/ does not exist"; ASSERT( Handle == NULL ); Handle = dlopen( lib, RTLD_NOW ); if( Handle == NULL ) return ssprintf("dlopen(%s): %s", lib.c_str(), dlerror()); RString error; /* Eww. The "new" HW and SW API functions are really prefixed by __, * eg. __snd_pcm_hw_params_set_rate_near. */ #define FUNC(ret, name, proto) \ d##name = (name##_f) dlsym(Handle, "__" #name); \ if( !d##name ) { \ d##name = (name##_f) dlsym(Handle, #name); \ if( !d##name ) { \ error="Couldn't load symbol " #name; \ goto error; \ } \ } #include "ALSA9Functions.h" #undef FUNC return ""; error: UnloadALSA(); return error; }
void ClassBuffer::SearchDir (const char* path) { Directory dir(path); if (_verbose) { printf("searching directory %s\n", path); } for (int i = 0; i < dir.Count(); ++i) { const char* file = dir.File(i); if (HeaderFile(file) || (_CPlusPlusFiles && CPlusPlusFile(path))) { struct stat filestats; char filePath[MAXPATHLEN+1]; strcpy(filePath, dir.Normalize(path)); strcat(filePath, file); if (!IsADirectory(filePath, filestats)) { SearchFile(filePath, filestats); } } } }
FileType ActorUtil::GetFileType( const RString &sPath ) { RString sExt = GetExtension( sPath ); sExt.MakeLower(); if( sExt=="lua" ) return FT_Lua; else if(sExt=="xml") return FT_Xml; else if( sExt=="png" || sExt=="jpg" || sExt=="jpeg" || sExt=="gif" || sExt=="bmp" ) return FT_Bitmap; else if( sExt=="ogg" || sExt=="oga" || sExt=="wav" || sExt=="mp3" ) return FT_Sound; else if( sExt=="ogv" || sExt=="avi" || sExt=="mpeg" || sExt=="mp4" || sExt=="mkv" || sExt=="mov" || sExt=="flv" || sExt=="f4v" || sExt=="mpg" ) return FT_Movie; else if( sExt=="sprite" ) return FT_Sprite; else if( sExt=="txt" ) return FT_Model; else if( sPath.size() > 0 && sPath[sPath.size()-1] == '/' ) return FT_Directory; /* Do this last, to avoid the IsADirectory in most cases. */ else if( IsADirectory(sPath) ) return FT_Directory; else return FileType_Invalid; }
// this is the diary of a mad man bool GetUSBDeviceList(vector<USBDevice> &pDevList) { FlushDirCache(); std::map< CString, vector<CString> > sDevInterfaceList; vector<CString> sDirList; GetDirListing( "/rootfs/sys/bus/usb/devices/", sDirList, true, false ); for (unsigned i = 0; i < sDirList.size(); i++) { CString sDirEntry = sDirList[i]; vector<CString> components; if (sDirEntry.substr(0, 3) == "usb") continue; split( sDirEntry, ":", components, true ); if ( components.size() < 2 ) continue; if ( ! IsADirectory( "/rootfs/sys/bus/usb/devices/" + components[0] ) ) continue; // I win --infamouspat sDevInterfaceList[components[0]].push_back(components[1]); } map< CString, vector<CString> >::iterator iter; for(iter = sDevInterfaceList.begin(); iter != sDevInterfaceList.end(); iter++) { USBDevice newDev; CString sDevName = iter->first; vector<CString> sDevChildren = iter->second; if ( newDev.Load(sDevName, sDevChildren) ) pDevList.push_back(newDev); } return true; }
void BGAnimation::LoadFromAniDir( CString sAniDir ) { Unload(); if( sAniDir.empty() ) return; if( sAniDir.Right(1) != "/" ) sAniDir += "/"; ASSERT_M( IsADirectory(sAniDir), sAniDir + " isn't a directory" ); CString sPathToIni = sAniDir + "BGAnimation.ini"; if( DoesFileExist(sPathToIni) ) { // This is a new style BGAnimation (using .ini) AddLayersFromAniDir( sAniDir, m_SubActors, m_bGeneric ); // TODO: Check for circular load IniFile ini; ini.ReadFile( sPathToIni ); if( !ini.GetValue( "BGAnimation", "LengthSeconds", m_fLengthSeconds ) ) { /* XXX: if m_bGeneric, simply constructing the BG layer won't run "On", * so at this point GetMaxTweenTimeLeft is probably 0 */ m_fLengthSeconds = this->GetTweenTimeLeft(); } bool bUseScroller; if( ini.GetValue( "BGAnimation", "UseScroller", bUseScroller ) && bUseScroller ) { // TODO: Move this into ActorScroller #define REQUIRED_GET_VALUE( szName, valueOut ) \ if( !ini.GetValue( "Scroller", szName, valueOut ) ) \ Dialog::OK( ssprintf("File '%s' is missing the value Scroller::%s", sPathToIni.c_str(), szName) ); float fSecondsPerItem = 1; int iNumItemsToDraw = 7; RageVector3 vRotationDegrees = RageVector3(0,0,0); RageVector3 vTranslateTerm0 = RageVector3(0,0,0); RageVector3 vTranslateTerm1 = RageVector3(0,0,0); RageVector3 vTranslateTerm2 = RageVector3(0,0,0); float fItemPaddingStart = 0; float fItemPaddingEnd = 0; REQUIRED_GET_VALUE( "SecondsPerItem", fSecondsPerItem ); REQUIRED_GET_VALUE( "NumItemsToDraw", iNumItemsToDraw ); REQUIRED_GET_VALUE( "RotationDegreesX", vRotationDegrees[0] ); REQUIRED_GET_VALUE( "RotationDegreesY", vRotationDegrees[1] ); REQUIRED_GET_VALUE( "RotationDegreesZ", vRotationDegrees[2] ); REQUIRED_GET_VALUE( "TranslateTerm0X", vTranslateTerm0[0] ); REQUIRED_GET_VALUE( "TranslateTerm0Y", vTranslateTerm0[1] ); REQUIRED_GET_VALUE( "TranslateTerm0Z", vTranslateTerm0[2] ); REQUIRED_GET_VALUE( "TranslateTerm1X", vTranslateTerm1[0] ); REQUIRED_GET_VALUE( "TranslateTerm1Y", vTranslateTerm1[1] ); REQUIRED_GET_VALUE( "TranslateTerm1Z", vTranslateTerm1[2] ); REQUIRED_GET_VALUE( "TranslateTerm2X", vTranslateTerm2[0] ); REQUIRED_GET_VALUE( "TranslateTerm2Y", vTranslateTerm2[1] ); REQUIRED_GET_VALUE( "TranslateTerm2Z", vTranslateTerm2[2] ); REQUIRED_GET_VALUE( "ItemPaddingStart", fItemPaddingStart ); REQUIRED_GET_VALUE( "ItemPaddingEnd", fItemPaddingEnd ); #undef REQUIRED_GET_VALUE ActorScroller::Load( fSecondsPerItem, iNumItemsToDraw, vRotationDegrees, vTranslateTerm0, vTranslateTerm1, vTranslateTerm2 ); ActorScroller::SetCurrentAndDestinationItem( int(-fItemPaddingStart) ); ActorScroller::SetDestinationItem( int(m_SubActors.size()-1+fItemPaddingEnd) ); } CString InitCommand; if( ini.GetValue( "BGAnimation", "InitCommand", InitCommand ) ) { /* There's an InitCommand. Run it now. This can be used to eg. change Z to * modify draw order between BGAs in a Foreground. Most things should be done * in metrics.ini commands, not here. */ this->Command( InitCommand ); } } else { // This is an old style BGAnimation (not using .ini) // loading a directory of layers CStringArray asImagePaths; ASSERT( sAniDir != "" ); GetDirListing( sAniDir+"*.png", asImagePaths, false, true ); GetDirListing( sAniDir+"*.jpg", asImagePaths, false, true ); GetDirListing( sAniDir+"*.gif", asImagePaths, false, true ); GetDirListing( sAniDir+"*.avi", asImagePaths, false, true ); GetDirListing( sAniDir+"*.mpg", asImagePaths, false, true ); GetDirListing( sAniDir+"*.mpeg", asImagePaths, false, true ); GetDirListing( sAniDir+"*.sprite", asImagePaths, false, true ); SortCStringArray( asImagePaths ); for( unsigned i=0; i<asImagePaths.size(); i++ ) { const CString sPath = asImagePaths[i]; if( Basename(sPath).Left(1) == "_" ) continue; // don't directly load files starting with an underscore BGAnimationLayer* pLayer = new BGAnimationLayer( m_bGeneric ); pLayer->LoadFromAniLayerFile( asImagePaths[i] ); AddChild( pLayer ); } } }