2004-03-03 00:56:51 +01:00
|
|
|
// Windows-specific system detect
|
|
|
|
//
|
|
|
|
// Copyright (c) 2004 Jan Wassenberg
|
|
|
|
//
|
|
|
|
// This file is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This file is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// Contact info:
|
|
|
|
// Jan.Wassenberg@stud.uni-karlsruhe.de
|
|
|
|
// http://www.stud.uni-karlsruhe.de/~urkt/
|
|
|
|
|
2004-05-08 03:11:51 +02:00
|
|
|
#include "precompiled.h"
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
#include "detect.h"
|
2004-05-06 19:14:30 +02:00
|
|
|
#include "lib.h"
|
2004-11-22 08:41:02 +01:00
|
|
|
#include "lib/res/file.h" // file_enum
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
#include "win_internal.h"
|
|
|
|
|
2005-06-28 06:06:25 +02:00
|
|
|
|
2004-06-04 14:41:53 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2004-11-22 08:41:02 +01:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
// DirectSound header
|
|
|
|
// HACK: workaround for "subwtype.h not found" errors on VC6/7 hybrid.
|
|
|
|
// (subwtype.h <- d3dtypes.h <- dsound.h)
|
|
|
|
// since we're only using one DS function (DirectSoundEnumerate),
|
|
|
|
// we forward-declare it rather than fix/mess with the system headers.
|
|
|
|
#if 0
|
|
|
|
// mmsystem.h is necessary for dsound.h; we cut out unnecessary junk
|
|
|
|
# define MMNODRV // Installable driver support
|
|
|
|
# define MMNOSOUND // Sound support
|
|
|
|
//# define MMNOWAVE // Waveform support
|
|
|
|
# define MMNOMIDI // MIDI support
|
|
|
|
# define MMNOAUX // Auxiliary audio support
|
|
|
|
# define MMNOMIXER // Mixer support
|
|
|
|
# define MMNOTIMER // Timer support
|
|
|
|
# define MMNOJOY // Joystick support
|
|
|
|
# define MMNOMCI // MCI support
|
|
|
|
# define MMNOMMIO // Multimedia file I/O support
|
|
|
|
# define MMNOMMSYSTEM // General MMSYSTEM functions
|
|
|
|
# include <MMSystem.h>
|
|
|
|
# define DIRECTSOUND_VERSION 0x0500
|
|
|
|
# include <dsound.h>
|
|
|
|
#else
|
|
|
|
# define DS_OK 0
|
|
|
|
typedef BOOL (CALLBACK* LPDSENUMCALLBACKA)(void*, const char*, const char*, void*);
|
|
|
|
extern "C" __declspec(dllimport) HRESULT WINAPI DirectSoundEnumerateA(LPDSENUMCALLBACKA, void*);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// these are all delay-loaded - they're not needed if
|
|
|
|
// system information is never queried.
|
2004-03-03 00:56:51 +01:00
|
|
|
#ifdef _MSC_VER
|
2004-11-19 23:43:02 +01:00
|
|
|
#pragma comment(lib, "version.lib") // DLL version
|
|
|
|
#pragma comment(lib, "advapi32.lib") // registry
|
|
|
|
#pragma comment(lib, "dsound.lib") // sound card name
|
2004-03-03 00:56:51 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-05-08 03:11:51 +02:00
|
|
|
// EnumDisplayDevices is not available on Win95 or NT.
|
|
|
|
// try to import it manually here; return -1 if not available.
|
2004-05-06 19:14:30 +02:00
|
|
|
static BOOL (WINAPI *pEnumDisplayDevicesA)(void*, DWORD, void*, DWORD);
|
|
|
|
static int import_EnumDisplayDevices()
|
|
|
|
{
|
|
|
|
if(!pEnumDisplayDevicesA)
|
|
|
|
{
|
|
|
|
static HMODULE hUser32Dll = LoadLibrary("user32.dll");
|
|
|
|
*(void**)&pEnumDisplayDevicesA = GetProcAddress(hUser32Dll, "EnumDisplayDevicesA");
|
2005-06-16 23:55:02 +02:00
|
|
|
// FreeLibrary(hUser32Dll);
|
|
|
|
// make sure the reference is released so BoundsChecker
|
|
|
|
// doesn't complain. it won't actually be unloaded anyway -
|
|
|
|
// there is at least one other reference.
|
2004-05-06 19:14:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return pEnumDisplayDevicesA? 0 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-19 23:43:02 +01:00
|
|
|
// useful for choosing a video mode.
|
2004-05-06 19:14:30 +02:00
|
|
|
// if we fail, outputs are unchanged (assumed initialized to defaults)
|
2004-06-01 19:34:12 +02:00
|
|
|
int get_cur_vmode(int* xres, int* yres, int* bpp, int* freq)
|
2004-03-03 00:56:51 +01:00
|
|
|
{
|
2004-06-20 00:51:54 +02:00
|
|
|
// don't use EnumDisplaySettingsW - BoundsChecker reports it causes
|
|
|
|
// a memory overrun (even if called as the very first thing, before
|
|
|
|
// static CRT initialization).
|
|
|
|
|
|
|
|
DEVMODEA dm;
|
2004-03-03 16:16:20 +01:00
|
|
|
memset(&dm, 0, sizeof(dm));
|
2004-03-03 00:56:51 +01:00
|
|
|
dm.dmSize = sizeof(dm);
|
2004-03-03 16:16:20 +01:00
|
|
|
// dm.dmDriverExtra already set to 0 by memset
|
|
|
|
|
2004-06-20 00:51:54 +02:00
|
|
|
if(!EnumDisplaySettingsA(0, ENUM_CURRENT_SETTINGS, &dm))
|
2004-05-06 19:14:30 +02:00
|
|
|
return -1;
|
|
|
|
|
2005-01-23 18:48:32 +01:00
|
|
|
if(dm.dmFields & (DWORD)DM_PELSWIDTH && xres)
|
2004-06-01 19:34:12 +02:00
|
|
|
*xres = (int)dm.dmPelsWidth;
|
2005-01-23 18:48:32 +01:00
|
|
|
if(dm.dmFields & (DWORD)DM_PELSHEIGHT && yres)
|
2004-06-01 19:34:12 +02:00
|
|
|
*yres = (int)dm.dmPelsHeight;
|
2005-01-23 18:48:32 +01:00
|
|
|
if(dm.dmFields & (DWORD)DM_BITSPERPEL && bpp)
|
2004-06-01 19:34:12 +02:00
|
|
|
*bpp = (int)dm.dmBitsPerPel;
|
2005-01-23 18:48:32 +01:00
|
|
|
if(dm.dmFields & (DWORD)DM_DISPLAYFREQUENCY && freq)
|
2004-06-01 19:34:12 +02:00
|
|
|
*freq = (int)dm.dmDisplayFrequency;
|
|
|
|
|
2004-05-06 19:14:30 +02:00
|
|
|
return 0;
|
2004-03-03 00:56:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-19 23:43:02 +01:00
|
|
|
// useful for determining aspect ratio.
|
2004-05-06 19:14:30 +02:00
|
|
|
// if we fail, outputs are unchanged (assumed initialized to defaults)
|
2004-05-08 03:11:51 +02:00
|
|
|
int get_monitor_size(int& width_mm, int& height_mm)
|
2004-03-03 00:56:51 +01:00
|
|
|
{
|
2004-05-08 03:11:51 +02:00
|
|
|
HDC dc = GetDC(0); // dc for entire screen
|
2004-05-06 19:14:30 +02:00
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
width_mm = GetDeviceCaps(dc, HORZSIZE);
|
2004-05-08 03:11:51 +02:00
|
|
|
height_mm = GetDeviceCaps(dc, VERTSIZE);
|
2004-05-06 19:14:30 +02:00
|
|
|
|
2004-05-08 03:11:51 +02:00
|
|
|
ReleaseDC(0, dc);
|
|
|
|
return 0;
|
2004-05-06 19:14:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// support routines for getting DLL version
|
|
|
|
//----------------------------------------------------------------------------
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
static int get_ver(const char* module_path, char* out_ver, size_t out_ver_len)
|
2004-05-24 22:25:48 +02:00
|
|
|
{
|
2005-06-16 23:55:02 +02:00
|
|
|
WIN_SAVE_LAST_ERROR; // GetFileVersion*, Ver*
|
2004-05-24 22:25:48 +02:00
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
// determine size of and allocate memory for version information.
|
|
|
|
DWORD unused;
|
|
|
|
const DWORD ver_size = GetFileVersionInfoSize(module_path, &unused);
|
|
|
|
if(!ver_size)
|
2004-05-24 22:25:48 +02:00
|
|
|
return -1;
|
2005-06-16 23:55:02 +02:00
|
|
|
void* buf = malloc(ver_size);
|
|
|
|
if(!buf)
|
|
|
|
return ERR_NO_MEM;
|
2004-05-24 22:25:48 +02:00
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
int ret = -1; // single point of exit (for free())
|
|
|
|
|
|
|
|
if(GetFileVersionInfo(module_path, 0, ver_size, buf))
|
2004-05-24 22:25:48 +02:00
|
|
|
{
|
2005-06-16 23:55:02 +02:00
|
|
|
u16* lang; // -> 16 bit language ID, 16 bit codepage
|
|
|
|
uint lang_len;
|
|
|
|
const BOOL ok = VerQueryValue(buf, "\\VarFileInfo\\Translation", (void**)&lang, &lang_len);
|
|
|
|
if(ok && lang && lang_len == 4)
|
2004-05-24 22:25:48 +02:00
|
|
|
{
|
2005-06-16 23:55:02 +02:00
|
|
|
char subblock[64];
|
|
|
|
sprintf(subblock, "\\StringFileInfo\\%04X%04X\\FileVersion", lang[0], lang[1]);
|
|
|
|
const char* in_ver;
|
|
|
|
uint in_ver_len;
|
|
|
|
if(VerQueryValue(buf, subblock, (void**)&in_ver, &in_ver_len))
|
2004-05-26 01:16:21 +02:00
|
|
|
{
|
2005-06-16 23:55:02 +02:00
|
|
|
strcpy_s(out_ver, out_ver_len, in_ver);
|
2004-05-24 22:25:48 +02:00
|
|
|
ret = 0; // success
|
2004-05-26 01:16:21 +02:00
|
|
|
}
|
2004-05-24 22:25:48 +02:00
|
|
|
}
|
|
|
|
}
|
2005-06-16 23:55:02 +02:00
|
|
|
free(buf);
|
2004-05-24 22:25:48 +02:00
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
WIN_RESTORE_LAST_ERROR;
|
2004-05-24 22:25:48 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
//
|
|
|
|
// build a string containing DLL filename(s) and their version info.
|
|
|
|
//
|
|
|
|
|
|
|
|
static char* dll_list_buf;
|
|
|
|
static size_t dll_list_chars;
|
|
|
|
static char* dll_list_pos;
|
|
|
|
|
|
|
|
static void dll_list_init(char* buf, size_t chars)
|
|
|
|
{
|
|
|
|
dll_list_pos = dll_list_buf = buf;
|
|
|
|
dll_list_chars = chars;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// read DLL file version and append that and its name to the list.
|
|
|
|
// return 0 on success or a negative error code.
|
|
|
|
//
|
2005-06-21 18:31:55 +02:00
|
|
|
// name should preferably be the complete path to DLL, to make sure
|
2005-06-16 23:55:02 +02:00
|
|
|
// we don't inadvertently load another one on the library search path.
|
2005-06-21 18:31:55 +02:00
|
|
|
// we add the .dll extension if necessary.
|
|
|
|
static int dll_list_add(const char* name)
|
2005-06-16 23:55:02 +02:00
|
|
|
{
|
|
|
|
// make sure we're allowed to be called.
|
|
|
|
if(!dll_list_pos)
|
|
|
|
{
|
|
|
|
debug_warn("dll_list_add: called before dll_list_init or after failure");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-06-21 18:31:55 +02:00
|
|
|
// some driver names are stored in the registry without .dll extension.
|
|
|
|
// if necessary, copy to new buffer and add it there.
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
const char* dll_name = name;
|
2005-07-01 04:11:45 +02:00
|
|
|
const char* ext = strrchr(name, '.');
|
2005-06-21 18:31:55 +02:00
|
|
|
if(!ext || stricmp(ext, ".dll") != 0)
|
|
|
|
{
|
|
|
|
snprintf(buf, ARRAY_SIZE(buf), "%s.dll", name);
|
|
|
|
dll_name = buf;
|
|
|
|
}
|
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
// read file version.
|
2005-06-21 18:31:55 +02:00
|
|
|
char dll_ver[128] = "unknown"; // enclosed in () below
|
|
|
|
(void)get_ver(dll_name, dll_ver, sizeof(dll_ver));
|
2005-06-16 23:55:02 +02:00
|
|
|
// if this fails, default is already set and we don't want to abort.
|
|
|
|
|
|
|
|
const ssize_t max_chars_to_write = (ssize_t)dll_list_chars - (dll_list_pos-dll_list_buf) - 10;
|
|
|
|
// reserves enough room for subsequent comma and "..." strings.
|
|
|
|
|
|
|
|
// not first time: prepend comma to string (room was reserved above).
|
|
|
|
if(dll_list_pos != dll_list_buf)
|
|
|
|
dll_list_pos += sprintf(dll_list_pos, ", ");
|
|
|
|
|
|
|
|
// extract filename.
|
2005-06-21 18:31:55 +02:00
|
|
|
const char* slash = strrchr(dll_name, '\\');
|
|
|
|
const char* dll_fn = slash? slash+1 : dll_name;
|
2005-06-16 23:55:02 +02:00
|
|
|
|
|
|
|
int len = snprintf(dll_list_pos, max_chars_to_write, "%s (%s)", dll_fn, dll_ver);
|
|
|
|
// success
|
|
|
|
if(len > 0)
|
|
|
|
{
|
|
|
|
dll_list_pos += len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// didn't fit; complain
|
|
|
|
sprintf(dll_list_pos, "..."); // (room was reserved above)
|
|
|
|
debug_warn("dll_list_add: not enough room");
|
|
|
|
dll_list_pos = 0; // poison pill, prevent further calls
|
|
|
|
return ERR_BUF_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// graphics card / driver version
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2004-11-22 08:41:02 +01:00
|
|
|
static int win_get_gfx_card()
|
2004-03-03 00:56:51 +01:00
|
|
|
{
|
2004-11-22 08:41:02 +01:00
|
|
|
if(gfx_card[0] != '\0')
|
2004-03-03 00:56:51 +01:00
|
|
|
return -1;
|
2004-11-19 23:43:02 +01:00
|
|
|
|
2004-11-22 08:41:02 +01:00
|
|
|
// make sure EnumDisplayDevices is available (as pEnumDisplayDevicesA)
|
|
|
|
if(import_EnumDisplayDevices() >= 0)
|
2004-03-03 00:56:51 +01:00
|
|
|
{
|
2004-11-22 08:41:02 +01:00
|
|
|
DISPLAY_DEVICEA dev = { sizeof(dev) };
|
|
|
|
if(pEnumDisplayDevicesA(0, 0, &dev, 0))
|
2004-03-03 00:56:51 +01:00
|
|
|
{
|
2005-03-01 21:13:00 +01:00
|
|
|
strcpy_s(gfx_card, sizeof(gfx_card), (const char*)dev.DeviceString);
|
2004-11-22 08:41:02 +01:00
|
|
|
return 0;
|
2004-03-03 00:56:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-22 08:41:02 +01:00
|
|
|
return -1;
|
2004-03-03 00:56:51 +01:00
|
|
|
}
|
|
|
|
|
2004-11-19 23:43:02 +01:00
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
// note: this implementation doesn't require OpenGL to be initialized.
|
2004-11-22 08:41:02 +01:00
|
|
|
static int win_get_gfx_drv_ver()
|
2004-11-19 23:43:02 +01:00
|
|
|
{
|
|
|
|
if(gfx_drv_ver[0] != '\0')
|
|
|
|
return -1;
|
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
// rationale:
|
|
|
|
// - we could easily determine the 2d driver via EnumDisplaySettings,
|
|
|
|
// but we want to query the actual OpenGL driver. see
|
|
|
|
// http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/009679.html ;
|
|
|
|
// in short, we need the exact OpenGL driver version because some
|
|
|
|
// driver packs (e.g. Omega) mix and match DLLs.
|
|
|
|
// - an alternative implementation would be to enumerate all
|
|
|
|
// DLLs loaded into the process, and check for a glBegin export.
|
|
|
|
// that requires toolhelp/PSAPI (a bit complicated) and telling
|
|
|
|
// ICD/opengl32.dll apart (not future-proof).
|
|
|
|
// - therefore, we stick with the OpenGLDrivers approach. since there is
|
|
|
|
// no good way to determine which of the subkeys (e.g. nvoglnt) is
|
|
|
|
// active (several may exist due to previously removed drivers),
|
|
|
|
// we just display all of them. it is obvious from looking at
|
|
|
|
// gfx_card which one is correct; we thus avoid driver-specific
|
|
|
|
// name checks and reporting incorrectly.
|
|
|
|
|
|
|
|
int ret = -1; // single point of exit (for RegCloseKey)
|
2005-06-21 18:31:55 +02:00
|
|
|
DWORD i;
|
|
|
|
char drv_name[MAX_PATH+1];
|
|
|
|
|
|
|
|
dll_list_init(gfx_drv_ver, GFX_DRV_VER_LEN);
|
2005-06-16 23:55:02 +02:00
|
|
|
|
|
|
|
HKEY hkOglDrivers;
|
|
|
|
const char* key = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\OpenGLDrivers";
|
2005-06-21 18:31:55 +02:00
|
|
|
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hkOglDrivers) != 0)
|
2005-06-16 23:55:02 +02:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
// for each subkey (i.e. set of installed OpenGL drivers):
|
2005-06-21 18:31:55 +02:00
|
|
|
for(i = 0; ; i++)
|
2005-06-16 23:55:02 +02:00
|
|
|
{
|
|
|
|
char set_name[32];
|
|
|
|
DWORD set_name_len = ARRAY_SIZE(set_name);
|
2005-06-21 18:31:55 +02:00
|
|
|
LONG err = RegEnumKeyEx(hkOglDrivers, i, set_name, &set_name_len, 0, 0,0, 0);
|
|
|
|
if(err != ERROR_SUCCESS) // error or no more items - bail
|
2005-06-16 23:55:02 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
HKEY hkSet;
|
|
|
|
if(RegOpenKeyEx(hkOglDrivers, set_name, 0, KEY_QUERY_VALUE, &hkSet) == 0)
|
|
|
|
{
|
2005-06-21 18:31:55 +02:00
|
|
|
DWORD drv_name_len = ARRAY_SIZE(drv_name)-5; // for ".dll"
|
|
|
|
if(RegQueryValueEx(hkSet, "Dll", 0, 0, (LPBYTE)drv_name, &drv_name_len) == 0)
|
|
|
|
ret = dll_list_add(drv_name);
|
2005-06-16 23:55:02 +02:00
|
|
|
|
|
|
|
RegCloseKey(hkSet);
|
|
|
|
}
|
|
|
|
} // for each subkey
|
|
|
|
|
2005-06-21 18:31:55 +02:00
|
|
|
// for each value:
|
|
|
|
// (some old drivers, e.g. S3 Super Savage, store their ICD name in a
|
|
|
|
// single REG_SZ value. we therefore include those as well.)
|
|
|
|
for(i = 0; ; i++)
|
|
|
|
{
|
|
|
|
char value_name[100]; // we don't need this, but RegEnumValue fails otherwise.
|
|
|
|
DWORD value_name_len = ARRAY_SIZE(value_name);
|
|
|
|
DWORD type;
|
|
|
|
DWORD drv_name_len = ARRAY_SIZE(drv_name)-5; // for ".dll"
|
|
|
|
DWORD err = RegEnumValue(hkOglDrivers, i, value_name,&value_name_len,
|
|
|
|
0, &type, (LPBYTE)drv_name,&drv_name_len);
|
|
|
|
if(err != ERROR_SUCCESS) // error or no more items - bail
|
|
|
|
break;
|
|
|
|
if(type == REG_SZ)
|
|
|
|
ret = dll_list_add(drv_name);
|
|
|
|
} // for each value
|
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
RegCloseKey(hkOglDrivers);
|
|
|
|
return ret;
|
2004-11-19 23:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-26 01:16:21 +02:00
|
|
|
int win_get_gfx_info()
|
|
|
|
{
|
2005-06-16 23:55:02 +02:00
|
|
|
int err1 = win_get_gfx_card();
|
|
|
|
int err2 = win_get_gfx_drv_ver();
|
|
|
|
|
|
|
|
// don't exit before trying both
|
|
|
|
CHECK_ERR(err1);
|
|
|
|
CHECK_ERR(err2);
|
2004-05-26 01:16:21 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-11-19 23:43:02 +01:00
|
|
|
|
2004-11-22 08:41:02 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// sound card / driver version
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2004-11-19 23:43:02 +01:00
|
|
|
|
|
|
|
// note: OpenAL alGetString is worthless: it only returns OpenAL API version
|
|
|
|
// and renderer (e.g. "Software").
|
|
|
|
|
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
// file_enum only passes add_if_oal_dll the filename, so we need to append
|
|
|
|
// that to the directory. this is done is a buffer allocated by
|
|
|
|
// add_oal_dlls_in_dir for efficiency.
|
2004-11-19 23:43:02 +01:00
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
typedef std::set<std::string> DllSet;
|
2004-11-19 23:43:02 +01:00
|
|
|
|
2004-11-22 08:41:02 +01:00
|
|
|
struct PathInfo
|
|
|
|
{
|
2005-03-01 21:13:00 +01:00
|
|
|
const char* path; // PATH_MAX
|
2004-11-22 08:41:02 +01:00
|
|
|
char* end;
|
|
|
|
size_t remaining;
|
2005-06-16 23:55:02 +02:00
|
|
|
DllSet* dlls;
|
2004-11-22 08:41:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// if this file is an OpenAL DLL, add it to our list.
|
2005-06-16 23:55:02 +02:00
|
|
|
// (matches "*oal.dll" and "*OpenAL*", as with OpenAL router's search)
|
|
|
|
// called via file_enum.
|
|
|
|
static int add_if_oal_dll(const char* fn, const struct stat* s, uintptr_t user)
|
2004-11-22 08:41:02 +01:00
|
|
|
{
|
2005-06-16 23:55:02 +02:00
|
|
|
// skip non-files.
|
|
|
|
if(!S_ISREG(s->st_mode))
|
|
|
|
goto skip;
|
2005-01-23 18:48:32 +01:00
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
{
|
2004-11-22 08:41:02 +01:00
|
|
|
PathInfo* pi = (PathInfo*)user;
|
2005-03-01 21:13:00 +01:00
|
|
|
strncpy(pi->end, fn, pi->remaining); // safe
|
2004-11-22 08:41:02 +01:00
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
// make sure this DLL hasn't been added yet.
|
|
|
|
if(pi->dlls->find(fn) != pi->dlls->end())
|
|
|
|
goto skip;
|
|
|
|
pi->dlls->insert(fn);
|
|
|
|
|
2004-11-22 08:41:02 +01:00
|
|
|
const size_t len = strlen(fn);
|
|
|
|
const bool oal = len >= 7 && !stricmp(fn+len-7, "oal.dll");
|
|
|
|
const bool openal = strstr(fn, "OpenAL") != 0;
|
|
|
|
if(oal || openal)
|
2005-06-16 23:55:02 +02:00
|
|
|
dll_list_add(pi->path);
|
|
|
|
}
|
|
|
|
|
|
|
|
skip:
|
2004-11-22 08:41:02 +01:00
|
|
|
return 0; // continue calling
|
2004-11-19 23:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
// find all OpenAL DLLs in a dir (via file_enum and add_if_oal_dll).
|
|
|
|
// call in library search order (exe dir, then win sys dir); otherwise,
|
|
|
|
// DLLs in the executable's starting directory hide those of the
|
|
|
|
// same name in the system directory.
|
2004-11-22 08:41:02 +01:00
|
|
|
//
|
|
|
|
// dir: no trailing '\\'.
|
2005-06-16 23:55:02 +02:00
|
|
|
static void add_oal_dlls_in_dir(const char* dir, DllSet* dlls)
|
2004-11-19 23:43:02 +01:00
|
|
|
{
|
2004-11-22 08:41:02 +01:00
|
|
|
char path[MAX_PATH+1]; path[MAX_PATH] = '\0';
|
|
|
|
const int len = snprintf(path, MAX_PATH, "%s\\", dir);
|
|
|
|
if(len < 0)
|
|
|
|
{
|
2005-06-28 06:06:25 +02:00
|
|
|
debug_assert(0);
|
2004-11-22 08:41:02 +01:00
|
|
|
return;
|
|
|
|
}
|
2005-06-16 23:55:02 +02:00
|
|
|
PathInfo pi = { path, path+len, MAX_PATH-len, dlls };
|
|
|
|
file_enum(path, add_if_oal_dll, (uintptr_t)&pi);
|
2004-11-22 08:41:02 +01:00
|
|
|
}
|
2004-11-19 23:43:02 +01:00
|
|
|
|
|
|
|
|
2005-06-21 18:31:55 +02:00
|
|
|
// DS3D driver name; filled by ds_enum, used by win_get_snd_info.
|
2005-06-16 23:55:02 +02:00
|
|
|
// side effect: remains zeroed if there's no sound card installed.
|
2005-06-21 18:31:55 +02:00
|
|
|
static char ds_drv_name[MAX_PATH+1];
|
2004-11-22 08:41:02 +01:00
|
|
|
|
|
|
|
// store sound card name and path to DirectSound driver.
|
|
|
|
// called for each DirectSound driver, but aborts after first valid driver.
|
|
|
|
static BOOL CALLBACK ds_enum(void* guid, const char* description, const char* module, void* ctx)
|
|
|
|
{
|
2005-01-23 18:48:32 +01:00
|
|
|
UNUSED(guid);
|
|
|
|
UNUSED(ctx);
|
|
|
|
|
2004-11-22 08:41:02 +01:00
|
|
|
// skip first (dummy) entry, where description == "Primary Sound Driver".
|
|
|
|
if(module[0] == '\0')
|
|
|
|
return TRUE; // continue calling
|
|
|
|
|
2005-06-21 18:31:55 +02:00
|
|
|
strcpy_s(snd_card, SND_CARD_LEN, description);
|
|
|
|
strcpy_s(ds_drv_name, ARRAY_SIZE(ds_drv_name), module);
|
2004-11-22 08:41:02 +01:00
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
// we assume the first "driver name" (sound card) is the one we want;
|
|
|
|
// stick with that and stop calling.
|
|
|
|
return FALSE;
|
2004-11-19 23:43:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int win_get_snd_info()
|
|
|
|
{
|
2005-06-16 23:55:02 +02:00
|
|
|
// get sound card name and DS driver path.
|
2004-11-22 04:03:25 +01:00
|
|
|
if(DirectSoundEnumerateA((LPDSENUMCALLBACKA)ds_enum, (void*)0) != DS_OK)
|
2004-11-21 09:41:40 +01:00
|
|
|
debug_warn("DirectSoundEnumerate failed");
|
2004-11-19 23:43:02 +01:00
|
|
|
|
2005-06-16 23:55:02 +02:00
|
|
|
// there are apparently no sound card/drivers installed; so indicate.
|
|
|
|
// (the code below would fail and not produce reasonable output)
|
2005-06-21 18:31:55 +02:00
|
|
|
if(ds_drv_name[0] == '\0')
|
2005-06-16 23:55:02 +02:00
|
|
|
{
|
|
|
|
strcpy_s(snd_card, SND_CARD_LEN, "(none)");
|
|
|
|
strcpy_s(snd_drv_ver, SND_DRV_VER_LEN, "(none)");
|
2005-01-02 01:05:33 +01:00
|
|
|
return 0;
|
2005-06-16 23:55:02 +02:00
|
|
|
}
|
2005-01-02 01:05:33 +01:00
|
|
|
|
2004-11-22 08:41:02 +01:00
|
|
|
// find all DLLs related to OpenAL, retrieve their versions,
|
|
|
|
// and store in snd_drv_ver string.
|
2005-06-16 23:55:02 +02:00
|
|
|
dll_list_init(snd_drv_ver, SND_DRV_VER_LEN);
|
2005-06-21 18:31:55 +02:00
|
|
|
dll_list_add(ds_drv_name);
|
2005-06-16 23:55:02 +02:00
|
|
|
std::set<std::string> dlls; // ensures uniqueness
|
|
|
|
add_oal_dlls_in_dir(win_exe_dir, &dlls);
|
|
|
|
add_oal_dlls_in_dir(win_sys_dir, &dlls);
|
2004-11-19 23:43:02 +01:00
|
|
|
return 0;
|
|
|
|
}
|