/////////////////////////////////////////////////////////////// // // DelTree // // // /////////////////////////////////////////////////////////////// bool SharedUtil::DelTree ( const SString& strPath, const SString& strInsideHere ) { // Safety: Make sure strPath is inside strInsideHere WString wstrPath = FromUTF8( strPath ); WString wstrInsideHere = FromUTF8( strInsideHere ); if ( !wstrPath.BeginsWithI( wstrInsideHere ) ) { assert ( 0 ); return false; } DWORD dwBufferSize = ( wstrPath.length() + 3 ) * sizeof( wchar_t ); wchar_t *szBuffer = static_cast < wchar_t* > ( alloca ( dwBufferSize ) ); memset ( szBuffer, 0, dwBufferSize ); wcsncpy ( szBuffer, wstrPath, wstrPath.length() ); SHFILEOPSTRUCTW sfos; sfos.hwnd = NULL; sfos.wFunc = FO_DELETE; sfos.pFrom = szBuffer; // Double NULL terminated sfos.pTo = NULL; sfos.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; int status = SHFileOperationW(&sfos); return status == 0; }
float CBassAudio::GetSoundBPM(void) { if (m_fBPM == 0.0f && !m_bStream) { float fData = 0.0f; // open the same file as played but for bpm decoding detection DWORD bpmChan = BASS_StreamCreateFile(false, FromUTF8(m_strPath), 0, 0, BASS_STREAM_DECODE | BASS_UNICODE); if (!bpmChan) { bpmChan = BASS_MusicLoad(false, FromUTF8(m_strPath), 0, 0, BASS_MUSIC_DECODE | BASS_MUSIC_PRESCAN | BASS_UNICODE, 0); } // detect bpm in background and return progress in GetBPM_ProgressCallback function if (bpmChan) { fData = BASS_FX_BPM_DecodeGet(bpmChan, 0, GetLength(), 0, BASS_FX_FREESOURCE, NULL, NULL); } if (BASS_ErrorGetCode() != BASS_OK) { g_pCore->GetConsole()->Printf("BASS ERROR %d in BASS_FX_BPM_DecodeGet path:%s 3d:%d loop:%d", BASS_ErrorGetCode(), *m_strPath, m_b3D, m_bLoop); } else { m_fBPM = floor(fData); } BASS_FX_BPM_BeatFree(bpmChan); } return m_fBPM; }
int SharedUtil::File::Rename(const char* szOldFilename, const char* szNewFilename) { #ifdef WIN32 return _wrename(FromUTF8(szOldFilename), FromUTF8(szNewFilename)); #else return rename(szOldFilename, szNewFilename); #endif }
FILE* SharedUtil::File::Fopen(const char* szFilename, const char* szMode) { #ifdef WIN32 return _wfsopen(FromUTF8(szFilename), FromUTF8(szMode), _SH_DENYNO); #else return fopen(szFilename, szMode); #endif }
BOOL WINAPI MyMoveFileA( __in LPCSTR lpExistingFileName, __in LPCSTR lpNewFileName ) { return MoveFileW( FromUTF8( lpExistingFileName ), FromUTF8( lpNewFileName ) ); }
BOOL WINAPI MyCopyFileA( __in LPCSTR lpExistingFileName, __in LPCSTR lpNewFileName, __in BOOL bFailIfExists ) { return CopyFileW( FromUTF8( lpExistingFileName ), FromUTF8( lpNewFileName ), bFailIfExists ); }
SString SharedUtil::GetSystemLongPathName( const SString& strPath ) { wchar_t szBuffer[32000]; szBuffer[0] = 0; GetLongPathNameW( FromUTF8( strPath ), szBuffer, NUMELMS( szBuffer ) - 1 ); return ToUTF8( szBuffer ); }
void MeaXMLParser::StartElementHandler(void *userData, const XML_Char *elementName, const XML_Char **attrs) { MeaXMLParser *ps = static_cast<MeaXMLParser*>(userData); if (ps->m_haveDTD) { ps->m_validator->StartElement(ps->m_parser, elementName, attrs); } MeaXMLAttributes attributes(attrs, XML_GetSpecifiedAttributeCount(ps->m_parser)); CString name(FromUTF8(elementName)); CString container; if (!ps->m_elementStack->empty()) container = ps->m_elementStack->top(); ps->m_handler->StartElementHandler(container, name, attributes); ps->m_elementStack->push(name); if (ps->m_buildDOM) { MeaXMLNode* node = new MeaXMLNode(name, attributes); if (ps->m_nodeStack->empty()) { MeaAssert(ps->m_dom == NULL); ps->m_dom = node; } else { ps->m_nodeStack->top()->AddChild(node); } ps->m_nodeStack->push(node); } }
int MeaXMLParser::ExternalEntityRefHandler(XML_Parser parser, const XML_Char* context, const XML_Char* /*base*/, const XML_Char* systemId, const XML_Char* /*publicId*/) { if (systemId != NULL) { MeaXMLParser *ps = reinterpret_cast<MeaXMLParser*>(parser); CString sysId(FromUTF8(systemId)); if (sysId.Find(MeaXMLParser::m_homeURL) == 0) { TCHAR pathname[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR]; GetModuleFileName(NULL, pathname, _MAX_PATH); _tsplitpath_s(pathname, drive, _MAX_DRIVE, dir, _MAX_DIR, NULL, 0, NULL, 0); sysId = CString(drive) + CString(dir) + sysId.Mid(_tcslen(MeaXMLParser::m_homeURL)); sysId.Replace(_T('/'), _T('\\')); ps->m_pathnameStack->push(sysId); ps->m_context = context; ps->m_handler->ParseEntity(*ps, sysId); ps->m_context = NULL; ps->m_pathnameStack->pop(); } } return 1; }
void CBassAudio::PlayStreamIntern(void* arguments) { CBassAudio* pBassAudio = LockCallbackId(arguments); if (pBassAudio) { pBassAudio->m_pVars->criticalSection.Lock(); SString strURL = pBassAudio->m_pVars->strURL; long lFlags = pBassAudio->m_pVars->lFlags; pBassAudio->m_pVars->criticalSection.Unlock(); UnlockCallbackId(); // This can take a while HSTREAM pSound = BASS_StreamCreateURL(FromUTF8(strURL), 0, lFlags | BASS_UNICODE, NULL, NULL); CBassAudio* pBassAudio = LockCallbackId(arguments); if (pBassAudio) { pBassAudio->m_pVars->criticalSection.Lock(); pBassAudio->m_pVars->bStreamCreateResult = true; pBassAudio->m_pVars->pSound = pSound; pBassAudio->m_pVars->criticalSection.Unlock(); } else { // Deal with unwanted pSound g_pClientGame->GetManager()->GetSoundManager()->QueueChannelStop(pSound); } } UnlockCallbackId(); }
SString CScreenShot::GetScreenShotPath ( int iNumber ) { //Create a search string SString strScreenShotName ( "%s\\mta-screen*.png", &szScreenShotPath[0] ); HANDLE hFind; SString strReturn = ""; WIN32_FIND_DATAW fdFindData; int i = 1; //Find the first match hFind = FindFirstFileW(FromUTF8( strScreenShotName ), &fdFindData); //Check if the first match failed if ( hFind != INVALID_HANDLE_VALUE) { if (iNumber == 1) { //We wanted the first file strReturn = SString("%s\\%s",&szScreenShotPath[0],fdFindData.cFileName); } else { //Loop through and find all occurences of the file while (FindNextFileW(hFind, &fdFindData)) { //Keep going until we find the last file i++; if (iNumber == i) { strReturn = SString("%s\\%s",&szScreenShotPath[0], fdFindData.cFileName); break; } } } } FindClose(hFind); //Close the file handle // Get Return the file directory return strReturn; }
bool CAudioContainerSA::GetRawAudioData ( eAudioLookupIndex lookupIndex, int bankIndex, int audioIndex, uint8*& dataOut, unsigned int& lengthOut, int& iSampleRateOut ) { int numBanks = m_pLookupTable->CountIndex ( lookupIndex ); if ( numBanks == 0 ) return false; // Get archive file size std::ifstream archive ( FromUTF8( GetAudioArchiveName ( lookupIndex ) ), std::ios::binary ); SAudioLookupEntrySA* lookupEntry = m_pLookupTable->GetEntry ( lookupIndex, bankIndex ); if ( !lookupEntry ) return false; // Read audio archive bank header (an audio archieve has multiple bank headers) SAudioBankHeaderSA bankHeader; // Seek to the bank offset and read the header archive.seekg ( lookupEntry->offset ); if ( !archive.read ( reinterpret_cast<char*> ( &bankHeader ), sizeof ( SAudioBankHeaderSA ) ) ) return false; // Get offsets to calculate the length SAudioEntrySA* audioEntry = &bankHeader.sounds[audioIndex]; if ( !audioEntry ) return false; unsigned int rawLength; if ( audioIndex+1 < bankHeader.numSounds ) // hacky fix: audioIndex starts at 0 { SAudioEntrySA* nextAudioEntry = &bankHeader.sounds[audioIndex+1]; if ( !nextAudioEntry ) return false; rawLength = nextAudioEntry->offset - audioEntry->offset; } else if ( audioIndex+1 == bankHeader.numSounds ) { rawLength = lookupEntry->length - audioEntry->offset; } else return false; // 2MB check in case of user modification errors (Max length of standard audio files is 560KB) if ( rawLength > 2 * 1024 * 1024 ) return false; // Now we are ready to read the audio data :) uint8* buffer = new uint8[rawLength]; dataOut = buffer; lengthOut = rawLength; iSampleRateOut = audioEntry->sampleRate; // Seek to the correct offset and read archive.seekg ( lookupEntry->offset + sizeof(SAudioBankHeaderSA) + audioEntry->offset ); // Or just archive.seekg ( archive.tellg() + audioEntry->offset ) archive.read(reinterpret_cast<char*> ( buffer ), rawLength ); return !archive.fail(); }
SString SharedUtil::GetSystemShortPathName(const SString& strPath) { wchar_t szBuffer[32000]; szBuffer[0] = 0; if (!GetShortPathNameW(FromUTF8(strPath), szBuffer, NUMELMS(szBuffer) - 1)) return strPath; return ToUTF8(szBuffer); }
int SharedUtil::File::Delete(const char* szFilename) { #ifdef WIN32 return _wremove(FromUTF8(szFilename)); #else return remove(szFilename); #endif }
BOOL WINAPI MySetDllDirectoryA( __in_opt LPCSTR lpPathName ) { return SetDllDirectoryW( FromUTF8( lpPathName ) ); }
// Get drive root from path SString SharedUtil::GetPathDriveName( const SString& strPath ) { wchar_t szDrive[4] = L""; int iDriveNumber = PathGetDriveNumberW( FromUTF8( strPath ) ); if ( iDriveNumber > -1 ) PathBuildRootW( szDrive, iDriveNumber ); return ToUTF8( szDrive ); }
int SharedUtil::File::Mkdir(const char* szPath, int iMode) { #ifdef WIN32 return _wmkdir(FromUTF8(szPath)); #else return mkdir(szPath, (mode_t)iMode); #endif }
BOOL WINAPI MyDeleteFileA( __in LPCSTR lpFileName ) { return DeleteFileW( FromUTF8( lpFileName ) ); }
HMODULE WINAPI MyLoadLibraryA( __in LPCSTR lpLibFileName ) { return LoadLibraryW( FromUTF8( lpLibFileName ) ); }
int SharedUtil::File::Rmdir(const char* szPath) { #ifdef WIN32 return _wrmdir(FromUTF8(szPath)); #else return rmdir(szPath); #endif }
DWORD WINAPI MyGetFileAttributesA( __in LPCSTR lpFileName ) { return GetFileAttributesW( FromUTF8( lpFileName ) ); }
BOOL WINAPI MyRemoveDirectoryA( __in LPCSTR lpPathName ) { return RemoveDirectoryW( FromUTF8( lpPathName ) ); }
bool CWebCore::Initialise () { CefMainArgs mainArgs; void* sandboxInfo = nullptr; CefRefPtr<CCefApp> app { new CCefApp }; #if CEF_ENABLE_SANDBOX CefScopedSandboxInfo scopedSandbox; sandboxInfo = scopedSandbox.sandbox_info(); #endif if ( CefExecuteProcess ( mainArgs, app, sandboxInfo ) >= 0 ) return false; CefSettings settings; #if !CEF_ENABLE_SANDBOX settings.no_sandbox = true; #endif // Specifiy sub process executable path #ifndef MTA_DEBUG CefString ( &settings.browser_subprocess_path ).FromWString( FromUTF8( CalcMTASAPath ( "MTA\\CEF\\CEFLauncher.exe" ) ) ); #else CefString ( &settings.browser_subprocess_path ).FromWString( FromUTF8( CalcMTASAPath ( "MTA\\CEF\\CEFLauncher_d.exe" ) ) ); #endif CefString ( &settings.resources_dir_path ).FromWString ( FromUTF8( CalcMTASAPath( "MTA\\CEF") ) ); CefString ( &settings.locales_dir_path ).FromWString( FromUTF8( CalcMTASAPath( "MTA\\CEF\\locales" ) ) ); CefString ( &settings.log_file ).FromWString ( FromUTF8( CalcMTASAPath ( "MTA\\CEF\\cefdebug.txt" ) ) ); #ifdef MTA_DEBUG settings.log_severity = cef_log_severity_t::LOGSEVERITY_INFO; #else settings.log_severity = cef_log_severity_t::LOGSEVERITY_WARNING; #endif settings.multi_threaded_message_loop = true; settings.windowless_rendering_enabled = true; bool state = CefInitialize ( mainArgs, settings, app, sandboxInfo ); // Register custom scheme handler factory CefRegisterSchemeHandlerFactory ( "mtalocal", "", app ); CefRegisterSchemeHandlerFactory ( "http", "mta", app ); return state; }
BOOL WINAPI MySetFileAttributesA( __in LPCSTR lpFileName, __in DWORD dwFileAttributes ) { return SetFileAttributesW( FromUTF8( lpFileName ), dwFileAttributes ); }
std::auto_ptr<std::istream> UnixFileSystem::open_file(const std::string& filename) { #ifdef WIN32 return std::auto_ptr<std::istream>(new std::ifstream(FromUTF8(filename.c_str()))); #else return std::auto_ptr<std::istream>(new std::ifstream(filename.c_str())); #endif }
std::wstring const FromDouble(double const value, size_t const prec) { char format[16] = {0}; //sprintf_s(format, 16, "%%.%df", prec); sprintf(format, "%%.%df", (int)prec); char stringValue[64] = {0}; //sprintf_s(stringValue, 64, format, value); sprintf(stringValue, format, value); return FromUTF8(stringValue); }
HMODULE WINAPI MyGetModuleHandleA( __in_opt LPCSTR lpModuleName ) { if ( !lpModuleName ) return GetModuleHandleW( NULL ); return GetModuleHandleW( FromUTF8( lpModuleName ) ); }
size_t BUnicodeChar::UTF8StringLength(const char *str, size_t maxLength) { size_t len = 0; while (len < maxLength && *str) { FromUTF8(&str); len++; } return len; }
HMODULE WINAPI MyLoadLibraryExA( __in LPCSTR lpLibFileName, __reserved HANDLE hFile, __in DWORD dwFlags ) { return LoadLibraryExW( FromUTF8( lpLibFileName ), hFile, dwFlags ); }
BOOL WINAPI MyGetDiskFreeSpaceExA( __in_opt LPCSTR lpDirectoryName, __out_opt PULARGE_INTEGER lpFreeBytesAvailableToCaller, __out_opt PULARGE_INTEGER lpTotalNumberOfBytes, __out_opt PULARGE_INTEGER lpTotalNumberOfFreeBytes ) { return GetDiskFreeSpaceExW( FromUTF8( lpDirectoryName ), lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes ); }