| 724 | static DWORD WINAPI writeScreenshot(void* data) |
| 725 | #else |
| 726 | static void* writeScreenshot(void* data) |
| 727 | #endif |
| 728 | { |
| 729 | ScreenshotData* ssdata = (ScreenshotData*)data; |
| 730 | |
| 731 | const std::string dirname = getScreenShotDirName(); |
| 732 | const std::string prefix = "bzfi"; |
| 733 | const std::string ext = ".png"; |
| 734 | |
| 735 | // scan the directory and start numbering with the filename |
| 736 | // that follows the existing filename with the highest snap number |
| 737 | int snap = 0; |
| 738 | |
| 739 | #ifdef _WIN32 |
| 740 | const std::string pattern = dirname + prefix + "*" + ext; |
| 741 | WIN32_FIND_DATA findData; |
| 742 | HANDLE h = FindFirstFile(pattern.c_str(), &findData); |
| 743 | if (h != INVALID_HANDLE_VALUE) { |
| 744 | std::string file; |
| 745 | while (FindNextFile(h, &findData)) { |
| 746 | file = findData.cFileName; |
| 747 | const int number = atoi((file.substr(file.length() - 8, 4)).c_str()); |
| 748 | if (snap < number) { |
| 749 | snap = number; |
| 750 | } |
| 751 | } |
| 752 | } |
| 753 | #else |
| 754 | const std::string pattern = prefix + "*" + ext; |
| 755 | DIR* directory = opendir(dirname.c_str()); |
| 756 | if (directory) { |
| 757 | struct dirent* contents; |
| 758 | std::string file; |
| 759 | while ((contents = readdir(directory))) { |
| 760 | file = contents->d_name; |
| 761 | if (glob_match(pattern, file)) { |
| 762 | const int number = atoi((file.substr(file.length() - 8, 4)).c_str()); |
| 763 | if (snap < number) { |
| 764 | snap = number; |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | closedir(directory); |
| 769 | } |
| 770 | #endif // _WIN32 |
| 771 | |
| 772 | snap++; |
| 773 | std::string filename = dirname + prefix + TextUtils::format("%04d", snap) + ext; |
| 774 | |
| 775 | std::ostream* f = FILEMGR.createDataOutStream(filename.c_str(), true, true); |
| 776 | |
| 777 | if (f != NULL) { |
| 778 | |
| 779 | const std::string& renderer = ssdata->renderer; |
| 780 | unsigned char* pixels = ssdata->pixels; |
| 781 | const int xsize = ssdata->xsize; |
| 782 | const int ysize = ssdata->ysize; |
| 783 | const int channels = ssdata->channels; |
no test coverage detected