Skip to content

Commit b5ef230

Browse files
committed
launcher work
1 parent c981c5d commit b5ef230

File tree

3 files changed

+32
-125
lines changed

3 files changed

+32
-125
lines changed
27.3 KB
Binary file not shown.

build/windows/export/launcher.cpp

Lines changed: 32 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
22

3-
// if this code looks shitty, that's because it is. people are likely to have
4-
// the durndest things in their CLASSPATH and QTJAVA environment variables.
3+
// if this code looks shitty, that's because it is. people are likely
4+
// to have the durndest things in their CLASSPATH environment variable.
55
// mostly because installers often mangle them without the user knowing.
66
// so who knows where and when the quotes will show up. the code below is
77
// based on a couple years of trial and error with processing releases.
@@ -12,6 +12,11 @@
1212
// or directories) are also stripped out before being set.
1313
// (<A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=112">Bug 112</A>)
1414

15+
// For revision 0201 (love that symmetry), the 'lib' folder was added to
16+
// the java.library.path, so that we can hide the pile of DLLs included
17+
// with some libraries (I'm looking at you, video), inside the lib folder.
18+
// QTJAVA mess was also excised, now that we're switching to gstreamer.
19+
1520
// The size of all of the strings was made sort of ambiguously large, since
1621
// 1) nothing is hurt by allocating an extra few bytes temporarily and
1722
// 2) if the user has a long path, and it gets copied five times over for the
@@ -36,6 +41,8 @@ char *mallocChars(int count);
3641
void removeQuotes(char *quoted);
3742
void removeTrailingSlash(char *slashed);
3843

44+
#define DEBUG
45+
3946
int STDCALL
4047
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
4148
{
@@ -73,18 +80,6 @@ WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
7380
exe_directory);
7481
MessageBox(NULL, app_classpath, "Folder Missing", MB_OK);
7582
return 0;
76-
/*
77-
sprintf(app_classpath,
78-
"%s\\lib;"
79-
"%s\\lib\\pde.jar;"
80-
"%s\\lib\\core.jar;"
81-
"%s\\lib\\jna.jar;"
82-
"%s\\lib\\ecj.jar;"
83-
"%s\\lib\\antlr.jar;",
84-
exe_directory,
85-
exe_directory, exe_directory,
86-
exe_directory, exe_directory, exe_directory);
87-
*/
8883

8984
} else {
9085
fgets(java_args, 511, argsfile);
@@ -94,9 +89,11 @@ WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
9489
fgets(jar_list, 511, argsfile);
9590
removeLineEndings(jar_list);
9691

97-
//MessageBox(NULL, java_args, "args", MB_OK);
98-
//MessageBox(NULL, java_main_class, "class", MB_OK);
99-
//MessageBox(NULL, jar_list, "jarlist", MB_OK);
92+
#ifdef DEBUG
93+
MessageBox(NULL, java_args, "args", MB_OK);
94+
MessageBox(NULL, java_main_class, "class", MB_OK);
95+
MessageBox(NULL, jar_list, "jarlist", MB_OK);
96+
#endif
10097

10198
app_classpath[0] = 0;
10299
char *jar = (char*) strtok(jar_list, ",");
@@ -120,8 +117,7 @@ WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
120117
strcat(testpath, "\\java\\bin\\java.exe");
121118
FILE *fp = fopen(testpath, "rb");
122119
int local_jre_installed = (fp != NULL);
123-
//char *rt_jar = (fp == NULL) ? "" : "java\\lib\\rt.jar;";
124-
if (fp != NULL) fclose(fp); // argh! this was probably causing trouble
120+
if (fp != NULL) fclose(fp);
125121

126122
//const char *envClasspath = getenv("CLASSPATH");
127123
//char *env_classpath = (char *)malloc(16384 * sizeof(char));
@@ -130,100 +126,6 @@ WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
130126
// and causes more trouble than it's worth [0060]
131127
//env_classpath[0] = 0;
132128

133-
/*
134-
// keep this code around since may be re-enabled later
135-
if (getenv("CLASSPATH") != NULL) {
136-
strcpy(env_classpath, getenv("CLASSPATH"));
137-
if (env_classpath[0] == '\"') {
138-
// starting quote in classpath.. yech
139-
env_classpath++; // shitty.. i know..
140-
141-
int len = strlen(env_classpath);
142-
if (env_classpath[len-1] == '\"') {
143-
env_classpath[len-1] = 0;
144-
} else {
145-
// a starting quote but no ending quote.. ugh
146-
// maybe throw an error
147-
}
148-
}
149-
int last = strlen(env_classpath);
150-
env_classpath[last++] = ';';
151-
env_classpath[last] = 0;
152-
} else {
153-
env_classpath[0] = 0;
154-
}
155-
*/
156-
157-
char *qtjava_path = (char *)malloc(16384 * sizeof(char));
158-
qtjava_path[0] = 0;
159-
160-
if (getenv("QTJAVA") != NULL) {
161-
//char *qtjava_temp = (char *)malloc(16384 * sizeof(char));
162-
strcpy(qtjava_path, getenv("QTJAVA"));
163-
removeQuotes(qtjava_path);
164-
165-
/*
166-
//MessageBox(NULL, qtjava_temp, "QTJAVA", MB_OK);
167-
if (qtjava_temp[0] == '\"') { // has quotes
168-
// remove quotes by subsetting string by two
169-
int qtjava_repaired_length = strlen(qtjava_temp) - 2;
170-
strncpy(qtjava_path, &qtjava_temp[1], qtjava_repaired_length);
171-
// terminate the string since strncpy ain't gonna do it
172-
qtjava_path[qtjava_repaired_length] = 0;
173-
//MessageBox(NULL, qtjava_path, "QTJAVA", MB_OK);
174-
} else {
175-
strcpy(qtjava_path, getenv("QTJAVA"));
176-
}
177-
*/
178-
179-
FILE *fp = fopen(qtjava_path, "rb");
180-
if (fp != NULL) {
181-
fclose(fp); // found it, all set
182-
strcat(qtjava_path, ";"); // add path separator
183-
//MessageBox(NULL, "found 1", "msg", MB_OK);
184-
//MessageBox(NULL, qtjava_path, "QTJAVA after strcat", MB_OK);
185-
} else {
186-
qtjava_path[0] = 0; // not a valid path
187-
}
188-
//} else {
189-
//MessageBox(NULL, "no qtjava set", "mess", MB_OK);
190-
}
191-
192-
if (qtjava_path[0] == 0) { // not set yet
193-
//if (getenv("WINDIR") == NULL) {
194-
// uh-oh.. serious problem.. gonna have to report this
195-
// but hopefully WINDIR is set on win98 too
196-
//} else {
197-
198-
strcpy(qtjava_path, getenv("WINDIR"));
199-
strcat(qtjava_path, "\\SYSTEM32\\QTJava.zip");
200-
201-
FILE *fp = fopen(qtjava_path, "rb");
202-
if (fp != NULL) {
203-
fclose(fp); // found it, all set
204-
strcat(qtjava_path, ";"); // add path separator
205-
//MessageBox(NULL, "found 2", "msg", MB_OK);
206-
} else {
207-
qtjava_path[0] = 0; // not a valid path
208-
}
209-
}
210-
211-
if (qtjava_path[0] == 0) {
212-
strcpy(qtjava_path, getenv("WINDIR"));
213-
strcat(qtjava_path, "\\SYSTEM\\QTJava.zip");
214-
215-
fp = fopen(qtjava_path, "rb");
216-
if (fp != NULL) {
217-
fclose(fp); // found it, all set
218-
strcat(qtjava_path, ";"); // add path separator
219-
//MessageBox(NULL, "found 3", "msg", MB_OK);
220-
} else {
221-
// doesn't seem to be installed, which is a problem.
222-
// but the error will be reported by the pde
223-
qtjava_path[0] = 0;
224-
}
225-
}
226-
227129
// don't put quotes around contents of cp, even though %s might have
228130
// spaces in it. don't put quotes in it, because it's setting the
229131
// environment variable for CLASSPATH, not being included on the
@@ -236,19 +138,18 @@ WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
236138
sprintf(local_jre, "%s\\java\\lib\\rt.jar;%s\\java\\lib\\tools.jar;", exe_directory, exe_directory);
237139
strcat(cp, local_jre);
238140
}
239-
strcat(cp, qtjava_path);
240141

241142
char *clean_cp = scrubPath(cp);
242143
//if (!SetEnvironmentVariable("CLASSPATH", cp)) {
243144
if (!SetEnvironmentVariable("CLASSPATH", clean_cp)) {
244145
MessageBox(NULL, "Could not set CLASSPATH environment variable",
245146
"Processing Error", MB_OK);
246-
return 0;
147+
return 1;
247148
}
248149

249-
//MessageBox(NULL, "2", "checking", MB_OK);
250-
251-
//char *env_path = (char *)malloc(strlen(getenv("PATH")) * sizeof(char));
150+
#ifdef DEBUG
151+
MessageBox(NULL, "done with classpath cleaning", "2", MB_OK);
152+
#endif
252153

253154
int env_path_length = strlen(getenv("PATH"));
254155
char *env_path = mallocChars(env_path_length);
@@ -300,18 +201,23 @@ WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
300201
// exe_directory is the name path to the current application
301202

302203
if (local_jre_installed) {
303-
//strcpy(executable, exe_directory);
204+
strcpy(executable, exe_directory);
304205
// copy in the path for javaw, relative to launcher.exe
305-
//strcat(executable, "\\java\\bin\\javaw.exe");
306-
sprintf(executable, "%s\\java\\bin\\javaw.exe", exe_directory);
206+
strcat(executable, "\\java\\bin\\javaw.exe");
307207
} else {
208+
#ifdef DEBUG
209+
strcpy(executable, "java.exe");
210+
#else
308211
strcpy(executable, "javaw.exe");
212+
#endif
309213
}
310214

311215
/*
312216
SHELLEXECUTEINFO ShExecInfo;
313217
314-
//MessageBox(NULL, executable, outgoing_cmd_line, MB_OK);
218+
#ifdef DEBUG
219+
MessageBox(NULL, outgoing_cmd_line, executable, MB_OK);
220+
#endif
315221
316222
// set up the execution info
317223
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
@@ -364,7 +270,7 @@ WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
364270
si.cb = sizeof(si);
365271
int wait = 0;
366272

367-
DWORD dwExitCode = -1;
273+
DWORD dwExitCode = (DWORD) -1;
368274
char cmdline[32768];
369275
//executable;
370276
//outgoing_cmd_line;
@@ -383,8 +289,9 @@ WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
383289
GetExitCodeProcess(pi.hProcess, &dwExitCode);
384290
//debug("Exit code:\t%d\n", dwExitCode);
385291
//closeHandles();
386-
char[128] big_trouble;
387-
sprintf(big_trouble, "Sorry, could not launch. (Error %d)", dwExitCode);
292+
char big_trouble[128];
293+
sprintf(big_trouble, "Sorry, could not launch. (Error %d)",
294+
(int) dwExitCode);
388295
MessageBox(NULL, big_trouble, "Apologies", MB_OK);
389296
} else {
390297
dwExitCode = 0;

java/application/template.exe

27.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)