| 219 | #include <strsafe.h> |
| 220 | |
| 221 | void getFontFilePaths(std::vector<std::string>& pFiles, |
| 222 | const std::string& pDir, |
| 223 | const std::string& pExt) |
| 224 | { |
| 225 | WIN32_FIND_DATA ffd; |
| 226 | LARGE_INTEGER filesize; |
| 227 | TCHAR szDir[MAX_PATH]; |
| 228 | size_t length_of_arg; |
| 229 | DWORD dwError=0; |
| 230 | HANDLE hFind = INVALID_HANDLE_VALUE; |
| 231 | |
| 232 | // Check that the input path plus 3 is not longer than MAX_PATH. |
| 233 | // Three characters are for the "\*" plus NULL appended below. |
| 234 | StringCchLength(pDir.c_str(), MAX_PATH, &length_of_arg); |
| 235 | |
| 236 | if (length_of_arg > (MAX_PATH - 3)) { |
| 237 | FG_ERROR("WIN API call: Directory path is too long", FG_ERR_FILE_NOT_FOUND); |
| 238 | } |
| 239 | |
| 240 | //printf("\nTarget directory is %s\n\n", pDir.c_str()); |
| 241 | // Prepare string for use with FindFile functions. First, copy the |
| 242 | // string to a buffer, then append '\*' to the directory name. |
| 243 | StringCchCopy(szDir, MAX_PATH, pDir.c_str()); |
| 244 | std::string wildcard = "\\*" + pExt; |
| 245 | StringCchCat(szDir, MAX_PATH, wildcard.c_str()); |
| 246 | |
| 247 | // Find the first file in the directory. |
| 248 | hFind = FindFirstFile(szDir, &ffd); |
| 249 | if (INVALID_HANDLE_VALUE == hFind) { |
| 250 | FG_ERROR("WIN API call: file fetch in DIR failed", FG_ERR_FILE_NOT_FOUND); |
| 251 | } |
| 252 | |
| 253 | // List all the files in the directory with some info about them. |
| 254 | do { |
| 255 | if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| 256 | // It is a directory, skip the entry |
| 257 | //_tprintf(TEXT(" %s <DIR>\n"), ffd.cFileName); |
| 258 | } else { |
| 259 | filesize.LowPart = ffd.nFileSizeLow; |
| 260 | filesize.HighPart = ffd.nFileSizeHigh; |
| 261 | //_tprintf(TEXT(" %s %ld bytes\n"), ffd.cFileName, filesize.QuadPart); |
| 262 | pFiles.push_back(std::string(ffd.cFileName)); |
| 263 | } |
| 264 | } while (FindNextFile(hFind, &ffd) != 0); |
| 265 | |
| 266 | dwError = GetLastError(); |
| 267 | if (dwError != ERROR_NO_MORE_FILES) { |
| 268 | FG_ERROR("WIN API call: files fetch returned no files", FG_ERR_FILE_NOT_FOUND); |
| 269 | } |
| 270 | |
| 271 | FindClose(hFind); |
| 272 | } |
| 273 | #endif |
| 274 | |
| 275 | std::string toString(const float pVal, const std::string pFormat) |