1 | #include <windows.h>
|
---|
2 |
|
---|
3 | #include <stdlib.h>
|
---|
4 | #include <stdio.h>
|
---|
5 | #include <string.h>
|
---|
6 | #include <map>
|
---|
7 |
|
---|
8 | #include "splash.h"
|
---|
9 | #include "bmputil.h"
|
---|
10 |
|
---|
11 | // define the magic value used in GetWinFlags to show that this application
|
---|
12 | // is running on a Windows NT box in 16-bit emulation mode.
|
---|
13 | #define WF_WINNT 0x4000
|
---|
14 |
|
---|
15 | #define MAX_PATH 256
|
---|
16 |
|
---|
17 | #ifdef _WIN32
|
---|
18 | int GetWinFlags()
|
---|
19 | { return 0;
|
---|
20 | }
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | HWND app_window;
|
---|
24 | HINSTANCE app_instance;
|
---|
25 | char * app_cmdLine;
|
---|
26 |
|
---|
27 | typedef void (* splashfn) (HINSTANCE a, unsigned int time);
|
---|
28 | typedef HBITMAP (* bmploadfn) (HDC device, LPSTR name);
|
---|
29 |
|
---|
30 | typedef struct
|
---|
31 | { BYTE majorVersion;
|
---|
32 | BYTE minorVersion;
|
---|
33 | WORD buildNumber;
|
---|
34 | BOOL debug;
|
---|
35 | } win32sInfo, FAR * lpWin32sInfo;
|
---|
36 |
|
---|
37 | typedef enum
|
---|
38 | { Windows2x, Windows3_0x, Windows3_1x, Windows9x, WindowsNT
|
---|
39 | } gs16PlatformId;
|
---|
40 |
|
---|
41 | typedef struct
|
---|
42 | { gs16PlatformId platform;
|
---|
43 | bool win32s;
|
---|
44 | } gs16PlatformInfo;
|
---|
45 |
|
---|
46 | typedef int (FAR PASCAL * win32sInfoFn)(lpWin32sInfo);
|
---|
47 |
|
---|
48 | bool appendPath(char *original, char *extension, int maxlen)
|
---|
49 | { int extralen = 0;
|
---|
50 |
|
---|
51 | if (original[strlen(original) - 1] != '\\')
|
---|
52 | { extralen ++;
|
---|
53 | }
|
---|
54 | if (extension[0] == '\\')
|
---|
55 | { extralen --;
|
---|
56 | }
|
---|
57 | if (strlen(original) + strlen(extension) + extralen + 1 > maxlen)
|
---|
58 | { return false;
|
---|
59 | }
|
---|
60 | if (extralen > 0)
|
---|
61 | { strcat(original, "\\");
|
---|
62 | }
|
---|
63 | else if (extralen < 0)
|
---|
64 | { extension ++;
|
---|
65 | }
|
---|
66 | strcat(original,extension);
|
---|
67 | return true;
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Function called before attempting a LoadModule as that call reports
|
---|
72 | * an error if w32sys.dll doesn't exist
|
---|
73 | */
|
---|
74 | bool GS16bit_checkExistsWin32s()
|
---|
75 | { char buffer[MAX_PATH];
|
---|
76 | OFSTRUCT of;
|
---|
77 |
|
---|
78 | if (GetSystemDirectory(buffer, MAX_PATH) == 0)
|
---|
79 | { return true;
|
---|
80 | }
|
---|
81 |
|
---|
82 | if (!appendPath(buffer, "win32s\\w32sys.dll", MAX_PATH))
|
---|
83 | { return FALSE;
|
---|
84 | }
|
---|
85 |
|
---|
86 | strcpy(buffer, "win32s\\w32.dll");
|
---|
87 | if (OpenFile((LPCSTR) buffer, (LPOFSTRUCT) &of, OF_EXIST) == HFILE_ERROR)
|
---|
88 | { // try system directory directly; no need to error check - we know that
|
---|
89 | // we don't have a length problem
|
---|
90 | GetSystemDirectory(buffer, MAX_PATH);
|
---|
91 | appendPath(buffer, "w32sys.dll", MAX_PATH);
|
---|
92 |
|
---|
93 | // if it isn't there either, return false
|
---|
94 | if (OpenFile((LPCSTR) buffer, (LPOFSTRUCT) &of, OF_EXIST) == HFILE_ERROR)
|
---|
95 | { return false;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | return true;
|
---|
99 | }
|
---|
100 |
|
---|
101 | bool GS16bit_checkForWin32s()
|
---|
102 | {
|
---|
103 | HINSTANCE w32sHandle;
|
---|
104 | win32sInfoFn infoFnPtr;
|
---|
105 | win32sInfo w32sInfo;
|
---|
106 | bool reply = false;
|
---|
107 |
|
---|
108 | // check if the module exists
|
---|
109 | if (GS16bit_checkExistsWin32s() == true)
|
---|
110 | { w32sHandle = LoadLibrary("W32SYS.DLL");
|
---|
111 | }
|
---|
112 | else
|
---|
113 | { w32sHandle = NULL;
|
---|
114 | }
|
---|
115 |
|
---|
116 | // try to get a handle onto the win32s library
|
---|
117 | if (w32sHandle != NULL)
|
---|
118 | { // now get the address of the GetWin32sInfo function
|
---|
119 | infoFnPtr = (win32sInfoFn) GetProcAddress(w32sHandle, "GETWIN32SINFO");
|
---|
120 |
|
---|
121 | // if the function exists, we've got win32s1.1 or later
|
---|
122 | if (infoFnPtr != NULL)
|
---|
123 | { if ((*infoFnPtr)((lpWin32sInfo) &w32sInfo) == 0) // no error state
|
---|
124 | { reply = true;
|
---|
125 | }
|
---|
126 | else // error - call didn't work; assume that we have a non-functional
|
---|
127 | // win32s
|
---|
128 | { reply = false;
|
---|
129 | }
|
---|
130 | }
|
---|
131 | // else we've got win32s 1.0. TODO: We need to check if it's actually up and
|
---|
132 | // running;
|
---|
133 | else
|
---|
134 | { reply = true;
|
---|
135 | }
|
---|
136 |
|
---|
137 | // we need to free the library before finishing this function
|
---|
138 | FreeLibrary(w32sHandle);
|
---|
139 | }
|
---|
140 | // no win32s at all
|
---|
141 | else
|
---|
142 | { reply = false;
|
---|
143 | }
|
---|
144 |
|
---|
145 | return reply;
|
---|
146 | }
|
---|
147 |
|
---|
148 | void GS16bit_getPlatformInfo(gs16PlatformInfo &info)
|
---|
149 | {
|
---|
150 | DWORD version = GetVersion();
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * NB: Ignore ALL standard information on using GetVersion in the
|
---|
154 | * standard Windows 3.1 SDK and Windows 32-bit SDK documentation;
|
---|
155 | * the latter does not apply, and the former is (slightly but signif-
|
---|
156 | * cantly) misdocumented.
|
---|
157 | *
|
---|
158 | * On 16-bit windows (i.e. this program) take the following comments
|
---|
159 | * as gospel. Also refer to
|
---|
160 | *
|
---|
161 | * http://support.microsoft.com/support/kb/articles/Q131/3/71.asp
|
---|
162 | */
|
---|
163 | BYTE majorVersion = LOBYTE(LOWORD(version));
|
---|
164 | BYTE minorVersion = HIBYTE(LOWORD(version));
|
---|
165 | BYTE dosVersion = HIBYTE(HIWORD(version));
|
---|
166 |
|
---|
167 | if (majorVersion < 3)
|
---|
168 | {
|
---|
169 | info.platform = Windows2x;
|
---|
170 | }
|
---|
171 | else if (majorVersion == 3 && minorVersion >= 95) // it's Windows 95 from the
|
---|
172 | // minor version; I guess that
|
---|
173 | // 98 may have minor version == 98,
|
---|
174 | // but I don't know! Hence the
|
---|
175 | // cautious check
|
---|
176 | {
|
---|
177 | info.platform = Windows9x;
|
---|
178 | }
|
---|
179 | else // we're running in "some sort" of Windows 3.x environment
|
---|
180 | {
|
---|
181 | if (minorVersion == 10 && dosVersion == 5) // it could be running under WOW
|
---|
182 | // (16-bit Windows emulation in
|
---|
183 | // Windows NT)
|
---|
184 | {
|
---|
185 | if ((GetWinFlags() & WF_WINNT) == WF_WINNT) // check for NT in emulation mode
|
---|
186 | {
|
---|
187 | info.platform = WindowsNT;
|
---|
188 | }
|
---|
189 | else
|
---|
190 | {
|
---|
191 | info.platform = Windows3_1x;
|
---|
192 | }
|
---|
193 | }
|
---|
194 | else if (minorVersion >= 10) // perhaps Windows 3.11
|
---|
195 | {
|
---|
196 | info.platform = Windows3_1x;
|
---|
197 | }
|
---|
198 | else
|
---|
199 | {
|
---|
200 | info.platform = Windows3_0x;
|
---|
201 | }
|
---|
202 | }
|
---|
203 |
|
---|
204 | if (info.platform == Windows3_1x)
|
---|
205 | {
|
---|
206 | info.win32s = GS16bit_checkForWin32s();
|
---|
207 | }
|
---|
208 | else
|
---|
209 | {
|
---|
210 | info.win32s = false;
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 | void GS16bit_checkWindowsVersion()
|
---|
215 | {
|
---|
216 | gs16PlatformInfo platformInfo;
|
---|
217 |
|
---|
218 | GS16bit_getPlatformInfo(platformInfo);
|
---|
219 | if (platformInfo.platform == Windows3_0x ||
|
---|
220 | platformInfo.platform == Windows2x)
|
---|
221 | {
|
---|
222 | MessageBox(app_window,
|
---|
223 | "Greenstone cannot be installed on this computer. It requires "
|
---|
224 | "Windows 3.10 or later",
|
---|
225 | "Greenstone Installer",
|
---|
226 | MB_OK);
|
---|
227 | }
|
---|
228 | else if ( platformInfo.platform == Windows3_1x &&
|
---|
229 | platformInfo.win32s == false)
|
---|
230 | {
|
---|
231 | int result;
|
---|
232 |
|
---|
233 | MessageBox(app_window,
|
---|
234 | "Greenstone requires 32 bit Windows. Win32s will now be installed "
|
---|
235 | "on your computer to provide this, before continuing with the main "
|
---|
236 | "installation.",
|
---|
237 | "Greenstone Installer",
|
---|
238 | MB_OK);
|
---|
239 | result = WinExec("win32s\\setup.exe", SW_SHOWNORMAL);
|
---|
240 | }
|
---|
241 | else
|
---|
242 | {
|
---|
243 | char buffer[20];
|
---|
244 | int result;
|
---|
245 | /* MessageBox(app_window,
|
---|
246 | "Greenstone will now install", "Greenstone Installer", MB_OK);*/
|
---|
247 | result = WinExec("gssetup.exe", SW_SHOWNORMAL);
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | long FAR PASCAL GS16bitWindProc(HWND Window,
|
---|
252 | WORD Message,
|
---|
253 | WPARAM wParameter,
|
---|
254 | LPARAM lParameter)
|
---|
255 | { long reply = 0;
|
---|
256 |
|
---|
257 | switch(Message)
|
---|
258 | { case WM_CREATE:
|
---|
259 | {
|
---|
260 | }
|
---|
261 | break;
|
---|
262 |
|
---|
263 | case WM_COMMAND:
|
---|
264 | break;
|
---|
265 |
|
---|
266 | case WM_CLOSE:
|
---|
267 | DestroyWindow(Window);
|
---|
268 | return 0L;
|
---|
269 |
|
---|
270 | case WM_DESTROY:
|
---|
271 | {
|
---|
272 | PostQuitMessage(0);
|
---|
273 | }
|
---|
274 | break;
|
---|
275 |
|
---|
276 | default:
|
---|
277 | return(DefWindowProc(Window, Message, wParameter, lParameter));
|
---|
278 | }
|
---|
279 | return reply;
|
---|
280 | }
|
---|
281 |
|
---|
282 | void GS16bit_init(HINSTANCE instance, int Show)
|
---|
283 | {
|
---|
284 | FARPROC showsplash;
|
---|
285 | FARPROC loadbmp;
|
---|
286 | HDC dc;
|
---|
287 | char buffer[20];
|
---|
288 |
|
---|
289 | /*
|
---|
290 | dc = GetDC(GetDesktopWindow());
|
---|
291 | bmpUtil_loadBitmap(dc, "C:\\gs.bmp");
|
---|
292 | ReleaseDC(GetDesktopWindow(), dc);
|
---|
293 | */
|
---|
294 | // showsplash = MakeProcInstance((FARPROC) splash_show, instance);
|
---|
295 | // (*(splashfn) showsplash)(instance, 3000);
|
---|
296 |
|
---|
297 | GS16bit_checkWindowsVersion();
|
---|
298 |
|
---|
299 | app_window = CreateWindow("GS16bit:Main", "Greenstone Installer",
|
---|
300 | WS_OVERLAPPEDWINDOW | WS_MINIMIZE | CS_DBLCLKS,
|
---|
301 | CW_USEDEFAULT,
|
---|
302 | 0,
|
---|
303 | CW_USEDEFAULT,
|
---|
304 | 0,
|
---|
305 | NULL,
|
---|
306 | NULL,
|
---|
307 | app_instance,
|
---|
308 | NULL);
|
---|
309 |
|
---|
310 | ShowWindow(app_window, Show);
|
---|
311 |
|
---|
312 | PostQuitMessage(0);
|
---|
313 | }
|
---|
314 |
|
---|
315 | void WinClassInit(void)
|
---|
316 | {
|
---|
317 | WNDCLASS Class;
|
---|
318 |
|
---|
319 | Class.lpszClassName = "GS16bit:Main";
|
---|
320 | Class.hInstance = app_instance;
|
---|
321 | Class.lpfnWndProc = (WNDPROC) GS16bitWindProc;
|
---|
322 | Class.hCursor = LoadCursor(NULL, IDC_ARROW);
|
---|
323 | Class.hIcon = NULL; //LoadIcon(app_instance, "GSInstall");
|
---|
324 | Class.lpszMenuName = NULL;
|
---|
325 | Class.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1);
|
---|
326 | Class.style = NULL;
|
---|
327 | Class.cbClsExtra = 0;
|
---|
328 | Class.cbWndExtra = 0;
|
---|
329 | RegisterClass(&Class);
|
---|
330 | }
|
---|
331 |
|
---|
332 | int PASCAL WinMain(HINSTANCE Current,
|
---|
333 | HINSTANCE Previous,
|
---|
334 | LPSTR CmdLine,
|
---|
335 | int CmdShow)
|
---|
336 | {
|
---|
337 | MSG msg;
|
---|
338 |
|
---|
339 | app_cmdLine = (char *) LocalAlloc(LMEM_FIXED, lstrlen(CmdLine) + 1);
|
---|
340 | lstrcpy(app_cmdLine, CmdLine);
|
---|
341 |
|
---|
342 | app_instance = Current;
|
---|
343 | /* -- init application */
|
---|
344 | if (!Previous)
|
---|
345 | {
|
---|
346 | WinClassInit();
|
---|
347 | }
|
---|
348 |
|
---|
349 | /* -- init instance */
|
---|
350 | GS16bit_init(Current, CmdShow);
|
---|
351 |
|
---|
352 | while (GetMessage(&msg, NULL, 0, 0))
|
---|
353 | {
|
---|
354 | TranslateMessage(&msg);
|
---|
355 | DispatchMessage(&msg);
|
---|
356 | }
|
---|
357 | return (int) msg.wParam;
|
---|
358 | }
|
---|
359 |
|
---|