////////////////////////////////////////////////////////////////////////////////// // Function name : util_RemoveLastPathElement // Description : // effectively pops off a path element from the end, except for the root dir, where it does nothing // it removes any slashes before and after the element // ///root//foo/ -> leaves "///root" ("foo" is strElem) // ///root -> leaves "" ("root" is strElem) // // -> leaves "" ("" is strElem) // // Return type : void // Argument : TSTRING& strPath // Argument : TSTRING& strElem ///////////////////////////////////////////////////////////////////////////////// void util_RemoveLastPathElement(TSTRING& strPath, TSTRING& strElem) { // remove all trailing separators util_RemoveTrailingSeps(strPath); // find the last separator TSTRING::size_type lastSep = strPath.rfind(TW_SLASH); // if separator was found, take all chars after it if (lastSep != TSTRING::npos) { strElem = strPath.substr(lastSep + 1); strPath.resize(lastSep + 1); } else // no seps in name, take whole string { // last element strElem = strPath; strPath.erase(); } // remove all trailing separators util_RemoveTrailingSeps(strPath); }
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; }
///////////////////////////////////////////////////////////////////////// // Function name : util_TrailingSep // Description : ensure that a path ( fLeaveSep ? "has" : "does not have" ) a trailing slash // // Return type : bool : was there a trailing slash? // Argument : TSTRING& str // Argument : bool fLeaveSep ///////////////////////////////////////////////////////////////////////////////// bool util_TrailingSep(TSTRING& str, bool fLeaveSep) { bool fWasSep = false; // if there's a trailing sep if (!str.empty() && str[str.size() - 1] == TW_SLASH) { if (!fLeaveSep) str.resize(str.size() - 1); fWasSep = true; } else // else no trailing sep { if (fLeaveSep) str += TW_SLASH; fWasSep = false; } return (fWasSep); }
/////////////////////////////////////////////////////////////////////////////// // 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; }
/////////////////////////////////////////////////////////////////////////////// // 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; }
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; }