예제 #1
0
	HRESULT SLog::splitFullPath(TSTRING szFullPath)
	{
		HRESULT retValue = S_OK;

		TSTRING szSlash = TSTRING(_T("/\\"));
		TSTRING szDot = TSTRING(_T("."));
		int iLastSlash, iLastDot;
		bool bBadPath = false;

		// Quick sanity check...
		if (szFullPath.empty())
		{
			retValue = ERROR_BAD_ARGUMENTS;
			goto EXIT;
		}

		// First, make sure we actually have strings...
		if (NULL == m_szLogFilePath)
			m_szLogFilePath = new TSTRING();

		if (NULL == m_szLogFileName)
			m_szLogFileName = new TSTRING();

		if (NULL == m_szLogFileExt)
			m_szLogFileExt = new TSTRING();

		// Make sure they're clear (remember, we may not have created them)
		m_szLogFilePath->clear();
		m_szLogFileName->clear();
		m_szLogFileExt->clear();

		// To peel apart the string, we need to find the last slash character
		iLastSlash = szFullPath.find_last_of(szSlash.c_str(), TNPOS);

		// Now, this could go either way; either we have no slash, in which case
		// this DOESN'T have a path, or we do and there's a path...
		if (iLastSlash == TNPOS)
		{
			// We didn't get a path...
			bBadPath = true;
		}
		else
		{
			// Get the path, if there is one...
			m_szLogFilePath->append(szFullPath.substr(0, (iLastSlash + 1)));

			// Does that path actually exist?
			WIN32_FILE_ATTRIBUTE_DATA dirData;
			if (!GetFileAttributesEx(m_szLogFilePath->c_str(),
				GetFileExInfoStandard,
				&dirData))
			{
				// We hit an error!
				DWORD dw;
				dw = GetLastError();
				retValue = HRESULT_FROM_WIN32(dw);
				bBadPath = true;
			}
			else if ((dirData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
			{
				// The path isn't to a directory!
				retValue = ERROR_BAD_PATHNAME;
				bBadPath = true;
			}
		}

		if (bBadPath)
		{
			// We either got no path or a bad path, so let's
			// set it to the Current Directory...
			// First, get the size of buffer we're going to need
			int iDirSize = GetCurrentDirectory(0, NULL);

			// Next, declare the buffer and use it to get the current directory
			m_szLogFilePath->clear();
			TCHAR* szDirBuffer = new TCHAR[iDirSize];
			GetCurrentDirectory(iDirSize, szDirBuffer);
			m_szLogFilePath->append(szDirBuffer);
			m_szLogFilePath->append(_T("\\"));		// Have to add the trailing slash
		}

		// To peel apart the extension, we need to find the last dot character
		iLastDot = szFullPath.find_last_of(szDot.c_str(), TNPOS);

		// We may or may not have a dot; no dot, no extension
		if (iLastDot == TNPOS)
		{
			iLastDot = szFullPath.length();
			m_szLogFileExt->append(DEFAULT_EXT);
		}
		else
		{
			m_szLogFileExt->append(szFullPath.substr(iLastDot));
		}

		// With all that out of the way, we can get our file name
		m_szLogFileName->append(szFullPath.substr((iLastSlash + 1), ( iLastDot - iLastSlash - 1 )));

	EXIT:
		return retValue;
	}
예제 #2
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;
}