source: trunk/gsinstaller/gsinstall.cpp@ 1639

Last change on this file since 1639 was 1639, checked in by cs025, 24 years ago

Further fixes to get around bloopers in Visual C++; it wasn't resetting the
status flags for a stream on the reopening of a file, also had forgotten to read
the old log file when doing an additional installation.

  • Property svn:keywords set to Author Date Id Revision
File size: 30.4 KB
Line 
1#include <vector>
2#include <string>
3
4// use the standard namespace
5#if !defined (GSDL_NAMESPACE_BROKEN)
6#if defined(GSDL_USE_OBJECTSPACE)
7using namespace ospace::std;
8#else
9using namespace std;
10#endif
11#endif
12
13#include <stdlib.h>
14#include <stdio.h>
15#include <windows.h>
16#include <commctrl.h>
17
18#include "dirSelector.h"
19#include "common.h"
20#include "configFile.h"
21#include "File.h"
22#include "FilePath.h"
23#include "FileCopier.h"
24#include "launchApp.h"
25#include "unInstall.h"
26
27#include "gsRegistry.h"
28#include "gsPlatform.h"
29#include "gsProgman.h"
30#include "gsProfile.h"
31#include "gsManifest.h"
32
33char *app_cmdLine;
34static char app_name[] = "Greenstone Installer";
35HINSTANCE app_instance;
36HWND app_window;
37
38bool config_complete = false;
39
40dirSelector *rootSelector = NULL;
41
42typedef vector<dirSelector *> dirSelVector;
43
44class GSInstall : public installManager
45{
46private:
47 configureFile *configFile; // the installation configure file
48
49 FilePath *collectPath; // where the collection is currently installed
50 FilePath *installToPath; // the first cut at a destination folder
51 FilePath *sourcePath; // the root source folder
52 FilePath *gsdlSourcePath; // the gsdl folder in the source area
53 FilePath *destinationPath; // where the executables will be installed to
54 FilePath *dataDestPath; // where the collection data files will go
55
56 bool installVolume; // whether to install collection data
57 bool installFullVolume; // whether to install all collection data
58
59 dirSelVector selectedDirs; // configuration objects
60
61 gsPlatform platform; // platform information
62 gsRegistry *gsRegister; // registry
63 gsManifest *manifest; // manifest of files
64 gsProgramManager *progman; // program manager connection
65
66 void getSourcePath();
67 void getExistingInstall();
68public:
69 bool installExe;
70
71 GSInstall(bool uninstall);
72 FilePath *collectionPath();
73 FilePath *installPath();
74 bool copyFiles();
75 bool updateRegistry();
76 bool updateProfiles();
77 bool updateProgman();
78 bool updateSetupExe();
79 bool installNetscape();
80 void setDestination();
81 bool setUninstall();
82 void uninstall();
83 void setManifest();
84 void addSelectedDir(dirSelector *selector);
85};
86
87static string gsdl_DBHOME = "gdbmhome";
88static string gsdl_VLHOME = "gsdlhome";
89static string gsdl_STATIC = "staticpath";
90static string gsdl_COLLIST= "collections";
91
92void gsInstall_getDesktopExt(int *sx, int *sy)
93{
94 HDC dc = GetDC(GetDesktopWindow());
95 *sx = GetDeviceCaps(dc, HORZRES);
96 *sy = GetDeviceCaps(dc, VERTRES);
97 ReleaseDC(GetDesktopWindow(), dc);
98}
99
100/**
101 * Get various and nefarious details before we start trying an installation.
102 * The installation configuration file is read, we seek for an existing
103 * installation and reconfigure the default install settings appropriately.
104 * THe source path is also discovered.
105 */
106GSInstall::GSInstall(bool uninstall)
107 : installManager()
108{
109 // get the installation configuration file
110 this->configFile = new configureFile("install.cfg");
111
112 // set up "default" installation bits
113 this->installToPath = new FilePath("C:\\GSDL");
114 this->collectPath = NULL;
115 this->installExe = true; // we must install the exe files
116
117 // don't attempt this with windows 3.1
118 if (!this->platform.isWindows32s())
119 {
120 // get the registry
121 this->gsRegister = new gsRegistry(*this, *this->configFile);
122 }
123 else
124 {
125 // TODO: in windows 3.1 we can't use the register as it isn't fully/properly
126 // implemented; we must get the existing path information from elsewhere
127 this->gsRegister = new gsRegistry(*this, *this->configFile);
128 }
129
130 // assume for now we will install the full volume and the database
131 this->installVolume = true;
132 this->installFullVolume = true;
133
134 // detect any existing installation; unnecessary in uninstall (it's the
135 // "source" directory - see later
136 if (uninstall == false)
137 {
138 this->getExistingInstall();
139 }
140
141 // get where we are installing from
142 this->getSourcePath();
143
144 // if doing an uninstall we now know where the "uninstall" is
145 if (uninstall == true)
146 {
147 this->collectPath = this->sourcePath;
148 }
149
150 // get the manifest and program manager objects
151 if (uninstall)
152 {
153 this->manifest = new gsManifest(*this);
154 }
155 else
156 {
157 this->manifest = new gsManifest(*this, *this->sourcePath);
158 }
159 this->progman = new gsProgramManager(*this);
160
161 // tell manifest the number of bits in the raw windows environment; this may
162 // be required for loading certain modules such as winsock; the number of
163 // macros is over-the-top, but is more robust to unforeseen future requirements
164 /* if (platform.isWindows32s())
165 { this->manifest->expandMacro("WINBITS", "16");
166 this->manifest->expandMacro("WIN16", "16");
167 this->manifest->expandMacro("WIN32", "32");
168 }
169 else
170 { this->manifest->expandMacro("WINBITS", "32");
171 this->manifest->expandMacro("WIN16", "");
172 this->manifest->expandMacro("WIN32", "32");
173 }
174 */
175 // inform manifest of collection directory name
176 string colDir;
177 colDir = this->configFile->getString("CollectionDirName");
178 if (colDir != "")
179 {
180 this->manifest->expandMacro("COLDIRNAME", colDir);
181 }
182}
183
184/**
185 * Detect the presence of an existing installation
186 */
187void GSInstall::getExistingInstall()
188{
189 if (!this->platform.isWindows32s())
190 {
191 if (gsRegister->collectionInstalled())
192 {
193 // TODO: check if receptionist etc should be replaced or not
194
195 // TODO: check build version of the volume
196
197 // Get location of the library executable from the registry; this
198 // is thence used to get the location of gsdl.ini etc.
199 this->collectPath = this->gsRegister->collectionPath();
200 if (this->collectPath->pathString() != "")
201 {
202 this->installToPath = this->collectPath;
203 // we don't need to install the exe files
204 this->installExe = false;
205 }
206 }
207 }
208}
209
210/**
211 * get the source path for this install; we derive this from the path of this
212 * executable (the installer)
213 */
214void GSInstall::getSourcePath()
215{
216 static char filename[512];
217 FilePath *exePath;
218
219 // get the filepath of this executable
220 GetModuleFileName(0, filename, 512);
221 exePath = new FilePath(filename);
222
223 // get the parent (i.e. the folder containing this executable) for the source
224 // folder
225 this->sourcePath = exePath->parent();
226
227 // get the gsdl source path
228 this->gsdlSourcePath = new FilePath(this->sourcePath->pathString(), "gsdl");
229 delete exePath;
230}
231
232/**
233 * Controls the actual copying of the files; manifests of what to install
234 * are read in from a configuration on the hard drive - this should be basically
235 * greenstone dependent, and void of any collection-specific rubbish!
236 */
237bool GSInstall::copyFiles()
238{
239 // ensure that we have got the required destination and that we can write there
240 if (this->installExe)
241 {
242// this->destinationPath->ensureWriteablePath();
243 }
244
245 // ensure that the destination path for the collection itself is available
246 if (this->installVolume)
247 {
248// this->dataDestPath->ensureWriteablePath();
249 }
250
251 // do the copy
252 this->manifest->copy(this->gsdlSourcePath);
253
254 return true;
255}
256
257/**
258 * Fulfill registry update requirements; first the keys are set up, then they
259 * are filled with key item/value pairs.
260 */
261bool GSInstall::updateRegistry()
262{
263 // don't do registry stuff under windows 32s
264 if (this->platform.isWindows32s() && FALSE)
265 {
266 return true;
267 }
268
269 // ensure all pertinent keys already exist for this volume/collection
270 this->gsRegister->ensureKeysExist();
271
272 // now move on to add key items
273 if (this->installExe)
274 {
275 // FilePath *serverPath = new FilePath(this->destinationPath->pathString(), "server.exe");
276 FilePath *serverPath = new FilePath(this->destinationPath->pathString(), "library.exe");
277 FilePath *setupPath = new FilePath(this->destinationPath->pathString(), "gssetup.exe");
278 FilePath *logPath = new FilePath(this->destinationPath->pathString(), "install.log");
279 string exeKeyPath, uninstallCmd, uninstallKeyPath;
280 gsPlatform platform;
281
282 // store the normal collection key information
283 this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE,
284 this->gsRegister->collectKeyId(),
285 "library",
286 serverPath->pathString());
287
288 // This test is in fact for 9x or NT 4+; we're worried about the registry
289 // format, not about the shell as such
290 if (platform.isExplorerShell())
291 {
292 // get special app path key for windows 9x
293 exeKeyPath = this->gsRegister->exeKeyId("library.exe");
294
295 // ensure that the exe key exists
296 this->gsRegister->ensureKeyExists(HKEY_LOCAL_MACHINE, exeKeyPath);
297
298 // store default key for this application
299 this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE,
300 exeKeyPath,
301 "",
302 serverPath->pathString());
303
304 // store path for this application
305 this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE,
306 exeKeyPath,
307 "path",
308 this->destinationPath->pathString());
309
310 // create uninstall command line
311 uninstallCmd = setupPath->pathString() + " -u " + logPath->pathString();
312 uninstallKeyPath = this->gsRegister->uninstallKeyId(this->configFile->getString("CollectionName"));
313
314 // ensure uninstall key exists
315 this->gsRegister->ensureKeyExists(HKEY_LOCAL_MACHINE, uninstallKeyPath);
316
317 this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE, uninstallKeyPath,
318 "DisplayName",
319 this->configFile->getString("CollectionName"));
320 this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE, uninstallKeyPath,
321 "UninstallString", uninstallCmd);
322 }
323 delete setupPath;
324 delete serverPath;
325 delete logPath;
326 }
327
328 if (this->installVolume || this->installFullVolume)
329 {
330 // no actual key items are held in the volume key; for future use
331 }
332 return true;
333}
334
335/**
336 * Set the destination directory details
337 */
338void GSInstall::setDestination()
339{
340 // get configuration from the install wizard pages
341 this->destinationPath = new FilePath(this->selectedDirs[0]->selectedPath());
342 this->installFullVolume = this->selectedDirs[1]->getOption();
343 if (this->installFullVolume || true) // NB: always take path from 2nd dialog
344 {
345 this->dataDestPath = new FilePath(this->selectedDirs[1]->selectedPath());
346 }
347 else
348 {
349 this->dataDestPath = this->destinationPath;
350 }
351
352 // set the log for writing
353 FilePath *logPath = new FilePath(this->destinationPath->pathString(), "install.log");
354 this->setLogFile(logPath->pathString());
355 this->readLog();
356 delete logPath;
357}
358
359bool GSInstall::setUninstall()
360{
361 char tempPathStr[MAX_PATH];
362
363 // if we failed to get the Windows temporary directory, abort
364 if (GetTempPath(MAX_PATH, tempPathStr) == 0)
365 {
366 // TODO: abort!
367 return false;
368 }
369
370 FilePath tempPath(tempPathStr);
371
372 // if we are not running in the Windows temporary directory, copy this exe
373 // and the installation log to the temporary directory and run them there
374 if (*this->sourcePath != tempPath)
375 {
376 // copy this and install.log to temporary directory and restart
377 FilePath exePath(*this->sourcePath, "gssetup.exe");
378 FilePath logPath(*this->sourcePath, "install.log");
379
380 FilePath exeDest(tempPath, "gssetup.exe");
381 FilePath logDest(tempPath, "install.log");
382
383 CopyFile(exePath.cString(), exeDest.cString(), false);
384 CopyFile(logPath.cString(), logDest.cString(), false);
385
386 // now run the gssetup in the temporary directory
387 launchApp launchUninstall(exeDest);
388 launchUninstall.setCommandLine(" -u " + logPath.pathString());
389 launchUninstall.run(false, 0, "", "", false);
390
391 return false;
392 }
393
394 // open the log for reading from the directory this exe is now in (which
395 // will in fact be the temporary directory as outlined above)
396 FilePath *logPath = new FilePath(this->sourcePath->pathString(), "install.log");
397 this->setLogFile(logPath->pathString());
398 this->readLog();
399 delete logPath;
400
401 return true;
402}
403
404void GSInstall::uninstall()
405{
406 FilePath *iniPath;
407 string command;
408 stringArray params;
409
410 this->manifest = new gsManifest(*this); // get a manifest manager
411
412 iniPath = new FilePath(this->collectPath->pathString(), "gsdl.ini");
413 gsProfile gsdlProfile(*this, iniPath->pathString());
414
415 while ((command = this->popCommand(params)) != "")
416 {
417 if (!this->manifest->undoAction(command, params))
418 {
419 if (!gsdlProfile.undoAction(command, params))
420 {
421 if (!this->gsRegister->undoAction(command, params))
422 {
423 if (!this->progman->undoAction(command, params))
424 {
425 }
426 }
427 }
428 }
429 }
430}
431
432/**
433 * Collate the manifest for installation
434 */
435void GSInstall::setManifest()
436{
437 if (this->installExe)
438 {
439 this->manifest->selectGroup("library", *this->destinationPath);
440 }
441 if (this->installFullVolume)
442 {
443 this->manifest->selectGroup("collection", *this->dataDestPath);
444 }
445 else
446 {
447 this->manifest->selectGroup("database", *this->dataDestPath);
448 }
449}
450
451/**
452 * Update the program manager/explorer shell with icons, groups etc for this
453 * collection/application
454 */
455bool GSInstall::updateProgman()
456{
457 string groupName;
458
459 // if we managed to get a connection to the program manager (or explorer
460 // shell) then do the requisite updates
461 if (this->progman->connect())
462 {
463 // get group name from folders
464 groupName = this->configFile->getString("ProgramGroupName");
465 if (groupName == "")
466 {
467 // TODO: error handling
468 this->progman->disconnect();
469 return false;
470 }
471
472 // add the group
473 if (!this->progman->addProgramGroup(groupName))
474 {
475 this->progman->disconnect();
476 return false;
477 }
478
479 // add a "server" icon
480 FilePath libraryPath(this->destinationPath->pathString(), "library.exe");
481 if (!this->progman->addIcon(groupName, "Library", libraryPath.pathString(), ""))
482 {
483 // assume that it may be there already
484 }
485
486 // check for server existence
487 // FilePath serverPath(this->destinationPath->pathString(), "server.exe");
488 // if (serverPath.exists())
489 // {
490 // if (!this->progman->addIcon(groupName, "Server", serverPath.pathString(), ""))
491 // {
492 // assume that it may be there already
493 // }
494 // }
495
496 FilePath readMePath(this->destinationPath->pathString(), "readme.txt");
497 if (!this->progman->addIcon(groupName, "ReadMe", readMePath.pathString(), ""))
498 {
499 }
500
501 FilePath supportPath(this->destinationPath->pathString(), "support.html");
502 if (!this->progman->addIcon(groupName, "Technical Support", supportPath.pathString(), ""))
503 {
504 }
505
506
507 FilePath uninstallPath(this->destinationPath->pathString(), "gssetup.exe");
508 FilePath logPath(this->destinationPath->pathString(), "install.log");
509 if (!this->progman->addIcon(groupName, "Uninstall", uninstallPath.pathString() + " -u " + logPath.pathString(), ""))
510 {
511 }
512
513 // disconnect from program manager
514 this->progman->disconnect();
515 }
516 return true;
517}
518
519/**
520 * Update the profile (ini) files associated with the program; these changes
521 * must be made after copying to files in the destination/executable folders
522 * as we can't write to CD-ROM (or at least we shouldn't - the install would
523 * become tainted).
524 */
525bool GSInstall::updateProfiles()
526{
527 FilePath *exePath;
528 FilePath *dataPath;
529 FilePath *iniPath;
530
531 // if we're installing the exe, then the exe path leads to the destination
532 // folder of this installation sequence; if not, then we pick it up from
533 // the existing location of that folder
534 if (this->installExe)
535 {
536 exePath = this->destinationPath;
537 }
538 else
539 {
540 exePath = this->collectPath;
541 }
542 iniPath = new FilePath(exePath->pathString(), "gsdl.ini");
543
544 // TODO: check if this 'if' structure is correct; suspect that it isn't quite
545 // as we may not be installing the volume, but exe etc individually;
546 // may be okay now but not future proof; also the destination directory
547 // may or may not be tied to the exe directory if that existed already.
548 // This all needs investigating
549 if (this->installVolume)
550 {
551 // Manufacture the appropriate section name now; an equivalent string
552 // is also constructed
553 string volumeSectionString = this->configFile->getString("CollectionName") +
554 "#" + this->configFile->getString("CollectionVolume");
555
556 // if we're installing the full data for the collection, then take the
557 // data path to be at the selected destination directory for the collection
558 // files; otherwise take the data path to be on the CD/distribution media
559 if (this->installFullVolume)
560 {
561 dataPath = this->dataDestPath;
562 }
563 else
564 {
565 dataPath = this->gsdlSourcePath;
566 }
567
568 // create a profile object to write to the gsdl.ini file
569 gsProfile gsdlProfile(*this, iniPath->pathString());
570
571 // if installing the executable, add the database and greenstone home
572 // directories
573 if (this->installExe)
574 {
575 // set the correct exe entries in gsdl.ini (in the gsdl section)
576 gsdlProfile.writeString("gsdl", "gsdlhome", dataPath->pathString());
577 gsdlProfile.writeString("gsdl", "gdbmhome", this->dataDestPath->pathString());
578 }
579
580 // set the correct collection volume entries in gsdl.ini
581 if (this->installVolume)
582 {
583 // note the collection in the general gsdl section; and add the undo item too
584 gsdlProfile.ensureListMember("gsdl", gsdl_COLLIST, volumeSectionString);
585
586 // note the volume data in its own section
587 gsdlProfile.writeString(volumeSectionString, "gsdlhome", dataPath->pathString());
588 gsdlProfile.writeString(volumeSectionString, "gdbmhome", this->dataDestPath->pathString());
589 gsdlProfile.writeString(volumeSectionString, "staticpath", dataPath->pathString());
590 }
591 }
592
593 // clean up
594 delete iniPath;
595
596 return true;
597}
598
599/**
600 * Ensure that we've installed the very latest setup executable @ the destination/
601 * greenstone folder
602 */
603bool GSInstall::updateSetupExe()
604{
605 FilePath *destExePath;
606 FilePath srcExeFile(*this->sourcePath, "gssetup.exe");
607
608 if (this->installExe)
609 {
610 destExePath = this->destinationPath;
611 }
612 else
613 {
614 destExePath = this->collectPath;
615 }
616 FilePath destExeFile(*destExePath, "gssetup.exe");
617
618 if (!CopyFile(srcExeFile.cString(), destExeFile.cString(), false))
619 {
620 return false;
621 }
622 return true;
623}
624
625bool GSInstall::installNetscape()
626{
627 FilePath netscape32Path(this->sourcePath->pathString(), "netscape\\n32e405.exe");
628 FilePath netscape16Path(this->sourcePath->pathString(), "netscape\\n16e405.exe");
629
630 launchApp launchNetscape(netscape32Path);
631 launchNetscape.platformApp(gsPlatform_WINDOWS32S, netscape16Path);
632 launchNetscape.platformApp(gsPlatform_WINDOWS, netscape16Path);
633 if (launchNetscape.run(true, 1,
634 "This library is displayed using a web browser. If you don't "
635 "currently have a web browser installed on your machine you may "
636 "install the Netscape 4.05 browser now.\n\n"
637 "Note that if your current browser was provided by your internet "
638 "service provider, you should install Netscape in a different "
639 "directory.\n\n"
640 "Would you like to install the Netscape 4.05 browser now?",
641 "Greenstone Installer", false) < 0)
642 {
643 MessageBox(0, "Error", app_name, MB_OK);
644 return false;
645 }
646 return true;
647}
648
649FilePath *GSInstall::collectionPath()
650{
651 return this->collectPath;
652}
653
654FilePath *GSInstall::installPath()
655{
656 return this->installToPath;
657}
658
659void GSInstall::addSelectedDir(dirSelector *selector)
660{
661 this->selectedDirs.push_back(selector);
662}
663
664typedef struct
665{
666 dirSelector * dirSelect;
667} GSInstall_dirPathData;
668
669HGLOBAL loadDirBrowser()
670{
671 HRSRC resHdl;
672
673 resHdl = FindResource(app_instance, "MySaveAsDlg", RT_DIALOG);
674 return LoadResource(app_instance, resHdl);
675}
676
677void gsInstall_wizard_centre(HWND dialog)
678{
679 RECT rect;
680 int sx, sy;
681 int dx, dy;
682
683 gsInstall_getDesktopExt(&sx, &sy);
684 GetWindowRect(dialog, &rect);
685
686 dx = (sx - rect.right + rect.left) >> 1;
687 dy = (sy - rect.bottom + rect.top) >> 1;
688 SetWindowPos(dialog, 0, dx, dy, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
689}
690
691BOOL FAR PASCAL GSInstall_dlgproc(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam)
692{
693 static bool first = true; // static variable to hack the position of the
694 // whole wizard; note doing this in the wizard
695 // property sheet initialisation DOES NOT WORK
696
697 switch (Message)
698 {
699 case WM_INITDIALOG:
700 {
701 dirSelector *selector = (dirSelector *) ((PROPSHEETPAGE *) lParam)->lParam;
702
703 SetDlgItemText(Dialog, dirpath_PROMPT, selector->prompt);
704 if (selector->optPrompt != NULL)
705 {
706 SetDlgItemText(Dialog, dirpath_OPTION, selector->optPrompt);
707 EnableWindow(GetDlgItem(Dialog, dirpath_BROWSE), true); // was false
708 EnableWindow(GetDlgItem(Dialog, dirpath_PATH), true); // was false
709 }
710 else
711 {
712 ShowWindow(GetDlgItem(Dialog, dirpath_OPTION), SW_HIDE);
713 }
714 SetWindowLong(Dialog, GWL_USERDATA, ((PROPSHEETPAGE *) lParam)->lParam);
715 SetDlgItemText(Dialog, dirpath_PATH, selector->selectedPath());
716
717 // if this is the first time this function is called, then centre the
718 // wizard into the centre of our screen.
719 if (first)
720 {
721 gsInstall_wizard_centre(GetParent(Dialog));
722 first = false;
723 }
724 }
725 return TRUE;
726
727 case WM_COMMAND:
728 switch (LOWORD(wParam))
729 {
730 case dirpath_BROWSE:
731 ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->requestPath(Dialog, "Select Directory");
732 SetDlgItemText(Dialog, dirpath_PATH, ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->selectedPath());
733 break;
734
735 case dirpath_OPTION:
736 ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->setOption(IsDlgButtonChecked(Dialog, dirpath_OPTION));
737 if (HIWORD(wParam) == BN_CLICKED && false)
738 // don't do the enable/disable these days
739 {
740 EnableWindow(GetDlgItem(Dialog, dirpath_BROWSE), IsDlgButtonChecked(Dialog, dirpath_OPTION));
741 EnableWindow(GetDlgItem(Dialog, dirpath_PATH), IsDlgButtonChecked(Dialog, dirpath_OPTION));
742 }
743 break;
744 }
745 break;
746
747 case WM_NOTIFY:
748 switch (((LPNMHDR) lParam)->code)
749 {
750 case PSN_SETACTIVE:
751 {
752 dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
753
754 // bodge to set the dialogue path to the correct value
755 if (selector != rootSelector)
756 {
757 selector->setPath(rootSelector->selectedPath());
758 SetDlgItemText(Dialog, dirpath_PATH, selector->selectedPath());
759 }
760
761 if (selector->isFinal())
762 {
763 PropSheet_SetWizButtons(GetParent(Dialog), PSWIZB_BACK | PSWIZB_FINISH);
764 }
765 else
766 {
767 PropSheet_SetWizButtons(GetParent(Dialog), PSWIZB_BACK | PSWIZB_NEXT);
768 }
769 }
770 break;
771
772 case PSN_KILLACTIVE:
773 break;
774
775 case PSN_WIZNEXT:
776 {
777 // note the path from the dialog
778 dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
779 selector->setPathFromEdit(GetDlgItem(Dialog, dirpath_PATH));
780
781 // create a new FilePath object to check on the proposed destination
782 FilePath *path = new FilePath(selector->selectedPath());
783
784 // if the proposed destination doesn't exist, ask the user whether to
785 // create it now. TODO: actually create it if asked!
786 if (path->exists() == false)
787 {
788 char buffer[128];
789
790 sprintf(buffer, "Directory %s does not exist - create it?", selector->selectedPath());
791
792 // if the user cancelled that, then don't permit them to go to the next
793 // page of the wizard
794 if (MessageBox(0, buffer, app_name, MB_YESNO | MB_TOPMOST) == IDNO)
795 {
796 delete path;
797 SetWindowLong(Dialog, DWL_MSGRESULT, TRUE);
798 return TRUE;
799 }
800 }
801 delete path;
802 }
803 break;
804
805 case PSN_WIZFINISH:
806 {
807 // Finish the activity now
808 config_complete = true;
809 }
810 break;
811 }
812 break;
813 }
814 return FALSE;
815}
816
817void GSInstall_init_propertySheet(PROPSHEETPAGE &ppage, char *prompt, char *optPrompt,
818 char *title, GSInstall &installer, bool isFinal)
819{
820 GSInstall_dirPathData *data = new GSInstall_dirPathData;
821
822 // create the directory Selector
823 data->dirSelect = new dirSelector(prompt, optPrompt, title, installer.installPath());
824 data->dirSelect->setFinal(isFinal);
825
826 // if there is no extant root selector, make this it
827 if (rootSelector == NULL)
828 {
829 rootSelector = data->dirSelect;
830 }
831
832 // add this directory selector to the installer
833 installer.addSelectedDir(data->dirSelect);
834
835 // set up the rest of the page
836 ppage.dwSize = sizeof(PROPSHEETPAGE);
837 ppage.dwFlags = PSP_USETITLE;
838 ppage.hInstance = app_instance;
839 ppage.pszTemplate = "getDirPath";
840 ppage.pszIcon = 0;
841 ppage.pszTitle = app_name;
842 ppage.pfnDlgProc = (DLGPROC) GSInstall_dlgproc;
843 ppage.lParam = (LPARAM) data->dirSelect;
844 ppage.pfnCallback = NULL;
845}
846
847int CALLBACK GSInstall_wizardProc(HWND dialog, UINT Message, LPARAM lParameter)
848{
849 switch (Message)
850 {
851 case PSCB_INITIALIZED :
852 // Process PSCB_INITIALIZED
853 gsInstall_wizard_centre(dialog);
854 break ;
855
856 case PSCB_PRECREATE :
857 // Process PSCB_PRECREATE
858 break ;
859
860 default :
861 // Unknown message
862 break ;
863 }
864 return 0;
865}
866
867bool GSInstall_init_wizard(GSInstall &install)
868{
869 PROPSHEETHEADER pshead;
870 PROPSHEETPAGE ppage[2];
871 bool reply;
872
873 ZeroMemory(&pshead, sizeof(PROPSHEETHEADER));
874 pshead.dwSize = sizeof(PROPSHEETHEADER);
875 pshead.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_USEHICON | PSH_WIZARD;
876 pshead.hwndParent = app_window;
877 pshead.hInstance = app_instance;
878 pshead.hIcon = NULL;
879 pshead.pszCaption = "Greenstone Installer";
880 pshead.nPages = 2;
881 pshead.nStartPage = 0;
882 if (install.installExe == true)
883 {
884 pshead.ppsp = ppage;
885 }
886 else // cheat as the executable etc. is already installed
887 {
888 pshead.ppsp = &ppage[1];
889 }
890 pshead.pfnCallback = GSInstall_wizardProc;
891
892 GSInstall_init_propertySheet( ppage[0],
893 "Choose a directory to install your "
894 "GreenStone software to.", NULL,
895 "Select", install, false);
896 GSInstall_init_propertySheet(ppage[1],
897 "Choose a directory to install the collection "
898 "files to.\n\n"
899 "You can also choose to install all the collection "
900 "files onto your computer hard drive.\n\n"
901 "If you do this, you will not have to load the "
902 "CD-ROM each time you use your Greenstone software "
903 "but more of your hard disk will be used.\n\n"
904 "Some collection files must be installed on your "
905 "computer.\n\n",
906 "Install all collection files",
907 "Select", install, true);
908
909 reply = (PropertySheet (&pshead) >= 0);
910 return reply;
911}
912
913long FAR PASCAL GSInstallWindProc(HWND Window, WORD Message, WPARAM wParameter, LPARAM lParameter)
914{
915 long reply = 0;
916
917 switch(Message)
918 {
919 case WM_CREATE:
920 {
921 ShowWindow(Window, SW_MAXIMIZE);
922 }
923 break;
924
925 case WM_COMMAND:
926 break;
927
928 case WM_USER:
929 {
930 if (strstr(app_cmdLine, "-u") != NULL)
931 {
932 // uninstall action
933
934 // skip past the -u option itself
935 char *at = strstr(app_cmdLine, "-u");
936 at += strlen("-u");
937
938 // extract the log file path from the command line
939 while (*at == ' ')
940 {
941 at ++;
942 }
943 string logPathString(at);
944 FilePath logPath(logPathString);
945
946 GSInstall install(true);
947 // if we're running in the temporary directory, do the uninstall
948 if (install.setUninstall())
949 {
950 install.uninstall();
951
952 // close the log to write back all changes to the log; if the file
953 // will be deleted, it must be closed; copying may also fail, so it's
954 // safer to close it before doing either.
955 install.recordLog();
956
957 // if the install is empty, terminate all final items (currently the
958 // log and setup executables,
959 if (install.isEmpty())
960 {
961 // delete the log file
962 DeleteFile(logPath.cString());
963
964 // get it's parent to find where the gssetup executable will be
965 FilePath *logParent = logPath.parent();
966 FilePath uninstallPath(*logParent, "gssetup.exe");
967
968 // delete the gssetup executable
969 DeleteFile(uninstallPath.cString());
970
971 // dispose of the parent directory information
972 delete logParent;
973 }
974 // if not, then overwrite the original log with the modified one
975 else
976 {
977 // do nothing - should be changed already!
978 }
979 }
980 }
981 // install wizard
982 else
983 {
984 GSInstall install(false);
985 GSInstall_init_wizard(install);
986 if (config_complete == false)
987 {
988 MessageBox(0, "Install cancelled", app_name, MB_OK);
989 }
990 else
991 {
992 // configure the installation
993 install.setDestination();
994 install.setManifest();
995
996 // perform installation
997 install.copyFiles();
998 install.updateProgman();
999 install.updateRegistry();
1000 install.updateProfiles();
1001 install.updateSetupExe();
1002
1003 // close log
1004 install.recordLog();
1005
1006 // do further actions
1007 install.installNetscape();
1008 }
1009 }
1010 DestroyWindow(Window);
1011 }
1012 break;
1013
1014 case WM_USER + 1:
1015 break;
1016
1017 case WM_CLOSE:
1018 /*if (!file_ischanged || IDCANCEL != file_query(Window, file_name))*/
1019 DestroyWindow(Window);
1020 return 0L;
1021
1022 case WM_DESTROY:
1023 {
1024 PostQuitMessage(0);
1025 }
1026 break;
1027
1028 default:
1029 return(DefWindowProc(Window, Message, wParameter, lParameter));
1030 }
1031 return reply;
1032}
1033
1034void GSInstall_init(HINSTANCE instance, int Show)
1035{
1036 int sx, sy;
1037
1038 gsInstall_getDesktopExt(&sx, &sy);
1039
1040 app_window = CreateWindow("GSInstall:Main", "GreenStone Installer",
1041 WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | CS_DBLCLKS,
1042 0, 0,
1043 sx, sy,
1044 NULL,
1045 NULL,
1046 app_instance,
1047 NULL);
1048
1049 ShowWindow(app_window, Show);
1050
1051 PostMessage(app_window, WM_USER, 0, 0L);
1052}
1053
1054void WinClassInit(void)
1055{
1056 WNDCLASS Class;
1057
1058 Class.lpszClassName = "GSInstall:Main";
1059 Class.hInstance = app_instance;
1060 Class.lpfnWndProc = (WNDPROC) GSInstallWindProc;
1061 Class.hCursor = LoadCursor(NULL, IDC_ARROW);
1062 Class.hIcon = NULL; //LoadIcon(app_instance, "GSInstall");
1063 Class.lpszMenuName = NULL;
1064 Class.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1);
1065 Class.style = 0;
1066 Class.cbClsExtra = 0;
1067 Class.cbWndExtra = 0;
1068 RegisterClass(&Class);
1069}
1070
1071int PASCAL WinMain(HINSTANCE Current,
1072 HINSTANCE Previous,
1073 LPSTR CmdLine,
1074 int CmdShow)
1075{
1076 MSG msg;
1077
1078 app_cmdLine = (char *) malloc(lstrlen(CmdLine) + 1);
1079 lstrcpy(app_cmdLine, CmdLine);
1080
1081 app_instance = Current;
1082 /* -- init application */
1083 if (!Previous)
1084 {
1085 WinClassInit();
1086 InitCommonControls();
1087 }
1088
1089 /* -- init instance */
1090 GSInstall_init(Current, CmdShow);
1091
1092 while (GetMessage(&msg, NULL, 0, 0))
1093 {
1094 TranslateMessage(&msg);
1095 DispatchMessage(&msg);
1096 }
1097 return (int) msg.wParam;
1098}
Note: See TracBrowser for help on using the repository browser.