winepulse: Move get_application_name into mmdevapi.

This commit is contained in:
Davide Beatrici 2023-06-16 08:32:20 +02:00 committed by Alexandre Julliard
parent 62cd90e8ac
commit bfb3bbba54
6 changed files with 114 additions and 114 deletions

View file

@ -1,5 +1,5 @@
MODULE = mmdevapi.dll
IMPORTS = uuid ole32 oleaut32 user32 advapi32
IMPORTS = uuid ole32 oleaut32 user32 advapi32 version
C_SRCS = \
audiosessionmanager.c \

View file

@ -21,6 +21,8 @@
#define COBJMACROS
#include <wchar.h>
#include <audiopolicy.h>
#include <mmdeviceapi.h>
#include <winternl.h>
@ -33,6 +35,12 @@
WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
typedef struct tagLANGANDCODEPAGE
{
WORD wLanguage;
WORD wCodePage;
} LANGANDCODEPAGE;
extern void sessions_lock(void) DECLSPEC_HIDDEN;
extern void sessions_unlock(void) DECLSPEC_HIDDEN;
@ -169,6 +177,105 @@ static DWORD CALLBACK timer_loop_func(void *user)
return 0;
}
static BOOL query_productname(void *data, LANGANDCODEPAGE *lang, LPVOID *buffer, UINT *len)
{
WCHAR pn[37];
swprintf(pn, ARRAY_SIZE(pn), L"\\StringFileInfo\\%04x%04x\\ProductName", lang->wLanguage, lang->wCodePage);
return VerQueryValueW(data, pn, buffer, len) && *len;
}
WCHAR *get_application_name(void)
{
WCHAR path[MAX_PATH], *name;
UINT translate_size, productname_size;
LANGANDCODEPAGE *translate;
LPVOID productname;
BOOL found = FALSE;
void *data = NULL;
unsigned int i;
LCID locale;
DWORD size;
GetModuleFileNameW(NULL, path, ARRAY_SIZE(path));
size = GetFileVersionInfoSizeW(path, NULL);
if (!size)
goto skip;
data = malloc(size);
if (!data)
goto skip;
if (!GetFileVersionInfoW(path, 0, size, data))
goto skip;
if (!VerQueryValueW(data, L"\\VarFileInfo\\Translation", (LPVOID *)&translate, &translate_size))
goto skip;
/* No translations found. */
if (translate_size < sizeof(LANGANDCODEPAGE))
goto skip;
/* The following code will try to find the best translation. We first search for an
* exact match of the language, then a match of the language PRIMARYLANGID, then we
* search for a LANG_NEUTRAL match, and if that still doesn't work we pick the
* first entry which contains a proper productname. */
locale = GetThreadLocale();
for (i = 0; i < translate_size / sizeof(LANGANDCODEPAGE); i++) {
if (translate[i].wLanguage == locale &&
query_productname(data, &translate[i], &productname, &productname_size)) {
found = TRUE;
break;
}
}
if (!found) {
for (i = 0; i < translate_size / sizeof(LANGANDCODEPAGE); i++) {
if (PRIMARYLANGID(translate[i].wLanguage) == PRIMARYLANGID(locale) &&
query_productname(data, &translate[i], &productname, &productname_size)) {
found = TRUE;
break;
}
}
}
if (!found) {
for (i = 0; i < translate_size / sizeof(LANGANDCODEPAGE); i++) {
if (PRIMARYLANGID(translate[i].wLanguage) == LANG_NEUTRAL &&
query_productname(data, &translate[i], &productname, &productname_size)) {
found = TRUE;
break;
}
}
}
if (!found) {
for (i = 0; i < translate_size / sizeof(LANGANDCODEPAGE); i++) {
if (query_productname(data, &translate[i], &productname, &productname_size)) {
found = TRUE;
break;
}
}
}
skip:
if (found) {
name = wcsdup(productname);
free(data);
return name;
}
free(data);
name = wcsrchr(path, '\\');
if (!name)
name = path;
else
name++;
return wcsdup(name);
}
static HRESULT WINAPI capture_QueryInterface(IAudioCaptureClient *iface, REFIID riid, void **ppv)
{
struct audio_client *This = impl_from_IAudioCaptureClient(iface);

View file

@ -1,6 +1,6 @@
MODULE = winealsa.drv
UNIXLIB = winealsa.so
IMPORTS = uuid ole32 advapi32
IMPORTS = uuid ole32 advapi32 version
PARENTSRC = ../mmdevapi
DELAYIMPORTS = winmm
UNIX_LIBS = $(ALSA_LIBS) $(PTHREAD_LIBS)

View file

@ -1,6 +1,6 @@
MODULE = winecoreaudio.drv
UNIXLIB = winecoreaudio.so
IMPORTS = uuid ole32 user32 advapi32
IMPORTS = uuid ole32 user32 advapi32 version
PARENTSRC = ../mmdevapi
DELAYIMPORTS = winmm
UNIX_LIBS = $(COREAUDIO_LIBS)

View file

@ -1,6 +1,6 @@
MODULE = wineoss.drv
UNIXLIB = wineoss.so
IMPORTS = uuid ole32 user32 advapi32
IMPORTS = uuid ole32 user32 advapi32 version
PARENTSRC = ../mmdevapi
DELAYIMPORTS = winmm
UNIX_LIBS = $(OSS4_LIBS) $(PTHREAD_LIBS)

View file

@ -133,6 +133,8 @@ extern HRESULT main_loop_start(void) DECLSPEC_HIDDEN;
extern struct audio_session_wrapper *session_wrapper_create(
struct audio_client *client) DECLSPEC_HIDDEN;
extern WCHAR *get_application_name(void);
static inline ACImpl *impl_from_IAudioClient3(IAudioClient3 *iface)
{
return CONTAINING_RECORD(iface, ACImpl, IAudioClient3_iface);
@ -153,115 +155,6 @@ static void pulse_release_stream(stream_handle stream, HANDLE timer)
pulse_call(release_stream, &params);
}
typedef struct tagLANGANDCODEPAGE
{
WORD wLanguage;
WORD wCodePage;
} LANGANDCODEPAGE;
static BOOL query_productname(void *data, LANGANDCODEPAGE *lang, LPVOID *buffer, UINT *len)
{
WCHAR pn[37];
swprintf(pn, ARRAY_SIZE(pn), L"\\StringFileInfo\\%04x%04x\\ProductName", lang->wLanguage, lang->wCodePage);
return VerQueryValueW(data, pn, buffer, len) && *len;
}
static WCHAR *get_application_name(BOOL query_app_name)
{
WCHAR path[MAX_PATH], *name;
GetModuleFileNameW(NULL, path, ARRAY_SIZE(path));
if (query_app_name)
{
UINT translate_size, productname_size;
LANGANDCODEPAGE *translate;
LPVOID productname;
BOOL found = FALSE;
void *data = NULL;
unsigned int i;
LCID locale;
DWORD size;
size = GetFileVersionInfoSizeW(path, NULL);
if (!size)
goto skip;
data = malloc(size);
if (!data)
goto skip;
if (!GetFileVersionInfoW(path, 0, size, data))
goto skip;
if (!VerQueryValueW(data, L"\\VarFileInfo\\Translation", (LPVOID *)&translate, &translate_size))
goto skip;
/* no translations found */
if (translate_size < sizeof(LANGANDCODEPAGE))
goto skip;
/* The following code will try to find the best translation. We first search for an
* exact match of the language, then a match of the language PRIMARYLANGID, then we
* search for a LANG_NEUTRAL match, and if that still doesn't work we pick the
* first entry which contains a proper productname. */
locale = GetThreadLocale();
for (i = 0; i < translate_size / sizeof(LANGANDCODEPAGE); i++) {
if (translate[i].wLanguage == locale &&
query_productname(data, &translate[i], &productname, &productname_size)) {
found = TRUE;
break;
}
}
if (!found) {
for (i = 0; i < translate_size / sizeof(LANGANDCODEPAGE); i++) {
if (PRIMARYLANGID(translate[i].wLanguage) == PRIMARYLANGID(locale) &&
query_productname(data, &translate[i], &productname, &productname_size)) {
found = TRUE;
break;
}
}
}
if (!found) {
for (i = 0; i < translate_size / sizeof(LANGANDCODEPAGE); i++) {
if (PRIMARYLANGID(translate[i].wLanguage) == LANG_NEUTRAL &&
query_productname(data, &translate[i], &productname, &productname_size)) {
found = TRUE;
break;
}
}
}
if (!found) {
for (i = 0; i < translate_size / sizeof(LANGANDCODEPAGE); i++) {
if (query_productname(data, &translate[i], &productname, &productname_size)) {
found = TRUE;
break;
}
}
}
skip:
if (found)
{
name = wcsdup(productname);
free(data);
return name;
}
free(data);
}
name = wcsrchr(path, '\\');
if (!name)
name = path;
else
name++;
return wcsdup(name);
}
static void set_stream_volumes(ACImpl *This)
{
struct set_volumes_params params;
@ -726,7 +619,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
return hr;
}
params.name = name = get_application_name(TRUE);
params.name = name = get_application_name();
params.device = This->device_name;
params.flow = This->dataflow;
params.share = mode;