From c444231b874c6c351ef59a5afbe4563b63b707af Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Thu, 4 Oct 2018 10:20:12 +0200 Subject: [PATCH] [MSPORTS] Check and show which parallel port is in use. --- dll/win32/msports/lang/bg-BG.rc | 1 + dll/win32/msports/lang/de-DE.rc | 1 + dll/win32/msports/lang/en-US.rc | 1 + dll/win32/msports/lang/es-ES.rc | 1 + dll/win32/msports/lang/he-IL.rc | 1 + dll/win32/msports/lang/it-IT.rc | 1 + dll/win32/msports/lang/ja-JP.rc | 1 + dll/win32/msports/lang/pl-PL.rc | 1 + dll/win32/msports/lang/ro-RO.rc | 1 + dll/win32/msports/lang/ru-RU.rc | 1 + dll/win32/msports/lang/sq-AL.rc | 1 + dll/win32/msports/lang/tr-TR.rc | 1 + dll/win32/msports/lang/uk-UA.rc | 1 + dll/win32/msports/lang/zh-CN.rc | 1 + dll/win32/msports/lang/zh-TW.rc | 1 + dll/win32/msports/parallel.c | 107 ++++++++++++++++++++++++++++++-- dll/win32/msports/resource.h | 1 + 17 files changed, 118 insertions(+), 5 deletions(-) diff --git a/dll/win32/msports/lang/bg-BG.rc b/dll/win32/msports/lang/bg-BG.rc index de8fa745bd0..cdc3c25a167 100644 --- a/dll/win32/msports/lang/bg-BG.rc +++ b/dll/win32/msports/lang/bg-BG.rc @@ -38,4 +38,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/de-DE.rc b/dll/win32/msports/lang/de-DE.rc index b968518dbe2..f1ccb23a448 100644 --- a/dll/win32/msports/lang/de-DE.rc +++ b/dll/win32/msports/lang/de-DE.rc @@ -38,4 +38,5 @@ BEGIN IDS_PARITY "Gerade,Ungerade,Keine,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,Keine" + IDS_PORT_IN_USE " (wird benutzt)" END diff --git a/dll/win32/msports/lang/en-US.rc b/dll/win32/msports/lang/en-US.rc index baf27250419..eb37b840b62 100644 --- a/dll/win32/msports/lang/en-US.rc +++ b/dll/win32/msports/lang/en-US.rc @@ -38,4 +38,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/es-ES.rc b/dll/win32/msports/lang/es-ES.rc index dd6587b6bf2..d6c7c700c21 100644 --- a/dll/win32/msports/lang/es-ES.rc +++ b/dll/win32/msports/lang/es-ES.rc @@ -38,4 +38,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/he-IL.rc b/dll/win32/msports/lang/he-IL.rc index e6fef329c31..61933ac3858 100644 --- a/dll/win32/msports/lang/he-IL.rc +++ b/dll/win32/msports/lang/he-IL.rc @@ -38,4 +38,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/it-IT.rc b/dll/win32/msports/lang/it-IT.rc index eeaad20568b..666a6b88868 100644 --- a/dll/win32/msports/lang/it-IT.rc +++ b/dll/win32/msports/lang/it-IT.rc @@ -38,4 +38,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/ja-JP.rc b/dll/win32/msports/lang/ja-JP.rc index 25e5dfca793..cedc65f5576 100644 --- a/dll/win32/msports/lang/ja-JP.rc +++ b/dll/win32/msports/lang/ja-JP.rc @@ -38,4 +38,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/pl-PL.rc b/dll/win32/msports/lang/pl-PL.rc index d7af8e7626b..6cd025fedf6 100644 --- a/dll/win32/msports/lang/pl-PL.rc +++ b/dll/win32/msports/lang/pl-PL.rc @@ -46,4 +46,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/ro-RO.rc b/dll/win32/msports/lang/ro-RO.rc index caa284ef72d..825eeb50ffd 100644 --- a/dll/win32/msports/lang/ro-RO.rc +++ b/dll/win32/msports/lang/ro-RO.rc @@ -44,4 +44,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/ru-RU.rc b/dll/win32/msports/lang/ru-RU.rc index d6ac1e7f609..f90eb9c1579 100644 --- a/dll/win32/msports/lang/ru-RU.rc +++ b/dll/win32/msports/lang/ru-RU.rc @@ -44,4 +44,5 @@ BEGIN IDS_PARITY "Чёт,Нечёт,Нет,Маркер,Пробел" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Аппаратное,Нет" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/sq-AL.rc b/dll/win32/msports/lang/sq-AL.rc index 73cc86ada10..6ee7f1f58fe 100644 --- a/dll/win32/msports/lang/sq-AL.rc +++ b/dll/win32/msports/lang/sq-AL.rc @@ -42,4 +42,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/tr-TR.rc b/dll/win32/msports/lang/tr-TR.rc index 39bad63929a..c7132feff22 100644 --- a/dll/win32/msports/lang/tr-TR.rc +++ b/dll/win32/msports/lang/tr-TR.rc @@ -40,4 +40,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/uk-UA.rc b/dll/win32/msports/lang/uk-UA.rc index 0f161170f53..503cb492e80 100644 --- a/dll/win32/msports/lang/uk-UA.rc +++ b/dll/win32/msports/lang/uk-UA.rc @@ -46,4 +46,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/zh-CN.rc b/dll/win32/msports/lang/zh-CN.rc index 9f17ba41c14..f6daeb36e7a 100644 --- a/dll/win32/msports/lang/zh-CN.rc +++ b/dll/win32/msports/lang/zh-CN.rc @@ -40,4 +40,5 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/lang/zh-TW.rc b/dll/win32/msports/lang/zh-TW.rc index cfaf247a3e5..ac9c6e202af 100644 --- a/dll/win32/msports/lang/zh-TW.rc +++ b/dll/win32/msports/lang/zh-TW.rc @@ -40,5 +40,6 @@ BEGIN IDS_PARITY "Even,Odd,None,Mark,Space" IDS_STOPBITS "1,1.5,2" IDS_FLOWCONTROL "Xon / Xoff,Hardware,None" + IDS_PORT_IN_USE " (in use)" END diff --git a/dll/win32/msports/parallel.c b/dll/win32/msports/parallel.c index ddb72c5a6b3..076bb20d443 100644 --- a/dll/win32/msports/parallel.c +++ b/dll/win32/msports/parallel.c @@ -8,18 +8,83 @@ #include "precomp.h" + typedef struct _PORT_DATA { HDEVINFO DeviceInfoSet; PSP_DEVINFO_DATA DeviceInfoData; WCHAR szPortName[16]; + DWORD dwPortNumber; DWORD dwFilterResourceMethod; DWORD dwLegacy; } PORT_DATA, *PPORT_DATA; +static +VOID +GetUsedPorts( + PDWORD pPortMap) +{ + WCHAR szDeviceName[64]; + WCHAR szDosDeviceName[64]; + DWORD dwIndex, dwType, dwPortNumber; + DWORD dwDeviceNameSize, dwDosDeviceNameSize; + PWSTR ptr; + HKEY hKey; + DWORD dwError; + + *pPortMap = 0; + + dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"Hardware\\DeviceMap\\PARALLEL PORTS", + 0, + KEY_READ, + &hKey); + if (dwError == ERROR_SUCCESS) + { + for (dwIndex = 0; ; dwIndex++) + { + dwDeviceNameSize = ARRAYSIZE(szDeviceName); + dwDosDeviceNameSize = sizeof(szDosDeviceName); + dwError = RegEnumValueW(hKey, + dwIndex, + szDeviceName, + &dwDeviceNameSize, + NULL, + &dwType, + (LPBYTE)szDosDeviceName, + &dwDosDeviceNameSize); + if (dwError != ERROR_SUCCESS) + break; + + if (dwType == REG_SZ) + { + TRACE("%S --> %S\n", szDeviceName, szDosDeviceName); + if (_wcsnicmp(szDosDeviceName, L"\\DosDevices\\LPT", wcslen(L"\\DosDevices\\LPT")) == 0) + { + ptr = szDosDeviceName + wcslen(L"\\DosDevices\\LPT"); + if (wcschr(ptr, L'.') == NULL) + { + TRACE("Device number %S\n", ptr); + dwPortNumber = wcstoul(ptr, NULL, 10); + if (dwPortNumber != 0) + { + *pPortMap |=(1 << dwPortNumber); + } + } + } + } + } + + RegCloseKey(hKey); + } + + TRACE("Done\n"); +} + + static VOID ReadPortSettings( @@ -33,6 +98,7 @@ ReadPortSettings( pPortData->dwFilterResourceMethod = 1; /* Never use an interrupt */ pPortData->dwLegacy = 0; /* Disabled */ + pPortData->dwPortNumber = 0; /* Unknown */ hKey = SetupDiOpenDevRegKey(pPortData->DeviceInfoSet, pPortData->DeviceInfoData, @@ -102,6 +168,7 @@ WritePortSettings( DWORD dwDisposition; DWORD dwFilterResourceMethod; DWORD dwLegacy; + DWORD dwPortNumber; HKEY hKey; DWORD dwError; @@ -169,9 +236,24 @@ WritePortSettings( if (dwError == ERROR_SUCCESS) { FIXME("Notify the driver!\n"); + + pPortData->dwLegacy = dwLegacy; } } } + + dwPortNumber = ComboBox_GetCurSel(GetDlgItem(hwnd, IDC_PARALLEL_NAME)); + if (dwPortNumber != LB_ERR) + { + dwPortNumber++; + if (dwPortNumber != pPortData->dwPortNumber) + { + FIXME("Port name changed! LPT%lu --> LPT%lu", pPortData->dwPortNumber, dwPortNumber); + + +// pPortData->dwPortNumber = dwPortNumber; + } + } } @@ -181,9 +263,11 @@ OnInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam) { + WCHAR szBuffer[256]; + WCHAR szPortInUse[64]; PPORT_DATA pPortData; HWND hwndControl; - WCHAR szBuffer[256]; + DWORD dwPortMap; UINT i; TRACE("OnInitDialog()\n"); @@ -214,18 +298,31 @@ OnInitDialog(HWND hwnd, pPortData->dwLegacy ? BST_CHECKED : BST_UNCHECKED); } + LoadStringW(hInstance, IDS_PORT_IN_USE, szPortInUse, ARRAYSIZE(szPortInUse)); + /* Fill the 'LPT Port Number' combobox */ hwndControl = GetDlgItem(hwnd, IDC_PARALLEL_NAME); if (hwndControl) { - for (i = 0; i < 3; i++) + GetUsedPorts(&dwPortMap); + + for (i = 1; i < 4; i++) { - swprintf(szBuffer, L"LPT%lu", i + 1); + swprintf(szBuffer, L"LPT%lu", i); + + if ((dwPortMap & (1 << i)) && (pPortData->dwPortNumber != i)) + wcscat(szBuffer, szPortInUse); + ComboBox_AddString(hwndControl, szBuffer); + + if (_wcsicmp(pPortData->szPortName, szBuffer) == 0) + pPortData->dwPortNumber = i; } - /* Disable it */ - EnableWindow(hwndControl, FALSE); + if (pPortData->dwPortNumber != 0) + { + ComboBox_SetCurSel(hwndControl, pPortData->dwPortNumber - 1); + } } return TRUE; diff --git a/dll/win32/msports/resource.h b/dll/win32/msports/resource.h index c9d716859d9..335f74a4959 100644 --- a/dll/win32/msports/resource.h +++ b/dll/win32/msports/resource.h @@ -20,3 +20,4 @@ #define IDS_PARITY 11 #define IDS_STOPBITS 12 #define IDS_FLOWCONTROL 13 +#define IDS_PORT_IN_USE 61