alternative to assert
[gtkD.git] / installer / ui / Installer.d
blob0b9c47b8ce432f652f8c7d5382b9148dfe5a4ddd
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 module ui.Installer;
21 private import ui.Main;
22 private import ui.Exec;
23 private import gtk.Duit;
24 private import gtk.MainWindow;
25 private import gtk.Widget;
26 private import gtk.ProgressBar;
27 private import gtk.Label;
28 private import gtk.VBox;
30 private import gdk.Gdk;
31 private import gdk.Event;
33 private import compd.Compiler;
35 private import std.stdio;
37 private import std.path;
38 private import std.file;
39 private import std.process;
41 private import std.thread;
42 private import std.c.time;
45 /**
46 * From the informatino collected from the UI this will install Duit, Duitgl and or leds
48 class Installer : MainWindow
50 InstallerUI installerUI;
51 Label label;
52 ProgressBar progressBar;
54 bool cancel = false;
56 this(InstallerUI installerUI)
58 super("Installing Duit components");
59 this.installerUI = installerUI;
60 setDefaultSize(400,300);
61 setup();
62 showAll();
63 install();
64 progressBar.setFraction(1.0);
65 progressBar.setText("");
68 private void setup()
70 VBox vbox = new VBox(false, 7);
71 vbox.setBorderWidth(11);
72 label = new Label("");
73 vbox.packStart(new Label("Installing"), false, false, 14);
74 vbox.packStart(label, false, false, 14);
75 progressBar = new ProgressBar();
76 progressBar.setPulseStep(0.01);
77 vbox.packStart(progressBar, false, false, 14);
78 add(vbox);
81 protected int windowDelete(Event event, Widget widget)
83 cancel = true;
84 mainInstaller.show();
85 return super.windowDelete(event, widget);
88 char[] dmdHome;
89 char[] duitDevHome;
90 char[] phobos;
91 char[] compilerExec;
93 int ccount;
96 private void install()
98 bool ok = true;
99 duitDevHome = installerUI.getDirectory("duitDevHome");
100 dmdHome = installerUI.getDirectory("dmdHome");
101 phobos = std.path.join(std.path.join(dmdHome,"src"),"phobos");
102 compilerExec = std.path.join(installerUI.getDirectory("dmdHome"),"bin");
103 version(Win32)
105 compilerExec = std.path.join(compilerExec,"dmd.exe");
107 else
109 compilerExec = std.path.join(compilerExec,"dmd");
112 // if ( ok && installerUI.getSelection("duit") )
113 // {
114 // label.setText("");
115 // Gdk.flush();
116 // ok = installDuit();
117 // }
121 class CompileThread : Thread
123 bool delegate() compile;
124 bool ok;
126 this(char[] stepLabel, bool delegate() compile)
128 super(&run);
129 this.compile = compile;
130 label.setText(stepLabel);
131 progressBar.setText(stepLabel);
132 go();
133 //ok = compile();
136 private void go()
138 std.gc.fullCollect();
139 start();
140 while ( !cancel && getState() != Thread.TS.TERMINATED )
142 progressBar.pulse();
143 while ( Duit.eventsPending() )
145 Duit.mainIterationDo(false);
147 std.c.time.usleep(30000);
151 int run()
153 ok = compile();
154 return ok;
159 if ( !cancel && ok && installerUI.getSelection("duitDev") )
161 ok = (new CompileThread("Duit Development", &installDuitDev)).ok;
164 // if ( ok && installerUI.getSelection("duitgl") )
165 // {
166 // label.setText("Duitgl - openGL bindings");
167 // Gdk.flush();
168 // ok = installDuitgl();
169 // }
171 if ( !cancel && ok && installerUI.getSelection("duiglDev") )
173 ok = (new CompileThread("Duitgl Development", &installDuitglDev)).ok;
176 // if ( !cancel && ok && installerUI.getSelection("leds") )
177 // {
178 // label.setText("leds");
179 // Gdk.flush();
180 // ok = installLeds();
181 // }
183 // if ( !cancel && ok && installerUI.getSelection("duitdi") )
184 // {
185 // label.setText("Duit .di files");
186 // Gdk.flush();
187 // ok = installDuitdi();
188 // }
190 // if ( !cancel && ok && installerUI.getSelection("duitSource") )
191 // {
192 // label.setText("Duit source files");
193 // Gdk.flush();
194 // ok = installDuitSource();
195 // }
197 if ( !cancel && ok && installerUI.getSelection("duitTests") )
199 ok = (new CompileThread("Duit Test and demos programs", &installDuitTests)).ok;
202 if ( !cancel && ok && installerUI.getSelection("duitglSimple") )
204 ok = (new CompileThread("Duitgl SimpleGL demo program", &installDuitglSimpleGL)).ok;
207 if ( !cancel && ok && installerUI.getSelection("duitglShapes") )
209 ok = (new CompileThread("Duitgl ShapeGL and demo program", &installDuitglShapesGL)).ok;
212 // if ( !cancel && ok && installerUI.getSelection("ledsDuit") )
213 // {
214 // label.setText("Leds project for Duit");
215 // Gdk.flush();
216 // ok = installLedsDuit();
217 // }
219 // if ( !cancel && ok && installerUI.getSelection("ledsLeds") )
220 // {
221 // label.setText("Leds project for leds");
222 // Gdk.flush();
223 // ok = installLedsLeds();
224 // }
226 // if ( !cancel && ok && installerUI.getSelection("ledsDool") )
227 // {
228 // label.setText("Leds project for Dool");
229 // Gdk.flush();
230 // ok = installLedsDool();
231 // }
233 // if ( !cancel && ok && installerUI.getSelection("ledsDante") )
234 // {
235 // label.setText("Leds project for Dante");
236 // Gdk.flush();
237 // ok = installLedsDante();
238 // }
240 // if ( !cancel && ok && installerUI.getSelection("ledsPhobos") )
241 // {
242 // label.setText("Leds project for phobos");
243 // Gdk.flush();
244 // ok = installLedsPhobos();
245 // }
250 private bool makeDirs(char[] dir)
252 bool ok = false;
253 version(Win32)
255 system("md "~dir);
257 else
259 system("mkdir -p "~dir);
263 std.file.isdir(dir);
264 ok = true;
266 catch ( FileException fe )
270 return ok;
273 private bool installDuitglSimpleGL()
275 bool ok = moveDuitDev();
276 if ( ok )
278 char[] cwd = std.file.getcwd();
279 Compiler compiler;
280 std.file.chdir(duitDevHome);
282 compiler = new Compiler();
283 compiler.setExecutor(new Exec());
284 compiler.setCompilerExec(compilerExec);
286 compiler.addArg("-Isrc");
287 compiler.addArg("-Isrcgl");
288 compiler.addArg("-Idemos");
289 compiler.addArg("demos/gl/SimpleGL.d");
290 compiler.addArg("-I"~phobos);
291 compiler.addArg("-L"~std.path.join(dmdHome,"lib"));
292 compiler.addArg("-o SimpleGL");
293 compiler.addArg("-L .");
294 compiler.addArg("-lduit");
295 compiler.addArg("-lduitgl");
296 compiler.addArg("-lGL");
297 compiler.addArg("-lGLU");
298 version(linux)compiler.addArg("-ldl");
300 compiler.addArg("-c");
301 compiler.addArg("-op");
303 version(Win32)
305 compiler.addArg("-lkernel32");
306 compiler.addArg("-luser32");
308 else
310 compiler.addArg("-lpthread");
311 compiler.addArg("-lm");
313 compiler.compile();
314 if ( compiler.compileStatus == 0
315 && compiler.linkStatus == 0
318 ok = true;
320 else
322 ok = false;
325 std.file.chdir(cwd);
327 return ok;
330 private bool installDuitglShapesGL()
332 bool ok = moveDuitDev();
333 if ( ok )
335 char[] cwd = std.file.getcwd();
336 Compiler compiler;
337 std.file.chdir(duitDevHome);
339 compiler = new Compiler();
340 compiler.setExecutor(new Exec());
341 compiler.setCompilerExec(compilerExec);
343 compiler.addArg("-Isrc");
344 compiler.addArg("-Isrcgl");
345 compiler.addArg("demos/gl/TrackBall.d");
346 compiler.addArg("demos/gl/ShapesGL.d");
347 compiler.addArg("-I"~phobos);
348 compiler.addArg("-L"~std.path.join(dmdHome,"lib"));
349 compiler.addArg("-o ShapesGL");
350 compiler.addArg("-L .");
351 compiler.addArg("-lduit");
352 compiler.addArg("-lduitgl");
353 compiler.addArg("-lGL");
354 compiler.addArg("-lGLU");
355 version(linux)compiler.addArg("-ldl");
357 compiler.addArg("-c");
358 compiler.addArg("-op");
360 version(Win32)
362 compiler.addArg("-lkernel32");
363 compiler.addArg("-luser32");
365 else
367 compiler.addArg("-lpthread");
368 compiler.addArg("-lm");
370 compiler.compile();
371 if ( compiler.compileStatus == 0
372 && compiler.linkStatus == 0
375 ok = true;
377 else
379 ok = false;
382 std.file.chdir(cwd);
384 return ok;
387 private bool installDuitglDev()
389 bool ok = true;
391 Compiler compiler;
393 char[] cwd = std.file.getcwd();
397 version(Win32)
399 char[] libDuitgl = "duitgl";
401 else
403 char[] libDuitgl = "libduitgl";
408 ok = moveDuitDev();
409 if ( ok )
411 std.file.chdir(duitDevHome);
412 compiler = new Compiler();
413 compiler.setExecutor(new Exec());
414 compiler.setCompilerExec(compilerExec);
416 compiler.addArg("-Isrc");
417 compiler.addArg("-Isrcgl");
418 compiler.addArg("srcgl/glgdk");
419 compiler.addArg("srcgl/glgtk");
420 compiler.addArg("srcgl/lib");
421 compiler.addArg("-I"~phobos);
422 compiler.addArg("-L"~std.path.join(dmdHome,"lib"));
423 compiler.addArg("-olib "~libDuitgl);
424 compiler.addArg("-L. ");
425 compiler.addArg("-lduit ");
426 compiler.addArg("-c");
427 compiler.addArg("-op");
429 version(Win32)
431 compiler.addArg("-lkernel32");
432 compiler.addArg("-luser32");
434 else
436 compiler.addArg("-lpthread");
437 compiler.addArg("-lm");
439 compiler.compile();
440 if ( compiler.compileStatus == 0
441 && compiler.linkStatus == 0
444 ok = true;
446 else
448 ok = false;
451 std.file.chdir(cwd);
453 return ok;
457 private bool installDuitTests()
459 bool ok = moveDuitDev();
460 if ( ok )
462 char[] cwd = std.file.getcwd();
463 Compiler compiler;
464 std.file.chdir(duitDevHome);
466 compiler = new Compiler();
467 compiler.setExecutor(new Exec());
468 compiler.setCompilerExec(compilerExec);
470 compiler.addArg("-Isrc");
471 compiler.addArg("-Idemos");
472 compiler.addArg("demos/duit");
473 compiler.addArg("-I"~phobos);
474 compiler.addArg("-L"~std.path.join(dmdHome,"lib"));
475 compiler.addArg("-o DuitTests");
476 compiler.addArg("-L .");
477 compiler.addArg("-lduit");
478 version(linux)compiler.addArg("-ldl");
480 compiler.addArg("-c");
481 compiler.addArg("-op");
483 version(Win32)
485 compiler.addArg("-lkernel32");
486 compiler.addArg("-luser32");
488 else
490 compiler.addArg("-lpthread");
491 compiler.addArg("-lm");
493 compiler.compile();
494 if ( compiler.compileStatus == 0
495 && compiler.linkStatus == 0
498 ok = true;
500 else
502 ok = false;
505 std.file.chdir(cwd);
507 return ok;
510 private bool movePackToDestiny(char[] from, char[] to)
512 int ok;
513 version(Win32)
515 ok = system("xcopy /s /Y /E /Q "~from~" "~to);
517 else
519 ok = system("cp -R "~from~" "~to);
521 return ok == 0;
524 bool duitDevMoved;
526 private bool moveDuitDev()
528 if ( !duitDevMoved )
530 if ( makeDirs(duitDevHome) )
532 duitDevMoved = movePackToDestiny("*", duitDevHome);
535 return duitDevMoved;
538 // private bool installDuit()
539 // {
540 // // nothing
541 // return true;
542 // }
544 private bool installDuitDev()
546 bool ok = true;
548 Compiler compiler;
550 char[] cwd = std.file.getcwd();
554 version(Win32)
556 char[] libDuit = "duit";
558 else
560 char[] libDuit = "libduit";
564 ok = moveDuitDev();
565 if ( ok )
567 std.file.chdir(duitDevHome);
568 compiler = new Compiler();
569 compiler.setExecutor(new Exec());
571 compiler.setCompilerExec(compilerExec);
573 compiler.addArg("-Isrc");
574 compiler.addArg("src/atk");
575 compiler.addArg("src/cairoLib");
576 compiler.addArg("src/gdk");
577 compiler.addArg("src/glib");
578 compiler.addArg("src/gobject");
579 compiler.addArg("src/gthread");
580 compiler.addArg("src/gtk");
581 compiler.addArg("src/lib");
582 compiler.addArg("src/pango");
583 compiler.addArg("-I"~phobos);
584 compiler.addArg("-L"~std.path.join(dmdHome,"lib"));
585 compiler.addArg("-olib "~libDuit);
586 compiler.addArg("-c");
587 compiler.addArg("-op");
589 version(Win32)
591 compiler.addArg("-lkernel32");
592 compiler.addArg("-luser32");
594 else
596 compiler.addArg("-lpthread");
597 compiler.addArg("-lm");
599 compiler.compile();
600 if ( compiler.compileStatus == 0
601 && compiler.linkStatus == 0
604 ok = true;
606 else
608 ok = false;
611 std.file.chdir(cwd);
613 return ok;