1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Importing Processing rev. 5503 (1.0.3).

This commit is contained in:
David A. Mellis
2009-05-31 15:53:33 +00:00
parent 40982627a3
commit 22ed6cdb73
767 changed files with 341874 additions and 0 deletions

View File

@ -0,0 +1,23 @@
Copyright (c) 2004, 2008 Grzegorz Kowal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,33 @@
# Project: consolehead
# Makefile created by Dev-C++ 4.9.9.2
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
RES =
OBJ = ../../head/consolehead.o ../../head/head.o $(RES)
LINKOBJ = ../../head/consolehead.o ../../head/head.o $(RES)
LIBS = -L"C:/Dev-Cpp/lib" -n -s
INCS = -I"C:/Dev-Cpp/include"
CXXINCS = -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
BIN = consolehead.exe
CXXFLAGS = $(CXXINCS) -fexpensive-optimizations -O3
CFLAGS = $(INCS) -fexpensive-optimizations -O3
RM = rm -f
.PHONY: all all-before all-after clean clean-custom
all: all-before consolehead.exe all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
# $(CC) $(LINKOBJ) -o "consolehead.exe" $(LIBS)
../../head/consolehead.o: consolehead.c
$(CC) -c consolehead.c -o ../../head/consolehead.o $(CFLAGS)
../../head/head.o: ../head.c
$(CC) -c ../head.c -o ../../head/head.o $(CFLAGS)

View File

@ -0,0 +1,65 @@
/*
Launch4j (http://launch4j.sourceforge.net/)
Cross-platform Java application wrapper for creating Windows native executables.
Copyright (c) 2004, 2007 Grzegorz Kowal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "../resource.h"
#include "../head.h"
int main(int argc, char* argv[])
{
setConsoleFlag();
LPTSTR cmdLine = GetCommandLine();
if (*cmdLine == '"') {
if (*(cmdLine = strchr(cmdLine + 1, '"') + 1)) {
cmdLine++;
}
} else if ((cmdLine = strchr(cmdLine, ' ')) != NULL) {
cmdLine++;
} else {
cmdLine = "";
}
int result = prepare(cmdLine);
if (result == ERROR_ALREADY_EXISTS) {
char errMsg[BIG_STR] = {0};
loadString(INSTANCE_ALREADY_EXISTS_MSG, errMsg);
msgBox(errMsg);
closeLogFile();
return 2;
}
if (result != TRUE) {
signalError();
return 1;
}
result = (int) execute(TRUE);
if (result == -1) {
signalError();
} else {
return result;
}
}

View File

@ -0,0 +1,108 @@
[Project]
FileName=consolehead.dev
Name=consolehead
UnitCount=4
Type=1
Ver=1
ObjFiles=
Includes=
Libs=
PrivateResource=
ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=
Linker=-n_@@_
IsCpp=0
Icon=
ExeOutput=
ObjectOutput=..\..\head
OverrideOutput=0
OverrideOutputName=consolehead.exe
HostApplication=
Folders=
CommandLine=
UseCustomMakefile=0
CustomMakefile=Makefile.win
IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=0
CompilerSettings=0000000001001000000100
[Unit1]
FileName=consolehead.c
CompileCpp=0
Folder=consolehead
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[VersionInfo]
Major=0
Minor=1
Release=1
Build=1
LanguageID=1033
CharsetID=1252
CompanyName=
FileVersion=
FileDescription=Developed using the Dev-C++ IDE
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=
AutoIncBuildNr=0
[Unit2]
FileName=..\resource.h
CompileCpp=0
Folder=consolehead
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit3]
FileName=..\head.c
CompileCpp=0
Folder=consolehead
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit4]
FileName=..\head.h
CompileCpp=0
Folder=consolehead
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit5]
FileName=..\head.rc
Folder=consolehead
Compile=1
Link=0
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit6]
FileName=..\resid.h
CompileCpp=0
Folder=consolehead
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

View File

@ -0,0 +1,38 @@
# Project: guihead
# Makefile created by Dev-C++ 4.9.9.2
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
RES =
OBJ = ../../head/guihead.o ../../head/head.o $(RES)
LINKOBJ = ../../head/guihead.o ../../head/head.o $(RES)
# removed dev-cpp flags, replacing for cygwin/mingw [fry]
CXXFLAGS = -mwindows -mno-cygwin -O2 -Wall
CFLAGS = -mwindows -mno-cygwin -O2 -Wall
#CFLAGS = -I/cygdrive/c/cygwin/usr/include/mingw
#LIBS = -L"C:/Dev-Cpp/lib" -mwindows -n -s
#INCS = -I"C:/Dev-Cpp/include"
#CXXINCS = -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
BIN = guihead.exe
#CXXFLAGS = $(CXXINCS) -fexpensive-optimizations -O3
#CFLAGS = $(INCS) -fexpensive-optimizations -O3
RM = rm -f
.PHONY: all all-before all-after clean clean-custom
all: all-before guihead.exe all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
# $(CC) $(LINKOBJ) -o "guihead.exe" $(LIBS)
../../head/guihead.o: guihead.c
$(CC) -c guihead.c -o ../../head/guihead.o $(CFLAGS)
../../head/head.o: ../head.c
$(CC) -c ../head.c -o ../../head/head.o $(CFLAGS)

View File

@ -0,0 +1,185 @@
/*
Launch4j (http://launch4j.sourceforge.net/)
Cross-platform Java application wrapper for creating Windows native executables.
Copyright (c) 2004, 2007 Grzegorz Kowal
Sylvain Mina (single instance patch)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "../resource.h"
#include "../head.h"
#include "guihead.h"
extern FILE* hLog;
extern PROCESS_INFORMATION pi;
HWND hWnd;
DWORD dwExitCode = 0;
BOOL stayAlive = FALSE;
BOOL splash = FALSE;
BOOL splashTimeoutErr;
BOOL waitForWindow;
int splashTimeout = DEFAULT_SPLASH_TIMEOUT;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
int result = prepare(lpCmdLine);
if (result == ERROR_ALREADY_EXISTS) {
HWND handle = getInstanceWindow();
ShowWindow(handle, SW_SHOW);
SetForegroundWindow(handle);
closeLogFile();
return 2;
}
if (result != TRUE) {
signalError();
return 1;
}
splash = loadBool(SHOW_SPLASH)
&& strstr(lpCmdLine, "--l4j-no-splash") == NULL;
stayAlive = loadBool(GUI_HEADER_STAYS_ALIVE)
&& strstr(lpCmdLine, "--l4j-dont-wait") == NULL;
if (splash || stayAlive) {
hWnd = CreateWindowEx(WS_EX_TOOLWINDOW, "STATIC", "",
WS_POPUP | SS_BITMAP,
0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (splash) {
char timeout[10] = {0};
if (loadString(SPLASH_TIMEOUT, timeout)) {
splashTimeout = atoi(timeout);
if (splashTimeout <= 0 || splashTimeout > MAX_SPLASH_TIMEOUT) {
splashTimeout = DEFAULT_SPLASH_TIMEOUT;
}
}
splashTimeoutErr = loadBool(SPLASH_TIMEOUT_ERR)
&& strstr(lpCmdLine, "--l4j-no-splash-err") == NULL;
waitForWindow = loadBool(SPLASH_WAITS_FOR_WINDOW);
HANDLE hImage = LoadImage(hInstance, // handle of the instance containing the image
MAKEINTRESOURCE(SPLASH_BITMAP), // name or identifier of image
IMAGE_BITMAP, // type of image
0, // desired width
0, // desired height
LR_DEFAULTSIZE);
if (hImage == NULL) {
signalError();
return 1;
}
SendMessage(hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) hImage);
RECT rect;
GetWindowRect(hWnd, &rect);
int x = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
int y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
SetWindowPos(hWnd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE);
ShowWindow(hWnd, nCmdShow);
UpdateWindow (hWnd);
}
if (!SetTimer (hWnd, ID_TIMER, 1000 /* 1s */, TimerProc)) {
signalError();
return 1;
}
}
if (execute(FALSE) == -1) {
signalError();
return 1;
}
if (!(splash || stayAlive)) {
debug("Exit code:\t0\n");
closeHandles();
return 0;
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
debug("Exit code:\t%d\n", dwExitCode);
closeHandles();
return dwExitCode;
}
HWND getInstanceWindow() {
char windowTitle[STR];
char instWindowTitle[STR] = {0};
if (loadString(INSTANCE_WINDOW_TITLE, instWindowTitle)) {
HWND handle = FindWindowEx(NULL, NULL, NULL, NULL);
while (handle != NULL) {
GetWindowText(handle, windowTitle, STR - 1);
if (strstr(windowTitle, instWindowTitle) != NULL) {
return handle;
} else {
handle = FindWindowEx(NULL, handle, NULL, NULL);
}
}
}
return NULL;
}
BOOL CALLBACK enumwndfn(HWND hwnd, LPARAM lParam) {
DWORD processId;
GetWindowThreadProcessId(hwnd, &processId);
if (pi.dwProcessId == processId) {
LONG styles = GetWindowLong(hwnd, GWL_STYLE);
if ((styles & WS_VISIBLE) != 0) {
splash = FALSE;
ShowWindow(hWnd, SW_HIDE);
return FALSE;
}
}
return TRUE;
}
VOID CALLBACK TimerProc(
HWND hwnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime) { // current system time
if (splash) {
if (splashTimeout == 0) {
splash = FALSE;
ShowWindow(hWnd, SW_HIDE);
if (waitForWindow && splashTimeoutErr) {
KillTimer(hwnd, ID_TIMER);
signalError();
PostQuitMessage(0);
}
} else {
splashTimeout--;
if (waitForWindow) {
EnumWindows(enumwndfn, 0);
}
}
}
GetExitCodeProcess(pi.hProcess, &dwExitCode);
if (dwExitCode != STILL_ACTIVE
|| !(splash || stayAlive)) {
KillTimer(hWnd, ID_TIMER);
PostQuitMessage(0);
}
}

View File

@ -0,0 +1,109 @@
[Project]
FileName=guihead.dev
Name=guihead
UnitCount=5
Type=0
Ver=1
ObjFiles=
Includes=
Libs=
PrivateResource=
ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=
Linker=-n_@@_
IsCpp=0
Icon=
ExeOutput=
ObjectOutput=..\..\head
OverrideOutput=0
OverrideOutputName=guihead.exe
HostApplication=
Folders=
CommandLine=
UseCustomMakefile=1
CustomMakefile=Makefile.win
IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=0
CompilerSettings=0000000001001000000100
[Unit1]
FileName=guihead.c
CompileCpp=0
Folder=guihead
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=$(CC) -c guihead.c -o ../../head/guihead.o $(CFLAGS)
[Unit2]
FileName=guihead.h
CompileCpp=0
Folder=guihead
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[VersionInfo]
Major=0
Minor=1
Release=1
Build=1
LanguageID=1033
CharsetID=1252
CompanyName=
FileVersion=
FileDescription=Developed using the Dev-C++ IDE
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=
AutoIncBuildNr=0
[Unit4]
FileName=..\head.h
CompileCpp=0
Folder=guihead
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit6]
FileName=..\resid.h
CompileCpp=0
Folder=guihead
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit3]
FileName=..\head.c
CompileCpp=0
Folder=guihead
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit5]
FileName=..\resource.h
CompileCpp=0
Folder=guihead
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

View File

@ -0,0 +1,43 @@
/*
Launch4j (http://launch4j.sourceforge.net/)
Cross-platform Java application wrapper for creating Windows native executables.
Copyright (c) 2004, 2007 Grzegorz Kowal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#define ID_TIMER 1
#define DEFAULT_SPLASH_TIMEOUT 60 /* 60 seconds */
#define MAX_SPLASH_TIMEOUT 60 * 15 /* 15 minutes */
HWND getInstanceWindow();
BOOL CALLBACK enumwndfn(HWND hwnd, LPARAM lParam);
VOID CALLBACK TimerProc(
HWND hwnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime // current system time
);

View File

@ -0,0 +1,818 @@
/*
Launch4j (http://launch4j.sourceforge.net/)
Cross-platform Java application wrapper for creating Windows native executables.
Copyright (c) 2004, 2008 Grzegorz Kowal,
Ian Roberts (jdk preference patch)
Sylvain Mina (single instance patch)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "resource.h"
#include "head.h"
HMODULE hModule;
FILE* hLog;
BOOL console = FALSE;
BOOL wow64 = FALSE;
int foundJava = NO_JAVA_FOUND;
struct _stat statBuf;
PROCESS_INFORMATION pi;
DWORD priority;
char mutexName[STR] = {0};
char errUrl[256] = {0};
char errTitle[STR] = "Launch4j";
char errMsg[BIG_STR] = {0};
char javaMinVer[STR] = {0};
char javaMaxVer[STR] = {0};
char foundJavaVer[STR] = {0};
char foundJavaKey[_MAX_PATH] = {0};
char oldPwd[_MAX_PATH] = {0};
char workingDir[_MAX_PATH] = {0};
char cmd[_MAX_PATH] = {0};
char args[MAX_ARGS] = {0};
FILE* openLogFile(const char* exePath, const int pathLen) {
char path[_MAX_PATH] = {0};
strncpy(path, exePath, pathLen);
strcat(path, "\\launch4j.log");
return fopen(path, "a");
}
void closeLogFile() {
if (hLog != NULL) {
fclose(hLog);
}
}
void setWow64Flag() {
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
if (fnIsWow64Process != NULL) {
fnIsWow64Process(GetCurrentProcess(), &wow64);
}
debug("WOW64:\t\t%s\n", wow64 ? "yes" : "no");
}
void setConsoleFlag() {
console = TRUE;
}
void msgBox(const char* text) {
if (console) {
printf("%s: %s\n", errTitle, text);
} else {
MessageBox(NULL, text, errTitle, MB_OK);
}
}
void signalError() {
DWORD err = GetLastError();
if (err) {
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL);
debug("Error:\t\t%s\n", (LPCTSTR) lpMsgBuf);
strcat(errMsg, "\n\n");
strcat(errMsg, (LPCTSTR) lpMsgBuf);
msgBox(errMsg);
LocalFree(lpMsgBuf);
} else {
msgBox(errMsg);
}
if (*errUrl) {
debug("Open URL:\t%s\n", errUrl);
ShellExecute(NULL, "open", errUrl, NULL, NULL, SW_SHOWNORMAL);
}
closeLogFile();
}
BOOL loadString(const int resID, char* buffer) {
HRSRC hResource;
HGLOBAL hResourceLoaded;
LPBYTE lpBuffer;
hResource = FindResourceEx(hModule, RT_RCDATA, MAKEINTRESOURCE(resID),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT));
if (NULL != hResource) {
hResourceLoaded = LoadResource(hModule, hResource);
if (NULL != hResourceLoaded) {
lpBuffer = (LPBYTE) LockResource(hResourceLoaded);
if (NULL != lpBuffer) {
int x = 0;
do {
buffer[x] = (char) lpBuffer[x];
} while (buffer[x++] != 0);
// debug("Resource %d:\t%s\n", resID, buffer);
return TRUE;
}
}
} else {
SetLastError(0);
}
return FALSE;
}
BOOL loadBool(const int resID) {
char boolStr[20] = {0};
loadString(resID, boolStr);
return strcmp(boolStr, TRUE_STR) == 0;
}
int loadInt(const int resID) {
char intStr[20] = {0};
loadString(resID, intStr);
return atoi(intStr);
}
BOOL regQueryValue(const char* regPath, unsigned char* buffer,
unsigned long bufferLength) {
HKEY hRootKey;
char* key;
char* value;
if (strstr(regPath, HKEY_CLASSES_ROOT_STR) == regPath) {
hRootKey = HKEY_CLASSES_ROOT;
} else if (strstr(regPath, HKEY_CURRENT_USER_STR) == regPath) {
hRootKey = HKEY_CURRENT_USER;
} else if (strstr(regPath, HKEY_LOCAL_MACHINE_STR) == regPath) {
hRootKey = HKEY_LOCAL_MACHINE;
} else if (strstr(regPath, HKEY_USERS_STR) == regPath) {
hRootKey = HKEY_USERS;
} else if (strstr(regPath, HKEY_CURRENT_CONFIG_STR) == regPath) {
hRootKey = HKEY_CURRENT_CONFIG;
} else {
return FALSE;
}
key = strchr(regPath, '\\') + 1;
value = strrchr(regPath, '\\') + 1;
*(value - 1) = 0;
HKEY hKey;
unsigned long datatype;
BOOL result = FALSE;
if ((wow64 && RegOpenKeyEx(hRootKey,
key,
0,
KEY_READ | KEY_WOW64_64KEY,
&hKey) == ERROR_SUCCESS)
|| RegOpenKeyEx(hRootKey,
key,
0,
KEY_READ,
&hKey) == ERROR_SUCCESS) {
result = RegQueryValueEx(hKey, value, NULL, &datatype, buffer, &bufferLength)
== ERROR_SUCCESS;
RegCloseKey(hKey);
}
*(value - 1) = '\\';
return result;
}
void regSearch(const HKEY hKey, const char* keyName, const int searchType) {
DWORD x = 0;
unsigned long size = BIG_STR;
FILETIME time;
char buffer[BIG_STR] = {0};
while (RegEnumKeyEx(
hKey, // handle to key to enumerate
x++, // index of subkey to enumerate
buffer, // address of buffer for subkey name
&size, // address for size of subkey buffer
NULL, // reserved
NULL, // address of buffer for class string
NULL, // address for size of class buffer
&time) == ERROR_SUCCESS) {
if (strcmp(buffer, javaMinVer) >= 0
&& (!*javaMaxVer || strcmp(buffer, javaMaxVer) <= 0)
&& strcmp(buffer, foundJavaVer) > 0) {
strcpy(foundJavaVer, buffer);
strcpy(foundJavaKey, keyName);
appendPath(foundJavaKey, buffer);
foundJava = searchType;
debug("Match:\t\t%s\\%s\n", keyName, buffer);
} else {
debug("Ignore:\t\t%s\\%s\n", keyName, buffer);
}
size = BIG_STR;
}
}
void regSearchWow(const char* keyName, const int searchType) {
HKEY hKey;
debug("64-bit search:\t%s...\n", keyName);
if (wow64 && RegOpenKeyEx(HKEY_LOCAL_MACHINE,
keyName,
0,
KEY_READ | KEY_WOW64_64KEY,
&hKey) == ERROR_SUCCESS) {
regSearch(hKey, keyName, searchType | KEY_WOW64_64KEY);
RegCloseKey(hKey);
if ((foundJava & KEY_WOW64_64KEY) != NO_JAVA_FOUND)
{
debug("Using 64-bit runtime.\n");
return;
}
}
debug("32-bit search:\t%s...\n", keyName);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
keyName,
0,
KEY_READ,
&hKey) == ERROR_SUCCESS) {
regSearch(hKey, keyName, searchType);
RegCloseKey(hKey);
}
}
void regSearchJreSdk(const char* jreKeyName, const char* sdkKeyName,
const int jdkPreference) {
if (jdkPreference == JDK_ONLY || jdkPreference == PREFER_JDK) {
regSearchWow(sdkKeyName, FOUND_SDK);
if (jdkPreference != JDK_ONLY) {
regSearchWow(jreKeyName, FOUND_JRE);
}
} else { // jdkPreference == JRE_ONLY or PREFER_JRE
regSearchWow(jreKeyName, FOUND_JRE);
if (jdkPreference != JRE_ONLY) {
regSearchWow(sdkKeyName, FOUND_SDK);
}
}
}
BOOL findJavaHome(char* path, const int jdkPreference) {
regSearchJreSdk("SOFTWARE\\JavaSoft\\Java Runtime Environment",
"SOFTWARE\\JavaSoft\\Java Development Kit",
jdkPreference);
if (foundJava == NO_JAVA_FOUND) {
regSearchJreSdk("SOFTWARE\\IBM\\Java2 Runtime Environment",
"SOFTWARE\\IBM\\Java Development Kit",
jdkPreference);
}
if (foundJava != NO_JAVA_FOUND) {
HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
foundJavaKey,
0,
KEY_READ | (foundJava & KEY_WOW64_64KEY),
&hKey) == ERROR_SUCCESS) {
unsigned char buffer[BIG_STR] = {0};
unsigned long bufferlength = BIG_STR;
unsigned long datatype;
if (RegQueryValueEx(hKey, "JavaHome", NULL, &datatype, buffer,
&bufferlength) == ERROR_SUCCESS) {
int i = 0;
do {
path[i] = buffer[i];
} while (path[i++] != 0);
// (foundJava & FOUND_SDK) { // removed by fry
// appendPath(path, "jre");
//
RegCloseKey(hKey);
return TRUE;
}
RegCloseKey(hKey);
}
}
return FALSE;
}
/*
* Extract the executable name, returns path length.
*/
int getExePath(char* exePath) {
if (GetModuleFileName(hModule, exePath, _MAX_PATH) == 0) {
return -1;
}
return strrchr(exePath, '\\') - exePath;
}
void appendPath(char* basepath, const char* path) {
if (basepath[strlen(basepath) - 1] != '\\') {
strcat(basepath, "\\");
}
strcat(basepath, path);
}
void appendJavaw(char* jrePath) {
if (console) {
appendPath(jrePath, "bin\\java.exe");
} else {
appendPath(jrePath, "bin\\javaw.exe");
}
}
void appendLauncher(const BOOL setProcName, char* exePath,
const int pathLen, char* cmd) {
if (setProcName) {
char tmpspec[_MAX_PATH];
char tmpfile[_MAX_PATH];
strcpy(tmpspec, cmd);
strcat(tmpspec, LAUNCH4J_TMP_DIR);
tmpspec[strlen(tmpspec) - 1] = 0;
if (_stat(tmpspec, &statBuf) == 0) {
// Remove temp launchers and manifests
struct _finddata_t c_file;
long hFile;
appendPath(tmpspec, "*.exe");
strcpy(tmpfile, cmd);
strcat(tmpfile, LAUNCH4J_TMP_DIR);
char* filename = tmpfile + strlen(tmpfile);
if ((hFile = _findfirst(tmpspec, &c_file)) != -1L) {
do {
strcpy(filename, c_file.name);
debug("Unlink:\t\t%s\n", tmpfile);
_unlink(tmpfile);
strcat(tmpfile, MANIFEST);
debug("Unlink:\t\t%s\n", tmpfile);
_unlink(tmpfile);
} while (_findnext(hFile, &c_file) == 0);
}
_findclose(hFile);
} else {
if (_mkdir(tmpspec) != 0) {
debug("Mkdir failed:\t%s\n", tmpspec);
appendJavaw(cmd);
return;
}
}
char javaw[_MAX_PATH];
strcpy(javaw, cmd);
appendJavaw(javaw);
strcpy(tmpfile, cmd);
strcat(tmpfile, LAUNCH4J_TMP_DIR);
char* tmpfilename = tmpfile + strlen(tmpfile);
char* exeFilePart = exePath + pathLen + 1;
// Copy manifest
char manifest[_MAX_PATH] = {0};
strcpy(manifest, exePath);
strcat(manifest, MANIFEST);
if (_stat(manifest, &statBuf) == 0) {
strcat(tmpfile, exeFilePart);
strcat(tmpfile, MANIFEST);
debug("Copy:\t\t%s -> %s\n", manifest, tmpfile);
CopyFile(manifest, tmpfile, FALSE);
}
// Copy launcher
strcpy(tmpfilename, exeFilePart);
debug("Copy:\t\t%s -> %s\n", javaw, tmpfile);
if (CopyFile(javaw, tmpfile, FALSE)) {
strcpy(cmd, tmpfile);
return;
} else if (_stat(javaw, &statBuf) == 0) {
long fs = statBuf.st_size;
if (_stat(tmpfile, &statBuf) == 0 && fs == statBuf.st_size) {
debug("Reusing:\t\t%s\n", tmpfile);
strcpy(cmd, tmpfile);
return;
}
}
}
appendJavaw(cmd);
}
void appendAppClasspath(char* dst, const char* src, const char* classpath) {
strcat(dst, src);
if (*classpath) {
strcat(dst, ";");
}
}
BOOL isJrePathOk(const char* path) {
char javaw[_MAX_PATH];
BOOL result = FALSE;
if (*path) {
strcpy(javaw, path);
appendJavaw(javaw);
result = _stat(javaw, &statBuf) == 0;
}
debug("Check launcher:\t%s %s\n", javaw, result ? "(OK)" : "(n/a)");
return result;
}
/*
* Expand environment %variables%
*/
BOOL expandVars(char *dst, const char *src, const char *exePath, const int pathLen) {
char varName[STR];
char varValue[MAX_VAR_SIZE];
while (strlen(src) > 0) {
char *start = strchr(src, '%');
if (start != NULL) {
char *end = strchr(start + 1, '%');
if (end == NULL) {
return FALSE;
}
// Copy content up to %VAR%
strncat(dst, src, start - src);
// Insert value of %VAR%
*varName = 0;
strncat(varName, start + 1, end - start - 1);
// Remember value start for logging
char *varValue = dst + strlen(dst);
if (strcmp(varName, "EXEDIR") == 0) {
strncat(dst, exePath, pathLen);
} else if (strcmp(varName, "EXEFILE") == 0) {
strcat(dst, exePath);
} else if (strcmp(varName, "PWD") == 0) {
GetCurrentDirectory(_MAX_PATH, dst + strlen(dst));
} else if (strcmp(varName, "OLDPWD") == 0) {
strcat(dst, oldPwd);
} else if (strstr(varName, HKEY_STR) == varName) {
regQueryValue(varName, dst + strlen(dst), BIG_STR);
} else if (GetEnvironmentVariable(varName, varValue, MAX_VAR_SIZE) > 0) {
strcat(dst, varValue);
}
debug("Substitute:\t%s = %s\n", varName, varValue);
src = end + 1;
} else {
// Copy remaining content
strcat(dst, src);
break;
}
}
return TRUE;
}
void appendHeapSizes(char *dst) {
MEMORYSTATUS m;
memset(&m, 0, sizeof(m));
GlobalMemoryStatus(&m);
appendHeapSize(dst, INITIAL_HEAP_SIZE, INITIAL_HEAP_PERCENT,
m.dwAvailPhys, "-Xms");
appendHeapSize(dst, MAX_HEAP_SIZE, MAX_HEAP_PERCENT,
m.dwAvailPhys, "-Xmx");
}
void appendHeapSize(char *dst, const int absID, const int percentID,
const DWORD freeMemory, const char *option) {
const int mb = 1048576; // 1 MB
int abs = loadInt(absID);
int percent = loadInt(percentID);
int free = (long long) freeMemory * percent / (100 * mb); // 100% * 1 MB
int size = free > abs ? free : abs;
if (size > 0) {
debug("Heap %s:\t%d MB / %d%%, Free: %d MB, Heap size: %d MB\n",
option, abs, percent, freeMemory / mb, size);
strcat(dst, option);
_itoa(size, dst + strlen(dst), 10); // 10 -- radix
strcat(dst, "m ");
}
}
int prepare(const char *lpCmdLine) {
char tmp[MAX_ARGS] = {0};
hModule = GetModuleHandle(NULL);
if (hModule == NULL) {
return FALSE;
}
// Get executable path
char exePath[_MAX_PATH] = {0};
int pathLen = getExePath(exePath);
if (pathLen == -1) {
return FALSE;
}
// Initialize logging
if (strstr(lpCmdLine, "--l4j-debug") != NULL) {
hLog = openLogFile(exePath, pathLen);
if (hLog == NULL) {
return FALSE;
}
debug("\n\nCmdLine:\t%s %s\n", exePath, lpCmdLine);
}
setWow64Flag();
// Set default error message, title and optional support web site url.
loadString(SUPPORT_URL, errUrl);
loadString(ERR_TITLE, errTitle);
if (!loadString(STARTUP_ERR, errMsg)) {
return FALSE;
}
// Single instance
loadString(MUTEX_NAME, mutexName);
if (*mutexName) {
SECURITY_ATTRIBUTES security;
security.nLength = sizeof(SECURITY_ATTRIBUTES);
security.bInheritHandle = TRUE;
security.lpSecurityDescriptor = NULL;
CreateMutexA(&security, FALSE, mutexName);
if (GetLastError() == ERROR_ALREADY_EXISTS) {
debug("Instance already exists.");
return ERROR_ALREADY_EXISTS;
}
}
// Working dir
char tmp_path[_MAX_PATH] = {0};
GetCurrentDirectory(_MAX_PATH, oldPwd);
if (loadString(CHDIR, tmp_path)) {
strncpy(workingDir, exePath, pathLen);
appendPath(workingDir, tmp_path);
_chdir(workingDir);
debug("Working dir:\t%s\n", workingDir);
}
// Use bundled jre or find java
if (loadString(JRE_PATH, tmp_path)) {
char jrePath[MAX_ARGS] = {0};
expandVars(jrePath, tmp_path, exePath, pathLen);
debug("Bundled JRE:\t%s\n", jrePath);
if (jrePath[0] == '\\' || jrePath[1] == ':') {
// Absolute
strcpy(cmd, jrePath);
} else {
// Relative
strncpy(cmd, exePath, pathLen);
appendPath(cmd, jrePath);
}
}
if (!isJrePathOk(cmd)) {
if (!loadString(JAVA_MIN_VER, javaMinVer)) {
loadString(BUNDLED_JRE_ERR, errMsg);
return FALSE;
}
loadString(JAVA_MAX_VER, javaMaxVer);
if (!findJavaHome(cmd, loadInt(JDK_PREFERENCE))) {
loadString(JRE_VERSION_ERR, errMsg);
strcat(errMsg, " ");
strcat(errMsg, javaMinVer);
if (*javaMaxVer) {
strcat(errMsg, " - ");
strcat(errMsg, javaMaxVer);
}
loadString(DOWNLOAD_URL, errUrl);
return FALSE;
}
if (!isJrePathOk(cmd)) {
loadString(LAUNCHER_ERR, errMsg);
return FALSE;
}
}
// Append a path to the Path environment variable
char jreBinPath[_MAX_PATH];
strcpy(jreBinPath, cmd);
strcat(jreBinPath, "\\bin");
if (!appendToPathVar(jreBinPath)) {
return FALSE;
}
// Set environment variables
char envVars[MAX_VAR_SIZE] = {0};
loadString(ENV_VARIABLES, envVars);
char *var = strtok(envVars, "\t");
while (var != NULL) {
char *varValue = strchr(var, '=');
*varValue++ = 0;
*tmp = 0;
expandVars(tmp, varValue, exePath, pathLen);
debug("Set var:\t%s = %s\n", var, tmp);
SetEnvironmentVariable(var, tmp);
var = strtok(NULL, "\t");
}
*tmp = 0;
// Process priority
priority = loadInt(PRIORITY_CLASS);
// Custom process name
const BOOL setProcName = loadBool(SET_PROC_NAME)
&& strstr(lpCmdLine, "--l4j-default-proc") == NULL;
const BOOL wrapper = loadBool(WRAPPER);
char jdk_path[_MAX_PATH] = {0}; // fry
strcpy(jdk_path, cmd);
//msgBox(jdk_path);
appendLauncher(setProcName, exePath, pathLen, cmd);
// Heap sizes
appendHeapSizes(args);
// JVM options
if (loadString(JVM_OPTIONS, tmp)) {
strcat(tmp, " ");
} else {
*tmp = 0;
}
/*
* Load additional JVM options from .l4j.ini file
* Options are separated by spaces or CRLF
* # starts an inline comment
*/
strncpy(tmp_path, exePath, strlen(exePath) - 3);
strcat(tmp_path, "l4j.ini");
long hFile;
if ((hFile = _open(tmp_path, _O_RDONLY)) != -1) {
const int jvmOptLen = strlen(tmp);
char* src = tmp + jvmOptLen;
char* dst = src;
const int len = _read(hFile, src, MAX_ARGS - jvmOptLen - BIG_STR);
BOOL copy = TRUE;
int i;
for (i = 0; i < len; i++, src++) {
if (*src == '#') {
copy = FALSE;
} else if (*src == 13 || *src == 10) {
copy = TRUE;
if (dst > tmp && *(dst - 1) != ' ') {
*dst++ = ' ';
}
} else if (copy) {
*dst++ = *src;
}
}
*dst = 0;
if (len > 0 && *(dst - 1) != ' ') {
strcat(tmp, " ");
}
_close(hFile);
}
// Expand environment %variables%
expandVars(args, tmp, exePath, pathLen);
// MainClass + Classpath or Jar
char mainClass[STR] = {0};
char jar[_MAX_PATH] = {0};
loadString(JAR, jar);
if (loadString(MAIN_CLASS, mainClass)) {
if (!loadString(CLASSPATH, tmp)) {
return FALSE;
}
char exp[MAX_ARGS] = {0};
expandVars(exp, tmp, exePath, pathLen);
strcat(args, "-classpath \"");
if (wrapper) {
appendAppClasspath(args, exePath, exp);
} else if (*jar) {
appendAppClasspath(args, jar, exp);
}
// add tools.jar for JDK [fry]
char tools[_MAX_PATH] = { 0 };
sprintf(tools, "%s\\lib\\tools.jar", jdk_path);
appendAppClasspath(args, tools, exp);
// Deal with wildcards or >> strcat(args, exp); <<
char* cp = strtok(exp, ";");
while(cp != NULL) {
debug("Add classpath:\t%s\n", cp);
if (strpbrk(cp, "*?") != NULL) {
int len = strrchr(cp, '\\') - cp + 1;
strncpy(tmp_path, cp, len);
char* filename = tmp_path + len;
*filename = 0;
struct _finddata_t c_file;
long hFile;
if ((hFile = _findfirst(cp, &c_file)) != -1L) {
do {
strcpy(filename, c_file.name);
strcat(args, tmp_path);
strcat(args, ";");
debug(" \" :\t%s\n", tmp_path);
} while (_findnext(hFile, &c_file) == 0);
}
_findclose(hFile);
} else {
strcat(args, cp);
strcat(args, ";");
}
cp = strtok(NULL, ";");
}
*(args + strlen(args) - 1) = 0;
strcat(args, "\" ");
strcat(args, mainClass);
} else if (wrapper) {
strcat(args, "-jar \"");
strcat(args, exePath);
strcat(args, "\"");
} else {
strcat(args, "-jar \"");
strncat(args, exePath, pathLen);
appendPath(args, jar);
strcat(args, "\"");
}
// Constant command line args
if (loadString(CMD_LINE, tmp)) {
strcat(args, " ");
strcat(args, tmp);
}
// Command line args
if (*lpCmdLine) {
strcpy(tmp, lpCmdLine);
char* dst;
while ((dst = strstr(tmp, "--l4j-")) != NULL) {
char* src = strchr(dst, ' ');
if (src == NULL || *(src + 1) == 0) {
*dst = 0;
} else {
strcpy(dst, src + 1);
}
}
if (*tmp) {
strcat(args, " ");
strcat(args, tmp);
}
}
debug("Launcher:\t%s\n", cmd);
debug("Launcher args:\t%s\n", args);
debug("Args length:\t%d/32768 chars\n", strlen(args));
return TRUE;
}
void closeHandles() {
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
closeLogFile();
}
/*
* Append a path to the Path environment variable
*/
BOOL appendToPathVar(const char* path) {
char chBuf[MAX_VAR_SIZE] = {0};
const int pathSize = GetEnvironmentVariable("Path", chBuf, MAX_VAR_SIZE);
if (MAX_VAR_SIZE - pathSize - 1 < strlen(path)) {
return FALSE;
}
strcat(chBuf, ";");
strcat(chBuf, path);
return SetEnvironmentVariable("Path", chBuf);
}
// may need to ignore STILL_ACTIVE (error code 259) here
// http://msdn.microsoft.com/en-us/library/ms683189(VS.85).aspx
DWORD execute(const BOOL wait) {
STARTUPINFO si;
memset(&pi, 0, sizeof(pi));
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
DWORD dwExitCode = -1;
char cmdline[MAX_ARGS];
strcpy(cmdline, "\"");
strcat(cmdline, cmd);
strcat(cmdline, "\" ");
strcat(cmdline, args);
if (CreateProcess(NULL, cmdline, NULL, NULL,
TRUE, priority, NULL, NULL, &si, &pi)) {
if (wait) {
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &dwExitCode);
debug("Exit code:\t%d\n", dwExitCode);
closeHandles();
} else {
dwExitCode = 0;
}
}
return dwExitCode;
}

View File

@ -0,0 +1,113 @@
/*
Launch4j (http://launch4j.sourceforge.net/)
Cross-platform Java application wrapper for creating Windows native executables.
Copyright (c) 2004, 2008 Grzegorz Kowal,
Ian Roberts (jdk preference patch)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef _LAUNCH4J_HEAD__INCLUDED_
#define _LAUNCH4J_HEAD__INCLUDED_
#define WIN32_LEAN_AND_MEAN // VC - Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <shellapi.h>
#include <direct.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <io.h>
#include <process.h>
#define NO_JAVA_FOUND 0
#define FOUND_JRE 1
#define FOUND_SDK 2
#define JRE_ONLY 0
#define PREFER_JRE 1
#define PREFER_JDK 2
#define JDK_ONLY 3
#define LAUNCH4J_TMP_DIR "\\launch4j-tmp\\"
#define MANIFEST ".manifest"
#define KEY_WOW64_64KEY 0x0100
#define HKEY_STR "HKEY"
#define HKEY_CLASSES_ROOT_STR "HKEY_CLASSES_ROOT"
#define HKEY_CURRENT_USER_STR "HKEY_CURRENT_USER"
#define HKEY_LOCAL_MACHINE_STR "HKEY_LOCAL_MACHINE"
#define HKEY_USERS_STR "HKEY_USERS"
#define HKEY_CURRENT_CONFIG_STR "HKEY_CURRENT_CONFIG"
#define STR 128
#define BIG_STR 1024
#define MAX_VAR_SIZE 32767
#define MAX_ARGS 32768
#define TRUE_STR "true"
#define FALSE_STR "false"
#define debug(args...) if (hLog != NULL) fprintf(hLog, ## args);
typedef void (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
FILE* openLogFile(const char* exePath, const int pathLen);
void closeLogFile();
void msgBox(const char* text);
void signalError();
BOOL loadString(const int resID, char* buffer);
BOOL loadBool(const int resID);
int loadInt(const int resID);
BOOL regQueryValue(const char* regPath, unsigned char* buffer,
unsigned long bufferLength);
void regSearch(const HKEY hKey, const char* keyName, const int searchType);
void regSearchWow(const char* keyName, const int searchType);
void regSearchJreSdk(const char* jreKeyName, const char* sdkKeyName,
const int jdkPreference);
BOOL findJavaHome(char* path, const int jdkPreference);
int getExePath(char* exePath);
void appendPath(char* basepath, const char* path);
void appendJavaw(char* jrePath);
void appendAppClasspath(char* dst, const char* src, const char* classpath);
BOOL isJrePathOk(const char* path);
BOOL expandVars(char *dst, const char *src, const char *exePath, const int pathLen);
void appendHeapSizes(char *dst);
void appendHeapSize(char *dst, const int absID, const int percentID,
const DWORD freeMemory, const char *option);
int prepare(const char *lpCmdLine);
void closeHandles();
BOOL appendToPathVar(const char* path);
DWORD execute(const BOOL wait);
#endif // _LAUNCH4J_HEAD__INCLUDED_

View File

@ -0,0 +1,71 @@
/*
Launch4j (http://launch4j.sourceforge.net/)
Cross-platform Java application wrapper for creating Windows native executables.
Copyright (c) 2004, 2008 Grzegorz Kowal
Ian Roberts (jdk preference patch)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// ICON
#define APP_ICON 1
// BITMAP
#define SPLASH_BITMAP 1
// RCDATA
#define JRE_PATH 1
#define JAVA_MIN_VER 2
#define JAVA_MAX_VER 3
#define SHOW_SPLASH 4
#define SPLASH_WAITS_FOR_WINDOW 5
#define SPLASH_TIMEOUT 6
#define SPLASH_TIMEOUT_ERR 7
#define CHDIR 8
#define SET_PROC_NAME 9
#define ERR_TITLE 10
#define GUI_HEADER_STAYS_ALIVE 11
#define JVM_OPTIONS 12
#define CMD_LINE 13
#define JAR 14
#define MAIN_CLASS 15
#define CLASSPATH 16
#define WRAPPER 17
#define JDK_PREFERENCE 18
#define ENV_VARIABLES 19
#define PRIORITY_CLASS 20
#define DOWNLOAD_URL 21
#define SUPPORT_URL 22
#define MUTEX_NAME 23
#define INSTANCE_WINDOW_TITLE 24
#define INITIAL_HEAP_SIZE 25
#define INITIAL_HEAP_PERCENT 26
#define MAX_HEAP_SIZE 27
#define MAX_HEAP_PERCENT 28
#define STARTUP_ERR 101
#define BUNDLED_JRE_ERR 102
#define JRE_VERSION_ERR 103
#define LAUNCHER_ERR 104
#define INSTANCE_ALREADY_EXISTS_MSG 105