Java Code Examples for com.sun.jna.Platform#isWindows()
The following examples show how to use
com.sun.jna.Platform#isWindows() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JvmDiscoverer.java From apm-agent-java with Apache License 2.0 | 6 votes |
public static ForHotSpotVm withDefaultTempDir() { String temporaryDirectory; if (Platform.isMac()) { temporaryDirectory = System.getenv("TMPDIR"); if (temporaryDirectory == null) { temporaryDirectory = "/tmp"; } } else if (Platform.isWindows()) { temporaryDirectory = System.getenv("TEMP"); if (temporaryDirectory == null) { temporaryDirectory = "c:/Temp"; } } else { temporaryDirectory = "/tmp"; } return new ForHotSpotVm(temporaryDirectory); }
Example 2
Source File: ContextMenuTools.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
public static boolean isAddedToContextMenu() { if (!Platform.isWindows()) { return false; } final WinReg.HKEY REG_CLASSES_HKEY = WinReg.HKEY_LOCAL_MACHINE; final String REG_CLASSES_PATH = "Software\\Classes\\"; try { if (!Advapi32Util.registryKeyExists(REG_CLASSES_HKEY, REG_CLASSES_PATH + ".swf")) { return false; } String clsName = Advapi32Util.registryGetStringValue(REG_CLASSES_HKEY, REG_CLASSES_PATH + ".swf", ""); if (clsName == null) { return false; } return Advapi32Util.registryKeyExists(REG_CLASSES_HKEY, REG_CLASSES_PATH + clsName + "\\shell\\ffdec"); } catch (Win32Exception ex) { return false; } }
Example 3
Source File: LibraryFinder.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
private static String findCoreLibrary() { String path=""; if (Platform.isWindows()) { try { path = getCPath(true); path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "InstallDir"); } catch (Exception ignored) { try { path = getCPath(false); path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "InstallDir"); } catch (Exception ignored1) { return ""; } } path = path + "CoreFoundation.dll"; File f = new File(path); if (f.exists()) return path; } else if (Platform.isMac()) { return "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"; } return ""; }
Example 4
Source File: PtyUtil.java From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static String getPlatformFolder() { String result; if (Platform.isMac()) { result = "macosx"; } else if (Platform.isWindows()) { result = "win"; } else if (Platform.isLinux()) { result = "linux"; } else if (Platform.isFreeBSD()) { result = "freebsd"; } else if (Platform.isOpenBSD()) { result = "openbsd"; } else { throw new IllegalStateException("Platform " + Platform.getOSType() + " is not supported"); } return result; }
Example 5
Source File: CommandLineArgumentParser.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
private static void parseAffinity(Stack<String> args) { if (Platform.isWindows()) { if (args.isEmpty()) { System.err.println("affinity parameter expected"); badArguments("affinity"); } try { int affinityMask = Integer.parseInt(args.pop()); Kernel32.INSTANCE.SetProcessAffinityMask(Kernel32.INSTANCE.GetCurrentProcess(), affinityMask); } catch (NumberFormatException nex) { System.err.println("Bad affinityMask value"); } } else { System.err.println("Process affinity setting is only available on Windows platform."); } }
Example 6
Source File: NativeCallsJNAImpl.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private static final NativeCalls getImplInstance() { if (Platform.isLinux()) { return new LinuxNativeCalls(); } if (Platform.isWindows()) { return new WinNativeCalls(); } if (Platform.isSolaris()) { return new SolarisNativeCalls(); } if (Platform.isMac()) { return new MacOSXNativeCalls(); } if (Platform.isFreeBSD()) { return new FreeBSDNativeCalls(); } return new POSIXNativeCalls(); }
Example 7
Source File: SystemHelper.java From azure-devops-intellij with MIT License | 5 votes |
/** * Takes in a path and converts it to Unix standard if Windows OS is detected * * @param path * @return path with forward slashes */ public static String getUnixPath(final String path) { if (Platform.isWindows()) { return path.replace("\\", "/"); } else { return path; } }
Example 8
Source File: UnixDomainSocket.java From mariadb-connector-j with GNU Lesser General Public License v2.1 | 5 votes |
public UnixDomainSocket(String path) throws IOException { if (Platform.isWindows() || Platform.isWindowsCE()) { throw new IOException("Unix domain sockets are not supported on Windows"); } sockaddr = new SockAddr(path); closeLock.set(false); try { fd = socket(AF_UNIX, SOCK_STREAM, PROTOCOL); } catch (LastErrorException lee) { throw new IOException("native socket() failed : " + formatError(lee)); } }
Example 9
Source File: UnixDomainSocket.java From docker-java with Apache License 2.0 | 5 votes |
UnixDomainSocket(String path) throws IOException { if (Platform.isWindows() || Platform.isWindowsCE()) { throw new IOException("Unix domain sockets are not supported on Windows"); } sockaddr = new SockAddr(path); closeLock.set(false); try { fd = socket(AF_UNIX, SOCK_STREAM, PROTOCOL); } catch (LastErrorException lee) { throw new IOException("native socket() failed : " + formatError(lee)); } }
Example 10
Source File: HostnameFetching.java From buck with Apache License 2.0 | 5 votes |
public static String getHostname() throws IOException { if (Platform.isWindows()) { return getHostnameWin32(); } else { return getHostnamePosix(); } }
Example 11
Source File: MapleEngineImpl.java From Gaalop with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void loadModule(InputStream input) throws MapleEngineException { try { File tempFile = File.createTempFile("gaalop", ".m"); try { FileOutputStream output = new FileOutputStream(tempFile); byte[] buffer = new byte[1024]; int read; while ((read = input.read(buffer)) != -1) { output.write(buffer, 0, read); } output.close(); if (Platform.isWindows()) { evaluate("read " + "\"" + tempFile.getAbsolutePath().replace("\\", "\\\\") + "\";"); } else { evaluate("read \"" + tempFile.getAbsolutePath() + "\";"); } } finally { tempFile.delete(); } } catch (IOException e) { throw new MapleEngineException("Unable to load module in Maple.", e); } }
Example 12
Source File: PtyUtil.java From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static String getNativeLibraryName() { String result; if (Platform.isMac()) { result = "libpty.dylib"; } else if (Platform.isWindows()) { result = "winpty.dll"; } else if (Platform.isLinux() || Platform.isFreeBSD() || Platform.isOpenBSD()) { result = "libpty.so"; } else { throw new IllegalStateException("Platform " + Platform.getOSType() + " is not supported"); } return result; }
Example 13
Source File: LibraryFinder.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
private static boolean systemLoad(String path) { if (path.isEmpty()) { return false; } File file = new File(path); if (!file.exists()) { return false; } if (Platform.isWindows()) { path = path.replace("\\\\", "\\"); path = path.replace("\\", "\\\\"); path = path.replace("/", "\\\\"); } else if (Platform.isMac()){ path = path.replace("\\\\", "\\"); path = path.replace("\\", "/"); } try { System.out.println("+++path+++ "+path); System.load(path); ANBActivator .getDefault() .getLog() .log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, "System.load() path = "+path, null)); return true; } catch (SecurityException se) { ANBActivator .getDefault() .getLog() .log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, "System.load() path = "+path + " failed due to SecurityException", null)); return false; } catch (UnsatisfiedLinkError le) { ANBActivator .getDefault() .getLog() .log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, "System.load() path = "+path + " failed due to UnsatisfiedLinkError", null)); return false; } catch (NullPointerException ne) { ANBActivator .getDefault() .getLog() .log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, "System.load() path = "+path + " failed due to NullPointerException", null)); return false; } catch (Throwable e) { ANBActivator .getDefault() .getLog() .log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, "System.load() path = "+path + " failed", null)); return false; } }
Example 14
Source File: TfTool.java From azure-devops-intellij with MIT License | 4 votes |
/** * Try to find the tf command by checking common places based on the OS * * @return */ public static String tryDetectTf() { final String[] exeNames = Platform.isWindows() ? TF_WINDOWS_PROGRAMS : TF_OTHER_PROGRAMS; final File[] filePaths = Platform.isWindows() ? PROGRAM_FILE_PATHS : UNIX_PATHS; return tryDetectTf(exeNames, filePaths); }
Example 15
Source File: ProcessTools.java From jpexs-decompiler with GNU General Public License v3.0 | 4 votes |
public static List<Process> listProcesses() { if (Platform.isWindows()) { return Win32ProcessTools.listProcesses(); } return null; }
Example 16
Source File: DefaultJarContentHasherTest.java From buck with Apache License 2.0 | 4 votes |
@Test public void testGetContentHashesDoesNotIncorrectlyCache() throws Exception { if (Platform.isWindows()) { // Windows doesn't allow clobbering a file while it's already open, so this test isn't // meaningful for windows platforms return; } ProjectFilesystem filesystem = TestProjectFilesystems.createProjectFilesystem(temporaryFolder.getRoot().toPath()); File toTest = temporaryFolder.newFile(); File modification = temporaryFolder.newFile(); new JarBuilder() .setShouldHashEntries(true) .addEntry( new JarEntrySupplier( new CustomZipEntry("Before"), "container_test", () -> new ByteArrayInputStream("Before".getBytes(StandardCharsets.UTF_8)))) .createJarFile(toTest.toPath()); new JarBuilder() .setShouldHashEntries(true) .addEntry( new JarEntrySupplier( new CustomZipEntry("After"), "container_test", () -> new ByteArrayInputStream("After".getBytes(StandardCharsets.UTF_8)))) .createJarFile(modification.toPath()); FileTime hardcodedTime = FileTime.fromMillis(ZipConstants.getFakeTime()); Files.setLastModifiedTime(toTest.toPath(), hardcodedTime); Files.setLastModifiedTime(modification.toPath(), hardcodedTime); Path relativeToTestPath = temporaryFolder.getRoot().toPath().relativize(toTest.toPath()); // Use JarBuilder with toTest -- we cache the open file to make sure it stays mmapped //noinspection unused JarFile cache = new JarFile(toTest); assertThat( new DefaultJarContentHasher(filesystem, relativeToTestPath).getContentHashes().keySet(), Matchers.contains(Paths.get("Before"))); // Now modify toTest make sure we don't get a cached result when we open it for a second time Files.move(modification.toPath(), toTest.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.setLastModifiedTime(toTest.toPath(), hardcodedTime); assertThat( new DefaultJarContentHasher(filesystem, relativeToTestPath).getContentHashes().keySet(), Matchers.contains(Paths.get("After"))); cache.close(); }
Example 17
Source File: HostnameUtilsWinTest.java From netbeans with Apache License 2.0 | 4 votes |
@Override public boolean canRun() { return super.canRun() && Platform.isWindows(); }
Example 18
Source File: Main.java From jpexs-decompiler with GNU General Public License v3.0 | 4 votes |
public static void initLang() { if (!Configuration.locale.hasValue()) { if (Platform.isWindows()) { //Load from Installer String uninstKey = "{E618D276-6596-41F4-8A98-447D442A77DB}_is1"; uninstKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + uninstKey; try { if (Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, uninstKey)) { if (Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, uninstKey, "NSIS: Language")) { String installedLoc = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, uninstKey, "NSIS: Language"); int lcid = Integer.parseInt(installedLoc); char[] buf = new char[9]; int cnt = Kernel32.INSTANCE.GetLocaleInfo(lcid, Kernel32.LOCALE_SISO639LANGNAME, buf, 9); String langCode = new String(buf, 0, cnt).trim().toLowerCase(); cnt = Kernel32.INSTANCE.GetLocaleInfo(lcid, Kernel32.LOCALE_SISO3166CTRYNAME, buf, 9); String countryCode = new String(buf, 0, cnt).trim().toLowerCase(); List<String> langs = Arrays.asList(SelectLanguageDialog.getAvailableLanguages()); for (int i = 0; i < langs.size(); i++) { langs.set(i, langs.get(i).toLowerCase()); } String selectedLang = null; if (langs.contains(langCode + "-" + countryCode)) { selectedLang = SelectLanguageDialog.getAvailableLanguages()[langs.indexOf(langCode + "-" + countryCode)]; } else if (langs.contains(langCode)) { selectedLang = SelectLanguageDialog.getAvailableLanguages()[langs.indexOf(langCode)]; } if (selectedLang != null) { Configuration.locale.set(selectedLang); } } } } catch (Exception ex) { //ignore } } } Locale.setDefault(Locale.forLanguageTag(Configuration.locale.get())); AppStrings.updateLanguage(); Helper.decompilationErrorAdd = AppStrings.translate(Configuration.autoDeobfuscate.get() ? "deobfuscation.comment.failed" : "deobfuscation.comment.tryenable"); }
Example 19
Source File: ProcessTools.java From jpexs-decompiler with GNU General Public License v3.0 | 4 votes |
public static boolean toolsAvailable() { return Platform.isWindows(); }
Example 20
Source File: LoadLibs.java From lept4j with Apache License 2.0 | 2 votes |
/** * Gets native library name. * * @return the name of the Leptonica library to be loaded using the * <code>Native.register()</code>. */ public static String getLeptonicaLibName() { return Platform.isWindows() ? LIB_NAME : LIB_NAME_NON_WIN; }