1 | #include <vector>
|
---|
2 | #include <string>
|
---|
3 | using namespace std;
|
---|
4 |
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <stdio.h>
|
---|
7 | #include <windows.h>
|
---|
8 | #include <commctrl.h>
|
---|
9 |
|
---|
10 | #include "dirSelector.h"
|
---|
11 | #include "common.h"
|
---|
12 | #include "configFile.h"
|
---|
13 | #include "File.h"
|
---|
14 | #include "FilePath.h"
|
---|
15 | #include "FileCopier.h"
|
---|
16 | #include "launchApp.h"
|
---|
17 | #include "unInstall.h"
|
---|
18 |
|
---|
19 | #include "gsRegistry.h"
|
---|
20 | #include "gsPlatform.h"
|
---|
21 | #include "gsProgman.h"
|
---|
22 | #include "gsProfile.h"
|
---|
23 | #include "gsManifest.h"
|
---|
24 |
|
---|
25 | char * app_cmdLine;
|
---|
26 | static char app_name[] = "Greenstone Installer";
|
---|
27 | HINSTANCE app_instance;
|
---|
28 | HWND app_window;
|
---|
29 |
|
---|
30 | bool config_complete = false;
|
---|
31 | // static char app_tmptext[100] = "George";
|
---|
32 |
|
---|
33 | typedef vector<dirSelector *> dirSelVector;
|
---|
34 |
|
---|
35 | class GSInstall
|
---|
36 | { private:
|
---|
37 | configureFile * configFile;
|
---|
38 | FilePath * collectPath;
|
---|
39 | FilePath * installToPath;
|
---|
40 | FilePath * sourcePath;
|
---|
41 | FilePath * gsdlSourcePath;
|
---|
42 | FilePath * destinationPath;
|
---|
43 | FilePath * dataDestPath;
|
---|
44 | bool installExe;
|
---|
45 | bool installVolume;
|
---|
46 | bool installFullVolume;
|
---|
47 | gsPlatform platform;
|
---|
48 | unInstaller * unInstall;
|
---|
49 |
|
---|
50 | dirSelVector selectedDirs;
|
---|
51 |
|
---|
52 | gsRegistry * gsRegister;
|
---|
53 | gsManifest * manifest;
|
---|
54 |
|
---|
55 | void getSourcePath();
|
---|
56 | public:
|
---|
57 | GSInstall();
|
---|
58 | FilePath * collectionPath();
|
---|
59 | FilePath * installPath();
|
---|
60 | bool copyFiles();
|
---|
61 | bool updateRegistry();
|
---|
62 | bool updateProfiles();
|
---|
63 | bool updateProgman();
|
---|
64 | bool installNetscape();
|
---|
65 | void setDestination();
|
---|
66 | void setManifest();
|
---|
67 | void addSelectedDir(dirSelector *selector);
|
---|
68 | };
|
---|
69 |
|
---|
70 | static string gsdl_DBHOME = "gdbmhome";
|
---|
71 | static string gsdl_VLHOME = "gsdlhome";
|
---|
72 | static string gsdl_STATIC = "staticpath";
|
---|
73 | static string gsdl_COLLIST= "collections";
|
---|
74 |
|
---|
75 | void gsInstall_getDesktopExt(int *sx, int *sy)
|
---|
76 | {
|
---|
77 | HDC dc = GetDC(GetDesktopWindow());
|
---|
78 | *sx = GetDeviceCaps(dc, HORZRES);
|
---|
79 | *sy = GetDeviceCaps(dc, VERTRES);
|
---|
80 | ReleaseDC(GetDesktopWindow(), dc);
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Get various and nefarious details before we start trying an installation.
|
---|
85 | * The installation configuration file is read, we seek for an existing
|
---|
86 | * installation and reconfigure the default install settings appropriately.
|
---|
87 | * THe source path is also discovered.
|
---|
88 | */
|
---|
89 | GSInstall::GSInstall()
|
---|
90 | { gsPlatform platform;
|
---|
91 |
|
---|
92 | // get the installation configuration file
|
---|
93 | this->configFile = new configureFile("install.cfg");
|
---|
94 |
|
---|
95 | // initialise the pointers that we test later this fn.
|
---|
96 | this->unInstall = NULL;
|
---|
97 |
|
---|
98 | // don't attempt this with windows 3.1
|
---|
99 | if (!platform.isWindows32s() || TRUE)
|
---|
100 | { // get the registry
|
---|
101 | this->gsRegister = new gsRegistry(*this->configFile);
|
---|
102 |
|
---|
103 | // TODO: in windows 3.1 we can't use the register as it isn't fully/properly
|
---|
104 | // implemented; we must get the existing path information from elsewhere
|
---|
105 | if (gsRegister->collectionInstalled())
|
---|
106 | { // TODO: check if receptionist etc should be replaced or not
|
---|
107 |
|
---|
108 | // TODO: check build version of the volume
|
---|
109 |
|
---|
110 | // Get location of the library executable from the registry; this
|
---|
111 | // is thence used to get the location of gsdl.ini etc.
|
---|
112 | this->collectPath = this->gsRegister->collectionPath();
|
---|
113 | this->installToPath = this->collectPath;
|
---|
114 |
|
---|
115 | // TODO: if collectPath == NULL generate error
|
---|
116 |
|
---|
117 | // get uninstall information from destination location
|
---|
118 | FilePath *uninstallPath = new FilePath(this->collectPath->cString(), "uninstl.cfg");
|
---|
119 | this->unInstall = new unInstaller(uninstallPath->cString());
|
---|
120 | delete uninstallPath;
|
---|
121 |
|
---|
122 | // we don't need to install the exe files
|
---|
123 | this->installExe = false||true;
|
---|
124 | }
|
---|
125 | else
|
---|
126 | { this->installToPath = new FilePath("C:\\GSDL");
|
---|
127 | this->collectPath = NULL;
|
---|
128 | // we must install the exe files
|
---|
129 | this->installExe = true;
|
---|
130 | }
|
---|
131 | }
|
---|
132 | else
|
---|
133 | { // TODO: do windows 3.1 stuff here
|
---|
134 | this->installToPath = new FilePath("C:\\GSDL");
|
---|
135 | this->installExe = true;
|
---|
136 | this->collectPath = NULL;
|
---|
137 | }
|
---|
138 |
|
---|
139 | if (this->unInstall == NULL)
|
---|
140 | { this->unInstall = new unInstaller("");
|
---|
141 | }
|
---|
142 |
|
---|
143 | // assume for now we will install the full volume and the database
|
---|
144 | this->installVolume = true;
|
---|
145 | this->installFullVolume = true;
|
---|
146 |
|
---|
147 | // get where we are installing from
|
---|
148 | this->getSourcePath();
|
---|
149 |
|
---|
150 | // get the manifest
|
---|
151 | this->manifest = new gsManifest(*this->sourcePath);
|
---|
152 |
|
---|
153 | // tell manifest the number of bits in the raw windows environment; this may
|
---|
154 | // be required for loading certain modules such as winsock; the number of
|
---|
155 | // macros is over-the-top, but is more robust to unforeseen future requirements
|
---|
156 | /* if (platform.isWindows32s())
|
---|
157 | { this->manifest->expandMacro("WINBITS", "16");
|
---|
158 | this->manifest->expandMacro("WIN16", "16");
|
---|
159 | this->manifest->expandMacro("WIN32", "32");
|
---|
160 | }
|
---|
161 | else
|
---|
162 | { this->manifest->expandMacro("WINBITS", "32");
|
---|
163 | this->manifest->expandMacro("WIN16", "");
|
---|
164 | this->manifest->expandMacro("WIN32", "32");
|
---|
165 | }
|
---|
166 | */
|
---|
167 | // inform manifests of collection directory name
|
---|
168 | char *buffer;
|
---|
169 | this->configFile->get("CollectionDirName", &buffer);
|
---|
170 | this->manifest->expandMacro("COLDIRNAME", buffer);
|
---|
171 | delete buffer;
|
---|
172 | }
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * get the source path for this install; we derive this from the path of this
|
---|
176 | * executable (the installer)
|
---|
177 | */
|
---|
178 | void GSInstall::getSourcePath()
|
---|
179 | { static char filename[512];
|
---|
180 | FilePath *exePath;
|
---|
181 |
|
---|
182 | // get the filepath of this executable
|
---|
183 | GetModuleFileName(0, filename, 512);
|
---|
184 | exePath = new FilePath(filename);
|
---|
185 |
|
---|
186 | // get the parent (i.e. the folder containing this executable) for the source
|
---|
187 | // folder
|
---|
188 | this->sourcePath = exePath->parent();
|
---|
189 |
|
---|
190 | // get the gsdl source path
|
---|
191 | this->gsdlSourcePath = new FilePath(this->sourcePath->cString(), "gsdl");
|
---|
192 | delete exePath;
|
---|
193 | }
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * Controls the actual copying of the files; manifests of what to install
|
---|
197 | * are read in from a configuration on the hard drive - this should be basically
|
---|
198 | * greenstone dependent, and void of any collection-specific rubbish!
|
---|
199 | */
|
---|
200 | bool GSInstall::copyFiles()
|
---|
201 | { FileVector *fileList;
|
---|
202 |
|
---|
203 | // ensure that we have got the required destination and that we can write there
|
---|
204 | if (this->installExe)
|
---|
205 | { this->destinationPath->ensureWriteablePath();
|
---|
206 | }
|
---|
207 |
|
---|
208 | // ensure that the destination path for the collection itself is available
|
---|
209 | if (this->installVolume)
|
---|
210 | { this->dataDestPath->ensureWriteablePath();
|
---|
211 | }
|
---|
212 |
|
---|
213 | // do the copy
|
---|
214 | this->manifest->copy(this->gsdlSourcePath);
|
---|
215 |
|
---|
216 | return true;
|
---|
217 | }
|
---|
218 |
|
---|
219 | /**
|
---|
220 | * Fulfill registry update requirements; first the keys are set up, then they
|
---|
221 | * are filled with key item/value pairs.
|
---|
222 | */
|
---|
223 | bool GSInstall::updateRegistry()
|
---|
224 | { // don't do registry stuff under windows 32s
|
---|
225 | if (this->platform.isWindows32s() && FALSE)
|
---|
226 | { return true;
|
---|
227 | }
|
---|
228 |
|
---|
229 | // ensure all pertinent keys already exist for this volume/collection
|
---|
230 | this->gsRegister->ensureKeysExist();
|
---|
231 |
|
---|
232 | // now move on to add key items
|
---|
233 | if (this->installExe)
|
---|
234 | { FilePath *serverPath = new FilePath((char *) this->destinationPath->cString(), "server.exe");
|
---|
235 | char *exeKeyPath;
|
---|
236 | gsPlatform platform;
|
---|
237 |
|
---|
238 | // store the normal collection key information
|
---|
239 | this->gsRegister->storeKeyString( HKEY_LOCAL_MACHINE,
|
---|
240 | this->gsRegister->collectKeyId(),
|
---|
241 | "library",
|
---|
242 | serverPath->cString());
|
---|
243 |
|
---|
244 | // This test is in fact for 9x or NT 4+; we're worried about the registry
|
---|
245 | // format, not about the shell as such
|
---|
246 | if (platform.isExplorerShell())
|
---|
247 | { // get special app path key for windows 9x
|
---|
248 | exeKeyPath = this->gsRegister->exeKeyId("library.exe");
|
---|
249 |
|
---|
250 | // ensure that the exe key exists
|
---|
251 | this->gsRegister->ensureKeyExists(HKEY_LOCAL_MACHINE, exeKeyPath);
|
---|
252 |
|
---|
253 | // store default key for this application
|
---|
254 | this->gsRegister->storeKeyString( HKEY_LOCAL_MACHINE,
|
---|
255 | exeKeyPath,
|
---|
256 | NULL,
|
---|
257 | serverPath->cString());
|
---|
258 |
|
---|
259 | // store path for this application
|
---|
260 | this->gsRegister->storeKeyString( HKEY_LOCAL_MACHINE,
|
---|
261 | exeKeyPath,
|
---|
262 | "path",
|
---|
263 | this->destinationPath->cString());
|
---|
264 | // delete the windows 9x speciall app path key
|
---|
265 | delete exeKeyPath;
|
---|
266 |
|
---|
267 | // TODO: set up uninstall option
|
---|
268 | }
|
---|
269 | delete serverPath;
|
---|
270 | }
|
---|
271 |
|
---|
272 | if (this->installVolume || this->installFullVolume)
|
---|
273 | { // no actual key items are held in the volume key; for future use
|
---|
274 | }
|
---|
275 | return true;
|
---|
276 | }
|
---|
277 |
|
---|
278 | /**
|
---|
279 | * Set the destination directory details
|
---|
280 | */
|
---|
281 | void GSInstall::setDestination()
|
---|
282 | { this->destinationPath = new FilePath(this->selectedDirs[0]->selectedPath());
|
---|
283 | this->installFullVolume = this->selectedDirs[1]->getOption();
|
---|
284 | if (this->installFullVolume || true) // NB: always take path from 2nd dialog
|
---|
285 | { this->dataDestPath = new FilePath(this->selectedDirs[1]->selectedPath());
|
---|
286 | }
|
---|
287 | else
|
---|
288 | { this->dataDestPath = this->destinationPath;
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 | /**
|
---|
293 | * Collate the manifest for installation
|
---|
294 | */
|
---|
295 | void GSInstall::setManifest()
|
---|
296 | { if (this->installExe)
|
---|
297 | { this->manifest->selectGroup("library", this->destinationPath->pathString());
|
---|
298 | }
|
---|
299 | if (this->installFullVolume)
|
---|
300 | { this->manifest->selectGroup("collection", this->dataDestPath->pathString());
|
---|
301 | }
|
---|
302 | else
|
---|
303 | { this->manifest->selectGroup("database", this->dataDestPath->pathString());
|
---|
304 | }
|
---|
305 | }
|
---|
306 |
|
---|
307 | /**
|
---|
308 | * Update the program manager/explorer shell with icons, groups etc for this
|
---|
309 | * collection/application
|
---|
310 | */
|
---|
311 | bool GSInstall::updateProgman()
|
---|
312 | { gsProgramManager progman;
|
---|
313 | char * groupName = NULL;
|
---|
314 |
|
---|
315 | // if we managed to get a connection to the program manager (or explorer
|
---|
316 | // shell) then do the requisite updates
|
---|
317 | if (progman.connect())
|
---|
318 | { // get group name from folders
|
---|
319 | this->configFile->get("ProgramGroupName", &groupName);
|
---|
320 | if (groupName == NULL)
|
---|
321 | { // TODO: error handling
|
---|
322 | progman.disconnect();
|
---|
323 | delete groupName;
|
---|
324 | return false;
|
---|
325 | }
|
---|
326 |
|
---|
327 | // add the group
|
---|
328 | if (!progman.addProgramGroup(groupName))
|
---|
329 | { progman.disconnect();
|
---|
330 | delete groupName;
|
---|
331 | return false;
|
---|
332 | }
|
---|
333 |
|
---|
334 | // add a "server" icon
|
---|
335 | FilePath libraryPath(this->destinationPath->cString(), "library.exe");
|
---|
336 | if (!progman.addIcon(groupName, "Library (without nextwork support)", libraryPath.cString(), ""))
|
---|
337 | { progman.disconnect();
|
---|
338 | delete groupName;
|
---|
339 | return false;
|
---|
340 | }
|
---|
341 |
|
---|
342 | // TODO: check for server existence
|
---|
343 | FilePath serverPath(this->destinationPath->cString(), "server.exe");
|
---|
344 | if (!progman.addIcon(groupName, "Server", serverPath.cString(), ""))
|
---|
345 | { progman.disconnect();
|
---|
346 | delete groupName;
|
---|
347 | return false;
|
---|
348 | }
|
---|
349 |
|
---|
350 | FilePath readMePath(this->destinationPath->cString(), "readme.txt");
|
---|
351 | if (!progman.addIcon(groupName, "ReadMe", readMePath.cString(), ""))
|
---|
352 | { progman.disconnect();
|
---|
353 | delete groupName;
|
---|
354 | return false;
|
---|
355 | }
|
---|
356 |
|
---|
357 | FilePath supportPath(this->destinationPath->cString(), "support.html");
|
---|
358 | if (!progman.addIcon(groupName, "Technical Support", supportPath.cString(), ""))
|
---|
359 | { progman.disconnect();
|
---|
360 | delete groupName;
|
---|
361 | return false;
|
---|
362 | }
|
---|
363 |
|
---|
364 | // TODO: add uninstall support
|
---|
365 |
|
---|
366 | // dispose of group name
|
---|
367 | delete groupName;
|
---|
368 |
|
---|
369 | // disconnect from program manager
|
---|
370 | progman.disconnect();
|
---|
371 | }
|
---|
372 | return true;
|
---|
373 | }
|
---|
374 |
|
---|
375 | /**
|
---|
376 | * Update the profile (ini) files associated with the program; these changes
|
---|
377 | * must be made after copying to files in the destination/executable folders
|
---|
378 | * as we can't write to CD-ROM (or at least we shouldn't - the install would
|
---|
379 | * become tainted).
|
---|
380 | */
|
---|
381 | bool GSInstall::updateProfiles()
|
---|
382 | { FilePath *exePath;
|
---|
383 | FilePath *dataPath;
|
---|
384 | FilePath *iniPath;
|
---|
385 |
|
---|
386 | // if we're installing the exe, then the exe path leads to the destination
|
---|
387 | // folder of this installation sequence; if not, then we pick it up from
|
---|
388 | // the existing location of that folder
|
---|
389 | if (this->installExe)
|
---|
390 | { exePath = this->destinationPath;
|
---|
391 | }
|
---|
392 | else
|
---|
393 | { exePath = this->collectPath;
|
---|
394 | }
|
---|
395 | iniPath = new FilePath((char *) exePath->cString(), "gsdl.ini");
|
---|
396 |
|
---|
397 | // TODO: check if this 'if' structure is correct; suspect that it isn't quite
|
---|
398 | // as we may not be installing the volume, but exe etc individually;
|
---|
399 | // may be okay now but not future proof; also the destination directory
|
---|
400 | // may or may not be tied to the exe directory if that existed already.
|
---|
401 | // This all needs investigating
|
---|
402 | if (this->installVolume)
|
---|
403 | { char volumeSectionName[100] = "\0";
|
---|
404 | unsigned int space = 99;
|
---|
405 |
|
---|
406 | // Manufacture the appropriate section name now; an equivalent string
|
---|
407 | // is also constructed
|
---|
408 | this->configFile->concat("CollectionName", volumeSectionName, space);
|
---|
409 | strcat(volumeSectionName, "#");
|
---|
410 | space --;
|
---|
411 | this->configFile->concat("CollectionVolume", volumeSectionName, space);
|
---|
412 | string volumeSectionString(volumeSectionName);
|
---|
413 |
|
---|
414 | // if we're installing the full data for the collection, then take the
|
---|
415 | // data path to be at the selected destination directory for the collection
|
---|
416 | // files; otherwise take the data path to be on the CD/distribution media
|
---|
417 | if (this->installFullVolume)
|
---|
418 | { dataPath = this->dataDestPath;
|
---|
419 | }
|
---|
420 | else
|
---|
421 | { dataPath = this->gsdlSourcePath;
|
---|
422 | }
|
---|
423 |
|
---|
424 | // create a profile object to write to the gsdl.ini file
|
---|
425 | gsProfile gsdlProfile(iniPath->cString());
|
---|
426 |
|
---|
427 | // if installing the executable, add the database and greenstone home
|
---|
428 | // directories
|
---|
429 | if (this->installExe)
|
---|
430 | { // set the correct exe entries in gsdl.ini (in the gsdl section)
|
---|
431 | gsdlProfile.writeString("gsdl", "gsdlhome", dataPath->cString());
|
---|
432 | gsdlProfile.writeString("gsdl", "gdbmhome", this->dataDestPath->cString());
|
---|
433 |
|
---|
434 | this->unInstall->record("gsdl", "profilewrite", 2, &gsdl_VLHOME,
|
---|
435 | &dataPath->pathString());
|
---|
436 | this->unInstall->record("gsdl", "profilewrite", 2, &gsdl_DBHOME,
|
---|
437 | &this->dataDestPath->pathString());
|
---|
438 | }
|
---|
439 |
|
---|
440 | // set the correct collection volume entries in gsdl.ini
|
---|
441 | if (this->installVolume)
|
---|
442 | { // note the collection in the general gsdl section; and add the undo item too
|
---|
443 | gsdlProfile.ensureListMember("gsdl", gsdl_COLLIST.c_str(), volumeSectionName);
|
---|
444 | this->unInstall->record("gsdl", "proflistensure", 2, &gsdl_COLLIST, &volumeSectionString);
|
---|
445 |
|
---|
446 | // note the volume data in its own section
|
---|
447 | gsdlProfile.writeString(volumeSectionName, "gsdlhome", dataPath->cString());
|
---|
448 | gsdlProfile.writeString(volumeSectionName, "gdbmhome", this->dataDestPath->cString());
|
---|
449 | gsdlProfile.writeString(volumeSectionName, "staticpath", dataPath->cString());
|
---|
450 |
|
---|
451 | this->unInstall->record(volumeSectionName, "profilewrite", 2, &gsdl_VLHOME, &dataPath->pathString());
|
---|
452 | this->unInstall->record(volumeSectionName, "profilewrite", 2, &gsdl_DBHOME, &this->dataDestPath->pathString());
|
---|
453 | this->unInstall->record(volumeSectionName, "profilewrite", 2, &gsdl_STATIC, &dataPath->pathString());
|
---|
454 | }
|
---|
455 | }
|
---|
456 |
|
---|
457 | // clean up
|
---|
458 | delete iniPath;
|
---|
459 |
|
---|
460 | return true;
|
---|
461 | }
|
---|
462 |
|
---|
463 | bool GSInstall::installNetscape()
|
---|
464 | { FilePath netscape32Path(this->sourcePath->cString(), "netscape\\n32e405.exe");
|
---|
465 | FilePath netscape16Path(this->sourcePath->cString(), "netscape\\n16e405.exe");
|
---|
466 |
|
---|
467 | launchApp launchNetscape(netscape32Path);
|
---|
468 | launchNetscape.platformApp(gsPlatform_WINDOWS32S, netscape16Path);
|
---|
469 | if (launchNetscape.run(true, 1,
|
---|
470 | "This library is displayed using a web browser. If you don't "
|
---|
471 | "currently have a web browser installed on your machine you may "
|
---|
472 | "install the Netscape 4.05 browser now.\n\n"
|
---|
473 | "Note that if your current browser was provided by your internet "
|
---|
474 | "service provider, you should install Netscape in a different "
|
---|
475 | "directory.\n\n"
|
---|
476 | "Would you like to install the Netscape 4.05 browser now?",
|
---|
477 | "Greenstone Installer", false) < 0)
|
---|
478 | { MessageBox(0, "Error", app_name, MB_OK);
|
---|
479 | return false;
|
---|
480 | }
|
---|
481 | return true;
|
---|
482 | }
|
---|
483 |
|
---|
484 | FilePath *GSInstall::collectionPath()
|
---|
485 | { return this->collectPath;
|
---|
486 | }
|
---|
487 |
|
---|
488 | FilePath *GSInstall::installPath()
|
---|
489 | { return this->installToPath;
|
---|
490 | }
|
---|
491 |
|
---|
492 | void GSInstall::addSelectedDir(dirSelector *selector)
|
---|
493 | { this->selectedDirs.push_back(selector);
|
---|
494 | }
|
---|
495 |
|
---|
496 | typedef struct
|
---|
497 | { dirSelector * dirSelect;
|
---|
498 | } GSInstall_dirPathData;
|
---|
499 |
|
---|
500 | HGLOBAL loadDirBrowser()
|
---|
501 | { HRSRC resHdl;
|
---|
502 |
|
---|
503 | resHdl = FindResource(app_instance, "MySaveAsDlg", RT_DIALOG);
|
---|
504 | return LoadResource(app_instance, resHdl);
|
---|
505 | }
|
---|
506 |
|
---|
507 | void gsInstall_wizard_centre(HWND dialog)
|
---|
508 | {
|
---|
509 | RECT rect;
|
---|
510 | int sx, sy;
|
---|
511 | int dx, dy;
|
---|
512 |
|
---|
513 | gsInstall_getDesktopExt(&sx, &sy);
|
---|
514 | GetWindowRect(dialog, &rect);
|
---|
515 |
|
---|
516 | dx = (sx - rect.right + rect.left) >> 1;
|
---|
517 | dy = (sy - rect.bottom + rect.top) >> 1;
|
---|
518 | SetWindowPos(dialog, 0, dx, dy, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
|
---|
519 | }
|
---|
520 |
|
---|
521 | BOOL FAR PASCAL GSInstall_dlgproc(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam)
|
---|
522 | { static bool first = true; // static variable to hack the position of the
|
---|
523 | // whole wizard; note doing this in the wizard
|
---|
524 | // property sheet initialisation DOES NOT WORK
|
---|
525 |
|
---|
526 | switch (Message)
|
---|
527 | { case WM_INITDIALOG:
|
---|
528 | { dirSelector *selector = (dirSelector *) ((PROPSHEETPAGE *) lParam)->lParam;
|
---|
529 |
|
---|
530 | SetDlgItemText(Dialog, dirpath_PROMPT, selector->prompt);
|
---|
531 | if (selector->optPrompt != NULL)
|
---|
532 | { SetDlgItemText(Dialog, dirpath_OPTION, selector->optPrompt);
|
---|
533 | EnableWindow(GetDlgItem(Dialog, dirpath_BROWSE), true); // was false
|
---|
534 | EnableWindow(GetDlgItem(Dialog, dirpath_PATH), true); // was false
|
---|
535 | }
|
---|
536 | else
|
---|
537 | { ShowWindow(GetDlgItem(Dialog, dirpath_OPTION), SW_HIDE);
|
---|
538 | }
|
---|
539 | SetWindowLong(Dialog, GWL_USERDATA, ((PROPSHEETPAGE *) lParam)->lParam);
|
---|
540 | SetDlgItemText(Dialog, dirpath_PATH, selector->selectedPath());
|
---|
541 |
|
---|
542 | // if this is the first time this function is called, then centre the
|
---|
543 | // wizard into the centre of our screen.
|
---|
544 | if (first)
|
---|
545 | { gsInstall_wizard_centre(GetParent(Dialog));
|
---|
546 | first = false;
|
---|
547 | }
|
---|
548 | }
|
---|
549 | return TRUE;
|
---|
550 |
|
---|
551 | case WM_COMMAND:
|
---|
552 | switch (LOWORD(wParam))
|
---|
553 | { case dirpath_BROWSE:
|
---|
554 | ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->requestPath(Dialog, "Select Directory");
|
---|
555 | SetDlgItemText(Dialog, dirpath_PATH, ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->selectedPath());
|
---|
556 | break;
|
---|
557 |
|
---|
558 | case dirpath_OPTION:
|
---|
559 | ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->setOption(IsDlgButtonChecked(Dialog, dirpath_OPTION));
|
---|
560 | if (HIWORD(wParam) == BN_CLICKED && false) // don't do the enable/disable these days
|
---|
561 | { EnableWindow(GetDlgItem(Dialog, dirpath_BROWSE), IsDlgButtonChecked(Dialog, dirpath_OPTION));
|
---|
562 | EnableWindow(GetDlgItem(Dialog, dirpath_PATH), IsDlgButtonChecked(Dialog, dirpath_OPTION));
|
---|
563 | }
|
---|
564 | break;
|
---|
565 | }
|
---|
566 | break;
|
---|
567 |
|
---|
568 | case WM_NOTIFY:
|
---|
569 | switch (((LPNMHDR) lParam)->code)
|
---|
570 | { case PSN_SETACTIVE:
|
---|
571 | { dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
|
---|
572 | if (selector->isFinal())
|
---|
573 | { PropSheet_SetWizButtons(GetParent(Dialog), PSWIZB_BACK | PSWIZB_FINISH);
|
---|
574 | }
|
---|
575 | else
|
---|
576 | { PropSheet_SetWizButtons(GetParent(Dialog), PSWIZB_BACK | PSWIZB_NEXT);
|
---|
577 | }
|
---|
578 | }
|
---|
579 | break;
|
---|
580 |
|
---|
581 | case PSN_KILLACTIVE:
|
---|
582 | { // note the path from the dialog
|
---|
583 | dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
|
---|
584 | selector->setPathFromEdit(GetDlgItem(Dialog, dirpath_PATH));
|
---|
585 |
|
---|
586 | // create a new FilePath object to check on the proposed destination
|
---|
587 | FilePath *path = new FilePath(selector->selectedPath());
|
---|
588 | if (path->exists() == false)
|
---|
589 | { char buffer[128];
|
---|
590 |
|
---|
591 | sprintf(buffer, "Directory %s does not exist - create it?", selector->selectedPath());
|
---|
592 |
|
---|
593 | // if the user cancelled that, then don't permit them to go to the next
|
---|
594 | // page of the wizard
|
---|
595 | if (MessageBox(0, buffer, app_name, MB_YESNO | MB_TOPMOST) == IDNO)
|
---|
596 | { delete path;
|
---|
597 | SetWindowLong(Dialog, DWL_MSGRESULT, TRUE);
|
---|
598 | return TRUE;
|
---|
599 | }
|
---|
600 | }
|
---|
601 | delete path;
|
---|
602 | }
|
---|
603 | break;
|
---|
604 |
|
---|
605 | case PSN_WIZNEXT:
|
---|
606 | { if (((LPNMHDR) lParam)->idFrom == 0)
|
---|
607 | { // TODO: note a default here
|
---|
608 | }
|
---|
609 | }
|
---|
610 | break;
|
---|
611 |
|
---|
612 | case PSN_WIZFINISH:
|
---|
613 | { // Finish the activity now
|
---|
614 | config_complete = true;
|
---|
615 | }
|
---|
616 | break;
|
---|
617 | }
|
---|
618 | break;
|
---|
619 | }
|
---|
620 | return FALSE;
|
---|
621 | }
|
---|
622 |
|
---|
623 | void GSInstall_init_propertySheet(PROPSHEETPAGE &ppage, char *prompt, char *optPrompt,
|
---|
624 | char *title, GSInstall &installer, bool isFinal)
|
---|
625 | { GSInstall_dirPathData *data = new GSInstall_dirPathData;
|
---|
626 |
|
---|
627 | data->dirSelect = new dirSelector(prompt, optPrompt, title, installer.installPath());
|
---|
628 | data->dirSelect->setFinal(isFinal);
|
---|
629 |
|
---|
630 | installer.addSelectedDir(data->dirSelect);
|
---|
631 |
|
---|
632 | ppage.dwSize = sizeof(PROPSHEETPAGE);
|
---|
633 | ppage.dwFlags = PSP_USETITLE;
|
---|
634 | ppage.hInstance = app_instance;
|
---|
635 | ppage.pszTemplate = "getDirPath";
|
---|
636 | ppage.pszIcon = 0;
|
---|
637 | ppage.pszTitle = app_name;
|
---|
638 | ppage.pfnDlgProc = (DLGPROC) GSInstall_dlgproc;
|
---|
639 | ppage.lParam = (LPARAM) data->dirSelect;
|
---|
640 | ppage.pfnCallback = NULL;
|
---|
641 | }
|
---|
642 |
|
---|
643 | int CALLBACK GSInstall_wizardProc(HWND dialog, UINT Message, LPARAM lParameter)
|
---|
644 | { switch (Message)
|
---|
645 | { case PSCB_INITIALIZED :
|
---|
646 | // Process PSCB_INITIALIZED
|
---|
647 | gsInstall_wizard_centre(dialog);
|
---|
648 | break ;
|
---|
649 |
|
---|
650 | case PSCB_PRECREATE :
|
---|
651 | // Process PSCB_PRECREATE
|
---|
652 | break ;
|
---|
653 |
|
---|
654 | default :
|
---|
655 | // Unknown message
|
---|
656 | break ;
|
---|
657 | }
|
---|
658 | return 0;
|
---|
659 | }
|
---|
660 |
|
---|
661 | bool GSInstall_init_wizard(GSInstall &install)
|
---|
662 | { PROPSHEETHEADER pshead;
|
---|
663 | PROPSHEETPAGE ppage[2];
|
---|
664 | bool reply;
|
---|
665 |
|
---|
666 | ZeroMemory(&pshead, sizeof(PROPSHEETHEADER));
|
---|
667 | pshead.dwSize = sizeof(PROPSHEETHEADER);
|
---|
668 | pshead.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_USEHICON | PSH_WIZARD;
|
---|
669 | pshead.hwndParent = app_window;
|
---|
670 | pshead.hInstance = app_instance;
|
---|
671 | pshead.hIcon = NULL;
|
---|
672 | pshead.pszCaption = "Greenstone Installer";
|
---|
673 | pshead.nPages = 2;
|
---|
674 | pshead.nStartPage = 0;
|
---|
675 | pshead.ppsp = ppage;
|
---|
676 | pshead.pfnCallback = GSInstall_wizardProc;
|
---|
677 |
|
---|
678 | GSInstall_init_propertySheet( ppage[0],
|
---|
679 | "Choose a directory to install your "
|
---|
680 | "GreenStone software to.", NULL,
|
---|
681 | "Select", install, false);
|
---|
682 | GSInstall_init_propertySheet(ppage[1],
|
---|
683 | "Choose a directory to install the collection "
|
---|
684 | "files to.\n\n"
|
---|
685 | "You can also choose to install all the collection "
|
---|
686 | "files onto your computer hard drive.\n\n"
|
---|
687 | "If you do this, you will not have to load the "
|
---|
688 | "CD-ROM each time you use your Greenstone software "
|
---|
689 | "but more of your hard disk will be used.\n\n"
|
---|
690 | "Some collection files must be installed on your "
|
---|
691 | "computer.\n\n",
|
---|
692 | "Install all collection files",
|
---|
693 | "Select", install, true);
|
---|
694 |
|
---|
695 | reply = (PropertySheet (&pshead) >= 0);
|
---|
696 | return reply;
|
---|
697 | }
|
---|
698 |
|
---|
699 | long FAR PASCAL GSInstallWindProc(HWND Window,
|
---|
700 | WORD Message,
|
---|
701 | WPARAM wParameter,
|
---|
702 | LPARAM lParameter)
|
---|
703 | { long reply = 0;
|
---|
704 |
|
---|
705 | switch(Message)
|
---|
706 | { case WM_CREATE:
|
---|
707 | {
|
---|
708 | }
|
---|
709 | break;
|
---|
710 |
|
---|
711 | case WM_COMMAND:
|
---|
712 | break;
|
---|
713 |
|
---|
714 | case WM_USER:
|
---|
715 | { //dirSelector selector("Choose a Greenstone directory", "Select directory");
|
---|
716 |
|
---|
717 | //selector.requestPath(Window, "Select directory");
|
---|
718 | GSInstall install;
|
---|
719 | GSInstall_init_wizard(install);
|
---|
720 | if (config_complete == false)
|
---|
721 | { MessageBox(0, "Install cancelled", app_name, MB_OK);
|
---|
722 | }
|
---|
723 | else
|
---|
724 | { install.setDestination();
|
---|
725 | install.setManifest();
|
---|
726 | install.copyFiles();
|
---|
727 | install.updateProgman();
|
---|
728 | install.updateRegistry();
|
---|
729 | install.updateProfiles();
|
---|
730 | install.installNetscape();
|
---|
731 | }
|
---|
732 | DestroyWindow(Window);
|
---|
733 | }
|
---|
734 | break;
|
---|
735 |
|
---|
736 | case WM_CLOSE:
|
---|
737 | /* if (!file_ischanged || IDCANCEL != file_query(Window, file_name))*/
|
---|
738 | DestroyWindow(Window);
|
---|
739 | return 0L;
|
---|
740 |
|
---|
741 | case WM_DESTROY:
|
---|
742 | { PostQuitMessage(0);
|
---|
743 | }
|
---|
744 | break;
|
---|
745 |
|
---|
746 | default:
|
---|
747 | return(DefWindowProc(Window, Message, wParameter, lParameter));
|
---|
748 | }
|
---|
749 | return reply;
|
---|
750 | }
|
---|
751 |
|
---|
752 | void GSInstall_init(HINSTANCE instance, int Show)
|
---|
753 | { int sx, sy;
|
---|
754 |
|
---|
755 | gsInstall_getDesktopExt(&sx, &sy);
|
---|
756 |
|
---|
757 | app_window = CreateWindow("GSInstall:Main", "GreenStone Installer",
|
---|
758 | WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | CS_DBLCLKS,
|
---|
759 | 0, 0,
|
---|
760 | sx, sy,
|
---|
761 | NULL,
|
---|
762 | NULL,
|
---|
763 | app_instance,
|
---|
764 | NULL);
|
---|
765 |
|
---|
766 | ShowWindow(app_window, Show);
|
---|
767 |
|
---|
768 | PostMessage(app_window, WM_USER, 0, 0L);
|
---|
769 | }
|
---|
770 |
|
---|
771 | void WinClassInit(void)
|
---|
772 | { WNDCLASS Class;
|
---|
773 |
|
---|
774 | Class.lpszClassName = "GSInstall:Main";
|
---|
775 | Class.hInstance = app_instance;
|
---|
776 | Class.lpfnWndProc = (WNDPROC) GSInstallWindProc;
|
---|
777 | Class.hCursor = LoadCursor(NULL, IDC_ARROW);
|
---|
778 | Class.hIcon = NULL; //LoadIcon(app_instance, "GSInstall");
|
---|
779 | Class.lpszMenuName = NULL;
|
---|
780 | Class.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1);
|
---|
781 | Class.style = NULL;
|
---|
782 | Class.cbClsExtra = 0;
|
---|
783 | Class.cbWndExtra = 0;
|
---|
784 | RegisterClass(&Class);
|
---|
785 | /*
|
---|
786 | Class.lpszClassName = "GSInstall:Splash";
|
---|
787 | Class.hInstance = app_instance;
|
---|
788 | Class.lpfnWndProc = (WNDPROC) splash_windproc;
|
---|
789 | Class.hCursor = LoadCursor(NULL, IDC_ARROW);
|
---|
790 | Class.hIcon = NULL;
|
---|
791 | Class.lpszMenuName = NULL;
|
---|
792 | Class.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
|
---|
793 | Class.style = NULL;
|
---|
794 | Class.cbClsExtra = 0;
|
---|
795 | Class.cbWndExtra = 0;
|
---|
796 | RegisterClass(&Class);*/
|
---|
797 | }
|
---|
798 |
|
---|
799 | int PASCAL WinMain(HINSTANCE Current,
|
---|
800 | HINSTANCE Previous,
|
---|
801 | LPSTR CmdLine,
|
---|
802 | int CmdShow)
|
---|
803 | { MSG msg;
|
---|
804 | // HACCEL accel;
|
---|
805 |
|
---|
806 | app_cmdLine = (char *) malloc(lstrlen(CmdLine) + 1);
|
---|
807 | lstrcpy(app_cmdLine, CmdLine);
|
---|
808 |
|
---|
809 | app_instance = Current;
|
---|
810 | /* -- init application */
|
---|
811 | if (!Previous)
|
---|
812 | { WinClassInit();
|
---|
813 | InitCommonControls();
|
---|
814 | // grbStatic_registerClass(Current);
|
---|
815 | }
|
---|
816 |
|
---|
817 | /* -- init instance */
|
---|
818 | GSInstall_init(Current, CmdShow);
|
---|
819 |
|
---|
820 | // config_init("ReTreeval");
|
---|
821 |
|
---|
822 | // accel = LoadAccelerators(Current, "ReTreevalMenu");
|
---|
823 |
|
---|
824 | while (GetMessage(&msg, NULL, 0, 0))
|
---|
825 | { /*if (!TranslateAccelerator(app_window, accel, &msg))
|
---|
826 | { */
|
---|
827 | TranslateMessage(&msg);
|
---|
828 | DispatchMessage(&msg);
|
---|
829 | /*}*/
|
---|
830 | }
|
---|
831 | return (int) msg.wParam;
|
---|
832 | } |
---|