LOCAL_C void testTPtrLocateReverse() // // Test locating in reverse on an empty TPtr // { TPtrC a; test(a.LocateReverse('0')==KErrNotFound); test(a.LocateReverseF('0')==KErrNotFound); }
// -------------------------------------------------------------------------- // CImageCapture::GetNextFileNameLC // Get the file name // -------------------------------------------------------------------------- HBufC* CImageCapture::GetNextFileNameLC(const TDesC& aName) const { const TInt KNumberLength = 4; // this is to indicate the file numbering, // e.g. 0001, 0002, etc. const TInt KMaxIndex = 10000; const TInt KTimeRecordSize = 512; TPtrC filePathPtr; _LIT(KExtensionpng, ".png"); _LIT(KSlash,"\\"); // Gets the file extension. TPtrC fileExtension; fileExtension.Set(KExtensionpng); filePathPtr.Set(iSettings.iLogPath); TInt result = filePathPtr.LocateReverse('\\'); TPtrC string; if(result!=KErrNotFound) string.Set(filePathPtr.Left(result+1)); TBuf8<KTimeRecordSize> fileName; fileName.Copy(string); if(iXmlFileName.Length()>0) { TInt pos=iXmlFileName.LocateReverse('.'); TPtrC8 ptr; if(pos!=KErrNotFound) { ptr.Set(iXmlFileName.Left(pos)); fileName.Append(ptr); } fileName.Append(KSlash); } fileName.Append(aName); HBufC* newFileName = HBufC::NewLC(fileName.Length()+ KNumberLength + fileExtension.Length() + 1); TPtr newFileNamePtr(newFileName->Des()); newFileNamePtr.Copy(fileName); // Checks whether aNamexxxx.png already exists on the phone or not. // This is to prevent over-riding of any existing images with the same name TBool IsFileExist = ETrue; TInt index = 1; HBufC* buffer = HBufC::NewL(newFileNamePtr.MaxLength()); TPtr bufferPtr(buffer->Des()); while ((index < KMaxIndex) && (IsFileExist)) { bufferPtr.Copy(newFileNamePtr); bufferPtr.AppendNumFixedWidth(index, EDecimal, KNumberLength); bufferPtr.Append(fileExtension); if (BaflUtils::FileExists(CCoeEnv::Static()->FsSession(), *buffer)) { index++; } else { IsFileExist = EFalse; } } delete buffer; // If the index exceeds KMaxIndex, then we don't need to format the file name. if (index >= KMaxIndex) { newFileNamePtr.AppendNum(index); } else { newFileNamePtr.AppendNumFixedWidth(index, EDecimal, KNumberLength); } newFileNamePtr.Append(fileExtension); // If the index greated then KMaxIndex, then rollback to 1 if (index >= KMaxIndex) { index = 1; } return newFileName; }
// --------------------------------------------------------------------------- // Re-creates backed-up file in private directory. // --------------------------------------------------------------------------- // TInt CAknsSrvActiveBackupDataClient::RestoreFileInPrivateDirectoryL( const TDesC& aFileName ) { AKNS_TRACE_DEBUG("CAknsSrvActiveBackupDataClient::RestoreFileInPrivateDirectoryL" ); _LIT( KAknsStaticPath, "\\private\\10207114\\import" ); _LIT( KAknsSknExtension, ".SKN" ); TBool parseError = EFalse; TInt fileErr = KErrNone; HBufC* fileNameBuffer = HBufC::NewL( KMaxFileName ); TParsePtrC fileName( aFileName ); TPtr bufferPtr = fileNameBuffer->Des(); // First append drive and static path. if ( fileName.DrivePresent() ) { bufferPtr.Append( fileName.Drive() ); } else { AKNS_TRACE_DEBUG("CAknsSrvActiveBackupDataClient::RestoreFileInPrivateDirectoryL parse error1" ); parseError = ETrue; } if ( !parseError ) { bufferPtr.Append( KAknsStaticPath ); } if ( fileName.PathPresent() && !parseError ) { // Take path without the trailing backslash. TPtrC path = fileName.Path().Left( fileName.Path().Length() - 1 ); // Locate last backslash. TChar backslash('\\'); TInt bsLoc = path.LocateReverse( backslash ); // Append skin PID to the directory. bufferPtr.Append( fileName.Path().Mid( bsLoc ) ); if ( fileName.ExtPresent() ) { // Last, append filename. Now string is complete. bufferPtr.Append( fileName.NameAndExt() ); // switch the extension and check for file existance. bufferPtr.Replace( bufferPtr.Length() - KExtensionLength, KExtensionLength, KAknsSknExtension ); if ( !AknsSrvUtils::IsFile( iFsSession, bufferPtr ) ) { // There is no matching .skn-file, do not restore the graphics file. fileErr = KErrNotFound; } // switch back the graphics file extension. bufferPtr.Replace( bufferPtr.Length() - KExtensionLength, KExtensionLength, fileName.Ext() ); } else { AKNS_TRACE_DEBUG("CAknsSrvActiveBackupDataClient::RestoreFileInPrivateDirectoryL parse error2" ); parseError = ETrue; } } else { AKNS_TRACE_DEBUG("CAknsSrvActiveBackupDataClient::RestoreFileInPrivateDirectoryL parse error3" ); parseError = ETrue; } if( !parseError && fileErr == KErrNone ) { if ( AknsSrvUtils::IsFile( iFsSession, bufferPtr ) ) { // Do not restore, if the file already exists. fileErr = KErrAlreadyExists; } else { // Create the file. fileErr = iFile.Replace( iFsSession, bufferPtr, ( EFileWrite | EFileShareExclusive | EFileStream ) ); } } AKNS_TRACE_DEBUG1("CAknsSrvActiveBackupDataClient::RestoreFileInPrivateDirectoryL parse ret=%d", fileErr ); if ( fileErr != KErrNone ) { // If error creating or parsing the file, skip to next one. return fileErr; } if ( parseError ) { return KErrArgument; } return KErrNone; }
/** * Wraps the text and sets it into the labels. */ void CAknTextControl::ParseTextL(const CFont* aFont, CArrayFixFlat<TInt>* aLineWidths,const TWrapMethod& aWrapMethod) { if ( aWrapMethod == ENoAllocation && iWrappedArray ) { // We preallocate text required in construction of alert win, so we just replace the texts in labels. TPtrC remainder = Text(); TChar endlchar('\n'); TInt linebreak = remainder.LocateReverse(endlchar); TBuf<17 + KAknBidiExtraSpacePerLine> temp; //KEikAlertMaxMsgLength not declared in this scope if ( linebreak == KErrNotFound ) { AknBidiTextUtils::ConvertToVisualAndClip(remainder, temp, *aFont, KMaxTInt, KMaxTInt ); Line(0)->SetTextL(temp); // won't leave as there is enough space in buffer iLines[0]->iModified = ETrue; Line(1)->SetTextL(KNullDesC); iLines[1]->iModified = ETrue; } else { AknBidiTextUtils::ConvertToVisualAndClip( remainder.Left(linebreak), temp, *aFont, KMaxTInt, KMaxTInt ); Line(0)->SetTextL(temp); iLines[0]->iModified = ETrue; if ( remainder.Length()-1 == linebreak) // Line break is the last character { Line(1)->SetTextL(KNullDesC); } else { AknBidiTextUtils::ConvertToVisualAndClip( remainder.Right(remainder.Length()-linebreak-1), temp, *aFont, KMaxTInt, KMaxTInt ); Line(1)->SetTextL(temp); // we don't want new line to label, thus -1 } iLines[1]->iModified = ETrue; } return; } if (iTextIsAlreadyInLabel || !iWrappedArray) return; TInt maxLines = aLineWidths->Count(); // user handles all text processing if ( aWrapMethod == ENoProcessing ) { iWrappedArray->Reset(); TPtrC remainder = Text(); while ( remainder.Length() && iWrappedArray->Count() < maxLines ) { const TText* textArray = remainder.Ptr(); TInt textLength = remainder.Length(); TInt i = 0; for ( ; i < textLength ; i++ ) { TText t = textArray[i]; if ( t == KLineFeed || t == KLineSeparator || t == KParagraphSeparator || t == KCarriageReturn ) { break; } } iWrappedArray->AppendL( remainder.Left( i ) ); // After a CR, skip also possible matching LF if ( i < textLength - 1 && textArray[i] == KCarriageReturn && textArray[i + 1] == KLineFeed ) { i++; } i++; if ( i >= textLength ) { break; } remainder.Set( remainder.Right( textLength - i ) ); } } else { TPtr text = Text(); HBufC* visualBuffer = HBufC::NewLC( text.Length() + maxLines * KAknBidiExtraSpacePerLine ); *visualBuffer = text; TPtr ptr = visualBuffer->Des(); AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr); if (aWrapMethod == EWord) { AknBidiTextUtils::ConvertToVisualAndWrapToArrayL( ptr, *aLineWidths, *aFont, *iWrappedArray, ETrue ); } else if (aWrapMethod == ELine) { AknBidiTextUtils::ConvertToVisualAndChopToArrayL( ptr, *aLineWidths, *aFont, *iWrappedArray ); } else { __ASSERT_DEBUG(0,Panic(EAknPanicNotSupported)); } } TInt numLines = iWrappedArray->Count(); UpdateLabelsL(numLines,aFont,aLineWidths); SetWrappedTextIntoLabelsL(*iWrappedArray, numLines, aFont); if ( aWrapMethod != ENoProcessing ) { CleanupStack::PopAndDestroy(); // visualBuffer } }
TVerdict CForceRemove::doTestStepL() { #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK // Wait up to 30 seconds to ensure both SWIS and the sisregistry server // have shut down _LIT(KSisRegistryServerName, "!SisRegistryServer"); _LIT(KInstallServerName, "!InstallServer"); TInt delaytime = 30; while (delaytime-- > 0) { TFullName serverName; TFindServer find(KInstallServerName); if (KErrNotFound == find.Next(serverName)) { find.Find(KSisRegistryServerName); if (KErrNotFound == find.Next(serverName)) { break; } } User::After(1000000); // wait a second until the next test } #endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK TPtrC name; RTestUtilSessionSwi testutil; User::LeaveIfError(testutil.Connect()); CleanupClosePushL(testutil); // If file deletion fails we'll try moving the file to a temp directory // for another process to clean up later. TTime currentTime; currentTime.UniversalTime(); _LIT(KTempPathFormat, "\\temp\\%Lu"); TDriveUnit sysDrive (RFs::GetSystemDrive()); TBuf<128> tempPathFormat(sysDrive.Name()); tempPathFormat.Append(KTempPathFormat); TFileName targetPath; targetPath.Format(tempPathFormat, currentTime.Int64()); _LIT(KNumFiles, "numfiles"); #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK RArray<TUint> removeUids; CleanupClosePushL(removeUids); #endif TInt num(0); GetIntFromConfig(ConfigSection(), KNumFiles, num); // Get the file names and use testutil to remove them for (TInt i = 0; i < num; ++i) { _LIT(KFile, "file"); TBuf<32> key(KFile); key.AppendNum(i); if (!GetStringFromConfig(ConfigSection(), key, name)) continue; INFO_PRINTF2(_L("ForceRemove - trying to delete file %S"), &name); TInt err = testutil.Delete(name); if (err != KErrNone && err != KErrNotFound && err != KErrPathNotFound) { INFO_PRINTF3(_L("RTestUtilSessionSwi::Delete(%S) returned %d, attempting move instead."), &name, err); TFileName source(name); TParsePtr parse(source); TFileName dest(targetPath); dest.Append(parse.Path()); if (parse.DrivePresent()) { dest[0] = source[0]; } testutil.MkDirAll(dest); dest.Append(parse.NameAndExt()); err = testutil.Move(source, dest); if (err != KErrNone) { INFO_PRINTF4(_L("Attempt to move from %S to %S returned %d"), &source, &dest, err); } } #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK _LIT(KRegistryPath, "\\sys\\install\\sisregistry\\"); if (name.FindF(KRegistryPath) == KErrNotFound) continue; // Extract the uid and add it to our list TInt slashPos = name.LocateReverse('\\'); TPtrC ptrUid = name.Mid(slashPos + 1); if (ptrUid.Length() != 8) continue; TUint uid = 0; TLex lex(ptrUid); if (lex.Val(uid, EHex) == KErrNone) { removeUids.InsertInOrder(uid); // Will not allow duplicates } #endif } #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK // Use the sisregistry folder uid to remove the package entries from SCR // Note that we remove packages present in ROM too due to two reasons: // This is exactly what ForceRemove used to do (delete entire registry folder containing ALL reg files) // After deleting an entry SWIRegistry re-registers ROM apps (missing ones) TInt count = removeUids.Count(); RSisRegistryAccessSession regWrite; TInt err = regWrite.Connect(); User::LeaveIfError(err); CleanupClosePushL(regWrite); Swi::RSisRegistrySession regRead; User::LeaveIfError(regRead.Connect()); CleanupClosePushL(regRead); for (TInt i = 0; i < count; ++i) { TUid uid = TUid::Uid(removeUids[i]); Swi::RSisRegistryEntry entry; CleanupClosePushL(entry); if (entry.Open(regRead, uid) == KErrNone) { // Get its augmentations RPointerArray<Swi::CSisRegistryPackage> augmentations; CleanupResetAndDestroy<RPointerArray<Swi::CSisRegistryPackage> >::PushL(augmentations); entry.AugmentationsL(augmentations); TInt augCount = augmentations.Count(); for (TInt j = 0; j < augCount; ++j) { // Remove it TInt dummyTime; regWrite.DeleteEntryL(*augmentations[j], dummyTime); } // Finally remove the base package entry Swi::CSisRegistryPackage* package = entry.PackageL(); CleanupStack::PushL(package); TInt dummyTime; regWrite.DeleteEntryL(*package,dummyTime); CleanupStack::PopAndDestroy(2, &augmentations); // package } CleanupStack::PopAndDestroy(&entry); } CleanupStack::PopAndDestroy(3, &removeUids); // regWrite, regRead #endif CleanupStack::PopAndDestroy(&testutil); return EPass; }