https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c444231b874c6c351ef59…
commit c444231b874c6c351ef59a5afbe4563b63b707af
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Thu Oct 4 10:20:12 2018 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Thu Oct 4 10:21:06 2018 +0200
[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 de8fa745bd..cdc3c25a16 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 b968518dbe..f1ccb23a44 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 baf2725041..eb37b840b6 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 dd6587b6bf..d6c7c700c2 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 e6fef329c3..61933ac385 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 eeaad20568..666a6b8886 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 25e5dfca79..cedc65f557 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 d7af8e7626..6cd025fedf 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 caa284ef72..825eeb50ff 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 d6ac1e7f60..f90eb9c157 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 73cc86ada1..6ee7f1f58f 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 39bad63929..c7132feff2 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 0f161170f5..503cb492e8 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 9f17ba41c1..f6daeb36e7 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 cfaf247a3e..ac9c6e202a 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 ddb72c5a6b..076bb20d44 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 c9d716859d..335f74a495 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