commands/rez/rez.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // rez.cpp
       
     2 // 
       
     3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <fshell/ioutils.h>
       
    14 #include <barsc.h>
       
    15 #include <bautils.h>
       
    16 #include <fshell/ltkutils.h>
       
    17 
       
    18 using namespace IoUtils;
       
    19 
       
    20 class CCmdRez : public CCommandBase
       
    21 	{
       
    22 public:
       
    23 	static CCommandBase* NewLC();
       
    24 	~CCmdRez();
       
    25 private:
       
    26 	CCmdRez();
       
    27 
       
    28 private: // From CCommandBase.
       
    29 	virtual const TDesC& Name() const;
       
    30 	virtual void DoRunL();
       
    31 	virtual void ArgumentsL(RCommandArgumentList& aArguments);
       
    32 	virtual void OptionsL(RCommandOptionList& aOptions);
       
    33 private:
       
    34 	HBufC* iIdentifier;
       
    35 	TBool iHex;
       
    36 	RResourceFile iFile;
       
    37 	};
       
    38 
       
    39 
       
    40 CCommandBase* CCmdRez::NewLC()
       
    41 	{
       
    42 	CCmdRez* self = new(ELeave) CCmdRez();
       
    43 	CleanupStack::PushL(self);
       
    44 	self->BaseConstructL();
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 CCmdRez::~CCmdRez()
       
    49 	{
       
    50 	delete iIdentifier;
       
    51 	iFile.Close();
       
    52 	}
       
    53 
       
    54 CCmdRez::CCmdRez()
       
    55 	{
       
    56 	}
       
    57 
       
    58 const TDesC& CCmdRez::Name() const
       
    59 	{
       
    60 	_LIT(KName, "rez");
       
    61 	return KName;
       
    62 	}
       
    63 
       
    64 void CCmdRez::ArgumentsL(RCommandArgumentList& aArguments)
       
    65 	{
       
    66 	aArguments.AppendStringL(iIdentifier, _L("resource-identifier"));
       
    67 	}
       
    68 
       
    69 void CCmdRez::OptionsL(RCommandOptionList& aOptions)
       
    70 	{
       
    71 	aOptions.AppendBoolL(iHex, _L("hex"));
       
    72 	}
       
    73 
       
    74 
       
    75 EXE_BOILER_PLATE(CCmdRez)
       
    76 
       
    77 void CCmdRez::DoRunL()
       
    78 	{
       
    79 	if (iIdentifier->Left(2) != _L("R:"))
       
    80 		{
       
    81 		LeaveIfErr(KErrArgument, _L("Resource identifiers must start R: (see help for details)"));
       
    82 		}
       
    83 
       
    84 	TBool wide = ETrue;
       
    85 	if ((*iIdentifier)[iIdentifier->Length()-1] == 'd') wide = EFalse;
       
    86 
       
    87 	HBufC* errString = NULL;
       
    88 	HBufC8* result = NULL;
       
    89 	TRAPD(err, result = LtkUtils::Rez8L(*iIdentifier, NULL, &errString));
       
    90 	if (err && errString)
       
    91 		{
       
    92 		PrintError(err, _L("%S"), errString);
       
    93 		}
       
    94 	delete errString;
       
    95 	User::LeaveIfError(err);
       
    96 	CleanupStack::PushL(result);
       
    97 
       
    98 	if (iHex)
       
    99 		{
       
   100 		LtkUtils::HexDumpToOutput(*result, Stdout());
       
   101 		}
       
   102 	else if (wide)
       
   103 		{
       
   104 		TPtrC16 wptr((TUint16*)result->Ptr(), result->Size()/2);
       
   105 		Write(wptr);
       
   106 		}
       
   107 	else
       
   108 		{
       
   109 		RBuf buf;
       
   110 		buf.CreateL(result->Length());
       
   111 		buf.Copy(*result);
       
   112 		Write(buf);
       
   113 		buf.Close();
       
   114 		}
       
   115 	CleanupStack::PopAndDestroy(result);
       
   116 	if (Stdout().AttachedToConsole())
       
   117 		{
       
   118 		Printf(_L("\r\n"));
       
   119 		}
       
   120 	}