3 Part of the swftools installer (Main program).
5 Copyright (c) 2004 Matthias Kramm <kramm@quiss.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
28 #include "../config.h" //for swftools version
32 static char*install_path = "c:\\swftools\\";
34 static HWND wnd_progress = 0;
35 static HWND wnd_params = 0;
37 #define USER_SETMESSAGE 0x7fff0001
39 struct progress_data {
60 LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
62 printf("%08x, %d %08x %08x\n", hwnd, message, wParam, lParam);
64 /* in order for the delegation below to also work for
65 WM_CREATE, we need to assign our window pointers *before* the
66 CreateWindow returns, because that's when the WM_CREATE event
68 if(message == WM_CREATE) {
69 CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
70 if(cs->lpCreateParams && !strcmp((char*)cs->lpCreateParams, "params")) {
73 if(cs->lpCreateParams && !strcmp((char*)cs->lpCreateParams, "progress")) {
79 return DefWindowProc(hwnd, message, wParam, lParam);
80 } else if(hwnd == wnd_progress) {
81 static struct progress_data data;
86 data.text3 = (char*)wParam;
87 SendMessage(data.wnd_text3, WM_SETTEXT, 0, data.text3);
90 memset(&data, 0, sizeof(data));
91 data.text1 = "Installing SWFTools";
92 data.text2 = (char*)malloc(strlen(install_path)+250);
93 sprintf(data.text2, "to %s", install_path);
97 CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
99 GetClientRect (hwnd, &rc);
100 data.width = rc.right - rc.left;
101 data.height = rc.bottom - rc.top;
102 data.bar_width = cs->cx - 17;
104 data.bar_posx = (data.width -data.bar_width)/2;
107 data.hwndButton = CreateWindow (
110 WS_CHILD | WS_VISIBLE,
121 data.wnd_text3 = CreateWindow (
124 WS_CHILD | WS_VISIBLE | ES_READONLY | ES_CENTER,
127 (rc.right - rc.left - data.bar_posx*2),
134 SendMessage(data.hwndButton, PBM_SETRANGE, 0, (LPARAM) MAKELONG(0,data.range));
135 SendMessage(data.hwndButton, PBM_SETSTEP, (WPARAM) data.step, 0);
136 //ShowWindow(hwndButton, SW_SHOW);
140 if(data.pos+data.step < data.range) {
141 data.pos += data.step;
142 SendMessage(data.hwndButton, PBM_STEPIT, wParam, lParam);
147 HDC hdc; /* A device context used for drawing */
148 PAINTSTRUCT ps; /* Also used during window drawing */
149 RECT rc; /* A rectangle used during drawing */
152 SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
153 GetTextMetrics(hdc, &tm);
154 ReleaseDC(hwnd, hdc);
156 hdc = BeginPaint (hwnd, &ps);
158 rc.top = 8; rc.left= 0; rc.right = data.width; rc.bottom = 24;
159 DrawText(hdc, data.text1, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
162 rc.top = 112; rc.left= 0; rc.right = data.width; rc.bottom = 128;
163 InvalidateRect(hwnd,&rc,1);
164 DrawText(hdc, data.text3, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
168 char*text = data.text2;
169 if(tm.tmAveCharWidth * strlen(text) > data.width) {
170 int chars = (data.width / tm.tmAveCharWidth)-8;
171 if(chars>240) chars=240;
172 strncpy(buf, text, chars);
173 strcpy(&buf[chars],"...");
177 rc.top = 32; rc.left= 0; rc.right = data.width; rc.bottom = 48;
178 DrawText(hdc, text, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
180 EndPaint (hwnd, &ps);
185 return DefWindowProc(hwnd, message, wParam, lParam);
187 return DefWindowProc(hwnd, message, wParam, lParam);
189 } else if(hwnd == wnd_params) {
190 static struct params_data data;
194 memset(&data, 0, sizeof(data));
195 CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
197 GetClientRect (hwnd, &rc);
198 data.width = rc.right - rc.left;
199 data.height = rc.bottom - rc.top;
201 //EDITTEXT IDD_EDIT,68,8,72,12, ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP
202 HWND text = CreateWindow(
204 "Select Installation Directory:",
205 WS_CHILD | WS_VISIBLE,
216 SendMessage(text, WM_SETTEXT, "test1", "test2");
218 data.edit = CreateWindow (
221 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL,
232 data.installButton = CreateWindow (
235 WS_CHILD | WS_VISIBLE | WS_TABSTOP,
248 return DefWindowProc(hwnd, message, wParam, lParam);
252 DestroyWindow(wnd_params);
257 DestroyWindow(wnd_params);
265 return DefWindowProc(hwnd, message, wParam, lParam);
267 return DefWindowProc(hwnd, message, wParam, lParam);
270 return DefWindowProc(hwnd, message, wParam, lParam);
273 void processMessages()
276 while(PeekMessage(&msg,NULL,0,0,0))
278 GetMessage(&msg, NULL, 0, 0);
279 TranslateMessage(&msg);
280 DispatchMessage(&msg);
284 static char*lastmessage = 0;
285 void myarchivestatus(int type, char*text)
287 if(text && text[0]=='[')
289 //printf("%s\n", text);
291 SendMessage(wnd_progress, USER_SETMESSAGE, (WPARAM)strdup(text), 0);
292 SendMessage(wnd_progress, WM_PAINT, 0, 0);
295 SendMessage(wnd_progress, PBM_STEPIT, 0, 0);
296 /* while we're here, we might also make ourselves useful */
298 /* we want the user to see what we're writing, right? */
304 int ret = MessageBox(0, text, "Error", MB_RETRYCANCEL|MB_ICONERROR);
306 /* there is no MB_CANCEL, so, *sigh*, we have to display
307 the "retry" button. So pretend it's doing anything... */
316 static int regEnter(char*key,char*value)
320 ret = RegCreateKey(HKEY_LOCAL_MACHINE, key, &hkey);
321 if(ret != ERROR_SUCCESS) {
322 fprintf(stderr, "registry: CreateKey %s failed\n", key);
325 ret = RegSetValue(hkey, NULL, REG_SZ, value, strlen(value)+1);
326 if(ret != ERROR_SUCCESS) {
327 fprintf(stderr, "registry: SetValue %s failed\n", key);
333 int addRegistryEntries(char*install_dir)
336 ret = regEnter("Software\\quiss.org\\swftools\\InstallPath", install_dir);
341 int WINAPI WinMain(HINSTANCE me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMode)
344 char*install_dir = "C:\\swftools\\";
347 wcl.lpszClassName= "SWFTools-Installer";
348 wcl.lpfnWndProc = WindowFunc;
349 wcl.style = CS_HREDRAW | CS_VREDRAW;
350 wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
351 wcl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
352 wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
353 wcl.lpszMenuName = NULL; //no menu
356 //wcl.hbrBackground= (HBRUSH) GetStockObject(DKGRAY_BRUSH);
357 wcl.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH);
358 wcl.cbSize = sizeof(WNDCLASSEX);
360 if(!RegisterClassEx (&wcl)) {
364 InitCommonControls();
367 wcl.lpszClassName, /* Class name */
368 "SWFTools Installer", /* Caption */
369 WS_OVERLAPPEDWINDOW&(~WS_SIZEBOX), /* Style */
370 CW_USEDEFAULT, /* Initial x (use default) */
371 CW_USEDEFAULT, /* Initial y (use default) */
372 320, /* Initial x size */
373 200, /* Initial y size */
374 NULL, /* No parent window */
376 me, /* This program instance */
377 (void*)"params" /* Creation parameters */
379 ShowWindow (wnd_params, nWinMode);
380 UpdateWindow (wnd_params);
385 GetMessage(&msg,NULL,0,0);
386 TranslateMessage(&msg);
387 DispatchMessage(&msg);
391 sprintf(buf, "Do you want me to install SWFTools into the directory %s now?", install_dir);
392 int ret = MessageBox(0, buf, "SWFTools Install", MB_YESNO|MB_ICONQUESTION);
398 wcl.lpszClassName, /* Class name */
399 "Installing...", /* Caption */
400 WS_OVERLAPPEDWINDOW&(~WS_SIZEBOX), /* Style */
401 CW_USEDEFAULT, /* Initial x (use default) */
402 CW_USEDEFAULT, /* Initial y (use default) */
403 260, /* Initial x size */
404 128, /* Initial y size */
405 NULL, /* No parent window */
407 me, /* This program instance */
408 (void*)"progress" /* Creation parameters */
410 ShowWindow (wnd_progress, nWinMode);
411 UpdateWindow (wnd_progress);
413 int success = unpack_archive(crndata, "C:\\swftools\\", myarchivestatus);
415 DestroyWindow(wnd_progress);
420 if(!addRegistryEntries(install_dir)) {
422 ret = MessageBox(0, "Couldn't create Registry Entries", "SWFTools Install", MB_OK|MB_ICONERROR);
426 sprintf(buf, "SWFTools Version %s has been installed into %s successfully", VERSION, install_dir);
427 ret = MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONINFORMATION);
429 /* error will already have been notified by either myarchivestatus or some other
431 /*sprintf(buf, "Installation failed\nLast message: %s", lastmessage);
432 ret = MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONERROR);*/