Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ add_executable(${PROJECT_NAME} WIN32
resource.h
dxview.rc)

target_compile_options(${PROJECT_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>)
target_compile_definitions(${PROJECT_NAME} PRIVATE _UNICODE UNICODE)
target_link_libraries(${PROJECT_NAME} PRIVATE dxguid.lib comctl32.lib version.lib)

find_package(directx-headers CONFIG QUIET)
Expand Down
886 changes: 446 additions & 440 deletions ddraw.cpp

Large diffs are not rendered by default.

1,213 changes: 610 additions & 603 deletions dxg.cpp

Large diffs are not rendered by default.

2,114 changes: 1,047 additions & 1,067 deletions dxgi.cpp

Large diffs are not rendered by default.

127 changes: 97 additions & 30 deletions dxprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <shlobj.h>

BOOL g_PrintToFile = FALSE; // Don't print to printer print to dxview.log
TCHAR g_PrintToFilePath[MAX_PATH]; // "Print" to this file instead of dxview.log
WCHAR g_PrintToFilePath[MAX_PATH]; // "Print" to this file instead of dxview.log

namespace
{
Expand Down Expand Up @@ -151,14 +151,78 @@ namespace
//-----------------------------------------------------------------------------
VOID DoMessage(DWORD dwTitle, DWORD dwMsg)
{
TCHAR strTitle[MAX_TITLE];
TCHAR strMsg[MAX_MESSAGE];
WCHAR strTitle[MAX_TITLE];
WCHAR strMsg[MAX_MESSAGE];

LoadString(GetModuleHandle(nullptr), dwTitle, strTitle, MAX_TITLE);
LoadString(GetModuleHandle(nullptr), dwMsg, strMsg, MAX_MESSAGE);
MessageBox(nullptr, strMsg, strTitle, MB_OK);
}

//-----------------------------------------------------------------------------
// Name: ConvertEncoding()
// Desc: Convert output file encoding
//-----------------------------------------------------------------------------
VOID ConvertEncoding(HANDLE hFile, UINT CodePage)
{
LARGE_INTEGER pos;
LARGE_INTEGER srcSize;
DWORD dwRead;
DWORD dwWrite;
WCHAR* srcStr = NULL;
int srcLen = 0;
char* dstStr = NULL;
int dstLen = 0;

if (hFile == NULL || hFile == INVALID_HANDLE_VALUE)
goto lblCLEANUP;

pos.QuadPart = 0;
if (!SetFilePointerEx(hFile, pos, &srcSize, FILE_CURRENT))
goto lblCLEANUP;
if (srcSize.QuadPart == 0)
return; // no content

srcStr = (WCHAR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, srcSize.LowPart);
if (srcStr == NULL)
goto lblCLEANUP;

pos.QuadPart = 0;
if (!SetFilePointerEx(hFile, pos, NULL, FILE_BEGIN))
goto lblCLEANUP;

if (!ReadFile(hFile, srcStr, srcSize.LowPart, &dwRead, NULL))
goto lblCLEANUP;
srcLen = (int)(dwRead / sizeof(WCHAR));

dstLen = WideCharToMultiByte(CodePage, 0, srcStr, srcLen, NULL, 0, NULL, NULL);
if (dstLen <= 0)
goto lblCLEANUP;

dstStr = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dstLen * sizeof(char));
if (dstStr == NULL)
goto lblCLEANUP;

if (WideCharToMultiByte(CodePage, 0, srcStr, srcLen, dstStr, dstLen, NULL, NULL) != dstLen)
goto lblCLEANUP;

pos.QuadPart = 0;
if (!SetFilePointerEx(hFile, pos, NULL, FILE_BEGIN))
goto lblCLEANUP;

if (!WriteFile(hFile, dstStr, dstLen * sizeof(char), &dwWrite, NULL))
goto lblCLEANUP;
if (dwWrite != dstLen * sizeof(char))
goto lblCLEANUP;

SetEndOfFile(hFile); // new file end

lblCLEANUP:
if (srcStr != NULL)
HeapFree(GetProcessHeap(), 0, srcStr);
if (dstStr != NULL)
HeapFree(GetProcessHeap(), 0, dstStr);
}

//-----------------------------------------------------------------------------
// Name: PrintStats()
Expand All @@ -184,10 +248,11 @@ namespace
BOOL fResult = FALSE;
BOOL fStartDoc = FALSE;
BOOL fDisableWindow = FALSE;
LPTSTR pstrTitle = nullptr;
LPTSTR pstrBuff = nullptr;
LPWSTR pstrTitle = nullptr;
LPWSTR pstrBuff = nullptr;
DWORD dwCurrCopy;
HANDLE hHeap = nullptr;
DWORD buffCnt;
DWORD buffSize;
DWORD cchLen;
TV_ITEM tvi;
Expand Down Expand Up @@ -246,8 +311,9 @@ namespace
}

// Create line buffer
buffSize = (pci.dwCharsPerLine + 1) * sizeof(TCHAR);
pstrBuff = (LPTSTR)HeapAlloc(hHeap, HEAP_NO_SERIALIZE, buffSize);
buffCnt = (pci.dwCharsPerLine + 1);
buffSize = buffCnt * sizeof(WCHAR);
pstrBuff = (LPWSTR)HeapAlloc(hHeap, HEAP_NO_SERIALIZE, buffSize);
if (!pstrBuff)
{
// Error, not enough memory
Expand Down Expand Up @@ -281,32 +347,32 @@ namespace
{
SetWindowText(g_hAbortPrintDlg, pstrBuff);
SetAbortProc(pd.hDC, AbortProc);
cchLen = static_cast<DWORD>(_tcsclen(pstrBuff));
DWORD cbSize = (cchLen + 1) * sizeof(TCHAR);
pstrTitle = (LPTSTR)HeapAlloc(hHeap, HEAP_NO_SERIALIZE, cbSize);
cchLen = static_cast<DWORD>(wcslen(pstrBuff));
DWORD cbSize = (cchLen + 1) * sizeof(WCHAR);
pstrTitle = (LPWSTR)HeapAlloc(hHeap, HEAP_NO_SERIALIZE, cbSize);
if (!pstrTitle)
{
// Error, not enough memory
goto lblCLEANUP;
}

strcpy_s(pstrTitle, cbSize, pstrBuff);
wcscpy_s(pstrTitle, cchLen + 1, pstrBuff);
pstrTitle[cchLen] = 0;
}
else
{
SetWindowText(g_hAbortPrintDlg, TEXT("Unknown"));
SetWindowText(g_hAbortPrintDlg, L"Unknown");
SetAbortProc(pd.hDC, AbortProc);
cchLen = static_cast<DWORD>(_tcsclen(TEXT("Unknown")));
DWORD cbSize = (cchLen + 1) * sizeof(TCHAR);
pstrTitle = (LPTSTR)HeapAlloc(hHeap, HEAP_NO_SERIALIZE, cbSize);
cchLen = static_cast<DWORD>(wcslen(L"Unknown"));
DWORD cbSize = (cchLen + 1) * sizeof(WCHAR);
pstrTitle = (LPWSTR)HeapAlloc(hHeap, HEAP_NO_SERIALIZE, cbSize);
if (!pstrTitle)
{
// Error, not enough memory
goto lblCLEANUP;
}

strcpy_s(pstrTitle, cbSize, TEXT("Unknown"));
wcscpy_s(pstrTitle, cchLen + 1, L"Unknown");
pstrTitle[cchLen] = 0;
}

Expand All @@ -320,22 +386,22 @@ namespace
// Start document
if (g_PrintToFile)
{
const TCHAR* pstrFile;
TCHAR buff[MAX_PATH];
if (strlen(g_PrintToFilePath) > 0)
const WCHAR* pstrFile;
WCHAR buff[MAX_PATH];
if (wcslen(g_PrintToFilePath) > 0)
pstrFile = g_PrintToFilePath;
else
{
HRESULT hr = SHGetFolderPath(nullptr, CSIDL_DESKTOP, nullptr, SHGFP_TYPE_CURRENT, buff);
if (SUCCEEDED(hr))
{
strcat_s(buff, MAX_PATH, TEXT("\\dxview.log"));
wcscat_s(buff, MAX_PATH, L"\\dxview.log");
pstrFile = buff;
}
else
pstrFile = TEXT("dxview.log");
pstrFile = L"dxview.log";
}
g_FileHandle = CreateFile(pstrFile, GENERIC_WRITE, 0, nullptr,
g_FileHandle = CreateFile(pstrFile, GENERIC_READ | GENERIC_WRITE, 0, nullptr,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
}
else
Expand Down Expand Up @@ -381,8 +447,8 @@ namespace
tvi.cchTextMax = pci.dwCharsPerLine;
if (TreeView_GetItem(hTreeWnd, &tvi))
{
cchLen = static_cast<DWORD>(_tcslen(pstrBuff));
cchLen = __min(cchLen, buffSize);
cchLen = static_cast<DWORD>(wcslen(pstrBuff));
cchLen = __min(cchLen, buffCnt);
if (cchLen > 0)
{
int xOffset = (int)(pci.dwCurrIndent * DEF_TAB_SIZE * pci.dwCharWidth);
Expand Down Expand Up @@ -517,6 +583,7 @@ namespace
{
if (g_PrintToFile)
{
ConvertEncoding(g_FileHandle, CP_ACP);
CloseHandle(g_FileHandle);
}
else
Expand Down Expand Up @@ -643,7 +710,7 @@ BOOL DXView_OnFile(HWND hWnd, HWND hTreeWnd, BOOL bPrintAll)
// Desc: Prints text to page at specified location
//-----------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT PrintLine(int xOffset, int yOffset, LPCTSTR pszBuff, size_t cchBuff,
HRESULT PrintLine(int xOffset, int yOffset, LPCWSTR pszBuff, size_t cchBuff,
PRINTCBINFO* pci)
{
if (!pci)
Expand All @@ -661,19 +728,19 @@ HRESULT PrintLine(int xOffset, int yOffset, LPCTSTR pszBuff, size_t cchBuff,
if (g_PrintToFile)
{
DWORD dwDummy;
TCHAR Temp[80];
WCHAR Temp[80];

int offset = (xOffset - iLastXPos) / pci->dwCharWidth;

if (offset < 0 || offset >= 80)
return S_OK;

memset(Temp, ' ', sizeof(TCHAR) * 79);
for (auto& c : Temp) c = L' ';
Temp[offset] = 0;
WriteFile(g_FileHandle, Temp, (xOffset - iLastXPos) / pci->dwCharWidth, &dwDummy, nullptr);
WriteFile(g_FileHandle, Temp, (xOffset - iLastXPos) * sizeof(WCHAR) / pci->dwCharWidth, &dwDummy, nullptr);
iLastXPos = (xOffset - iLastXPos) + (pci->dwCharWidth * static_cast<DWORD>(cchBuff));

WriteFile(g_FileHandle, pszBuff, static_cast<DWORD>(cchBuff), &dwDummy, nullptr);
WriteFile(g_FileHandle, pszBuff, static_cast<DWORD>(cchBuff) * sizeof(WCHAR), &dwDummy, nullptr);
}
else
{
Expand All @@ -695,7 +762,7 @@ HRESULT PrintNextLine(PRINTCBINFO* pci)
{
DWORD dwDummy;

WriteFile(g_FileHandle, "\r\n", 2, &dwDummy, nullptr);
WriteFile(g_FileHandle, L"\r\n", 4, &dwDummy, nullptr);
iLastXPos = 0;
return S_OK;
}
Expand Down
Loading