|
Nokia N97 SDK Example Applications Guide |
Definition in file DriveInfo.cpp.
#include <f32file.h>
#include <bacline.h>
#include "CommonFramework.h"
Go to the source code of this file.
Defines |
|
| #define | ASCII_ZERO '0' |
Functions |
|
| void | PrintAllDrivesVolInfo () |
| void | PrintDriveVolInfo (TPtrC &drive) |
| void | PrintDriveInfo (TInt driveNumber) |
| void | FormatDriveInfo (TDes &aBuffer, const TDriveInfo aDriveInfo) |
| void | FormatVolumeInfo (TDes &aBuffer, const TVolumeInfo aVolumeInfo) |
| _LIT (KMessage,"Drive Info\n") | |
| _LIT (KValidDriveMsg,"\nValid drives as names (and as numbers) are:\n") | |
| _LIT (KDriveCharAndNum,"%c(%d) ") | |
| _LIT (KNewLine,"\n") | |
| _LIT (KAvailDriveMsg,"\nUsing DriveList(), available drives are:\n") | |
| _LIT (KDriveAtts," %c: %02x\n") | |
| void | WaitForKey () |
| LOCAL_C void | doExampleL () |
Variables |
|
| LOCAL_D RFs | fsSession |
|
|
shows all valid drive identifications and available drives in current device. Then drive and volume information are shown for each available drive with the help of PrintDriveInfo() Definition at line 81 of file DriveInfo.cpp. References console, and fsSession. Referenced by doExampleL(). 00082 { 00083 console->Printf(KMessage); 00084 00085 // Print the valid drives as characters and as numbers. 00086 // Then print the drive list (list of available drives), and 00087 // information about each drive in the list using Drive(). 00088 // Finally, print volume information. 00089 00090 console->Printf(KValidDriveMsg); 00091 00092 TInt driveNumber=EDriveA; 00093 TChar driveLetter; 00094 for (; driveNumber<=EDriveZ; ++driveNumber) 00095 { 00096 if (fsSession.IsValidDrive(driveNumber)) 00097 { 00098 fsSession.DriveToChar(driveNumber,driveLetter); 00099 fsSession.CharToDrive(driveLetter, driveNumber); 00100 console->Printf(KDriveCharAndNum, TUint(driveLetter), driveNumber); 00101 } 00102 } 00103 console->Printf(KNewLine); 00104 00105 // A TDriveList (the list of available drives), is an array of 00106 // 26 bytes. Each byte with a non zero value signifies that the 00107 // corresponding drive is available. 00108 // 00109 TDriveList drivelist; 00110 User::LeaveIfError(fsSession.DriveList(drivelist)); 00111 console->Printf(KAvailDriveMsg); 00112 for (driveNumber=EDriveA; driveNumber<=EDriveZ; ++driveNumber) 00113 { 00114 // if drive-list entry non-zero, drive is available 00115 if (drivelist[driveNumber]) 00116 { 00117 User::LeaveIfError(fsSession.DriveToChar(driveNumber,driveLetter)); 00118 // The following line prints the drive letter followed by the hex value 00119 // of the integer indicating that drive's attributes 00120 console->Printf(KDriveAtts,TUint(driveLetter), drivelist[driveNumber]); 00121 } 00122 } 00123 console->Printf(KNewLine); 00124 WaitForKey(); 00125 00126 for (driveNumber=EDriveA; driveNumber<=EDriveZ; ++driveNumber) 00127 { 00128 PrintDriveInfo( driveNumber ); 00129 } 00130 }
|
|
|
Parses given commandline argument and checks, whether specified drive is a valid one. Then drive and volume information are shown for the drive with the help of PrintDriveInfo()
Definition at line 141 of file DriveInfo.cpp. References fsSession. Referenced by doExampleL(). 00142 { 00143 _LIT(KInvalidDrive,"Drive %c is not available!\n"); 00144 _LIT(KInvalidArgument,"\nInvalid argument: %S (not a drive letter or number!)\n\n"); 00145 00146 TInt driveNumber = 0; 00147 TChar driveLetter; 00148 if ((drive.Length() == 1) && (TChar(drive[0]).IsAlpha())) 00149 { 00150 driveLetter = drive[0]; 00151 fsSession.CharToDrive(driveLetter, driveNumber); 00152 } 00153 else 00154 { 00155 // assumption: user gave a number as parameter. 00156 // no fancy parsing; just assume the parameter is ascii-number 00157 for (TInt i = 0; i<drive.Length(); ++i) 00158 { 00159 if (! TChar(drive[i]).IsDigit()) 00160 { 00161 console->Printf(KInvalidArgument, &drive); 00162 return; 00163 } 00164 driveNumber *= 10; 00165 driveNumber += drive[i] - ASCII_ZERO; 00166 } 00167 } 00168 00169 TDriveList drivelist; 00170 User::LeaveIfError(fsSession.DriveList(drivelist)); 00171 00172 // if drive-list entry non-zero, drive is available 00173 if (!drivelist[driveNumber]) 00174 { 00175 console->Printf(KInvalidDrive); 00176 return; 00177 } 00178 00179 PrintDriveInfo( driveNumber ); 00180 }
|
|
|
shows drive and volume information of the specified drive
Definition at line 187 of file DriveInfo.cpp. References console, FormatDriveInfo(), FormatVolumeInfo(), fsSession, and WaitForKey(). 00188 { 00189 _LIT(KDriveInfo,"\nDrive information for drive %c:\n%S"); 00190 _LIT(KVolInfo,"\nVolume information for drive %c:\n%S"); 00191 00192 TChar driveLetter; 00193 00194 // Print information about the drive 00195 TBuf<200> buffer; 00196 TDriveInfo driveInfo; 00197 fsSession.Drive(driveInfo, driveNumber); 00198 00199 // test whether drive is available. If not, return 00200 if (driveInfo.iDriveAtt == KDriveAbsent) 00201 { 00202 return; 00203 } 00204 00205 FormatDriveInfo(buffer, driveInfo); 00206 User::LeaveIfError(fsSession.DriveToChar(driveNumber, driveLetter)); 00207 console->Printf(KDriveInfo, TUint(driveLetter), &buffer); 00208 buffer.Zero(); 00209 WaitForKey(); 00210 00211 // Print volume information 00212 TVolumeInfo volumeInfo; 00213 TInt err=fsSession.Volume(volumeInfo, driveNumber); 00214 00215 // Volume() returns KErrNotReady if no volume present. 00216 // In this case, check next drive number 00217 if (err != KErrNotReady) 00218 { 00219 buffer.Zero(); 00220 FormatVolumeInfo(buffer, volumeInfo); 00221 console->Printf(KVolInfo, TUint(driveLetter), &buffer); 00222 WaitForKey(); 00223 } 00224 }
|
|
||||||||||||
|
Interprets passed drive information to user readable form
Definition at line 232 of file DriveInfo.cpp. Referenced by PrintDriveInfo(). 00233 { 00234 // Append battery, media and drive information to aBuffer 00235 // Define descriptor constants using the _LIT macro 00236 00237 _LIT(KFormatString,"iType=%02x\niBattery=%02x\niDriveAtt=%02x\niMediaAtt=%02x\n"); 00238 _LIT(KBatLow,"Battery low\n"); 00239 _LIT(KBatGood,"Battery good\n"); 00240 _LIT(KBatNotSupported,"Battery not supported\n"); 00241 _LIT(KNotPresent,"No media present\n"); 00242 _LIT(KFloppy,"Media is floppy disk\n"); 00243 _LIT(KHard,"Media is hard disk\n"); 00244 _LIT(KCDROM,"Media is CD-ROM\n"); 00245 _LIT(KRam,"Media is RAM\n"); 00246 _LIT(KFlash,"Media is flash\n"); 00247 _LIT(KRom,"Media is ROM\n"); 00248 _LIT(KRemote,"Media is remote\n"); 00249 _LIT(KNANDFlash,"Media is NAND flash\n"); 00250 _LIT(KUnknown,"Media unknown\n"); 00251 _LIT(KDriveAtts,"Drive attributes:"); 00252 _LIT(KLocal," local"); 00253 _LIT(KROMDrive," ROM"); 00254 _LIT(KRedirected," redirected"); 00255 _LIT(KSubstituted," substituted"); 00256 _LIT(KInternal," internal"); 00257 _LIT(KRemovable," removable"); 00258 _LIT(KMediaAtts,"\nMedia attributes:"); 00259 _LIT(KDynamic," dynamic"); 00260 _LIT(KDual," dual-density"); 00261 _LIT(KFormattable," formattable"); 00262 _LIT(KLockable," lockable"); 00263 _LIT(KLocked," locked"); 00264 _LIT(KHasPassword," has password"); 00265 _LIT(KWriteProtected," write-protected"); 00266 _LIT(KNewLine,"\n"); 00267 00268 // aBuffer.AppendFormat(KFormatString, TInt(aDriveInfo.iType), 00269 // TInt(aDriveInfo.iBattery), TInt(aDriveInfo.iDriveAtt), TInt(aDriveInfo.iMediaAtt)); 00270 00271 aBuffer.AppendFormat(KFormatString, aDriveInfo.iType, aDriveInfo.iBattery, 00272 aDriveInfo.iDriveAtt, aDriveInfo.iMediaAtt); 00273 switch (aDriveInfo.iType) 00274 { 00275 case EMediaNotPresent: 00276 aBuffer.Append(KNotPresent); 00277 break; 00278 case EMediaFloppy: 00279 aBuffer.Append(KFloppy); 00280 break; 00281 case EMediaHardDisk: 00282 aBuffer.Append(KHard); 00283 break; 00284 case EMediaCdRom: 00285 aBuffer.Append(KCDROM); 00286 break; 00287 case EMediaRam: 00288 aBuffer.Append(KRam); 00289 break; 00290 case EMediaFlash: 00291 aBuffer.Append(KFlash); 00292 break; 00293 case EMediaRom: 00294 aBuffer.Append(KRom); 00295 break; 00296 case EMediaRemote: 00297 aBuffer.Append(KRemote); 00298 break; 00299 case EMediaNANDFlash: 00300 aBuffer.Append(KNANDFlash); 00301 break; 00302 default: 00303 aBuffer.Append(KUnknown); 00304 } 00305 00306 switch (aDriveInfo.iBattery) 00307 { 00308 case EBatLow: 00309 aBuffer.Append(KBatLow); 00310 break; 00311 case EBatGood: 00312 aBuffer.Append(KBatGood); 00313 break; 00314 default: 00315 aBuffer.Append(KBatNotSupported); 00316 } 00317 00318 aBuffer.Append(KDriveAtts); 00319 if (aDriveInfo.iDriveAtt & KDriveAttLocal) 00320 aBuffer.Append(KLocal); 00321 if (aDriveInfo.iDriveAtt & KDriveAttRom) 00322 aBuffer.Append(KROMDrive); 00323 if (aDriveInfo.iDriveAtt & KDriveAttRedirected) 00324 aBuffer.Append(KRedirected); 00325 if (aDriveInfo.iDriveAtt & KDriveAttSubsted) 00326 aBuffer.Append(KSubstituted); 00327 if (aDriveInfo.iDriveAtt & KDriveAttInternal) 00328 aBuffer.Append(KInternal); 00329 if (aDriveInfo.iDriveAtt & KDriveAttRemovable) 00330 aBuffer.Append(KRemovable); 00331 00332 aBuffer.Append(KMediaAtts); 00333 if (aDriveInfo.iMediaAtt & KMediaAttVariableSize) 00334 aBuffer.Append(KDynamic); 00335 if (aDriveInfo.iMediaAtt & KMediaAttDualDensity) 00336 aBuffer.Append(KDual); 00337 if (aDriveInfo.iMediaAtt & KMediaAttFormattable) 00338 aBuffer.Append(KFormattable); 00339 if (aDriveInfo.iMediaAtt & KMediaAttWriteProtected) 00340 aBuffer.Append(KWriteProtected); 00341 if (aDriveInfo.iMediaAtt & KMediaAttLockable) 00342 aBuffer.Append(KLockable); 00343 if (aDriveInfo.iMediaAtt & KMediaAttLocked) 00344 aBuffer.Append(KLocked); 00345 if (aDriveInfo.iMediaAtt & KMediaAttHasPassword) 00346 aBuffer.Append(KHasPassword); 00347 aBuffer.Append(KNewLine); 00348 }
|
|
||||||||||||
|
Interprets passed volume information to user readable form
Definition at line 356 of file DriveInfo.cpp. Referenced by PrintDriveInfo(). 00357 { 00358 // Append volume information to aBuffer 00359 _LIT(KUID, "Unique ID : %08x\n"); 00360 _LIT(KSize, "Size : %Ld bytes\n"); 00361 _LIT(KFree, "Free space : %Ld bytes\n"); 00362 _LIT(KVolName, "Volume name: %S\n"); 00363 aBuffer.AppendFormat(KUID, aVolumeInfo.iUniqueID); 00364 aBuffer.AppendFormat(KSize, aVolumeInfo.iSize); 00365 aBuffer.AppendFormat(KFree, aVolumeInfo.iFree); 00366 aBuffer.AppendFormat(KVolName, &aVolumeInfo.iName); 00367 }
|
|
|
main-function of the DriveInfo console application checks commandline arguments and then displays drive information either for all available drives or the ones specified in commandline Definition at line 49 of file DriveInfo.cpp. References fsSession, PrintAllDrivesVolInfo(), and PrintDriveVolInfo(). Referenced by callExampleL(). 00050 { 00051 CCommandLineArguments *cmdline = CCommandLineArguments::NewLC(); 00052 00053 // Connect to file server 00054 User::LeaveIfError(fsSession.Connect()); // Start session 00055 CleanupClosePushL( fsSession ); 00056 00057 TInt count = cmdline->Count(); 00058 if (count > 1) 00059 { 00060 // skip commandline argument 0, because that is the name of the exe 00061 for (TInt i=1; i<count; ++i) 00062 { 00063 TPtrC arg = cmdline->Arg(i); 00064 PrintDriveVolInfo(arg); 00065 } 00066 } 00067 else // show all 00068 { 00069 PrintAllDrivesVolInfo(); 00070 } 00071 00072 CleanupStack::PopAndDestroy(2, cmdline); // cmdline, fsSession 00073 }
|
|
© Nokia 2009 |