1 | /*
|
---|
2 | Copyright (C) 1996
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
17 |
|
---|
18 | The author can be contacted via Email at [email protected]
|
---|
19 | */
|
---|
20 | #include "text_t.h"
|
---|
21 | #include <windows.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <stdio.h>
|
---|
24 | #include <string.h>
|
---|
25 | #include <memory.h>
|
---|
26 | #pragma hdrstop
|
---|
27 | #include "netio.h"
|
---|
28 | #include "settings.h"
|
---|
29 | #include "httpsrv.h"
|
---|
30 | #include "resource.h"
|
---|
31 | #include "locate.h"
|
---|
32 | #include "cgiwrapper.h"
|
---|
33 | #include "startbrowser.h"
|
---|
34 | #include "d_winsock.h"
|
---|
35 |
|
---|
36 | #define MAINWINDOWWIDTH 400
|
---|
37 | #define MAINWINDOWHEIGHT 200
|
---|
38 |
|
---|
39 | #define RESTHEIGHT 45 // Extra window size reqd below logo
|
---|
40 | #define WASTEHEIGHT 44 // Error in ht due to caption and menu bar
|
---|
41 | #define WASTEWIDTH 6
|
---|
42 |
|
---|
43 | // size and position of the collection title
|
---|
44 | #define COLTITLEWIDTH 351
|
---|
45 | #define COLTITLEHEIGHT 35
|
---|
46 | #define COLTITLEX ((MAINWINDOWWIDTH-COLTITLEWIDTH)/2)
|
---|
47 | #define COLTITLEY 10
|
---|
48 |
|
---|
49 | // size and position of the version string
|
---|
50 | #define VERSIONWIDTH MAINWINDOWWIDTH
|
---|
51 | #define VERSIONHEIGHT 20
|
---|
52 | #define VERSIONX 0
|
---|
53 | #define VERSIONY (COLTITLEY+COLTITLEHEIGHT)
|
---|
54 |
|
---|
55 | // size and position of the Greenstone digital library logo
|
---|
56 | #define LOGOWIDTH 135
|
---|
57 | #define LOGOHEIGHT 55
|
---|
58 | #define LOGOX (MAINWINDOWWIDTH-LOGOWIDTH-20)
|
---|
59 | #define LOGOY (MAINWINDOWHEIGHT-LOGOHEIGHT-RESTHEIGHT)
|
---|
60 |
|
---|
61 | // size and position of the status string
|
---|
62 | #define STATUSX 20
|
---|
63 | #define STATUSY ((LOGOY-VERSIONY-VERSIONHEIGHT)/2+VERSIONY+VERSIONHEIGHT)
|
---|
64 | #define STATUSWIDTH MAINWINDOWWIDTH-STATUSX
|
---|
65 | #define STATUSHEIGHT (MAINWINDOWHEIGHT-RESTHEIGHT-STATUSY)
|
---|
66 |
|
---|
67 | // size and position of the info string (same position as the button)
|
---|
68 | #define INFOWIDTH MAINWINDOWWIDTH
|
---|
69 | #define INFOHEIGHT (MAINWINDOWHEIGHT-INFOY)
|
---|
70 | #define INFOX 0
|
---|
71 | #define INFOY ((MAINWINDOWHEIGHT-RESTHEIGHT)+10)
|
---|
72 |
|
---|
73 | // size and position of the button
|
---|
74 | #define ENTERBUTTONWIDTH 150
|
---|
75 | #define ENTERBUTTONHEIGHT 30
|
---|
76 | #define ENTERBUTTONX ((MAINWINDOWWIDTH-ENTERBUTTONWIDTH)/2)
|
---|
77 | #define ENTERBUTTONY ((MAINWINDOWHEIGHT-RESTHEIGHT)+5)
|
---|
78 |
|
---|
79 | #define VERSIONSTRING "version x.xx"
|
---|
80 | const char versionstring[] = VERSIONSTRING;
|
---|
81 |
|
---|
82 | const char strnothing[] = "";
|
---|
83 | const char strinit[] = "Initialising...";
|
---|
84 | const char strsb[] = "Starting browser...";
|
---|
85 | const char strenterlib[] = "Press the 'Enter Library' button to start a browser\n"
|
---|
86 | "and begin using this library";
|
---|
87 | const char strenterstaticlib[] = "Press the 'Enter Library' button to start a browser\n"
|
---|
88 | "and begin using the static version\n"
|
---|
89 | "of this library";
|
---|
90 | const char *statusstring = NULL; // points to the current status string
|
---|
91 | const char *infostring = NULL; // points to the current info string
|
---|
92 |
|
---|
93 |
|
---|
94 | // globals to do with networking and browsers
|
---|
95 | int have_networking = 0;
|
---|
96 | int netscapeneeded = 0;
|
---|
97 | char startbrowserdir[1024] = ""; // HARD LIMIT!!!!!
|
---|
98 |
|
---|
99 |
|
---|
100 | // stats to do with the last time the enter library button was pressed
|
---|
101 | // these stats are needed to make suggestions about the proxy
|
---|
102 | int enterlib_libaccessnum = -1; // -1 = NA
|
---|
103 | DWORD enterlib_time = 0;
|
---|
104 |
|
---|
105 |
|
---|
106 | enum { undefined_window, console_window, plain_window }
|
---|
107 | window_state;
|
---|
108 |
|
---|
109 | HDC coltitledc = NULL;
|
---|
110 | HBITMAP defcoltitlebitmap = NULL, coltitlebitmap=NULL;
|
---|
111 |
|
---|
112 | HDC logodc=NULL;
|
---|
113 | HBITMAP deflogobitmap=NULL, logobitmap=NULL;
|
---|
114 |
|
---|
115 | HWND GoButton = NULL;
|
---|
116 |
|
---|
117 |
|
---|
118 | void finish_up() {
|
---|
119 | // remember the current preferences
|
---|
120 | write_settings();
|
---|
121 |
|
---|
122 | // Shutdown the HTTP server
|
---|
123 | EndHTTPServer();
|
---|
124 |
|
---|
125 | // Shutdown the main server modules
|
---|
126 | CleanUpNetIO();
|
---|
127 | // RemoveFnordFromTray();
|
---|
128 |
|
---|
129 | // Unload the wsock32 dll
|
---|
130 | d_UnloadWinsock();
|
---|
131 |
|
---|
132 | // Clean up graphics stuff from window
|
---|
133 |
|
---|
134 | if (defcoltitlebitmap != NULL)
|
---|
135 | SelectObject (coltitledc, defcoltitlebitmap);
|
---|
136 | if (coltitlebitmap != NULL)
|
---|
137 | DeleteObject (coltitlebitmap);
|
---|
138 | if (coltitledc != NULL)
|
---|
139 | DeleteDC (coltitledc);
|
---|
140 |
|
---|
141 | if (deflogobitmap != NULL)
|
---|
142 | SelectObject (logodc, deflogobitmap);
|
---|
143 | if (logobitmap != NULL)
|
---|
144 | DeleteObject (logobitmap);
|
---|
145 | if (logodc != NULL)
|
---|
146 | DeleteDC (logodc);
|
---|
147 |
|
---|
148 | // Shutdown the main window
|
---|
149 | PostQuitMessage(0);
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | int overlap(int left, int top, int right, int bottom,
|
---|
154 | RECT &r2)
|
---|
155 | {
|
---|
156 | if (left <= r2.right && r2.left <= right &&
|
---|
157 | top <= r2.bottom && r2.top <= bottom)
|
---|
158 | return 1;
|
---|
159 | else
|
---|
160 | return 0;
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | void paint_window (HDC pdc, RECT &updateRect) {
|
---|
165 | // make sure the various DCs are set up
|
---|
166 | if (coltitledc == NULL) {
|
---|
167 | coltitledc = CreateCompatibleDC(pdc);
|
---|
168 | defcoltitlebitmap = (HBITMAP)SelectObject (coltitledc, coltitlebitmap);
|
---|
169 | }
|
---|
170 |
|
---|
171 | if (logodc == NULL) {
|
---|
172 | logodc = CreateCompatibleDC(pdc);
|
---|
173 | deflogobitmap = (HBITMAP)SelectObject (logodc, logobitmap);
|
---|
174 | }
|
---|
175 |
|
---|
176 | // update the collection title if needed
|
---|
177 | if (overlap(COLTITLEX, COLTITLEY,
|
---|
178 | COLTITLEX+COLTITLEWIDTH, COLTITLEY+COLTITLEHEIGHT,
|
---|
179 | updateRect)) {
|
---|
180 | BitBlt (pdc, COLTITLEX, COLTITLEY,
|
---|
181 | COLTITLEX+COLTITLEWIDTH, COLTITLEY+COLTITLEHEIGHT,
|
---|
182 | coltitledc, 0, 0, SRCCOPY);
|
---|
183 | }
|
---|
184 |
|
---|
185 | // update the version string if needed
|
---|
186 | if (overlap (VERSIONX, VERSIONY,
|
---|
187 | VERSIONX+VERSIONWIDTH, VERSIONY+VERSIONHEIGHT,
|
---|
188 | updateRect)) {
|
---|
189 | RECT versionRect;
|
---|
190 | versionRect.left = VERSIONX;
|
---|
191 | versionRect.top = VERSIONY;
|
---|
192 | versionRect.right = VERSIONX+VERSIONWIDTH;
|
---|
193 | versionRect.bottom = VERSIONY+VERSIONHEIGHT;
|
---|
194 | DrawText(pdc, versionstring, -1, &versionRect, DT_CENTER);
|
---|
195 | }
|
---|
196 |
|
---|
197 | // decide what we want to draw
|
---|
198 | if (gsdl_show_console) {
|
---|
199 | // we want to draw a "console" window
|
---|
200 | if (window_state != console_window ||
|
---|
201 | overlap (text_rect.left, text_rect.top,
|
---|
202 | text_rect.right, text_rect.bottom,
|
---|
203 | updateRect)) {
|
---|
204 | refresh_console (pdc);
|
---|
205 | }
|
---|
206 |
|
---|
207 | window_state = console_window;
|
---|
208 |
|
---|
209 | } else {
|
---|
210 | // we want to draw a "plain" window
|
---|
211 |
|
---|
212 | // update the status string if needed
|
---|
213 | if ((statusstring != NULL) && (strlen(statusstring) > 0)
|
---|
214 | && overlap (STATUSX, STATUSY,
|
---|
215 | STATUSX+STATUSWIDTH, STATUSY+STATUSHEIGHT,
|
---|
216 | updateRect)) {
|
---|
217 | RECT statusRect;
|
---|
218 | statusRect.left = STATUSX;
|
---|
219 | statusRect.top = STATUSY;
|
---|
220 | statusRect.right = STATUSX+STATUSWIDTH;
|
---|
221 | statusRect.bottom = STATUSY+STATUSHEIGHT;
|
---|
222 | FillRect(pdc, &statusRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
|
---|
223 |
|
---|
224 | int cury = STATUSY;
|
---|
225 | int startline = 0, here = 0;
|
---|
226 | while (statusstring[here] != '\0') {
|
---|
227 | if (statusstring[here] < ' ') {
|
---|
228 | if (here - startline > 0) {
|
---|
229 | // output the text
|
---|
230 | TextOut (pdc, STATUSX, cury,
|
---|
231 | &statusstring[startline], here-startline);
|
---|
232 | cury += line_spacing;
|
---|
233 | }
|
---|
234 | startline = here+1;
|
---|
235 | }
|
---|
236 | here++;
|
---|
237 | }
|
---|
238 | // output any remaining text
|
---|
239 | if (here - startline > 0) {
|
---|
240 | TextOut (pdc, STATUSX, cury, &statusstring[startline], here-startline);
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | // update the logo (always)
|
---|
245 | BitBlt (pdc, LOGOX, LOGOY, LOGOX+LOGOWIDTH, LOGOY+LOGOHEIGHT,
|
---|
246 | logodc, 0, 0, SRCCOPY);
|
---|
247 |
|
---|
248 | window_state = plain_window;
|
---|
249 | }
|
---|
250 |
|
---|
251 |
|
---|
252 | // update the info string if needed
|
---|
253 | if ((GoButton == NULL) && (infostring != NULL) &&
|
---|
254 | overlap (INFOX, INFOY,
|
---|
255 | INFOX+INFOWIDTH, INFOY+INFOHEIGHT,
|
---|
256 | updateRect)) {
|
---|
257 | RECT infoRect;
|
---|
258 | infoRect.left = INFOX;
|
---|
259 | infoRect.top = INFOY;
|
---|
260 | infoRect.right = INFOX+INFOWIDTH;
|
---|
261 | infoRect.bottom = INFOY+INFOHEIGHT;
|
---|
262 | FillRect(pdc, &infoRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
|
---|
263 | DrawText(pdc, infostring, -1, &infoRect, DT_CENTER);
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 |
|
---|
268 | void handle_painting (HWND Window) {
|
---|
269 | HDC pdc; PAINTSTRUCT ps;
|
---|
270 | pdc = BeginPaint(Window, &ps);
|
---|
271 |
|
---|
272 | paint_window (pdc, ps.rcPaint);
|
---|
273 |
|
---|
274 | EndPaint(Window, &ps);
|
---|
275 | }
|
---|
276 |
|
---|
277 |
|
---|
278 | // returns 1 on success, 0 otherwise
|
---|
279 | int enter_library (HWND Window) {
|
---|
280 | int res;
|
---|
281 |
|
---|
282 | // get the url and attempt to start a browser
|
---|
283 | char *localname = GetLocalName(NULL);
|
---|
284 | if (have_networking) {
|
---|
285 | text_t url = "http://" + text_t(localname);
|
---|
286 | if (gsdl_port_num != 80)
|
---|
287 | url += ":" + text_t(gsdl_port_num);
|
---|
288 |
|
---|
289 | url += gsdl_enterlib;
|
---|
290 |
|
---|
291 | // add a unique ending so it will always result in a request
|
---|
292 | text_t::const_iterator it =
|
---|
293 | findchar (gsdl_enterlib.begin(), gsdl_enterlib.end(), '?');
|
---|
294 | if (it == gsdl_enterlib.end()) url.push_back ('?');
|
---|
295 | else url.push_back ('&');
|
---|
296 | int tcount = GetTickCount();
|
---|
297 | url += "uq=" + text_t(tcount);
|
---|
298 |
|
---|
299 | // remember the library access number for later proxy checking
|
---|
300 | enterlib_libaccessnum = libaccessnum;
|
---|
301 |
|
---|
302 | // do a quick check to make sure we're using netscape when
|
---|
303 | // we should be (it might have been just installed)
|
---|
304 | if (netscapeneeded) gsdl_check_browser_settings (netscapeneeded);
|
---|
305 |
|
---|
306 | char *cstr_url = url.getcstr();
|
---|
307 | if (strlen (startbrowserdir) <= 0) {
|
---|
308 | res = startbrowser (cstr_url, gsdl_browser_exe, NULL);
|
---|
309 |
|
---|
310 | } else res = startbrowser (cstr_url, gsdl_browser_exe, startbrowserdir);
|
---|
311 |
|
---|
312 | delete cstr_url;
|
---|
313 |
|
---|
314 | } else {
|
---|
315 | /*
|
---|
316 | char staticpath[256];
|
---|
317 |
|
---|
318 | // try to find the static pages
|
---|
319 | strcpy (url, gsdl_staticpages);
|
---|
320 |
|
---|
321 | // remove any slashes from the static pathname
|
---|
322 | int len = strlen (url);
|
---|
323 | while ((len > 0) && ((url[len-1] == '\\') || (url[len-1] == '/'))) {
|
---|
324 | len--;
|
---|
325 | }
|
---|
326 | url[len] = '\0';
|
---|
327 |
|
---|
328 | // add one slash to the end
|
---|
329 | strcat (url, "\\");
|
---|
330 |
|
---|
331 | // check to make sure the static directory is available
|
---|
332 | strcpy (staticpath, url);
|
---|
333 | strcat (staticpath, "static\\");
|
---|
334 |
|
---|
335 | // check this directory
|
---|
336 | if (!cstrcheckdir(staticpath)) {
|
---|
337 | PostMessage(Window,WM_CLOSE,0,0);
|
---|
338 | return 0;
|
---|
339 | }
|
---|
340 |
|
---|
341 | // add filename of the first page
|
---|
342 | strcat (url, "niupepa.htm");
|
---|
343 |
|
---|
344 | res = startbrowser (url, gsdl_browser_exe, NULL);
|
---|
345 | startbrowserdir[0] = '\0'; // doesn't make sense for non-networked case
|
---|
346 | */
|
---|
347 | }
|
---|
348 |
|
---|
349 | if (res == SB_NOERROR) {
|
---|
350 | // success !!
|
---|
351 |
|
---|
352 | // remember the time the browser was started for later proxy checking
|
---|
353 | if (have_networking) enterlib_time = GetTickCount();
|
---|
354 |
|
---|
355 | return 1;
|
---|
356 | }
|
---|
357 |
|
---|
358 | // no browser was started
|
---|
359 | enterlib_libaccessnum = -1;
|
---|
360 |
|
---|
361 | if ((res == SB_FAIL_BADFORMAT) || (res == SB_FAIL_NOTFOUND)) {
|
---|
362 | if (!netscapeneeded) { // any browser
|
---|
363 | MessageBox(Window,
|
---|
364 | "Failed to start your chosen browser. It seems that your\n"
|
---|
365 | "chosen browser has been removed or corrupted.\n"
|
---|
366 | "Please check you browser choice by going to the\n"
|
---|
367 | "'Settings...' item under the 'File' menu.",
|
---|
368 | "Greenstone Digital Library Software", MB_OK);
|
---|
369 | } else { // netscape used
|
---|
370 | MessageBox(Window,
|
---|
371 | "Failed to start Netscape. It seems that Netscape has\n"
|
---|
372 | "been removed or corrupted. You need Netscape\n"
|
---|
373 | "installed to use the Greenstone Digital Library\n"
|
---|
374 | "software on non-networked machines.\n\n"
|
---|
375 | "You can install Netscape by choosing\n"
|
---|
376 | "'Install Netscape 4.05' from the 'File' menu.",
|
---|
377 | "Greenstone Digital Library Software", MB_OK);
|
---|
378 | }
|
---|
379 |
|
---|
380 | } else {
|
---|
381 | MessageBox(Window,
|
---|
382 | "Failed to start your browser. This may have been\n"
|
---|
383 | "because there was not enough memory available. Shut\n"
|
---|
384 | "down all other applications you have running, and\n"
|
---|
385 | "try again.",
|
---|
386 | "Greenstone Digital Library Software", MB_OK);
|
---|
387 | }
|
---|
388 |
|
---|
389 | return 0; // failed
|
---|
390 | }
|
---|
391 |
|
---|
392 |
|
---|
393 | void install_netscape (HWND Window) {
|
---|
394 | char installpath[256];
|
---|
395 |
|
---|
396 | // try to find the browser directory
|
---|
397 | char *gsdlhome = gsdl_gsdlhome.getcstr();
|
---|
398 | strcpy (installpath, gsdlhome); // use gsdlhome to find the CD-ROM drive...
|
---|
399 | delete gsdlhome;
|
---|
400 |
|
---|
401 | // remove any slashes from the pathname
|
---|
402 | int len = strlen (installpath);
|
---|
403 | while ((len > 0) && ((installpath[len-1] == '\\') || (installpath[len-1] == '/'))) {
|
---|
404 | len--;
|
---|
405 | }
|
---|
406 | // remove '\gsdl'
|
---|
407 | len = len - 5;
|
---|
408 | installpath[len] = '\0';
|
---|
409 |
|
---|
410 | strcat (installpath, "\\netscape\\");
|
---|
411 |
|
---|
412 | // check this directory
|
---|
413 | if (!cstrcheckdir(installpath)) {
|
---|
414 | return;
|
---|
415 | }
|
---|
416 |
|
---|
417 | // get the operating system information
|
---|
418 | OSVERSIONINFO osver;
|
---|
419 | memset(&osver, 0, sizeof(OSVERSIONINFO));
|
---|
420 | osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
---|
421 | GetVersionEx(&osver);
|
---|
422 |
|
---|
423 | // get the install program for this operating system
|
---|
424 | if (osver.dwPlatformId == VER_PLATFORM_WIN32s) {
|
---|
425 | strcat (installpath, "n16e405.exe");
|
---|
426 | } else {
|
---|
427 | strcat (installpath, "n32e405.exe");
|
---|
428 | }
|
---|
429 |
|
---|
430 | // run the install program
|
---|
431 | int res = WinExec (installpath, SW_SHOW);
|
---|
432 | if (res == 0) {
|
---|
433 | // out of resources or memory
|
---|
434 | MessageBox (Window,
|
---|
435 | "Did not have enough resources or memory to run the\n"
|
---|
436 | "install program. Try shutting down all other programs\n"
|
---|
437 | "and trying again.",
|
---|
438 | "Greenstone Digital Library Software",
|
---|
439 | MB_OK|MB_APPLMODAL);
|
---|
440 |
|
---|
441 | } else if (res == ERROR_BAD_FORMAT) {
|
---|
442 | // executable image is corrupt -- ????
|
---|
443 | MessageBox (Window,
|
---|
444 | "The install program seems to be corrupt.",
|
---|
445 | "Greenstone Digital Library Software",
|
---|
446 | MB_OK|MB_APPLMODAL);
|
---|
447 |
|
---|
448 | } else if ((res == ERROR_FILE_NOT_FOUND) || (res == ERROR_PATH_NOT_FOUND)) {
|
---|
449 | // couldn't find the executable -- ????
|
---|
450 | MessageBox (Window,
|
---|
451 | "Could not find the install program. Try installing\n"
|
---|
452 | "Netscape from the Greenstone Digital Library\n"
|
---|
453 | "software's install program.",
|
---|
454 | "Greenstone Digital Library Software",
|
---|
455 | MB_OK|MB_APPLMODAL);
|
---|
456 | }
|
---|
457 | }
|
---|
458 |
|
---|
459 | void open_help () {
|
---|
460 | char topdir[256], cmd[256];
|
---|
461 |
|
---|
462 | // try to find the browser directory
|
---|
463 | char *gsdlhome = gsdl_gsdlhome.getcstr();
|
---|
464 | strcpy (topdir, gsdlhome); // use gsdlhome to find the CD-ROM drive...
|
---|
465 | delete gsdlhome;
|
---|
466 | strcpy (cmd, "notepad ");
|
---|
467 |
|
---|
468 | // remove any slashes from the pathname
|
---|
469 | int len = strlen (topdir);
|
---|
470 | while ((len > 0) && ((topdir[len-1] == '\\') || (topdir[len-1] == '/'))) {
|
---|
471 | len--;
|
---|
472 | }
|
---|
473 | // remove the '\gsdl'
|
---|
474 | len = len - 5;
|
---|
475 | topdir[len] = '\0';
|
---|
476 |
|
---|
477 | strcat (topdir, "\\README.txt");
|
---|
478 | strcat (cmd, topdir);
|
---|
479 |
|
---|
480 | WinExec (cmd, SW_SHOW);
|
---|
481 | }
|
---|
482 |
|
---|
483 |
|
---|
484 | long __stdcall WndProc(HWND Window, UINT Message, WPARAM WParam, LPARAM LParam) {
|
---|
485 | switch(Message) {
|
---|
486 | // Constant Messages
|
---|
487 | case WM_CREATE:
|
---|
488 | break;
|
---|
489 |
|
---|
490 | case WM_CHAR:
|
---|
491 | // if the user hit the return key and if this is not a
|
---|
492 | // repeat key press then attempt to start a browser
|
---|
493 | if ((WParam == '\r') && !(LParam & 0xe0000000)) {
|
---|
494 | if (enter_library (Window) && !gsdl_show_console)
|
---|
495 | ShowWindow(Window,SW_MINIMIZE);
|
---|
496 | }
|
---|
497 |
|
---|
498 | case WM_COMMAND:
|
---|
499 | if ((HWND)LParam == GoButton) {
|
---|
500 | // attempt to start a browser
|
---|
501 | if (enter_library (Window) && !gsdl_show_console)
|
---|
502 | ShowWindow(Window,SW_MINIMIZE);
|
---|
503 |
|
---|
504 | } else {
|
---|
505 | switch (LOWORD(WParam)) {
|
---|
506 | case ID_PROJECT_SETTINGS:
|
---|
507 | Settings_Dialog(Window, netscapeneeded);
|
---|
508 | break;
|
---|
509 | case ID_INSTALL_NETSCAPE:
|
---|
510 | install_netscape(Window);
|
---|
511 | break;
|
---|
512 | case IDHELP:
|
---|
513 | open_help();
|
---|
514 | break;
|
---|
515 | case ID_PROJECT_EXIT:
|
---|
516 | finish_up();
|
---|
517 | break;
|
---|
518 | default:
|
---|
519 | break;
|
---|
520 | }
|
---|
521 | }
|
---|
522 | break;
|
---|
523 |
|
---|
524 | case WM_PAINT:
|
---|
525 | handle_painting(Window);
|
---|
526 | break;
|
---|
527 |
|
---|
528 | case HTTP_SERVER_MSG:
|
---|
529 | ProcessHTTPServerMsg(WParam, LParam);
|
---|
530 | break;
|
---|
531 |
|
---|
532 | case WM_DESTROY:
|
---|
533 | finish_up();
|
---|
534 | break;
|
---|
535 |
|
---|
536 | default:
|
---|
537 | //Unhandled Messages end up here (DefWindowProc)
|
---|
538 | return DefWindowProc(Window, Message, WParam, LParam);
|
---|
539 | }
|
---|
540 |
|
---|
541 | return(0);
|
---|
542 | }
|
---|
543 |
|
---|
544 | // returns 0 if successful,
|
---|
545 | // otherwise a WSA error number
|
---|
546 | int tryinitnetwork (HANDLE Instance, HWND MsgWindow, char *path) {
|
---|
547 | // try to load winsock
|
---|
548 | int err = d_LoadWinsock (path);
|
---|
549 |
|
---|
550 | if (err == D_NOERROR) {
|
---|
551 | // next, try to init netio
|
---|
552 | err = InitNetIO();
|
---|
553 |
|
---|
554 | if (err == 0) {
|
---|
555 | // next, try to start the http server
|
---|
556 | err = StartHTTPServer(MsgWindow);
|
---|
557 |
|
---|
558 | if (err == 0) {
|
---|
559 | // finally, get the host name (no error value
|
---|
560 | // is returned from this function)
|
---|
561 | GetLocalName((HINSTANCE)Instance);
|
---|
562 |
|
---|
563 | } else {
|
---|
564 | // couldn't start the http server,
|
---|
565 | // deinit netio and unload winsock
|
---|
566 | CleanUpNetIO();
|
---|
567 | d_UnloadWinsock();
|
---|
568 | }
|
---|
569 |
|
---|
570 | } else {
|
---|
571 | // couldn't init netio, unload winsock
|
---|
572 | d_UnloadWinsock();
|
---|
573 | }
|
---|
574 |
|
---|
575 | } else {
|
---|
576 | // couldn't load winsock
|
---|
577 | err = WSASYSNOTREADY;
|
---|
578 | }
|
---|
579 |
|
---|
580 | return err;
|
---|
581 | }
|
---|
582 |
|
---|
583 |
|
---|
584 | // inits all the network functionality
|
---|
585 | // returns 0 if an unrecoverable error occurred,
|
---|
586 | // and 1 if everything successfully initialised.
|
---|
587 | int initnetwork (HANDLE Instance, HWND MsgWindow) {
|
---|
588 | OSVERSIONINFO osver;
|
---|
589 |
|
---|
590 | // get the operating system information
|
---|
591 | memset(&osver, 0, sizeof(OSVERSIONINFO));
|
---|
592 | osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
---|
593 | GetVersionEx(&osver);
|
---|
594 |
|
---|
595 | // first try to initialise the network with system installed
|
---|
596 | // networking software
|
---|
597 | startbrowserdir[0] = '\0';
|
---|
598 | netscapeneeded = 0;
|
---|
599 | // int err = tryinitnetwork (Instance, MsgWindow, NULL);
|
---|
600 | int err = 1;
|
---|
601 |
|
---|
602 | // if an error occurred, try again with billsock
|
---|
603 | if (err != 0) {
|
---|
604 | // get the path of billsock (current directory + ("net16" | "net32"))
|
---|
605 | char winsockpath[1024]; // HARD LIMIT!!!!
|
---|
606 |
|
---|
607 | find_location();
|
---|
608 | strcpy (winsockpath, data_location);
|
---|
609 |
|
---|
610 | // remove all the slashes at the end of billpath
|
---|
611 | int len = strlen (winsockpath);
|
---|
612 | while ((len > 0) && ((winsockpath[len-1] == '\\') || (winsockpath[len-1] == '/'))) {
|
---|
613 | len--;
|
---|
614 | }
|
---|
615 | winsockpath[len] = '\0';
|
---|
616 |
|
---|
617 | if (osver.dwPlatformId == VER_PLATFORM_WIN32s)
|
---|
618 | strcat (winsockpath, "\\net16\\");
|
---|
619 | else {
|
---|
620 | strcat (winsockpath, "\\net32\\");
|
---|
621 | strcpy (startbrowserdir, winsockpath);
|
---|
622 | }
|
---|
623 |
|
---|
624 | // try again
|
---|
625 | err = tryinitnetwork (Instance, MsgWindow, winsockpath);
|
---|
626 |
|
---|
627 | if (err == 0) {
|
---|
628 | // we will need to use netscape on 95/98/NT machines
|
---|
629 | if (osver.dwPlatformId != VER_PLATFORM_WIN32s) {
|
---|
630 | netscapeneeded = 1;
|
---|
631 | // make sure the browser state is in step with the network condition
|
---|
632 | gsdl_check_browser_settings (netscapeneeded);
|
---|
633 | }
|
---|
634 |
|
---|
635 | // check to see if a browser is running
|
---|
636 | if (browserrunning(gsdl_browser_exe) == NO_ERROR) {
|
---|
637 | MessageBox (NULL,
|
---|
638 | "The Greenstone Digital Library software has detected a\n"
|
---|
639 | "running browser. To let our networking software\n"
|
---|
640 | "correctly initialize, please shut down your browser\n"
|
---|
641 | "and restart the Greenstone Digital Library software.",
|
---|
642 | "Greenstone Digital Library Software", MB_OK|MB_APPLMODAL);
|
---|
643 | PostMessage(MsgWindow,WM_CLOSE,0,0);
|
---|
644 | finish_up(); // will unload winsock
|
---|
645 | exit(0); // nothing more to do
|
---|
646 | }
|
---|
647 | }
|
---|
648 | }
|
---|
649 |
|
---|
650 | // if an error occurred display a nice error message
|
---|
651 | if (err != 0) {
|
---|
652 |
|
---|
653 | // WSASYSNOTREADY Couldn't load winsock
|
---|
654 | // WSAVERNOTSUPPORTED The version of Windows Sockets support requested
|
---|
655 | // is not provided by this particular Windows Sockets implementation.
|
---|
656 | // WSAEINVAL The Windows Sockets version specified by the application
|
---|
657 | // is not supported by this DLL.
|
---|
658 | // WSAEPROTONOSUPPORT The specified protocol is not supported.
|
---|
659 | // WSAEPROTOTYPE The specified protocol is the wrong type for this socket.
|
---|
660 | // WSAESOCKTNOSUPPORT The specified socket type is not supported in
|
---|
661 | // this address family.
|
---|
662 | // WSANOTINITIALISED A successful WSAStartup must occur before
|
---|
663 | // using this function.
|
---|
664 | // WSAENETDOWN The Windows Sockets implementation
|
---|
665 | // has detected that the network subsystem has failed.
|
---|
666 | // WSAEADDRINUSE The specified address
|
---|
667 | // is already in use. (See the SO_REUSEADDR socket option under setsockopt.)
|
---|
668 | // WSAEFAULT The namelen argument is too small (less
|
---|
669 | // than the size of a struct sockaddr).
|
---|
670 | // WSAEINPROGRESS A blocking Windows Sockets call is in progress.
|
---|
671 | // WSAEAFNOSUPPORT The specified address family is not supported
|
---|
672 | // by this protocol.
|
---|
673 | // WSAENOBUFS Not enough buffers available, too many connections.
|
---|
674 | // WSAENOTSOCK The descriptor is not a socket.
|
---|
675 | // WSAEISCONN The socket is already connected.
|
---|
676 | // WSAEMFILE No more file descriptors are available.
|
---|
677 | // WSAEOPNOTSUPP The referenced socket is not of a type that
|
---|
678 | // supports the listen operation.
|
---|
679 |
|
---|
680 | // get a text version of the error number
|
---|
681 | char errstr[256];
|
---|
682 |
|
---|
683 | switch (err) {
|
---|
684 | case WSASYSNOTREADY: strcpy(errstr, "WSASYSNOTREADY");
|
---|
685 | break;
|
---|
686 | case WSAVERNOTSUPPORTED: strcpy (errstr, "WSAVERNOTSUPPORTED");
|
---|
687 | break;
|
---|
688 | case WSAEINVAL: strcpy (errstr, "WSAEINVAL");
|
---|
689 | break;
|
---|
690 | case WSAEPROTONOSUPPORT: strcpy (errstr, "WSAEPROTONOSUPPORT");
|
---|
691 | break;
|
---|
692 | case WSAEPROTOTYPE: strcpy (errstr, "WSAEPROTOTYPE");
|
---|
693 | break;
|
---|
694 | case WSAESOCKTNOSUPPORT: strcpy (errstr, "WSAESOCKTNOSUPPORT");
|
---|
695 | break;
|
---|
696 | case WSANOTINITIALISED: strcpy (errstr, "WSANOTINITIALISED");
|
---|
697 | break;
|
---|
698 | case WSAEFAULT: strcpy (errstr, "WSAEFAULT");
|
---|
699 | break;
|
---|
700 | case WSAEAFNOSUPPORT: strcpy (errstr, "WSAEAFNOSUPPORT");
|
---|
701 | break;
|
---|
702 | case WSAENOTSOCK: strcpy (errstr, "WSAENOTSOCK");
|
---|
703 | break;
|
---|
704 | case WSAEISCONN: strcpy (errstr, "WSAEISCONN");
|
---|
705 | break;
|
---|
706 | case WSAEOPNOTSUPP: strcpy (errstr, "WSAEOPNOTSUPP");
|
---|
707 | break;
|
---|
708 | case WSAENETDOWN: strcpy (errstr, "WSAENETDOWN");
|
---|
709 | break;
|
---|
710 | case WSAEADDRINUSE: strcpy (errstr, "WSAEADDRINUSE");
|
---|
711 | break;
|
---|
712 | case WSAEINPROGRESS: strcpy (errstr, "WSAEINPROGRESS");
|
---|
713 | break;
|
---|
714 | case WSAENOBUFS: strcpy (errstr, "WSAENOBUFS");
|
---|
715 | break;
|
---|
716 | case WSAEMFILE: strcpy (errstr, "WSAEMFILE");
|
---|
717 | break;
|
---|
718 | default: sprintf (errstr, "WSA ERROR: %i", err);
|
---|
719 | break;
|
---|
720 | }
|
---|
721 |
|
---|
722 | // create a nice error message
|
---|
723 | char message[2048];
|
---|
724 |
|
---|
725 | switch (err) {
|
---|
726 | case WSAEADDRINUSE:
|
---|
727 | // couldn't bind socket
|
---|
728 | sprintf (message, "Could not find a free socket.", errstr);
|
---|
729 | break;
|
---|
730 |
|
---|
731 | default:
|
---|
732 | // cannot init winsock
|
---|
733 | sprintf (message, "Could not initialize the network\n"
|
---|
734 | " (Reason: %s).", errstr);
|
---|
735 | break;
|
---|
736 | }
|
---|
737 |
|
---|
738 | strcat (message, "\n\n"
|
---|
739 | // no static library for this collection
|
---|
740 | // "You will still be able to use the static version of this\n"
|
---|
741 | // "collection, however, searching will be unavailable.");
|
---|
742 | "Please submit a bug report using the support.htm file\n"
|
---|
743 | "on the CD-ROM.");
|
---|
744 |
|
---|
745 | MessageBox (NULL, message, "Greestone Digital Library Software", MB_OK);
|
---|
746 | }
|
---|
747 |
|
---|
748 | return (err == 0);
|
---|
749 | }
|
---|
750 |
|
---|
751 |
|
---|
752 | void log_computer_info () {
|
---|
753 | char tmpstr[1024];
|
---|
754 |
|
---|
755 | // get various information about this computer
|
---|
756 | if (gsdl_keep_log || gsdl_show_console) {
|
---|
757 | // get operating system information
|
---|
758 | OSVERSIONINFO osver;
|
---|
759 | osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
---|
760 |
|
---|
761 | if (GetVersionEx(&osver)) {
|
---|
762 | if (osver.dwPlatformId == VER_PLATFORM_WIN32s) {
|
---|
763 | log_message ("Platform: win32s\n");
|
---|
764 | } else if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
|
---|
765 | log_message ("Platform: windows 95\n");
|
---|
766 | } else if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
---|
767 | log_message ("Platform: windows NT\n");
|
---|
768 | }
|
---|
769 |
|
---|
770 | sprintf (tmpstr, "MajorVersion: %i\n", (int)osver.dwMajorVersion);
|
---|
771 | log_message(tmpstr);
|
---|
772 | sprintf (tmpstr, "MinorVersion: %i\n", (int)osver.dwMinorVersion);
|
---|
773 | log_message(tmpstr);
|
---|
774 | sprintf (tmpstr, "BuildNumber: %i\n", (int)osver.dwBuildNumber);
|
---|
775 | log_message(tmpstr);
|
---|
776 | sprintf (tmpstr, "CSDVersion: %s\n\n", osver.szCSDVersion);
|
---|
777 | log_message(tmpstr);
|
---|
778 | }
|
---|
779 |
|
---|
780 | // get memory information
|
---|
781 | MEMORYSTATUS memstatus;
|
---|
782 | memstatus.dwLength = sizeof(MEMORYSTATUS);
|
---|
783 | GlobalMemoryStatus(&memstatus);
|
---|
784 |
|
---|
785 | sprintf (tmpstr, "TotalPhys: %i Meg\n", (int)(memstatus.dwTotalPhys/1024/1024));
|
---|
786 | log_message (tmpstr);
|
---|
787 | sprintf (tmpstr, "AvailPhys: %i Meg\n", (int)(memstatus.dwAvailPhys/1024/1024));
|
---|
788 | log_message (tmpstr);
|
---|
789 | sprintf (tmpstr, "TotalPageFile: %i Meg\n", (int)(memstatus.dwTotalPageFile/1024/1024));
|
---|
790 | log_message (tmpstr);
|
---|
791 | sprintf (tmpstr, "AvailPageFile: %i Meg\n", (int)(memstatus.dwAvailPageFile/1024/1024));
|
---|
792 | log_message (tmpstr);
|
---|
793 | sprintf (tmpstr, "TotalVirtual: %i Meg\n", (int)(memstatus.dwTotalVirtual/1024/1024));
|
---|
794 | log_message (tmpstr);
|
---|
795 | sprintf (tmpstr, "AvailVirtual: %i Meg\n\n", (int)(memstatus.dwAvailVirtual/1024/1024));
|
---|
796 | log_message (tmpstr);
|
---|
797 |
|
---|
798 | // log the version number
|
---|
799 | log_message("GSDL version: " VERSIONSTRING "\n");
|
---|
800 | }
|
---|
801 |
|
---|
802 | }
|
---|
803 |
|
---|
804 |
|
---|
805 | int __stdcall WinMain(HINSTANCE Instance, HINSTANCE /*PrevInstance*/, LPSTR CmdLineStr, int /*CmdShow*/) {
|
---|
806 | HWND MainWindow; MSG Message; WNDCLASS MainClass;
|
---|
807 |
|
---|
808 | //Create a window class
|
---|
809 | MainClass.style = CS_HREDRAW | CS_VREDRAW;
|
---|
810 | MainClass.lpfnWndProc = WndProc;
|
---|
811 | MainClass.cbClsExtra = 0;
|
---|
812 | MainClass.cbWndExtra = 0;
|
---|
813 | MainClass.hInstance = Instance;
|
---|
814 | MainClass.hIcon = LoadIcon(Instance, MAKEINTRESOURCE(TRAY_ICON));
|
---|
815 | MainClass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
---|
816 | MainClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
|
---|
817 | MainClass.lpszMenuName = MAKEINTRESOURCE(Main_Menu);
|
---|
818 | MainClass.lpszClassName = "Greenstone Digital Library Software";
|
---|
819 | if (!RegisterClass(&MainClass))
|
---|
820 | return 0;
|
---|
821 |
|
---|
822 | // Load various bitmaps
|
---|
823 | coltitlebitmap = LoadBitmap (Instance, MAKEINTRESOURCE(GSDL_COL_TITLE));
|
---|
824 | logobitmap= LoadBitmap (Instance, MAKEINTRESOURCE(GSDL_LOGO));
|
---|
825 |
|
---|
826 | // Create the main window
|
---|
827 | MainWindow = CreateWindow("Greenstone Digital Library Software",
|
---|
828 | "Greenstone Digital Library Software",
|
---|
829 | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
|
---|
830 | WS_MINIMIZEBOX,
|
---|
831 | CW_USEDEFAULT, CW_USEDEFAULT,
|
---|
832 | MAINWINDOWWIDTH + WASTEWIDTH,
|
---|
833 | MAINWINDOWHEIGHT + WASTEHEIGHT,
|
---|
834 | NULL, NULL, Instance, NULL);
|
---|
835 |
|
---|
836 | text_rect.left = 0;
|
---|
837 | text_rect.top = VERSIONY+VERSIONHEIGHT + 5;
|
---|
838 | text_rect.right = MAINWINDOWWIDTH;
|
---|
839 | text_rect.bottom = MAINWINDOWHEIGHT-RESTHEIGHT - 1;
|
---|
840 |
|
---|
841 | window_state = undefined_window;
|
---|
842 |
|
---|
843 | ShowWindow(MainWindow, SW_SHOW);
|
---|
844 | set_location(CmdLineStr);
|
---|
845 |
|
---|
846 | // get ready to draw the main window
|
---|
847 | RECT windowRect;
|
---|
848 | GetClientRect (MainWindow, &windowRect);
|
---|
849 | HDC pdc = GetDC (MainWindow);
|
---|
850 |
|
---|
851 | // retrieve and save the text metrics
|
---|
852 | TEXTMETRIC tm;
|
---|
853 | GetTextMetrics(pdc, &tm);
|
---|
854 | line_spacing = tm.tmHeight + tm.tmExternalLeading;
|
---|
855 | GSDL_Window = MainWindow;
|
---|
856 |
|
---|
857 | // draw the main window containing an init message
|
---|
858 | infostring = strinit;
|
---|
859 | paint_window (pdc, windowRect);
|
---|
860 | DWORD lastcheck = GetTickCount();
|
---|
861 |
|
---|
862 | // init various modules
|
---|
863 | read_settings (0); // don't know if netscape is needed at this point
|
---|
864 |
|
---|
865 | // attempt to initialise the network
|
---|
866 | // we do this first now as gsdl_init
|
---|
867 | // needs networking initialized to
|
---|
868 | // set httpprefix - Stefan.
|
---|
869 | // -- gsdl_init doesn't currently set httpprefix,
|
---|
870 | // it did for a brief time when I was using some
|
---|
871 | // scary html that didn't like relative links
|
---|
872 | have_networking = initnetwork (Instance, MainWindow);
|
---|
873 | if (!have_networking) {
|
---|
874 | MessageBox(NULL,
|
---|
875 | "Failed to initialize networking.",
|
---|
876 | "Greenstone Digital Library Software",MB_OK|MB_SYSTEMMODAL);
|
---|
877 | exit (0); // there is no static library for this collection
|
---|
878 | }
|
---|
879 |
|
---|
880 | if (!gsdl_init()) // quit if can't initialise the library correctly
|
---|
881 | exit (0);
|
---|
882 | initstartbrowser();
|
---|
883 | log_computer_info ();
|
---|
884 |
|
---|
885 | // show the initialising message for at least 1 second
|
---|
886 | while (DiffTickCounts (lastcheck, GetTickCount()) < 1000) {
|
---|
887 | Sleep (1);
|
---|
888 | }
|
---|
889 |
|
---|
890 | // if autoenter is enabled attempt to start a browser
|
---|
891 | if (have_networking && gsdl_auto_enter) {
|
---|
892 | infostring = strsb;
|
---|
893 | paint_window (pdc, windowRect);
|
---|
894 | lastcheck = GetTickCount();
|
---|
895 | if (enter_library (MainWindow) && !gsdl_show_console) {
|
---|
896 | // stay maximised for at least 1 second
|
---|
897 | while (DiffTickCounts (lastcheck, GetTickCount()) < 1000) Sleep (1);
|
---|
898 | ShowWindow(MainWindow,SW_MINIMIZE);
|
---|
899 | }
|
---|
900 | }
|
---|
901 |
|
---|
902 | // remove the last info message
|
---|
903 | infostring = strnothing;
|
---|
904 | paint_window (pdc, windowRect);
|
---|
905 |
|
---|
906 | // add the "enter library" button
|
---|
907 | GoButton = CreateWindow(
|
---|
908 | "BUTTON", // predefined class
|
---|
909 | "Enter Library", // button text
|
---|
910 | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles
|
---|
911 | ENTERBUTTONX, // starting x position
|
---|
912 | ENTERBUTTONY, // starting y position
|
---|
913 | ENTERBUTTONWIDTH, // button width
|
---|
914 | ENTERBUTTONHEIGHT, // button height
|
---|
915 | MainWindow, // parent window
|
---|
916 | NULL, // No menu
|
---|
917 | Instance,
|
---|
918 | NULL); // pointer not needed
|
---|
919 |
|
---|
920 | if (have_networking) statusstring = strenterlib;
|
---|
921 | else statusstring = strenterstaticlib;
|
---|
922 | paint_window (pdc, windowRect);
|
---|
923 |
|
---|
924 | // release the DC used to display the init messages
|
---|
925 | ReleaseDC (MainWindow, pdc);
|
---|
926 |
|
---|
927 | //Message loop
|
---|
928 | lastcheck = GetTickCount();
|
---|
929 | int seenbrowser = 0; // if we see a browser then it disappears
|
---|
930 | // we will ask if they want to close the
|
---|
931 | // the library down
|
---|
932 | char last_gsdl_browser_exe[MAX_FILENAME_SIZE]; // need to notice when the
|
---|
933 | // browser setting changes
|
---|
934 | strcpy (last_gsdl_browser_exe, gsdl_browser_exe);
|
---|
935 |
|
---|
936 | for (;;) {
|
---|
937 | if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) {
|
---|
938 | if (Message.message == WM_QUIT) break;
|
---|
939 | TranslateMessage(&Message); /* translate keyboard messages */
|
---|
940 | DispatchMessage(&Message); /* return control to Windows NT */
|
---|
941 |
|
---|
942 | } else {
|
---|
943 | if (DiffTickCounts (lastcheck, GetTickCount()) > 500) {
|
---|
944 | // make sure the browser hasn't changed
|
---|
945 | if (strcmp (last_gsdl_browser_exe, gsdl_browser_exe) != 0) {
|
---|
946 | seenbrowser = 0;
|
---|
947 | strcpy (last_gsdl_browser_exe, gsdl_browser_exe);
|
---|
948 | }
|
---|
949 |
|
---|
950 | // do check
|
---|
951 | lastcheck = GetTickCount();
|
---|
952 | if (browserrunning(gsdl_browser_exe) == NO_ERROR) {
|
---|
953 | // we were able to connect to a browser
|
---|
954 | seenbrowser = 1;
|
---|
955 |
|
---|
956 | // see if the enter library button has been pressed
|
---|
957 | // with nothing happening for 20 seconds
|
---|
958 | if ((enterlib_libaccessnum >= 0) &&
|
---|
959 | (enterlib_libaccessnum == libaccessnum) &&
|
---|
960 | (DiffTickCounts (enterlib_time, GetTickCount()) > 20000)) {
|
---|
961 | // something could be wrong!! (most likely cause is a proxy)
|
---|
962 | MessageBox(NULL,
|
---|
963 | "Your browser does not seem to be responding to the 'Enter Library'\n"
|
---|
964 | "request. Try turning off all proxy servers in your browser settings.",
|
---|
965 | "Greenstone Digital Library Software",MB_OK|MB_SYSTEMMODAL);
|
---|
966 | enterlib_libaccessnum = -1;
|
---|
967 | }
|
---|
968 |
|
---|
969 |
|
---|
970 | } else {
|
---|
971 | // no browser was found
|
---|
972 | if (seenbrowser) {
|
---|
973 | // we have seen a browser in the past
|
---|
974 | if (MessageBox(NULL,
|
---|
975 | "The Greenstone Digital Library software has noticed that you\n"
|
---|
976 | "shut down your browser. Would you also like to shut down the\n"
|
---|
977 | "Greenstone Digital Library software?",
|
---|
978 | "Greenstone Digital Library Software",MB_YESNO|MB_SYSTEMMODAL) == IDYES)
|
---|
979 | PostMessage(MainWindow,WM_CLOSE,0,0);
|
---|
980 | }
|
---|
981 | seenbrowser = 0;
|
---|
982 | }
|
---|
983 | }
|
---|
984 |
|
---|
985 | Sleep (1); // millisecond
|
---|
986 | }
|
---|
987 | }
|
---|
988 |
|
---|
989 | return Message.wParam;
|
---|
990 | }
|
---|