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
31 #include "../lib/os.h" //for registry functions
35 static char*install_path = "c:\\swftools\\";
36 static char pathBuf[1024];
37 static int do_abort = 0;
39 static HWND wnd_progress = 0;
40 static HWND wnd_params = 0;
44 #define USER_SETMESSAGE 0x7f01
46 struct progress_data {
67 LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
69 printf("%08x, %d %08x %08x\n", hwnd, message, wParam, lParam);
71 /* in order for the delegation below to also work for
72 WM_CREATE, we need to assign our window pointers *before* the
73 CreateWindow returns, because that's when the WM_CREATE event
75 if(message == WM_CREATE) {
76 CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
77 if(cs->lpCreateParams && !strcmp((char*)cs->lpCreateParams, "params")) {
80 if(cs->lpCreateParams && !strcmp((char*)cs->lpCreateParams, "progress")) {
86 return DefWindowProc(hwnd, message, wParam, lParam);
87 } else if(hwnd == wnd_progress) {
88 static struct progress_data data;
93 data.text3 = (char*)wParam;
94 SendMessage(data.wnd_text3, WM_SETTEXT, 0, (LPARAM)data.text3);
97 memset(&data, 0, sizeof(data));
98 data.text1 = "Installing SWFTools";
99 data.text2 = (char*)malloc(strlen(install_path)+250);
100 sprintf(data.text2, "to %s", install_path);
104 CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
106 GetClientRect (hwnd, &rc);
107 data.width = rc.right - rc.left;
108 data.height = rc.bottom - rc.top;
109 data.bar_width = cs->cx - 17;
111 data.bar_posx = (data.width -data.bar_width)/2;
115 data.hwndButton = CreateWindow (
118 WS_CHILD | WS_VISIBLE,
129 data.wnd_text3 = CreateWindow (
132 WS_CHILD | WS_VISIBLE,
135 (rc.right - rc.left - data.bar_posx*2),
142 SendMessage(data.wnd_text3, WM_SETTEXT, 0, (LPARAM)"");
144 SendMessage(data.hwndButton, PBM_SETRANGE, 0, (LPARAM) MAKELONG(0,data.range));
145 SendMessage(data.hwndButton, PBM_SETSTEP, (WPARAM) data.step, 0);
149 if(data.pos+data.step < data.range) {
150 data.pos += data.step;
151 SendMessage(data.hwndButton, PBM_STEPIT, wParam, lParam);
156 HDC hdc; /* A device context used for drawing */
157 PAINTSTRUCT ps; /* Also used during window drawing */
158 RECT rc; /* A rectangle used during drawing */
161 SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
162 GetTextMetrics(hdc, &tm);
163 ReleaseDC(hwnd, hdc);
165 hdc = BeginPaint (hwnd, &ps);
169 HDC memDc=CreateCompatibleDC(hdc);
170 SelectObject(memDc,logo);
171 BitBlt(hdc,0,0,406,93,memDc,0,0,SRCCOPY);
176 SetBkMode(hdc, TRANSPARENT);
178 rc.top = 8; rc.left= 0; rc.right = data.width; rc.bottom = 24;
179 DrawText(hdc, data.text1, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
182 char*text = data.text2;
183 if(tm.tmAveCharWidth * strlen(text) > data.width) {
184 int chars = (data.width / tm.tmAveCharWidth)-8;
185 if(chars>240) chars=240;
186 strncpy(buf, text, chars);
187 strcpy(&buf[chars],"...");
191 rc.top = 32; rc.left= 0; rc.right = data.width; rc.bottom = 48;
192 DrawText(hdc, text, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
194 EndPaint (hwnd, &ps);
199 return DefWindowProc(hwnd, message, wParam, lParam);
201 return DefWindowProc(hwnd, message, wParam, lParam);
203 } else if(hwnd == wnd_params) {
204 static struct params_data data;
208 memset(&data, 0, sizeof(data));
209 CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
211 GetClientRect (hwnd, &rc);
212 data.width = rc.right - rc.left;
213 data.height = rc.bottom - rc.top;
215 //EDITTEXT IDD_EDIT,68,8,72,12, ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP
216 HWND text = CreateWindow(
218 "Select Installation Directory:",
219 WS_CHILD | WS_VISIBLE,
230 data.edit = CreateWindow (
233 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL,
236 (data.width-64)-32*2,
244 data.explore = CreateWindow (
247 WS_CHILD | WS_VISIBLE | WS_TABSTOP,
258 data.installButton = CreateWindow (
261 WS_CHILD | WS_VISIBLE | WS_TABSTOP,
272 SendMessage(data.edit, WM_SETTEXT, 0, (LPARAM)install_path);
275 case USER_SETMESSAGE: {
276 //install_path = (char*)lParam;
277 SendMessage(data.edit, WM_SETTEXT, 0, (LPARAM)install_path);
278 printf("Setting path to %s\n", install_path);
282 return DefWindowProc(hwnd, message, wParam, lParam);
285 if((wParam&0xffff) == 0x9999) {
287 memset(&browse, 0, sizeof(browse));
288 browse.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_USENEWUI;// | BIF_RETURNONLYFSDIRS; //BIF_VALIDATE
289 browse.pszDisplayName = (CHAR*)malloc(MAX_PATH);
290 memset(browse.pszDisplayName, 0, MAX_PATH);
291 browse.lpszTitle = "Select installation directory";
292 /*browse.pidlRoot = (ITEMIDLIST*)malloc(sizeof(ITEMIDLIST)*200);
293 memset((void*)browse.pidlRoot, 0, sizeof(ITEMIDLIST)*200);*/
294 printf("Start browsing %s\n", browse.pszDisplayName);
296 //ParseDisplayName(install_path,0,&browse.pidlRoot,0,0);
297 //SHParseDisplayName(install_path,0,&browse.pidlRoot,0,0);
298 //SHBrowseForFolderA(&browse);
299 browse.pidlRoot = SHBrowseForFolder(&browse);
300 printf("Browsing returns %s / %08x\n", browse.pszDisplayName, browse.pidlRoot);
301 if(browse.pszDisplayName) {
302 if(SHGetPathFromIDList(browse.pidlRoot, browse.pszDisplayName)) {
303 printf("Path is %s\n", browse.pszDisplayName);
304 install_path = browse.pszDisplayName;
307 SendMessage(data.edit, WM_SETTEXT, 0, (LPARAM)install_path);
309 } else if((wParam&0xffff) == 0xabcd) {
311 DestroyWindow(wnd_params);
313 } else if((wParam&0xffff) == 0x1234) {
314 SendMessage(data.edit, WM_GETTEXT, sizeof(pathBuf), (LPARAM)&(pathBuf[0]));
316 install_path = pathBuf;
317 printf("Path edited: now \"%s\"\n", install_path);
321 return DefWindowProc(hwnd, message, wParam, lParam);
325 DestroyWindow(wnd_params);
335 return DefWindowProc(hwnd, message, wParam, lParam);
337 return DefWindowProc(hwnd, message, wParam, lParam);
340 return DefWindowProc(hwnd, message, wParam, lParam);
343 void processMessages()
346 while(PeekMessage(&msg,NULL,0,0,0))
348 GetMessage(&msg, NULL, 0, 0);
349 TranslateMessage(&msg);
350 DispatchMessage(&msg);
354 static char*lastmessage = 0;
355 void myarchivestatus(int type, char*text)
357 if(text && text[0]=='[')
359 //printf("%s\n", text);
361 SendMessage(wnd_progress, USER_SETMESSAGE, (WPARAM)strdup(text), 0);
362 SendMessage(wnd_progress, WM_PAINT, 0, 0);
365 SendMessage(wnd_progress, PBM_STEPIT, 0, 0);
366 /* while we're here, we might also make ourselves useful */
368 /* we want the user to see what we're writing, right? */
374 int ret = MessageBox(0, text, "Error", MB_RETRYCANCEL|MB_ICONERROR);
376 /* there is no MB_CANCEL, so, *sigh*, we have to display
377 the "retry" button. So pretend it's doing anything... */
386 int addRegistryEntries(char*install_dir)
389 ret = setRegistryEntry("Software\\quiss.org\\swftools\\InstallPath", install_dir);
394 int WINAPI WinMain(HINSTANCE me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMode)
399 wcl.lpszClassName= "SWFTools-Installer";
400 wcl.lpfnWndProc = WindowFunc;
401 wcl.style = CS_HREDRAW | CS_VREDRAW;
402 wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
403 wcl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
404 wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
405 wcl.lpszMenuName = NULL; //no menu
408 //wcl.hbrBackground= (HBRUSH) GetStockObject(DKGRAY_BRUSH);
409 //wcl.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH);
410 wcl.hbrBackground= (HBRUSH) GetStockObject(LTGRAY_BRUSH);
411 //wcl.hbrBackground= (HBRUSH) GetStockObject (GRAY_BRUSH);
412 wcl.cbSize = sizeof(WNDCLASSEX);
414 if(!RegisterClassEx(&wcl)) {
418 logo = LoadBitmap(me, "SWFTOOLS");
420 install_path = getRegistryEntry("Software\\quiss.org\\swftools\\InstallPath");
421 if(!install_path || !install_path[0])
422 install_path = "c:\\swftools\\";
425 InitCommonControls();
428 wcl.lpszClassName, /* Class name */
429 "SWFTools Installer", /* Caption */
430 WS_OVERLAPPEDWINDOW&(~WS_SIZEBOX), /* Style */
431 CW_USEDEFAULT, /* Initial x (use default) */
432 CW_USEDEFAULT, /* Initial y (use default) */
433 320, /* Initial x size */
434 200, /* Initial y size */
435 NULL, /* No parent window */
437 me, /* This program instance */
438 (void*)"params" /* Creation parameters */
441 ShowWindow (wnd_params, nWinMode);
442 UpdateWindow (wnd_params);
447 GetMessage(&msg,NULL,0,0);
448 TranslateMessage(&msg);
449 DispatchMessage(&msg);
456 sprintf(buf, "Do you want me to install SWFTools into the directory %s now?", install_path);
457 int ret = MessageBox(0, buf, "SWFTools Install", MB_YESNO|MB_ICONQUESTION);
462 wcl.lpszClassName, /* Class name */
463 "Installing...", /* Caption */
464 WS_OVERLAPPEDWINDOW&(~WS_SIZEBOX), /* Style */
465 CW_USEDEFAULT, /* Initial x (use default) */
466 CW_USEDEFAULT, /* Initial y (use default) */
467 260, /* Initial x size */
468 128, /* Initial y size */
469 NULL, /* No parent window */
471 me, /* This program instance */
472 (void*)"progress" /* Creation parameters */
474 ShowWindow (wnd_progress, nWinMode);
475 UpdateWindow (wnd_progress);
477 int success = unpack_archive(crndata, install_path, myarchivestatus);
479 DestroyWindow(wnd_progress);
484 if(!addRegistryEntries(install_path)) {
486 MessageBox(0, "Couldn't create Registry Entries", "SWFTools Install", MB_OK|MB_ICONERROR);
491 sprintf(buf, "SWFTools Version %s has been installed into %s successfully", VERSION, install_path);
492 MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONINFORMATION);
494 /* error will already have been notified by either myarchivestatus or some other
496 /*sprintf(buf, "Installation failed\nLast message: %s", lastmessage);
497 ret = MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONERROR);*/