sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @test sl@0: @internalComponent sl@0: sl@0: This contains CT_FsData sl@0: */ sl@0: sl@0: // User includes sl@0: #include "T_FsData.h" sl@0: #include "FileserverUtil.h" sl@0: sl@0: // EPOC includes sl@0: #include sl@0: sl@0: /*@{*/ sl@0: sl@0: // Parameters sl@0: _LIT(KAttMask, "attmask" ); sl@0: _LIT(KPath, "path"); sl@0: _LIT(KDrive, "drive"); sl@0: _LIT(KDir, "dir"); sl@0: _LIT(KFile, "file"); sl@0: _LIT(KName, "name"); sl@0: _LIT(KNewName, "newname"); sl@0: _LIT(KOldName, "oldname"); sl@0: _LIT(KLongName, "longname"); sl@0: _LIT(KShortName, "shortname"); sl@0: _LIT(KLengthBuffer, "length_buffer"); sl@0: _LIT(KLengthRead, "length_read"); sl@0: _LIT(KEntrySortKey, "sortkey"); sl@0: _LIT(KEntrySetAttMask, "setattmask"); sl@0: _LIT(KEntryClearAttMask, "clearattmask"); sl@0: _LIT(KTime, "time"); sl@0: _LIT(KOffset, "offset"); sl@0: _LIT(KTUidType, "uidtype"); sl@0: _LIT(KIsDirList, "isdirlist"); sl@0: _LIT(KRelated, "related"); sl@0: _LIT(KBadChar, "badchar"); sl@0: _LIT(KIsBadChar, "isbadchar"); sl@0: _LIT(KCompareName, "comparename"); sl@0: _LIT(KComparePath, "comparepath"); sl@0: _LIT(KParseName, "parsename"); sl@0: _LIT(KParseDrive, "parsedrive"); sl@0: _LIT(KParsePath, "parsepath"); sl@0: _LIT(KParseExt, "parseext"); sl@0: _LIT(KIsExist, "isexist"); sl@0: _LIT(KIsSetAtt, "issetatt"); sl@0: _LIT(KSize, "size"); sl@0: _LIT(KIsOpen, "isopen"); sl@0: _LIT(KIsValid, "isvalid"); sl@0: _LIT(KIsInRom, "isinrom"); sl@0: _LIT(KDirEntryArray, "dirEntryObject"); sl@0: _LIT(KDirDirectoryArray, "dirDirectoryObject"); sl@0: _LIT(KObjectEntry, "entry" ); sl@0: sl@0: // Attributes for compare sl@0: _LIT(KIsAttReadOnly, "isattreadonly"); sl@0: _LIT(KIsAttHidden, "isatthidden"); sl@0: _LIT(KIsAttSystem, "isattsystem"); sl@0: _LIT(KIsAttDir, "isattdir"); sl@0: _LIT(KIsAttArchive, "isattarchive"); sl@0: _LIT(KIsAttAllowUid, "isattuid"); sl@0: sl@0: // Commands sl@0: _LIT(KCmdRealName, "RealName"); sl@0: _LIT(KCmdSessionPath, "SessionPath"); sl@0: _LIT(KCmdSetSessionPath, "SetSessionPath"); sl@0: _LIT(KCmdParse, "Parse"); sl@0: _LIT(KCmdMkDir, "MkDir"); sl@0: _LIT(KCmdMkDirAll, "MkDirAll"); sl@0: _LIT(KCmdRmDir, "RmDir"); sl@0: _LIT(KCmdGetDir, "GetDir"); sl@0: _LIT(KCmdDelete, "Delete"); sl@0: _LIT(KCmdRename, "Rename"); sl@0: _LIT(KCmdReplace, "Replace"); sl@0: _LIT(KCmdAtt, "Att"); sl@0: _LIT(KCmdSetAtt, "SetAtt"); sl@0: _LIT(KCmdModified, "Modified"); sl@0: _LIT(KCmdSetModified, "SetModified"); sl@0: _LIT(KCmdEntry, "Entry"); sl@0: _LIT(KCmdSetEntry, "SetEntry"); sl@0: _LIT(KCmdReadFileSection, "ReadFileSection"); sl@0: _LIT(KCmdIsFileOpen, "IsFileOpen"); sl@0: _LIT(KCmdGetShortName, "GetShortName"); sl@0: _LIT(KCmdGetLongName, "GetLongName"); sl@0: _LIT(KCmdIsFileInRom, "IsFileInRom"); sl@0: _LIT(KCmdIsValidName, "IsValidName"); sl@0: _LIT(KCmdSetSessionToPrivate, "SetSessionToPrivate"); sl@0: _LIT(KCmdPrivatePath, "PrivatePath"); sl@0: _LIT(KCmdCreatePrivatePath, "CreatePrivatePath"); sl@0: sl@0: // Sort key sl@0: _LIT(KESortNone, "ESortNone"); sl@0: _LIT(KESortByName, "ESortByName"); sl@0: _LIT(KESortByExt, "ESortByExt"); sl@0: _LIT(KESortBySize, "ESortBySize"); sl@0: _LIT(KESortByDate, "ESortByDate"); sl@0: _LIT(KESortByUid, "ESortByUid"); sl@0: _LIT(KEDirsAnyOrder, "EDirsAnyOrder"); sl@0: _LIT(KEDirsFirst, "EDirsFirst"); sl@0: _LIT(KEDirsLast, "EDirsLast"); sl@0: _LIT(KEAscending, "EAscending"); sl@0: _LIT(KEDescending, "EDescending"); sl@0: _LIT(KEDirDescending, "EDirDescending"); sl@0: sl@0: // Attributes sl@0: _LIT(KEntryAttUnknown, "KEntryAttUnknown"); sl@0: _LIT(KEntryAttReadOnlyStr, "KEntryAttReadOnly"); sl@0: _LIT(KEntryAttHiddenStr, "KEntryAttHidden"); sl@0: _LIT(KEntryAttSystemStr, "KEntryAttSystem"); sl@0: _LIT(KEntryAttVolumeStr, "KEntryAttVolume"); sl@0: _LIT(KEntryAttDirStr, "KEntryAttDir"); sl@0: _LIT(KEntryAttArchiveStr, "KEntryAttArchive"); sl@0: _LIT(KEntryAttAllowUidStr, "KEntryAttAllowUid"); sl@0: _LIT(KEntryAttXIPStr, "KEntryAttXIP"); sl@0: sl@0: // Constants sl@0: _LIT(KTimeFormat, "%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B"); //SIZE 30 sl@0: #define KTimeFormatSize 30 sl@0: #define KShortNameSize 13 sl@0: #define KLongNameSize 256 sl@0: sl@0: /*@}*/ sl@0: sl@0: /** sl@0: * Process a files related command read from the ini file sl@0: * sl@0: * @param aCommand the command to process sl@0: * @param aSection the entry in the ini file requiring the command to be processed sl@0: * sl@0: * @return ETrue if the command is processed sl@0: */ sl@0: TBool CT_FsData::DoCommandFilesL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aSynchronous*/) sl@0: { sl@0: TBool retVal = ETrue; sl@0: sl@0: if (aCommand == KCmdAtt) sl@0: { sl@0: DoCmdAtt(aSection); sl@0: } sl@0: else if (aCommand == KCmdCreatePrivatePath) sl@0: { sl@0: DoCmdCreatePrivatePath(aSection); sl@0: } sl@0: else if (aCommand == KCmdDelete) sl@0: { sl@0: DoCmdDelete(aSection); sl@0: } sl@0: else if (aCommand == KCmdEntry) sl@0: { sl@0: DoCmdEntryL(aSection); sl@0: } sl@0: else if (aCommand == KCmdGetDir) sl@0: { sl@0: DoCmdGetDir(aSection); sl@0: } sl@0: else if (aCommand == KCmdGetShortName) sl@0: { sl@0: DoCmdGetShortName(aSection); sl@0: } sl@0: else if (aCommand == KCmdGetLongName) sl@0: { sl@0: DoCmdGetLongName(aSection); sl@0: } sl@0: else if (aCommand == KCmdIsFileInRom) sl@0: { sl@0: DoCmdIsFileInRom(aSection); sl@0: } sl@0: else if (aCommand == KCmdIsFileOpen) sl@0: { sl@0: DoCmdIsFileOpen(aSection); sl@0: } sl@0: else if (aCommand == KCmdIsValidName) sl@0: { sl@0: DoCmdIsValidName(aSection); sl@0: } sl@0: else if (aCommand == KCmdMkDir) sl@0: { sl@0: DoCmdMkDir(aSection); sl@0: } sl@0: else if (aCommand == KCmdMkDirAll) sl@0: { sl@0: DoCmdMkDirAll(aSection); sl@0: } sl@0: else if (aCommand == KCmdModified) sl@0: { sl@0: DoCmdModified(aSection); sl@0: } sl@0: else if (aCommand == KCmdParse) sl@0: { sl@0: DoCmdParse(aSection); sl@0: } sl@0: else if (aCommand == KCmdPrivatePath) sl@0: { sl@0: DoCmdPrivatePath(aSection); sl@0: } sl@0: else if (aCommand == KCmdReadFileSection) sl@0: { sl@0: DoCmdReadFileSectionL(aSection); sl@0: } sl@0: else if (aCommand == KCmdRealName) sl@0: { sl@0: DoCmdRealName(aSection); sl@0: } sl@0: else if (aCommand == KCmdRename) sl@0: { sl@0: DoCmdRename(aSection); sl@0: } sl@0: else if (aCommand == KCmdReplace) sl@0: { sl@0: DoCmdReplace(aSection); sl@0: } sl@0: else if (aCommand == KCmdRmDir) sl@0: { sl@0: DoCmdRmDir(aSection); sl@0: } sl@0: else if (aCommand == KCmdSessionPath) sl@0: { sl@0: DoCmdSessionPath(aSection); sl@0: } sl@0: else if (aCommand == KCmdSetAtt) sl@0: { sl@0: DoCmdSetAtt(aSection); sl@0: } sl@0: else if (aCommand == KCmdSetEntry) sl@0: { sl@0: DoCmdSetEntry(aSection); sl@0: } sl@0: else if (aCommand == KCmdSetModified) sl@0: { sl@0: DoCmdSetModified(aSection); sl@0: } sl@0: else if (aCommand == KCmdSetSessionPath) sl@0: { sl@0: DoCmdSetSessionPath(aSection); sl@0: } sl@0: else if (aCommand == KCmdSetSessionToPrivate) sl@0: { sl@0: DoCmdSetSessionToPrivate(aSection); sl@0: } sl@0: else sl@0: { sl@0: retVal = EFalse; sl@0: } sl@0: sl@0: return retVal; sl@0: } sl@0: sl@0: void CT_FsData::DoCmdRealName(const TDesC& aSection) sl@0: { sl@0: // Gets name of file from ini file. sl@0: TPtrC name; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: // Gets the real name of a file. sl@0: TFileName realName; sl@0: TInt err = iFs->RealName(name, realName); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("RealName error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: // Prints real name. sl@0: INFO_PRINTF2(_L("Real name: %S"), &realName); sl@0: sl@0: // Compares realname from ini file and realname from function. sl@0: TPtrC compareName; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KCompareName(), aSection, compareName)) sl@0: { sl@0: if (compareName.CompareC(realName, 0, NULL) != 0) sl@0: { sl@0: ERR_PRINTF3(_L("Error compare %S != %S"), &realName, &compareName); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("%S == %S"), &realName, &compareName); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdSessionPath(const TDesC& aSection) sl@0: { sl@0: // Gets the session path. sl@0: TBuf path; sl@0: TInt err = iFs->SessionPath(path); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("SessionPath error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: // Prints session path. sl@0: INFO_PRINTF2(_L("Session path is %S"), &path); sl@0: sl@0: // Compares path from ini file and path from function. sl@0: TPtrC comparePath; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KComparePath(), aSection, comparePath)) sl@0: { sl@0: if (comparePath.CompareC(path, 0, NULL) != 0) sl@0: { sl@0: ERR_PRINTF3(_L("Error compare %S != %S"), &path, &comparePath); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("%S == %S"), &path, &comparePath); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdSetSessionPath(const TDesC& aSection) sl@0: { sl@0: // Gets path from ini file. sl@0: TPtrC path; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KPath(), aSection, path)) sl@0: { sl@0: // Sets the session path for the current file server client. sl@0: TInt err = iFs->SetSessionPath(path); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("SetSessionPath error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: // Prints session path. sl@0: INFO_PRINTF2(_L("Path is set into %S"), &path); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdParse(const TDesC& aSection) sl@0: { sl@0: // Gets name of file from ini file. sl@0: TPtrC name; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: TInt err; sl@0: TParse parse; sl@0: TPtrC related; sl@0: sl@0: // Reads the related file specification. sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KRelated(), aSection, related)) sl@0: { sl@0: INFO_PRINTF2(_L("Related parameter: %S"), &related); sl@0: sl@0: // Parses a filename specification, specifying related file path components. sl@0: err = iFs->Parse(name, related, parse); sl@0: } sl@0: else sl@0: { sl@0: // Parses a filename specification. sl@0: err = iFs->Parse(name, parse); sl@0: } sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Parse error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: // Writes parsed components to log file. sl@0: TPtrC parsedResult[] = sl@0: { sl@0: parse.Drive(), //parsedDrive, sl@0: parse.Path(), //parsedPath, sl@0: parse.Name(), //parsedName, sl@0: parse.Ext() //parsedExt, sl@0: };// size 4 sl@0: sl@0: TBuf tempStore; sl@0: tempStore.Format(_L("Parsed %S, Drive: %S, Path: %S, Name: %S, Ext: %S"), &name, sl@0: &parsedResult[0], //Drive sl@0: &parsedResult[1], //Path sl@0: &parsedResult[2], //Name sl@0: &parsedResult[3]);//Ext sl@0: INFO_PRINTF1(tempStore); sl@0: sl@0: sl@0: // Compares parsed components from ini file. sl@0: TPtrC iniParsed[] = sl@0: { sl@0: KParseDrive(), sl@0: KParsePath(), sl@0: KParseName(), sl@0: KParseExt() sl@0: };// size 4 sl@0: sl@0: TInt size = sizeof(iniParsed) / sizeof(TPtrC); sl@0: for (TInt i = 0; i < size; i++) sl@0: { sl@0: // Reads components from ini sl@0: TPtrC compareName; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(iniParsed[i], aSection, compareName)) sl@0: { sl@0: if (parsedResult[i].CompareC(compareName, 0, NULL) != 0) sl@0: { sl@0: ERR_PRINTF3(_L("Error compare %S != %S"), &parsedResult[i], &compareName); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("%S == %S"), &parsedResult[i], &compareName); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdMkDir(const TDesC& aSection) sl@0: { sl@0: // Gets name of directiry from ini file. sl@0: TPtrC dir; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KDir(), aSection, dir)) sl@0: { sl@0: // Makes a directory. sl@0: TInt err = iFs->MkDir(dir); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("MkDir error %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdMkDirAll(const TDesC& aSection) sl@0: { sl@0: // Gets name of directiry from ini file. sl@0: TPtrC dir; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KDir(), aSection, dir)) sl@0: { sl@0: // Makes one or more directories. sl@0: TInt err = iFs->MkDirAll(dir); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("MkDirAll error %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdRmDir(const TDesC& aSection) sl@0: { sl@0: // Gets name of directiry from ini file. sl@0: TPtrC dir; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KDir(), aSection, dir)) sl@0: { sl@0: // Removes a directory. sl@0: TInt err = iFs->RmDir(dir); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("RmDir error %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdGetDir(const TDesC& aSection) sl@0: { sl@0: TBool dataOk = ETrue; sl@0: sl@0: // Reads name of directory from ini file. sl@0: TPtrC name; sl@0: if (!GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: // Reads sort key from ini file. sl@0: TPtrC entrySortKey; sl@0: TUint sortKey = ESortByName; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KEntrySortKey(), aSection, entrySortKey)) sl@0: { sl@0: if ( !ConvertToSortKey(entrySortKey, sortKey) ) sl@0: { sl@0: TInt intTemp; sl@0: if ( GET_MANDATORY_INT_PARAMETER(KEntrySortKey(), aSection, intTemp) ) sl@0: { sl@0: sortKey=intTemp; sl@0: } sl@0: else sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: // Reads attribute mask from ini file sl@0: // if not exist sl@0: // Reads uidtype from ini file sl@0: sl@0: TInt intUIDType = 0; sl@0: TUidType uidType = KNullUid; sl@0: TBool isUidType = EFalse; sl@0: sl@0: TUint attMask = KEntryAttNormal; sl@0: sl@0: TBool isDirList = FALSE; sl@0: sl@0: if (FileserverUtil::GetAttMask(*this, aSection, KAttMask(), attMask)) sl@0: { sl@0: // Reads boolean of dirlist from ini file. sl@0: GET_OPTIONAL_BOOL_PARAMETER(KIsDirList(), aSection, isDirList); sl@0: } sl@0: else if (GET_MANDATORY_INT_PARAMETER(KTUidType(), aSection, intUIDType)) sl@0: { sl@0: TUid id = TUid::Uid(intUIDType); sl@0: uidType = TUidType(id); sl@0: INFO_PRINTF2(_L("UID type set to %d"), uidType[0].iUid); sl@0: } sl@0: else sl@0: { sl@0: dataOk = EFalse; sl@0: ERR_PRINTF2(_L("attmask or %S must be declared !!!"), &KTUidType); sl@0: } sl@0: sl@0: // If all data was read sl@0: if (dataOk) sl@0: { sl@0: // Gets a filtered list of a directory's contents. sl@0: TInt err = KErrNone; sl@0: CT_DirData* dirWrapperEntry = NULL; sl@0: CT_DirData* dirWrapperDirectory = NULL; sl@0: CDir* entryArray = NULL; sl@0: CDir* dirArray = NULL; sl@0: TPtrC dirEntryArray; sl@0: TPtrC dirDirectoryArray; sl@0: sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KDirEntryArray(), aSection, dirEntryArray)) sl@0: { sl@0: TRAP(err, dirWrapperEntry = static_cast(GetDataWrapperL(dirEntryArray))); sl@0: } sl@0: sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KDirDirectoryArray(), aSection, dirDirectoryArray)) sl@0: { sl@0: TRAP(err, dirWrapperDirectory = static_cast(GetDataWrapperL(dirDirectoryArray))); sl@0: } sl@0: sl@0: if (isUidType) sl@0: { sl@0: // Gets a filtered list of a directory's contents by UID type. sl@0: err = iFs->GetDir(name, uidType, sortKey, entryArray); sl@0: } sl@0: else sl@0: { sl@0: if (isDirList) sl@0: { sl@0: // Gets a filtered list of the directory and file entries contained in a directory, sl@0: // and a list of the directory entries only. sl@0: err = iFs->GetDir(name, attMask, sortKey, entryArray, dirArray); sl@0: } sl@0: else sl@0: { sl@0: // Gets a filtered list of a directory's contents. sl@0: err = iFs->GetDir(name, attMask, sortKey, entryArray); sl@0: } sl@0: } sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("GetDir error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: // Writes sorted entries to log file. sl@0: INFO_PRINTF2(_L("PATH %S"), &name); sl@0: for (TInt i = 0; i < entryArray->Count(); i++) sl@0: { sl@0: TBuf tempStore; sl@0: tempStore.Format(_L("%d) %S"), i+1, &(*entryArray)[i].iName); sl@0: INFO_PRINTF1(tempStore); sl@0: } sl@0: sl@0: // If "_comparename" of parameter is set in INI file, then sl@0: // try to find this name in the list of entries. sl@0: TPtrC compareName; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KCompareName(), aSection, compareName)) sl@0: { sl@0: // Find compare name in list of entries. sl@0: TBool isFind = FALSE; sl@0: for (TInt i = 0; i < entryArray->Count(); i++) sl@0: { sl@0: if (compareName.CompareC((*entryArray)[i].iName, 0, NULL) == 0) sl@0: { sl@0: isFind = TRUE; sl@0: } sl@0: } sl@0: sl@0: // Reads a flag which specifies a name should be existing or not be existing sl@0: // specified in parameter "KCompareName". sl@0: TBool isExist = TRUE; sl@0: GET_OPTIONAL_BOOL_PARAMETER(KIsExist(), aSection, isExist); sl@0: sl@0: TPtrC strIsExist = isExist ? _L("EXIST") : _L("NOT EXIST"); sl@0: INFO_PRINTF3(_L("%S must be %S"), &compareName, &strIsExist); sl@0: sl@0: TPtrC strIsFind = isFind ? _L("FOUND") : _L("NOT FOUND"); sl@0: INFO_PRINTF3(_L("%S is %S"), &compareName, &strIsFind); sl@0: sl@0: // If name has been found when this name must not be existing sl@0: // or when name has been not found when name must be existing sl@0: // then test case fail. sl@0: if (isExist != isFind) sl@0: { sl@0: ERR_PRINTF1(_L("Expected exist does not match actual")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: // Delete list of data sl@0: if (entryArray) sl@0: { sl@0: if(dirWrapperEntry) sl@0: { sl@0: dirWrapperEntry->SetObjectL(entryArray); sl@0: } sl@0: else sl@0: { sl@0: delete entryArray; sl@0: entryArray = NULL; sl@0: } sl@0: } sl@0: if (dirArray) sl@0: { sl@0: if(dirWrapperDirectory) sl@0: { sl@0: dirWrapperDirectory->SetObjectL(dirArray); sl@0: } sl@0: else sl@0: { sl@0: delete dirArray; sl@0: dirArray = NULL; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdDelete(const TDesC& aSection) sl@0: { sl@0: // Reads name of file from ini file. sl@0: TPtrC name; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: // Deletes a single file. sl@0: TInt err = iFs->Delete(name); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Delete error %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdRename(const TDesC& aSection) sl@0: { sl@0: TBool dataOk=ETrue; sl@0: sl@0: // Reads the old name of file or directory from ini file. sl@0: TPtrC oldName; sl@0: if ( !GET_MANDATORY_STRING_PARAMETER(KOldName(), aSection, oldName) ) sl@0: { sl@0: dataOk=EFalse; sl@0: } sl@0: sl@0: // Reads the new name of file or directory from ini file. sl@0: TPtrC newName; sl@0: if ( !GET_MANDATORY_STRING_PARAMETER(KNewName(), aSection, newName) ) sl@0: { sl@0: dataOk=EFalse; sl@0: } sl@0: sl@0: if ( dataOk ) sl@0: { sl@0: // Renames a single file or directory. sl@0: TInt err = iFs->Rename(oldName, newName); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Rename error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("File %S was renamed to %S successfully"), &oldName, &newName); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdReplace(const TDesC& aSection) sl@0: { sl@0: TBool dataOk=ETrue; sl@0: sl@0: // Reads the old name of file from ini file. sl@0: TPtrC oldName; sl@0: if ( !GET_MANDATORY_STRING_PARAMETER(KOldName(), aSection, oldName) ) sl@0: { sl@0: dataOk=EFalse; sl@0: } sl@0: sl@0: // Reads the new name of file from ini file. sl@0: TPtrC newName; sl@0: if ( !GET_MANDATORY_STRING_PARAMETER(KNewName(), aSection, newName) ) sl@0: { sl@0: dataOk=EFalse; sl@0: } sl@0: sl@0: if ( dataOk ) sl@0: { sl@0: // Replaces a single file with another. sl@0: TInt err = iFs->Replace(oldName, newName); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Replace error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("File %S was replaced to %S successfully"), &oldName, &newName); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdAtt(const TDesC& aSection) sl@0: { sl@0: // Reads the name of file from ini file. sl@0: TPtrC name; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: // Gets a file's attributes. sl@0: TUint attValue; sl@0: TInt err = iFs->Att(name, attValue); sl@0: INFO_PRINTF2(_L("RFs::Att = 0x%X"), attValue); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Att error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: TUint arrAttMask[]= sl@0: { sl@0: KEntryAttReadOnly, sl@0: KEntryAttHidden, sl@0: KEntryAttSystem, sl@0: KEntryAttVolume, sl@0: KEntryAttDir, sl@0: KEntryAttArchive, sl@0: KEntryAttXIP sl@0: };//size 7 sl@0: sl@0: // Writes what attributes has a file. sl@0: INFO_PRINTF1(_L("--- START --- print all attributes")); sl@0: sl@0: TInt size = sizeof(arrAttMask) / sizeof(TUint); sl@0: for (TInt i = 0; i < size; i++) sl@0: { sl@0: if (attValue & arrAttMask[i]) sl@0: { sl@0: INFO_PRINTF2(_L("Attribute %S is set"), &ConvertToStrAttMask(arrAttMask[i])); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Attribute %S is not set"), &ConvertToStrAttMask(arrAttMask[i])); sl@0: } sl@0: } sl@0: INFO_PRINTF1(_L("--- END --- print all attributes")); sl@0: sl@0: // Reads atribute wich is testing. sl@0: TPtrC testAttMaskStr; sl@0: if(GET_OPTIONAL_STRING_PARAMETER(KEntrySetAttMask(), aSection, testAttMaskStr)) sl@0: { sl@0: TUint testAttMask = 0; sl@0: if (FileserverUtil::GetAttMask(*this, aSection, KEntrySetAttMask(), testAttMask)) sl@0: { sl@0: // Reads a flag which specifies a attribute should be set or not set sl@0: // specified in parameter "KEntrySetAttMask". sl@0: TBool testIsSet = TRUE; sl@0: if (GET_OPTIONAL_BOOL_PARAMETER(KIsSetAtt(), aSection, testIsSet)) sl@0: { sl@0: INFO_PRINTF2(_L("TEST attributes %S must be set"), &ConvertToStrAttMask(testAttMask)); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("TEST attributes %S must not be set"), &ConvertToStrAttMask(testAttMask)); sl@0: } sl@0: if ( (attValue&testAttMask)==testAttMask ) sl@0: { sl@0: if ( !testIsSet ) sl@0: { sl@0: ERR_PRINTF2(_L("All bits not set %S"), &ConvertToStrAttMask(testAttMask)); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: else if ( (attValue&testAttMask)==0 ) sl@0: { sl@0: if ( testIsSet ) sl@0: { sl@0: ERR_PRINTF2(_L("Some bits set %S"), &ConvertToStrAttMask(testAttMask)); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Some bits set %S"), &ConvertToStrAttMask(testAttMask)); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Unknown attribute!")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdSetAtt(const TDesC& aSection) sl@0: { sl@0: // Reads attributes to be set from ini file. sl@0: TUint setAttMask = 0; sl@0: sl@0: if (!FileserverUtil::GetAttMask(*this, aSection, KEntrySetAttMask(), setAttMask)) sl@0: { sl@0: ERR_PRINTF1(_L("Unknown attribute!")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: sl@0: // Reads attributes to be clear from ini file. sl@0: TUint clearAttMask = 0; sl@0: if (!FileserverUtil::GetAttMask(*this, aSection, KEntryClearAttMask(), clearAttMask)) sl@0: { sl@0: ERR_PRINTF1(_L("Unknown attribute!")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: sl@0: // Reads the name of file or directory from ini file. sl@0: TPtrC name; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: // Sets or clears the attributes of a single file or directory. sl@0: TInt err = iFs->SetAtt(name, setAttMask, clearAttMask); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("SetAtt error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("SetAtt() is successful")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdModified(const TDesC& aSection) sl@0: { sl@0: // Reads the name of file or directory from ini file. sl@0: TPtrC name; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: // Gets the last modification date and time of a file or a directory, in UTC. sl@0: TTime time; sl@0: TInt err = iFs->Modified(name, time); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Modified error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: // Write to log modified date and time. sl@0: TBuf dateString; sl@0: TRAP (err, time.FormatL(dateString, KTimeFormat)); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("time.FormatL() error %d"), err); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("File %S modified: %S"), &name, &dateString); sl@0: sl@0: // Reads time in ini file which must be returned from function "Modified()". sl@0: TPtrC inputTime; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KTime(), aSection, inputTime)) sl@0: { sl@0: // Convert input string in "KTime" from ini to TTime object. sl@0: // Assigns a date and time contained in a descriptor. sl@0: TTime iniTime; sl@0: TInt err = iniTime.Set(inputTime); sl@0: if (err == KErrNone) sl@0: { sl@0: // Compares time from ini file and time returned from function. sl@0: if (iniTime == time) sl@0: { sl@0: INFO_PRINTF1(_L("Time equal")); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF3(_L("Time not equal, %S != %S"), &inputTime, &dateString); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Fail set time, error %d"), err); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdSetModified(const TDesC& aSection) sl@0: { sl@0: // Reads the time from ini file. sl@0: TTime time(0); sl@0: TPtrC inputTime; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KTime(), aSection, inputTime)) sl@0: { sl@0: // Assigns a date and time contained in a descriptor. sl@0: TInt err = time.Set(inputTime); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Time set failed, error %d"), err); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: // Reads the name of file or directory from ini file. sl@0: TPtrC name; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: // Sets the date and time that the contents of a file or directory were modified, in UTC. sl@0: TInt err = iFs->SetModified(name, time); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("SetModified error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("SetModified() OK")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdEntryL(const TDesC& aSection) sl@0: { sl@0: TBool isEntryNew = EFalse; sl@0: sl@0: // Reads the name of file or directory from ini file. sl@0: TPtrC name; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: TEntry *entry = NULL; sl@0: sl@0: // Gets the entry details for a file or directory. sl@0: TPtrC entryObjectName; sl@0: if( GET_OPTIONAL_STRING_PARAMETER( KObjectEntry, aSection, entryObjectName ) ) sl@0: { sl@0: INFO_PRINTF1( _L( "Get TEntry class instance." ) ); sl@0: TRAPD( err, entry = (TEntry*)GetDataObjectL(entryObjectName)); sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF3( _L( "Unrecognized object name parameter value: %S. Error %d"), &entryObjectName, err ); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1( _L( "TEntry class instance accepted OK." ) ); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1( _L( "Create new temporary TEntry() class instance." ) ); sl@0: TRAPD( err, entry = new (ELeave) TEntry() ); sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2( _L( "new TEntry() error %d" ), err ); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: isEntryNew = ETrue; sl@0: } sl@0: } sl@0: sl@0: if ( entry != NULL ) sl@0: { sl@0: TInt err = iFs->Entry(name, *entry); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Entry error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: // Prints all entry details for the file or directory. sl@0: // and compares these entry fith entry in ini file sl@0: TPtrC arrNames[] = sl@0: { sl@0: KEntryAttDirStr(), sl@0: KEntryAttArchiveStr(), sl@0: KEntryAttHiddenStr(), sl@0: KEntryAttReadOnlyStr(), sl@0: KEntryAttSystemStr(), sl@0: KEntryAttAllowUidStr() sl@0: };//size 6 sl@0: sl@0: TInt64 arrFunctions[] = sl@0: { sl@0: entry->IsDir() > 0, sl@0: entry->IsArchive() > 0, sl@0: entry->IsHidden() > 0, sl@0: entry->IsReadOnly() > 0, sl@0: entry->IsSystem() > 0, sl@0: entry->IsTypeValid() > 0 sl@0: };//size 6 sl@0: sl@0: TPtrC iniParam[] = sl@0: { sl@0: KIsAttDir(), sl@0: KIsAttArchive(), sl@0: KIsAttHidden(), sl@0: KIsAttReadOnly(), sl@0: KIsAttSystem(), sl@0: KIsAttAllowUid(), sl@0: };//size 6 sl@0: sl@0: TInt size = sizeof(arrNames) / sizeof(TPtrC); sl@0: for (TInt i = 0; i < size; i++) sl@0: { sl@0: TBuf tempStore; sl@0: if (arrFunctions[i]) sl@0: { sl@0: tempStore.Format(_L("%S - attribute %S is SET"), &name, &arrNames[i]); sl@0: } sl@0: else sl@0: { sl@0: tempStore.Format(_L("%S - attribute %S is NOT SET"), &name, &arrNames[i]); sl@0: } sl@0: INFO_PRINTF1(tempStore); sl@0: sl@0: // If iniParam[] is set in ini then compare with attribute returned from function. sl@0: TBool iniCompare = FALSE; sl@0: if (GET_OPTIONAL_BOOL_PARAMETER(iniParam[i], aSection, iniCompare)) sl@0: { sl@0: // Compares entry in ini file and entry returned from function. sl@0: if (arrFunctions[i] != iniCompare) sl@0: { sl@0: ERR_PRINTF2(_L("Error compare attribute %S"), &iniParam[i]); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: // Prints size of file. sl@0: INFO_PRINTF3(_L("%S - size %d"), &name, entry->iSize); sl@0: sl@0: // Compare size of file returned from function with size from ini. sl@0: TInt iniSize = 0; sl@0: if (GET_OPTIONAL_INT_PARAMETER(KSize(), aSection, iniSize)) sl@0: { sl@0: if (entry->iSize != iniSize) sl@0: { sl@0: ERR_PRINTF3(_L("Size from ini file not equal with size returned from function (%d != %d)"), iniSize, entry->iSize); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: // Prints the system time of last modification. sl@0: TBuf dateString; sl@0: entry->iModified.FormatL(dateString, KTimeFormat); sl@0: INFO_PRINTF3(_L("%S - modified %S"), &name, &dateString); sl@0: sl@0: // Compare time from ini with time returned from function. sl@0: TPtrC iniTimeStr; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KTime(), aSection, iniTimeStr)) sl@0: { sl@0: // Assigns a date and time contained in a descriptor. sl@0: TTime iniTime; sl@0: sl@0: TInt error = iniTime.Set(iniTimeStr); sl@0: if(error == KErrNone) sl@0: { sl@0: // Compares size in ini file and size returned from function. sl@0: if (entry->iModified != iniTime) sl@0: { sl@0: ERR_PRINTF1(_L("Time from ini file not equal with time returned from function.")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF3(_L("Cannot convert %S to TTime type. Error: %d"), &iniTimeStr, error); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: // Prints the file's UIDtype. sl@0: INFO_PRINTF3(_L("%S - UIDtype %d"), &name, entry->MostDerivedUid().iUid); sl@0: sl@0: if (isEntryNew) sl@0: { sl@0: INFO_PRINTF1(_L("Delete temporary TEntry() class instance.")); sl@0: delete entry; sl@0: entry = NULL; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdSetEntry(const TDesC& aSection) sl@0: { sl@0: TBool dataOk=ETrue; sl@0: sl@0: TUint setAttMask = 0; sl@0: if (!FileserverUtil::GetAttMask(*this, aSection, KEntrySetAttMask(), setAttMask)) sl@0: { sl@0: dataOk = EFalse; sl@0: ERR_PRINTF1(_L("Unknown attribute!")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: sl@0: // Reads attributes to be clear from ini file. sl@0: TUint clearAttMask = 0; sl@0: if (!FileserverUtil::GetAttMask(*this, aSection, KEntryClearAttMask(), clearAttMask)) sl@0: { sl@0: dataOk = EFalse; sl@0: ERR_PRINTF1(_L("Unknown attribute!")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: // Reads the time from ini file. sl@0: TTime time(0); sl@0: TPtrC inputTime; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KTime(), aSection, inputTime)) sl@0: { sl@0: // Assigns a date and time contained in a descriptor. sl@0: TInt err = time.Set(inputTime); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Time set failed, error %d"), err); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: // Reads the name of file or directory from ini file. sl@0: TPtrC name; sl@0: if (!GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: if ( dataOk ) sl@0: { sl@0: // Sets both the attributes and the last modified date and time for a file or directory. sl@0: TInt err = iFs->SetEntry(name, time, setAttMask, clearAttMask); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("SetEntry error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("SetEntry() is successful.")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdReadFileSectionL(const TDesC& aSection) sl@0: { sl@0: TBuf tempStore; sl@0: TBool dataOk = ETrue; sl@0: sl@0: sl@0: // Reads the offset, in bytes, from the start of the file where reading is to start. sl@0: TInt offset = 0; sl@0: if (!GET_MANDATORY_INT_PARAMETER(KOffset(), aSection, offset)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: // Reads the number of bytes to be read from the file. sl@0: TInt lengthRead = 0; sl@0: if (!GET_MANDATORY_INT_PARAMETER(KLengthRead(), aSection, lengthRead)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: // Reads the number of bytes to be alocated. sl@0: TInt lengthBuffer = 0; sl@0: if (!GET_MANDATORY_INT_PARAMETER(KLengthBuffer(), aSection, lengthBuffer)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: // Reads the name of file from ini file. sl@0: TPtrC name; sl@0: if (!GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: if ( dataOk ) sl@0: { sl@0: // Creates 8-bit heap descriptor. sl@0: HBufC8* buffer = NULL; sl@0: TRAPD (err, buffer = HBufC8::NewL(lengthBuffer)); sl@0: if (err == KErrNone) sl@0: { sl@0: // Pushes descriptor onto the cleanup stack. sl@0: CleanupStack::PushL(buffer); sl@0: sl@0: // Create memory for 16-bit bufer. sl@0: HBufC* buffer16 = NULL; sl@0: TRAP (err, buffer16 = HBufC::NewL(lengthBuffer)); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("The 16-bit heap descriptor cannot be created, err %d"), err); sl@0: SetBlockResult(EFail); sl@0: CleanupStack::PopAndDestroy(buffer); sl@0: } sl@0: else sl@0: { sl@0: // Pushes descriptor onto the cleanup stack. sl@0: CleanupStack::PushL(buffer16); sl@0: sl@0: // Reads data from a file without opening it. sl@0: TPtr8 bufferPtr = buffer->Des(); sl@0: err = iFs->ReadFileSection(name, offset, bufferPtr, lengthRead); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("ReadFileSection error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: // Writes data from a file. sl@0: tempStore.Format(_L("The data from a file %S, offset =%d, length_buffer =%d, length_read =%d"), &name, offset, lengthBuffer, lengthRead); sl@0: INFO_PRINTF1(tempStore); sl@0: // Converts 8-bit to 16-bit. sl@0: buffer16->Des().Copy(bufferPtr); sl@0: TPtr16 bufferPtr16 = buffer16->Des(); sl@0: INFO_PRINTF2(_L("%S"), &bufferPtr16); sl@0: } sl@0: sl@0: // Clean memory buffer and buffer16 sl@0: CleanupStack::PopAndDestroy(2, buffer); // buffer, buffer16. sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("The 8-bit heap descriptor cannot be created, err %d"), err); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdIsFileOpen(const TDesC& aSection) sl@0: { sl@0: // Reads the name of file from ini file. sl@0: TPtrC file; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, file)) sl@0: { sl@0: // Tests whether a file is open. sl@0: TBool isOpen; sl@0: TInt err = iFs->IsFileOpen(file, isOpen); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("IsFileOpen error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: if (isOpen) sl@0: { sl@0: INFO_PRINTF2(_L("The File %S is OPEN"), &file); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("The FILE %S is CLOSED"), &file); sl@0: } sl@0: sl@0: // Compare parameter from ini sl@0: TBool iniIsOpen; sl@0: if (GET_OPTIONAL_BOOL_PARAMETER(KIsOpen(), aSection, iniIsOpen)) sl@0: { sl@0: if (isOpen != iniIsOpen) sl@0: { sl@0: ERR_PRINTF2(_L("Error compare parameter %S"), &KIsOpen); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdGetShortName(const TDesC& aSection) sl@0: { sl@0: // Reads the long name of file from ini file. sl@0: TPtrC longName; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KLongName(), aSection, longName)) sl@0: { sl@0: // Gets the short filename associated with a VFAT long filename. sl@0: TBuf shortName; sl@0: TInt err = iFs->GetShortName(longName, shortName); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("GetShortName error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Short name: %S"), &shortName); sl@0: sl@0: // Compares name from ini file and name from function. sl@0: TPtrC compareName; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KShortName(), aSection, compareName)) sl@0: { sl@0: if (shortName.CompareC(compareName, 0, NULL) != 0) sl@0: { sl@0: ERR_PRINTF3(_L("%S != %S"), &shortName, &compareName); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("%S == %S"), &shortName, &compareName); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdGetLongName(const TDesC& aSection) sl@0: { sl@0: // Reads the short name of file from ini file. sl@0: TPtrC shortName; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KShortName(), aSection, shortName)) sl@0: { sl@0: // Gets the long filename associated with a short (8.3) filename. sl@0: TBuf longName; sl@0: TInt err = iFs->GetLongName(shortName, longName); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("GetLongName error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Long name: %S"), &longName); sl@0: sl@0: // Compares name from ini file and name from function. sl@0: TPtrC compareName; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KLongName(), aSection, compareName)) sl@0: { sl@0: if (longName.CompareC(compareName, 0, NULL) != 0) sl@0: { sl@0: ERR_PRINTF3(_L("%S != %S"), &longName, &compareName); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("%S == %S"), &longName, &compareName); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdIsFileInRom(const TDesC& aSection) sl@0: { sl@0: // Reads the name of file from ini file. sl@0: TPtrC file; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, file)) sl@0: { sl@0: // Gets a pointer to the specified file, if it is in ROM. sl@0: iIsFileInRom=iFs->IsFileInRom(file); sl@0: INFO_PRINTF2(_L("Fs->IsFileInRom = 0x%X"), iIsFileInRom); sl@0: sl@0: TBool isInROM = (iIsFileInRom!=NULL); sl@0: if ( isInROM ) sl@0: { sl@0: INFO_PRINTF2(_L("File %S in ROM"), &file); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("File %S not in ROM"), &file); sl@0: } sl@0: sl@0: // Compare parameter from ini sl@0: TBool iniIsInROM = FALSE; sl@0: if (GET_OPTIONAL_BOOL_PARAMETER(KIsInRom(), aSection, iniIsInROM)) sl@0: { sl@0: if (isInROM != iniIsInROM) sl@0: { sl@0: ERR_PRINTF1(_L("Expected result does not match actual")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdIsValidName(const TDesC& aSection) sl@0: { sl@0: // Reads the name of file from ini file. sl@0: TPtrC name; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KName(), aSection, name)) sl@0: { sl@0: TBool isValid = FALSE; sl@0: TBool isBadChar; sl@0: if (GET_OPTIONAL_BOOL_PARAMETER(KIsBadChar(), aSection, isBadChar)) sl@0: { sl@0: // Tests whether a filename and path are syntactically correct. sl@0: // badChar = on return, contains any illegal character within name, sl@0: // if the path is valid, badChar is blank. sl@0: sl@0: TText badChar; sl@0: isValid = iFs->IsValidName(name, badChar); sl@0: INFO_PRINTF2(_L("BadChar: %c"), badChar); sl@0: sl@0: TPtrC iniBadChar; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KBadChar(), aSection, iniBadChar)) sl@0: { sl@0: TText expectedBadChar=iniBadChar[0]; sl@0: if (badChar != expectedBadChar) sl@0: { sl@0: ERR_PRINTF3(_L("Error compare badchar %c != %c"), badChar, expectedBadChar); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("Badchar's has equal value %c == %c"), badChar, expectedBadChar); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: // Tests whether a filename and path are syntactically correct. sl@0: isValid = iFs->IsValidName(name); sl@0: } sl@0: sl@0: if (isValid) sl@0: { sl@0: INFO_PRINTF2(_L("Name %S is valid"), &name); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Name %S is not valid"), &name); sl@0: } sl@0: sl@0: // Compare parameter from ini sl@0: TBool iniIsValid; sl@0: if (GET_OPTIONAL_BOOL_PARAMETER(KIsValid(), aSection, iniIsValid)) sl@0: { sl@0: if (isValid != iniIsValid) sl@0: { sl@0: ERR_PRINTF1(_L("Error compare with ini parameter")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdSetSessionToPrivate(const TDesC& aSection) sl@0: { sl@0: // Reads the name of drive from ini file. sl@0: TDriveNumber driveNumber; sl@0: if (!GetDriveNumberFromConfig(aSection, KDrive(), driveNumber)) sl@0: { sl@0: ERR_PRINTF2(_L("Error read parameter %S"), &KDrive()); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: // Sets the session path to point to the private path on the specified drive. sl@0: TInt err = iFs->SetSessionToPrivate(driveNumber); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("SetSessionToPrivate error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Function DoCmdSetSessionToPrivate() OK")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdPrivatePath(const TDesC& aSection) sl@0: { sl@0: // Creates the text defining the private path for a process. sl@0: TBuf privatePath; sl@0: TInt err = iFs->PrivatePath(privatePath); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("PrivatePath error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("PrivatePath: %S"), &privatePath); sl@0: sl@0: // Compares path from ini file and path from function. sl@0: TPtrC comparePath; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KComparePath(), aSection, comparePath)) sl@0: { sl@0: if (comparePath.CompareC(privatePath, 0, NULL) != 0) sl@0: { sl@0: ERR_PRINTF3(_L("%S != %S"), &privatePath, &comparePath); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("%S == %S"), &privatePath, &comparePath); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FsData::DoCmdCreatePrivatePath(const TDesC& aSection) sl@0: { sl@0: // Reads the name of drive from ini file. sl@0: TDriveNumber driveNumber; sl@0: if (!GetDriveNumberFromConfig(aSection, KDrive(), driveNumber)) sl@0: { sl@0: ERR_PRINTF2(_L("Error read parameter %S"), &KDrive()); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: // Creates the private path for a process on the specified drive. sl@0: TInt err = iFs->CreatePrivatePath(driveNumber); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("PrivatePath error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Function DoCmdCreatePrivatePath() OK")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: TBool CT_FsData::ConvertToSortKey(const TDesC& aSortKeyStr, TUint& aSortKey) sl@0: { sl@0: TBool ret = ETrue; sl@0: sl@0: if (aSortKeyStr == KESortNone) sl@0: { sl@0: aSortKey = ESortNone; sl@0: } sl@0: else if (aSortKeyStr == KESortByName) sl@0: { sl@0: aSortKey = ESortByName; sl@0: } sl@0: else if (aSortKeyStr == KESortByExt) sl@0: { sl@0: aSortKey = ESortByExt; sl@0: } sl@0: else if (aSortKeyStr == KESortBySize) sl@0: { sl@0: aSortKey = ESortBySize; sl@0: } sl@0: else if (aSortKeyStr == KESortByDate) sl@0: { sl@0: aSortKey = ESortByDate; sl@0: } sl@0: else if (aSortKeyStr == KESortByUid) sl@0: { sl@0: aSortKey = ESortByUid; sl@0: } sl@0: else if (aSortKeyStr == KEDirsAnyOrder) sl@0: { sl@0: aSortKey = EDirsAnyOrder; sl@0: } sl@0: else if (aSortKeyStr == KEDirsFirst) sl@0: { sl@0: aSortKey = EDirsFirst; sl@0: } sl@0: else if (aSortKeyStr == KEDirsLast) sl@0: { sl@0: aSortKey = EDirsLast; sl@0: } sl@0: else if (aSortKeyStr == KEAscending) sl@0: { sl@0: aSortKey = EAscending; sl@0: } sl@0: else if (aSortKeyStr == KEDescending) sl@0: { sl@0: aSortKey = EDescending; sl@0: } sl@0: else if (aSortKeyStr == KEDirDescending) sl@0: { sl@0: aSortKey = EDirDescending; sl@0: } sl@0: else if (aSortKeyStr.Match((_L("*|*"))) != KErrNotFound) sl@0: { sl@0: TUint tmpSortKey; sl@0: sl@0: TInt location = aSortKeyStr.Match(_L("*|*")); sl@0: //Converting Left part of the data sl@0: TPtrC left = aSortKeyStr.Left(location); sl@0: if (ConvertToSortKey(left, tmpSortKey)) sl@0: { sl@0: aSortKey = tmpSortKey; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: //Converting right data can be with another "|" sl@0: TPtrC right = aSortKeyStr.Mid(location + 1); sl@0: sl@0: if (ConvertToSortKey(right, tmpSortKey)) sl@0: { sl@0: aSortKey = aSortKey | tmpSortKey; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: const TDesC& CT_FsData::ConvertToStrAttMask(TUint aAttMask) sl@0: { sl@0: switch(aAttMask) sl@0: { sl@0: case KEntryAttReadOnly: sl@0: return KEntryAttReadOnlyStr; sl@0: case KEntryAttHidden: sl@0: return KEntryAttHiddenStr; sl@0: case KEntryAttSystem: sl@0: return KEntryAttSystemStr; sl@0: case KEntryAttVolume: sl@0: return KEntryAttVolumeStr; sl@0: case KEntryAttDir: sl@0: return KEntryAttDirStr; sl@0: case KEntryAttArchive: sl@0: return KEntryAttArchiveStr; sl@0: case KEntryAttXIP: sl@0: return KEntryAttXIPStr; sl@0: default: sl@0: break; sl@0: }; sl@0: return KEntryAttUnknown; sl@0: }