MCPcopy Create free account
hub / github.com/TortoiseGit/TortoiseGit / LoadFile

Method LoadFile

src/TortoiseUDiff/MainWindow.cpp:804–845  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

802}
803
804bool 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
847bool CMainWindow::LoadFile(LPCWSTR filename)
848{

Callers 4

BuildRegexSubitemsMethod · 0.80
wWinMainFunction · 0.80
LoadMethod · 0.80

Calls 3

ResStringClass · 0.85
SetTitleFunction · 0.85

Tested by

no test coverage detected