#include #include #include using namespace std; #include "mywrapper.h" bool extract_bundled_file( const char[], int, char* ); int main(int argc, char** argv) { string tempdir = (string)argv[0] + ".tmp"; //temporary directory where we will store extracted files string jarfile = tempdir + "/greenstone3.jar"; //where we will store the jar file bool succeeded = false; //create the temp folder cout << "Creating temp directory" << endl; succeeded = ( 0 == system( ("mkdir " + tempdir).c_str() ) ); if ( !succeeded ) { cout << "Failed to write to create the temp directory '" << tempdir << "'" << endl; cout << "Check that it does not already exist and try again" << endl; cout << "Exiting" << endl; return 1; } //extract files cout << "Extracting JAR file..." << endl; succeeded = extract_bundled_file( greenstone3jar, sizeof(greenstone3jar), (char*)jarfile.c_str() ); if ( !succeeded ) { cout << "failed" << endl; cout << "Failed to extract the JAR file to '" << jarfile << "'" << endl; cout << "The JAR file may have been bundled with this executable incorrectly" << endl; cout << "Or this program may not have sufficient file permissions to write it to disk" << endl; cout << "Exiting" << endl; return 1; } //run the jar cout << "Running the jar" << endl; system( ("java -jar " + jarfile).c_str() ); //delete the temp files cout << "Deleting the temp directory" << endl; system( ("rm -rf " + tempdir).c_str() ); system( "rm ant.install.log" ); return 0; } bool extract_bundled_file( const char data[], int size, char* filename ) { //delete the file if it exists remove( filename ); //open the file fstream binary_file( filename, ios::out|ios::binary ); if ( !binary_file.good() ) { binary_file.close(); return false; } //write the file binary_file.write( data, size ); if ( !binary_file.good() ) { binary_file.close(); return false; } //close the file binary_file.close(); if ( !binary_file.good() ) { binary_file.close(); return false; } return true; }