//------------------------------------------------------------------------------ int callback_sqlite_chrome(void *datas, int argc, char **argv, char **azColName) { FORMAT_CALBAK_READ_INFO *type = datas; char tmp[MAX_PATH]=""; char date[DATE_SIZE_MAX]=""; unsigned int i,size=0; if (type->type <= nb_sql_CHROME) { //special case of password !!! if(sql_CHROME[type->type].test_string_id == SPECIAL_CASE_CHROME_PASSWORD) { char password[MAX_PATH]="", raw_password[MAX_PATH]=""; //decrypt datas password !!! CRYPT_INTEGER_BLOB data_in, data_out; data_in.cbData = strlen(argv[3]); data_in.pbData = (BYTE*)argv[3]; snprintf(tmp,MAX_PATH,"%s, %s",argv[1],argv[2]); snprintf(raw_password,MAX_PATH,"%s",argv[3]); if (CryptUnprotectData(&data_out,NULL,NULL,NULL,NULL,0,&data_in)) { snprintf(password,MAX_PATH,"%s",data_out.pbData); LocalFree(data_out.pbData); } convertStringToSQL(tmp, MAX_PATH); convertStringToSQL(password, MAX_PATH); convertStringToSQL(raw_password, MAX_PATH); addPasswordtoDB(tmp_file_chrome,tmp,password,raw_password,SPECIAL_CASE_CHROME_PASSWORD,current_session_id,db_scan); }else { //copy datas for (i=0;i<argc && MAX_PATH-size > 0 && start_scan;i++) { if (argv[i] == NULL)continue; //date or not ? if (strlen(argv[i]) == DATE_SIZE_MAX-1) { if (argv[i][4] == '/' && argv[i][13] == ':') { if (strcmp("1970/01/01 01:00:00",argv[i])!=0 && strcmp("1601/01/01 01:00:00",argv[i])!=0)strncpy(date,argv[i],DATE_SIZE_MAX); continue; } } if (i>0)snprintf(tmp+size,MAX_PATH-size,", %s",convertUTF8toUTF16(argv[i], strlen(argv[i])+1)); else snprintf(tmp+size,MAX_PATH-size,"%s",convertUTF8toUTF16(argv[i], strlen(argv[i])+1)); size = strlen(tmp); } //get datas and write it convertStringToSQL(tmp, MAX_PATH); addChrometoDB(tmp_file_chrome,sql_CHROME[type->type].params,tmp,date,sql_CHROME[type->type].test_string_id,current_session_id,db_scan); } } return 0; }
bool RegistryObject::deleteValue( const char* pszSubKey, const char* pszValue ) { HKEY hKey; LONG lRes; #ifdef UNICODE UTF16 pszSafeSubKey[MAX_PATH]; UTF16 pszSafeValue[MAX_PATH]; convertUTF8toUTF16(pszSubKey, pszSafeSubKey, sizeof(pszSafeSubKey)); convertUTF8toUTF16(pszValue, pszSafeValue, sizeof(pszSafeValue)); #else UTF8 pszSafeSubKey[MAX_PATH]; UTF8 pszSafeValue[MAX_PATH]; dStrcpy( pszSafeSubKey, pszSubKey ); dStrcpy( pszSafeValue, pszValue ); #endif lRes = ::RegOpenKeyEx( m_hKey, pszSafeSubKey, 0, KEY_SET_VALUE, &hKey); if( lRes != ERROR_SUCCESS ) { SetLastError((DWORD)lRes); return false; } lRes = ::RegDeleteValue(hKey, pszSafeValue); RegCloseKey(hKey); if( lRes != ERROR_SUCCESS ) return false; return true; }
S32 Platform::messageBox(const UTF8 *title, const UTF8 *message, MBButtons buttons, MBIcons icon) { // Get us rendering while we're blocking. winState.renderThreadBlocked = true; #ifdef UNICODE const UTF16 *msg = convertUTF8toUTF16(message); const UTF16 *t = convertUTF8toUTF16(title); #else const UTF8 *msg = message; const UTF8 *t = title; #endif S32 ret = ::MessageBox(winState.appWindow, msg, t, getMaskFromID(sgButtonMap, buttons) | getMaskFromID(sgIconMap, icon)); #ifdef UNICODE delete [] msg; delete [] t; #endif // Dialog is gone. winState.renderThreadBlocked = false; return getMaskFromID(sgMsgBoxRetMap, ret); }
bool RegistryObject::setDWORD(const char* pszSubKey, const char* pszValue, DWORD dwValue) { HKEY hKey; LONG lRes; #ifdef UNICODE UTF16 pszSafeSubKey[MAX_PATH]; UTF16 pszSafeValue[MAX_PATH]; convertUTF8toUTF16(pszSubKey, pszSafeSubKey, sizeof(pszSafeSubKey)); convertUTF8toUTF16(pszValue, pszSafeValue, sizeof(pszSafeValue)); #else UTF8 pszSafeSubKey[MAX_PATH]; UTF8 pszSafeValue[MAX_PATH]; dStrcpy( pszSafeSubKey, pszSubKey ); dStrcpy( pszSafeValue, pszValue ); #endif createKey( pszSubKey ); lRes = ::RegOpenKeyEx(m_hKey, pszSafeSubKey, 0, KEY_WRITE, &hKey); if( lRes != ERROR_SUCCESS ) return false; lRes = ::RegSetValueEx(hKey, pszSafeValue,0,REG_DWORD,reinterpret_cast<BYTE*>(&dwValue),sizeof(DWORD)); ::RegCloseKey(hKey); if( lRes != ERROR_SUCCESS ) return false; return true; }
DWORD RegistryObject::getDWORD(const char* pszSubKey, const char* pszValue) { HKEY hKey; DWORD dwType = REG_DWORD; DWORD dwSize = sizeof(DWORD); DWORD dwValue = 0; LONG lRes; #ifdef UNICODE UTF16 pszSafeSubKey[MAX_PATH]; UTF16 pszSafeValue[MAX_PATH]; convertUTF8toUTF16(pszSubKey, pszSafeSubKey, sizeof(pszSafeSubKey)); convertUTF8toUTF16(pszValue, pszSafeValue, sizeof(pszSafeValue)); #else UTF8 pszSafeSubKey[MAX_PATH]; UTF8 pszSafeValue[MAX_PATH]; dStrcpy( pszSafeSubKey, pszSubKey ); dStrcpy( pszSafeValue, pszValue ); #endif lRes = ::RegOpenKeyEx(m_hKey, pszSafeSubKey, 0, KEY_READ, &hKey); if( lRes != ERROR_SUCCESS ) return static_cast<DWORD>(-1); lRes = ::RegQueryValueEx(hKey, pszSafeValue, 0, &dwType, (LPBYTE)&dwValue, &dwSize); ::RegCloseKey(hKey); if(lRes!=ERROR_SUCCESS) return static_cast<DWORD>(-1); return dwValue; }
//-------------------------------------- void Platform::AlertOK(const char *windowTitle, const char *message) { ShowCursor(true); #ifdef UNICODE UTF16 m[1024], t[512]; convertUTF8toUTF16((UTF8 *)windowTitle, t, sizeof(t)); convertUTF8toUTF16((UTF8 *)message, m, sizeof(m)); MessageBox(NULL, m, t, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TASKMODAL | MB_OK); #else MessageBox(NULL, message, windowTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TASKMODAL | MB_OK); #endif }
//-------------------------------------- bool Platform::AlertRetry(const char *windowTitle, const char *message) { ShowCursor(true); #ifdef UNICODE UTF16 m[1024], t[512]; convertUTF8toUTF16((UTF8 *)windowTitle, t, sizeof(t)); convertUTF8toUTF16((UTF8 *)message, m, sizeof(m)); return (MessageBox(NULL, m, t, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TASKMODAL | MB_RETRYCANCEL) == IDRETRY); #else return (MessageBox(NULL, message, windowTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TASKMODAL | MB_RETRYCANCEL) == IDRETRY); #endif }
//-------------------------------------- bool Platform::isSubDirectory(const char *pParent, const char *pDir) { if (!pParent || !*pDir) return false; const char* fileName = avar("%s/*", pParent); TempAlloc< TCHAR > file( dStrlen( fileName ) + 1 ); TempAlloc< TCHAR > dir( dStrlen( pDir ) + 1 ); #ifdef UNICODE convertUTF8toUTF16( fileName, file, file.size ); convertUTF8toUTF16( pDir, dir, dir.size ); #else dStrcpy( file, fileName ); dStrcpy( dir, pDir ); #endif backslash( file ); backslash( dir ); // this is somewhat of a brute force method but we need to be 100% sure // that the user cannot enter things like ../dir or /dir etc,... WIN32_FIND_DATA findData; HANDLE handle = FindFirstFile(file, &findData); if (handle == INVALID_HANDLE_VALUE) return false; do { // if it is a directory... if (findData.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY| FILE_ATTRIBUTE_OFFLINE| FILE_ATTRIBUTE_SYSTEM| FILE_ATTRIBUTE_TEMPORARY) ) { //FIXME: this has to be dStrcasecmp but there's no implementation for Unicode // and the names match if (dStrcmp(dir, findData.cFileName ) == 0) { // then we have a real sub directory FindClose(handle); return true; } } }while(FindNextFile(handle, &findData)); FindClose(handle); return false; }
ExecuteThread::ExecuteThread(const char *executable, const char *args /* = NULL */, const char *directory /* = NULL */) : Thread(0, NULL, false) { SHELLEXECUTEINFO shl; dMemset(&shl, 0, sizeof(shl)); shl.cbSize = sizeof(shl); shl.fMask = SEE_MASK_NOCLOSEPROCESS; char exeBuf[1024]; Platform::makeFullPathName(executable, exeBuf, sizeof(exeBuf)); TempAlloc< TCHAR > dirBuf( ( directory ? dStrlen( directory ) : 0 ) + 1 ); dirBuf[ dirBuf.size - 1 ] = 0; #ifdef UNICODE WCHAR exe[ 1024 ]; convertUTF8toUTF16( exeBuf, exe, sizeof( exe ) / sizeof( exe[ 0 ] ) ); TempAlloc< WCHAR > argsBuf( ( args ? dStrlen( args ) : 0 ) + 1 ); argsBuf[ argsBuf.size - 1 ] = 0; if( args ) convertUTF8toUTF16( args, argsBuf, argsBuf.size ); if( directory ) convertUTF8toUTF16( directory, dirBuf, dirBuf.size ); #else char* exe = exeBuf; char* argsBuf = args; if( directory ) dStrpcy( dirBuf, directory ); #endif backslash( exe ); backslash( dirBuf ); shl.lpVerb = TEXT( "open" ); shl.lpFile = exe; shl.lpParameters = argsBuf; shl.lpDirectory = dirBuf; shl.nShow = SW_SHOWNORMAL; if(ShellExecuteEx(&shl) && shl.hProcess) { mProcess = shl.hProcess; start(); } }
//-------------------------------------- S32 Platform::getFileSize(const char *pFilePath) { if (!pFilePath || !*pFilePath) return -1; TempAlloc< TCHAR > buf( dStrlen( pFilePath ) + 1 ); #ifdef UNICODE convertUTF8toUTF16( pFilePath, buf, buf.size ); #else dStrcpy( buf, pFilePath ); #endif backslash( buf ); // Get file info WIN32_FIND_DATA findData; HANDLE handle = FindFirstFile(buf, &findData); if(handle == INVALID_HANDLE_VALUE) return -1; FindClose(handle); // if the file is a Directory, Offline, System or Temporary then FALSE if (findData.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY| FILE_ATTRIBUTE_OFFLINE| FILE_ATTRIBUTE_SYSTEM| FILE_ATTRIBUTE_TEMPORARY) ) return -1; // must be a real file then return findData.nFileSizeLow; }
//-------------------------------------- bool Platform::createPath(const char *file) { TempAlloc< TCHAR > pathbuf( dStrlen( file ) + 1 ); #ifdef UNICODE TempAlloc< WCHAR > fileBuf( pathbuf.size ); convertUTF8toUTF16( file, fileBuf, fileBuf.size ); const WCHAR* fileName = fileBuf; const WCHAR* dir; #else const char* fileName = file; const char* dir; #endif pathbuf[ 0 ] = 0; U32 pathLen = 0; while((dir = dStrchr(fileName, '/')) != NULL) { TCHAR* pathptr = pathbuf; dMemcpy( pathptr + pathLen, fileName, ( dir - fileName ) * sizeof( TCHAR ) ); pathbuf[pathLen + dir-fileName] = 0; // ignore return value because we are fine with already existing directory CreateDirectory(pathbuf, NULL); pathLen += dir - fileName; pathbuf[pathLen++] = '\\'; fileName = dir + 1; } return true; }
///just check if the app's global mutex exists, and if so, ///return true - otherwise, false. Should be called before ExcludeOther /// at very start of app execution. bool Platform::checkOtherInstances(const char *mutexName) { #ifdef TORQUE_MULTITHREAD HANDLE pMutex = NULL; #ifdef UNICODE UTF16 b[512]; convertUTF8toUTF16((UTF8 *)mutexName, b, sizeof(b)); pMutex = CreateMutex(NULL, true, b); #else pMutex = CreateMutex(NULL, true, mutexName); #endif if(!pMutex) return false; if(GetLastError() == ERROR_ALREADY_EXISTS) { //another mutex of the same name exists //close ours CloseHandle(pMutex); pMutex = NULL; return true; } CloseHandle(pMutex); pMutex = NULL; #endif //we don;t care, always false return false; }
//----------------------------------------------------------------------------- bool Platform::setClipboard(const char *text) { ScrapRef clip; U32 textSize; OSStatus err = noErr; // make sure we have something to copy textSize = dStrlen(text); if(textSize == 0) return false; // get a local ref to the system clipboard GetScrapByName( kScrapClipboardScrap, kScrapClearNamedScrap, &clip ); // put the data on the clipboard as text err = PutScrapFlavor( clip, kScrapFlavorTypeText, kScrapFlavorMaskNone, textSize, text); // put the data on the clipboard as unicode const UTF16 *utf16Data = convertUTF8toUTF16(text); err |= PutScrapFlavor( clip, kScrapFlavorTypeUnicode, kScrapFlavorMaskNone, dStrlen(utf16Data) * sizeof(UTF16), utf16Data); delete [] utf16Data; // and see if we were successful. if( err == noErr ) return true; else return false; }
bool Platform::getFileTimes(const char *filePath, FileTime *createTime, FileTime *modifyTime) { WIN32_FIND_DATA findData; TempAlloc< TCHAR > fp( dStrlen( filePath ) + 1 ); #ifdef UNICODE convertUTF8toUTF16( filePath, fp, fp.size ); #else dStrcpy( fp, filePath ); #endif backslash( fp ); HANDLE h = FindFirstFile(fp, &findData); if(h == INVALID_HANDLE_VALUE) return false; if(createTime) { createTime->v1 = findData.ftCreationTime.dwLowDateTime; createTime->v2 = findData.ftCreationTime.dwHighDateTime; } if(modifyTime) { modifyTime->v1 = findData.ftLastWriteTime.dwLowDateTime; modifyTime->v2 = findData.ftLastWriteTime.dwHighDateTime; } FindClose(h); return true; }
// // Converts UTF-8 string to wchar_t type // UnicodeConversionResult convertUTF8toWCHAR(const UTF8 *& sourceStart, const UTF8 * sourceEnd, wchar_t *& targetStart, wchar_t * targetEnd, UnicodeConversionFlags flags) { Q_ASSERT(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4); if (sizeof(wchar_t) == 2) return convertUTF8toUTF16(sourceStart, sourceEnd, (UTF16 *&)targetStart, (UTF16 *)targetEnd, flags); else return convertUTF8toUTF32(sourceStart, sourceEnd, (UTF32 *&)targetStart, (UTF32 *)targetEnd, flags); }
StringTableEntry RegistryObject::getString(const char* pszSubKey, const char* pszValue) { HKEY hKey; LONG lRes; #ifdef UNICODE DWORD dwSize = 1024 * sizeof(UTF16); UTF16 pszSafeSubKey[1024]; UTF16 pszSafeValue[1024]; UTF16 pszSafeString[1024]; convertUTF8toUTF16(pszSubKey, pszSafeSubKey, sizeof(pszSafeSubKey)); convertUTF8toUTF16(pszValue, pszSafeValue, sizeof(pszSafeValue)); #else DWORD dwSize = 1024 * sizeof(UTF8); UTF8 pszSafeSubKey[1024]; UTF8 pszSafeValue[1024]; UTF8 pszSafeString[1024]; dStrcpy( pszSafeSubKey, pszSubKey ); dStrcpy( pszSafeValue, pszValue ); #endif lRes = ::RegOpenKeyEx(m_hKey, pszSafeSubKey, 0, KEY_READ, &hKey); if( lRes != ERROR_SUCCESS ) return StringTable->EmptyString; lRes = ::RegQueryValueEx(hKey, pszSafeValue, NULL, NULL, (BYTE*)pszSafeString, &dwSize); ::RegCloseKey(hKey); if( lRes != ERROR_SUCCESS ) return StringTable->EmptyString; char pszResultString[1024]; #ifdef UNICODE convertUTF16toUTF8(pszSafeString, pszResultString, sizeof(pszResultString)); #else dStrcpy( pszResultString, pszSafeString ); #endif return StringTable->insert(pszResultString); }
bool dFileRename(const char *oldName, const char *newName) { AssertFatal( oldName != NULL && newName != NULL, "dFileRename - NULL file name" ); TempAlloc< TCHAR > oldf( dStrlen( oldName ) + 1 ); TempAlloc< TCHAR > newf( dStrlen( newName ) + 1 ); #ifdef UNICODE convertUTF8toUTF16( oldName, oldf, oldf.size ); convertUTF8toUTF16( newName, newf, newf.size ); #else dStrcpy(oldf, oldName); dStrcpy(newf, newName); #endif backslash(oldf); backslash(newf); return MoveFile( oldf, newf ); }
bool RegistryObject::setString(const char* pszSubKey, const char* pszValue, const char* pszString) { HKEY hKey; LONG lRes; #ifdef UNICODE DWORD dwSize = dStrlen(pszString) * sizeof(UTF16); UTF16 pszSafeSubKey[1024]; UTF16 pszSafeValue[1024]; UTF16 pszSafeString[1024]; convertUTF8toUTF16(pszSubKey, pszSafeSubKey, sizeof(pszSafeSubKey)); convertUTF8toUTF16(pszValue, pszSafeValue, sizeof(pszSafeValue)); convertUTF8toUTF16(pszString, pszSafeString, sizeof(pszSafeString)); #else DWORD dwSize = dStrlen(pszString) * sizeof(UTF8); UTF8 pszSafeSubKey[1024]; UTF8 pszSafeValue[1024]; UTF8 pszSafeString[1024]; dStrcpy( pszSafeSubKey, pszSubKey ); dStrcpy( pszSafeValue, pszValue ); dStrcpy( pszSafeString, pszString ); #endif createKey( pszSubKey ); lRes = ::RegOpenKeyEx(m_hKey, pszSafeSubKey, 0, KEY_WRITE, &hKey); if( lRes != ERROR_SUCCESS) return false; lRes = ::RegSetValueEx(hKey, pszSafeValue, 0, REG_SZ, reinterpret_cast<const BYTE*>(pszSafeString), dwSize); ::RegCloseKey(hKey); if( lRes != ERROR_SUCCESS ) return false; return true; }
bool Win32RedBookDevice::open() { if(mAcquired) { setLastError("Device is already open."); return(false); } U32 error; // open the device MCI_OPEN_PARMS openParms; #ifdef UNICODE openParms.lpstrDeviceType = (LPCWSTR)MCI_DEVTYPE_CD_AUDIO; UTF16 buf[512]; convertUTF8toUTF16((UTF8 *)mDeviceName, buf, sizeof(buf)); openParms.lpstrElementName = buf; #else openParms.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_CD_AUDIO; openParms.lpstrElementName = mDeviceName; #endif error = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID, (DWORD_PTR)(LPMCI_OPEN_PARMS)&openParms); if(error) { // attempt to open as a shared device error = mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID|MCI_OPEN_SHAREABLE, (DWORD_PTR)(LPMCI_OPEN_PARMS)&openParms); if(error) { setLastError(error); return(false); } } // set time mode to milliseconds MCI_SET_PARMS setParms; setParms.dwTimeFormat = MCI_FORMAT_MILLISECONDS; error = mciSendCommand(openParms.wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)(LPMCI_SET_PARMS)&setParms); if(error) { setLastError(error); return(false); } // mDeviceId = openParms.wDeviceID; mAcquired = true; openVolume(); setLastError(""); return(true); }
UTF16* utf16() const { if( !mUTF16 ) { // Do this atomically to protect interned strings. UTF16* utf16 = convertUTF8toUTF16( mData ); if( !dCompareAndSwap( mUTF16,( UTF16* ) NULL, utf16 ) ) delete [] utf16; } return mUTF16; }
bool RegistryObject::valueExists( const char* pszSubKey, const char* pszValue ) { HKEY hKey; BYTE pBuffer[512]; DWORD dwType; DWORD dwSize = 512; LONG lRes = 0; #ifdef UNICODE UTF16 pszSafeSubKey[MAX_PATH]; UTF16 pszSafeValue[MAX_PATH]; convertUTF8toUTF16(pszSubKey, pszSafeSubKey, sizeof(pszSafeSubKey)); convertUTF8toUTF16(pszValue, pszSafeValue, sizeof(pszSafeValue)); #else UTF8 pszSafeSubKey[MAX_PATH]; UTF8 pszSafeValue[MAX_PATH]; dStrcpy( pszSafeSubKey, pszSubKey ); dStrcpy( pszSafeValue, pszValue ); #endif ZeroMemory(pBuffer,512); lRes = ::RegOpenKeyEx(m_hKey, pszSafeSubKey, 0, KEY_READ, &hKey); if( lRes != ERROR_SUCCESS ) { SetLastError((DWORD)lRes); return false; } lRes = ::RegQueryValueEx(hKey, pszSafeValue, 0, &dwType, (LPBYTE)&pBuffer, &dwSize); RegCloseKey(hKey); if(lRes != ERROR_SUCCESS ) return false; return true; }
U32 GFXDrawUtil::drawTextN( GFont *font, const Point2I &ptDraw, const UTF8 *in_string, U32 n, const ColorI *colorTable, const U32 maxColorIndex, F32 rot ) { // return on zero length strings if( n == 0 ) return ptDraw.x; // Convert to UTF16 temporarily. n++; // space for null terminator FrameTemp<UTF16> ubuf( n * sizeof(UTF16) ); convertUTF8toUTF16(in_string, ubuf, n); return drawTextN( font, ptDraw, ubuf, n, colorTable, maxColorIndex, rot ); }
void Win32CursorController::setCursorShape( const UTF8 *fileName, bool reload ) { #ifdef UNICODE const UTF16 *lFileName = convertUTF8toUTF16( fileName ); #else const UTF8 *lFileName = fileName; #endif if ( !gCursorShape || reload ) gCursorShape = LoadCursorFromFile( lFileName ); if ( gCursorShape ) SetCursor( gCursorShape ); }
void Platform::DumpDirectories(const string& path, vector<string>& outList) { string searchPath; Platform::MakeFullPathName("*", searchPath, &path); #ifdef UNICODE UTF16 search[1024]; convertUTF8toUTF16((UTF8 *)searchPath.c_str(), search, sizeof(search)); #else char *search = searchPath.c_str(); #endif WIN32_FIND_DATA findData; HANDLE handle = FindFirstFile((LPCWSTR)search, &findData); if (handle == INVALID_HANDLE_VALUE) { return; } do { #ifdef UNICODE char fnbuf[1024]; Platform::convertUTF16toUTF8((UTF16*)findData.cFileName, (UTF8 *)fnbuf, sizeof(fnbuf)); #else char *fnbuf = findData.cFileName; #endif if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // make sure it is a directory if (findData.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE|FILE_ATTRIBUTE_SYSTEM) ) continue; // skip . and .. directories if (strcmp(fnbuf, ".") == 0 || strcmp(fnbuf, "..") == 0) continue; // Skip excluded directores if(Platform::IsExcludedDirectory(fnbuf)) continue; outList.push_back(fnbuf); } } while(FindNextFile(handle, &findData)); FindClose(handle); }
bool Platform::setCurrentDirectory(StringTableEntry newDir) { if (Platform::getWebDeployment()) return true; TempAlloc< TCHAR > buf( dStrlen( newDir ) + 2 ); #ifdef UNICODE convertUTF8toUTF16( newDir, buf, buf.size - 1 ); #else dStrcpy( buf, newDir ); #endif backslash( buf ); return SetCurrentDirectory( buf ); }
bool RegistryObject::createKey(const char* pszSubKey) { HKEY hKey; DWORD dwFunc; LONG lRet; #ifdef UNICODE UTF16 pszSafeSubKey[MAX_PATH]; convertUTF8toUTF16(pszSubKey, pszSafeSubKey, sizeof(pszSafeSubKey)); lRet = ::RegCreateKeyEx( m_hKey, pszSafeSubKey, 0, (UTF16*)NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, (LPSECURITY_ATTRIBUTES)NULL, &hKey, &dwFunc); #else UTF8 pszSafeSubKey[MAX_PATH]; dStrcpy( pszSafeSubKey, pszSubKey ); lRet = ::RegCreateKeyEx( m_hKey, pszSafeSubKey, 0, (UTF8*)NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, (LPSECURITY_ATTRIBUTES)NULL, &hKey, &dwFunc); #endif if( lRet == ERROR_SUCCESS ) { ::RegCloseKey(hKey); hKey = (HKEY)NULL; return true; } ::SetLastError((DWORD)lRet); return false; }
//----------------------------------------------------------------------------- bool dFileDelete(const char * name) { AssertFatal( name != NULL, "dFileDelete - NULL file name" ); TempAlloc< TCHAR > buf( dStrlen( name ) + 1 ); #ifdef UNICODE convertUTF8toUTF16( name, buf, buf.size ); #else dStrcpy( buf, name ); #endif backslash( buf ); if( Platform::isFile( name ) ) return DeleteFile( buf ); else return RemoveDirectory( buf ); }
//----------------------------------------------------------------------------- // Functions that convert buffers of unicode code points //----------------------------------------------------------------------------- UTF16* convertUTF8toUTF16( const UTF8* unistring) { PROFILE_SCOPE(convertUTF8toUTF16_create); // allocate plenty of memory. U32 nCodepoints, len = dStrlen(unistring) + 1; FrameTemp<UTF16> buf(len); // perform conversion nCodepoints = convertUTF8toUTF16( unistring, buf, len); // add 1 for the NULL terminator the converter promises it included. nCodepoints++; // allocate the return buffer, copy over, and return it. UTF16 *ret = new UTF16[nCodepoints]; dMemcpy(ret, buf, nCodepoints * sizeof(UTF16)); return ret; }
bool RegistryObject::keyExists( const char* pszSubKey ) { HKEY hKey; LONG lRes = 0; #ifdef UNICODE UTF16 pszSafeSubKey[MAX_PATH]; //UTF16 pszSafeValue[MAX_PATH]; convertUTF8toUTF16(pszSubKey, pszSafeSubKey, sizeof(pszSafeSubKey)); #else UTF8 pszSafeSubKey[MAX_PATH]; dStrcpy( pszSafeSubKey, pszSubKey ); #endif lRes = ::RegOpenKeyEx(m_hKey, pszSafeSubKey, 0, KEY_READ, &hKey); if( lRes != ERROR_SUCCESS) return false; return true; }
//-------------------------------------- bool Platform::excludeOtherInstances(const char *mutexName) { #ifdef UNICODE UTF16 b[512]; convertUTF8toUTF16((UTF8 *)mutexName, b, sizeof(b)); gMutexHandle = CreateMutex(NULL, true, b); #else gMutexHandle = CreateMutex(NULL, true, mutexName); #endif if(!gMutexHandle) return false; if(GetLastError() == ERROR_ALREADY_EXISTS) { CloseHandle(gMutexHandle); gMutexHandle = NULL; return false; } return true; }