Commit a747eca8 authored by Alexander Nicolaysen Sørnes's avatar Alexander Nicolaysen Sørnes Committed by Alexandre Julliard

wordpad: Improve file reading code.

parent a28f91f1
...@@ -100,17 +100,16 @@ static void AddSeparator(HWND hwndToolBar) ...@@ -100,17 +100,16 @@ static void AddSeparator(HWND hwndToolBar)
SendMessage(hwndToolBar, TB_ADDBUTTONS, 1, (LPARAM)&button); SendMessage(hwndToolBar, TB_ADDBUTTONS, 1, (LPARAM)&button);
} }
static LPSTR stream_buffer;
static LONG stream_buffer_size;
static DWORD CALLBACK stream_in(DWORD_PTR cookie, LPBYTE buffer, LONG cb, LONG *pcb) static DWORD CALLBACK stream_in(DWORD_PTR cookie, LPBYTE buffer, LONG cb, LONG *pcb)
{ {
LONG size = min(stream_buffer_size, cb); HANDLE hFile = (HANDLE)cookie;
DWORD read;
if(!ReadFile(hFile, buffer, cb, &read, 0))
return 1;
*pcb = read;
memcpy(buffer, stream_buffer, size);
stream_buffer_size -= size;
stream_buffer += size;
*pcb = size;
return 0; return 0;
} }
...@@ -152,9 +151,6 @@ static void set_caption(LPCWSTR wszNewFileName) ...@@ -152,9 +151,6 @@ static void set_caption(LPCWSTR wszNewFileName)
static void DoOpenFile(LPCWSTR szOpenFileName) static void DoOpenFile(LPCWSTR szOpenFileName)
{ {
HANDLE hFile; HANDLE hFile;
LPSTR pTemp;
DWORD size;
DWORD dwNumRead;
EDITSTREAM es; EDITSTREAM es;
hFile = CreateFileW(szOpenFileName, GENERIC_READ, FILE_SHARE_READ, NULL, hFile = CreateFileW(szOpenFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
...@@ -162,38 +158,13 @@ static void DoOpenFile(LPCWSTR szOpenFileName) ...@@ -162,38 +158,13 @@ static void DoOpenFile(LPCWSTR szOpenFileName)
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
return; return;
size = GetFileSize(hFile, NULL); es.dwCookie = (DWORD_PTR)hFile;
if (size == INVALID_FILE_SIZE)
{
CloseHandle(hFile);
return;
}
size++;
pTemp = HeapAlloc(GetProcessHeap(), 0, size);
if (!pTemp)
{
CloseHandle(hFile);
return;
}
if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
{
CloseHandle(hFile);
HeapFree(GetProcessHeap(), 0, pTemp);
return;
}
CloseHandle(hFile);
pTemp[dwNumRead] = 0;
memset(&es, 0, sizeof(es));
es.pfnCallback = stream_in; es.pfnCallback = stream_in;
stream_buffer = pTemp; /* FIXME: Handle different file formats */
stream_buffer_size = size; SendMessageW(hEditorWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es);
SendMessage(hEditorWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es); CloseHandle(hFile);
HeapFree(GetProcessHeap(), 0, pTemp);
SetFocus(hEditorWnd); SetFocus(hEditorWnd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment