Example #1
0
	/// <summary>
	/// <para name='Name'>SLog::openLog</para>
	/// <para name='Purpose'>Open a log for output</para>
	/// </summary>
	/// <param name='szFullPathToLog'>the full path to the log file to open</param>
	/// <param name='makeUnique'>Whether to append a date/time stamp to the file name</param>
	/// <returns>S_OK if successful, failure if it failed</returns>
	/// <remarks>
	/// <para name='Notes'></para>
	/// <para name='Author'>Kenn Guilstorf</para>
	/// <para name='LastModified'>2015-10-26</para>
	/// </remarks>
	HRESULT SLog::openLog(TSTRING szFullPathToLog, bool makeUnique)
	{
		HRESULT hrRetVal = S_OK;
		TSTRING szFullLogPath = TSTRING();

		// If we're trying to open when a log is already open...
		// Let's flush and close the main OSTREAM first...
		if (NULL != m_pO)
		{
			m_pO->flush();
			delete m_pO;
			m_pO = NULL;
		}

		// Now, close the file stream...
		if (NULL != m_log)
		{
			if (m_log->is_open())
			{
				m_log->flush();
				m_log->close();
				delete m_log;
				m_log = NULL;
			}
		}

		// Split the path into path, name and ext
		hrRetVal = splitFullPath(szFullPathToLog);
		if (hrRetVal == ERROR_BAD_ARGUMENTS)
			goto EXIT;

		// Do we want to add date/time to the file?
		if (makeUnique)
			m_szLogFileName->append(getDateTimeString(false));

		szFullLogPath.append(m_szLogFilePath->c_str());
		szFullLogPath.append(m_szLogFileName->c_str());
		szFullLogPath.append(m_szLogFileExt->c_str());

		// Enter our critical section
		EnterCriticalSection(&m_CriticalSection);

		// Open our file stream
		m_log = new TOFSTREAM(szFullLogPath.c_str(),
			TOFSTREAM::app | TOFSTREAM::out);
		
		// Open a new output stream
		m_pO = new TOSTREAM(m_log->rdbuf());

		// Leave our critical section
		LeaveCriticalSection(&m_CriticalSection);

	EXIT:
		return hrRetVal;
	}
///////////////////////////////////////////////////////////////////////////////
// MakeFileError
///////////////////////////////////////////////////////////////////////////////
TSTRING cErrorUtil::MakeFileError( const TSTRING& msg, const TSTRING& fileName )
{
	TSTRING ret;
    ret = TSS_GetString( cCore, core::STR_ERR2_FILENAME );
    ret.append( fileName );
    ret.append( 1, _T('\n') );

    if ( msg.length() > 0 )
    {
        ret.append(msg);
    }
	
	return ret;
}
TSTRING cSHASignature::AsStringHex() const
{
    TSTRING ret;
    
    TCHAR stringBuffer[128];
    TCHAR sigStringOut[128];
    sigStringOut[0] = '\0';
    
    for (int i=0; i < SIG_UINT32_SIZE; ++i)
    {
        _stprintf(stringBuffer, _T("%08x"), mSHAInfo.digest[i]);
        _tcscat(sigStringOut, stringBuffer);
    }
    ret.append(sigStringOut);
    
    return ret;
}
TSTRING cHAVALSignature::AsStringHex() const 
{
    TSTRING ret;

    TCHAR stringBuffer[128];
    TCHAR sigStringOut[128];
    sigStringOut[0] = _T('\0');

    for (int i=0; i < SIG_BYTE_SIZE; ++i)
    {
        _stprintf(stringBuffer, _T("%02x"), mSignature[i]);
        _tcscat(sigStringOut, stringBuffer);
    }
    ret.append(sigStringOut);

    return ret;
}
TSTRING cSHASignature::AsStringHex() const
{
    TSTRING ret;
    
    TCHAR stringBuffer[128];
    TCHAR sigStringOut[128];
    sigStringOut[0] = '\0';
    uint8           *dbuf = (uint8 *)sha_digest;
    
    for (int i=0; i < SIG_UINT32_SIZE*(int)sizeof(uint32); ++i)
    {
        _stprintf(stringBuffer, _T("%02x"), dbuf[i]);
        _tcscat(sigStringOut, stringBuffer);
    }
    ret.append(sigStringOut);
    
    return ret;
}
TSTRING cMD5Signature::AsStringHex() const
{
    TSTRING ret;

    TCHAR stringBuffer[128];
    TCHAR sigStringOut[128];
    sigStringOut[0] = '\0';
    uint8       *dbuf = (uint8 *)md5_digest;

    for(int i = 0; i < SIG_BYTE_SIZE; ++i)
    {
        _stprintf(stringBuffer, _T("%02lx"), (unsigned long)dbuf[i]);
        _tcscat(sigStringOut, stringBuffer);
    }
    ret.append(sigStringOut);

    return ret;
}
TSTRING cChecksumSignature::AsString() const
{
    TSTRING ret;
    char *ps_signature;
    char buf[100];
    uint32 local[2];
    local[0] = (uint32)(mChecksum >> 32); // note we put the MSB first
    local[1] = (uint32)(mChecksum);

    ps_signature = pltob64(local, buf, 2);
        //ps_signature holds base64 representation of mCRC
#ifdef _UNICODE
    ret.resize(strlen(ps_signature));
    mbstowcs((TCHAR*)ret.data(), ps_signature, strlen(ps_signature));
#else
    ret.append(ps_signature);
#endif
    return ret;
}
///////////////////////////////////////////////////////////////////////////////
// AsString -- Returns a TSTRING that holds the base64 representation of 
//  mCRC
TSTRING cCRC32Signature::AsString() const
{
    if (cArchiveSigGen::Hex())
        return AsStringHex();
    
    TSTRING ret;
    char *ps_signature;
    char buf[100];
    uint32 local = mCRCInfo.crc;

    ps_signature = pltob64(&local, buf, 1);
    //ps_signature holds base64 representation of mCRCInfo.crc
#ifdef _UNICODE
    ret.resize(strlen(ps_signature));
    mbstowcs((TCHAR*)ret.data(), ps_signature, strlen(ps_signature));
#else
    ret.append(ps_signature);
#endif
    return ret;
}
void cEncoder::Encode( TSTRING& strIn ) const
{
    // TODO:BAM -- reserve space for strOut as an optimization?
    TSTRING strOut;         // encoded string we will build up

    TSTRING::const_iterator         cur = strIn.begin();  // pointer to working position in strIn
    const TSTRING::const_iterator   end = strIn.end();    // end of strIn
    TSTRING::const_iterator         first = end;          // identifies beginning of current character
    TSTRING::const_iterator         last  = end;          // identifies end of current character

    // while get next char (updates cur)
    while( cCharUtil::PopNextChar( cur, end, first, last ) )
    {
        bool fCharEncoded = false; // answers: did char need encoding?
        sack_type::const_iterator atE;

        // for all encoders
        for( atE = m_encodings.begin(); 
             atE != m_encodings.end();
             atE++ )
        {
            // does char need encoding?
            if( (*atE)->NeedsEncoding( first, last ) )
            {
                strOut += Encode( first, last, atE );
                fCharEncoded = true;
                break;  // each char should only fail at most one 
                        // encoding test, so it should be cool to quit
            }
        }

        if( ! fCharEncoded )
        {
            strOut.append( first, last ); // simply add current char to output since it needed no encoding
        }
    }

    // pass back encoded string
    strIn = strOut;
}
///////////////////////////////////////////////////////////////////////////////
// AsString -- Returns Base64 representation of mSignature in a TSTRING
TSTRING cHAVALSignature::AsString() const
{
    if (cArchiveSigGen::Hex())
        return AsStringHex();
    
    TSTRING ret;
    char buf[24];

    btob64((byte*)mSignature, buf, 128);
    //converting to base64 representation.

#ifdef _UNICODE     //making it TSTRING sensitive
    int length;
    length = strlen(buf);
    ret.resize(length);
    mbstowcs((TCHAR*) ret.data(), buf, length);
#else
    ret.append(buf);
#endif
    
    return ret;
}
TSTRING cSHASignature::AsString(void) const
{
    if (cArchiveSigGen::Hex())
        return AsStringHex();
    
    TSTRING ret;
    char* ps_signature; 
    char buf[100];
    
    ps_signature = btob64((uint8*)sha_digest, buf, SIG_UINT32_SIZE*sizeof(uint32)*8);
    //converting to base64 representation.

#ifdef _UNICODE                //making it TSTRING sensitive
    int length;
    length = strlen(ps_signature);
    ret.resize(length);
    mbstowcs((TCHAR*) ret.data(), ps_signature, length);
#else
    ret.append(ps_signature);
#endif
    return ret;
}
////////////////////////////////////////////////////////////////////////////////
// AsString -- Converts to Base64 representation and returns a TSTRING
TSTRING cMD5Signature::AsString() const
{
    if (cArchiveSigGen::Hex())
        return AsStringHex();
    
    TSTRING ret;
    char buf[24];

    ASSERT( sizeof( uint8 ) == sizeof( byte ) ); /* everything breaks otherwise */
    btob64((byte*)md5_digest, buf, SIG_BYTE_SIZE*8);
        //converting to base64 representation.

#ifdef _UNICODE     //making it TSTRING sensitive
    int length;
    length = strlen(buf);
    ret.resize(length);
    mbstowcs((TCHAR*) ret.data(), buf, length);
#else
    ret.append(buf);
#endif
    
    return ret;
}
void cEncoder::Decode( TSTRING& strIn ) const
{
    // TODO:BAM -- reserve space for strOut as an optimization?
    TSTRING strOut;         // decoded string we will build up

    TSTRING::const_iterator         cur = strIn.begin();  // pointer to working position in strIn
    const TSTRING::const_iterator   end = strIn.end();    // end of strIn
    TSTRING::const_iterator         first = end;          // identifies beginning of current character
    TSTRING::const_iterator         last  = end;          // identifies end of current character
    

    // while get next char (updates cur)
    while( cCharUtil::PopNextChar( cur, end, first, last ) )
    {
        // is this char the escape character?
        if( IsSingleTCHAR( first, last ) && 
            *first == iCharEncoder::EscapeChar() )
        {
            // get to identifier
            if( ! cCharUtil::PopNextChar( cur, end, first, last ) )
                ThrowAndAssert( eBadDecoderInput() );
            
            // this algorithm assumes that all identifiers are single char
            // so anything following the escape char should be a 
            // single-char identifier
            if( ! IsSingleTCHAR( first, last ) ) 
                THROW_INTERNAL( "displayencoder.cpp" );

            // determine to which encoding the identifier belongs
            bool fFoundEncoding = false;
            sack_type::const_iterator atE;
            for( atE = m_encodings.begin(); 
                 atE != m_encodings.end(); 
                 atE++ )
            {
                // is this the right encoding?
                if( *first == (*atE)->Identifier() )
                {
                    // this is the correct encoding....
                    fFoundEncoding = true;

                    // ...so decode char
                    strOut += (*atE)->Decode( &first, end ); // should modify cur
                    
                    cur = first; // advance current char pointer

                    break;  // no need to run other tests after 
                            // this because all identifiers should be unique
                }
            }

            if( ! fFoundEncoding )
                ThrowAndAssert( eUnknownEscapeEncoding( TSTRING( 1, *first ) ) );
        }
        else
        {        
            strOut.append( first, last );
        }
    }

    strIn = strOut;
}
Example #14
0
int main(int argc, char* argv[])
{
    // Get application path
    g_ApplicationExePath.append(argv[0]);

    // Calculate INI file path
    g_ApplicationIniPath = g_ApplicationExePath;
    g_ApplicationIniPath.resize(g_ApplicationIniPath.find_last_of(_T('.')));
    g_ApplicationIniPath.append(_T(".ini"));

    if (! InitInstance())
        return 255;

    Emulator_Start();

    // The main loop
    Uint32 ticksLast;
    Uint32 ticksLastFps = SDL_GetTicks();
    int frames = 0;
    while (!g_okQuit)
    {
        ticksLast = SDL_GetTicks();  // Time at frame start
        SDL_Event evt;
        while (SDL_PollEvent(&evt))
        {
            if (evt.type == SDL_QUIT)
            {
                g_okQuit = TRUE;
                break;
            }
            else
            {
                if (evt.type == SDL_KEYDOWN || evt.type == SDL_KEYUP ||
                        evt.type == SDL_JOYBUTTONDOWN || evt.type == SDL_JOYBUTTONUP)
                {
                    Main_OnKeyJoyEvent(evt);
                }
            }
        }

        if (g_okEmulatorRunning)
        {
            Emulator_SystemFrame();

            Main_DrawScreen();

            frames++;
        }

        // Delay
        Uint32 ticksNew = SDL_GetTicks();
        Uint32 ticksElapsed = ticksNew - ticksLast;
        g_LastDelay = 0;
        if (ticksElapsed < FRAME_TICKS)
        {
            g_LastDelay = FRAME_TICKS - ticksElapsed;
            SDL_Delay(FRAME_TICKS - ticksElapsed);
        }
        ticksLast = ticksNew;

        if (ticksLast - ticksLastFps > 1000)  //DEBUG: FPS calculation
        {
            g_LastFps = frames;
            frames = 0;
            ticksLastFps += 1000;
        }
    }

    Emulator_Stop();

    DoneInstance();

    return 0;
}
/// <summary>
/// <para name='Name'>GetEID</para>
/// <para name='Purpose'>Resolve the EID from the email address</para>
/// </summary>
/// <param name='szEmailAddress'>Email address to resolve</param>
/// <param name='sbEID'>[out]SBinary EID to return</param>
/// <returns>HRESULT</returns>
/// <remarks>
/// <para name='Notes'></para>
/// <para name='Author'>Kenn Guilstorf</para>
/// <para name='LastModified'>28Jan2016</para>
/// </remarks>
STDMETHODIMP ZybraxiSoft::CMailbox::GetEID(const TSTRING sEmailAddress, SBinary &sbEID)
{
	FBEG;
	HRESULT hr = S_OK;
	LPMDB lpDefaultMDB = NULL;
	LPEXCHANGEMANAGESTORE lpExStore = NULL;
	TSTRING sServerName;
	TSTRING sServerPre = TSTRING(SERVER_PRE);
	TSTRING sServerPost = TSTRING(SERVER_POST);
	TSTRING sServerDN = wstring();
	std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
	string sTempEmailAddress;
	string sTempServerDN;


	// Clean our sbEID
	sbEID.cb = 0;

	// Get a pointer to the default message store
	if (FAILED(hr = OpenDefaultMessageStore(
		&lpDefaultMDB)))
	{
		ERROR_MSG_W_HR("OpenDefaultMessageStore failed", hr);
		goto CLEANUP;
	}

	// Use the pointer to the default message store to
	// Get a pointer to the Manage Store interface
	if (FAILED(hr = lpDefaultMDB->QueryInterface(
		IID_IExchangeManageStore,
		(LPVOID*)&lpExStore)))
	{
		ERROR_MSG_W_HR("Getting the Exchange store manager failed", hr);
		goto CLEANUP;
	}

	// Get our Server Name
	if (FAILED(hr = this->GetServerNameFromProfile(sServerName)))
	{
		ERROR_MSG_W_HR("Getting the server name failed", hr);
		goto CLEANUP;
	}

	// Go ahead and build our server dn
	sServerDN.append(sServerPre.c_str());
	sServerDN.append(sServerName.c_str());
	sServerDN.append(sServerPost.c_str());

	// if we're in UNICODE, we need to convert; we can only pass ASCII
#if defined(UNICODE) || defined(_UNICODE)
	sTempServerDN = converter.to_bytes(sServerDN);
	sTempEmailAddress = converter.to_bytes(sEmailAddress);
#else
	sTempServerDN = sServerDN;
	sTempEmailAddress = sEmailAddress;
#endif

	// Get the EID
	if (FAILED(hr = lpExStore->CreateStoreEntryID(
		(LPSTR)sTempServerDN.c_str(),
		(LPSTR)sTempEmailAddress.c_str(),
		OPENSTORE_TAKE_OWNERSHIP,
		&sbEID.cb,
		(LPENTRYID*)&sbEID.lpb)))
	{
		ERROR_MSG_W_HR("CreateStoreEntryID failed", hr);
		goto CLEANUP;
	}

	// Check to make sure we got an actual EID
	if (sbEID.cb == 0)
	{
		hr = MAPI_E_NOT_FOUND;
		ERROR_MSG_W_HR("Failed to resolve the mailbox", hr);
		goto CLEANUP;
	}
	
CLEANUP:
	if (lpExStore)
	{
		lpExStore->Release();
		lpExStore = NULL;
	}

	if (lpDefaultMDB)
	{
		lpDefaultMDB->Release();
		lpDefaultMDB = NULL;
	}

	FEND;
	return hr;
}