void CZipPathComponent::SetFullPath(LPCTSTR lpszFullPath) { TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; TCHAR szFname[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; CZipString szTempPath(lpszFullPath); const CZipString szPrefix = _T("\\\\?\\unc\\"); int i = -1, iLen = szPrefix.GetLength(); if (iLen > szTempPath.GetLength()) iLen = szTempPath.GetLength(); CZipString szPossiblePrefix = szTempPath.Left(iLen); szPossiblePrefix.MakeLower(); // must perform case insensitive comparison while (++i < iLen && szPossiblePrefix[i] == szPrefix[i]); if (i == 2 || i == 4 || i == 8) // unc path, unicode path or unc path meeting windows file name conventions { m_szPrefix = szTempPath.Left(i); szTempPath = szTempPath.Mid(i); } else m_szPrefix.Empty(); _tsplitpath(szTempPath, szDrive , szDir, szFname, szExt); m_szDrive = szDrive; m_szDirectory = szDir; m_szDirectory.TrimLeft(m_cSeparator); m_szDirectory.TrimRight(m_cSeparator); SetExtension(szExt); m_szFileTitle = szFname; }
void RageTexture::GetFrameDimensionsFromFileName( CString sPath, int* piFramesWide, int* piFramesHigh ) { *piFramesWide = *piFramesHigh = 1; // set default values in case we don't find the dimension in the file name sPath.MakeLower(); const CString sFName = SetExtension( sPath, "" ); CStringArray arrayBits; split( sFName, " ", arrayBits, false ); /* XXX: allow dims to be in parens */ for( unsigned i=0; i<arrayBits.size(); i++ ) { // Test to see if it looks like "%ux%u" (e.g. 16x8) CStringArray arrayDimensionsBits; split( arrayBits[i], "x", arrayDimensionsBits, false ); if( arrayDimensionsBits.size() != 2 ) continue; else if( !IsAnInt(arrayDimensionsBits[0]) || !IsAnInt(arrayDimensionsBits[1]) ) continue; *piFramesWide = atoi(arrayDimensionsBits[0]); *piFramesHigh = atoi(arrayDimensionsBits[1]); return; } }
/* Given the INI for a font, find all of the texture pages for the font. */ void Font::GetFontPaths( const RString &sFontIniPath, vector<RString> &asTexturePathsOut ) { RString sPrefix = SetExtension( sFontIniPath, "" ); vector<RString> asFiles; GetDirListing( sPrefix + "*", asFiles, false, true ); for( unsigned i = 0; i < asFiles.size(); ++i ) { if( !asFiles[i].Right(4).EqualsNoCase(".ini") ) asTexturePathsOut.push_back( asFiles[i] ); } }
DTLSContext() : PSSLContext(PSSLContext::DTLSv1) { PStringStream dn; dn << "/O=" << PProcess::Current().GetManufacturer() << "/CN=*"; PSSLPrivateKey pk(1024); if (!m_cert.CreateRoot(dn, pk)) { PTRACE(1, "Could not create certificate for DTLS."); return; } if (!UseCertificate(m_cert)) { PTRACE(1, "Could not use DTLS certificate."); return; } if (!UsePrivateKey(pk)) { PTRACE(1, "Could not use private key for DTLS."); return; } PStringStream ext; for (PINDEX i = 0; i < PARRAYSIZE(ProfileNames); ++i) { const OpalMediaCryptoSuite* cryptoSuite = OpalMediaCryptoSuiteFactory::CreateInstance(ProfileNames[i].m_opalName); if (cryptoSuite) { if (!ext.IsEmpty()) ext << ':'; ext << ProfileNames[i].m_dtlsName; } } if (!SetExtension(ext)) { PTRACE(1, "Could not set TLS extension for SSL context."); return; } }
bool LoadStudioCollisionModel( char const* pModelName, CUtlBuffer& buf ) { char tmp[1024]; SetExtension( tmp, pModelName, ".phy" ); // No luck, gotta build it // Construct the file name... char const* pFileName = ConstructFileName( tmp ); if (!LoadFile( pFileName, buf )) { // this is not an error, the model simply has no PHY file return false; } phyheader_t *header = (phyheader_t *)buf.PeekGet(); if ( header->size != sizeof(*header) || header->solidCount <= 0 ) return false; return true; }
bool Sprite::LoadFromTexture( RageTextureID ID ) { LOG->Trace( "Sprite::LoadFromTexture( %s )", ID.filename.c_str() ); if( !m_pTexture || !(m_pTexture->GetID() == ID) ) { /* Load the texture if it's not already loaded. We still need * to do the rest, even if it's the same texture, since we need * to reset Sprite::m_size, etc. */ UnloadTexture(); m_pTexture = TEXTUREMAN->LoadTexture( ID ); ASSERT( m_pTexture->GetTextureWidth() >= 0 ); ASSERT( m_pTexture->GetTextureHeight() >= 0 ); } ASSERT( m_pTexture != NULL ); /* Hack: if we load "_blank", mark the actor hidden, so we can short-circuit * rendering later on. (This helps NoteField rendering.) */ if( !SetExtension(Basename(ID.filename), "").CompareNoCase("_blank") ) this->SetHidden( true ); // the size of the sprite is the size of the image before it was scaled Sprite::m_size.x = (float)m_pTexture->GetSourceFrameWidth(); Sprite::m_size.y = (float)m_pTexture->GetSourceFrameHeight(); // Assume the frames of this animation play in sequential order with 0.1 second delay. m_States.clear(); for( int i=0; i<m_pTexture->GetNumFrames(); i++ ) { State newState = { i, 0.1f }; m_States.push_back( newState ); } // apply clipping (if any) if( m_fRememberedClipWidth != -1 && m_fRememberedClipHeight != -1 ) ScaleToClipped( m_fRememberedClipWidth, m_fRememberedClipHeight ); return true; }
void Pathname::SetFilename(const char *filename) { char *dot = strrchr(filename,'.'); if (dot == NULL) { SetFiletitle(filename); SetExtension(""); return; } int tllen = dot-filename; int exlen = strlen(dot); char *c = (char *)alloca((tllen+1)*sizeof(*c)); memcpy(c,filename,tllen); c[tllen] = 0; if (exlen+tllen+1<_end-_filetitle) { memcpy(_filetitle,c,tllen+1); _extension = _filetitle+tllen+1; memcpy(_extension,dot,exlen+1); RebuildPath(); } else RebuildData(_path,c,dot,strlen(_path),tllen,exlen); }
bool DEncrypt(const char* filename) { //Open allocate/read a file into memory FILE *pFile; pFile = fopen (filename, "rb"); if(! pFile) Exit("Failed to open input file\n"); long lFileSize; //Size of input file unsigned char *pBuff; //Holds the input file contents unsigned char *pOutBuff; //Holds the output goodies // obtain file size. fseek (pFile , 0 , SEEK_END); lFileSize= ftell (pFile); rewind (pFile); // allocate memory to contain the whole file. pBuff = (unsigned char*) malloc (lFileSize); pOutBuff = (unsigned char*) malloc (lFileSize); if (pBuff == NULL || pOutBuff == NULL) { fclose(pFile); std::cout << "Could not allocate buffer" << std::endl; return false; } // copy the file into the buffer. fread (pBuff,1,lFileSize,pFile); //clean the output buffer memset(pOutBuff,NULL,lFileSize); fclose(pFile); //Lets start the ice goodies! IceKey ice( 0 ); // level 0 = 64bit key ice.set( (unsigned char*) g_ICEKey ); // set key int blockSize = ice.blockSize(); unsigned char *p1 = pBuff; unsigned char *p2 = pOutBuff; // encrypt data in 8 byte blocks int bytesLeft = lFileSize; while ( bytesLeft >= blockSize ) { if ( g_Encrypt ) ice.encrypt( p1, p2 ); else ice.decrypt( p1, p2 ); bytesLeft -= blockSize; p1+=blockSize; p2+=blockSize; } //The end chunk doesn't get an encryption? that sux... memcpy( p2, p1, bytesLeft ); size_t outLength = strlen(filename) + MAX_EXTENSION + 1; char *pOutPath = (char *)malloc(outLength); strncpy(pOutPath,filename,outLength); SetExtension(pOutPath, outLength, g_Extension); pFile = fopen (pOutPath , "wb"); if(pFile == NULL) { fprintf( stderr, "Was not able to open output file for writing.\n" ); free(pBuff); free(pOutBuff); free(pOutPath); return false; } fwrite (pOutBuff , 1 , lFileSize , pFile); fclose (pFile); free(pBuff); free(pOutBuff); free(pOutPath); return true; }