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