1
2
3
4
5 package oshi.hardware.platform.windows;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import com.sun.jna.platform.win32.Advapi32Util;
11 import com.sun.jna.platform.win32.Win32Exception;
12 import com.sun.jna.platform.win32.WinError;
13 import com.sun.jna.platform.win32.WinReg;
14
15 import oshi.annotation.concurrent.Immutable;
16 import oshi.hardware.SoundCard;
17 import oshi.hardware.common.AbstractSoundCard;
18
19
20
21
22 @Immutable
23 final class WindowsSoundCard extends AbstractSoundCard {
24
25 private static final String REGISTRY_SOUNDCARDS = "SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e96c-e325-11ce-bfc1-08002be10318}\\";
26
27
28
29
30
31
32
33
34 WindowsSoundCard(String kernelVersion, String name, String codec) {
35 super(kernelVersion, name, codec);
36 }
37
38
39
40
41
42
43
44
45
46
47 public static List<SoundCard> getSoundCards() {
48 List<SoundCard> soundCards = new ArrayList<>();
49 String[] keys = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, REGISTRY_SOUNDCARDS);
50 for (String key : keys) {
51 String fullKey = REGISTRY_SOUNDCARDS + key;
52 try {
53 if (Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, fullKey, "Driver")) {
54 soundCards.add(new WindowsSoundCard(
55 Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, fullKey, "Driver") + " "
56 + Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, fullKey,
57 "DriverVersion"),
58 Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, fullKey, "ProviderName")
59 + " "
60 + Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, fullKey,
61 "DriverDesc"),
62 Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, fullKey, "DriverDesc")));
63 }
64 } catch (Win32Exception e) {
65 if (e.getErrorCode() != WinError.ERROR_ACCESS_DENIED) {
66
67 throw e;
68 }
69 }
70 }
71 return soundCards;
72 }
73 }