下面列出了怎么用com.sun.jna.platform.win32.Shell32的API类实例代码及写法,或者点击链接到github查看源代码。
private static File getSettingsFile() {
if (WINDOWS) {
char[] path = new char[]{};
if (Shell32.INSTANCE.SHGetSpecialFolderPath(null, path, ShlObj.CSIDL_LOCAL_APPDATA, false)) {
configDir = String.valueOf(path) + File.separator + "gta-sa_savegame_editor";
} else {
log.warn("Unable to determine appdata folder! Falling back to old config dir!");
return new File(System.getProperty("user.home"), ".gta_sa_savegame_editor");
}
} else {
String xdgConfigHome = System.getenv("XDG_CONFIG_HOME");
if (xdgConfigHome == null || xdgConfigHome.isBlank() || xdgConfigHome.isEmpty()) {
configDir = System.getProperty("user.home") + File.separator + ".config" + File.separator + "gta-sa_savegame_editor";
} else {
configDir = xdgConfigHome + File.separator + "gta-sa_savegame_editor";
}
}
return new File(configDir, "config");
}
public static BufferedImage extractExeIcon(String fullExeFile, int index, boolean large) {
PointerByReference iconsLargeRef = new PointerByReference();
PointerByReference iconsSmallRef = new PointerByReference();
int cnt = Shell32.INSTANCE.ExtractIconEx(fullExeFile, index, iconsLargeRef, iconsSmallRef, new WinDef.UINT(1)).intValue();
if (cnt == 0) {
return null;
}
Pointer iconsLarge = iconsLargeRef.getPointer();
Pointer iconsSmall = iconsSmallRef.getPointer();
WinDef.HICON icon;
if (large) {
icon = new WinDef.HICON(iconsLarge.getPointer(0));
} else {
icon = new WinDef.HICON(iconsSmall.getPointer(0));
}
BufferedImage ic = iconToImage(icon);
User32.INSTANCE.DestroyIcon(icon);
return ic;
}
@Override
protected void configure() {
bind(User32.class).toInstance(User32.INSTANCE);
expose(User32.class);
bind(Kernel32.class).toInstance(Kernel32.INSTANCE);
expose(Kernel32.class);
bind(Advapi32.class).toInstance(Advapi32.INSTANCE);
expose(Advapi32.class);
bind(Shell32.class).toInstance(Shell32.INSTANCE);
expose(Shell32.class);
}
@Inject
public SystemService(final Kernel32 kernel32, final Advapi32 advapi32,
final Shell32 shell32) throws SystemException {
this.kernel32 = Objects.requireNonNull(kernel32);
this.advapi32 = Objects.requireNonNull(advapi32);
this.shell32 = Objects.requireNonNull(shell32);
escalatePrivileges(REQUIRED_PRIVILEGES);
}
@Nonnull
private static List<String> getUnityUserPaths()
{
List<String> paths = new SmartList<>();
if(SystemInfo.isWinVistaOrNewer)
{
paths.add(Shell32Util.getFolderPath(ShlObj.CSIDL_LOCAL_APPDATA) + "\\Unity");
PointerByReference pointerByReference = new PointerByReference();
// LocalLow
WinNT.HRESULT hresult = Shell32.INSTANCE.SHGetKnownFolderPath(Guid.GUID.fromString("{A520A1A4-1780-4FF6-BD18-167343C5AF16}"), 0, null, pointerByReference);
if(hresult.longValue() == 0)
{
paths.add(pointerByReference.getValue().getWideString(0) + "\\Unity");
}
}
else if(SystemInfo.isMac)
{
paths.add(SystemProperties.getUserHome() + "/Library/Unity");
}
else if(SystemInfo.isLinux)
{
paths.add(SystemProperties.getUserHome() + "/.config/unity3d");
}
return paths;
}
public static BufferedImage getShellIcon(String path) {
SHFILEINFO fi = new SHFILEINFO();
BaseTSD.DWORD_PTR r = Shell32.INSTANCE.SHGetFileInfo(path, 0, fi, fi.size(), Shell32.SHGFI_ICON | Shell32.SHGFI_SMALLICON);
if (r.intValue() == 0) {
return null;
}
return iconToImage(fi.hIcon);
}