diff --git a/build.xml b/build.xml index 2b6240d8..6abd8d7c 100644 --- a/build.xml +++ b/build.xml @@ -514,7 +514,7 @@ - + diff --git a/src/java/org/lwjgl/Sys.java b/src/java/org/lwjgl/Sys.java index 3744a0b7..2a17404b 100644 --- a/src/java/org/lwjgl/Sys.java +++ b/src/java/org/lwjgl/Sys.java @@ -57,7 +57,7 @@ public final class Sys { private static final String VERSION = "1.0beta2"; /** Current version of the JNI library */ - static final int JNI_VERSION = 2; + static final int JNI_VERSION = 3; /** The implementation instance to delegate platform specific behavior to */ private final static SysImplementation implementation; @@ -114,7 +114,7 @@ public final class Sys { class_name = "org.lwjgl.LinuxSysImplementation"; break; case LWJGLUtil.PLATFORM_WINDOWS: - class_name = "org.lwjgl.Win32SysImplementation"; + class_name = "org.lwjgl.WindowsSysImplementation"; break; case LWJGLUtil.PLATFORM_MACOSX: class_name = "org.lwjgl.MacOSXSysImplementation"; diff --git a/src/java/org/lwjgl/Win32SysImplementation.java b/src/java/org/lwjgl/Win32SysImplementation.java deleted file mode 100644 index ce97b162..00000000 --- a/src/java/org/lwjgl/Win32SysImplementation.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2002-2004 LWJGL Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.lwjgl; - -/** - *

- * Win32 SysImplementation. This is just a straightforward NativsSysImplementation. - *

- * @author $Author$ - * @version $Revision$ - * $Id$ - */ -class Win32SysImplementation extends NativeSysImplementation { -} diff --git a/src/java/org/lwjgl/NativeSysImplementation.java b/src/java/org/lwjgl/WindowsSysImplementation.java similarity index 72% rename from src/java/org/lwjgl/NativeSysImplementation.java rename to src/java/org/lwjgl/WindowsSysImplementation.java index ce118821..a3343c02 100644 --- a/src/java/org/lwjgl/NativeSysImplementation.java +++ b/src/java/org/lwjgl/WindowsSysImplementation.java @@ -31,26 +31,43 @@ */ package org.lwjgl; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; + /** - * A SysImplementation that uses native calls only. *

* @author $Author$ * @version $Revision$ * $Id$ */ -class NativeSysImplementation extends DefaultSysImplementation { - +class WindowsSysImplementation extends DefaultSysImplementation { static { Sys.initialize(); } - public native long getTimerResolution(); + public long getTimerResolution() { + return 1000; + } public native long getTime(); public native void alert(String title, String message); - public native boolean openURL(String url); + public boolean openURL(final String url) { + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + Runtime.getRuntime().exec(new String[]{"rundll32", "url.dll,FileProtocolHandler", url}); + return null; + } + }); + return true; + } catch (PrivilegedActionException e) { + LWJGLUtil.log("Failed to open url (" + url + "): " + e.getCause().getMessage()); + return false; + } + } public native String getClipboard(); } diff --git a/src/java/org/lwjgl/test/DisplayTest.java b/src/java/org/lwjgl/test/DisplayTest.java index 0b39e656..c5eb6c9a 100644 --- a/src/java/org/lwjgl/test/DisplayTest.java +++ b/src/java/org/lwjgl/test/DisplayTest.java @@ -69,6 +69,7 @@ public class DisplayTest { System.out.println("Info about current:"); System.out.println("Graphics card: " + Display.getAdapter() + ", version: " + Display.getVersion()); +System.exit(1); System.out.println("Resolution: " + Display.getDisplayMode().getWidth() + "x" + Display.getDisplayMode().getHeight() + "x" + diff --git a/src/native/windows/org_lwjgl_Sys.c b/src/native/windows/org_lwjgl_Sys.c index 293bd377..4cffd05d 100644 --- a/src/native/windows/org_lwjgl_Sys.c +++ b/src/native/windows/org_lwjgl_Sys.c @@ -41,48 +41,21 @@ #include "Window.h" #include "mmsystem.h" -#include "org_lwjgl_NativeSysImplementation.h" +#include "org_lwjgl_WindowsSysImplementation.h" #include "common_tools.h" #include -/* - * Class: org_lwjgl_Sys - * Method: getTimerResolution - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_NativeSysImplementation_getTimerResolution - (JNIEnv * env, jobject ignored) -{ - return (jlong) 1000L; -} - -/* - * Class: org_lwjgl_Sys - * Method: ngetTime - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_NativeSysImplementation_getTime - (JNIEnv * env, jobject ignored) -{ - - MMRESULT result; +JNIEXPORT jlong JNICALL Java_org_lwjgl_WindowsSysImplementation_getTime(JNIEnv * env, jobject ignored) { DWORD time; - result = timeBeginPeriod(1); + timeBeginPeriod(1); time = timeGetTime(); - result = timeEndPeriod(1); + timeEndPeriod(1); return time; } -/* - * Class: org_lwjgl_Sys - * Method: alert - * Signature: (Ljava/lang/String;Ljava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_NativeSysImplementation_alert - (JNIEnv * env, jobject ignored, jstring title, jstring message) -{ +JNIEXPORT void JNICALL Java_org_lwjgl_WindowsSysImplementation_alert(JNIEnv * env, jobject ignored, jstring title, jstring message) { char * eMessageText = GetStringNativeChars(env, message); char * cTitleBarText = GetStringNativeChars(env, title); MessageBox(getCurrentHWND(), eMessageText, cTitleBarText, MB_OK | MB_TOPMOST); @@ -93,56 +66,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_NativeSysImplementation_alert free(cTitleBarText); } -/* - * Class: org_lwjgl_Sys - * Method: openURL - * Signature: (Ljava/lang/String;)V - */ -JNIEXPORT jboolean JNICALL Java_org_lwjgl_NativeSysImplementation_openURL - (JNIEnv * env, jobject ignored, jstring url) -{ -#define BUFFER_SIZE 1024 - const char *std_args = "rundll32 url.dll,FileProtocolHandler "; - STARTUPINFO si; - PROCESS_INFORMATION pi; - - char * urlString = GetStringNativeChars(env, url); - - char command[BUFFER_SIZE]; - strncpy_s(command, BUFFER_SIZE, "", 1); - strncat_s(command, BUFFER_SIZE, std_args, _TRUNCATE); - strncat_s(command, BUFFER_SIZE, urlString, _TRUNCATE); - free(urlString); - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - // Start the child process. - if( !CreateProcess( NULL, // No module name (use command line). - command, // Command line. - NULL, // Process handle not inheritable. - NULL, // Thread handle not inheritable. - FALSE, // Set handle inheritance to FALSE. - 0, // No creation flags. - NULL, // Use parent's environment block. - NULL, // Use parent's starting directory. - &si, // Pointer to STARTUPINFO structure. - &pi ) // Pointer to PROCESS_INFORMATION structure. - ) - { - printfDebugJava(env, "Failed to open URL %s", urlString); - return JNI_FALSE; - } - - // Close process and thread handles. - CloseHandle( pi.hProcess ); - CloseHandle( pi.hThread ); - - return JNI_TRUE; -} - -JNIEXPORT jstring JNICALL Java_org_lwjgl_NativeSysImplementation_getClipboard +JNIEXPORT jstring JNICALL Java_org_lwjgl_WindowsSysImplementation_getClipboard (JNIEnv * env, jobject ignored) { // Check to see if there's text available in the clipboard