// --------------------------------------------------------- // CPosLmLocalDatabaseManager::CreateDriveInfoListL // // (other items were commented in a header). // --------------------------------------------------------- // void CPosLmLocalDatabaseManager::CreateDriveInfoListL() { RFs fs; CleanupClosePushL(fs); User::LeaveIfError(fs.Connect()); TDriveList driveList; User::LeaveIfError(fs.DriveList(driveList)); for (TInt drive = EDriveA; drive <= EDriveZ; drive++) { if ( driveList[drive] && !( driveList[drive] & KDriveAttRemote ) ) // avoid remote drives { TDriveInfo drvInfo; TInt err = fs.Drive( drvInfo, drive ); if ( !err && drvInfo.iType != EMediaNotPresent ) { TMediaInfo mediaInfo; mediaInfo.iMediaType = drvInfo.iType; User::LeaveIfError(fs.DriveToChar(drive, mediaInfo.iDrive)); User::LeaveIfError(iMediaInfoList.Append(mediaInfo)); } } } CleanupStack::PopAndDestroy(&fs); }
void CPlaylist::ScanDirectory(const char *dir) { ResetView(); if (!dir || !strlen(dir)) { RFs iFs; TDriveList aList; iFs.Connect(); iFs.DriveList(aList); for (TInt i=0; i<KMaxDrives; i++) { if (aList[i]) { TChar aDrive; iFs.DriveToChar(i, aDrive); sprintf(szCurrentDir, "%c:", (TUint)aDrive); AddItem(szCurrentDir, 0); } } iFs.Close(); FlushItemList(); strcpy(szCurrentDir, ""); return; } else { strcpy(szCurrentDir, dir); AddItem("..", 1); } #ifndef GPAC_GUI_ONLY gf_enum_directory((const char *) szCurrentDir, 1, enum_dirs, this, NULL); gf_enum_directory((char *) szCurrentDir, 0, enum_files, this, view_all_files ? NULL : ext_list); #endif FlushItemList(); ((COsmo4AppUi *) CEikonEnv::Static()->AppUi())->SetTitle(szCurrentDir, 0); }
// --------------------------------------------------------------------------- // void CLbtAppChangeHandler::MemoryCardChar() // --------------------------------------------------------------------------- // void CLbtAppChangeHandler::MemoryCardChar() { TInt drive; TInt err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, drive); //if memory card is not supported if( err!=KErrNone ) { iMMCDriveChar.Copy(KMMCErrorChar); return; } //retrieve memory card character RFs fs; err = fs.Connect(); if( err==KErrNone ) { TChar memChar; fs.DriveToChar(drive,memChar); iMMCDriveChar.Zero(); iMMCDriveChar.Append( memChar ); } else { iMMCDriveChar.Copy(KMMCErrorChar); } iMMCDriveChar.Append(KCharColon); fs.Close(); }
// ----------------------------------------------------------------------------- // DataFileL // return data filename as a TParse // ----------------------------------------------------------------------------- // LOCAL_C TParse DataFileL(RFs& aFs) { TBuf<256> path; TParse p; User::LeaveIfError(aFs.PrivatePath(path)); #ifndef RD_MULTIPLE_DRIVE p.Set(KHelperServerDataStorage,&path,NULL); #else //RD_MULTIPLE_DRIVE TInt driveNumber( -1 ); TChar driveLetter; DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); aFs.DriveToChar( driveNumber, driveLetter ); TFileName helperServerDataStorage; helperServerDataStorage.Format( KHelperServerDataStorage, (TUint)driveLetter ); p.Set( helperServerDataStorage, &path, NULL ); #endif return p; }
LOCAL_C void GetDriveLetters() { // Assign the first drive that matches the required criteria test.Next(_L("T_DENYCLAMP - GetDriveLetters()")); TDriveList driveList; TDriveInfo driveInfo; TInt r=TheFs.DriveList(driveList); test(r==KErrNone); TInt drvNum; TBool drivesFound = EFalse; for(drvNum=0; (drvNum<KMaxDrives) && !drivesFound; drvNum++) { TChar drvLetter='?'; TFileName fileSystem; if(!driveList[drvNum]) continue; test(TheFs.Drive(driveInfo, drvNum) == KErrNone); test(TheFs.DriveToChar(drvNum,drvLetter) == KErrNone); r=TheFs.FileSystemName(fileSystem,drvNum); fileSystem.UpperCase(); test((r==KErrNone)||(r==KErrNotFound)); // Check for FAT on NAND if(NandFatDrv=='?') { if((driveInfo.iType==EMediaNANDFlash) && (fileSystem.Compare(KFATName)==0)) NandFatDrv=drvLetter; } // Check for ROFS if(RofsDrv=='?') { if((driveInfo.iType==EMediaNANDFlash) && (fileSystem.Compare(KROFSName)==0)) RofsDrv=drvLetter; } // Check for LFFS if(LffsDrv=='?') { if((driveInfo.iType==EMediaFlash) && (fileSystem.Compare(KLFFSName)==0)) LffsDrv=drvLetter; } // Check for CompFSys if(CompDrv=='?') { if((driveInfo.iType==EMediaRom) && ((fileSystem.Compare(KROMName)==0)||(fileSystem.Compare(KCOMPName)==0))) CompDrv=drvLetter; } drivesFound=((NandFatDrv!='?')&&(RofsDrv!='?')&&(LffsDrv!='?')&&(CompDrv!='?')); } if(NandFatDrv!='?') test((NandFatDrv!=RofsDrv)&&(NandFatDrv!=LffsDrv)&&(NandFatDrv!=CompDrv)); if(RofsDrv!='?') test((RofsDrv!=LffsDrv)&&(RofsDrv!=CompDrv)); if(LffsDrv!='?') test(LffsDrv!=CompDrv); RDebug::Printf("T_DENYCLAMP: FAT drive=%C, ROFS drive=%C, LFFS drive=%C, ROM-COMP drive=%C \n",(TText)NandFatDrv,(TText)RofsDrv,(TText)LffsDrv,(TText)CompDrv); return; }
LOCAL_C TInt MakeFileName(TInt aThreadId, TInt aFileNumber, RFs & aFs, TFileName& aName, TBool aMakeDir) // // creates a file name and makes all the directory components, if required // { TFileName path; path.Format(KPath, aThreadId); TChar driveLetter; TInt r; r = aFs.DriveToChar(gDriveNumber, driveLetter); if (r != KErrNone) { LogError(r, KDriveToChar, KNullDesC, driveLetter, 0); aFs.Close(); return(r); } path[0] = (TText) driveLetter; r = aFs.SetSessionPath(path); if (r != KErrNone) { LogError(r, KSetSessPath, path, 0, 0); aFs.Close(); return(r); } // add additional directories TInt fileNumber; fileNumber = aFileNumber; r = AppendPath(path, fileNumber, 0); if(r != KErrNone) { LogError(r, KAppendPath, path, fileNumber, 0); aFs.Close(); return(r); } if(aMakeDir) { r = aFs.MkDirAll(path); if (r != KErrNone && r != KErrAlreadyExists) { LogError(r, KMdAll, path, 0, 0); aFs.Close(); return(r); } } // and finally add file name path.Append(KFilePrefix); path.AppendNum(aFileNumber); aName = path; return(KErrNone); }
// ----------------------------------------------------------------------------- // CMessageMonitorPlugin::CreateFileNameL // Filename flag can be changed to use cen rep! // ----------------------------------------------------------------------------- // void CMessageMonitorPlugin::CreateFileNameL() { TInt drive ( 0 ); User::LeaveIfError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, drive ) ); RFs fsSession; User::LeaveIfError( fsSession.Connect() ); TChar driveLetter; fsSession.DriveToChar( drive, driveLetter ); iFileName.Append( driveLetter ); iFileName.Append( KRestoreFile ); // result-> C:\\private\\200009F5\\restoredone fsSession.Close(); }
RArray<TFileName> ListImages::listImageL() { RFs fs; TBuf<50> totalPath; TBuf<1> space; TBuf<30> fileName; TChar driveLetter; result.Reset(); TDriveList listaDrivers; TInt driveNumber = EDriveA; TFileName DirName; space.Append(_L("")); _LIT(KDirName, "\\Images\\"); User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); fs.DriveList(listaDrivers); for (; driveNumber <= EDriveZ; driveNumber++) { if (listaDrivers[driveNumber]) { User::LeaveIfError(fs.DriveToChar(driveNumber, driveLetter)); DirName = _L(""); DirName.Append(TUint(driveLetter)); DirName.Append(_L(":")); DirName.Append(KDirName); RArray<TFileName> res = searchJPGL(DirName, fs, space); for (TInt i = 0; i < res.Count(); i++) { result.Append(res[i]); } res.Reset(); } } fs.Close(); CleanupStack::PopAndDestroy(1); for (TInt i = 0; i < result.Count(); i++) RDebug::Print(_L("%S"),&result[i]); }
/** * Gets the mounted root file systems. * * Note: the caller is responsible for calling 'midpFree' after use. * @return A string containing currently mounted roots * separated by '\n' character */ char* getMountedRoots() { char* roots = NULL; TDriveList list; if(gFs.DriveList(list) == KErrNone) { TBuf8<64> buffer; for(int i=0;i<KMaxDrives;i++) { if(list[i] != 0) { TChar driveChar; gFs.DriveToChar(i,driveChar); buffer.Append(driveChar); buffer.Append(_L(":/\n")); } } buffer.SetLength(buffer.Length() -1); roots = midpStrdup((const char*)buffer.PtrZ()); } return roots; }
//TFindFile and CFileMan classes support the use of wildcard characters. //An asterisk indicates any number of characters, and a question mark indicates a single character. //Note that in the context of these classes, * and *.* are equivalent and match to all files, //with and without extensions. Filename matching is case insensitive. void CStateDownload::StartScanL(RFs& aFs,const TDesC& aSearchString, CDesCArray* aFileArray) { //retrieve all drives in mobile _LIT(KFormat,"%c:\\"); TDriveList driveList; TInt err = aFs.DriveList(driveList); if(err != KErrNone) return; for(TInt driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++) { if (driveList[driveNumber]) /** now we iterate through all the available drives */ { TChar driveLetter; err = aFs.DriveToChar(driveNumber,driveLetter); TBuf<8> buf; buf.Format(KFormat,(TUint)driveLetter); CDirScan* dirScan = CDirScan::NewLC(aFs); dirScan->SetScanDataL(buf, KEntryAttDir|KEntryAttMatchExclusive, ESortNone, CDirScan::EScanDownTree); while(1) { CDir* dir = NULL; TRAPD(err, dirScan->NextL(dir)); if(err == KErrPermissionDenied) //we could'nt have the required capab { delete dir; continue; } if (dir == NULL) //there are no more directory to iterate { break; } delete dir; ScanDirectory(aFs, dirScan->FullPath(), aSearchString, aFileArray); } CleanupStack::PopAndDestroy(dirScan); } } }
Vector<String> PluginDatabase::defaultPluginDirectories() { Vector<String> directories; //find the installation drive TDriveList drivelist; TChar driveLetter; RFs fsSession; if (fsSession.Connect() == KErrNone && fsSession.DriveList(drivelist) == KErrNone) { for (TInt driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++) { if (drivelist[driveNumber] && fsSession.DriveToChar(driveNumber, driveLetter) == KErrNone) { QString driveStringValue(QChar((uint)driveLetter.GetUpperCase())); QString stubDirPath; stubDirPath.append(driveStringValue); stubDirPath.append(QT_PLUGIN_FOLDER); if (QFileInfo(stubDirPath).exists()) directories.append(stubDirPath); } } } fsSession.Close(); return directories; }
static TChar DriveNumberToLetter(TInt driveNumber) { TChar driveLetter = '?'; fs.DriveToChar(driveNumber, driveLetter); return driveLetter; }
// ----------------------------------------------------------------------------- // CPosLmLocalDatabaseManager::ListDatabasesLC // // (other items were commented in a header). // ----------------------------------------------------------------------------- // CDesCArray* CPosLmLocalDatabaseManager::ListDatabasesLC() { CDesCArray* dbArray = new (ELeave) CDesCArrayFlat(KPosDbListGranularity); CleanupStack::PushL(dbArray); RFs fs; CleanupClosePushL(fs); User::LeaveIfError(fs.Connect()); TDriveList driveList; User::LeaveIfError(fs.DriveList(driveList)); RDbs dbSession; CleanupClosePushL(dbSession); User::LeaveIfError(dbSession.Connect()); for (TInt drive = EDriveA; drive <= EDriveZ; drive++) { if ( driveList[drive] && !( driveList[drive] & KDriveAttRemote ) ) // avoid remote drives { TDriveInfo drvInfo; TInt err = fs.Drive( drvInfo, drive ); if ( !err && drvInfo.iType != EMediaNotPresent ) { CDbDatabaseNames* dbNames = NULL; TRAPD(err, dbNames = dbSession.DatabaseNamesL( static_cast<TDriveNumber>(drive), KPosLmDbSecureUid)); // Ignore all errors except KErrNoMemory (and KErrNone) if (err == KErrNone) { CleanupStack::PushL(dbNames); for (TInt i = 0; i < dbNames->Count(); i++) { TPtrC ptr = (*dbNames)[i]; if (ptr.Right(KFileExtension().Length()). CompareF(KFileExtension) == 0) { HBufC* fullName = HBufC::NewLC( KFileProtocol().Length() + KProtocolDelimiter().Length() + KDriveAndDelimiterLength + (*dbNames)[i].Length()); TChar chr; fs.DriveToChar(drive, chr); TPtr ptr2 = fullName->Des(); ptr2.Append(KFileProtocol); ptr2.Append(KProtocolDelimiter); ptr2.Append(chr); ptr2.Append(KDriveDelimiter); ptr2.Append((*dbNames)[i]); dbArray->AppendL(*fullName); CleanupStack::PopAndDestroy(fullName); } } CleanupStack::PopAndDestroy(dbNames); } else if (err == KErrNoMemory) { User::Leave(err); } } } } CleanupStack::PopAndDestroy(2, &fs); //dbSession return dbArray; }
/*enumerate directories*/ GF_EXPORT GF_Err gf_enum_directory(const char *dir, Bool enum_directory, gf_enum_dir_item enum_dir_fct, void *cbck, const char *filter) { char item_path[GF_MAX_PATH]; GF_FileEnumInfo file_info; #if defined(_WIN32_WCE) char _path[GF_MAX_PATH]; unsigned short path[GF_MAX_PATH]; unsigned short w_filter[GF_MAX_PATH]; char file[GF_MAX_PATH]; #else char path[GF_MAX_PATH], *file; #endif #ifdef WIN32 WIN32_FIND_DATA FindData; HANDLE SearchH; #else DIR *the_dir; struct dirent* the_file; struct stat st; #endif if (!dir || !enum_dir_fct) return GF_BAD_PARAM; if (filter && (!strcmp(filter, "*") || !filter[0])) filter=NULL; memset(&file_info, 0, sizeof(GF_FileEnumInfo) ); if (!strcmp(dir, "/")) { #if defined(WIN32) && !defined(_WIN32_WCE) u32 len; char *drives, *volume; len = GetLogicalDriveStrings(0, NULL); drives = gf_malloc(sizeof(char)*(len+1)); drives[0]=0; GetLogicalDriveStrings(len, drives); len = (u32) strlen(drives); volume = drives; file_info.directory = GF_TRUE; file_info.drive = GF_TRUE; while (len) { enum_dir_fct(cbck, volume, "", &file_info); volume += len+1; len = (u32) strlen(volume); } gf_free(drives); return GF_OK; #elif defined(__SYMBIAN32__) RFs iFs; TDriveList aList; iFs.Connect(); iFs.DriveList(aList); for (TInt i=0; i<KMaxDrives; i++) { if (aList[i]) { char szDrive[10]; TChar aDrive; iFs.DriveToChar(i, aDrive); sprintf(szDrive, "%c:", (TUint)aDrive); enum_dir_fct(cbck, szDrive, "", &file_info); } } iFs.Close(); FlushItemList(); return GF_OK; #endif } #if defined (_WIN32_WCE) switch (dir[strlen(dir) - 1]) { case '/': case '\\': sprintf(_path, "%s*", dir); break; default: sprintf(_path, "%s%c*", dir, GF_PATH_SEPARATOR); break; } CE_CharToWide(_path, path); CE_CharToWide((char *)filter, w_filter); #elif defined(WIN32) switch (dir[strlen(dir) - 1]) { case '/': case '\\': sprintf(path, "%s*", dir); break; default: sprintf(path, "%s%c*", dir, GF_PATH_SEPARATOR); break; } #else strcpy(path, dir); if (path[strlen(path)-1] != '/') strcat(path, "/"); #endif #ifdef WIN32 SearchH= FindFirstFile(path, &FindData); if (SearchH == INVALID_HANDLE_VALUE) return GF_IO_ERR; #if defined (_WIN32_WCE) _path[strlen(_path)-1] = 0; #else path[strlen(path)-1] = 0; #endif while (SearchH != INVALID_HANDLE_VALUE) { #else the_dir = opendir(path); if (the_dir == NULL) { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] Cannot open directory %s for enumeration\n", path)); return GF_IO_ERR; } the_file = readdir(the_dir); while (the_file) { #endif memset(&file_info, 0, sizeof(GF_FileEnumInfo) ); #if defined (_WIN32_WCE) if (!wcscmp(FindData.cFileName, _T(".") )) goto next; if (!wcscmp(FindData.cFileName, _T("..") )) goto next; #elif defined(WIN32) if (!strcmp(FindData.cFileName, ".")) goto next; if (!strcmp(FindData.cFileName, "..")) goto next; #else if (!strcmp(the_file->d_name, "..")) goto next; if (the_file->d_name[0] == '.') goto next; #endif #ifdef WIN32 file_info.directory = (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? GF_TRUE : GF_FALSE; if (!enum_directory && file_info.directory) goto next; if (enum_directory && !file_info.directory) goto next; #endif if (filter) { #if defined (_WIN32_WCE) short ext[30]; short *sep = wcsrchr(FindData.cFileName, (wchar_t) '.'); if (!sep) goto next; wcscpy(ext, sep+1); wcslwr(ext); if (!wcsstr(w_filter, ext)) goto next; #elif defined(WIN32) char ext[30]; char *sep = strrchr(FindData.cFileName, '.'); if (!sep) goto next; strcpy(ext, sep+1); strlwr(ext); if (!strstr(filter, ext)) goto next; #else char ext[30]; char *sep = strrchr(the_file->d_name, '.'); if (!sep) goto next; strcpy(ext, sep+1); strlwr(ext); if (!strstr(filter, sep+1)) goto next; #endif } #if defined(WIN32) file_info.hidden = (FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? 1 : 0; file_info.system = (FindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? 1 : 0; file_info.size = MAXDWORD; file_info.size += 1; file_info.size *= FindData.nFileSizeHigh; file_info.size += FindData.nFileSizeLow; file_info.last_modified = (u64) ((*(LONGLONG *) &FindData.ftLastWriteTime - TIMESPEC_TO_FILETIME_OFFSET) / 10000000); #endif #if defined (_WIN32_WCE) CE_WideToChar(FindData.cFileName, file); strcpy(item_path, _path); strcat(item_path, file); #elif defined(WIN32) strcpy(item_path, path); strcat(item_path, FindData.cFileName); file = FindData.cFileName; #else strcpy(item_path, path); strcat(item_path, the_file->d_name); GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Checking file %s for enum\n", item_path)); if (stat( item_path, &st ) != 0) goto next; file_info.directory = ((st.st_mode & S_IFMT) == S_IFDIR) ? GF_TRUE : GF_FALSE; if (enum_directory && !file_info.directory) goto next; if (!enum_directory && file_info.directory) goto next; file_info.size = st.st_size; { struct tm _t = * gmtime(& st.st_mtime); file_info.last_modified = mktime(&_t); } file = the_file->d_name; if (file && file[0]=='.') file_info.hidden = 1; if (file_info.directory) { char * parent_name = strrchr(item_path, '/'); if (!parent_name) { file_info.drive = GF_TRUE; } else { struct stat st_parent; parent_name[0] = 0; if (stat(item_path, &st_parent) == 0) { if ((st.st_dev != st_parent.st_dev) || ((st.st_dev == st_parent.st_dev) && (st.st_ino == st_parent.st_ino))) { file_info.drive = GF_TRUE; } } parent_name[0] = '/'; } } #endif if (enum_dir_fct(cbck, file, item_path, &file_info)) { #ifdef WIN32 BOOL ret = FindClose(SearchH); if (!ret) { DWORD err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[core] FindClose() in gf_enum_directory() returned(1) the following error code: %d\n", err)); } #endif break; } next: #ifdef WIN32 if (!FindNextFile(SearchH, &FindData)) { BOOL ret = FindClose(SearchH); if (!ret) { DWORD err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[core] FindClose() in gf_enum_directory() returned(2) the following error code: %d\n", err)); } break; } #else the_file = readdir(the_dir); #endif } #ifndef WIN32 closedir(the_dir); #endif return GF_OK; } GF_EXPORT u64 gf_f64_tell(FILE *fp) { #if defined(_WIN32_WCE) return (u64) ftell(fp); #elif defined(GPAC_CONFIG_WIN32) /* mingw or cygwin */ #if (_FILE_OFFSET_BITS >= 64) return (u64) ftello64(fp); #else return (u64) ftell(fp); #endif #elif defined(WIN32) return (u64) _ftelli64(fp); #elif defined(GPAC_CONFIG_LINUX) && !defined(GPAC_ANDROID) return (u64) ftello64(fp); #elif (defined(GPAC_CONFIG_FREEBSD) || defined(GPAC_CONFIG_DARWIN)) return (u64) ftello(fp); #else return (u64) ftell(fp); #endif } GF_EXPORT u64 gf_f64_seek(FILE *fp, s64 offset, s32 whence) { #if defined(_WIN32_WCE) return (u64) fseek(fp, (s32) offset, whence); #elif defined(GPAC_CONFIG_WIN32) /* mingw or cygwin */ #if (_FILE_OFFSET_BITS >= 64) return (u64) fseeko64(fp, offset, whence); #else return (u64) fseek(fp, (s32) offset, whence); #endif #elif defined(WIN32) return (u64) _fseeki64(fp, offset, whence); #elif defined(GPAC_CONFIG_LINUX) && !defined(GPAC_ANDROID) return fseeko64(fp, (off64_t) offset, whence); #elif (defined(GPAC_CONFIG_FREEBSD) || defined(GPAC_CONFIG_DARWIN)) return fseeko(fp, (off_t) offset, whence); #else return fseek(fp, (s32) offset, whence); #endif } GF_EXPORT FILE *gf_f64_open(const char *file_name, const char *mode) { #if defined(WIN32) FILE *res = fopen(file_name, mode); if (res) return res; if (strchr(mode, 'w') || strchr(mode, 'a')) { u32 err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Win32] system failure for file opening of %s in mode %s: 0x%08x\n", file_name, mode, err)); } return NULL; #elif defined(GPAC_CONFIG_LINUX) && !defined(GPAC_ANDROID) return fopen64(file_name, mode); #elif (defined(GPAC_CONFIG_FREEBSD) || defined(GPAC_CONFIG_DARWIN)) return fopen(file_name, mode); #else return fopen(file_name, mode); #endif }
TBool CPMRfsPlugin::IsMMCFormatFlagEnabledL() { RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabledL()"); RFs rfs; User::LeaveIfError( rfs.Connect() ); CleanupClosePushL( rfs ); #ifndef RD_MULTIPLE_DRIVE TFileName fullPath; fullPath.Append( _L("e") ); fullPath.Append( MDriveColon ); fullPath.Append( KDMUtilServerPrivatePath ); fullPath.Append( KMMCEraseFlagFileName ); RFile file; TInt err = file.Open( rfs, fullPath, EFileRead ); file.Close(); CleanupStack::PopAndDestroy( &rfs ); if( err == KErrNone ) { RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: ETrue"); return ETrue; } RDEBUG_2("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: EFalse: %d)", err); return EFalse; #else TDriveList driveList; TInt driveCount; TBool fileReplace = EFalse; TInt err = KErrNone; //Get all removeable drive, both physically and logically User::LeaveIfError(DriveInfo::GetUserVisibleDrives( rfs, driveList, driveCount, KDriveAttRemovable )); TInt max(driveList.Length()); RFileWriteStream file; for(TInt i=0; i<max;++i) { if (driveList[i]) { TUint status; DriveInfo::GetDriveStatus(rfs, i, status); //To make sure the drive is physically removeable not logically removeable //need to format internal mass memory also. So no need to check the below condition //if (status & DriveInfo::EDriveRemovable) { TChar driveLetter; rfs.DriveToChar(i,driveLetter); TFileName fullPath; fullPath.Append( driveLetter ); fullPath.Append( MDriveColon ); fullPath.Append( KDMUtilServerPrivatePath ); fullPath.Append( KMMCEraseFlagFileName ); RFile flagfile; err = flagfile.Open( rfs, fullPath, EFileRead ); flagfile.Close(); if( err == KErrNone ) { if (!fileReplace) { User::LeaveIfError(file.Temp(rfs, _L("C:\\"),iFileName, EFileWrite)); file.WriteInt16L(65279); CleanupClosePushL(file); fileReplace = ETrue; RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabled() - File created on private path"); } file.WriteL(_L("FORMAT")); file.WriteL(_L(" ")); TBuf<4> DriveLetterBuf; DriveLetterBuf.Append(driveLetter); file.WriteL(DriveLetterBuf); file.WriteL(_L(":")); file.WriteL(_L("\r\n")); } } } } if (fileReplace) { file.CommitL(); CleanupStack::PopAndDestroy(); // pop file } CleanupStack::PopAndDestroy( &rfs ); if (fileReplace) { RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: ETrue:"); return ETrue; } else { RDEBUG_2("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: EFalse: %d)", err); return EFalse; } #endif //RD_MULTIPLE_DRIVE }
/*enumerate directories*/ GF_EXPORT GF_Err gf_enum_directory(const char *dir, Bool enum_directory, gf_enum_dir_item enum_dir_fct, void *cbck, const char *filter) { #ifdef WIN32 wchar_t item_path[GF_MAX_PATH]; #else char item_path[GF_MAX_PATH]; #endif GF_FileEnumInfo file_info; #if defined(_WIN32_WCE) char _path[GF_MAX_PATH]; unsigned short path[GF_MAX_PATH]; unsigned short w_filter[GF_MAX_PATH]; char file[GF_MAX_PATH]; #elif defined(WIN32) wchar_t path[GF_MAX_PATH], *file; wchar_t w_filter[GF_MAX_PATH]; wchar_t w_dir[GF_MAX_PATH]; char *mbs_file, *mbs_item_path; #else char path[GF_MAX_PATH], *file; #endif #ifdef WIN32 WIN32_FIND_DATAW FindData; HANDLE SearchH; #else DIR *the_dir; struct dirent* the_file; struct stat st; #endif if (!dir || !enum_dir_fct) return GF_BAD_PARAM; if (filter && (!strcmp(filter, "*") || !filter[0])) filter=NULL; memset(&file_info, 0, sizeof(GF_FileEnumInfo) ); if (!strcmp(dir, "/")) { #if defined(WIN32) && !defined(_WIN32_WCE) u32 len; char *drives, *volume; len = GetLogicalDriveStrings(0, NULL); drives = (char*)gf_malloc(sizeof(char)*(len+1)); drives[0]=0; GetLogicalDriveStrings(len, drives); len = (u32) strlen(drives); volume = drives; file_info.directory = GF_TRUE; file_info.drive = GF_TRUE; while (len) { enum_dir_fct(cbck, volume, "", &file_info); volume += len+1; len = (u32) strlen(volume); } gf_free(drives); return GF_OK; #elif defined(__SYMBIAN32__) RFs iFs; TDriveList aList; iFs.Connect(); iFs.DriveList(aList); for (TInt i=0; i<KMaxDrives; i++) { if (aList[i]) { char szDrive[10]; TChar aDrive; iFs.DriveToChar(i, aDrive); sprintf(szDrive, "%c:", (TUint)aDrive); enum_dir_fct(cbck, szDrive, "", &file_info); } } iFs.Close(); FlushItemList(); return GF_OK; #endif } #if defined (_WIN32_WCE) switch (dir[strlen(dir) - 1]) { case '/': case '\\': sprintf(_path, "%s*", dir); break; default: sprintf(_path, "%s%c*", dir, GF_PATH_SEPARATOR); break; } CE_CharToWide(_path, path); CE_CharToWide((char *)filter, w_filter); #elif defined(WIN32) { const char* tmpdir = dir; gf_utf8_mbstowcs(w_dir, sizeof(w_dir), &tmpdir); } switch (w_dir[wcslen(w_dir) - 1]) { case '/': case '\\': swprintf(path, MAX_PATH, L"%s*", w_dir); break; default: swprintf(path, MAX_PATH, L"%s%c*", w_dir, GF_PATH_SEPARATOR); break; } { const char* tmpfilter = filter; gf_utf8_mbstowcs(w_filter, sizeof(w_filter), &tmpfilter); } #else strcpy(path, dir); if (path[strlen(path)-1] != '/') strcat(path, "/"); #endif #ifdef WIN32 SearchH= FindFirstFileW(path, &FindData); if (SearchH == INVALID_HANDLE_VALUE) return GF_IO_ERR; #if defined (_WIN32_WCE) _path[strlen(_path)-1] = 0; #else path[wcslen(path)-1] = 0; #endif while (SearchH != INVALID_HANDLE_VALUE) { #else the_dir = opendir(path); if (the_dir == NULL) { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] Cannot open directory %s for enumeration: %d\n", path, errno)); return GF_IO_ERR; } the_file = readdir(the_dir); while (the_file) { #endif memset(&file_info, 0, sizeof(GF_FileEnumInfo) ); #if defined (_WIN32_WCE) if (!wcscmp(FindData.cFileName, _T(".") )) goto next; if (!wcscmp(FindData.cFileName, _T("..") )) goto next; #elif defined(WIN32) if (!wcscmp(FindData.cFileName, L".")) goto next; if (!wcscmp(FindData.cFileName, L"..")) goto next; #else if (!strcmp(the_file->d_name, "..")) goto next; if (the_file->d_name[0] == '.') goto next; #endif #ifdef WIN32 file_info.directory = (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? GF_TRUE : GF_FALSE; if (!enum_directory && file_info.directory) goto next; if (enum_directory && !file_info.directory) goto next; #endif if (filter) { #if defined (_WIN32_WCE) short ext[30]; short *sep = wcsrchr(FindData.cFileName, (wchar_t) '.'); if (!sep) goto next; wcscpy(ext, sep+1); wcslwr(ext); if (!wcsstr(w_filter, ext)) goto next; #elif defined(WIN32) wchar_t ext[30]; wchar_t *sep = wcsrchr(FindData.cFileName, L'.'); if (!sep) goto next; wcscpy(ext, sep+1); wcslwr(ext); if (!wcsstr(w_filter, ext)) goto next; #else char ext[30]; char *sep = strrchr(the_file->d_name, '.'); if (!sep) goto next; strcpy(ext, sep+1); strlwr(ext); if (!strstr(filter, sep+1)) goto next; #endif } #if defined(WIN32) file_info.hidden = (FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? GF_TRUE : GF_FALSE; file_info.system = (FindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? GF_TRUE : GF_FALSE; file_info.size = MAXDWORD; file_info.size += 1; file_info.size *= FindData.nFileSizeHigh; file_info.size += FindData.nFileSizeLow; file_info.last_modified = (u64) ((*(LONGLONG *) &FindData.ftLastWriteTime - TIMESPEC_TO_FILETIME_OFFSET) / 10000000); #endif #if defined (_WIN32_WCE) CE_WideToChar(FindData.cFileName, file); strcpy(item_path, _path); strcat(item_path, file); #elif defined(WIN32) wcscpy(item_path, path); wcscat(item_path, FindData.cFileName); file = FindData.cFileName; #else strcpy(item_path, path); strcat(item_path, the_file->d_name); GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Checking file %s for enum\n", item_path)); if (stat( item_path, &st ) != 0) goto next; file_info.directory = ((st.st_mode & S_IFMT) == S_IFDIR) ? GF_TRUE : GF_FALSE; if (enum_directory && !file_info.directory) goto next; if (!enum_directory && file_info.directory) goto next; file_info.size = st.st_size; { struct tm _t = * gmtime(& st.st_mtime); file_info.last_modified = mktime(&_t); } file = the_file->d_name; if (file && file[0]=='.') file_info.hidden = 1; if (file_info.directory) { char * parent_name = strrchr(item_path, '/'); if (!parent_name) { file_info.drive = GF_TRUE; } else { struct stat st_parent; parent_name[0] = 0; if (stat(item_path, &st_parent) == 0) { if ((st.st_dev != st_parent.st_dev) || ((st.st_dev == st_parent.st_dev) && (st.st_ino == st_parent.st_ino))) { file_info.drive = GF_TRUE; } } parent_name[0] = '/'; } } #endif #ifdef WIN32 mbs_file = wcs_to_utf8(file); mbs_item_path = wcs_to_utf8(item_path); if (!mbs_file || !mbs_item_path) { if (mbs_file) gf_free(mbs_file); if (mbs_item_path) gf_free(mbs_item_path); return GF_IO_ERR; } if (enum_dir_fct(cbck, mbs_file, mbs_item_path, &file_info)) { BOOL ret = FindClose(SearchH); if (!ret) { DWORD err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[core] FindClose() in gf_enum_directory() returned(1) the following error code: %d\n", err)); } #else if (enum_dir_fct(cbck, file, item_path, &file_info)) { #endif break; } #ifdef WIN32 gf_free(mbs_file); gf_free(mbs_item_path); #endif next: #ifdef WIN32 if (!FindNextFileW(SearchH, &FindData)) { BOOL ret = FindClose(SearchH); if (!ret) { DWORD err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[core] FindClose() in gf_enum_directory() returned(2) the following error code: %d\n", err)); } break; } #else the_file = readdir(the_dir); #endif } #ifndef WIN32 closedir(the_dir); #endif return GF_OK; } GF_EXPORT u64 gf_ftell(FILE *fp) { #if defined(_WIN32_WCE) return (u64) ftell(fp); #elif defined(GPAC_CONFIG_WIN32) && !defined(__CYGWIN__) /* mingw or cygwin */ #if (_FILE_OFFSET_BITS >= 64) return (u64) ftello64(fp); #else return (u64) ftell(fp); #endif #elif defined(WIN32) return (u64) _ftelli64(fp); #elif defined(GPAC_CONFIG_LINUX) && !defined(GPAC_ANDROID) return (u64) ftello64(fp); #elif (defined(GPAC_CONFIG_FREEBSD) || defined(GPAC_CONFIG_DARWIN)) return (u64) ftello(fp); #else return (u64) ftell(fp); #endif } GF_EXPORT u64 gf_fseek(FILE *fp, s64 offset, s32 whence) { #if defined(_WIN32_WCE) return (u64) fseek(fp, (s32) offset, whence); #elif defined(GPAC_CONFIG_WIN32) && !defined(__CYGWIN__) /* mingw or cygwin */ #if (_FILE_OFFSET_BITS >= 64) return (u64) fseeko64(fp, offset, whence); #else return (u64) fseek(fp, (s32) offset, whence); #endif #elif defined(WIN32) return (u64) _fseeki64(fp, offset, whence); #elif defined(GPAC_CONFIG_LINUX) && !defined(GPAC_ANDROID) return fseeko64(fp, (off64_t) offset, whence); #elif (defined(GPAC_CONFIG_FREEBSD) || defined(GPAC_CONFIG_DARWIN)) return fseeko(fp, (off_t) offset, whence); #else return fseek(fp, (s32) offset, whence); #endif } GF_EXPORT FILE *gf_fopen(const char *file_name, const char *mode) { FILE *res = NULL; #if defined(WIN32) wchar_t *wname; wchar_t *wmode; wname = utf8_to_wcs(file_name); wmode = utf8_to_wcs(mode); if (!wname || !wmode) { if (wname) gf_free(wname); if (wmode) gf_free(wmode); return NULL; } res = _wfsopen(wname, wmode, _SH_DENYNO); gf_free(wname); gf_free(wmode); #elif defined(GPAC_CONFIG_LINUX) && !defined(GPAC_ANDROID) res = fopen64(file_name, mode); #elif (defined(GPAC_CONFIG_FREEBSD) || defined(GPAC_CONFIG_DARWIN)) res = fopen(file_name, mode); #else res = fopen(file_name, mode); #endif if (res) { gpac_file_handles++; GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] file %s opened in mode %s - %d file handles\n", file_name, mode, gpac_file_handles)); } else { if (strchr(mode, 'w') || strchr(mode, 'a')) { #if defined(WIN32) u32 err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] system failure for file opening of %s in mode %s: 0x%08x\n", file_name, mode, err)); #else GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] system failure for file opening of %s in mode %s: %d\n", file_name, mode, errno)); #endif } } return res; } GF_EXPORT s32 gf_fclose(FILE *file) { if (file) { assert(gpac_file_handles); gpac_file_handles--; } return fclose(file); } #if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! defined(_GNU_SOURCE) && !defined(WIN32) #define HAVE_STRERROR_R 1 #endif GF_EXPORT size_t gf_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { return fread(ptr, size, nmemb, stream); } GF_EXPORT size_t gf_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { size_t result = fwrite(ptr, size, nmemb, stream); if (result != nmemb) { #ifdef _WIN32_WCE GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Error writing data: %d blocks to write but %d blocks written\n", nmemb, result)); #else #if defined WIN32 && !defined(GPAC_CONFIG_WIN32) errno_t errno_save; _get_errno(&errno_save); #else int errno_save = errno; #endif //if (errno_save!=0) { #ifdef HAVE_STRERROR_R #define ERRSTR_BUF_SIZE 256 char errstr[ERRSTR_BUF_SIZE]; if(strerror_r(errno_save, errstr, ERRSTR_BUF_SIZE) != 0) { strerror_r(0, errstr, ERRSTR_BUF_SIZE); } #else char *errstr = (char*)strerror(errno_save); #endif GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Error writing data (%s): %d blocks to write but %d blocks written\n", errstr, nmemb, result)); } #endif } return result; }