From f7686bac4e475082aaf0521fb45bf02fe5687a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20L=C3=A9vesque?= Date: Mon, 12 Aug 2013 12:06:01 -0400 Subject: [PATCH 1/2] Added Java 7 Support --- .../Source/jvm_connection.cpp | 56 +++++++++++++--- cpp/plugin/common/Source/jvm_connection.cpp | 64 ++++++++++++++----- 2 files changed, 95 insertions(+), 25 deletions(-) diff --git a/cpp/editor_launcher/rfdynhud_editor_launcher/Source/jvm_connection.cpp b/cpp/editor_launcher/rfdynhud_editor_launcher/Source/jvm_connection.cpp index 22f4bb7f..8c5831b2 100644 --- a/cpp/editor_launcher/rfdynhud_editor_launcher/Source/jvm_connection.cpp +++ b/cpp/editor_launcher/rfdynhud_editor_launcher/Source/jvm_connection.cpp @@ -8,6 +8,7 @@ static const char* LOG_FOLDER = getLogFolder(); static const char* LOG_FILENAME = getLogFilename(); +int JAVA_VERSION = 0; int findLastSeparator( const char* filename ) { @@ -142,21 +143,28 @@ void logg2( const char* message ) } char* readJavaHomeFromRegistry() -{ +{//int& version char* buffer = (char*)malloc( MAX_PATH ); HKEY keyHandle; DWORD size1; DWORD Type; + if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.7", 0, KEY_QUERY_VALUE, &keyHandle ) == ERROR_SUCCESS ) + { + size1 = MAX_PATH - 1; + RegQueryValueEx( keyHandle, "JavaHome", NULL, &Type, (LPBYTE)buffer, &size1); + RegCloseKey( keyHandle ); + JAVA_VERSION = 7; + return ( buffer ); + } if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.6", 0, KEY_QUERY_VALUE, &keyHandle ) == ERROR_SUCCESS ) { size1 = MAX_PATH - 1; RegQueryValueEx( keyHandle, "JavaHome", NULL, &Type, (LPBYTE)buffer, &size1); RegCloseKey( keyHandle ); - + JAVA_VERSION = 6; return ( buffer ); } - free( buffer ); logg( "WARNING: Registry key for 32 bit Java 6 Runtime Environment not found." ); @@ -167,8 +175,10 @@ char* readJavaHomeFromRegistry() char* guessJavaHome() { char* buffer = (char*)malloc( MAX_PATH ); + char* buffer7 = (char*)malloc( MAX_PATH ); DWORD len = GetEnvironmentVariable( "ProgramFiles", buffer, MAX_PATH ); + DWORD len7 = GetEnvironmentVariable( "ProgramFiles", buffer, MAX_PATH ); char* buff = buffer + len; memcpy( buff, "\\Java\\jre6", 11 ); @@ -177,17 +187,31 @@ char* guessJavaHome() char* result = (char*)malloc( len ); memcpy( result, buffer, len ); free( buffer ); + + char* buff7 = buffer7 + len7; + memcpy( buff7, "\\Java\\jre7", 11 ); + len7 += 11; - if ( checkDirectoryExists( result, false ) != 1 ) + char* result7 = (char*)malloc( len7 ); + memcpy( result7, buffer7, len7 ); + free( buffer7 ); + + if ( checkDirectoryExists( result, false ) != 1 && checkDirectoryExists( result7, false ) != 1) { free( result ); + free( result7 ); - logg( "WARNING: Couldn't find 32 bit Java 6 Runtime Environment in the default folder." ); + logg( "WARNING: Couldn't find 32 bit Java 6 or Java 7 Runtime Environment in the default folder." ); return ( NULL ); } - - return ( result ); + if ( checkDirectoryExists( result7, false ) != 1) + { + JAVA_VERSION = 7; + return ( result7 ); + } + JAVA_VERSION = 6; + return ( result ); } char* getJavaHome() @@ -228,13 +252,25 @@ bool createNewJavaVM( const char* PLUGIN_PATH, JavaVM** jvm, JNIEnv** env ) logg( fileBuffer ); - getFullPath( JAVA_HOME, "bin\\msvcr71.dll", fileBuffer ); - logg( " Loading msvcr71.dll..." ); + if(JAVA_VERSION == 7) + { + getFullPath( JAVA_HOME, "bin\\msvcr100.dll", fileBuffer ); + logg( " Loading msvcr100.dll...", false ); + } + else + { + getFullPath( JAVA_HOME, "bin\\msvcr71.dll", fileBuffer ); + logg( " Loading msvcr71.dll...", false ); + } + HMODULE msvcdll = LoadLibrary( fileBuffer ); if ( msvcdll == NULL ) { - logg( "ERROR: Failed to load msvcr71.dll." ); + if(JAVA_VERSION == 7) + logg( " ERROR: Failed to load msvcr100.dll." ); + else + logg( " ERROR: Failed to load msvcr71.dll." ); return ( false ); } diff --git a/cpp/plugin/common/Source/jvm_connection.cpp b/cpp/plugin/common/Source/jvm_connection.cpp index 509574be..4c4ca363 100644 --- a/cpp/plugin/common/Source/jvm_connection.cpp +++ b/cpp/plugin/common/Source/jvm_connection.cpp @@ -7,22 +7,30 @@ #include "util.h" #include "logging.h" +int JAVA_VERSION = 0; char* readJavaHomeFromRegistry() -{ +{//int& version char* buffer = (char*)malloc( MAX_PATH ); HKEY keyHandle; DWORD size1; DWORD Type; + if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.7", 0, KEY_QUERY_VALUE, &keyHandle ) == ERROR_SUCCESS ) + { + size1 = MAX_PATH - 1; + RegQueryValueEx( keyHandle, "JavaHome", NULL, &Type, (LPBYTE)buffer, &size1); + RegCloseKey( keyHandle ); + JAVA_VERSION = 7; + return ( buffer ); + } if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.6", 0, KEY_QUERY_VALUE, &keyHandle ) == ERROR_SUCCESS ) { size1 = MAX_PATH - 1; RegQueryValueEx( keyHandle, "JavaHome", NULL, &Type, (LPBYTE)buffer, &size1); RegCloseKey( keyHandle ); - + JAVA_VERSION = 6; return ( buffer ); } - free( buffer ); logg( "WARNING: Registry key for 32 bit Java 6 Runtime Environment not found." ); @@ -33,8 +41,10 @@ char* readJavaHomeFromRegistry() char* guessJavaHome() { char* buffer = (char*)malloc( MAX_PATH ); + char* buffer7 = (char*)malloc( MAX_PATH ); DWORD len = GetEnvironmentVariable( "ProgramFiles", buffer, MAX_PATH ); + DWORD len7 = GetEnvironmentVariable( "ProgramFiles", buffer, MAX_PATH ); char* buff = buffer + len; memcpy( buff, "\\Java\\jre6", 11 ); @@ -43,36 +53,50 @@ char* guessJavaHome() char* result = (char*)malloc( len ); memcpy( result, buffer, len ); free( buffer ); + + char* buff7 = buffer7 + len7; + memcpy( buff7, "\\Java\\jre7", 11 ); + len7 += 11; + + char* result7 = (char*)malloc( len7 ); + memcpy( result7, buffer7, len7 ); + free( buffer7 ); - if ( checkDirectoryExists( result, false ) != 1 ) + if ( checkDirectoryExists( result, false ) != 1 && checkDirectoryExists( result7, false ) != 1) { free( result ); + free( result7 ); - logg( "WARNING: Couldn't find 32 bit Java 6 Runtime Environment in the default folder." ); + logg( "WARNING: Couldn't find 32 bit Java 6 or Java 7 Runtime Environment in the default folder." ); return ( NULL ); } - - return ( result ); + if ( checkDirectoryExists( result7, false ) != 1) + { + JAVA_VERSION = 7; + return ( result7 ); + } + JAVA_VERSION = 6; + return ( result ); } char* getJavaHome() { char* result; - result = readJavaHomeFromRegistry(); - if ( result != NULL ) + logg( "JAVA_VERSION :" + JAVA_VERSION ); + if ( result != NULL ) return ( result ); result = guessJavaHome(); if ( result != NULL ) return ( result ); - + // TODO: Read the path from a user defined file. return ( NULL ); } - +//static const int& JAVA_VERSION; static const char* JAVA_HOME = getJavaHome(); jboolean isCopy = false; @@ -109,14 +133,24 @@ bool createNewJavaVM( const char* PLUGIN_PATH, JavaVM** jvm, JNIEnv** env ) memcpy( fileBuffer + 24 + strlen( JAVA_HOME ), "\".", 3 ); logg( fileBuffer ); - - getFullPath( JAVA_HOME, "bin\\msvcr71.dll", fileBuffer ); - logg( " Loading msvcr71.dll...", false ); + if(JAVA_VERSION == 7) + { + getFullPath( JAVA_HOME, "bin\\msvcr100.dll", fileBuffer ); + logg( " Loading msvcr100.dll...", false ); + } + else + { + getFullPath( JAVA_HOME, "bin\\msvcr71.dll", fileBuffer ); + logg( " Loading msvcr71.dll...", false ); + } HMODULE msvcdll = LoadLibrary( fileBuffer ); if ( msvcdll == NULL ) { - logg( " ERROR: Failed to load msvcr71.dll." ); + if(JAVA_VERSION == 7) + logg( " ERROR: Failed to load msvcr100.dll." ); + else + logg( " ERROR: Failed to load msvcr71.dll." ); return ( false ); } else From 9e7c1085443d6a1a42de1fa6e177212591138b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20L=C3=A9vesque?= Date: Mon, 12 Aug 2013 14:02:09 -0400 Subject: [PATCH 2/2] working tested launcher editor --- .../rfdynhud_editor_launcher/Source/jvm_connection.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/editor_launcher/rfdynhud_editor_launcher/Source/jvm_connection.cpp b/cpp/editor_launcher/rfdynhud_editor_launcher/Source/jvm_connection.cpp index 8c5831b2..7167879e 100644 --- a/cpp/editor_launcher/rfdynhud_editor_launcher/Source/jvm_connection.cpp +++ b/cpp/editor_launcher/rfdynhud_editor_launcher/Source/jvm_connection.cpp @@ -1,3 +1,5 @@ +#pragma comment(lib, "advapi32") + #include "jvm_connection.hpp" #include #include @@ -255,12 +257,12 @@ bool createNewJavaVM( const char* PLUGIN_PATH, JavaVM** jvm, JNIEnv** env ) if(JAVA_VERSION == 7) { getFullPath( JAVA_HOME, "bin\\msvcr100.dll", fileBuffer ); - logg( " Loading msvcr100.dll...", false ); + logg( " Loading msvcr100.dll..."); } else { getFullPath( JAVA_HOME, "bin\\msvcr71.dll", fileBuffer ); - logg( " Loading msvcr71.dll...", false ); + logg( " Loading msvcr71.dll..."); } HMODULE msvcdll = LoadLibrary( fileBuffer );