source: release-kits/wirk3/wrapper/wrapper.cpp@ 15025

Last change on this file since 15025 was 15025, checked in by oranfry, 16 years ago

use shared launch4j instead

File size: 3.2 KB
Line 
1#include <windows.h>
2
3#include <fstream>
4#include <iostream>
5
6using namespace std;
7
8void 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
16int extractResource(const char * name, const char * type, char * file) {
17
18 HMODULE hModule = GetModuleHandle(NULL);
19
20 HRSRC hRsrc = FindResource(hModule, name, type);
21 if (hRsrc == NULL) return 1; //couldn't find
22
23 HGLOBAL hGlobal = LoadResource(hModule, hRsrc);
24 if (hGlobal == NULL) return 1; //couldn't lock
25
26 BYTE* pBytes = (BYTE*) LockResource(hGlobal);
27 if (pBytes == NULL) return 1; //couldn't lock
28
29 DWORD dwLength = SizeofResource(hModule, hRsrc);
30 WriteUsingStream(pBytes, dwLength, file);
31 UnlockResource(hGlobal);
32
33 FreeResource(hGlobal);
34
35 return 0;
36
37}
38
39void main()
40{
41
42 cout << "Greenstone3 Installer" << endl;
43
44 //create the temp folder
45 cout << "Creating temp folder 'greenstone3.tmp' ..." << endl;
46 system("mkdir greenstone3.tmp");
47
48 //extract the resources
49 cout << "Extracting jar launcher ..." << endl;
50 extractResource( "LAUNCHER", "EXE", "greenstone3.tmp\\launch-installer.exe" );
51
52 cout << "Extracting jar installer ..." << endl;
53 extractResource( "GREENSTONE_JAR", "JAR", "greenstone3.tmp\\greenstone3.jar" );
54
55 //change to the temp directory and start the jar
56 SetCurrentDirectory("greenstone3.tmp");
57
58 //launch the jar with launch4j, taking a note of the exit code or info in the log
59 cout << "Launching Installer ..." << endl;
60 int launch_exit_code = 0;
61 launch_exit_code = system("launch-installer.exe");
62
63 //if it failed, launch the installer for the bundled java, then try again
64 if ( launch_exit_code == 1 ) {
65 cout << "It appears that you do not have an installed Java Runtime Enviromnent (JRE)" << endl;
66
67 //is this an installer with the bundled JRE?
68 cout << "Extracting java installer ..." << endl;
69 int extract_result = extractResource( "JAVA", "EXE", "@java.installer@" );
70 if ( extract_result == 0 ) {
71
72 //yes, JRE is bundled
73 cout << "Starting the installation process for the bundled JRE" << endl;
74 system( "@java.installer@" );
75 launch_exit_code = system("launch-installer.exe");
76 if ( launch_exit_code == 1 ) {
77 cout << "Still could not find a JRE. Please install a JRE and try again." << endl;
78 }
79
80 } else {
81
82 //no, JRE is not bundled
83 cout << "Sorry, there is no bundled JRE" << endl;
84 cout << "Install a JRE and try again (make sure JRE_HOME is set)" << endl;
85 cout << "Or, download a greentsone3 installer with a bundled JRE and use that instead of this one" << endl;
86
87 }
88 system("if EXISTS greenstone3.tmp\\@java.installer@ del greenstone3.tmp\\@java.installer@");
89
90 }
91
92 //change back to the original directory and clean up the temp directory
93 SetCurrentDirectory("..");
94 system("if EXISTS greenstone3.tmp\\greenstone3.jar del greenstone3.tmp\\greenstone3.jar");
95 system("if EXISTS greenstone3.tmp\\launch-installer.exe del greenstone3.tmp\\launch-installer.exe");
96 system("if EXISTS greenstone3.tmp\\ant.install.log del greenstone3.tmp\\ant.install.log");
97 system("rmdir greenstone3.tmp");
98
99
100}
Note: See TracBrowser for help on using the repository browser.