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

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

lots of work on wirk3

File size: 3.3 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 << "Greenstone requires Java Runtime Enviromnent (JRE) 1.4.0 or greater" << endl;
66 cout << "It appears that you do not have an a suitible JRE installed" << endl;
67
68
69 //is this an installer with the bundled JRE?
70 cout << "Extracting java installer ..." << endl;
71 int extract_result = extractResource( "JAVA", "EXE", "@java.installer@" );
72 if ( extract_result == 0 ) {
73
74 //yes, JRE is bundled
75 cout << "Starting the installation process for the bundled JRE" << endl;
76 system( "@java.installer@" );
77 launch_exit_code = system("launch-installer.exe");
78 if ( launch_exit_code == 1 ) {
79 cout << "Still could not find a JRE. Please install a JRE and try again." << endl;
80 }
81
82 } else {
83
84 //no, JRE is not bundled
85 cout << "Sorry, there is no bundled JRE" << endl;
86 cout << "Install a JRE and try again (make sure JRE_HOME is set)" << endl;
87 cout << "Or, download a greentsone3 installer with a bundled JRE and use that instead of this one" << endl;
88
89 }
90 system("if EXISTS greenstone3.tmp\\@java.installer@ del greenstone3.tmp\\@java.installer@");
91
92 }
93
94 //change back to the original directory and clean up the temp directory
95 SetCurrentDirectory("..");
96 system("if EXISTS greenstone3.tmp\\greenstone3.jar del greenstone3.tmp\\greenstone3.jar");
97 system("if EXISTS greenstone3.tmp\\launch-installer.exe del greenstone3.tmp\\launch-installer.exe");
98 system("if EXISTS greenstone3.tmp\\ant.install.log del greenstone3.tmp\\ant.install.log");
99 system("rmdir greenstone3.tmp");
100
101
102}
Note: See TracBrowser for help on using the repository browser.