| 802 | } |
| 803 | |
| 804 | bool CMainWindow::LoadFile(HANDLE hFile, bool wantStdIn) |
| 805 | { |
| 806 | InitEditor(); |
| 807 | char data[4096] = { 0 }; |
| 808 | DWORD dwRead = 0; |
| 809 | |
| 810 | BOOL bRet = ReadFile(hFile, data, sizeof(data), &dwRead, nullptr); |
| 811 | bool bUTF8 = IsUTF8(data, dwRead); |
| 812 | while ((dwRead > 0) && (bRet)) |
| 813 | { |
| 814 | SendEditor(SCI_ADDTEXT, dwRead, |
| 815 | reinterpret_cast<LPARAM>(static_cast<char *>(data))); |
| 816 | if (auto sciStatus = static_cast<int>(SendEditor(SCI_GETSTATUS)); sciStatus > SC_STATUS_OK && sciStatus < SC_STATUS_WARN_START) |
| 817 | { |
| 818 | if (sciStatus == SC_STATUS_BADALLOC) |
| 819 | SetLastError(static_cast<DWORD>(E_OUTOFMEMORY)); |
| 820 | else |
| 821 | SetLastError(static_cast<DWORD>(E_FAIL)); |
| 822 | MessageBox(*this, static_cast<LPCWSTR>(CFormatMessageWrapper()), L"TortoiseGitUDiff", MB_ICONEXCLAMATION); |
| 823 | return false; |
| 824 | } |
| 825 | if (static_cast<Sci_Position>(SendEditor(SCI_GETTEXT)) >= 250 * 1024 * 1024) // styling gets really slow and Scintilla requires special initialization for large files |
| 826 | { |
| 827 | MessageBox(*this, static_cast<LPCWSTR>(ResString(hResource, IDS_ERR_FILE_TOOBIG)), L"TortoiseGitUDiff", MB_ICONEXCLAMATION); |
| 828 | return false; |
| 829 | } |
| 830 | bRet = ReadFile(hFile, data, sizeof(data), &dwRead, nullptr); |
| 831 | } |
| 832 | if (auto lastError = GetLastError(); !bRet && lastError != ERROR_BROKEN_PIPE) |
| 833 | { |
| 834 | if (hFile || wantStdIn) |
| 835 | { |
| 836 | MessageBox(*this, static_cast<LPCWSTR>(CFormatMessageWrapper()), L"TortoiseGitUDiff", MB_ICONEXCLAMATION); |
| 837 | return false; |
| 838 | } |
| 839 | SetTitle(L"Unnamed"); |
| 840 | InitEditor(); |
| 841 | bUTF8 = true; |
| 842 | } |
| 843 | SetupWindow(bUTF8); |
| 844 | return true; |
| 845 | } |
| 846 | |
| 847 | bool CMainWindow::LoadFile(LPCWSTR filename) |
| 848 | { |
no test coverage detected