Changeset 15142 for release-kits/lirk3/wrapper/mywrapper.c
- Timestamp:
- 2008-03-28T12:43:46+13:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
release-kits/lirk3/wrapper/mywrapper.c
r14982 r15142 2 2 #include <fstream> 3 3 #include <iomanip> 4 4 5 using namespace std; 5 6 6 7 #include "mywrapper.h" 7 8 8 bool extract_bundled_file( const char[], int, char* );9 bool extract_bundled_file( const char[], int, char*, bool ); 9 10 10 11 int main(int argc, char** argv) { … … 12 13 string tempdir = (string)argv[0] + ".tmp"; //temporary directory where we will store extracted files 13 14 string jarfile = tempdir + "/greenstone3.jar"; //where we will store the jar file 15 string search4jfile = tempdir + "/search4j"; //where we will store the jar file 14 16 bool succeeded = false; 15 17 … … 25 27 26 28 //extract files 27 cout << "Extracting JAR file..." << endl;28 succeeded = extract_bundled_file( greenstone3jar, sizeof(greenstone3jar), (char*)jarfile.c_str() 29 cout << "Extracting installer jar..." << endl; 30 succeeded = extract_bundled_file( greenstone3jar, sizeof(greenstone3jar), (char*)jarfile.c_str(), false); 29 31 if ( !succeeded ) { 30 32 cout << "failed" << endl; 31 33 cout << "Failed to extract the JAR file to '" << jarfile << "'" << endl; 32 cout << "The JAR file may have been bundled with this executable incorrectly" << endl;33 cout << "Or this programmay not have sufficient file permissions to write it to disk" << endl;34 cout << "The file may be corrupt or missing" << endl; 35 cout << "Or this installer may not have sufficient file permissions to write it to disk" << endl; 34 36 cout << "Exiting" << endl; 35 37 return 1; 36 38 } 37 39 38 //run the jar 39 cout << "Running the jar" << endl; 40 system( ("java -jar " + jarfile).c_str() ); 40 cout << "Extracting search4j tool..." << endl; 41 succeeded = extract_bundled_file( search4j, sizeof(search4j), (char*)search4jfile.c_str(), true ); 42 if ( !succeeded ) { 43 cout << "failed" << endl; 44 cout << "Failed to extract the search4j tool to '" << jarfile << "'" << endl; 45 cout << "The file may be corrupt or missing" << endl; 46 cout << "Or this installer may not have sufficient file permissions to write it to disk" << endl; 47 cout << "Exiting" << endl; 48 return 1; 49 } 50 51 52 //change to the temp directory 53 chdir( tempdir.c_str() ); 54 55 56 //check if an appropriate java is found 57 bool jvmFound = (system( "./search4j -m @java.min.version@ -h ./@java.extracted@" ) == 0); 58 59 //if the jvm was not found, try to fix it and find it 60 if ( !jvmFound ) { 61 //did not find a good java 62 cout << "Greenstone requires java @java.min.version@ or greater" << endl; 63 64 //tell them if java is absent or just too old 65 if ( system( "./search4j -h ./@java.extracted@" ) == 0 ) { 66 cout << "Your java is too old." << endl; 67 } else { 68 cout << "Could not find java." << endl; 69 } 70 71 //is this an installer with the bundled JRE? 72 73 #ifdef java_is_bundled 74 //yes, JRE is bundled 75 cout 76 << "This installer comes bundled with a suitible version of java: " << endl 77 << " @java.installer@" << endl 78 << "Do you want to install this java? (y/n)" << endl; 79 char r[1024]; cin >> r; 80 if ( strcmp( r, "y" ) == 0 || strcmp( r, "Y" ) == 0) { 81 extract_bundled_file( java, sizeof(java), (char*)"@java.installer@", true ); 82 system( "./@java.installer@" ); 83 jvmFound = true; //assume the java installation went well 84 } 85 #endif 86 87 #ifndef java_is_bundled 88 //no, JRE is not bundled 89 cout << "Install java (@java.min.version@ or greater) and set JAVA_HOME or JRE_HOME, and try again" << endl; 90 cout << "Or, download a greentsone3 installer with bundled java and use that instead of this one" << endl; 91 #endif 92 } 93 94 //if we have found it by now, launch the installer 95 if ( jvmFound ) { 96 cout << "Launching Installer ..." << endl; 97 int launch_exit_code = 0; 98 launch_exit_code = system("./search4j -m @java.min.version@ -l greenstone3.jar -h ./@java.extracted@"); 99 100 //report how it went 101 if ( launch_exit_code == 0 ) { 102 cout << "Setup complete" << endl; 103 } else { 104 cout << "Still could not find a suitible version of java" << endl; 105 cout << "Please install java, set JAVA_HOME or JRE_HOME, and try again" << endl; 106 } 107 108 } 109 110 //change back to the original directory 111 chdir(".."); 41 112 42 113 //delete the temp files 43 114 cout << "Deleting the temp directory" << endl; 44 115 system( ("rm -rf " + tempdir).c_str() ); 45 system( "rm ant.install.log" );46 116 47 117 … … 50 120 } 51 121 52 bool extract_bundled_file( const char data[], int size, char* filename ) { 122 bool extract_bundled_file( const char data[], int size, char* filename, bool make_executable) { 123 124 if ( size == 0 ) return false; 53 125 54 126 //delete the file if it exists … … 76 148 } 77 149 150 if ( make_executable ) { 151 string command = "chmod a+x " + string(filename); 152 system( command.c_str() ); 153 } 154 78 155 return true; 79 156
Note:
See TracChangeset
for help on using the changeset viewer.