Skip to content

Commit

Permalink
Add feature for whitelisting controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Kendall committed Jan 25, 2020
1 parent 2eed0bd commit f8385c5
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 4 deletions.
71 changes: 70 additions & 1 deletion dinput8/dinput8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,37 @@ vector<string> & hiddenControllersA()
return result;
}

vector<wstring> & visibleControllersW()
{
static vector<wstring> result;
static bool needToInitialize = true;

if (needToInitialize) {
result = loadAllKeysFromSectionOfIni(L"visible");
needToInitialize = false;
}

return result;
}

vector<string> & visibleControllersA()
{
static vector<string> result;
static bool needToInitialize = true;

if (needToInitialize) {
vector<wstring> &wideList = visibleControllersW();

for (unsigned int i = 0; i < wideList.size(); ++i) {
result.push_back(UTF16ToUTF8(wideList[i]));
}

needToInitialize = false;
}

return result;
}

vector<wstring> & ignoredProcessesW()
{
static vector<wstring> result;
Expand Down Expand Up @@ -287,14 +318,33 @@ BOOL CALLBACK enumCallbackA(LPCDIDEVICEINSTANCEA deviceInstance, LPVOID userData
DeviceEnumData<DIDEVICEINSTANCEA> *enumData = (DeviceEnumData<DIDEVICEINSTANCEA> *)userData;
vector<string> &order = sortedControllersA();
vector<string> &hidden = hiddenControllersA();
vector<string> &visible = visibleControllersA();

for (unsigned int i = 0; i < hidden.size(); ++i) {
if (deviceMatchesEntry(deviceInstance, hidden[i])) {
PrintLog("devreorder: product \"%s\" is hidden", deviceInstance->tszProductName);
return DIENUM_CONTINUE;
}
}


DWORD deviceType = GET_DIDEVICE_TYPE(deviceInstance->dwDevType);

if (visible.size() > 0 && deviceType != DI8DEVTYPE_KEYBOARD && deviceType != DI8DEVTYPE_MOUSE
&& deviceType != DI8DEVTYPE_SCREENPOINTER) {
bool isVisible = false;

for (unsigned int i = 0; i < visible.size(); ++i) {
if (deviceMatchesEntry(deviceInstance, visible[i])) {
isVisible = true;
}
}

if (!isVisible) {
PrintLog("devreorder: product \"%s\" is not in visible section", deviceInstance->tszProductName);
return DIENUM_CONTINUE;
}
}

int nameMatchIndex = -1;

for (unsigned int i = 0; i < order.size(); ++i) {
Expand Down Expand Up @@ -327,13 +377,32 @@ BOOL CALLBACK enumCallbackW(LPCDIDEVICEINSTANCEW deviceInstance, LPVOID userData
DeviceEnumData<DIDEVICEINSTANCEW> *enumData = (DeviceEnumData<DIDEVICEINSTANCEW> *)userData;
vector<wstring> &order = sortedControllersW();
vector<wstring> &hidden = hiddenControllersW();
vector<wstring> &visible = visibleControllersW();

for (unsigned int i = 0; i < hidden.size(); ++i) {
if (deviceMatchesEntry(deviceInstance, hidden[i])) {
PrintLog(L"devreorder: product \"%s\" is hidden", deviceInstance->tszProductName);
return DIENUM_CONTINUE;
}
}

DWORD deviceType = GET_DIDEVICE_TYPE(deviceInstance->dwDevType);

if (visible.size() > 0 && deviceType != DI8DEVTYPE_KEYBOARD && deviceType != DI8DEVTYPE_MOUSE
&& deviceType != DI8DEVTYPE_SCREENPOINTER) {
bool isVisible = false;

for (unsigned int i = 0; i < visible.size(); ++i) {
if (deviceMatchesEntry(deviceInstance, visible[i])) {
isVisible = true;
}
}

if (!isVisible) {
PrintLog(L"devreorder: product \"%s\" is not in visible section", deviceInstance->tszProductName);
return DIENUM_CONTINUE;
}
}

int nameMatchIndex = -1;

Expand Down
19 changes: 16 additions & 3 deletions release/devreorder.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,24 @@
; Wireless Controller
; {01234567-89ab-cdef-0123-456789abcdef}

[visible]
; In this section, write the names or GUIDs of the
; controllers that you want to be the only ones that are
; visible. If this section is left blank, then it will have
; no effect and only the controllers in the [hidden] section
; will be invisible. Otherwise, any controller not listed in
; this section will be invisible. (This does not affect
; keyboards, mice, and other pointing devices.)
; Example:
; Controller (XBOX 360 For Windows)
; {01234567-89ab-cdef-0123-456789abcdef}

[ignored processes]
; In this section, write the names of processes you want
; devreorder to ignore so that the order of their
; controllers is not modified. Matches are not case
; sensitive. Be sure to include the file extension as well.
; devreorder to ignore so that the order and visibility of
; their controllers is not changed, as though devreorder is
; not installed. Matches are not case sensitive. Be sure to
; include the file extension as well.
; Example:
; steam.exe

0 comments on commit f8385c5

Please sign in to comment.