diff options
author | Chris Robinson <[email protected]> | 2015-06-30 07:44:56 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2015-06-30 07:44:56 -0700 |
commit | d90dfc8d1f4f9ae374230cab837400a64503c2c1 (patch) | |
tree | f270b2f1f36a9d8e82ae6ec80c2f4f4d9f80cc7b /Alc/backends/mmdevapi.c | |
parent | c24f4f230fda217641cc9484c03b0a2053185228 (diff) |
Check for duplicate device names in the mmdevapi backend
Diffstat (limited to 'Alc/backends/mmdevapi.c')
-rw-r--r-- | Alc/backends/mmdevapi.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index 3a4bde5c..e688052d 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -176,14 +176,40 @@ static void get_device_formfactor(IMMDevice *device, EndpointFormFactor *formfac static void add_device(IMMDevice *device, LPCWSTR devid, vector_DevMap *list) { + int count = 0; + al_string tmpname; DevMap entry; + AL_STRING_INIT(tmpname); AL_STRING_INIT(entry.name); + entry.devid = strdupW(devid); - get_device_name(device, &entry.name); + get_device_name(device, &tmpname); + + while(1) + { + const DevMap *iter; + + al_string_copy(&entry.name, tmpname); + if(count != 0) + { + char str[64]; + snprintf(str, sizeof(str), " #%d", count+1); + al_string_append_cstr(&entry.name, str); + } + +#define MATCH_ENTRY(i) (al_string_cmp(entry.name, (i)->name) == 0) + VECTOR_FIND_IF(iter, const DevMap, *list, MATCH_ENTRY); + if(iter == VECTOR_ITER_END(*list)) + break; +#undef MATCH_ENTRY + count++; + } TRACE("Got device \"%s\", \"%ls\"\n", al_string_get_cstr(entry.name), entry.devid); VECTOR_PUSH_BACK(*list, entry); + + AL_STRING_DEINIT(tmpname); } static LPWSTR get_device_id(IMMDevice *device) |