Neurogami-roir 1.3.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. data/History.txt +22 -0
  2. data/Manifest.txt +250 -0
  3. data/README.md +12 -0
  4. data/Rakefile +63 -0
  5. data/bin/roir +176 -0
  6. data/data/GenericJavaApp.icns +0 -0
  7. data/data/JavaApplicationStub +0 -0
  8. data/data/Rawr logo 1 large.png +0 -0
  9. data/data/Rawr logo 2 large.png +0 -0
  10. data/data/Rawr logo2.png +0 -0
  11. data/data/website/_notes/dwsync.xml +1 -0
  12. data/data/website/css/1.css +254 -0
  13. data/data/website/css/_notes/dwsync.xml +1 -0
  14. data/data/website/images/_notes/dwsync.xml +1 -0
  15. data/data/website/images/body_bg.jpg +0 -0
  16. data/data/website/images/bullet.gif +0 -0
  17. data/data/website/images/content.jpg +0 -0
  18. data/data/website/images/content_h2.gif +0 -0
  19. data/data/website/images/details.gif +0 -0
  20. data/data/website/images/details.jpg +0 -0
  21. data/data/website/images/header_bg.jpg +0 -0
  22. data/data/website/images/nav_a_hover.gif +0 -0
  23. data/data/website/images/rawr_logo.png +0 -0
  24. data/data/website/index.html +164 -0
  25. data/lib/app_bundler.rb +138 -0
  26. data/lib/bundler.rb +36 -0
  27. data/lib/command.rb +68 -0
  28. data/lib/exe_bundler.rb +106 -0
  29. data/lib/generator.rb +127 -0
  30. data/lib/jar_builder.rb +57 -0
  31. data/lib/jruby_batch_compiler.rb +127 -0
  32. data/lib/jruby_release.rb +104 -0
  33. data/lib/launch4j/LICENSE.txt +30 -0
  34. data/lib/launch4j/bin-linux/COPYING +340 -0
  35. data/lib/launch4j/bin-linux/ld +0 -0
  36. data/lib/launch4j/bin-linux/windres +0 -0
  37. data/lib/launch4j/bin-mac/COPYING +340 -0
  38. data/lib/launch4j/bin-mac/ld +0 -0
  39. data/lib/launch4j/bin-mac/readme.txt +1 -0
  40. data/lib/launch4j/bin-mac/windres +0 -0
  41. data/lib/launch4j/bin-win/COPYING +340 -0
  42. data/lib/launch4j/bin-win/ld.exe +0 -0
  43. data/lib/launch4j/bin-win/windres.exe +0 -0
  44. data/lib/launch4j/build.xml +62 -0
  45. data/lib/launch4j/demo/ConsoleApp/ConsoleApp.jar +0 -0
  46. data/lib/launch4j/demo/ConsoleApp/build.xml +57 -0
  47. data/lib/launch4j/demo/ConsoleApp/l4j/ConsoleApp.ico +0 -0
  48. data/lib/launch4j/demo/ConsoleApp/lib/readme.txt +8 -0
  49. data/lib/launch4j/demo/ConsoleApp/readme.txt +1 -0
  50. data/lib/launch4j/demo/ConsoleApp/src/net/sf/launch4j/example/ConsoleApp.java +72 -0
  51. data/lib/launch4j/demo/LICENSE.txt +30 -0
  52. data/lib/launch4j/demo/SimpleApp/SimpleApp.jar +0 -0
  53. data/lib/launch4j/demo/SimpleApp/build.xml +52 -0
  54. data/lib/launch4j/demo/SimpleApp/l4j/SimpleApp.ico +0 -0
  55. data/lib/launch4j/demo/SimpleApp/l4j/SimpleApp.xml +18 -0
  56. data/lib/launch4j/demo/SimpleApp/l4j/splash.bmp +0 -0
  57. data/lib/launch4j/demo/SimpleApp/lib/readme.txt +8 -0
  58. data/lib/launch4j/demo/SimpleApp/readme.txt +1 -0
  59. data/lib/launch4j/demo/SimpleApp/src/net/sf/launch4j/example/SimpleApp.java +104 -0
  60. data/lib/launch4j/demo/readme.txt +3 -0
  61. data/lib/launch4j/head/LICENSE.txt +23 -0
  62. data/lib/launch4j/head/consolehead.o +0 -0
  63. data/lib/launch4j/head/guihead.o +0 -0
  64. data/lib/launch4j/head/head.o +0 -0
  65. data/lib/launch4j/head_src/LICENSE.txt +23 -0
  66. data/lib/launch4j/head_src/consolehead/Makefile.win +33 -0
  67. data/lib/launch4j/head_src/consolehead/consolehead.c +65 -0
  68. data/lib/launch4j/head_src/consolehead/consolehead.dev +108 -0
  69. data/lib/launch4j/head_src/guihead/Makefile.win +33 -0
  70. data/lib/launch4j/head_src/guihead/guihead.c +185 -0
  71. data/lib/launch4j/head_src/guihead/guihead.dev +109 -0
  72. data/lib/launch4j/head_src/guihead/guihead.h +43 -0
  73. data/lib/launch4j/head_src/head.c +807 -0
  74. data/lib/launch4j/head_src/head.h +113 -0
  75. data/lib/launch4j/head_src/resource.h +71 -0
  76. data/lib/launch4j/launch4j +8 -0
  77. data/lib/launch4j/launch4j.jar +0 -0
  78. data/lib/launch4j/launch4j.jfpr +0 -0
  79. data/lib/launch4j/lib/JGoodies.Forms.LICENSE.txt +31 -0
  80. data/lib/launch4j/lib/JGoodies.Looks.LICENSE.txt +31 -0
  81. data/lib/launch4j/lib/Nuvola.Icon.Theme.LICENSE.txt +504 -0
  82. data/lib/launch4j/lib/XStream.LICENSE.txt +27 -0
  83. data/lib/launch4j/lib/commons-beanutils.jar +0 -0
  84. data/lib/launch4j/lib/commons-logging.jar +0 -0
  85. data/lib/launch4j/lib/commons.LICENSE.txt +50 -0
  86. data/lib/launch4j/lib/forms.jar +0 -0
  87. data/lib/launch4j/lib/formsrt.jar +0 -0
  88. data/lib/launch4j/lib/foxtrot.LICENSE.txt +25 -0
  89. data/lib/launch4j/lib/foxtrot.jar +0 -0
  90. data/lib/launch4j/lib/looks.jar +0 -0
  91. data/lib/launch4j/lib/xstream.jar +0 -0
  92. data/lib/launch4j/manifest/uac.exe.manifest +12 -0
  93. data/lib/launch4j/manifest/xp-themes.exe.manifest +14 -0
  94. data/lib/launch4j/src/images/asterix-o.gif +0 -0
  95. data/lib/launch4j/src/images/asterix.gif +0 -0
  96. data/lib/launch4j/src/images/build.png +0 -0
  97. data/lib/launch4j/src/images/button_ok.png +0 -0
  98. data/lib/launch4j/src/images/cancel16.png +0 -0
  99. data/lib/launch4j/src/images/down16.png +0 -0
  100. data/lib/launch4j/src/images/edit_add16.png +0 -0
  101. data/lib/launch4j/src/images/info.png +0 -0
  102. data/lib/launch4j/src/images/new.png +0 -0
  103. data/lib/launch4j/src/images/new16.png +0 -0
  104. data/lib/launch4j/src/images/ok16.png +0 -0
  105. data/lib/launch4j/src/images/open.png +0 -0
  106. data/lib/launch4j/src/images/open16.png +0 -0
  107. data/lib/launch4j/src/images/run.png +0 -0
  108. data/lib/launch4j/src/images/save.png +0 -0
  109. data/lib/launch4j/src/images/up16.png +0 -0
  110. data/lib/launch4j/src/launch4j.properties +2 -0
  111. data/lib/launch4j/src/net/sf/launch4j/Builder.java +207 -0
  112. data/lib/launch4j/src/net/sf/launch4j/BuilderException.java +52 -0
  113. data/lib/launch4j/src/net/sf/launch4j/ExecException.java +66 -0
  114. data/lib/launch4j/src/net/sf/launch4j/FileChooserFilter.java +76 -0
  115. data/lib/launch4j/src/net/sf/launch4j/Log.java +105 -0
  116. data/lib/launch4j/src/net/sf/launch4j/Main.java +99 -0
  117. data/lib/launch4j/src/net/sf/launch4j/Messages.java +78 -0
  118. data/lib/launch4j/src/net/sf/launch4j/OptionParser.java +71 -0
  119. data/lib/launch4j/src/net/sf/launch4j/RcBuilder.java +340 -0
  120. data/lib/launch4j/src/net/sf/launch4j/Util.java +197 -0
  121. data/lib/launch4j/src/net/sf/launch4j/ant/AntClassPath.java +61 -0
  122. data/lib/launch4j/src/net/sf/launch4j/ant/AntConfig.java +129 -0
  123. data/lib/launch4j/src/net/sf/launch4j/ant/AntJre.java +69 -0
  124. data/lib/launch4j/src/net/sf/launch4j/ant/Launch4jTask.java +162 -0
  125. data/lib/launch4j/src/net/sf/launch4j/ant/Messages.java +55 -0
  126. data/lib/launch4j/src/net/sf/launch4j/ant/StringWrapper.java +67 -0
  127. data/lib/launch4j/src/net/sf/launch4j/ant/messages.properties +35 -0
  128. data/lib/launch4j/src/net/sf/launch4j/ant/messages_es.properties +35 -0
  129. data/lib/launch4j/src/net/sf/launch4j/binding/Binding.java +62 -0
  130. data/lib/launch4j/src/net/sf/launch4j/binding/BindingException.java +52 -0
  131. data/lib/launch4j/src/net/sf/launch4j/binding/Bindings.java +317 -0
  132. data/lib/launch4j/src/net/sf/launch4j/binding/IValidatable.java +44 -0
  133. data/lib/launch4j/src/net/sf/launch4j/binding/InvariantViolationException.java +67 -0
  134. data/lib/launch4j/src/net/sf/launch4j/binding/JComboBoxBinding.java +119 -0
  135. data/lib/launch4j/src/net/sf/launch4j/binding/JListBinding.java +118 -0
  136. data/lib/launch4j/src/net/sf/launch4j/binding/JRadioButtonBinding.java +146 -0
  137. data/lib/launch4j/src/net/sf/launch4j/binding/JTextAreaBinding.java +123 -0
  138. data/lib/launch4j/src/net/sf/launch4j/binding/JTextComponentBinding.java +108 -0
  139. data/lib/launch4j/src/net/sf/launch4j/binding/JToggleButtonBinding.java +108 -0
  140. data/lib/launch4j/src/net/sf/launch4j/binding/Messages.java +78 -0
  141. data/lib/launch4j/src/net/sf/launch4j/binding/OptComponentBinding.java +119 -0
  142. data/lib/launch4j/src/net/sf/launch4j/binding/OptJTextAreaBinding.java +141 -0
  143. data/lib/launch4j/src/net/sf/launch4j/binding/Validator.java +259 -0
  144. data/lib/launch4j/src/net/sf/launch4j/binding/messages.properties +52 -0
  145. data/lib/launch4j/src/net/sf/launch4j/binding/messages_es.properties +51 -0
  146. data/lib/launch4j/src/net/sf/launch4j/config/ClassPath.java +87 -0
  147. data/lib/launch4j/src/net/sf/launch4j/config/Config.java +396 -0
  148. data/lib/launch4j/src/net/sf/launch4j/config/ConfigPersister.java +249 -0
  149. data/lib/launch4j/src/net/sf/launch4j/config/ConfigPersisterException.java +51 -0
  150. data/lib/launch4j/src/net/sf/launch4j/config/Jre.java +235 -0
  151. data/lib/launch4j/src/net/sf/launch4j/config/LdDefaults.java +62 -0
  152. data/lib/launch4j/src/net/sf/launch4j/config/Messages.java +78 -0
  153. data/lib/launch4j/src/net/sf/launch4j/config/Msg.java +111 -0
  154. data/lib/launch4j/src/net/sf/launch4j/config/SingleInstance.java +74 -0
  155. data/lib/launch4j/src/net/sf/launch4j/config/Splash.java +103 -0
  156. data/lib/launch4j/src/net/sf/launch4j/config/VersionInfo.java +168 -0
  157. data/lib/launch4j/src/net/sf/launch4j/config/messages.properties +93 -0
  158. data/lib/launch4j/src/net/sf/launch4j/config/messages_es.properties +75 -0
  159. data/lib/launch4j/src/net/sf/launch4j/form/BasicForm.java +283 -0
  160. data/lib/launch4j/src/net/sf/launch4j/form/BasicForm.jfrm +0 -0
  161. data/lib/launch4j/src/net/sf/launch4j/form/ClassPathForm.java +193 -0
  162. data/lib/launch4j/src/net/sf/launch4j/form/ClassPathForm.jfrm +0 -0
  163. data/lib/launch4j/src/net/sf/launch4j/form/ConfigForm.java +132 -0
  164. data/lib/launch4j/src/net/sf/launch4j/form/ConfigForm.jfrm +0 -0
  165. data/lib/launch4j/src/net/sf/launch4j/form/EnvironmentVarsForm.java +127 -0
  166. data/lib/launch4j/src/net/sf/launch4j/form/EnvironmentVarsForm.jfrm +0 -0
  167. data/lib/launch4j/src/net/sf/launch4j/form/HeaderForm.java +171 -0
  168. data/lib/launch4j/src/net/sf/launch4j/form/HeaderForm.jfrm +0 -0
  169. data/lib/launch4j/src/net/sf/launch4j/form/JreForm.java +266 -0
  170. data/lib/launch4j/src/net/sf/launch4j/form/JreForm.jfrm +0 -0
  171. data/lib/launch4j/src/net/sf/launch4j/form/Messages.java +55 -0
  172. data/lib/launch4j/src/net/sf/launch4j/form/MessagesForm.java +183 -0
  173. data/lib/launch4j/src/net/sf/launch4j/form/MessagesForm.jfrm +0 -0
  174. data/lib/launch4j/src/net/sf/launch4j/form/SingleInstanceForm.java +141 -0
  175. data/lib/launch4j/src/net/sf/launch4j/form/SingleInstanceForm.jfrm +0 -0
  176. data/lib/launch4j/src/net/sf/launch4j/form/SplashForm.java +166 -0
  177. data/lib/launch4j/src/net/sf/launch4j/form/SplashForm.jfrm +0 -0
  178. data/lib/launch4j/src/net/sf/launch4j/form/VersionInfoForm.java +232 -0
  179. data/lib/launch4j/src/net/sf/launch4j/form/VersionInfoForm.jfrm +0 -0
  180. data/lib/launch4j/src/net/sf/launch4j/form/messages.properties +146 -0
  181. data/lib/launch4j/src/net/sf/launch4j/form/messages_es.properties +118 -0
  182. data/lib/launch4j/src/net/sf/launch4j/formimpl/AbstractAcceptListener.java +75 -0
  183. data/lib/launch4j/src/net/sf/launch4j/formimpl/BasicFormImpl.java +101 -0
  184. data/lib/launch4j/src/net/sf/launch4j/formimpl/BrowseActionListener.java +79 -0
  185. data/lib/launch4j/src/net/sf/launch4j/formimpl/ClassPathFormImpl.java +222 -0
  186. data/lib/launch4j/src/net/sf/launch4j/formimpl/ConfigFormImpl.java +100 -0
  187. data/lib/launch4j/src/net/sf/launch4j/formimpl/EnvironmentVarsFormImpl.java +50 -0
  188. data/lib/launch4j/src/net/sf/launch4j/formimpl/FileChooser.java +65 -0
  189. data/lib/launch4j/src/net/sf/launch4j/formimpl/GlassPane.java +67 -0
  190. data/lib/launch4j/src/net/sf/launch4j/formimpl/HeaderFormImpl.java +102 -0
  191. data/lib/launch4j/src/net/sf/launch4j/formimpl/JreFormImpl.java +166 -0
  192. data/lib/launch4j/src/net/sf/launch4j/formimpl/MainFrame.java +358 -0
  193. data/lib/launch4j/src/net/sf/launch4j/formimpl/Messages.java +55 -0
  194. data/lib/launch4j/src/net/sf/launch4j/formimpl/MessagesFormImpl.java +58 -0
  195. data/lib/launch4j/src/net/sf/launch4j/formimpl/SingleInstanceFormImpl.java +54 -0
  196. data/lib/launch4j/src/net/sf/launch4j/formimpl/SplashFormImpl.java +61 -0
  197. data/lib/launch4j/src/net/sf/launch4j/formimpl/VersionInfoFormImpl.java +63 -0
  198. data/lib/launch4j/src/net/sf/launch4j/formimpl/messages.properties +74 -0
  199. data/lib/launch4j/src/net/sf/launch4j/formimpl/messages_es.properties +56 -0
  200. data/lib/launch4j/src/net/sf/launch4j/messages.properties +45 -0
  201. data/lib/launch4j/src/net/sf/launch4j/messages_es.properties +45 -0
  202. data/lib/launch4j/w32api/MinGW.LICENSE.txt +25 -0
  203. data/lib/launch4j/w32api/crt2.o +0 -0
  204. data/lib/launch4j/w32api/libadvapi32.a +0 -0
  205. data/lib/launch4j/w32api/libgcc.a +0 -0
  206. data/lib/launch4j/w32api/libkernel32.a +0 -0
  207. data/lib/launch4j/w32api/libmingw32.a +0 -0
  208. data/lib/launch4j/w32api/libmsvcrt.a +0 -0
  209. data/lib/launch4j/w32api/libshell32.a +0 -0
  210. data/lib/launch4j/w32api/libuser32.a +0 -0
  211. data/lib/launch4j/web/bullet.gif +0 -0
  212. data/lib/launch4j/web/changelog.html +356 -0
  213. data/lib/launch4j/web/docs.html +585 -0
  214. data/lib/launch4j/web/index.html +128 -0
  215. data/lib/launch4j/web/launch4j-use.gif +0 -0
  216. data/lib/launch4j/web/launch4j.gif +0 -0
  217. data/lib/launch4j/web/links.html +73 -0
  218. data/lib/launch4j/web/style.css +159 -0
  219. data/lib/options.rb +101 -0
  220. data/lib/platform.rb +28 -0
  221. data/lib/rawr.rb +178 -0
  222. data/lib/rawr_bundle.rb +26 -0
  223. data/lib/rawr_version.rb +3 -0
  224. data/lib/web_bundler.rb +114 -0
  225. data/lib/zip/ioextras.rb +155 -0
  226. data/lib/zip/stdrubyext.rb +111 -0
  227. data/lib/zip/tempfile_bugfixed.rb +195 -0
  228. data/lib/zip/zip.rb +1848 -0
  229. data/lib/zip/zipfilesystem.rb +609 -0
  230. data/lib/zip/ziprequire.rb +90 -0
  231. data/tasks/ann.rake +81 -0
  232. data/tasks/bones.rake +21 -0
  233. data/tasks/gem.rake +121 -0
  234. data/tasks/manifest.rake +49 -0
  235. data/tasks/notes.rake +28 -0
  236. data/tasks/post_load.rake +39 -0
  237. data/tasks/rdoc.rake +51 -0
  238. data/tasks/rubyforge.rake +57 -0
  239. data/tasks/setup.rb +269 -0
  240. data/tasks/spec.rake +63 -0
  241. data/tasks/svn.rake +48 -0
  242. data/tasks/test.rake +38 -0
  243. data/test/unit/app_bundler_spec.rb +65 -0
  244. data/test/unit/bundler_spec.rb +27 -0
  245. data/test/unit/generator_spec.rb +49 -0
  246. data/test/unit/jar_builder_spec.rb +5 -0
  247. data/test/unit/options_spec.rb +97 -0
  248. data/test/unit/platform_spec.rb +29 -0
  249. data/test/unit/spec_helpers.rb +22 -0
  250. data/test/unit/web_bundler_spec.rb +83 -0
  251. metadata +501 -0
@@ -0,0 +1,807 @@
1
+ /*
2
+ Launch4j (http://launch4j.sourceforge.net/)
3
+ Cross-platform Java application wrapper for creating Windows native executables.
4
+
5
+ Copyright (c) 2004, 2008 Grzegorz Kowal,
6
+ Ian Roberts (jdk preference patch)
7
+ Sylvain Mina (single instance patch)
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ Except as contained in this notice, the name(s) of the above copyright holders
20
+ shall not be used in advertising or otherwise to promote the sale, use or other
21
+ dealings in this Software without prior written authorization.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
+ THE SOFTWARE.
30
+ */
31
+
32
+ #include "resource.h"
33
+ #include "head.h"
34
+
35
+ HMODULE hModule;
36
+ FILE* hLog;
37
+ BOOL console = FALSE;
38
+ BOOL wow64 = FALSE;
39
+ int foundJava = NO_JAVA_FOUND;
40
+
41
+ struct _stat statBuf;
42
+ PROCESS_INFORMATION pi;
43
+ DWORD priority;
44
+
45
+ char mutexName[STR] = {0};
46
+
47
+ char errUrl[256] = {0};
48
+ char errTitle[STR] = "Launch4j";
49
+ char errMsg[BIG_STR] = {0};
50
+
51
+ char javaMinVer[STR] = {0};
52
+ char javaMaxVer[STR] = {0};
53
+ char foundJavaVer[STR] = {0};
54
+ char foundJavaKey[_MAX_PATH] = {0};
55
+
56
+ char oldPwd[_MAX_PATH] = {0};
57
+ char workingDir[_MAX_PATH] = {0};
58
+ char cmd[_MAX_PATH] = {0};
59
+ char args[MAX_ARGS] = {0};
60
+
61
+ FILE* openLogFile(const char* exePath, const int pathLen) {
62
+ char path[_MAX_PATH] = {0};
63
+ strncpy(path, exePath, pathLen);
64
+ strcat(path, "\\launch4j.log");
65
+ return fopen(path, "a");
66
+ }
67
+
68
+ void closeLogFile() {
69
+ if (hLog != NULL) {
70
+ fclose(hLog);
71
+ }
72
+ }
73
+
74
+ void setWow64Flag() {
75
+ LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
76
+ GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
77
+
78
+ if (fnIsWow64Process != NULL) {
79
+ fnIsWow64Process(GetCurrentProcess(), &wow64);
80
+ }
81
+ debug("WOW64:\t\t%s\n", wow64 ? "yes" : "no");
82
+ }
83
+
84
+ void setConsoleFlag() {
85
+ console = TRUE;
86
+ }
87
+
88
+ void msgBox(const char* text) {
89
+ if (console) {
90
+ printf("%s: %s\n", errTitle, text);
91
+ } else {
92
+ MessageBox(NULL, text, errTitle, MB_OK);
93
+ }
94
+ }
95
+
96
+ void signalError() {
97
+ DWORD err = GetLastError();
98
+ if (err) {
99
+ LPVOID lpMsgBuf;
100
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
101
+ | FORMAT_MESSAGE_FROM_SYSTEM
102
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
103
+ NULL,
104
+ err,
105
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
106
+ (LPTSTR) &lpMsgBuf,
107
+ 0,
108
+ NULL);
109
+ debug("Error:\t\t%s\n", (LPCTSTR) lpMsgBuf);
110
+ strcat(errMsg, "\n\n");
111
+ strcat(errMsg, (LPCTSTR) lpMsgBuf);
112
+ msgBox(errMsg);
113
+ LocalFree(lpMsgBuf);
114
+ } else {
115
+ msgBox(errMsg);
116
+ }
117
+ if (*errUrl) {
118
+ debug("Open URL:\t%s\n", errUrl);
119
+ ShellExecute(NULL, "open", errUrl, NULL, NULL, SW_SHOWNORMAL);
120
+ }
121
+ closeLogFile();
122
+ }
123
+
124
+ BOOL loadString(const int resID, char* buffer) {
125
+ HRSRC hResource;
126
+ HGLOBAL hResourceLoaded;
127
+ LPBYTE lpBuffer;
128
+
129
+ hResource = FindResourceEx(hModule, RT_RCDATA, MAKEINTRESOURCE(resID),
130
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT));
131
+ if (NULL != hResource) {
132
+ hResourceLoaded = LoadResource(hModule, hResource);
133
+ if (NULL != hResourceLoaded) {
134
+ lpBuffer = (LPBYTE) LockResource(hResourceLoaded);
135
+ if (NULL != lpBuffer) {
136
+ int x = 0;
137
+ do {
138
+ buffer[x] = (char) lpBuffer[x];
139
+ } while (buffer[x++] != 0);
140
+ // debug("Resource %d:\t%s\n", resID, buffer);
141
+ return TRUE;
142
+ }
143
+ }
144
+ } else {
145
+ SetLastError(0);
146
+ }
147
+ return FALSE;
148
+ }
149
+
150
+ BOOL loadBool(const int resID) {
151
+ char boolStr[20] = {0};
152
+ loadString(resID, boolStr);
153
+ return strcmp(boolStr, TRUE_STR) == 0;
154
+ }
155
+
156
+ int loadInt(const int resID) {
157
+ char intStr[20] = {0};
158
+ loadString(resID, intStr);
159
+ return atoi(intStr);
160
+ }
161
+
162
+ BOOL regQueryValue(const char* regPath, unsigned char* buffer,
163
+ unsigned long bufferLength) {
164
+ HKEY hRootKey;
165
+ char* key;
166
+ char* value;
167
+ if (strstr(regPath, HKEY_CLASSES_ROOT_STR) == regPath) {
168
+ hRootKey = HKEY_CLASSES_ROOT;
169
+ } else if (strstr(regPath, HKEY_CURRENT_USER_STR) == regPath) {
170
+ hRootKey = HKEY_CURRENT_USER;
171
+ } else if (strstr(regPath, HKEY_LOCAL_MACHINE_STR) == regPath) {
172
+ hRootKey = HKEY_LOCAL_MACHINE;
173
+ } else if (strstr(regPath, HKEY_USERS_STR) == regPath) {
174
+ hRootKey = HKEY_USERS;
175
+ } else if (strstr(regPath, HKEY_CURRENT_CONFIG_STR) == regPath) {
176
+ hRootKey = HKEY_CURRENT_CONFIG;
177
+ } else {
178
+ return FALSE;
179
+ }
180
+ key = strchr(regPath, '\\') + 1;
181
+ value = strrchr(regPath, '\\') + 1;
182
+ *(value - 1) = 0;
183
+
184
+ HKEY hKey;
185
+ unsigned long datatype;
186
+ BOOL result = FALSE;
187
+ if ((wow64 && RegOpenKeyEx(hRootKey,
188
+ key,
189
+ 0,
190
+ KEY_READ | KEY_WOW64_64KEY,
191
+ &hKey) == ERROR_SUCCESS)
192
+ || RegOpenKeyEx(hRootKey,
193
+ key,
194
+ 0,
195
+ KEY_READ,
196
+ &hKey) == ERROR_SUCCESS) {
197
+ result = RegQueryValueEx(hKey, value, NULL, &datatype, buffer, &bufferLength)
198
+ == ERROR_SUCCESS;
199
+ RegCloseKey(hKey);
200
+ }
201
+ *(value - 1) = '\\';
202
+ return result;
203
+ }
204
+
205
+ void regSearch(const HKEY hKey, const char* keyName, const int searchType) {
206
+ DWORD x = 0;
207
+ unsigned long size = BIG_STR;
208
+ FILETIME time;
209
+ char buffer[BIG_STR] = {0};
210
+ while (RegEnumKeyEx(
211
+ hKey, // handle to key to enumerate
212
+ x++, // index of subkey to enumerate
213
+ buffer, // address of buffer for subkey name
214
+ &size, // address for size of subkey buffer
215
+ NULL, // reserved
216
+ NULL, // address of buffer for class string
217
+ NULL, // address for size of class buffer
218
+ &time) == ERROR_SUCCESS) {
219
+
220
+ if (strcmp(buffer, javaMinVer) >= 0
221
+ && (!*javaMaxVer || strcmp(buffer, javaMaxVer) <= 0)
222
+ && strcmp(buffer, foundJavaVer) > 0) {
223
+ strcpy(foundJavaVer, buffer);
224
+ strcpy(foundJavaKey, keyName);
225
+ appendPath(foundJavaKey, buffer);
226
+ foundJava = searchType;
227
+ debug("Match:\t\t%s\\%s\n", keyName, buffer);
228
+ } else {
229
+ debug("Ignore:\t\t%s\\%s\n", keyName, buffer);
230
+ }
231
+ size = BIG_STR;
232
+ }
233
+ }
234
+
235
+ void regSearchWow(const char* keyName, const int searchType) {
236
+ HKEY hKey;
237
+ debug("64-bit search:\t%s...\n", keyName);
238
+ if (wow64 && RegOpenKeyEx(HKEY_LOCAL_MACHINE,
239
+ keyName,
240
+ 0,
241
+ KEY_READ | KEY_WOW64_64KEY,
242
+ &hKey) == ERROR_SUCCESS) {
243
+
244
+ regSearch(hKey, keyName, searchType | KEY_WOW64_64KEY);
245
+ RegCloseKey(hKey);
246
+ if ((foundJava & KEY_WOW64_64KEY) != NO_JAVA_FOUND)
247
+ {
248
+ debug("Using 64-bit runtime.\n");
249
+ return;
250
+ }
251
+ }
252
+ debug("32-bit search:\t%s...\n", keyName);
253
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
254
+ keyName,
255
+ 0,
256
+ KEY_READ,
257
+ &hKey) == ERROR_SUCCESS) {
258
+ regSearch(hKey, keyName, searchType);
259
+ RegCloseKey(hKey);
260
+ }
261
+ }
262
+
263
+ void regSearchJreSdk(const char* jreKeyName, const char* sdkKeyName,
264
+ const int jdkPreference) {
265
+ if (jdkPreference == JDK_ONLY || jdkPreference == PREFER_JDK) {
266
+ regSearchWow(sdkKeyName, FOUND_SDK);
267
+ if (jdkPreference != JDK_ONLY) {
268
+ regSearchWow(jreKeyName, FOUND_JRE);
269
+ }
270
+ } else { // jdkPreference == JRE_ONLY or PREFER_JRE
271
+ regSearchWow(jreKeyName, FOUND_JRE);
272
+ if (jdkPreference != JRE_ONLY) {
273
+ regSearchWow(sdkKeyName, FOUND_SDK);
274
+ }
275
+ }
276
+ }
277
+
278
+ BOOL findJavaHome(char* path, const int jdkPreference) {
279
+ regSearchJreSdk("SOFTWARE\\JavaSoft\\Java Runtime Environment",
280
+ "SOFTWARE\\JavaSoft\\Java Development Kit",
281
+ jdkPreference);
282
+ if (foundJava == NO_JAVA_FOUND) {
283
+ regSearchJreSdk("SOFTWARE\\IBM\\Java2 Runtime Environment",
284
+ "SOFTWARE\\IBM\\Java Development Kit",
285
+ jdkPreference);
286
+ }
287
+ if (foundJava != NO_JAVA_FOUND) {
288
+ HKEY hKey;
289
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
290
+ foundJavaKey,
291
+ 0,
292
+ KEY_READ | (foundJava & KEY_WOW64_64KEY),
293
+ &hKey) == ERROR_SUCCESS) {
294
+ unsigned char buffer[BIG_STR] = {0};
295
+ unsigned long bufferlength = BIG_STR;
296
+ unsigned long datatype;
297
+ if (RegQueryValueEx(hKey, "JavaHome", NULL, &datatype, buffer,
298
+ &bufferlength) == ERROR_SUCCESS) {
299
+ int i = 0;
300
+ do {
301
+ path[i] = buffer[i];
302
+ } while (path[i++] != 0);
303
+ if (foundJava & FOUND_SDK) {
304
+ appendPath(path, "jre");
305
+ }
306
+ RegCloseKey(hKey);
307
+ return TRUE;
308
+ }
309
+ RegCloseKey(hKey);
310
+ }
311
+ }
312
+ return FALSE;
313
+ }
314
+
315
+ /*
316
+ * Extract the executable name, returns path length.
317
+ */
318
+ int getExePath(char* exePath) {
319
+ if (GetModuleFileName(hModule, exePath, _MAX_PATH) == 0) {
320
+ return -1;
321
+ }
322
+ return strrchr(exePath, '\\') - exePath;
323
+ }
324
+
325
+ void appendPath(char* basepath, const char* path) {
326
+ if (basepath[strlen(basepath) - 1] != '\\') {
327
+ strcat(basepath, "\\");
328
+ }
329
+ strcat(basepath, path);
330
+ }
331
+
332
+ void appendJavaw(char* jrePath) {
333
+ if (console) {
334
+ appendPath(jrePath, "bin\\java.exe");
335
+ } else {
336
+ appendPath(jrePath, "bin\\javaw.exe");
337
+ }
338
+ }
339
+
340
+ void appendLauncher(const BOOL setProcName, char* exePath,
341
+ const int pathLen, char* cmd) {
342
+ if (setProcName) {
343
+ char tmpspec[_MAX_PATH];
344
+ char tmpfile[_MAX_PATH];
345
+ strcpy(tmpspec, cmd);
346
+ strcat(tmpspec, LAUNCH4J_TMP_DIR);
347
+ tmpspec[strlen(tmpspec) - 1] = 0;
348
+ if (_stat(tmpspec, &statBuf) == 0) {
349
+ // Remove temp launchers and manifests
350
+ struct _finddata_t c_file;
351
+ long hFile;
352
+ appendPath(tmpspec, "*.exe");
353
+ strcpy(tmpfile, cmd);
354
+ strcat(tmpfile, LAUNCH4J_TMP_DIR);
355
+ char* filename = tmpfile + strlen(tmpfile);
356
+ if ((hFile = _findfirst(tmpspec, &c_file)) != -1L) {
357
+ do {
358
+ strcpy(filename, c_file.name);
359
+ debug("Unlink:\t\t%s\n", tmpfile);
360
+ _unlink(tmpfile);
361
+ strcat(tmpfile, MANIFEST);
362
+ debug("Unlink:\t\t%s\n", tmpfile);
363
+ _unlink(tmpfile);
364
+ } while (_findnext(hFile, &c_file) == 0);
365
+ }
366
+ _findclose(hFile);
367
+ } else {
368
+ if (_mkdir(tmpspec) != 0) {
369
+ debug("Mkdir failed:\t%s\n", tmpspec);
370
+ appendJavaw(cmd);
371
+ return;
372
+ }
373
+ }
374
+ char javaw[_MAX_PATH];
375
+ strcpy(javaw, cmd);
376
+ appendJavaw(javaw);
377
+ strcpy(tmpfile, cmd);
378
+ strcat(tmpfile, LAUNCH4J_TMP_DIR);
379
+ char* tmpfilename = tmpfile + strlen(tmpfile);
380
+ char* exeFilePart = exePath + pathLen + 1;
381
+
382
+ // Copy manifest
383
+ char manifest[_MAX_PATH] = {0};
384
+ strcpy(manifest, exePath);
385
+ strcat(manifest, MANIFEST);
386
+ if (_stat(manifest, &statBuf) == 0) {
387
+ strcat(tmpfile, exeFilePart);
388
+ strcat(tmpfile, MANIFEST);
389
+ debug("Copy:\t\t%s -> %s\n", manifest, tmpfile);
390
+ CopyFile(manifest, tmpfile, FALSE);
391
+ }
392
+
393
+ // Copy launcher
394
+ strcpy(tmpfilename, exeFilePart);
395
+ debug("Copy:\t\t%s -> %s\n", javaw, tmpfile);
396
+ if (CopyFile(javaw, tmpfile, FALSE)) {
397
+ strcpy(cmd, tmpfile);
398
+ return;
399
+ } else if (_stat(javaw, &statBuf) == 0) {
400
+ long fs = statBuf.st_size;
401
+ if (_stat(tmpfile, &statBuf) == 0 && fs == statBuf.st_size) {
402
+ debug("Reusing:\t\t%s\n", tmpfile);
403
+ strcpy(cmd, tmpfile);
404
+ return;
405
+ }
406
+ }
407
+ }
408
+ appendJavaw(cmd);
409
+ }
410
+
411
+ void appendAppClasspath(char* dst, const char* src, const char* classpath) {
412
+ strcat(dst, src);
413
+ if (*classpath) {
414
+ strcat(dst, ";");
415
+ }
416
+ }
417
+
418
+ BOOL isJrePathOk(const char* path) {
419
+ char javaw[_MAX_PATH];
420
+ BOOL result = FALSE;
421
+ if (*path) {
422
+ strcpy(javaw, path);
423
+ appendJavaw(javaw);
424
+ result = _stat(javaw, &statBuf) == 0;
425
+ }
426
+ debug("Check launcher:\t%s %s\n", javaw, result ? "(OK)" : "(n/a)");
427
+ return result;
428
+ }
429
+
430
+ /*
431
+ * Expand environment %variables%
432
+ */
433
+ BOOL expandVars(char *dst, const char *src, const char *exePath, const int pathLen) {
434
+ char varName[STR];
435
+ char varValue[MAX_VAR_SIZE];
436
+ while (strlen(src) > 0) {
437
+ char *start = strchr(src, '%');
438
+ if (start != NULL) {
439
+ char *end = strchr(start + 1, '%');
440
+ if (end == NULL) {
441
+ return FALSE;
442
+ }
443
+ // Copy content up to %VAR%
444
+ strncat(dst, src, start - src);
445
+ // Insert value of %VAR%
446
+ *varName = 0;
447
+ strncat(varName, start + 1, end - start - 1);
448
+ // Remember value start for logging
449
+ char *varValue = dst + strlen(dst);
450
+ if (strcmp(varName, "EXEDIR") == 0) {
451
+ strncat(dst, exePath, pathLen);
452
+ } else if (strcmp(varName, "EXEFILE") == 0) {
453
+ strcat(dst, exePath);
454
+ } else if (strcmp(varName, "PWD") == 0) {
455
+ GetCurrentDirectory(_MAX_PATH, dst + strlen(dst));
456
+ } else if (strcmp(varName, "OLDPWD") == 0) {
457
+ strcat(dst, oldPwd);
458
+ } else if (strstr(varName, HKEY_STR) == varName) {
459
+ regQueryValue(varName, dst + strlen(dst), BIG_STR);
460
+ } else if (GetEnvironmentVariable(varName, varValue, MAX_VAR_SIZE) > 0) {
461
+ strcat(dst, varValue);
462
+ }
463
+ debug("Substitute:\t%s = %s\n", varName, varValue);
464
+ src = end + 1;
465
+ } else {
466
+ // Copy remaining content
467
+ strcat(dst, src);
468
+ break;
469
+ }
470
+ }
471
+ return TRUE;
472
+ }
473
+
474
+ void appendHeapSizes(char *dst) {
475
+ MEMORYSTATUS m;
476
+ memset(&m, 0, sizeof(m));
477
+ GlobalMemoryStatus(&m);
478
+
479
+ appendHeapSize(dst, INITIAL_HEAP_SIZE, INITIAL_HEAP_PERCENT,
480
+ m.dwAvailPhys, "-Xms");
481
+ appendHeapSize(dst, MAX_HEAP_SIZE, MAX_HEAP_PERCENT,
482
+ m.dwAvailPhys, "-Xmx");
483
+ }
484
+
485
+ void appendHeapSize(char *dst, const int absID, const int percentID,
486
+ const DWORD freeMemory, const char *option) {
487
+
488
+ const int mb = 1048576; // 1 MB
489
+ int abs = loadInt(absID);
490
+ int percent = loadInt(percentID);
491
+ int free = (long long) freeMemory * percent / (100 * mb); // 100% * 1 MB
492
+ int size = free > abs ? free : abs;
493
+ if (size > 0) {
494
+ debug("Heap %s:\t%d MB / %d%%, Free: %d MB, Heap size: %d MB\n",
495
+ option, abs, percent, freeMemory / mb, size);
496
+ strcat(dst, option);
497
+ _itoa(size, dst + strlen(dst), 10); // 10 -- radix
498
+ strcat(dst, "m ");
499
+ }
500
+ }
501
+
502
+ int prepare(const char *lpCmdLine) {
503
+ char tmp[MAX_ARGS] = {0};
504
+ hModule = GetModuleHandle(NULL);
505
+ if (hModule == NULL) {
506
+ return FALSE;
507
+ }
508
+
509
+ // Get executable path
510
+ char exePath[_MAX_PATH] = {0};
511
+ int pathLen = getExePath(exePath);
512
+ if (pathLen == -1) {
513
+ return FALSE;
514
+ }
515
+
516
+ // Initialize logging
517
+ if (strstr(lpCmdLine, "--l4j-debug") != NULL) {
518
+ hLog = openLogFile(exePath, pathLen);
519
+ if (hLog == NULL) {
520
+ return FALSE;
521
+ }
522
+ debug("\n\nCmdLine:\t%s %s\n", exePath, lpCmdLine);
523
+ }
524
+
525
+ setWow64Flag();
526
+
527
+ // Set default error message, title and optional support web site url.
528
+ loadString(SUPPORT_URL, errUrl);
529
+ loadString(ERR_TITLE, errTitle);
530
+ if (!loadString(STARTUP_ERR, errMsg)) {
531
+ return FALSE;
532
+ }
533
+
534
+ // Single instance
535
+ loadString(MUTEX_NAME, mutexName);
536
+ if (*mutexName) {
537
+ SECURITY_ATTRIBUTES security;
538
+ security.nLength = sizeof(SECURITY_ATTRIBUTES);
539
+ security.bInheritHandle = TRUE;
540
+ security.lpSecurityDescriptor = NULL;
541
+ CreateMutexA(&security, FALSE, mutexName);
542
+ if (GetLastError() == ERROR_ALREADY_EXISTS) {
543
+ debug("Instance already exists.");
544
+ return ERROR_ALREADY_EXISTS;
545
+ }
546
+ }
547
+
548
+ // Working dir
549
+ char tmp_path[_MAX_PATH] = {0};
550
+ GetCurrentDirectory(_MAX_PATH, oldPwd);
551
+ if (loadString(CHDIR, tmp_path)) {
552
+ strncpy(workingDir, exePath, pathLen);
553
+ appendPath(workingDir, tmp_path);
554
+ _chdir(workingDir);
555
+ debug("Working dir:\t%s\n", workingDir);
556
+ }
557
+
558
+ // Use bundled jre or find java
559
+ if (loadString(JRE_PATH, tmp_path)) {
560
+ char jrePath[MAX_ARGS] = {0};
561
+ expandVars(jrePath, tmp_path, exePath, pathLen);
562
+ debug("Bundled JRE:\t%s\n", jrePath);
563
+ if (jrePath[0] == '\\' || jrePath[1] == ':') {
564
+ // Absolute
565
+ strcpy(cmd, jrePath);
566
+ } else {
567
+ // Relative
568
+ strncpy(cmd, exePath, pathLen);
569
+ appendPath(cmd, jrePath);
570
+ }
571
+ }
572
+ if (!isJrePathOk(cmd)) {
573
+ if (!loadString(JAVA_MIN_VER, javaMinVer)) {
574
+ loadString(BUNDLED_JRE_ERR, errMsg);
575
+ return FALSE;
576
+ }
577
+ loadString(JAVA_MAX_VER, javaMaxVer);
578
+ if (!findJavaHome(cmd, loadInt(JDK_PREFERENCE))) {
579
+ loadString(JRE_VERSION_ERR, errMsg);
580
+ strcat(errMsg, " ");
581
+ strcat(errMsg, javaMinVer);
582
+ if (*javaMaxVer) {
583
+ strcat(errMsg, " - ");
584
+ strcat(errMsg, javaMaxVer);
585
+ }
586
+ loadString(DOWNLOAD_URL, errUrl);
587
+ return FALSE;
588
+ }
589
+ if (!isJrePathOk(cmd)) {
590
+ loadString(LAUNCHER_ERR, errMsg);
591
+ return FALSE;
592
+ }
593
+ }
594
+
595
+ // Append a path to the Path environment variable
596
+ char jreBinPath[_MAX_PATH];
597
+ strcpy(jreBinPath, cmd);
598
+ strcat(jreBinPath, "\\bin");
599
+ if (!appendToPathVar(jreBinPath)) {
600
+ return FALSE;
601
+ }
602
+
603
+ // Set environment variables
604
+ char envVars[MAX_VAR_SIZE] = {0};
605
+ loadString(ENV_VARIABLES, envVars);
606
+ char *var = strtok(envVars, "\t");
607
+ while (var != NULL) {
608
+ char *varValue = strchr(var, '=');
609
+ *varValue++ = 0;
610
+ *tmp = 0;
611
+ expandVars(tmp, varValue, exePath, pathLen);
612
+ debug("Set var:\t%s = %s\n", var, tmp);
613
+ SetEnvironmentVariable(var, tmp);
614
+ var = strtok(NULL, "\t");
615
+ }
616
+ *tmp = 0;
617
+
618
+ // Process priority
619
+ priority = loadInt(PRIORITY_CLASS);
620
+
621
+ // Custom process name
622
+ const BOOL setProcName = loadBool(SET_PROC_NAME)
623
+ && strstr(lpCmdLine, "--l4j-default-proc") == NULL;
624
+ const BOOL wrapper = loadBool(WRAPPER);
625
+
626
+ appendLauncher(setProcName, exePath, pathLen, cmd);
627
+
628
+ // Heap sizes
629
+ appendHeapSizes(args);
630
+
631
+ // JVM options
632
+ if (loadString(JVM_OPTIONS, tmp)) {
633
+ strcat(tmp, " ");
634
+ } else {
635
+ *tmp = 0;
636
+ }
637
+ /*
638
+ * Load additional JVM options from .l4j.ini file
639
+ * Options are separated by spaces or CRLF
640
+ * # starts an inline comment
641
+ */
642
+ strncpy(tmp_path, exePath, strlen(exePath) - 3);
643
+ strcat(tmp_path, "l4j.ini");
644
+ long hFile;
645
+ if ((hFile = _open(tmp_path, _O_RDONLY)) != -1) {
646
+ const int jvmOptLen = strlen(tmp);
647
+ char* src = tmp + jvmOptLen;
648
+ char* dst = src;
649
+ const int len = _read(hFile, src, MAX_ARGS - jvmOptLen - BIG_STR);
650
+ BOOL copy = TRUE;
651
+ int i;
652
+ for (i = 0; i < len; i++, src++) {
653
+ if (*src == '#') {
654
+ copy = FALSE;
655
+ } else if (*src == 13 || *src == 10) {
656
+ copy = TRUE;
657
+ if (dst > tmp && *(dst - 1) != ' ') {
658
+ *dst++ = ' ';
659
+ }
660
+ } else if (copy) {
661
+ *dst++ = *src;
662
+ }
663
+ }
664
+ *dst = 0;
665
+ if (len > 0 && *(dst - 1) != ' ') {
666
+ strcat(tmp, " ");
667
+ }
668
+ _close(hFile);
669
+ }
670
+
671
+ // Expand environment %variables%
672
+ expandVars(args, tmp, exePath, pathLen);
673
+
674
+ // MainClass + Classpath or Jar
675
+ char mainClass[STR] = {0};
676
+ char jar[_MAX_PATH] = {0};
677
+ loadString(JAR, jar);
678
+ if (loadString(MAIN_CLASS, mainClass)) {
679
+ if (!loadString(CLASSPATH, tmp)) {
680
+ return FALSE;
681
+ }
682
+ char exp[MAX_ARGS] = {0};
683
+ expandVars(exp, tmp, exePath, pathLen);
684
+ strcat(args, "-classpath \"");
685
+ if (wrapper) {
686
+ appendAppClasspath(args, exePath, exp);
687
+ } else if (*jar) {
688
+ appendAppClasspath(args, jar, exp);
689
+ }
690
+
691
+ // Deal with wildcards or >> strcat(args, exp); <<
692
+ char* cp = strtok(exp, ";");
693
+ while(cp != NULL) {
694
+ debug("Add classpath:\t%s\n", cp);
695
+ if (strpbrk(cp, "*?") != NULL) {
696
+ int len = strrchr(cp, '\\') - cp + 1;
697
+ strncpy(tmp_path, cp, len);
698
+ char* filename = tmp_path + len;
699
+ *filename = 0;
700
+ struct _finddata_t c_file;
701
+ long hFile;
702
+ if ((hFile = _findfirst(cp, &c_file)) != -1L) {
703
+ do {
704
+ strcpy(filename, c_file.name);
705
+ strcat(args, tmp_path);
706
+ strcat(args, ";");
707
+ debug(" \" :\t%s\n", tmp_path);
708
+ } while (_findnext(hFile, &c_file) == 0);
709
+ }
710
+ _findclose(hFile);
711
+ } else {
712
+ strcat(args, cp);
713
+ strcat(args, ";");
714
+ }
715
+ cp = strtok(NULL, ";");
716
+ }
717
+ *(args + strlen(args) - 1) = 0;
718
+
719
+ strcat(args, "\" ");
720
+ strcat(args, mainClass);
721
+ } else if (wrapper) {
722
+ strcat(args, "-jar \"");
723
+ strcat(args, exePath);
724
+ strcat(args, "\"");
725
+ } else {
726
+ strcat(args, "-jar \"");
727
+ strncat(args, exePath, pathLen);
728
+ appendPath(args, jar);
729
+ strcat(args, "\"");
730
+ }
731
+
732
+ // Constant command line args
733
+ if (loadString(CMD_LINE, tmp)) {
734
+ strcat(args, " ");
735
+ strcat(args, tmp);
736
+ }
737
+
738
+ // Command line args
739
+ if (*lpCmdLine) {
740
+ strcpy(tmp, lpCmdLine);
741
+ char* dst;
742
+ while ((dst = strstr(tmp, "--l4j-")) != NULL) {
743
+ char* src = strchr(dst, ' ');
744
+ if (src == NULL || *(src + 1) == 0) {
745
+ *dst = 0;
746
+ } else {
747
+ strcpy(dst, src + 1);
748
+ }
749
+ }
750
+ if (*tmp) {
751
+ strcat(args, " ");
752
+ strcat(args, tmp);
753
+ }
754
+ }
755
+
756
+ debug("Launcher:\t%s\n", cmd);
757
+ debug("Launcher args:\t%s\n", args);
758
+ debug("Args length:\t%d/32768 chars\n", strlen(args));
759
+ return TRUE;
760
+ }
761
+
762
+ void closeHandles() {
763
+ CloseHandle(pi.hThread);
764
+ CloseHandle(pi.hProcess);
765
+ closeLogFile();
766
+ }
767
+
768
+ /*
769
+ * Append a path to the Path environment variable
770
+ */
771
+ BOOL appendToPathVar(const char* path) {
772
+ char chBuf[MAX_VAR_SIZE] = {0};
773
+
774
+ const int pathSize = GetEnvironmentVariable("Path", chBuf, MAX_VAR_SIZE);
775
+ if (MAX_VAR_SIZE - pathSize - 1 < strlen(path)) {
776
+ return FALSE;
777
+ }
778
+ strcat(chBuf, ";");
779
+ strcat(chBuf, path);
780
+ return SetEnvironmentVariable("Path", chBuf);
781
+ }
782
+
783
+ DWORD execute(const BOOL wait) {
784
+ STARTUPINFO si;
785
+ memset(&pi, 0, sizeof(pi));
786
+ memset(&si, 0, sizeof(si));
787
+ si.cb = sizeof(si);
788
+
789
+ DWORD dwExitCode = -1;
790
+ char cmdline[MAX_ARGS];
791
+ strcpy(cmdline, "\"");
792
+ strcat(cmdline, cmd);
793
+ strcat(cmdline, "\" ");
794
+ strcat(cmdline, args);
795
+ if (CreateProcess(NULL, cmdline, NULL, NULL,
796
+ TRUE, priority, NULL, NULL, &si, &pi)) {
797
+ if (wait) {
798
+ WaitForSingleObject(pi.hProcess, INFINITE);
799
+ GetExitCodeProcess(pi.hProcess, &dwExitCode);
800
+ debug("Exit code:\t%d\n", dwExitCode);
801
+ closeHandles();
802
+ } else {
803
+ dwExitCode = 0;
804
+ }
805
+ }
806
+ return dwExitCode;
807
+ }