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