source: golgotha/src/test/g_install/setup.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 22.9 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9
10#include "window/window.hh"
11#include "app/app.hh"
12#include "main/main.hh"
13#include "window/style.hh"
14#include "file/file.hh"
15#include "loaders/load.hh"
16#include "window/wmanager.hh"
17#include "gui/text_input.hh"
18#include "gui/list_box.cc"
19#include "app/app.hh"
20#include "menu/textitem.hh"
21#include "video/display.hh"
22#include "loaders/load.hh"
23#include "gui/text_input.hh"
24#include "gui/text.hh"
25#include "font/anti_prop.hh"
26#include "window/colorwin.hh"
27#include "gui/button.hh"
28#include "install.hh"
29#include "app/registry.hh"
30#include "file/get_filename.hh"
31#include "gui/text_scroll.hh"
32#include "loaders/wav_load.hh"
33#include "loaders/mp3_load.hh"
34#include "lisp/lisp.hh"
35#include "status/status.hh"
36#include "../../golg/g1_file.hh"
37#include "status/gui_stat.hh"
38
39static i4_window_manager_class *wm;
40static i4_graphical_style_class *style;
41static i4_list_box_class *display_picker, *size_picker;
42static i4_text_scroll_window_class *error_win;
43static char inst_path[200];
44int inst_sizes[3]={20,40,60};
45
46char *reg_key="SOFTWARE\\Crack dot Com\\Golgotha\\1.0";
47char *i4_display_key="SOFTWARE\\Crack dot Com\\I4\\1.0";
48char *sfx_key="SOFTWARE\\Crack dot Com\\i4\\1.0";
49
50i4_file_class *uninstall_script=0;
51
52int installed=0;
53int col2=120;
54int size_needed_to_install=0;
55
56i4_text_input_class *path=0;
57
58
59enum {
60  BROWSE_OK,
61  BROWSE_CANCEL,
62  BROWSE,
63  SAVE_AND_QUIT,
64  SAVE_AND_RUN,
65  INSTALL,
66  QUIT,
67  COMPACT,
68  TYPICAL,
69  UNINSTALL,
70  DISPLAY_SELECT
71};
72
73
74
75void fix_path(char *f)
76{
77  for (;*f; f++)
78#ifdef __linux
79    if (*f=='\\')
80      *f='/';
81#else
82    if (*f=='/')
83      *f='\\';
84#endif
85
86}
87
88
89#ifdef __linux
90int free_space(char *path)
91{
92  reutn 100*1024*1024;
93}
94#else
95
96#include <windows.h>
97// int free_space(char *path)
98// {
99//   DWORD spc, bpc, bps, nfc, tnc;
100//   GetDiskFreeSpace(path, &spc, &bpc, &bps, &nfc, &tnc);
101
102//   return  nfc * tnc * bpc;
103// }
104#endif
105
106
107class setup_options : public i4_color_window_class
108{
109public:
110  setup_options(w16 w, w16 h, i4_graphical_style_class *style)
111    : i4_color_window_class(w,h, style->color_hint->neutral(),style) {}
112
113  void parent_draw(i4_draw_context_class &context)
114  {
115    undrawn_area.add_area(0,0, width()-1, height()-1);
116
117    i4_color_window_class::parent_draw(context);
118
119    i4_font_class *f=style->font_hint->normal_font;
120
121    char p[200];
122    i4_os_string(*(path->get_edit_string()), p, 200);
123
124    char display[200];
125    i4_text_item_class *ti=(i4_text_item_class *)display_picker->get_current_item();
126    i4_os_string(ti->get_text(), display, 200);
127
128    char size[200];
129    ti=(i4_text_item_class *)size_picker->get_current_item();
130    i4_os_string(ti->get_text(), size, 200);
131
132    char str[500];
133    sprintf(str,
134            "Installation Options:\n"
135            "  Display           : %s\n"
136            "  Installation Path : %s\n"
137            "  Install Size      : %s\n\n", display, p, size);
138
139    switch (size_picker->get_current())
140    {
141      case 0 :
142        size_needed_to_install=40*1024*1024;
143        li_set_value("install_size", li_get_symbol("compact"));
144        sprintf(str+strlen(str),
145                "Small Installation does not have music"); break;
146        break;
147
148      case 1 :
149        size_needed_to_install=60*1024*1024;
150        li_set_value("install_size", li_get_symbol("typical"));
151        sprintf(str+strlen(str),
152                "Large Installation has the best of everything"); break;
153        break;
154    }
155
156
157 
158    f->set_color(0);
159    f->put_paragraph(local_image, 6,6, str,
160                     context, 1, i4_font_class::LEFT,  width());
161
162    f->set_color(0xffffff);
163    f->put_paragraph(local_image, 5,5, str,
164                     context, 1, i4_font_class::LEFT,  width());
165  }
166  char *name() { return "options"; }
167};
168
169setup_options *setup_window=0;
170
171
172#ifdef _WINDOWS
173/*
174 * build a shortcut in the start menu
175 */
176void MakeShortcut()
177{
178  char buf[512];
179  char szSetupIni[MAX_PATH];
180  int len;
181  int fh;
182
183  static char setup_ini[] =
184    "[progman.groups]\r\n"
185    "groupX=Programs\r\n"
186    "[groupX]\r\n"
187    "\"Golgotha\",\"golgotha.exe\",,,,\"%s\"\r\n";
188
189  GetWindowsDirectory(szSetupIni, sizeof(szSetupIni));
190  sprintf(szSetupIni+strlen(szSetupIni), "\\SETUP.INI");
191
192 
193  fix_path(buf);
194
195 
196  len = wsprintf(buf, setup_ini, inst_path);
197  fh = _lcreat(szSetupIni, 0);
198
199  if (fh != -1)
200  {
201    _lwrite(fh, buf, len);
202    _lclose(fh);
203    WinExec("grpconv -o", SW_HIDE);
204  }
205}
206#endif
207 
208
209
210void setup_changed()
211{
212  if (setup_window)
213    setup_window->request_redraw(i4_F);
214  error_win->clear();
215}
216
217static i4_bool no_space=i4_F;
218
219
220void write_header(i4_file_class *fp, i4_sound_info &fmt)
221{
222  fp->write("RIFF",4);
223  fp->write_32(36+fmt.size);       // 36 + snd->size
224  fp->write("WAVE", 4);
225  fp->write("fmt ", 4);
226
227  fp->write_32(16);        // size of chunk
228
229  fp->write_16(1);         // data type
230
231  fp->write_16(fmt.channels);           // num channels
232  fp->write_32(fmt.sample_rate);   // sample rate
233  fp->write_32(fmt.sample_rate*
234               fmt.sample_size*fmt.channels);       // snd->sample_rate * snd->sample_size
235  fp->write_16(fmt.sample_size * fmt.channels);
236  fp->write_16(fmt.sample_size*8);
237
238
239  fp->write("data",4);
240  fp->write_32(fmt.size);       // snd->size
241}
242
243
244
245char *forward_slash(char *f)
246{
247  char *r=f;
248  for (;*f; f++)
249    if (*f=='\\')
250      *f='/';
251  return r;
252}
253
254
255
256
257li_object *li_uninstall_cmd(li_object *o, li_environment *env)
258{
259  if (uninstall_script)
260  {
261    li_object *c=li_eval(li_car(o,env),env);
262    li_get_type(c->type())->print(c, uninstall_script);
263    return li_true_sym;
264  }
265  return li_nil;
266}
267
268
269li_object *li_delete(li_object *o, li_environment *env)
270{
271  char p[200];
272  strcpy(p,li_get_string(li_eval(li_car(o,env), env),env));
273  fix_path(p);
274
275
276  if (i4_unlink(p))
277    return li_true_sym;
278  else return li_nil;
279}
280
281li_object *li_mkdir(li_object *o, li_environment *env)
282{
283  char *fn=li_get_string(li_eval(li_car(o,env),env),env);
284  char p[200];
285  sprintf(p, "%s/%s", inst_path, fn);
286  fix_path(p);
287
288  if (i4_mkdir(p))
289  {
290    if (uninstall_script)
291      uninstall_script->printf("(rmdir \"%s\")\n", forward_slash(p));
292   
293    return li_true_sym;
294  }
295  else
296    return 0;
297}
298
299
300li_object *li_rmdir(li_object *o, li_environment *env)
301{
302  char *fn=li_get_string(li_eval(li_car(o,env),env),env);
303  fix_path(fn);
304
305  i4_directory_struct ds;
306
307  if (i4_get_directory(fn, ds))
308  {
309    int i;
310    char f2[256], f[256];
311    for (i=0; i<ds.tfiles; i++)
312    {
313      i4_os_string(*ds.files[i], f, 256);
314      sprintf(f2, "%s/%s", fn, f);
315      fix_path(f2);
316      i4_unlink(f2);
317    }
318
319
320    for (i=0; i<ds.tdirs; i++)
321    {
322      i4_os_string(*ds.dirs[i], f, 256);
323      if (!(strcmp(f, ".")==0 ||  strcmp(f, "..")==0))
324      {
325        sprintf(f2, "%s/%s", fn, f);
326        fix_path(f2);
327        li_rmdir(li_make_list(new li_string(f2),0),0);
328      }
329    }
330  }
331
332  if (i4_rmdir(fn))
333    return li_true_sym;
334  else
335    return 0;
336}
337
338
339void down_sample_wav(char *in_file, char *out_file, int rate)
340{
341  i4_sound_info s;
342  i4_file_class *in=i4_open(in_file);
343  if (!in) return;
344  i4_file_class *out=i4_open(out_file, I4_WRITE);
345  if (!out) { delete in; return ; }
346
347
348  if (i4_load_wav_info(in, s))
349  {   
350    w16 *inm=(w16 *)i4_malloc(s.size,"");
351    in->read(inm, s.size);
352
353    float x_end=s.size/2;
354    float x=0, x_step=s.sample_rate/(float)rate;
355    int out_size=(int)((double)s.size * (double)rate / (double)s.sample_rate), outc=0;
356    int out_samples=out_size/2;
357
358
359    w16 *outm=(w16 *)i4_malloc(out_size,"");
360
361   
362    while (outc<out_samples)
363    {
364      outm[outc]=inm[(int)x];
365      x+=x_step;
366      outc++;
367    }
368   
369
370    s.sample_rate=rate;
371    s.size=out_size;
372    write_header(out, s);
373    out->write(outm, out_size);
374
375    i4_free(outm);
376    i4_free(inm);
377  }
378
379  delete in;
380  delete out;
381}
382
383li_object *mp3_2_wav(li_object *o, li_environment *env)
384{
385  char *fn=li_get_string(li_eval(li_car(o,env),env),env);
386  i4_filename_struct split;
387
388  int resample_rate=-1;
389  if (li_cdr(o,env))
390    resample_rate=li_get_int(li_eval(li_second(o,env),env),env);
391
392
393  i4_split_path(fn, split);
394  char out_name[256], tmp_name[256];
395
396  sprintf(out_name, "%s/%s/%s.wav", inst_path, split.path, split.filename);
397  sprintf(tmp_name, "%s/%s/%s_tmp.wav", inst_path, split.path, split.filename);
398 
399
400  fix_path(out_name);
401  fix_path(tmp_name);
402
403 
404  i4_file_class *out=i4_open(resample_rate==-1 ? out_name : tmp_name, I4_WRITE);
405  if (!out)
406    return 0;
407
408  if (uninstall_script)
409    uninstall_script->printf("(delete \"%s\")\n", forward_slash(out_name));
410
411
412  fix_path(fn);
413  i4_file_class *in=i4_open(fn);
414  if (!in)
415  {
416    delete out;
417    return 0;
418  }
419
420  i4_sound_info fmt;
421  write_header(out, fmt);
422
423  char stat[200];
424  sprintf(stat, "Decoding MP3 : %s", fn);
425  i4_status_class *status=i4_create_status(stat);
426
427  i4_bool ret=i4_load_mp3(in, out, fmt, status);
428  out->seek(0);
429  write_header(out, fmt);
430   
431  delete status;
432  delete in;
433  delete out;
434
435  if (resample_rate)
436  {
437    down_sample_wav(tmp_name, out_name, resample_rate);
438    i4_unlink(tmp_name);
439  }
440
441
442  if (!ret)
443    return 0;
444
445  return li_true_sym;
446}
447
448
449
450
451li_object *copy_file(li_object *o, li_environment *env)
452{
453  char *f1=li_get_string(li_eval(li_first(o,env),env),env);
454  char *f2=li_get_string(li_eval(li_second(o,env),env),env);
455  char full_f2[256];
456  sprintf(full_f2, "%s/%s", inst_path, f2);
457
458  fix_path(full_f2);
459  i4_file_class *out=i4_open(full_f2, I4_WRITE | I4_NO_BUFFER);
460  if (!out)
461  {
462    error_win->printf("Could not open output file %s\n", f2);
463    return 0;
464  }
465
466  if (uninstall_script)
467    uninstall_script->printf("(delete \"%s\")\n", forward_slash(full_f2));
468
469  fix_path(f1);
470  i4_file_class *in=i4_open(f1, I4_NO_BUFFER | I4_READ);
471  if (!in)
472  {
473    error_win->printf("Could not open %s\nAre you running setup from the correct directory?", f1);
474    return 0;
475  }
476
477  char s[200];
478  sprintf(s, "Copying to %s", f2);
479  i4_status_class *status=i4_create_status(s);
480
481
482  char buf[4096];
483  int tot=in->size(),size=0;
484
485  while (size<tot)
486  {
487    status->update((size+2)/(float)(tot+1));
488
489    int t=in->read(buf, sizeof(buf));
490    if (out->write(buf, t)!=t)
491    {
492      error_win->printf("Could write, out of disk space?\n");
493      return 0;
494    }
495
496    size+=t;
497  }
498  delete status;
499
500  delete in;
501  delete out;
502  return li_true_sym;
503}
504
505
506i4_bool install(int install_type)
507{
508  char display[200];
509  i4_text_item_class *ti=(i4_text_item_class *)display_picker->get_current_item();
510  i4_os_string(ti->get_text(), display, 200);
511
512#ifdef _WINDOWS
513    MakeShortcut();
514#endif
515 
516
517  if (!installed)
518  {
519
520    i4_os_string(*(path->get_edit_string()), inst_path, 200);
521
522    i4_file_status_struct r_stat;
523
524    int l=strlen(inst_path);
525
526    while (l && (inst_path[l-1]==' ' ||
527                 inst_path[l-1]=='\\' ||
528                 inst_path[l-1]=='/'))
529    {
530      inst_path[l-1]=0;
531      l--;
532    }
533
534    // try to make the installation path
535    if (!i4_mkdir(inst_path))
536    {
537      if (!i4_get_status(inst_path, r_stat))
538      {
539        error_win->printf("Could not create Directory '%s'\n", inst_path);
540        return i4_F;
541      }
542      else if ((r_stat.flags & I4_FILE_STATUS_DIRECTORY)==0)
543      {
544        error_win->printf("%s is a FILE not a Directory!\n", inst_path);
545        return i4_F;
546      }
547    }
548
549    char uscript[256];
550    sprintf(uscript, "%s/uninstall.scm", inst_path);
551    uninstall_script=i4_open(uscript, I4_WRITE);
552    if (!uninstall_script)
553    {
554      error_win->printf("Could not open %s for writing\n", uscript);
555      return i4_F;
556    }
557
558
559    char cd_dest[200];
560    sprintf(cd_dest,"%s/golgotha.cd",inst_path);
561
562
563    if (copy_file(li_make_list(new li_string("golgotha.cd"),
564                               new li_string("golgotha.cd"),0),0)==0)
565    {
566      delete uninstall_script; uninstall_script=0;
567      return i4_F;
568    }
569
570    g1_set_cd_image(cd_dest);
571
572
573
574    i4_status_class *s=i4_create_status("Decompressing Files");
575    li_load("install.scm", 0, s);
576    delete s;
577
578    delete uninstall_script;
579    uninstall_script=0;
580
581
582  // check for enough free space
583    w32 needed_size=inst_sizes[size_picker->get_current()]*1024*1024;
584 
585 
586//     w32 free_space=i4_disk_free_space(inst_path);
587//     if (free_space<needed_size)
588//     {
589//       error_win->printf("Free space = %dMB, I need %dMB to install!\n"
590//                         "Please Remove some files or select smaller install\n",
591//                         free_space/(1024*1024), needed_size/(1024*1024));
592//       return i4_F;
593//     }   
594  }
595
596
597  char tmp_data[256];
598
599  // don't set sfx path if it's already set
600  if (install_type==INSTALL ||
601      !i4_get_registry(I4_REGISTRY_USER, sfx_key, "G_SFX_PATH", tmp_data, 256))
602  {
603    if (!i4_set_registry(I4_REGISTRY_USER, sfx_key, "G_SFX_PATH", "sfx"))
604      error_win->printf("Could not set Registry item\n");
605  }
606
607  // don't set install path if it's already set
608  if (install_type==INSTALL ||
609      !i4_get_registry(I4_REGISTRY_USER, reg_key, "install_path", tmp_data, 256))
610  {
611    if (!i4_set_registry(I4_REGISTRY_USER, reg_key, "install_path", inst_path))
612      error_win->printf("Could not set Registry item\n");
613  }
614
615  // always set the display they picked
616  if (!i4_set_registry(I4_REGISTRY_MACHINE, i4_display_key, "display", display))
617  {
618    error_win->printf("Could not set Registry item\n");
619    return i4_F;
620  }
621     
622  if (install_type==INSTALL || install_type==SAVE_AND_RUN)
623  {
624    i4_chdir(inst_path);
625    system("golgotha");
626  }
627 
628  return i4_T;
629
630}
631
632class setup_app : public i4_application_class
633{
634public:
635
636 
637
638
639  void add_display_picker(int x, int y, i4_parent_window_class *p)
640  {
641    i4_text_window_class *ti=new i4_text_window_class("Rendering Method", style);
642    p->add_child(x,y, ti);
643
644
645    x+=col2;
646
647    i4_list_box_class *lbox=new i4_list_box_class(250, style, wm);
648
649    char old_name[256];
650    if (!i4_get_registry(I4_REGISTRY_MACHINE, i4_display_key, "display", old_name, 256))
651      old_name[0]=0;
652
653    int i=0, use=0;
654    for (i4_display_list_struct *f=i4_display_list; f; f=f->next)
655    {
656     
657      if (strcmp(f->name, "Windowed GDI") &&  // these displays don't work with render/
658          strcmp(f->name, "X Windows"))
659      {
660        if (strcmp(f->name, old_name)==0)
661          use=i;
662
663        i4_str *s=new i4_str(f->name);
664        lbox->add_item(new i4_text_item_class(*s, style, 0,0,
665                                              new i4_event_reaction_class(this,DISPLAY_SELECT + i)));     
666        i++;
667      }       
668    }
669
670    if (i==0)
671      i4_error("Golgotha requires DirectX5, or a 3dfx card\n"
672               "Make sure you have DX5 (and are in 16bit color mode)"
673               "Or that you have the current version Glide (for 3dfx) installed");
674
675    lbox->set_current_item(use);
676    display_picker=lbox;
677
678
679    p->add_child(x,y, lbox);
680  }
681
682 
683  void add_install_path(int x, int y, i4_parent_window_class *p)
684  {
685    p->add_child(x,y, new i4_text_window_class("Install Path", style));
686    x+=col2;
687
688    path=new i4_text_input_class(style, "c:\\golg", 200, 256, this);
689    p->add_child(x,y,path);
690
691    x+=path->width();
692   
693//     i4_button_class *but;
694//     but=new i4_button_class(0, new i4_text_window_class("Browse", style), style,
695//                                           new i4_event_reaction_class(this, BROWSE));
696//     but->set_popup(i4_T);
697//     p->add_child(x,y, but);
698                                         
699
700  }
701
702
703  void add_texture_size_picker(int x, int y, i4_parent_window_class *p)
704  {
705    i4_text_window_class *ti=new i4_text_window_class("Install size", style);
706    p->add_child(x,y, ti);
707    x+=col2;
708
709    i4_list_box_class *lbox=new i4_list_box_class(250, style, wm);
710    lbox->add_item(new i4_text_item_class("75MB (Compact)", style, 0,0,
711                                          new i4_event_reaction_class(this, COMPACT)));
712
713
714    lbox->add_item(new i4_text_item_class("100MB (Typical)", style, 0,0,
715                                          new i4_event_reaction_class(this, TYPICAL)));
716
717    size_needed_to_install=60*1024*1024;
718    lbox->set_current_item(1);
719    p->add_child(x,y, lbox);
720    size_picker=lbox;
721   
722
723  }
724
725  void add_buttons(int x, int y, i4_parent_window_class *p)
726  {
727    i4_button_class *b;
728    if (installed)
729    {
730      b=new i4_button_class(0, new i4_text_window_class("Save & Quit", style), style,
731                            new i4_event_reaction_class(this, SAVE_AND_QUIT));
732      b->set_popup(i4_T);
733      p->add_child(x,y,b);
734      x+=b->width();
735
736      b=new i4_button_class(0, new i4_text_window_class("Save & Run", style), style,
737                            new i4_event_reaction_class(this, SAVE_AND_RUN));
738    }
739    else
740      b=new i4_button_class(0, new i4_text_window_class("Install & Run", style), style,
741                            new i4_event_reaction_class(this, INSTALL));
742    b->set_popup(i4_T);
743    p->add_child(x,y,b);
744
745
746    x+=b->width();
747    b=new i4_button_class(0, new i4_text_window_class("      Exit     ", style), style,
748                          new i4_event_reaction_class(this, QUIT));
749    p->add_child(x,y,b);
750    x+=b->width();
751
752
753    if (installed)
754    {
755      b=new i4_button_class(0, new i4_text_window_class("    Uninstall    ", style), style,
756                            new i4_event_reaction_class(this, UNINSTALL));
757      p->add_child(x,y,b);
758    }
759
760
761  }
762
763  i4_bool check_installed()
764  {
765    for (int i=1; i<i4_global_argc; i++)
766      if (i4_global_argv[i]=="-installed")
767      {
768        installed=1;
769        strcpy(inst_path, "c:/golg");
770        return i4_T;
771      }
772
773    if (i4_get_registry(I4_REGISTRY_USER, reg_key, "install_path", inst_path, 256))
774    {
775      i4_file_status_struct s;
776      char f1[256];
777      sprintf(f1,"%s/golgotha.exe",inst_path);
778
779
780      if (!i4_get_status(f1, s))
781        return i4_F;
782
783
784      sprintf(f1,"%s/golgotha.cd",inst_path);
785      if (!i4_get_status(f1, s))
786        return i4_F;
787
788      installed=1;
789      return i4_T;
790    }
791
792    return i4_F;
793  }
794
795  void init()
796  {   
797    g1_set_cd_image(0);
798
799    i4_application_class::init();
800    style=get_style();
801    wm=get_window_manager();
802
803    i4_init_gui_status(wm, display);
804
805    li_add_function("mp3_2_wav", mp3_2_wav);
806    li_add_function("mkdir", li_mkdir);
807    li_add_function("rmdir", li_rmdir);
808    li_add_function("delete", li_delete);
809    li_add_function("copy_file", copy_file);
810    li_add_function("uninstall", li_uninstall_cmd);
811   
812    style->font_hint->normal_font=new i4_anti_proportional_font_class(i4_load_image("setup_font.tga"));
813    style->icon_hint->background_bitmap=i4_load_image("setup.jpg");
814
815    style->color_hint->text_foreground=0xffffff;
816    style->color_hint->text_background=0;
817
818    i4_image_window_class *im=new i4_image_window_class(style->icon_hint->background_bitmap,
819                                                        i4_T, i4_F);
820
821
822    wm->add_child(0,0, im);
823
824    i4_deco_window_class *deco=new i4_deco_window_class(400, 100, i4_F, style);
825    int x=120, y=110;
826
827    im->add_child(x, y, deco);
828    y+=deco->height()+20;
829
830    i4_graphical_style_class *style=wm->get_style();
831
832
833    add_display_picker(10,10, deco);
834
835    if (!check_installed())
836    {
837      add_install_path(10, 40, deco);
838
839      add_texture_size_picker(10,70, deco);
840   
841      setup_window=new setup_options(380, 80, style);
842      deco=new i4_deco_window_class(400, 100, i4_F, style);
843      deco->add_child(deco->get_x1(), deco->get_y1(), setup_window);
844      wm->add_child(x,y, deco);
845      y+=deco->height()+5;
846    }
847
848    error_win=new i4_text_scroll_window_class(style, 0xff0000, style->color_hint->neutral(),
849                                              400, 30);
850    wm->add_child(x, y, error_win);
851    y+=error_win->height()+10;
852
853    add_buttons(x, y, wm);
854
855  }
856
857  void receive_event(i4_event *ev)
858  {
859    if (ev->type()==i4_event::OBJECT_MESSAGE)
860      setup_changed();
861    else if (ev->type()==i4_event::USER_MESSAGE)
862    {
863
864      CAST_PTR(uev, i4_user_message_event_class, ev);
865      switch (uev->sub_type)
866      {
867        case QUIT :
868          quit();
869          break;
870         
871        case UNINSTALL :
872        {
873          char uscript[256];
874          sprintf(uscript, "%s/uninstall.scm", inst_path);
875          i4_status_class *stat=i4_create_status("Uninstalling");
876          li_load(uscript,0,stat);
877          delete stat;
878          quit();
879        } break;
880
881//         case CHECK_SPACE_BEFORE_INSTALL :
882//         {
883//           if (i4_disk_free_space(inst_path)<size_needed_to_install)
884//           {
885//             i4_deco_window_class *deco=new i4_deco_window_class(200, 50, i4_T, style);
886//             i4_text_window_class *t=new i4_text_window_class("");
887
888//           deco->add_child(
889
890        //        } break;
891
892        case SAVE_AND_QUIT :
893        case SAVE_AND_RUN :
894        case INSTALL :
895        {
896          i4_image_class *im=i4_load_image("thanks.jpg");
897          i4_image_window_class *iwin=new i4_image_window_class(im, i4_T, i4_F);
898          wm->add_child(0,0,iwin);
899         
900          if (install(uev->sub_type))
901            quit();
902
903
904          delete iwin;
905
906
907        } break;
908
909        case BROWSE :
910        {
911           
912          char p[200];
913          i4_os_string(*(path->get_edit_string()), p, 200);
914
915          i4_create_file_save_dialog(style,
916                                     p,
917                                     "Installation Path",
918                                     p,
919                                     "*",
920                                     "Directory",
921                                     this, BROWSE_OK,
922                                     BROWSE_CANCEL);
923
924
925
926        } break;
927
928        case BROWSE_OK :
929        {
930          CAST_PTR(fev, i4_file_open_message_class, ev);
931          path->change_text(*fev->filename);
932
933          setup_changed();
934        } break;
935
936        default:
937          setup_changed();
938          break;
939
940      }
941    }
942    else i4_application_class::receive_event(ev);
943  }
944
945 
946  i4_bool get_display_name(char *name, int max_len)
947  {
948    strcpy(name, "Windowed GDI");
949    return i4_T;
950  }
951
952  char *name() { return "test_app"; }
953};
954
955void i4_main(w32 argc, i4_const_str *argv)
956{
957  setup_app test;
958  test.run();
959}
960
961
962
963
964
Note: See TracBrowser for help on using the repository browser.