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 */
30 #include "../config.h" //for swftools version
34 static char*install_path = "c:\\swftools\\";
35 static char pathBuf[1024];
36 static int do_abort = 0;
38 static HWND wnd_progress = 0;
39 static HWND wnd_params = 0;
41 #define USER_SETMESSAGE 0x7f01
43 struct progress_data {
64 LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
66 printf("%08x, %d %08x %08x\n", hwnd, message, wParam, lParam);
68 /* in order for the delegation below to also work for
69 WM_CREATE, we need to assign our window pointers *before* the
70 CreateWindow returns, because that's when the WM_CREATE event
72 if(message == WM_CREATE) {
73 CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
74 if(cs->lpCreateParams && !strcmp((char*)cs->lpCreateParams, "params")) {
77 if(cs->lpCreateParams && !strcmp((char*)cs->lpCreateParams, "progress")) {
83 return DefWindowProc(hwnd, message, wParam, lParam);
84 } else if(hwnd == wnd_progress) {
85 static struct progress_data data;
90 data.text3 = (char*)wParam;
91 SendMessage(data.wnd_text3, WM_SETTEXT, 0, (LPARAM)data.text3);
94 memset(&data, 0, sizeof(data));
95 data.text1 = "Installing SWFTools";
96 data.text2 = (char*)malloc(strlen(install_path)+250);
97 sprintf(data.text2, "to %s", install_path);
101 CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
103 GetClientRect (hwnd, &rc);
104 data.width = rc.right - rc.left;
105 data.height = rc.bottom - rc.top;
106 data.bar_width = cs->cx - 17;
108 data.bar_posx = (data.width -data.bar_width)/2;
111 data.hwndButton = CreateWindow (
114 WS_CHILD | WS_VISIBLE,
125 data.wnd_text3 = CreateWindow (
128 WS_CHILD | WS_VISIBLE | ES_READONLY | ES_CENTER,
131 (rc.right - rc.left - data.bar_posx*2),
138 SendMessage(data.wnd_text3, WM_SETTEXT, 0, (LPARAM)"");
140 SendMessage(data.hwndButton, PBM_SETRANGE, 0, (LPARAM) MAKELONG(0,data.range));
141 SendMessage(data.hwndButton, PBM_SETSTEP, (WPARAM) data.step, 0);
145 if(data.pos+data.step < data.range) {
146 data.pos += data.step;
147 SendMessage(data.hwndButton, PBM_STEPIT, wParam, lParam);
152 HDC hdc; /* A device context used for drawing */
153 PAINTSTRUCT ps; /* Also used during window drawing */
154 RECT rc; /* A rectangle used during drawing */
157 SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
158 GetTextMetrics(hdc, &tm);
159 ReleaseDC(hwnd, hdc);
162 hdc = BeginPaint (hwnd, &ps);
164 SetBkMode(hdc, TRANSPARENT);
166 rc.top = 8; rc.left= 0; rc.right = data.width; rc.bottom = 24;
167 DrawText(hdc, data.text1, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
170 char*text = data.text2;
171 if(tm.tmAveCharWidth * strlen(text) > data.width) {
172 int chars = (data.width / tm.tmAveCharWidth)-8;
173 if(chars>240) chars=240;
174 strncpy(buf, text, chars);
175 strcpy(&buf[chars],"...");
179 rc.top = 32; rc.left= 0; rc.right = data.width; rc.bottom = 48;
180 DrawText(hdc, text, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
182 EndPaint (hwnd, &ps);
187 return DefWindowProc(hwnd, message, wParam, lParam);
189 return DefWindowProc(hwnd, message, wParam, lParam);
191 } else if(hwnd == wnd_params) {
192 static struct params_data data;
196 memset(&data, 0, sizeof(data));
197 CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
199 GetClientRect (hwnd, &rc);
200 data.width = rc.right - rc.left;
201 data.height = rc.bottom - rc.top;
203 //EDITTEXT IDD_EDIT,68,8,72,12, ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP
204 HWND text = CreateWindow(
206 "Select Installation Directory:",
207 WS_CHILD | WS_VISIBLE,
218 data.edit = CreateWindow (
221 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL,
224 (data.width-64)-32*2,
232 data.explore = CreateWindow (
235 WS_CHILD | WS_VISIBLE | WS_TABSTOP,
246 data.installButton = CreateWindow (
249 WS_CHILD | WS_VISIBLE | WS_TABSTOP,
260 SendMessage(data.edit, WM_SETTEXT, 0, (LPARAM)install_path);
263 case USER_SETMESSAGE: {
264 //install_path = (char*)lParam;
265 SendMessage(data.edit, WM_SETTEXT, 0, (LPARAM)install_path);
266 printf("Setting path to %s\n", install_path);
270 return DefWindowProc(hwnd, message, wParam, lParam);
273 if((wParam&0xffff) == 0x9999) {
275 memset(&browse, 0, sizeof(browse));
276 browse.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_USENEWUI;// | BIF_RETURNONLYFSDIRS; //BIF_VALIDATE
277 browse.pszDisplayName = (CHAR*)malloc(MAX_PATH);
278 memset(browse.pszDisplayName, 0, MAX_PATH);
279 browse.lpszTitle = "Select installation directory";
280 /*browse.pidlRoot = (ITEMIDLIST*)malloc(sizeof(ITEMIDLIST)*200);
281 memset((void*)browse.pidlRoot, 0, sizeof(ITEMIDLIST)*200);*/
282 printf("Start browsing %s\n", browse.pszDisplayName);
284 //ParseDisplayName(install_path,0,&browse.pidlRoot,0,0);
285 //SHParseDisplayName(install_path,0,&browse.pidlRoot,0,0);
286 //SHBrowseForFolderA(&browse);
287 browse.pidlRoot = SHBrowseForFolder(&browse);
288 printf("Browsing returns %s / %08x\n", browse.pszDisplayName, browse.pidlRoot);
289 if(browse.pszDisplayName) {
290 if(SHGetPathFromIDList(browse.pidlRoot, browse.pszDisplayName)) {
291 printf("Path is %s\n", browse.pszDisplayName);
292 install_path = browse.pszDisplayName;
295 SendMessage(data.edit, WM_SETTEXT, 0, (LPARAM)install_path);
297 } else if((wParam&0xffff) == 0xabcd) {
299 DestroyWindow(wnd_params);
301 } else if((wParam&0xffff) == 0x1234) {
302 SendMessage(data.edit, WM_GETTEXT, sizeof(pathBuf), (LPARAM)&(pathBuf[0]));
304 install_path = pathBuf;
305 printf("Path edited: now \"%s\"\n", install_path);
309 return DefWindowProc(hwnd, message, wParam, lParam);
313 DestroyWindow(wnd_params);
323 return DefWindowProc(hwnd, message, wParam, lParam);
325 return DefWindowProc(hwnd, message, wParam, lParam);
328 return DefWindowProc(hwnd, message, wParam, lParam);
331 void processMessages()
334 while(PeekMessage(&msg,NULL,0,0,0))
336 GetMessage(&msg, NULL, 0, 0);
337 TranslateMessage(&msg);
338 DispatchMessage(&msg);
342 static char*lastmessage = 0;
343 void myarchivestatus(int type, char*text)
345 if(text && text[0]=='[')
347 //printf("%s\n", text);
349 SendMessage(wnd_progress, USER_SETMESSAGE, (WPARAM)strdup(text), 0);
350 SendMessage(wnd_progress, WM_PAINT, 0, 0);
353 SendMessage(wnd_progress, PBM_STEPIT, 0, 0);
354 /* while we're here, we might also make ourselves useful */
356 /* we want the user to see what we're writing, right? */
362 int ret = MessageBox(0, text, "Error", MB_RETRYCANCEL|MB_ICONERROR);
364 /* there is no MB_CANCEL, so, *sigh*, we have to display
365 the "retry" button. So pretend it's doing anything... */
374 static int regEnter(char*key,char*value)
378 ret = RegCreateKey(HKEY_LOCAL_MACHINE, key, &hkey);
379 if(ret != ERROR_SUCCESS) {
380 fprintf(stderr, "registry: CreateKey %s failed\n", key);
383 ret = RegSetValue(hkey, NULL, REG_SZ, value, strlen(value)+1);
384 if(ret != ERROR_SUCCESS) {
385 fprintf(stderr, "registry: SetValue %s failed\n", key);
391 int addRegistryEntries(char*install_dir)
394 ret = regEnter("Software\\quiss.org\\swftools\\InstallPath", install_dir);
399 int WINAPI WinMain(HINSTANCE me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMode)
404 wcl.lpszClassName= "SWFTools-Installer";
405 wcl.lpfnWndProc = WindowFunc;
406 wcl.style = CS_HREDRAW | CS_VREDRAW;
407 wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
408 wcl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
409 wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
410 wcl.lpszMenuName = NULL; //no menu
413 //wcl.hbrBackground= (HBRUSH) GetStockObject(DKGRAY_BRUSH);
414 //wcl.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH);
415 wcl.hbrBackground= (HBRUSH) GetStockObject (LTGRAY_BRUSH);
416 //wcl.hbrBackground= (HBRUSH) GetStockObject (GRAY_BRUSH);
417 wcl.cbSize = sizeof(WNDCLASSEX);
419 if(!RegisterClassEx (&wcl)) {
424 InitCommonControls();
427 wcl.lpszClassName, /* Class name */
428 "SWFTools Installer", /* Caption */
429 WS_OVERLAPPEDWINDOW&(~WS_SIZEBOX), /* Style */
430 CW_USEDEFAULT, /* Initial x (use default) */
431 CW_USEDEFAULT, /* Initial y (use default) */
432 320, /* Initial x size */
433 200, /* Initial y size */
434 NULL, /* No parent window */
436 me, /* This program instance */
437 (void*)"params" /* Creation parameters */
440 ShowWindow (wnd_params, nWinMode);
441 UpdateWindow (wnd_params);
446 GetMessage(&msg,NULL,0,0);
447 TranslateMessage(&msg);
448 DispatchMessage(&msg);
455 sprintf(buf, "Do you want me to install SWFTools into the directory %s now?", install_path);
456 int ret = MessageBox(0, buf, "SWFTools Install", MB_YESNO|MB_ICONQUESTION);
461 wcl.lpszClassName, /* Class name */
462 "Installing...", /* Caption */
463 WS_OVERLAPPEDWINDOW&(~WS_SIZEBOX), /* Style */
464 CW_USEDEFAULT, /* Initial x (use default) */
465 CW_USEDEFAULT, /* Initial y (use default) */
466 260, /* Initial x size */
467 128, /* Initial y size */
468 NULL, /* No parent window */
470 me, /* This program instance */
471 (void*)"progress" /* Creation parameters */
473 ShowWindow (wnd_progress, nWinMode);
474 UpdateWindow (wnd_progress);
476 int success = unpack_archive(crndata, "C:\\swftools\\", myarchivestatus);
478 DestroyWindow(wnd_progress);
483 if(!addRegistryEntries(install_path)) {
485 MessageBox(0, "Couldn't create Registry Entries", "SWFTools Install", MB_OK|MB_ICONERROR);
490 sprintf(buf, "SWFTools Version %s has been installed into %s successfully", VERSION, install_path);
491 MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONINFORMATION);
493 /* error will already have been notified by either myarchivestatus or some other
495 /*sprintf(buf, "Installation failed\nLast message: %s", lastmessage);
496 ret = MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONERROR);*/