1 | #include <windows.h>
|
---|
2 |
|
---|
3 | #include <fstream>
|
---|
4 | #include <iostream>
|
---|
5 |
|
---|
6 | using namespace std;
|
---|
7 |
|
---|
8 | void WriteUsingStream(BYTE* pBytes, int nCount, char* filename)
|
---|
9 | {
|
---|
10 | ofstream fStream(filename, ios::binary | ios::out);
|
---|
11 |
|
---|
12 | fStream.write((char*) pBytes, nCount);
|
---|
13 | fStream.close();
|
---|
14 | }
|
---|
15 |
|
---|
16 | void main()
|
---|
17 | {
|
---|
18 | HMODULE hModule = GetModuleHandle(NULL);
|
---|
19 |
|
---|
20 | //HRSRC hRsrc = FindResource(hModule, MAKEINTRESOURCE(IDR_JAR1), "JAR");
|
---|
21 | HRSRC hRsrc = FindResource(hModule, "IDR_JAR1", "JAR");
|
---|
22 |
|
---|
23 | if (hRsrc == NULL)
|
---|
24 | {
|
---|
25 | cout << "Could not find resource." << endl;
|
---|
26 | }
|
---|
27 | else
|
---|
28 | {
|
---|
29 | HGLOBAL hGlobal = LoadResource(hModule, hRsrc);
|
---|
30 | if (hGlobal == NULL)
|
---|
31 | {
|
---|
32 | cout << "Could not lock resource." << endl;
|
---|
33 | }
|
---|
34 | else
|
---|
35 | {
|
---|
36 | BYTE* pBytes = (BYTE*) LockResource(hGlobal);
|
---|
37 | if (pBytes == NULL)
|
---|
38 | {
|
---|
39 | cout << "Could not lock resource." << endl;
|
---|
40 | }
|
---|
41 | else
|
---|
42 | {
|
---|
43 | DWORD dwLength = SizeofResource(hModule, hRsrc);
|
---|
44 | system("mkdir newwrapper.tmp");
|
---|
45 | WriteUsingStream(pBytes, dwLength, "newwrapper.tmp\\WebTransform.jar");
|
---|
46 | UnlockResource(hGlobal);
|
---|
47 | }
|
---|
48 |
|
---|
49 | FreeResource(hGlobal);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | //change to the temp directory and start the jar
|
---|
55 | SetCurrentDirectory("newwrapper.tmp");
|
---|
56 | system("java -jar WebTransform.jar");
|
---|
57 |
|
---|
58 | //change back to the original directory and clean up the temp directory
|
---|
59 | SetCurrentDirectory("..");
|
---|
60 | system("del newwrapper.tmp\\WebTransform.jar");
|
---|
61 | system("del newwrapper.tmp\\ant.install.log");
|
---|
62 | system("rmdir newwrapper.tmp");
|
---|
63 |
|
---|
64 |
|
---|
65 | } |
---|