| 3148 | } |
| 3149 | |
| 3150 | BFP_EXPORT intptr BFP_CALLTYPE BfpFile_Read(BfpFile* file, void* buffer, intptr size, int timeoutMS, BfpFileResult* outResult) |
| 3151 | { |
| 3152 | bool forceNormalRead = false; |
| 3153 | |
| 3154 | if ((file->mIsStd) && (file->mHandle == GetStdHandle(STD_INPUT_HANDLE))) |
| 3155 | { |
| 3156 | DWORD consoleMode = 0; |
| 3157 | GetConsoleMode(file->mHandle, &consoleMode); |
| 3158 | if ((consoleMode & ENABLE_LINE_INPUT) != 0) |
| 3159 | { |
| 3160 | forceNormalRead = true; |
| 3161 | } |
| 3162 | else |
| 3163 | { |
| 3164 | INPUT_RECORD record; |
| 3165 | DWORD numRead; |
| 3166 | while (true) |
| 3167 | { |
| 3168 | if (timeoutMS != -1) |
| 3169 | { |
| 3170 | if (!GetNumberOfConsoleInputEvents(file->mHandle, &numRead)) |
| 3171 | { |
| 3172 | forceNormalRead = true; |
| 3173 | break; |
| 3174 | } |
| 3175 | |
| 3176 | if (numRead == 0) |
| 3177 | { |
| 3178 | OUTRESULT(BfpFileResult_Timeout); |
| 3179 | return 0; |
| 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | if (!ReadConsoleInput(file->mHandle, &record, 1, &numRead)) |
| 3184 | { |
| 3185 | forceNormalRead = true; |
| 3186 | break; |
| 3187 | } |
| 3188 | if (numRead > 0) |
| 3189 | { |
| 3190 | if ((record.Event.KeyEvent.bKeyDown) && (record.Event.KeyEvent.uChar.AsciiChar != 0)) |
| 3191 | { |
| 3192 | memset(buffer, record.Event.KeyEvent.uChar.AsciiChar, 1); |
| 3193 | OUTRESULT(BfpFileResult_Ok); |
| 3194 | return 1; |
| 3195 | } |
| 3196 | } |
| 3197 | } |
| 3198 | } |
| 3199 | } |
| 3200 | |
| 3201 | if ((timeoutMS != -1) && (!forceNormalRead)) |
| 3202 | { |
| 3203 | if (file->mAsyncData == NULL) |
| 3204 | { |
| 3205 | OUTRESULT(BfpFileResult_InvalidParameter); |
| 3206 | return 0; |
| 3207 | } |