Changeset 15095 for release-kits/wirk3/wrapper/wrapper.cpp
- Timestamp:
- 2008-03-20T10:48:10+13:00 (16 years ago)
- Location:
- release-kits/wirk3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
release-kits/wirk3
- Property svn:externals
-
old new 1 1 lib http://svn.greenstone.org/release-kits/shared/lib 2 search4j http://svn.greenstone.org/release-kits/shared/search4j 2 3 4
-
- Property svn:externals
-
release-kits/wirk3/wrapper/wrapper.cpp
r15053 r15095 3 3 #include <fstream> 4 4 #include <iostream> 5 #include <conio.h> 6 #include <string> 7 #include <time.h> 5 8 6 9 using namespace std; … … 37 40 } 38 41 39 void main() 40 { 41 42 void cleanup( string dir, string file ) { 43 string command = "if EXIST "; 44 command.append( dir ); 45 command.append( "\\" ); 46 command.append( file ); 47 command.append( " del " ); 48 command.append( dir ); 49 command.append( "\\" ); 50 command.append( file ); 51 system( command.c_str() ); 52 } 53 54 void main() { 55 string command; 56 srand( time(0) ); 57 42 58 cout << "Greenstone3 Installer" << endl; 43 59 44 60 //create the temp folder 45 cout << "Creating temp folder 'greenstone3.tmp' ..." << endl; 46 system("mkdir greenstone3.tmp"); 61 char id[6]; for( int i=0; i<5; i++ ) id[i] = (char)((rand()%26) + 97); id[5] = '\0'; //id for this instance 62 string tempdir = "greenstone3.tmp"; tempdir.append( id ); //the temp dir 63 64 cout << "Creating temp folder '"; 65 cout << tempdir; 66 cout << "' ..." << endl; 67 command = "mkdir "; command.append(tempdir); 68 system( command.c_str() ); 47 69 48 70 //extract the resources 49 cout << "Extracting jar launcher ..." << endl; 50 extractResource( "LAUNCHER", "EXE", "greenstone3.tmp\\launch-installer.exe" ); 71 cout << "Extracting search4j tool ..." << endl; 72 string search4jLocation = ""; search4jLocation.append( tempdir ); search4jLocation.append( "\\search4j.exe" ); 73 extractResource( "SEARCH4J", "EXE", (char*) search4jLocation.c_str() ); 51 74 52 75 cout << "Extracting jar installer ..." << endl; 53 extractResource( "GREENSTONE_JAR", "JAR", "greenstone3.tmp\\greenstone3.jar" ); 54 76 string jarLocation = ""; jarLocation.append( tempdir ); jarLocation.append( "\\greenstone3.jar" ); 77 extractResource( "GREENSTONE_JAR", "JAR", (char*) jarLocation.c_str() ); 78 55 79 //change to the temp directory and start the jar 56 SetCurrentDirectory( "greenstone3.tmp");80 SetCurrentDirectory( tempdir.c_str() ); 57 81 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 82 //check if an appropriate java is found 83 bool jvmFound = (system( "search4j.exe -m @java.min.version@" ) == 0); 84 85 //if the jvm was not found, try to fix it and find it 86 if ( !jvmFound ) { 87 //did not find a good java 88 cout << "Greenstone requires java @java.min.version@ or greater" << endl; 89 90 //tell them if java is absent or just too old 91 if ( system( "search4j.exe" ) == 0 ) { 92 cout << "Your java is too old." << endl; 93 } else { 94 cout << "Could not find java." << endl; 95 } 68 96 69 97 //is this an installer with the bundled JRE? 70 cout << " Extracting java installer..." << endl;98 cout << "Checking for bundled java ..." << endl; 71 99 int extract_result = extractResource( "JAVA", "EXE", "@java.installer@" ); 72 100 if ( extract_result == 0 ) { 73 74 101 //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; 102 cout 103 << "This installer comes bundled with a suitible version of java: " << endl 104 << " @java.installer@" << endl 105 << "Do you want to install this java? (y/n)" << endl; 106 char r[1024]; cin >> r; 107 if ( _stricmp( r, "y" ) == 0 ) { 108 system( "@java.installer@" ); 80 109 } 81 110 jvmFound = true; //assume the java installation went well 82 111 } else { 83 84 112 //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; 113 cout << "Sorry, there is no bundled java with this installer" << endl; 114 cout << "Install java (@java.min.version@ or newer) and try again" << endl; 115 cout << "Or, download a greentsone3 installer with bundled java and use that instead of this one" << endl; 116 } 117 } 118 119 //if we have found it by now, launch the installer 120 if ( jvmFound ) { 121 //launch the jar with search4j, taking a note of the exit code 122 cout << "Launching Installer ..." << endl; 123 int launch_exit_code = 0; 124 launch_exit_code = system("search4j.exe -m @java.min.version@ -l greenstone3.jar"); 88 125 126 //if it failed, launch the installer for the bundled java, then try again 127 if ( launch_exit_code == 0 ) { 128 cout << "Setup complete" << endl; 129 } else { 130 cout << "Still could not find a suitible version of java" << endl; 131 cout << "Please install java and try again" << endl; 89 132 } 90 system("if EXISTS greenstone3.tmp\\@java.installer@ del greenstone3.tmp\\@java.installer@");91 92 133 } 93 134 94 135 //change back to the original directory and clean up the temp directory 95 136 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"); 137 138 cleanup(tempdir, "greenstone3.jar" ); 139 cleanup(tempdir, "search4j.exe"); 140 cleanup(tempdir, "ant.install.log"); 141 cleanup(tempdir, "@java.installer@"); 100 142 143 command = "rmdir "; 144 command.append( tempdir ); 145 system( command.c_str() ); 146 cout << "Press any key to exit..." << endl; 147 getch(); 101 148 102 149 }
Note:
See TracChangeset
for help on using the changeset viewer.