static void test_StrRChrW(void) { WCHAR string[129]; WORD count; /* this test crashes on win2k SP4 */ /*ok(!StrRChrW(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/ for (count = 32; count < 128; count++) string[count] = count; string[128] = '\0'; for (count = 32; count < 128; count++) { LPWSTR result = StrRChrW(string+32, NULL, count); INT pos = result - string; ok(pos == count, "found char %d in wrong place: got %d, expected %d\n", count, pos, count); } for (count = 32; count < 128; count++) { LPWSTR result = StrRChrW(string+count+1, NULL, count); ok(!result, "found char %d not in the string\n", count); } for (count = 32; count < 128; count++) { LPWSTR result = StrRChrW(string+count+1, string + 127, count); ok(!result, "found char %d not in the string\n", count); } }
wchar_t* BLBS_GetIniFullPath(wchar_t* iniFullPath, const size_t bufSize) { GetModuleFileNameW(NULL, iniFullPath, bufSize); wchar_t* dirPath = StrRChrW(iniFullPath, NULL, L'\\')+1; StringCbCopyW(dirPath, bufSize, BL_SettingFile); return iniFullPath; }
/******************************************************************************* * GAMEUX_createStatsDirectory * * Helper function, creates directory to store game statistics * * Parameters * path [I] path to game statistics file. * base directory of this file will * be created if it doesn't exists */ static HRESULT GAMEUX_createStatsDirectory(LPCWSTR lpFilePath) { HRESULT hr; WCHAR lpDirectoryPath[MAX_PATH]; LPCWSTR lpEnd; lpEnd = StrRChrW(lpFilePath, NULL, '\\'); lstrcpynW(lpDirectoryPath, lpFilePath, lpEnd-lpFilePath+1); hr = HRESULT_FROM_WIN32(SHCreateDirectoryExW(NULL, lpDirectoryPath, NULL)); if(hr == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS) || hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) hr = S_FALSE; return hr; }
void change_to_directory_of_file(LPCWSTR fileName) { WCHAR wcbuffer[MAX_PATH]; StrCpyW(wcbuffer, fileName); #if defined (WINDOWS_VERSION) LPWSTR backSlashAt = StrRChrW(wcbuffer, NULL, L'\\'); if (backSlashAt != NULL) { wcbuffer[wcslen(wcbuffer) - wcslen(backSlashAt)] = L'\0'; SetCurrentDirectoryW(wcbuffer); } #else if (strrchr(wcbuffer, '/') != NULL) { strrchr(wcbuffer, '/')[0] = 0; chdir(wcbuffer); } #endif }
/******************************************************************************* * _registerGame * Registers test suite executable as game in Games Explorer. Required to test * game statistics. */ static HRESULT _registerGame(void) { HRESULT hr; WCHAR sExePath[MAX_PATH]; BSTR bstrExeName, bstrExePath; DWORD dwExeNameLen; /* prepare path to binary */ dwExeNameLen = GetModuleFileNameW(NULL, sExeName, sizeof (sExeName) / sizeof (sExeName[0])); hr = (dwExeNameLen!= 0 ? S_OK : E_FAIL); lstrcpynW(sExePath, sExeName, StrRChrW(sExeName, NULL, '\\') - sExeName + 1); bstrExeName = SysAllocString(sExeName); if(!bstrExeName) hr = E_OUTOFMEMORY; bstrExePath = SysAllocString(sExePath); if(!bstrExePath) hr = E_OUTOFMEMORY; if(SUCCEEDED(hr)) { gameInstanceId = GUID_NULL; hr = CoCreateInstance(&CLSID_GameExplorer, NULL, CLSCTX_INPROC_SERVER, &IID_IGameExplorer, (LPVOID*)&ge); } if(SUCCEEDED(hr)) hr = IGameExplorer_AddGame(ge, bstrExeName, bstrExePath, GIS_CURRENT_USER, &gameInstanceId); if(FAILED(hr) && ge) { IGameExplorer_Release(ge); ge = NULL; } SysFreeString(bstrExeName); SysFreeString(bstrExePath); return hr; }
// // Searches for files according to the specified Mask starting from the specified Path. // For every file found allocates FILE_DESCW structure and links all theese structures into the FileListHead. // Returns number of files found. // Note: In the ANSI version of FindFirstFile the name is limited to MAX_PATH characters. So we have to use UNICODE version // to completely scan all files. // ULONG FilesScanW( PWCHAR Path, // directory to search in, should be ended with "\" PWCHAR Mask, // search mask PLIST_ENTRY FilesList, // the list where all FILE_DESCW structures will be linked PCRITICAL_SECTION FilesListLock, // file list locking object (OPTIONAL) ULONG SearchPathLen, // the length of the initial search path in chars, used to keep directory structure // relative to the search path ULONG SearchFlags // various flags ) { ULONG Found = 0, PathLen, MaskLen, ScanLen = MAX_PATH; LPWIN32_FIND_DATAW FindData; PWCHAR ScanPath, ResolvedPath = NULL; if (FindData = AppAlloc(sizeof(WIN32_FIND_DATAW))) { if (ResolvedPath = FilesExpandEnvironmentVariablesW(Path)) Path = ResolvedPath; PathLen = wcslen(Path); MaskLen = wcslen(Mask); if (SearchPathLen == 0) SearchPathLen = PathLen; while ((PathLen + MaskLen + 2) > ScanLen) // 1 for "\\" and 1 for "\0" ScanLen += MAX_PATH; if (ScanPath = AppAlloc(ScanLen * sizeof(WCHAR))) { HANDLE hFind; PFILE_DESCW fDesc; memset(FindData, 0, sizeof(WIN32_FIND_DATA)); PathCombineW(ScanPath, Path, Mask); // Searching for files within the current directory first if ((hFind = FindFirstFileW(ScanPath, FindData)) != INVALID_HANDLE_VALUE) { do { if ((FindData->nFileSizeHigh) || (FindData->nFileSizeLow > FILE_SIZE_MAX)) continue; if (FindData->cFileName[0] == '.') continue; if (fDesc = FileDescAlloc(sizeof(FILE_DESCW) + (PathLen + wcslen(Mask) + wcslen(FindData->cFileName) + 2) * sizeof(WCHAR))) { LPWSTR pDir, pPath; wcscpy((PWCHAR)&fDesc->Path, Path); if (pDir = StrRChrW(Mask, NULL, L'\\')) { PathCombineW((PWCHAR)&fDesc->Path, Path, Mask); *PathFindFileNameW((PWCHAR)&fDesc->Path) = 0; pPath = (PWCHAR)&fDesc->Path; } else pPath = Path; PathCombineW((PWCHAR)&fDesc->Path, pPath, FindData->cFileName); fDesc->SearchPathLen = SearchPathLen; fDesc->Flags = SearchFlags; if (FilesListLock) EnterCriticalSection(FilesListLock); InsertTailList(FilesList, &fDesc->Entry); if (FilesListLock) LeaveCriticalSection(FilesListLock); Found += 1; } } while(FindNextFileW(hFind, FindData) && WaitForSingleObject(g_AppShutdownEvent, 0) == WAIT_TIMEOUT); FindClose(hFind); } // if ((hFind = FindFirstFileW(ScanPath, FindData)) != INVALID_HANDLE_VALUE) // Files are searched, looking for directories to scan them recursively PathCombineW(ScanPath, Path, L"*"); if ((hFind = FindFirstFileW(ScanPath, FindData)) != INVALID_HANDLE_VALUE) { do { if (FindData->cFileName[0] != '.' && (FindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { MaskLen = wcslen(FindData->cFileName); if ((PathLen + MaskLen + 2) > ScanLen) // 1 for "\\" and 1 for "\0" { AppFree(ScanPath); do { ScanLen += MAX_PATH; } while ((PathLen + MaskLen + 2) > ScanLen); if (!(ScanPath = AppAlloc(ScanLen * sizeof(WCHAR)))) break; // not enough memory } // if ((PathLen + MaskLen + 2) > ScanLen) PathCombineW(ScanPath, Path, FindData->cFileName); Found += FilesScanW(ScanPath, Mask, FilesList, FilesListLock, SearchPathLen, SearchFlags); } // if (FindData->cFileName[0] != '.' && } while(FindNextFileW(hFind, FindData) && WaitForSingleObject(g_AppShutdownEvent, 0) == WAIT_TIMEOUT); FindClose(hFind); } // if (hFind = FindFirstFileW(ScanPath, FindData)) if (ScanPath) AppFree(ScanPath); } // if (ScanPath = if (ResolvedPath) AppFree(ResolvedPath); AppFree(FindData); } // if (FindData) return(Found); }