11 #include "wx/resource.h"
17 #if !defined(__EMX__) && !defined(__OS2__) && !defined(WIN32) && !defined(WINNT)
18 #define stricmp strcasecmp
25 extern char installdir
[];
31 typedef struct _wxCommands
{
38 wxCommands wxcommands
[COMMANDMAX
];
39 char finishedscript
[256] = "";
40 char percentname
[256] = "";
42 class MyApp
: public wxApp
47 virtual bool OnInit();
52 class MyDialog
: public wxDialog
55 void handle_button(wxCommandEvent
& event
);
58 class MyThread
: public wxThread
61 virtual void *Entry();
64 void *MyThread::Entry()
70 MyDialog
*dialog
= NULL
;
78 wxCondition
*InstCond
= NULL
;
80 void updatepercent(void)
82 wxGauge
*tmp
= (wxGauge
*)wxFindWindowByName(percentname
, dialog
);
86 unsigned long sliderpos
;
88 extern int current_file
, files
;
90 sliderpos
= (unsigned long)(((float)(current_file
)/(float)files
)*pixels
);
91 tmp
->SetValue(sliderpos
);
95 int parse_ini(char *filename
)
100 for(b
=0;b
<COMMANDMAX
;b
++)
102 wxcommands
[b
].id
= 0;
103 wxcommands
[b
].file
[0] = 0;
107 if((f
=fopen(filename
, "r")) != NULL
)
110 char raw
[256], entry
[256], entrydata
[256], entrydata2
[256];
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
)
116 bytesread
= getparseline(f
, '#', ',', '\"', raw
, entry
, entrydata
, entrydata2
);
117 if(stricmp(entry
, "loadwxr") == 0)
120 if(!wxResourceParseFile(entrydata
))
122 error("Error loading resources!");
129 dialog
= new MyDialog
;
131 dialog
->LoadFromResource(NULL
, "dialog1");
134 /*MyApp::SetTopWindow(dialog);*/
136 else if(stricmp(entry
, "closeold") == 0)
142 else if(stricmp(entry
, "getcheck") == 0)
144 wxCheckBox
*tmp
= (wxCheckBox
*)wxFindWindowByName(entrydata
, dialog
);
150 parse_ini(entrydata2
);
155 else if(stricmp(entry
, "gettext") == 0)
157 wxTextCtrl
*tmp
= (wxTextCtrl
*)wxFindWindowByName(entrydata
, dialog
);
162 if((bleah
= tmp
->GetValue()))
163 strcpy(installdir
, bleah
);
166 else if(stricmp(entry
, "settext") == 0)
168 wxTextCtrl
*tmp
= (wxTextCtrl
*)wxFindWindowByName(entrydata
, dialog
);
171 tmp
->SetValue(installdir
);
173 else if(stricmp(entry
, "message") == 0)
175 else if(stricmp(entry
, "disable") == 0)
177 wxButton
*tmp
= (wxButton
*)wxFindWindowByName(entrydata
, dialog
);
181 else if(stricmp(entry
, "grabfile") == 0)
183 else if(stricmp(entry
, "remove") == 0)
185 else if(stricmp(entry
, "system") == 0)
186 wxExecute(entrydata
);
187 else if(stricmp(entry
, "startinst") == 0)
189 strcpy(percentname
, entrydata
);
190 strcpy(finishedscript
, entrydata2
);
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
197 MyThread
*thread
= new MyThread();
199 if ( thread
->Create() != wxTHREAD_NO_ERROR
)
201 error("Can't create thread!");
203 strcpy(finishedscript
, entrydata
);
205 InstCond
= new wxCondition();
209 wxMutex
*test
= new wxMutex();
211 InstCond
->Wait(*test
);
213 install_thread(NULL
);
214 create_wps_objects();
215 parse_ini(finishedscript
);
217 else if(stricmp(entry
, "mleview") == 0)
222 wxTextCtrl
*tmp
= (wxTextCtrl
*)wxFindWindowByName(entrydata
, dialog
);
226 grabfile(entrydata2
);
228 if((f
= fopen(entrydata2
, "rb"))!= NULL
)
232 memset(buffer
, 0, 1025);
233 bytes
= fread(buffer
, 1, 1024, f
);
239 tmp
->ShowPosition(0);
243 else if(stricmp(entry
, "setbutton") == 0)
245 for(b
=0;b
<COMMANDMAX
;b
++)
247 if(!wxcommands
[b
].id
)
249 wxcommands
[b
].id
= atoi(entrydata
);
250 strcpy(wxcommands
[b
].file
, entrydata2
);
254 dialog
->Connect( atol(entrydata
), -1, wxEVT_COMMAND_BUTTON_CLICKED
,
255 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
256 &MyDialog::handle_button
);
268 void MyDialog::handle_button(wxCommandEvent
& event
)
272 for(b
=0;b
<COMMANDMAX
;b
++)
274 if(wxcommands
[b
].id
&&
275 wxcommands
[b
].id
== event
.GetId())
279 strcpy(tempbuf
, wxcommands
[b
].file
);
280 if(stricmp(tempbuf
, "exit") == 0)
283 if(!parse_ini(tempbuf
))
285 error("Error loading script \"%s\"", tempbuf
);
295 bool MyApp::OnInit(void)
298 install_init(argv
[0]);
300 install_init("install.exe");
303 if(!parse_ini("page1.ini"))
305 error("Could not load startup script!");