-
Notifications
You must be signed in to change notification settings - Fork 860
feat: [Windows] 支持自动使用高性能显卡 #5420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a815183
2156f8e
4cc086c
e252892
89218a5
6656050
590149f
24b3891
7029921
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,10 @@ public List<String> querySubKeys(HKEY root, String key) { | |
| return list; | ||
| } | ||
|
|
||
| public abstract boolean setValue(HKEY root, String key, String valueName, String value); | ||
|
|
||
| public abstract boolean deleteValue(HKEY root, String key, String valueName); | ||
|
Comment on lines
+91
to
+93
|
||
|
|
||
| private static final class JNAWinReg extends WinReg { | ||
|
|
||
| private final Advapi32 advapi32; | ||
|
|
@@ -245,6 +249,63 @@ public List<String> querySubKeyNames(HKEY root, String key) { | |
|
|
||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean setValue(HKEY root, String key, String valueName, String value) { | ||
| PointerByReference phkKey = new PointerByReference(); | ||
| int status = advapi32.RegCreateKeyExW( | ||
| root.toPointer(), | ||
| new WString(key), | ||
| 0, | ||
| null, | ||
| WinConstants.REG_OPTION_NON_VOLATILE, | ||
| WinConstants.KEY_WRITE, | ||
| null, | ||
| phkKey, | ||
| null | ||
| ); | ||
|
|
||
| if (status != WinConstants.ERROR_SUCCESS) { | ||
| return false; | ||
| } | ||
|
|
||
| Pointer hkey = phkKey.getValue(); | ||
| try { | ||
| byte[] data = (value + "\0").getBytes(StandardCharsets.UTF_16LE); | ||
| try (Memory mem = new Memory(data.length)) { | ||
| mem.write(0, data, 0, data.length); | ||
| status = advapi32.RegSetValueExW( | ||
| hkey, | ||
| new WString(valueName), | ||
| 0, | ||
| WinConstants.REG_SZ, | ||
| mem, | ||
| data.length | ||
| ); | ||
| } | ||
| return status == WinConstants.ERROR_SUCCESS; | ||
| } finally { | ||
| advapi32.RegCloseKey(hkey); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean deleteValue(HKEY root, String key, String valueName) { | ||
| PointerByReference phkKey = new PointerByReference(); | ||
| int status = advapi32.RegOpenKeyExW(root.toPointer(), new WString(key), 0, WinConstants.KEY_SET_VALUE, phkKey); | ||
|
|
||
| if (status != WinConstants.ERROR_SUCCESS) { | ||
| return false; | ||
| } | ||
|
|
||
| Pointer hkey = phkKey.getValue(); | ||
| try { | ||
| status = advapi32.RegDeleteValueW(hkey, new WString(valueName)); | ||
| return status == WinConstants.ERROR_SUCCESS; | ||
| } finally { | ||
| advapi32.RegCloseKey(hkey); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.