Changeset 15689 for release-kits
- Timestamp:
- 2008-05-23T17:05:31+12:00 (16 years ago)
- Location:
- release-kits/wirk3/wrapper
- Files:
-
- 16 added
- 17 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
release-kits/wirk3/wrapper
-
Property svn:ignore
set to
build
-
Property svn:ignore
set to
-
release-kits/wirk3/wrapper/compile.bat
r14986 r15689 1 rc newwrapper.rc 2 move newwrapper.RES build\newwrapper.res 1 mkdir build 3 2 4 cl /c -GX newwrapper.cpp /out:newwrapper.obj 5 move newwrapper.obj build3 rc wrapper.rc 4 move wrapper.RES build\wrapper.res 6 5 7 link /OUT:build\newwrapper.exe build\newwrapper.obj build\newwrapper.res 6 cl /c -GX wrapper.cpp /out:wrapper.obj 7 move wrapper.obj build 8 8 9 link /OUT:build\wrapper.exe build\wrapper.obj build\wrapper.res 10 -
release-kits/wirk3/wrapper/wrapper.cpp
r15146 r15689 6 6 #include <string> 7 7 #include <time.h> 8 #include <shellapi.h> 9 #include <direct.h> 10 #include "libsearch4j.h" 8 11 9 12 using namespace std; 10 13 11 void WriteUsingStream(BYTE* pBytes, int nCount, char* filename) 12 { 13 ofstream fStream(filename, ios::binary | ios::out); 14 15 fStream.write((char*) pBytes, nCount); 16 fStream.close(); 17 } 18 19 int extractResource(const char * name, const char * type, char * file) { 14 //globals 15 HBITMAP g_splash = NULL; //the main splash bitmap 16 char step[10] = "TMP"; //the current step 17 char progress[4] = "0"; //progress in the current step 18 HWND splashWnd; 19 HINSTANCE mainInstance; 20 int mainCmdShow; 21 bool window_loaded = false; 22 23 void set_splash_step( char* new_step ) { 24 strcpy( step, new_step ); 25 InvalidateRect(splashWnd, NULL, FALSE); 26 UpdateWindow(splashWnd); 27 } 28 29 void set_splash_progress( int percent_progress ) { 30 percent_progress = ( percent_progress / 10 ) * 10; 31 char p[4] = {0}; 32 strcpy( progress, itoa( percent_progress, p, 10 ) ); 33 InvalidateRect(splashWnd, NULL, FALSE); 34 //RedrawWindow(splashWnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ERASENOW | RDW_UPDATENOW | RDW_INTERNALPAINT); 35 UpdateWindow(splashWnd); 36 } 37 38 void spoof_progress( int interval ) { 39 int tenPercentWait = interval / 11; 40 for ( int i=0; i <= 100; i+=10 ) { 41 set_splash_progress( i ); 42 Sleep( tenPercentWait ); 43 } 44 } 45 46 //extracts a resource in chunks 47 int extractResource( const char * basename, const char * type, char * file, int no_chunks ) { 20 48 21 49 HMODULE hModule = GetModuleHandle(NULL); 22 23 HRSRC hRsrc = FindResource(hModule, name, type); 24 if (hRsrc == NULL) return 1; //couldn't find 25 26 HGLOBAL hGlobal = LoadResource(hModule, hRsrc); 27 if (hGlobal == NULL) return 1; //couldn't lock 28 29 BYTE* pBytes = (BYTE*) LockResource(hGlobal); 30 if (pBytes == NULL) return 1; //couldn't lock 31 32 DWORD dwLength = SizeofResource(hModule, hRsrc); 33 WriteUsingStream(pBytes, dwLength, file); 34 UnlockResource(hGlobal); 35 36 FreeResource(hGlobal); 37 50 set_splash_progress( 0 ); 51 52 for ( int i=0; i<no_chunks; i++ ) { 53 54 //construct the chunk name 55 char chunkname[127] = {0}; 56 strcpy( chunkname, basename ); 57 strcat( chunkname, "_" ); 58 char chunknum[5] = {0}; 59 itoa( i+1, chunknum, 10 ); 60 strcat( chunkname, chunknum ); 61 62 //MessageBox(NULL, chunkname, "chunk name", MB_OK); 63 64 //try to find it 65 HRSRC hRsrc = FindResource(hModule, chunkname, type); 66 if (hRsrc == NULL ) return -1; //couldn't find the chunk 67 68 //load it 69 HGLOBAL hGlobal = LoadResource(hModule, hRsrc); 70 if (hGlobal == NULL) return 1; //couldn't lock 71 BYTE* pBytes = (BYTE*) LockResource(hGlobal); 72 if (pBytes == NULL) return 1; //couldn't lock 73 74 //put it on disk 75 DWORD dwLength = SizeofResource(hModule, hRsrc); 76 ofstream fStream(file, ios::binary | ios::out | ios::app ); 77 fStream.write((char*) pBytes, dwLength); 78 fStream.close(); 79 80 //unload 81 UnlockResource(hGlobal); 82 FreeResource(hGlobal); 83 84 //update the progress 85 set_splash_progress( i * 100 / no_chunks ); 86 87 } 88 38 89 return 0; 39 90 40 91 } 41 92 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() { 93 //the splash window procedure 94 LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { 95 switch(msg) { 96 97 case WM_CREATE: { 98 //load in the reusable resources 99 g_splash = LoadBitmap(GetModuleHandle(NULL),"SPLASH"); 100 if(g_splash == NULL) { 101 MessageBox(hwnd, "Could not load splash bitmap!", "Error", MB_OK | MB_ICONEXCLAMATION); 102 } 103 104 //center the window automatically 105 RECT rect; 106 GetWindowRect(hwnd, &rect); 107 int x = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2; 108 int y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2; 109 SetWindowPos(hwnd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE); 110 } 111 112 case WM_PAINT: { 113 // Don't use MessageBox from inside WM_PAINT 114 115 //load in the correct resources 116 HBITMAP g_progress = NULL; 117 HBITMAP g_step = NULL; 118 char progress_res[20] = "PROGRESS_"; 119 strcat( progress_res, progress ); 120 char step_res[20] = "STEP_"; 121 strcat( step_res, step ); 122 g_progress = LoadBitmap(GetModuleHandle(NULL), progress_res ); 123 g_step = LoadBitmap(GetModuleHandle(NULL), step_res ); 124 if( g_progress == NULL || g_step == NULL ) { 125 MessageBox(hwnd, "Could not load an image!", "Error", MB_OK | MB_ICONEXCLAMATION); 126 } 127 128 BITMAP bm; //holds info about the width and height 129 PAINTSTRUCT ps; 130 131 HDC hdc = BeginPaint(hwnd, &ps); 132 HDC hdcMem = CreateCompatibleDC(hdc); 133 134 //paint the main splash screen 135 GetObject(g_splash, sizeof(bm), &bm); 136 HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, g_splash); 137 BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY); 138 139 //paint in the progress 140 GetObject(g_progress, sizeof(bm), &bm); 141 SelectObject(hdcMem, g_progress); 142 BitBlt(hdc, 0, 276, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY); 143 144 //paint in the step with transparency 145 GetObject(g_step, sizeof(bm), &bm); 146 SelectObject(hdcMem, g_step); 147 BitBlt(hdc, 0, 276, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCPAINT); 148 149 //restore the hdc 150 SelectObject(hdcMem, hbmOld); 151 152 //release resources 153 DeleteDC(hdcMem); 154 EndPaint(hwnd, &ps); 155 DeleteObject(g_progress); 156 DeleteObject(g_step); 157 158 } 159 break; 160 161 case WM_LBUTTONDOWN: { 162 DeleteObject(g_splash); 163 PostQuitMessage(0); 164 } 165 break; 166 167 case WM_CLOSE: 168 DestroyWindow(hwnd); 169 break; 170 171 case WM_DESTROY: 172 DeleteObject(g_splash); 173 PostQuitMessage(0); 174 break; 175 176 default: 177 return DefWindowProc(hwnd, msg, wParam, lParam); 178 } 179 180 return 0; 181 182 } 183 184 //function to process the window 185 DWORD WINAPI ProcessWindow( LPVOID lpParam ) { 186 187 const char g_szClassName[] = "splash"; 188 WNDCLASSEX wc; 189 MSG Msg; 190 191 //Step 1: Registering the Window Class 192 wc.cbSize = sizeof(WNDCLASSEX); 193 wc.style = 0; 194 wc.lpfnWndProc = WndProc; 195 wc.cbClsExtra = 0; 196 wc.cbWndExtra = 0; 197 wc.hInstance = mainInstance; 198 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 199 wc.hCursor = LoadCursor(NULL, IDC_ARROW); 200 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 201 wc.lpszMenuName = NULL; 202 wc.lpszClassName = g_szClassName; 203 wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); 204 if(!RegisterClassEx(&wc)) { 205 MessageBox(NULL, "Window Registration Failed!", "Error!", 206 MB_ICONEXCLAMATION | MB_OK); 207 return 0; 208 } 209 210 // Step 2: Creating the Window 211 splashWnd = CreateWindowEx( WS_EX_TOOLWINDOW, g_szClassName, "", WS_POPUP | SS_BITMAP, 0, 0, 420, 300, NULL, NULL, mainInstance, NULL); 212 if( splashWnd == NULL ) { 213 MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); 214 return 0; 215 } 216 ShowWindow(splashWnd, mainCmdShow); 217 UpdateWindow(splashWnd); 218 219 window_loaded = true; 220 221 // Step 3: The Message Loop 222 while(GetMessage(&Msg, NULL, 0, 0) > 0) { 223 TranslateMessage(&Msg); 224 DispatchMessage(&Msg); 225 } 226 return 0; 227 } 228 229 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { 230 231 const int SPOOF_TIME = 1000; 55 232 string command; 56 233 srand( time(0) ); 57 58 cout << "Greenstone3 Installer" << endl; 59 60 //create the temp folder 234 mainInstance = hInstance; 235 mainCmdShow = nCmdShow; 236 237 //start the window 238 HANDLE hThread; 239 DWORD dwThreadId, dwThrdParam = 1; 240 hThread = CreateThread( 241 NULL, // no security attributes 242 0, // use default stack size 243 ProcessWindow, // thread function 244 &dwThrdParam, // argument to thread function 245 0, // use default creation flags 246 &dwThreadId); // returns the thread identifier 247 if ( hThread == NULL ) { 248 return -1; 249 //ErrorExit( "CreateThread failed." ); 250 } 251 CloseHandle( hThread ); 252 253 while ( !window_loaded ) { 254 Sleep( 100 ); 255 } 256 257 //create the temp folder and change to it 258 set_splash_step( "TMP" ); 259 spoof_progress( SPOOF_TIME ); 260 char* tmp = getenv( "TMP" ); 61 261 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() ); 69 70 //extract the resources 71 cout << "Extracting search4j tool ..." << endl; 72 string search4jLocation = ""; search4jLocation.append( tempdir ); search4jLocation.append( "\\search4j.exe" ); 73 extractResource( "SEARCH4J", "EXE", (char*) search4jLocation.c_str() ); 74 75 cout << "Extracting jar installer ..." << endl; 76 string jarLocation = ""; jarLocation.append( tempdir ); jarLocation.append( "\\greenstone3.jar" ); 77 extractResource( "GREENSTONE_JAR", "JAR", (char*) jarLocation.c_str() ); 78 79 //change to the temp directory 262 string tempdir = ""; tempdir.append( tmp ); tempdir.append( "\\Greenstone3-" ); tempdir.append( id ); 263 _mkdir( tempdir.c_str() ); 80 264 SetCurrentDirectory( tempdir.c_str() ); 81 82 //check if an appropriate java is found 83 bool jvmFound = (system( "search4j.exe -m @java.min.version@" ) == 0); 265 266 //find java 267 //set_splash_status( hInstance, statusWnd, "STATUS_SEARCHING4J", 1000 ); 268 set_splash_step( "SEARCHING" ); 269 spoof_progress( SPOOF_TIME ); 270 bool use_minimum = true; 271 Jvm minimum; 272 minimum.setVersionFromString( "@java.min.version@" ); 273 string hint = ""; 274 bool verbose = true; 275 Jvm foundJvm; 276 bool jvmFound = find( foundJvm, use_minimum, minimum, hint, verbose ); 84 277 85 278 //if the jvm was not found, try to fix it and find it 86 279 if ( !jvmFound ) { 280 87 281 //did not find a good java 88 cout << "Greenstone requires java @java.min.version@ or greater" << endl;282 string message = "Greenstone requires java @java.min.version@ or greater, but "; 89 283 90 284 //tell them if java is absent or just too old 91 if ( system( "search4j.exe" ) == 0) {92 cout << "Your java is too old." << endl;285 if ( find( foundJvm, false, minimum, "", false ) ) { 286 message.append( "your java is too old."); 93 287 } else { 94 cout << "Could not find java." << endl; 95 } 288 message.append( "java could not be found on your computer." ); 289 } 290 message.append( "\n\n" ); 96 291 97 292 //is this an installer with the bundled JRE? 98 cout << "Checking for bundled java ..." << endl; 99 int extract_result = extractResource( "JAVA", "EXE", "@java.installer@" ); 293 set_splash_step( "XJAVA" ); 294 int extract_result = extractResource( "JAVA", "EXE", "@java.installer@", 2 ); 295 100 296 if ( extract_result == 0 ) { 297 101 298 //yes, JRE is bundled 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@" ); 109 jvmFound = true; //assume the java installation went well 110 } 299 message.append( "This installer is bundled with a suitible version of java (bundled.version.java)\n"); 300 message.append( "The installer program for this java will now be launched.\n" ); 301 string title = "Must install java first"; 302 MessageBox(NULL, message.c_str(), title.c_str(), MB_OK); 303 ShellExecute(NULL, "open", "@java.installer@", NULL, NULL, SW_SHOWNORMAL); 304 jvmFound = true; //assume the java installation went well 305 111 306 } else { 307 112 308 //no, JRE is not bundled 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 } 309 set_splash_step( "SEARCHING" ); 310 set_splash_progress( 100 ); //we are done searching 311 message.append( "Please install java (@java.min.version@ or newer) and try again.\n" ); 312 message.append( "Or, download a Greentsone3 installer with bundled java and use that instead of this one" ); 313 string title = "Installation Failed: Couldn't find java"; 314 MessageBox(NULL, message.c_str(), title.c_str(), MB_OK); 315 } 316 } 317 118 318 119 319 //if we have found it by now, launch the installer 120 320 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"); 321 322 //extract the jar 323 string jarLocation = ""; jarLocation.append( tempdir ); jarLocation.append( "\\greenstone3.jar" ); 324 //set_splash_status( hInstance, statusWnd, "STATUS_JAR", 0 ); 325 326 set_splash_step( "XJAR" ); 327 extractResource( "JAR", "JAR", (char*) jarLocation.c_str(), 12 ); 328 329 //launch the jar 330 set_splash_step( "LAUNCHING" ); 331 spoof_progress( SPOOF_TIME ); 332 string cmd = "\""; 333 cmd.append( foundJvm.getWinExecutable() ); 334 cmd.append( "\" -jar greenstone3.jar" ); 335 336 //hide splash screen 337 ShowWindow(splashWnd, SW_HIDE); 338 339 //run the jar 340 int launch_exit_code = process( cmd, true ); 125 341 126 342 //report how it went 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; 132 } 133 } 134 135 //change back to the original directory and clean up the temp directory 343 if ( launch_exit_code != 0 ) { 344 string title = "Installation Error"; 345 string message = "The installation exited with an error. Java may not be installed properly, or the installation may have been interrupted partway through. Please try again."; 346 MessageBox(NULL, message.c_str(), title.c_str(), MB_OK); 347 } 348 } 349 350 //clean up the temp directory 351 _unlink("greenstone3.jar"); 352 _unlink("ant.install.log"); 353 _unlink("@java.installer@"); 136 354 SetCurrentDirectory(".."); 137 138 cleanup(tempdir, "greenstone3.jar" ); 139 cleanup(tempdir, "search4j.exe"); 140 cleanup(tempdir, "ant.install.log"); 141 cleanup(tempdir, "@java.installer@"); 142 143 command = "rmdir "; 144 command.append( tempdir ); 145 system( command.c_str() ); 146 cout << "Press any key to exit..." << endl; 147 getch(); 148 149 } 355 _rmdir( tempdir.c_str() ); 356 357 return 0; 358 359 } -
release-kits/wirk3/wrapper/wrapper.rc
r15095 r15689 1 GREENSTONE_JAR JAR "greenstone3.jar" 2 SEARCH4J EXE "search4j.exe" 1 SPLASH BITMAP "splash.bmp" 2 3 PROGRESS_0 BITMAP "progress-0.bmp" 4 PROGRESS_10 BITMAP "progress-10.bmp" 5 PROGRESS_20 BITMAP "progress-20.bmp" 6 PROGRESS_30 BITMAP "progress-30.bmp" 7 PROGRESS_40 BITMAP "progress-40.bmp" 8 PROGRESS_50 BITMAP "progress-50.bmp" 9 PROGRESS_60 BITMAP "progress-60.bmp" 10 PROGRESS_70 BITMAP "progress-70.bmp" 11 PROGRESS_80 BITMAP "progress-80.bmp" 12 PROGRESS_90 BITMAP "progress-90.bmp" 13 PROGRESS_100 BITMAP "progress-100.bmp" 14 15 STEP_TMP BITMAP "step-tmp.bmp" 16 STEP_SEARCHING BITMAP "step-searching.bmp" 17 STEP_XJAVA BITMAP "step-xjava.bmp" 18 STEP_XJAR BITMAP "step-xjar.bmp" 19 STEP_LAUNCHING BITMAP "step-launching.bmp" 20 21 JAR_1 JAR "greenstone3.jar.1" 22 JAR_2 JAR "greenstone3.jar.2" 23 JAR_3 JAR "greenstone3.jar.3" 24 JAR_4 JAR "greenstone3.jar.4" 25 JAR_5 JAR "greenstone3.jar.5" 26 JAR_6 JAR "greenstone3.jar.6" 27 JAR_7 JAR "greenstone3.jar.7" 28 JAR_8 JAR "greenstone3.jar.8" 29 JAR_9 JAR "greenstone3.jar.9" 30 JAR_10 JAR "greenstone3.jar.10" 31 JAR_11 JAR "greenstone3.jar.11" 32 JAR_12 JAR "greenstone3.jar.12" 33 34 JAVA_1 EXE "@[email protected]" //bundled java only 35 JAVA_2 EXE "@[email protected]" //bundled java only 36 3 37 MAINICON ICON "gs3.ico" 4
Note:
See TracChangeset
for help on using the changeset viewer.