source: trunk/gsinstaller/gsinstall.cpp@ 1581

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

Added icon for uninstallation in the program group.

  • 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 // open the log for writing
353 FilePath *logPath = new FilePath(this->destinationPath->pathString(), "install.log");
354 this->openLog(logPath->pathString(), true);
355 delete logPath;
356}
357
358bool GSInstall::setUninstall()
359{
360 char tempPathStr[MAX_PATH];
361
362 // if we failed to get the Windows temporary directory, abort
363 if (GetTempPath(MAX_PATH, tempPathStr) == 0)
364 {
365 // TODO: abort!
366 return false;
367 }
368
369 FilePath tempPath(tempPathStr);
370
371 // if we are not running in the Windows temporary directory, copy this exe
372 // and the installation log to the temporary directory and run them there
373 MessageBox(0, tempPath.cString(), this->sourcePath->cString(), MB_OK);
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->openLog(logPath->pathString(), false);
398 delete logPath;
399
400 return true;
401}
402
403void GSInstall::uninstall()
404{
405 FilePath *iniPath;
406 string command;
407 stringArray params;
408
409 this->manifest = new gsManifest(*this); // get a manifest manager
410
411 iniPath = new FilePath(this->collectPath->pathString(), "gsdl.ini");
412 gsProfile gsdlProfile(*this, iniPath->pathString());
413
414 while ((command = this->popCommand(params)) != "")
415 {
416 if (!this->manifest->undoAction(command, params))
417 {
418 if (!gsdlProfile.undoAction(command, params))
419 {
420 if (!this->gsRegister->undoAction(command, params))
421 {
422 if (!this->progman->undoAction(command, params))
423 {
424 }
425 }
426 }
427 }
428 }
429}
430
431/**
432 * Collate the manifest for installation
433 */
434void GSInstall::setManifest()
435{
436 if (this->installExe)
437 {
438 this->manifest->selectGroup("library", *this->destinationPath);
439 }
440 if (this->installFullVolume)
441 {
442 this->manifest->selectGroup("collection", *this->dataDestPath);
443 }
444 else
445 {
446 this->manifest->selectGroup("database", *this->dataDestPath);
447 }
448}
449
450/**
451 * Update the program manager/explorer shell with icons, groups etc for this
452 * collection/application
453 */
454bool GSInstall::updateProgman()
455{
456 string groupName;
457
458 // if we managed to get a connection to the program manager (or explorer
459 // shell) then do the requisite updates
460 if (this->progman->connect())
461 {
462 // get group name from folders
463 groupName = this->configFile->getString("ProgramGroupName");
464 if (groupName == "")
465 {
466 // TODO: error handling
467 this->progman->disconnect();
468 return false;
469 }
470
471 // add the group
472 if (!this->progman->addProgramGroup(groupName))
473 {
474 this->progman->disconnect();
475 return false;
476 }
477
478 // add a "server" icon
479 FilePath libraryPath(this->destinationPath->pathString(), "library.exe");
480 if (!this->progman->addIcon(groupName, "Library", libraryPath.pathString(), ""))
481 {
482 // assume that it may be there already
483 }
484
485 // check for server existence
486 // FilePath serverPath(this->destinationPath->pathString(), "server.exe");
487 // if (serverPath.exists())
488 // {
489 // if (!this->progman->addIcon(groupName, "Server", serverPath.pathString(), ""))
490 // {
491 // assume that it may be there already
492 // }
493 // }
494
495 FilePath readMePath(this->destinationPath->pathString(), "readme.txt");
496 if (!this->progman->addIcon(groupName, "ReadMe", readMePath.pathString(), ""))
497 {
498 }
499
500 FilePath supportPath(this->destinationPath->pathString(), "support.html");
501 if (!this->progman->addIcon(groupName, "Technical Support", supportPath.pathString(), ""))
502 {
503 }
504
505 FilePath uninstallPath(this->destinationPath->pathString(), "gssetup.exe");
506 FilePath logPath(this->destinationPath->pathString(), "install.log");
507 if (!this->progman->addIcon(groupName, "Uninstall", uninstallPath.pathString() + " -u " + logPath.pathString(), ""))
508 {
509 }
510
511 // disconnect from program manager
512 this->progman->disconnect();
513 }
514 return true;
515}
516
517/**
518 * Update the profile (ini) files associated with the program; these changes
519 * must be made after copying to files in the destination/executable folders
520 * as we can't write to CD-ROM (or at least we shouldn't - the install would
521 * become tainted).
522 */
523bool GSInstall::updateProfiles()
524{
525 FilePath *exePath;
526 FilePath *dataPath;
527 FilePath *iniPath;
528
529 // if we're installing the exe, then the exe path leads to the destination
530 // folder of this installation sequence; if not, then we pick it up from
531 // the existing location of that folder
532 if (this->installExe)
533 {
534 exePath = this->destinationPath;
535 }
536 else
537 {
538 exePath = this->collectPath;
539 }
540 iniPath = new FilePath(exePath->pathString(), "gsdl.ini");
541
542 // TODO: check if this 'if' structure is correct; suspect that it isn't quite
543 // as we may not be installing the volume, but exe etc individually;
544 // may be okay now but not future proof; also the destination directory
545 // may or may not be tied to the exe directory if that existed already.
546 // This all needs investigating
547 if (this->installVolume)
548 {
549 // Manufacture the appropriate section name now; an equivalent string
550 // is also constructed
551 string volumeSectionString = this->configFile->getString("CollectionName") +
552 "#" + this->configFile->getString("CollectionVolume");
553
554 // if we're installing the full data for the collection, then take the
555 // data path to be at the selected destination directory for the collection
556 // files; otherwise take the data path to be on the CD/distribution media
557 if (this->installFullVolume)
558 {
559 dataPath = this->dataDestPath;
560 }
561 else
562 {
563 dataPath = this->gsdlSourcePath;
564 }
565
566 // create a profile object to write to the gsdl.ini file
567 gsProfile gsdlProfile(*this, iniPath->pathString());
568
569 // if installing the executable, add the database and greenstone home
570 // directories
571 if (this->installExe)
572 {
573 // set the correct exe entries in gsdl.ini (in the gsdl section)
574 gsdlProfile.writeString("gsdl", "gsdlhome", dataPath->pathString());
575 gsdlProfile.writeString("gsdl", "gdbmhome", this->dataDestPath->pathString());
576 }
577
578 // set the correct collection volume entries in gsdl.ini
579 if (this->installVolume)
580 {
581 // note the collection in the general gsdl section; and add the undo item too
582 gsdlProfile.ensureListMember("gsdl", gsdl_COLLIST, volumeSectionString);
583
584 // note the volume data in its own section
585 gsdlProfile.writeString(volumeSectionString, "gsdlhome", dataPath->pathString());
586 gsdlProfile.writeString(volumeSectionString, "gdbmhome", this->dataDestPath->pathString());
587 gsdlProfile.writeString(volumeSectionString, "staticpath", dataPath->pathString());
588 }
589 }
590
591 // clean up
592 delete iniPath;
593
594 return true;
595}
596
597/**
598 * Ensure that we've installed the very latest setup executable @ the destination/
599 * greenstone folder
600 */
601bool GSInstall::updateSetupExe()
602{
603 FilePath *destExePath;
604 FilePath srcExeFile(*this->sourcePath, "gssetup.exe");
605
606 if (this->installExe)
607 {
608 destExePath = this->destinationPath;
609 }
610 else
611 {
612 destExePath = this->collectPath;
613 }
614 FilePath destExeFile(*destExePath, "gssetup.exe");
615
616 if (!CopyFile(srcExeFile.cString(), destExeFile.cString(), false))
617 {
618 return false;
619 }
620 return true;
621}
622
623bool GSInstall::installNetscape()
624{
625 FilePath netscape32Path(this->sourcePath->pathString(), "netscape\\n32e405.exe");
626 FilePath netscape16Path(this->sourcePath->pathString(), "netscape\\n16e405.exe");
627
628 launchApp launchNetscape(netscape32Path);
629 launchNetscape.platformApp(gsPlatform_WINDOWS32S, netscape16Path);
630 if (launchNetscape.run(true, 1,
631 "This library is displayed using a web browser. If you don't "
632 "currently have a web browser installed on your machine you may "
633 "install the Netscape 4.05 browser now.\n\n"
634 "Note that if your current browser was provided by your internet "
635 "service provider, you should install Netscape in a different "
636 "directory.\n\n"
637 "Would you like to install the Netscape 4.05 browser now?",
638 "Greenstone Installer", false) < 0)
639 {
640 MessageBox(0, "Error", app_name, MB_OK);
641 return false;
642 }
643 return true;
644}
645
646FilePath *GSInstall::collectionPath()
647{
648 return this->collectPath;
649}
650
651FilePath *GSInstall::installPath()
652{
653 return this->installToPath;
654}
655
656void GSInstall::addSelectedDir(dirSelector *selector)
657{
658 this->selectedDirs.push_back(selector);
659}
660
661typedef struct
662{
663 dirSelector * dirSelect;
664} GSInstall_dirPathData;
665
666HGLOBAL loadDirBrowser()
667{
668 HRSRC resHdl;
669
670 resHdl = FindResource(app_instance, "MySaveAsDlg", RT_DIALOG);
671 return LoadResource(app_instance, resHdl);
672}
673
674void gsInstall_wizard_centre(HWND dialog)
675{
676 RECT rect;
677 int sx, sy;
678 int dx, dy;
679
680 gsInstall_getDesktopExt(&sx, &sy);
681 GetWindowRect(dialog, &rect);
682
683 dx = (sx - rect.right + rect.left) >> 1;
684 dy = (sy - rect.bottom + rect.top) >> 1;
685 SetWindowPos(dialog, 0, dx, dy, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
686}
687
688BOOL FAR PASCAL GSInstall_dlgproc(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam)
689{
690 static bool first = true; // static variable to hack the position of the
691 // whole wizard; note doing this in the wizard
692 // property sheet initialisation DOES NOT WORK
693
694 switch (Message)
695 {
696 case WM_INITDIALOG:
697 {
698 dirSelector *selector = (dirSelector *) ((PROPSHEETPAGE *) lParam)->lParam;
699
700 SetDlgItemText(Dialog, dirpath_PROMPT, selector->prompt);
701 if (selector->optPrompt != NULL)
702 {
703 SetDlgItemText(Dialog, dirpath_OPTION, selector->optPrompt);
704 EnableWindow(GetDlgItem(Dialog, dirpath_BROWSE), true); // was false
705 EnableWindow(GetDlgItem(Dialog, dirpath_PATH), true); // was false
706 }
707 else
708 {
709 ShowWindow(GetDlgItem(Dialog, dirpath_OPTION), SW_HIDE);
710 }
711 SetWindowLong(Dialog, GWL_USERDATA, ((PROPSHEETPAGE *) lParam)->lParam);
712 SetDlgItemText(Dialog, dirpath_PATH, selector->selectedPath());
713
714 // if this is the first time this function is called, then centre the
715 // wizard into the centre of our screen.
716 if (first)
717 {
718 gsInstall_wizard_centre(GetParent(Dialog));
719 first = false;
720 }
721 }
722 return TRUE;
723
724 case WM_COMMAND:
725 switch (LOWORD(wParam))
726 {
727 case dirpath_BROWSE:
728 ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->requestPath(Dialog, "Select Directory");
729 SetDlgItemText(Dialog, dirpath_PATH, ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->selectedPath());
730 break;
731
732 case dirpath_OPTION:
733 ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->setOption(IsDlgButtonChecked(Dialog, dirpath_OPTION));
734 if (HIWORD(wParam) == BN_CLICKED && false)
735 // don't do the enable/disable these days
736 {
737 EnableWindow(GetDlgItem(Dialog, dirpath_BROWSE), IsDlgButtonChecked(Dialog, dirpath_OPTION));
738 EnableWindow(GetDlgItem(Dialog, dirpath_PATH), IsDlgButtonChecked(Dialog, dirpath_OPTION));
739 }
740 break;
741 }
742 break;
743
744 case WM_NOTIFY:
745 switch (((LPNMHDR) lParam)->code)
746 {
747 case PSN_SETACTIVE:
748 {
749 dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
750
751 // bodge to set the dialogue path to the correct value
752 if (selector != rootSelector)
753 {
754 selector->setPath(rootSelector->selectedPath());
755 SetDlgItemText(Dialog, dirpath_PATH, selector->selectedPath());
756 }
757
758 if (selector->isFinal())
759 {
760 PropSheet_SetWizButtons(GetParent(Dialog), PSWIZB_BACK | PSWIZB_FINISH);
761 }
762 else
763 {
764 PropSheet_SetWizButtons(GetParent(Dialog), PSWIZB_BACK | PSWIZB_NEXT);
765 }
766 }
767 break;
768
769 case PSN_KILLACTIVE:
770 break;
771
772 case PSN_WIZNEXT:
773 {
774 // note the path from the dialog
775 dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
776 selector->setPathFromEdit(GetDlgItem(Dialog, dirpath_PATH));
777
778 // create a new FilePath object to check on the proposed destination
779 FilePath *path = new FilePath(selector->selectedPath());
780
781 // if the proposed destination doesn't exist, ask the user whether to
782 // create it now. TODO: actually create it if asked!
783 if (path->exists() == false)
784 {
785 char buffer[128];
786
787 sprintf(buffer, "Directory %s does not exist - create it?", selector->selectedPath());
788
789 // if the user cancelled that, then don't permit them to go to the next
790 // page of the wizard
791 if (MessageBox(0, buffer, app_name, MB_YESNO | MB_TOPMOST) == IDNO)
792 {
793 delete path;
794 SetWindowLong(Dialog, DWL_MSGRESULT, TRUE);
795 return TRUE;
796 }
797 }
798 delete path;
799 }
800 break;
801
802 case PSN_WIZFINISH:
803 {
804 // Finish the activity now
805 config_complete = true;
806 }
807 break;
808 }
809 break;
810 }
811 return FALSE;
812}
813
814void GSInstall_init_propertySheet(PROPSHEETPAGE &ppage, char *prompt, char *optPrompt,
815 char *title, GSInstall &installer, bool isFinal)
816{
817 GSInstall_dirPathData *data = new GSInstall_dirPathData;
818
819 // create the directory Selector
820 data->dirSelect = new dirSelector(prompt, optPrompt, title, installer.installPath());
821 data->dirSelect->setFinal(isFinal);
822
823 // if there is no extant root selector, make this it
824 if (rootSelector == NULL)
825 {
826 rootSelector = data->dirSelect;
827 }
828
829 // add this directory selector to the installer
830 installer.addSelectedDir(data->dirSelect);
831
832 // set up the rest of the page
833 ppage.dwSize = sizeof(PROPSHEETPAGE);
834 ppage.dwFlags = PSP_USETITLE;
835 ppage.hInstance = app_instance;
836 ppage.pszTemplate = "getDirPath";
837 ppage.pszIcon = 0;
838 ppage.pszTitle = app_name;
839 ppage.pfnDlgProc = (DLGPROC) GSInstall_dlgproc;
840 ppage.lParam = (LPARAM) data->dirSelect;
841 ppage.pfnCallback = NULL;
842}
843
844int CALLBACK GSInstall_wizardProc(HWND dialog, UINT Message, LPARAM lParameter)
845{
846 switch (Message)
847 {
848 case PSCB_INITIALIZED :
849 // Process PSCB_INITIALIZED
850 gsInstall_wizard_centre(dialog);
851 break ;
852
853 case PSCB_PRECREATE :
854 // Process PSCB_PRECREATE
855 break ;
856
857 default :
858 // Unknown message
859 break ;
860 }
861 return 0;
862}
863
864bool GSInstall_init_wizard(GSInstall &install)
865{
866 PROPSHEETHEADER pshead;
867 PROPSHEETPAGE ppage[2];
868 bool reply;
869
870 ZeroMemory(&pshead, sizeof(PROPSHEETHEADER));
871 pshead.dwSize = sizeof(PROPSHEETHEADER);
872 pshead.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_USEHICON | PSH_WIZARD;
873 pshead.hwndParent = app_window;
874 pshead.hInstance = app_instance;
875 pshead.hIcon = NULL;
876 pshead.pszCaption = "Greenstone Installer";
877 pshead.nPages = 2;
878 pshead.nStartPage = 0;
879 if (install.installExe == true)
880 {
881 pshead.ppsp = ppage;
882 }
883 else // cheat as the executable etc. is already installed
884 {
885 pshead.ppsp = &ppage[1];
886 }
887 pshead.pfnCallback = GSInstall_wizardProc;
888
889 GSInstall_init_propertySheet( ppage[0],
890 "Choose a directory to install your "
891 "GreenStone software to.", NULL,
892 "Select", install, false);
893 GSInstall_init_propertySheet(ppage[1],
894 "Choose a directory to install the collection "
895 "files to.\n\n"
896 "You can also choose to install all the collection "
897 "files onto your computer hard drive.\n\n"
898 "If you do this, you will not have to load the "
899 "CD-ROM each time you use your Greenstone software "
900 "but more of your hard disk will be used.\n\n"
901 "Some collection files must be installed on your "
902 "computer.\n\n",
903 "Install all collection files",
904 "Select", install, true);
905
906 reply = (PropertySheet (&pshead) >= 0);
907 return reply;
908}
909
910long FAR PASCAL GSInstallWindProc(HWND Window, WORD Message, WPARAM wParameter, LPARAM lParameter)
911{
912 long reply = 0;
913
914 switch(Message)
915 {
916 case WM_CREATE:
917 {
918 ShowWindow(Window, SW_MAXIMIZE);
919 }
920 break;
921
922 case WM_COMMAND:
923 break;
924
925 case WM_USER:
926 {
927 if (strstr(app_cmdLine, "-u") != NULL)
928 {
929 // uninstall action
930
931 // skip past the -u option itself
932 char *at = strstr(app_cmdLine, "-u");
933 at += strlen("-u");
934
935 // extract the log file path from the command line
936 while (*at == ' ')
937 {
938 at ++;
939 }
940 string logPathString(at);
941 FilePath logPath(logPathString);
942
943 GSInstall install(true);
944 // if we're running in the temporary directory, do the uninstall
945 if (install.setUninstall())
946 {
947 install.uninstall();
948
949 // close the log to write back all changes to the log; if the file
950 // will be deleted, it must be closed; copying may also fail, so it's
951 // safer to close it before doing either.
952 install.closeLog();
953
954 // if the install is empty, terminate all final items (currently the
955 // log and setup executables,
956 if (install.isEmpty())
957 {
958 // delete the log file
959 DeleteFile(logPath.cString());
960
961 // get it's parent to find where the gssetup executable will be
962 FilePath *logParent = logPath.parent();
963 FilePath uninstallPath(*logParent, "gssetup.exe");
964
965 // delete the gssetup executable
966 DeleteFile(uninstallPath.cString());
967
968 // dispose of the parent directory information
969 delete logParent;
970 }
971 // if not, then overwrite the original log with the modified one
972 else
973 {
974 // do nothing - should be changed already!
975 }
976 }
977 }
978 // install wizard
979 else
980 {
981 GSInstall install(false);
982 GSInstall_init_wizard(install);
983 if (config_complete == false)
984 {
985 MessageBox(0, "Install cancelled", app_name, MB_OK);
986 }
987 else
988 {
989 // configure the installation
990 install.setDestination();
991 install.setManifest();
992
993 // perform installation
994 install.copyFiles();
995 install.updateProgman();
996 install.updateRegistry();
997 install.updateProfiles();
998 install.updateSetupExe();
999
1000 // the log will need reopening (probably failed initially)
1001 install.reopenLog();
1002
1003 // close log
1004 install.closeLog();
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.