Exemplo n.º 1
0
int CLuaHTTPDefs::httpSetResponseCookie ( lua_State* luaVM )
{
    if ( lua_type ( luaVM, 1 ) == LUA_TSTRING && lua_type ( luaVM, 2 ) == LUA_TSTRING )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            CResourceFile * file = pLuaMain->GetResourceFile();
            if ( file && file->GetType() == CResourceHTMLItem::RESOURCE_FILE_TYPE_HTML )
            {
                CResourceHTMLItem * html = (CResourceHTMLItem *)file;
                char* szHeaderName = (char *) lua_tostring ( luaVM, 1 );
				char* szHeaderValue = (char *) lua_tostring ( luaVM, 2 );
				html->SetResponseCookie ( szHeaderName, szHeaderValue );
                lua_pushboolean ( luaVM, true );
                return 1;
            }
            else
                m_pScriptDebugging->LogError ( luaVM, "httpSetResponseCookie: Can only be used in HTML scripts" );
        } 
        else
            m_pScriptDebugging->LogError ( luaVM, "httpSetResponseCookie" );
    }   
    else
        m_pScriptDebugging->LogBadType ( luaVM, "httpSetResponseCookie" );
    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 2
0
int CLuaHTTPDefs::httpWrite ( lua_State* luaVM )
{
    if ( lua_type ( luaVM, 1 ) == LUA_TSTRING )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            CResourceFile * file = pLuaMain->GetResourceFile();
            if ( file && file->GetType() == CResourceHTMLItem::RESOURCE_FILE_TYPE_HTML )
            {
                CResourceHTMLItem * html = (CResourceHTMLItem *)file;
                unsigned long length = NULL;
                if ( lua_type ( luaVM, 2 ) == LUA_TNUMBER )
                    length = static_cast < unsigned long > ( lua_tonumber ( luaVM, 2 ) );
                else
                    length = lua_objlen ( luaVM, 1 );
                const char* szBuffer = lua_tolstring ( luaVM, 1, NULL );
                html->AppendToPageBuffer ( szBuffer, length );
                lua_pushboolean ( luaVM, true );
                return 1;
            }
            else
                m_pScriptDebugging->LogError ( luaVM, "httpWrite: Can only be used in HTML scripts" );
        } 
        else
            m_pScriptDebugging->LogError ( luaVM, "httpWrite" );
    }   
    else
        m_pScriptDebugging->LogBadType ( luaVM, "httpWrite" );
    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 3
0
int CLuaHTTPDefs::httpRequestLogin ( lua_State* luaVM )
{
    CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
    if ( pLuaMain )
    {
        CResourceFile * file = pLuaMain->GetResourceFile();
        if ( file && file->GetType() == CResourceHTMLItem::RESOURCE_FILE_TYPE_HTML )
        {
            CResourceHTMLItem * html = (CResourceHTMLItem *)file;

			char szName[255];
			sprintf ( szName, "Basic realm=\"%s\"", m_pMainConfig->GetServerName ().c_str () );
			html->SetResponseHeader("WWW-Authenticate", szName);
			html->SetResponseCode ( 401 );
            lua_pushboolean ( luaVM, true );
            return 1;
        }
        else
            m_pScriptDebugging->LogError ( luaVM, "httpRequestLogin: Can only be used in HTML scripts" );
    } 
    else
        m_pScriptDebugging->LogError ( luaVM, "httpRequestLogin" );   
    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 4
0
int CLuaHTTPDefs::httpSetResponseCode ( lua_State* luaVM )
{
    if ( lua_type ( luaVM, 1 ) == LUA_TNUMBER  )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            CResourceFile * file = pLuaMain->GetResourceFile();
            if ( file && file->GetType() == CResourceHTMLItem::RESOURCE_FILE_TYPE_HTML )
            {
                CResourceHTMLItem * html = (CResourceHTMLItem *)file;
                unsigned int responseCode = static_cast < unsigned int > ( lua_tonumber ( luaVM, 1 ) );
				html->SetResponseCode ( responseCode );
                lua_pushboolean ( luaVM, true );
                return 1;
            }
            else
                m_pScriptDebugging->LogError ( luaVM, "httpSetResponseCode: Can only be used in HTML scripts" );
        } 
        else
            m_pScriptDebugging->LogError ( luaVM, "httpSetResponseCode" );
    }   
    else
        m_pScriptDebugging->LogBadType ( luaVM, "httpSetResponseCode" );
    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 5
0
/**
 * Identify if input file is a Registration Resource File.
 @ Param : aRegistrationFileName - File name to be scanned.
 */
TInt FindRegistrationResourceFileL(std::string& aRegistrationFileName)
{
	CResourceFile* registrationFile = NULL;
	try {
			registrationFile = new CResourceFile(aRegistrationFileName, 0, 0);
			if(NULL==registrationFile)
			{
				std::cout<<"Failed : Error in Reading File. Memory Allocation Failed"<<std::endl;
				return 1;
			}
			else
			{
				TUid iAppUid = registrationFile->ReadFileUidL();
				if(KUidAppRegistrationResourceFile == iAppUid.GetUid())
				{
					delete registrationFile;
					return 0;
				}
			}
		}
		catch(const CResourceFileException& aObject)
		{
			if(registrationFile)
				delete registrationFile;
			return 1;
		}
	
	delete registrationFile;
	return 1;
}
Exemplo n.º 6
0
int CLuaHTTPDefs::httpClear ( lua_State* luaVM )
{
    CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
    if ( pLuaMain )
    {
        CResourceFile * file = pLuaMain->GetResourceFile();
        if ( file && file->GetType() == CResourceHTMLItem::RESOURCE_FILE_TYPE_HTML )
        {
            CResourceHTMLItem * html = (CResourceHTMLItem *)file;
			html->ClearPageBuffer();
            lua_pushboolean ( luaVM, true );
            return 1;
        }
        else
            m_pScriptDebugging->LogError ( luaVM, "httpClear: Can only be used in HTML scripts" );
    } 
    else
        m_pScriptDebugging->LogError ( luaVM, "httpClear" );   
    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 7
0
void CLuaMain::SaveXML ( CXMLNode * pRootNode )
{
    list<CXMLFile *>::iterator iter;
    for ( iter = m_XMLFiles.begin(); iter != m_XMLFiles.end(); ++iter )
    {
        CXMLFile * file = (*iter);
        if ( file )
        {
            if ( file->GetRootNode() == pRootNode )
            {
                file->Write();
                break;
            }
        }
    }
    if ( m_pResource )
    {
        list < CResourceFile* > ::iterator iter = m_pResource->IterBegin ();
        for ( ; iter != m_pResource->IterEnd () ; ++iter )
        {
            CResourceFile* pResourceFile = *iter;
            if ( pResourceFile->GetType () == CResourceFile::RESOURCE_FILE_TYPE_CONFIG )
            {
                CResourceConfigItem* pConfigItem = static_cast < CResourceConfigItem* > ( pResourceFile );
                if ( pConfigItem->GetRoot () == pRootNode )
                {
                    CXMLFile* pFile = pConfigItem->GetFile ();
                    if ( pFile )
                    {
                        pFile->Write ();
                    }
                    break;
                }
            }
        }
    }
}
Exemplo n.º 8
0
void CScriptDebugging::LogString ( const char* szPrePend, lua_State * luaVM, const char* szMessage, unsigned int uiMinimumDebugLevel, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue )
{
    SString strText;
    lua_Debug debugInfo;

    // Initialize values for onDebugMessage
    SString strMsg  = szMessage;
    SString strFile = "";
    int     iLine   = -1;

    // Get a VM from somewhere
    if ( !luaVM && !m_LuaMainStack.empty () )
        luaVM = m_LuaMainStack.back ()->GetVM ();

    for ( int level = 1; level < 3; level++ )
    {
	    if ( luaVM && lua_getstack ( luaVM, level, &debugInfo ) )
	    {
		    lua_getinfo ( luaVM, "nlS", &debugInfo );

		     // Make sure this function isn't defined in a string (eg: from runcode)
            if ( debugInfo.source[0] == '@' )
            {
                // Get and store the location of the debug message
                strFile = debugInfo.source + 1;
                iLine   = debugInfo.currentline;

                // Populate a message to print/send (unless "info" type)
                if ( uiMinimumDebugLevel < 3 )
                    strText = SString ( "%s%s:%d: %s", szPrePend, strFile.c_str (), debugInfo.currentline, szMessage );
                // if the file isn't empty, stop trying any other levels
                break;
            }
            else
            {
                strFile = debugInfo.short_src;

                if ( uiMinimumDebugLevel < 3 )
                    strText = SString ( "%s%s %s", szPrePend, szMessage, strFile.c_str () );
                if ( strFile != "[string \"?\"]" ) // if the file isn't empty, stop trying any other levels
                    break;
            }
        }
        else
        {
            strText = SString ( "%s%s%s", szPrePend, m_strLineAndFile.c_str(), szMessage );
            // no point in trying other levels
            break;
        }
    }

    // Create a different message if type is "INFO"
    if ( uiMinimumDebugLevel > 2 )
        strText = SString ( "%s%s", szPrePend, szMessage );

    // Check whether onDebugMessage is currently being triggered
    if ( !m_bTriggeringOnDebugMessage )
    {
        // Make sure the state of onDebugMessage being triggered can be retrieved later
        m_bTriggeringOnDebugMessage = true;

        // Prepare onDebugMessage
        CLuaArguments Arguments;
        Arguments.PushString ( strMsg.c_str ( ) );
        Arguments.PushNumber ( uiMinimumDebugLevel );

        // Push the file name (if any)
        if ( strFile.length ( ) > 0 )
            Arguments.PushString ( strFile.c_str ( ) );
        else
            Arguments.PushNil ( );

        // Push the line (if any)
        if ( iLine > -1 )
            Arguments.PushNumber ( iLine );
        else
            Arguments.PushNil ( );
        
        // Call onDebugMessage
        g_pGame->GetMapManager ( )->GetRootElement ( )->CallEvent ( "onDebugMessage", Arguments );

        // Reset trigger state, so onDebugMessage can be called again at a later moment
        m_bTriggeringOnDebugMessage = false;
    }

    // Log it to the file if enough level
    if ( m_uiLogFileLevel >= uiMinimumDebugLevel )
    {
        PrintLog ( strText );
    }

    // Log to console
    CLogger::LogPrintf( "%s\n", strText.c_str () );

    // Not sure what this is for, seems pretty useless
    if ( m_uiHtmlLogLevel >= uiMinimumDebugLevel )
    {
        if ( luaVM )
        {
            CLuaMain* pLuaMain = g_pGame->GetLuaManager()->GetVirtualMachine ( luaVM );
            if ( pLuaMain )
            {
                CResourceFile * file = pLuaMain->GetResourceFile();
                if ( file && file->GetType() == CResourceHTMLItem::RESOURCE_FILE_TYPE_HTML )
                {
                    CResourceHTMLItem * html = (CResourceHTMLItem *)file;
                    html->AppendToPageBuffer ( strText );
                    html->AppendToPageBuffer ( "<br/>" );
                }
            }
        }
    }

    // Tell the players
    Broadcast ( CDebugEchoPacket ( strText, uiMinimumDebugLevel, ucRed, ucGreen, ucBlue ), uiMinimumDebugLevel );
}
Exemplo n.º 9
0
void CResource::Load ( CClientEntity *pRootEntity )
{
    m_pRootEntity = pRootEntity;
    if ( m_pRootEntity )
    {
        // Set the GUI parent to the resource root entity
        m_pResourceCOLRoot->SetParent ( m_pResourceEntity );
        m_pResourceDFFEntity->SetParent ( m_pResourceEntity );
        m_pResourceGUIEntity->SetParent ( m_pResourceEntity );
        m_pResourceTXDRoot->SetParent ( m_pResourceEntity );
    }

    CLogger::LogPrintf ( "> Starting resource '%s'", m_szResourceName );

    char szBuffer [ MAX_PATH ] = { 0 };
    list < CResourceConfigItem* >::iterator iterc = m_ConfigFiles.begin ();
    for ( ; iterc != m_ConfigFiles.end (); iterc++ )
    {
        if ( !(*iterc)->Start() )
        {
            CLogger::LogPrintf ( "Failed to start resource item %s in %s\n", (*iterc)->GetName(), m_szResourceName );
        }
    }

    // Load the files that are queued in the list "to be loaded"
    list < CResourceFile* > ::iterator iter = m_ResourceFiles.begin ();
    for ( ; iter != m_ResourceFiles.end (); iter++ )
    {
        CResourceFile* pResourceFile = *iter;
        // Only load the resource file if it is a client script
        if ( pResourceFile->GetResourceType () == CDownloadableResource::RESOURCE_FILE_TYPE_CLIENT_SCRIPT )
        {
            // Load the file
            std::vector < char > buffer;
            FileLoad ( pResourceFile->GetName (), buffer );

            // Check the contents
            if ( buffer.size () > 0 && CChecksum::GenerateChecksumFromBuffer ( &buffer.at ( 0 ), buffer.size () ).CompareWithLegacy ( pResourceFile->GetServerChecksum () ) )
            {
                // Load the resource text
                m_pLuaVM->LoadScriptFromBuffer ( &buffer.at ( 0 ), buffer.size (), pResourceFile->GetName () );
            }
            else
            {
                SString strBuffer ( "ERROR: File '%s' in resource '%s' - CRC mismatch.", pResourceFile->GetShortName (), m_szResourceName );
                g_pCore->ChatEchoColor ( strBuffer, 255, 0, 0 );
            }
        }
        else
        if ( CheckFileForCorruption ( pResourceFile->GetName () ) )
        {
            SString strBuffer ( "WARNING: File '%s' in resource '%s' is invalid.", pResourceFile->GetShortName (), m_szResourceName );
            g_pCore->DebugEchoColor ( strBuffer, 255, 0, 0 );
        }
    }

    // Set active flag
    m_bActive = true;

    // Did we get a resource root entity?
    if ( m_pResourceEntity )
    {
        // Call the Lua "onClientResourceStart" event
        CLuaArguments Arguments;
        Arguments.PushUserData ( this );
        m_pResourceEntity->CallEvent ( "onClientResourceStart", Arguments, true );
    }
    else
        assert ( 0 );
}
Exemplo n.º 10
0
///////////////////////////////////////////////////////////////
//
// CResourceChecker::CheckResourceForIssues
//
// Check each file and do the appropriate action
//
///////////////////////////////////////////////////////////////
void CResourceChecker::CheckResourceForIssues( CResource* pResource, const string& strResourceZip )
{
    m_strMinClientReqFromMetaXml = pResource->GetMinClientReqFromMetaXml();
    m_strMinServerReqFromMetaXml = pResource->GetMinServerReqFromMetaXml();
    m_strReqClientVersion = "";
    m_strReqServerVersion = "";
    m_strReqClientReason = "";
    m_strReqServerReason = "";

    m_ulDeprecatedWarningCount = 0;
    m_upgradedFullPathList.clear ();

    // Check each file in the resource
    list < CResourceFile* > ::iterator iterf = pResource->IterBegin ();
    for ( ; iterf != pResource->IterEnd (); iterf++ )
    {
        CResourceFile* pResourceFile = *iterf;
        // Skip this one if validate=false in the meta.xml
        if ( stricmp( pResourceFile->GetMetaFileAttribute ( "validate" ).c_str (), "false" ) )
        {
            string strPath;
            if ( pResource->GetFilePath ( pResourceFile->GetName(), strPath ) )
            {
                CResourceFile::eResourceType type = pResourceFile->GetType ();

                bool bScript;
                bool bClient;
                if ( type == CResourceFile::RESOURCE_FILE_TYPE_SCRIPT )
                {
                    bScript = true;
                    bClient = false;
                }
                else
                if ( type == CResourceFile::RESOURCE_FILE_TYPE_CLIENT_SCRIPT )
                {
                    bScript = true;
                    bClient = true;
                }
                else
                if ( type == CResourceFile::RESOURCE_FILE_TYPE_CLIENT_FILE )
                {
                    bScript = false;
                    bClient = true;
                }
                else
                    continue;

                CheckFileForIssues ( strPath, pResourceFile->GetName(), pResource->GetName (), bScript, bClient, false );
            }
        }
    }

    // Also check meta.xml
    {
        SString strFilename = "meta.xml";
        string strPath;
        if ( pResource->GetFilePath ( strFilename, strPath ) )
        {
            CheckFileForIssues ( strPath, strFilename, pResource->GetName (), false, false, true );
        }
    }

    // Output deprecated warning if required
    if ( m_ulDeprecatedWarningCount )
    {
        CLogger::LogPrintf ( "Some files in '%s' use deprecated functions.\n", pResource->GetName ().c_str () );
        CLogger::LogPrintf ( "Use the 'upgrade' command to perform a basic upgrade of resources.\n" );
    }

    // Handle upgrading a zip file if required
    if ( m_upgradedFullPathList.size () )
    {
        if ( pResource->IsResourceZip () )
        {
            string strOrigZip = strResourceZip;
            string strTempZip = strResourceZip.substr ( 0, strResourceZip.length () - 4 ) + "_tmp.zip";

            string strCacheDir = pResource->GetResourceCacheDirectoryPath ();

            vector < string > pathInArchiveList;

            for ( unsigned long i = 0 ; i < m_upgradedFullPathList.size () ; i++ )
            {
                string strFullPath = m_upgradedFullPathList[i];
                string strPathInArchive = strFullPath.substr ( strCacheDir.length () );
                pathInArchiveList.push_back ( strPathInArchive );
            }

            File::Delete( strTempZip.c_str () );

            if ( !ReplaceFilesInZIP( strOrigZip, strTempZip, pathInArchiveList, m_upgradedFullPathList ) )
            {
                CLogger::LogPrintf ( "Failed to upgrade (ReplaceFilesInZIP) '%s'\n", strOrigZip.c_str () );
            }
            else
            {
                if ( !RenameBackupFile( strOrigZip, ".old" ) )
                {
                    CLogger::LogPrintf ( "Failed to upgrade (RenameBackupFile) '%s'\n", strOrigZip.c_str () );
                }
                else
                {
                    if ( File::Rename( strTempZip.c_str (), strOrigZip.c_str () ) )
                    {
                        CLogger::LogPrintf ( "Failed to upgrade (rename) '%s'\n", strOrigZip.c_str () );
                    }
                }
            }

            File::Delete( strTempZip.c_str () );
        }
    }

    // Check LC_COLLATE is correct
    if ( strcoll( "a", "B" ) < 0 )
    {
        CLogger::LogPrintf ( "ERROR: LC_COLLATE is not set correctly\n" );
    }
}
Exemplo n.º 11
0
void CAppInfoReader::ReadOpaqueDataL(TUint aResourceId, CResourceFile* aRegistrationFile, TUint32 aServiceUid)
{
	Ptr8* opaqueData = NULL;
	int iLocale = 0;

	if (aResourceId == 0)
	{
		opaqueData = new Ptr8(1);
		if(NULL==opaqueData || NULL==opaqueData->GetPtr())
		{
			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
			throw CResourceFileException(errMsg);
		}
		*(opaqueData->GetPtr()) = 0;
		opaqueData->UpdateLength(1);
	}
	else
	{
		if (aResourceId & KResourceOffsetMask)
		{
			if(iLocalisableResourceFileName)
			{
				std::string localizeFileName = Ptr16ToString(iLocalisableResourceFileName);
				std::string folder;
				std::string file;
				size_t found;
				size_t find;
				std::string iLocalPath(iDrivePath);
		
				#ifdef __LINUX__
				found=localizeFileName.find_last_of("//");
				#else
				found=localizeFileName.find_last_of("/\\");
				#endif

				if(found)
					folder = localizeFileName.substr(0,found);
				else
				{
					#ifdef __LINUX__
					folder.assign("/");
					#else
					folder.assign("\\");
					#endif					
				}
			
				file = localizeFileName.substr(found+1);
				file.append(".");
			
				iLocalPath.append(folder);
					
				std::wstring iFilePath = string2wstring(iLocalPath);
				std::wstring iFileName = string2wstring(file);
				#ifdef __LINUX__
				iLocalPath.append("/");
				#else
				iLocalPath.append("\\");
				#endif

		
				std::list<std::wstring> locDirs;
				GetDirContents( iFilePath, locDirs );
			
				std::list<std::wstring>::iterator curr = locDirs.begin();
				for( curr = locDirs.begin(); curr != locDirs.end(); ++curr )
				{
					if (curr->find(iFileName,0) != std::wstring::npos)
					{
						std::string fName;
						std::string sAbsolutePath;
						std::string Locale;
						sAbsolutePath.assign(iLocalPath);
						fName = wstring2string( *curr );

						find=fName.rfind("backup");
						if(find != string::npos)
							continue;

						sAbsolutePath.append(fName);										
						found=fName.find_last_of(".");
						if(found)
							Locale = fName.substr(found+2);
			
						iLocale = atoi(Locale.c_str()); 
						if(!iLocale)
							iLocale = KNonLocalized;
					   
						CResourceFile* tlocalisableFile = NULL;
			
						// open the localisable resource file	
						tlocalisableFile = new CResourceFile(sAbsolutePath, 0, 0);
						if(NULL==tlocalisableFile)
						{
							std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
							throw CResourceFileException(errMsg);
						}
			
						if (tlocalisableFile)
						{
							if (tlocalisableFile && (aResourceId & KResourceOffsetMask))
								tlocalisableFile->ConfirmSignatureL();

							opaqueData = tlocalisableFile->AllocReadL(aResourceId);

							if(opaqueData)
							{
								const TUint8* currentPtr=opaqueData->GetPtr();//TUint8 pointer is used
									
								//resource string length is limited to 255 characters max.
								const TInt unicodeLength=*currentPtr;
		
								if (unicodeLength!=0)
								{
									if (REINTERPRET_CAST(TUint,(currentPtr+1))&0x1)
									{			
										// The resource compiler puts out a padding byte (arbitrarily 0xab)
										// to ensure the alignment of Unicode strings within each resource.
								
										//Cardanility check. Values in the range 0-127 are stored in a single byte, 
										//128-16383 in two bytes and other values in 4 bytes.
										if((*(currentPtr+1)!=0xab) && (*(currentPtr+3)!=0xab))
										{
											std::string errMsg= "Failed : Trying to access invalid registrationFile";
											throw CResourceFileException(errMsg);
										}
									}
								}
								
								opaqueData->SetPtr(currentPtr);
								opaqueData->SetLength(opaqueData->GetLength());
								
							}
							else
							{
								opaqueData = new Ptr8(1);
								if(NULL==opaqueData || NULL==opaqueData->GetPtr())
								{
									std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
									throw CResourceFileException(errMsg);
								}
								*(opaqueData->GetPtr()) = 0;
								opaqueData->SetLength(1);
							}

							CAppLocalOpaqueDataInfo* opaqueInfo = CAppLocalOpaqueDataInfo::NewL(iLocale, aServiceUid, opaqueData);
							iOpaqueDataArray.push_back(opaqueInfo);
							
						}
						delete tlocalisableFile;
					}
				}
			}
		}
		else
		{	// expecting opaque data to be in the registration file
			assert(aRegistrationFile);
			opaqueData = aRegistrationFile->AllocReadL(aResourceId); //lint !e613 Suppress ossible use of null pointer

			const TUint8* currentPtr=opaqueData->GetPtr();//TUint8 pointer is used

			//resource string length is limited to 255 characters max.
			const TInt unicodeLength=*currentPtr;
		
			if (unicodeLength!=0)
			{
				if (REINTERPRET_CAST(TUint,(currentPtr+1))&0x1)
				{
					// The resource compiler puts out a padding byte (arbitrarily 0xab)
					// to ensure the alignment of Unicode strings within each resource.
					
					//Cardanility check. Values in the range 0-127 are stored in a single byte, 
					//128-16383 in two bytes and other values in 4 bytes.
					if((*(currentPtr+1)!=0xab) && (*(currentPtr+3)!=0xab))
					{
						std::string errMsg= "Failed : Trying to access invalid registrationFile";
						throw CResourceFileException(errMsg);
					}
				}
			}

			opaqueData->SetPtr(currentPtr);
			opaqueData->SetLength(opaqueData->GetLength());
			CAppLocalOpaqueDataInfo* opaqueInfo = CAppLocalOpaqueDataInfo::NewL(iLocale, aServiceUid, opaqueData);
			iOpaqueDataArray.push_back(opaqueInfo);
		}
	}
}
Exemplo n.º 12
0
// reads as much info as it can
// at least captions and icons must be setup on return from this method (using defaults if necessary)
TBool CAppInfoReader::ReadL()
{
	TUint fileOffset = 0;
	TInt fileLength = 0;
	TUid firstUid(KExecutableImageUidVal);
	TUid middleUid(KUidApp);
	TInt err;
	TInt LocalizeError = 0;
	TUid reguid;
	
	CResourceFile* registrationFile = new CResourceFile(iRegistrationFileName, fileOffset, fileLength);
	if(NULL==registrationFile)
	{
		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
		throw CResourceFileException(errMsg);
	}

	if(registrationFile)
	{
		iAppUid = registrationFile->ReadAppUidL();
		if(!iAppUid.GetUid())
		{
			std::string errMsg= "Failed : Invalid Resource File. Null Application UID.";
			throw CResourceFileException(errMsg);
		}

		reguid = registrationFile->ReadFileUidL();
		if(reguid.GetUid()!= KUidAppRegistrationResourceFile)
		{
			std::string errMsg= "Failed : Invalid Resource File. UID2 is not defined.";
			throw CResourceFileException(errMsg);
		}
	}

	// set the TUidType for the app binary
	// cannot read the TEntry info from the app binary because it's in \sys\bin
	iAppBinaryUidType = TUidType(firstUid, middleUid, iAppUid);	
	
	RResourceReader	resourceReader;
	resourceReader.OpenL(registrationFile, KAppRegistrationInfoResourceId);	

	TUint localisableResourceId = 1; // only initialising this here to keep the compiler happy, as it's concerned that the variable might be used without having been initialised. The variable should be initialised later, before it's used

	try {
			ReadMandatoryInfoL(resourceReader);
		
			err = ReadNonLocalisableInfoL(resourceReader, localisableResourceId);

			if (!err)
			{	
				err = ReadNonLocalisableOptionalInfoL(resourceReader, registrationFile);
			}
		}
		catch(const CResourceFileException& aObject)
		{
		
			delete registrationFile;
			cout<< aObject.GetMsg()<< endl;
			return EFalse; // might have read something, but failed to setup enough info to make it worthwhile trying to read any more
		}
	
	TBool useDefaultIcons = ETrue;

	if(iLocalisableResourceFileName)
	{
		std::string localizeFileName = Ptr16ToString(iLocalisableResourceFileName);
		std::string folder;
		std::string file;
		size_t found;
		std::string iLocalPath(iDrivePath);

		#ifdef __LINUX__
	  	found=localizeFileName.find_last_of("//");
		#else
		found=localizeFileName.find_last_of("/\\");
		#endif

	  	if(found)
	  		folder = localizeFileName.substr(0,found);
	  	else
		{
			#ifdef __LINUX__
			folder.assign("/");	  		
			#else
			folder.assign("\\");
			#endif
		}
	  	
	  	file = localizeFileName.substr(found+1);
		file.append(".");
		
		iLocalPath.append(folder);
				
		std::wstring iFilePath = string2wstring(iLocalPath);
		std::wstring iFileName = string2wstring(file);

		#ifdef __LINUX__
		iLocalPath.append("/");
		#else
		iLocalPath.append("\\");
		#endif
		
		std::list<std::wstring> locDirs;
		GetDirContents( iFilePath, locDirs );

	 	std::list<std::wstring>::iterator curr = locDirs.begin();
		for( curr = locDirs.begin(); curr != locDirs.end(); ++curr )
		{
			if (curr->find(iFileName,0) != std::wstring::npos)
			{
			    std::string fName;
				std::string sAbsolutePath;
				sAbsolutePath.assign(iLocalPath);
			 	fName = wstring2string( *curr );

			   	sAbsolutePath.append(fName);
				//cout << sAbsolutePath<<endl;
				
				std::string Locale;
				int iLocale = 0;
		
				found=fName.rfind(".r");
				if(found!=string::npos)
					Locale = fName.substr(found+2);
				else
					continue;

				iLocale = atoi(Locale.c_str()); 
			    if(!iLocale)
					iLocale = KNonLocalized;
				   
				CResourceFile* tlocalisableFile = NULL;

				try {
					// open the localisable resource file	
					tlocalisableFile = new CResourceFile(sAbsolutePath, 0, 0);
					if(NULL==tlocalisableFile)
					{
						std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
						throw CResourceFileException(errMsg);
					}

					if (!err)
					{
						if (tlocalisableFile && (localisableResourceId & KResourceOffsetMask))
							tlocalisableFile->ConfirmSignatureL();

						err = ReadLocalisableInfoLoopL(*tlocalisableFile, localisableResourceId, useDefaultIcons, iLocale);
					}
					
					delete tlocalisableFile;
				}
				catch(const CResourceFileException& aObject)
				{
					LocalizeError = 1;
					aObject.Display();
					delete tlocalisableFile;
				}
			}
		}
	}

	// if anything went wrong, we tell the caller that the read was unsuccessful. Some
	// of the members of this class may contain data which is not complete, but this doesn't matter
	// because the caller shouldn't try to access the data if the read was unsuccessful
	TBool readSuccessful = 0;
	if(!LocalizeError)
		readSuccessful = (err == KErrNone);
	delete registrationFile;
	return readSuccessful;
}
Exemplo n.º 13
0
TBool CAppInfoReader::ReadL(const std::vector<FileDescription*>& aFileDescription, std::string& aRomPath, int aInRom )
{
		TUint fileOffset = 0;
		TInt fileLength = 0;
		TUid firstUid(KExecutableImageUidVal);
		TUid middleUid(KUidApp);
		TInt err;
		TInt LocalizeError = 0;
		TUid reguid;
		CResourceFile* registrationFile = new CResourceFile(iRegistrationFileName, fileOffset, fileLength);
		if(NULL==registrationFile)
		{
			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
			throw CResourceFileException(errMsg);
		}
	
		if(registrationFile)
		{
			iAppUid = registrationFile->ReadAppUidL();
			if(!iAppUid.GetUid())
			{
				std::string errMsg= "Failed : Invalid Resource File. Null Application UID.";
				throw CResourceFileException(errMsg);
			}

			reguid = registrationFile->ReadFileUidL();
			if(reguid.GetUid()!= KUidAppRegistrationResourceFile)
			{
				std::string errMsg= "Failed : Invalid Resource File. UID2 is not defined.";
				throw CResourceFileException(errMsg);
			}
		}
	
		// set the TUidType for the app binary
		// cannot read the TEntry info from the app binary because it's in \sys\bin
		iAppBinaryUidType = TUidType(firstUid, middleUid, iAppUid); 
		
		RResourceReader resourceReader;
		resourceReader.OpenL(registrationFile, KAppRegistrationInfoResourceId); 
	
		TUint localisableResourceId = 1; // only initialising this here to keep the compiler happy, as it's concerned that the variable might be used without having been initialised. The variable should be initialised later, before it's used
	
		try {
				ReadMandatoryInfoL(resourceReader);
			
				err = ReadNonLocalisableInfoL(resourceReader, localisableResourceId);
	
				if (!err)
				{	
					err = ReadNonLocalisableOptionalInfoL(resourceReader, registrationFile);
				}
			}
			catch(const CResourceFileException& aObject)
			{
			
				delete registrationFile;
				cout<< aObject.GetMsg()<< endl;
				return EFalse; // might have read something, but failed to setup enough info to make it worthwhile trying to read any more
			}
		
		TBool useDefaultIcons = ETrue;
	
		if(iLocalisableResourceFileName)
		{
			std::string localizeFileName = Ptr16ToString(iLocalisableResourceFileName);

			std::vector<FileDescription*>::const_iterator filedesIter;
			//std::wstring iFile;
			std::wstring iLocalizeFile;
			//std::string aFileName;
			std::string iLocalFilePath;

			std::string iLocalFileExt(".r");
			
			for(filedesIter = aFileDescription.begin() ; filedesIter != aFileDescription.end(); ++filedesIter)
			{
				iLocalizeFile = (*filedesIter)->GetLocalFile();
			
				iLocalFilePath = wstring2string(iLocalizeFile);

				if((iLocalFilePath.find(localizeFileName,0) == std::wstring::npos) 
						|| (iLocalFilePath.find(iLocalFileExt,0) == std::wstring::npos))
					continue;

				size_t found;
				std::string Locale;
				int iLocale = 0;
			
				found=iLocalFilePath.find_last_of(".");
				if(found)
					Locale = iLocalFilePath.substr(found+2);

				iLocale = atoi(Locale.c_str()); 
				if(!iLocale)
					iLocale = KNonLocalized;
			
				CResourceFile* tlocalisableFile = NULL;

				if(aInRom)
				{
					std::string LocalFile = FullNameWithoutDrive(iLocalFilePath);
					iLocalFilePath = aRomPath + LocalFile;
				}

				try {
					// open the localisable resource file	
					tlocalisableFile = new CResourceFile(iLocalFilePath, 0, 0);
					if(NULL==tlocalisableFile)
					{
						std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
						throw CResourceFileException(errMsg);
					}
	
					if (!err)
					{
						if (tlocalisableFile && (localisableResourceId & KResourceOffsetMask))
							tlocalisableFile->ConfirmSignatureL();

						err = ReadLocalisableInfoLoopL(*tlocalisableFile, localisableResourceId, useDefaultIcons, iLocale);
					}
						
					delete tlocalisableFile;
				}
				catch(const CResourceFileException& aObject)
				{
					LocalizeError = 1;
					aObject.Display();
					delete tlocalisableFile;
				}
			}
		}
	
	// if anything went wrong, we tell the caller that the read was unsuccessful. Some
	// of the members of this class may contain data which is not complete, but this doesn't matter
	// because the caller shouldn't try to access the data if the read was unsuccessful
	TBool readSuccessful = 0;
	if(!LocalizeError)
		readSuccessful = (err == KErrNone);
	delete registrationFile;
	return readSuccessful;
}
Exemplo n.º 14
0
void CScriptDebugging::LogString ( const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage, unsigned int uiMinimumDebugLevel, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue )
{
    SString strText = ComposeErrorMessage( szPrePend, luaDebugInfo, szMessage );

    // Create a different message if type is "INFO"
    if ( uiMinimumDebugLevel > 2 )
        strText = SString ( "%s%s", szPrePend, szMessage );

    // Check whether onDebugMessage is currently being triggered
    if ( !m_bTriggeringOnDebugMessage )
    {
        // Make sure the state of onDebugMessage being triggered can be retrieved later
        m_bTriggeringOnDebugMessage = true;

        // Prepare onDebugMessage
        CLuaArguments Arguments;
        Arguments.PushString ( szMessage );
        Arguments.PushNumber ( uiMinimumDebugLevel );

        // Push the file name (if any)
        if ( !luaDebugInfo.strFile.empty() )
            Arguments.PushString ( luaDebugInfo.strFile );
        else
            Arguments.PushNil ( );

        // Push the line (if any)
        if ( luaDebugInfo.iLine != INVALID_LINE_NUMBER )
            Arguments.PushNumber ( luaDebugInfo.iLine );
        else
            Arguments.PushNil ( );
        
        // Call onDebugMessage
        g_pGame->GetMapManager ( )->GetRootElement ( )->CallEvent ( "onDebugMessage", Arguments );

        // Reset trigger state, so onDebugMessage can be called again at a later moment
        m_bTriggeringOnDebugMessage = false;
    }

    // Log it to the file if enough level
    if ( m_uiLogFileLevel >= uiMinimumDebugLevel )
    {
        PrintLog ( strText );
    }

    // Log to console
    CLogger::LogPrintf( "%s\n", strText.c_str () );

#if 0
    // Not sure what this is for, seems pretty useless
    if ( m_uiHtmlLogLevel >= uiMinimumDebugLevel )
    {
        if ( luaVM )
        {
            CLuaMain* pLuaMain = g_pGame->GetLuaManager()->GetVirtualMachine ( luaVM );
            if ( pLuaMain )
            {
                CResourceFile * file = pLuaMain->GetResourceFile();
                if ( file && file->GetType() == CResourceHTMLItem::RESOURCE_FILE_TYPE_HTML )
                {
                    CResourceHTMLItem * html = (CResourceHTMLItem *)file;
                    html->AppendToPageBuffer ( strText );
                    html->AppendToPageBuffer ( "<br/>" );
                }
            }
        }
    }
#endif

    // Tell the players
    Broadcast ( CDebugEchoPacket ( strText, uiMinimumDebugLevel, ucRed, ucGreen, ucBlue ), uiMinimumDebugLevel );
}