• R/O
  • SSH
  • HTTPS

exewrap: Commit


Commit MetaInfo

Revision30 (tree)
Time2016-01-03 10:31:45
Authorhirukawa_ryo

Log Message

1.1.2 *プロセスの環境変数を設定するユーティリティークラス exewrap.util.Environment を追加しました。

Change Summary

Incremental Difference

--- exewrap/trunk/exewrap/license.txt (revision 29)
+++ exewrap/trunk/exewrap/license.txt (revision 30)
@@ -1,4 +1,4 @@
1-Copyright (C) 2005-2014 HIRUKAWA Ryo. All rights reserved.
1+Copyright (C) 2005-2016 HIRUKAWA Ryo. All rights reserved.
22
33 ソースコード形式であれバイナリ形式であれ、変更の有無に関わらず、
44 以下の条件を満たす限りにおいて、再配布および使用を許可します:
--- exewrap/trunk/exewrap/src/Makefile (revision 29)
+++ exewrap/trunk/exewrap/src/Makefile (revision 30)
@@ -269,7 +269,7 @@
269269
270270 ### exewrap.util
271271
272-$(OBJ)\util.jar : $(OBJ) $(OBJ)\exewrap\util\EventLogHandler.class $(OBJ)\exewrap\util\EventLogStream.class $(OBJ)\exewrap\util\FileLogStream.class $(OBJ)\exewrap\util\UncaughtExceptionHandler.class $(OBJ)\exewrap\util\ConsoleOutputStream.class
272+$(OBJ)\util.jar : $(OBJ) $(OBJ)\exewrap\util\EventLogHandler.class $(OBJ)\exewrap\util\EventLogStream.class $(OBJ)\exewrap\util\FileLogStream.class $(OBJ)\exewrap\util\UncaughtExceptionHandler.class $(OBJ)\exewrap\util\ConsoleOutputStream.class $(OBJ)\exewrap\util\Environment.class
273273 $(JAR) cvf $(OBJ)\util.jar -C $(OBJ) exewrap\util
274274
275275 $(OBJ)\exewrap\util\EventLogHandler.class : $(OBJ) java\exewrap\util\EventLogHandler.java
@@ -287,6 +287,9 @@
287287 $(OBJ)\exewrap\util\ConsoleOutputStream.class : $(OBJ) java\exewrap\util\ConsoleOutputStream.java
288288 $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\exewrap\util\ConsoleOutputStream.java
289289
290+$(OBJ)\exewrap\util\Environment.class : $(OBJ) java\exewrap\util\Environment.java
291+ $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\exewrap\util\Environment.java
292+
290293 ### exewrap.tool
291294
292295 $(OBJ)\tool.jar : $(OBJ) $(OBJ)\exewrap\tool\JarProcessor.class $(OBJ)\exewrap\tool\PackOutputStream.class
--- exewrap/trunk/exewrap/src/java/exewrap/core/ExewrapClassLoader.java (revision 29)
+++ exewrap/trunk/exewrap/src/java/exewrap/core/ExewrapClassLoader.java (revision 30)
@@ -189,4 +189,5 @@
189189 public static native void WriteConsole(byte[] b, int off, int len);
190190 public static native void WriteEventLog(int type, String message);
191191 public static native void UncaughtException(String thread, String message, String trace);
192+ public static native String SetEnvironment(String key, String value);
192193 }
--- exewrap/trunk/exewrap/src/java/exewrap/util/Environment.java (revision 0)
+++ exewrap/trunk/exewrap/src/java/exewrap/util/Environment.java (revision 30)
@@ -0,0 +1,76 @@
1+package exewrap.util;
2+
3+import java.util.Collection;
4+import java.util.Map;
5+import java.util.Set;
6+
7+import exewrap.core.ExewrapClassLoader;
8+
9+public class Environment implements Map<String, String> {
10+
11+ @Override
12+ public void clear() {
13+ }
14+
15+ @Override
16+ public boolean containsKey(Object key) {
17+ return false;
18+ }
19+
20+ @Override
21+ public boolean containsValue(Object value) {
22+ return false;
23+ }
24+
25+ @Override
26+ public Set<java.util.Map.Entry<String, String>> entrySet() {
27+ return null;
28+ }
29+
30+ @Override
31+ public String get(Object key) {
32+ return null;
33+ }
34+
35+ @Override
36+ public boolean isEmpty() {
37+ return true;
38+ }
39+
40+ @Override
41+ public Set<String> keySet() {
42+ return null;
43+ }
44+
45+ @Override
46+ public String put(String key, String value) {
47+ return ExewrapClassLoader.SetEnvironment(key, value);
48+ }
49+
50+ @Override
51+ public void putAll(Map<? extends String, ? extends String> m) {
52+ if(m == null) {
53+ return;
54+ }
55+ for(Map.Entry<? extends String, ? extends String> entry : m.entrySet()) {
56+ String key = entry.getKey();
57+ String value = entry.getValue();
58+ put(key, value);
59+ }
60+ }
61+
62+ @Override
63+ public String remove(Object key) {
64+ return null;
65+ }
66+
67+ @Override
68+ public int size() {
69+ return 0;
70+ }
71+
72+ @Override
73+ public Collection<String> values() {
74+ return null;
75+ }
76+}
--- exewrap/trunk/exewrap/src/include/loader.h (revision 29)
+++ exewrap/trunk/exewrap/src/include/loader.h (revision 30)
@@ -27,16 +27,17 @@
2727 extern "C" {
2828 #endif
2929
30-extern BOOL LoadMainClass(int argc, char* argv[], char* utilities, LOAD_RESULT* result);
31-extern BOOL SetSplashScreenResource(char* splash_screen_name, BYTE* splash_screen_image_buf, DWORD splash_screen_image_len);
32-extern DWORD WINAPI RemoteCallMainMethod(void* _shared_memory_handle);
33-extern char* ToString(JNIEnv* env, jobject object, char* buf);
34-extern char* GetModuleObjectName(const char* prefix);
35-extern BYTE* GetResource(LPCTSTR name, RESOURCE* resource);
36-extern char* GetWinErrorMessage(DWORD err, int* exit_code, char* buf);
37-extern char* GetJniErrorMessage(int err, int* exit_code, char* buf);
38-extern void JNICALL JNI_WriteEventLog(JNIEnv *env, jobject clazz, jint logType, jstring message);
39-extern void JNICALL JNI_UncaughtException(JNIEnv *env, jobject clazz, jstring thread, jstring message, jstring trace);
30+extern BOOL LoadMainClass(int argc, char* argv[], char* utilities, LOAD_RESULT* result);
31+extern BOOL SetSplashScreenResource(char* splash_screen_name, BYTE* splash_screen_image_buf, DWORD splash_screen_image_len);
32+extern DWORD WINAPI RemoteCallMainMethod(void* _shared_memory_handle);
33+extern char* ToString(JNIEnv* env, jobject object, char* buf);
34+extern char* GetModuleObjectName(const char* prefix);
35+extern BYTE* GetResource(LPCTSTR name, RESOURCE* resource);
36+extern char* GetWinErrorMessage(DWORD err, int* exit_code, char* buf);
37+extern char* GetJniErrorMessage(int err, int* exit_code, char* buf);
38+extern void JNICALL JNI_WriteEventLog(JNIEnv *env, jobject clazz, jint logType, jstring message);
39+extern void JNICALL JNI_UncaughtException(JNIEnv *env, jobject clazz, jstring thread, jstring message, jstring trace);
40+extern jstring JNICALL JNI_SetEnvironment(JNIEnv *env, jobject clazz, jstring key, jstring value);
4041
4142 #ifdef __cplusplus
4243 }
--- exewrap/trunk/exewrap/src/loader.c (revision 29)
+++ exewrap/trunk/exewrap/src/loader.c (revision 30)
@@ -11,17 +11,18 @@
1111 #include "include/eventlog.h"
1212 #include "include/message.h"
1313
14-BOOL LoadMainClass(int argc, char* argv[], char* utilities, LOAD_RESULT* result);
15-BOOL SetSplashScreenResource(char* splash_screen_name, BYTE* splash_screen_image_buf, DWORD splash_screen_image_len);
16-DWORD WINAPI RemoteCallMainMethod(void* _shared_memory_handle);
17-char* ToString(JNIEnv* env, jobject object, char* buf);
18-char* GetModuleObjectName(const char* prefix);
19-BYTE* GetResource(LPCTSTR name, RESOURCE* resource);
20-char* GetWinErrorMessage(DWORD err, int* exit_code, char* buf);
21-char* GetJniErrorMessage(int err, int* exit_code, char* buf);
22-void JNICALL JNI_WriteConsole(JNIEnv *env, jobject clazz, jbyteArray b, jint off, jint len);
23-void JNICALL JNI_WriteEventLog(JNIEnv *env, jobject clazz, jint logType, jstring message);
24-void JNICALL JNI_UncaughtException(JNIEnv *env, jobject clazz, jstring thread, jstring message, jstring trace);
14+BOOL LoadMainClass(int argc, char* argv[], char* utilities, LOAD_RESULT* result);
15+BOOL SetSplashScreenResource(char* splash_screen_name, BYTE* splash_screen_image_buf, DWORD splash_screen_image_len);
16+DWORD WINAPI RemoteCallMainMethod(void* _shared_memory_handle);
17+char* ToString(JNIEnv* env, jobject object, char* buf);
18+char* GetModuleObjectName(const char* prefix);
19+BYTE* GetResource(LPCTSTR name, RESOURCE* resource);
20+char* GetWinErrorMessage(DWORD err, int* exit_code, char* buf);
21+char* GetJniErrorMessage(int err, int* exit_code, char* buf);
22+void JNICALL JNI_WriteConsole(JNIEnv *env, jobject clazz, jbyteArray b, jint off, jint len);
23+void JNICALL JNI_WriteEventLog(JNIEnv *env, jobject clazz, jint logType, jstring message);
24+void JNICALL JNI_UncaughtException(JNIEnv *env, jobject clazz, jstring thread, jstring message, jstring trace);
25+jstring JNICALL JNI_SetEnvironment(JNIEnv *env, jobject clazz, jstring key, jstring value);
2526
2627 static jint register_native(JNIEnv* env, jclass cls, const char* name, const char* signature, void* fnPtr);
2728 static void print_stack_trace(const char* text);
@@ -348,6 +349,12 @@
348349 sprintf(result->msg, _(MSG_ID_ERR_REGISTER_NATIVE), "UncaughtException");
349350 goto EXIT;
350351 }
352+ if (register_native(env, ExewrapClassLoader, "SetEnvironment", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", JNI_SetEnvironment) != 0)
353+ {
354+ result->msg_id = MSG_ID_ERR_REGISTER_NATIVE;
355+ sprintf(result->msg, _(MSG_ID_ERR_REGISTER_NATIVE), "SetEnvironment");
356+ goto EXIT;
357+ }
351358 // Create ExewrapClassLoader instance
352359 ExewrapClassLoader_init = (*env)->GetMethodID(env, ExewrapClassLoader, "<init>", "(Ljava/lang/ClassLoader;[Ljava/util/jar/JarInputStream;)V");
353360 if (ExewrapClassLoader_init == NULL)
@@ -752,6 +759,43 @@
752759 }
753760
754761
762+jstring JNICALL JNI_SetEnvironment(JNIEnv *env, jobject clazz, jstring key, jstring value)
763+{
764+ char* sjis_key;
765+ char* sjis_value;
766+ DWORD size;
767+ char* sjis_buf = NULL;
768+ jstring prev_value = NULL;
769+ BOOL result;
770+
771+ sjis_key = GetShiftJIS(env, key);
772+ sjis_value = GetShiftJIS(env, value);
773+
774+ size = GetEnvironmentVariable(sjis_key, NULL, 0);
775+ if (size > 0)
776+ {
777+ sjis_buf = (char*)malloc(size);
778+ size = GetEnvironmentVariable(sjis_key, sjis_buf, size);
779+ if (size > 0) {
780+ prev_value = GetJString(env, sjis_buf);
781+ }
782+ free(sjis_buf);
783+ }
784+
785+ result = SetEnvironmentVariable(sjis_key, sjis_value);
786+ if (result == 0)
787+ {
788+ if (prev_value != NULL)
789+ {
790+ (*env)->DeleteLocalRef(env, prev_value);
791+ prev_value = NULL;
792+ }
793+ }
794+
795+ return prev_value;
796+}
797+
798+
755799 static jint register_native(JNIEnv* env, jclass cls, const char* name, const char* signature, void* fnPtr)
756800 {
757801 JNINativeMethod nm;
Show on old repository browser