]> git.saurik.com Git - wxWidgets.git/blob - utils/Install/wxmain.cpp
changed version number
[wxWidgets.git] / utils / Install / wxmain.cpp
1 #include "wx/wxprec.h"
2
3 #ifdef __BORLANDC__
4 #pragma hdrstop
5 #endif
6
7 #ifndef WX_PRECOMP
8 #include "wx/wx.h"
9 #endif
10
11 #include "wx/resource.h"
12 #include "install.h"
13 #include "instsup.h"
14
15 #include <ctype.h>
16
17 #if !defined(__EMX__) && !defined(__OS2__) && !defined(WIN32) && !defined(WINNT)
18 #define stricmp strcasecmp
19 #endif
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 extern char installdir[];
26
27 #ifdef __cplusplus
28 }
29 #endif
30
31 typedef struct _wxCommands {
32 int id;
33 char file[50];
34 } wxCommands;
35
36 #define COMMANDMAX 20
37
38 wxCommands wxcommands[COMMANDMAX];
39 char finishedscript[256] = "";
40 char percentname[256] = "";
41
42 class MyApp: public wxApp
43 {
44 public:
45 MyApp();
46
47 virtual bool OnInit();
48
49 virtual ~MyApp();
50 };
51
52 class MyDialog : public wxDialog
53 {
54 public:
55 void handle_button(wxCommandEvent& event);
56 };
57
58 class MyThread : public wxThread
59 {
60 public:
61 virtual void *Entry();
62 };
63
64 void *MyThread::Entry()
65 {
66 install_thread(NULL);
67 return NULL;
68 }
69
70 MyDialog *dialog = NULL;
71
72 IMPLEMENT_APP(MyApp)
73
74 MyApp::MyApp()
75 {
76 }
77
78 wxCondition *InstCond = NULL;
79
80 void updatepercent(void)
81 {
82 wxGauge *tmp = (wxGauge *)wxFindWindowByName(percentname, dialog);
83
84 if(tmp)
85 {
86 unsigned long sliderpos;
87 int pixels = 100;
88 extern int current_file, files;
89
90 sliderpos = (unsigned long)(((float)(current_file)/(float)files)*pixels);
91 tmp->SetValue(sliderpos);
92 }
93 }
94
95 int parse_ini(char *filename)
96 {
97 FILE *f;
98 int b;
99
100 for(b=0;b<COMMANDMAX;b++)
101 {
102 wxcommands[b].id = 0;
103 wxcommands[b].file[0] = 0;
104 }
105
106 grabfile(filename);
107 if((f=fopen(filename, "r")) != NULL)
108 {
109 int bytesread = 1;
110 char raw[256], entry[256], entrydata[256], entrydata2[256];
111
112 /* figure out why we are not getting an EOF on windows...
113 bytesread is a hack to make sure it doesn't loop forever. */
114 while(!feof(f) && bytesread)
115 {
116 bytesread = getparseline(f, '#', ',', '\"', raw, entry, entrydata, entrydata2);
117 if(stricmp(entry, "loadwxr") == 0)
118 {
119 grabfile(entrydata);
120 if(!wxResourceParseFile(entrydata))
121 {
122 error("Error loading resources!");
123 remove(entrydata);
124 remove(filename);
125 return FALSE;
126 }
127 remove(entrydata);
128
129 dialog = new MyDialog;
130
131 dialog->LoadFromResource(NULL, "dialog1");
132 dialog->Show(TRUE);
133
134 /*MyApp::SetTopWindow(dialog);*/
135 }
136 else if(stricmp(entry, "closeold") == 0)
137 {
138 if(dialog)
139 dialog->Destroy();
140 dialog = NULL;
141 }
142 else if(stricmp(entry, "getcheck") == 0)
143 {
144 wxCheckBox *tmp = (wxCheckBox *)wxFindWindowByName(entrydata, dialog);
145
146 if(tmp)
147 {
148 if(!tmp->GetValue())
149 {
150 parse_ini(entrydata2);
151 bytesread = 0;
152 }
153 }
154 }
155 else if(stricmp(entry, "gettext") == 0)
156 {
157 wxTextCtrl *tmp = (wxTextCtrl *)wxFindWindowByName(entrydata, dialog);
158 wxString bleah;
159
160 if(tmp)
161 {
162 if((bleah = tmp->GetValue()))
163 strcpy(installdir, bleah);
164 }
165 }
166 else if(stricmp(entry, "settext") == 0)
167 {
168 wxTextCtrl *tmp = (wxTextCtrl *)wxFindWindowByName(entrydata, dialog);
169
170 if(tmp)
171 tmp->SetValue(installdir);
172 }
173 else if(stricmp(entry, "message") == 0)
174 mesg(entrydata);
175 else if(stricmp(entry, "disable") == 0)
176 {
177 wxButton *tmp = (wxButton *)wxFindWindowByName(entrydata, dialog);
178 if(tmp)
179 tmp->Disable();
180 }
181 else if(stricmp(entry, "grabfile") == 0)
182 grabfile(entrydata);
183 else if(stricmp(entry, "remove") == 0)
184 remove(entrydata);
185 else if(stricmp(entry, "system") == 0)
186 wxExecute(entrydata);
187 else if(stricmp(entry, "startinst") == 0)
188 {
189 strcpy(percentname, entrydata);
190 strcpy(finishedscript, entrydata2);
191
192 /* I couldn't get it working with threads, even when
193 using conditions it blocked the message loop making
194 it unreadable, so I am going with wxYield for the
195 moment. */
196 #if 0
197 MyThread *thread = new MyThread();
198
199 if ( thread->Create() != wxTHREAD_NO_ERROR )
200 {
201 error("Can't create thread!");
202 }
203 strcpy(finishedscript, entrydata);
204
205 InstCond = new wxCondition();
206
207 thread->Run();
208
209 wxMutex *test = new wxMutex();
210
211 InstCond->Wait(*test);
212 #endif
213 install_thread(NULL);
214 create_wps_objects();
215 parse_ini(finishedscript);
216 }
217 else if(stricmp(entry, "mleview") == 0)
218 {
219 FILE *f;
220 unsigned long bytes;
221 char buffer[1025];
222 wxTextCtrl *tmp = (wxTextCtrl *)wxFindWindowByName(entrydata, dialog);
223
224 if(tmp)
225 {
226 grabfile(entrydata2);
227
228 if((f = fopen(entrydata2, "rb"))!= NULL)
229 {
230 while(!feof(f))
231 {
232 memset(buffer, 0, 1025);
233 bytes = fread(buffer, 1, 1024, f);
234 *tmp << buffer;
235 }
236 fclose(f);
237 }
238 remove(entrydata2);
239 tmp->ShowPosition(0);
240 }
241
242 }
243 else if(stricmp(entry, "setbutton") == 0)
244 {
245 for(b=0;b<COMMANDMAX;b++)
246 {
247 if(!wxcommands[b].id)
248 {
249 wxcommands[b].id = atoi(entrydata);
250 strcpy(wxcommands[b].file, entrydata2);
251 b = COMMANDMAX;
252 }
253 }
254 dialog->Connect( atol(entrydata), -1, wxEVT_COMMAND_BUTTON_CLICKED,
255 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
256 &MyDialog::handle_button);
257
258 }
259 }
260 fclose(f);
261 remove(filename);
262 return TRUE;
263 }
264 remove(filename);
265 return FALSE;
266 }
267
268 void MyDialog::handle_button(wxCommandEvent& event )
269 {
270 int b;
271
272 for(b=0;b<COMMANDMAX;b++)
273 {
274 if(wxcommands[b].id &&
275 wxcommands[b].id == event.GetId())
276 {
277 char tempbuf[50];
278
279 strcpy(tempbuf, wxcommands[b].file);
280 if(stricmp(tempbuf, "exit") == 0)
281 exit(0);
282 grabfile(tempbuf);
283 if(!parse_ini(tempbuf))
284 {
285 error("Error loading script \"%s\"", tempbuf);
286 exit(1);
287 }
288 remove(tempbuf);
289 return;
290 }
291 }
292
293 }
294
295 bool MyApp::OnInit(void)
296 {
297 #if 1
298 install_init(argv[0]);
299 #else
300 install_init("install.exe");
301 #endif
302
303 if(!parse_ini("page1.ini"))
304 {
305 error("Could not load startup script!");
306 return FALSE;
307 }
308
309 return TRUE;
310 }
311
312 MyApp::~MyApp()
313 {
314 }
315
316