fixed empty CVS checkin.
[swftools.git] / installer / installer.c
1 /* installer.c
2
3    Part of the swftools installer (Main program).
4    
5    Copyright (c) 2004 Matthias Kramm <kramm@quiss.org> 
6  
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.
11
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.
16
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 */
20
21 #include <windows.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include "depack.h"
26
27 #include "../config.h" //for swftools version
28
29 extern char*crndata;
30
31 LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
32 {
33     printf("%08x, %d %08x %08x\n", hwnd, message, wParam, lParam);
34     switch(message)
35     {
36         case WM_DESTROY:
37             PostQuitMessage(0);
38             break;
39         default:
40             return DefWindowProc(hwnd, message, wParam, lParam);
41     }
42     return 0;
43 }
44
45 #if USE_CONSOLE
46 static HANDLE console;
47 #endif
48 static char*lastmessage = 0;
49 void myarchivestatus(int type, char*text)
50 {
51     DWORD written = 0;
52 #if USE_CONSOLE
53     if(console) {
54         WriteConsole(console, text, strlen(text), &written, 0);
55         WriteConsole(console, "\n", 1, &written, 0);
56         fflush(stdout);
57     } 
58 #endif
59     if(!written) {
60         printf("%s\n", text);
61     }
62
63     if(type<0) {
64         while(1) {
65             int ret = MessageBox(0, text, "Error", MB_RETRYCANCEL|MB_ICONERROR);
66             
67             /* there is no MB_CANCEL, so, *sigh*, we have to display
68                the "retry" button. So pretend it's doing anything... */
69             if(ret==IDRETRY)
70                 continue;
71             else
72                 break;
73         }
74     }
75 }
76
77 int WINAPI WinMain(HINSTANCE me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMode)
78 {
79     WNDCLASS wcl;
80     char*install_dir = "C:\\swftools\\";
81
82     wcl.hInstance    = me;
83     wcl.lpszClassName= "SWFTools-Installer";
84     wcl.lpfnWndProc  = WindowFunc;
85     wcl.style        = 0; //default style
86     wcl.hIcon        = LoadIcon  (NULL, IDI_APPLICATION);
87     wcl.hCursor      = LoadCursor(NULL, IDC_ARROW);
88     wcl.lpszMenuName = NULL; //no menu
89     wcl.cbClsExtra   = 0;
90     wcl.cbWndExtra   = 0;
91     wcl.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
92
93     if(!RegisterClass(&wcl)) 
94         return 0;
95    
96 #if USE_CONSOLE
97     FreeConsole();
98 #endif
99    
100     char buf[1024];
101     sprintf(buf, "Do you want me to install SWFTools into the directory %s now?", install_dir);
102     int ret = MessageBox(0, buf, "SWFTools Install", MB_YESNO|MB_ICONQUESTION);
103
104     if(ret == IDNO)
105         return 0;
106     
107 #if USE_CONSOLE
108     if(AllocConsole()) {
109         DWORD written;
110         console = GetStdHandle(STD_OUTPUT_HANDLE);
111         WriteConsole(console, "\r\n", 1, &written, 0);
112     }
113 #endif
114
115     int success = unpack_archive(crndata, "C:\\swftools\\", myarchivestatus);
116
117 #if USE_CONSOLE
118     FreeConsole();
119 #endif
120
121     if(success) {
122         sprintf(buf, "SWFTools Version %s has been installed into %s successfully", VERSION, install_dir);
123         ret = MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONINFORMATION);
124     } else {
125         /*sprintf(buf, "Installation failed\nLast message: %s", lastmessage);
126         ret = MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONERROR);*/
127     }
128     exit(0);
129 }
130
131
132