home *** CD-ROM | disk | FTP | other *** search
- #include "wimp.h"
- #include "wimpt.h"
- #include "win.h"
- #include "event.h"
- #include "baricon.h"
- #include "res.h"
- #include "resspr.h"
- #include "menu.h"
- #include "template.h"
- #include "dbox.h"
- #include "werr.h"
- #include "xferrecv.h"
- #include "kernel.h"
- #include "alarm.h"
- #include "interface.h"
- #define menu_info 1
- #define menu_status 2
- #define menu_over 3
- #define menu_auto 4
- #define menu_time 5
- #define menu_start_at 6
- #define menu_quit 7
-
- #define info_field 4
- #define author_field 3
- #define file_field 4
- #define backup_number_field 3
- #define overwrite_field 1
- #define time_field 2
- /**********wimp************/
- static BOOL initialise(void);
- static BOOL window_open = FALSE;
- static BOOL status_window = FALSE;
- static BOOL overwrite = FALSE;
- static BOOL autobackup = FALSE;
- static dbox info_dialogue;
- static dbox time_dialogue;
- static dbox main_dialogue;
- static dbox start_dialogue;
- static char *Version_String = "1.01 31th Oct '91";
- static char *Author = "Briag";
- char Time[] = "Off";
- char Overwrite[] = "Off";
- char backup_number[4];
- int timer = 5;
- static menu top_menu;
- static void iconclick(wimp_i icon);
- static void program_info(void);
- static void program_status(void);
- static void program_time(void);
- static void program_start_at(void);
- static void menuproc(void *handle, char *hit);
- static void event_handler(wimp_eventstr *e, void *handle);
- static void event_handler2(wimp_eventstr *e, void *handle);
- static void redraw_window(wimp_w handle);
- static void alarm_proc(int at,void *handle);
- static void status_handler(wimp_mousestr);
- void workarea_button (wimp_mousestr);
- /****************************/
-
- BOOL dialogue_raw_event (dialogue_box, action, handle)
-
- dbox dialogue_box;
- wimp_eventstr *action;
- void *handle;
-
- {
-
- switch (action->e)
- {
- case wimp_EREDRAW:
- redraw_window (action->data.o.w);
- break;
-
- case wimp_EOPEN:
- wimpt_noerr (wimp_open_wind (&action->data.o));
- break;
-
- case wimp_ECLOSE:
- dbox_dispose (&dialogue_box);
- break;
-
- case wimp_EBUT:
- if (action->data.but.m.bbits != 2){
- workarea_button (action->data.but.m);
- }
- if(status_window){
- status_handler(action->data.but.m);
- }
- break;
-
- }
- return TRUE;
- }
-
-
- static BOOL initialise(void)
- {
- FILE *fp;
- int result,i;
- char file[62],*ptr = file_name;
-
- _kernel_osfile_block inouts,*inout;
- inout = &inouts;
- wimpt_init("Progy Backeruperer"); /* Main Wimp initialisation */
- res_init("Backup"); /* Resources */
- resspr_init(); /* Application sprites */
- template_init(); /* Templates */
- dbox_init(); /* Dialogue boxes */
- alarm_init();
-
- if (top_menu = menu_new("backup", ">Info,Status,Overwrite,Auto backup,>Every,>Start at,Quit"),top_menu == NULL)
- return FALSE;
-
- baricon("!backup", (int)resspr_area(), iconclick);
-
- win_register_event_handler(win_ICONBAR,event_handler2,0);
- win_register_event_handler(win_ICONBARLOAD,event_handler,0);
- if(!event_attachmenu(win_ICONBAR, top_menu, menuproc, 0)){
- return FALSE;
- }
-
-
- /***backup init***/
- if((fp = fopen(current,"r")) == NULL){
- strcpy(backup_number,"0");
- fclose(fp);
- }
- else{
- fscanf(fp,"%s",backup_number);
- fclose(fp);
- }
-
- /*** read in full path name***/
- if((fp = fopen(file_path,"r")) == NULL){
- fclose(fp);
- strcpy(file_name,"None as yet");
- }
- else{
- fscanf(fp,"%s",file_name);
- fclose(fp);
- if((i = strlen(file_name)) > 59){
- i -= 59;
- for(;i > 0;i--,ptr++)
- ;
- strcpy(file,ptr);
- strcpy(short_file_name,file);
- }
- else{
- strcpy(short_file_name,file_name);
- }
- }
- inout->load=0xffd,inout->exec=0,inout->start=0,inout->end=0;
- result = _kernel_osfile(18,file_path,inout);
- inout->load=0xffd,inout->exec=0,inout->start=0,inout->end=0;
- result = _kernel_osfile(18,current,inout);
-
- return TRUE;
- }
-
- static void event_handler(wimp_eventstr *e, void *handle)
- {
- int filetype,result;
- char *filename;
- _kernel_osfile_block *inout,inouts;
- handle = handle;
- inout = &inouts;
- switch (e->e)
- {
- case wimp_EREDRAW:
- redraw_window(e->data.o.w);
- break;
-
- case wimp_ESEND:
- case wimp_ESENDWANTACK:
- {
- switch (e->data.msg.hdr.action)
- {
- case wimp_MDATALOAD: /* insert data */
- case wimp_MDATAOPEN:
- filetype = xferrecv_checkinsert(&filename);
- if (strlen(filename) > LINESIZE)
- {
- werr(0, "File path name is too long");
- }
- else{
- inout->load=0,inout->exec=0,inout->start=0,inout->end=0;
- result = _kernel_osfile(13,filename,inout);
- if(result == 0){
- werr(0,"file not found");
- }
- else if(result == 1){
- strcpy(file_name, filename);
- filelength = inout->start;
- file_attrib = inout->end;
- changepath();
- }
- else if(result == 2){
- werr(0,"sorry can't backup directories");
- }
- else{
- werr(0,"errr, u shouldn't get this msg");
- }
- }
- break;
- default: break;
- }
- }
- xferrecv_insertfileok();
- break;
-
- case wimp_ECLOSE:
- wimpt_noerr(wimp_close_wind(e->data.o.w));
- window_open = FALSE;
- break;
-
- default:
- break;
- }
- }
-
-
- static void event_handler2(wimp_eventstr *e, void *handle)
- {
- wimp_i iconbar;
- handle = handle;
-
-
- switch (e->e)
- {
- case wimp_EREDRAW:
- redraw_window(e->data.o.w);
- break;
-
- case wimp_EBUT:
- if(e->data.but.m.bbits != 4 && e->data.but.m.bbits != 2){
- program_status();
- }
- else if(e->data.but.m.bbits == 4)
- iconclick(iconbar);
- break;
-
- case wimp_ECLOSE:
- wimpt_noerr(wimp_close_wind(e->data.o.w));
- window_open = FALSE;
- break;
-
- default:
- break;
- }
- }
-
- static void menuproc(void *handle, char *hit)
- {
- int time_now,alarm_at;
- handle = handle;
-
- switch (hit[0]){
-
- case menu_info:
- program_info();
- break;
-
- case menu_status:
- program_status();
- break;
-
- case menu_auto:
- if(autobackup){
- autobackup = FALSE;
- alarm_init();
- strcpy(Time,"Off");
- menu_setflags(top_menu,menu_auto,0,0);
- }
- else{
- autobackup = TRUE;
- time_now = alarm_timenow();
- alarm_at = ((timer*100*60)+time_now);
- alarm_set(alarm_at,alarm_proc,0);
- strcpy(Time,"On");
- menu_setflags(top_menu,menu_auto,1,0);
- }
- break;
-
- case menu_time:
- program_time();
- break;
-
- case menu_start_at:
- program_start_at();
- break;
-
- case menu_over:
- if(overwrite){
- strcpy(Overwrite,"Off");
- overwrite = FALSE;
- menu_setflags(top_menu,menu_over,0,0);
- }
- else{
- strcpy(Overwrite,"On");
- overwrite = TRUE;
- menu_setflags(top_menu,menu_over,1,0);
- }
- break;
-
- case menu_quit:
- exit(0);
-
- default:
- break;
- }
- }
-
- static void iconclick(wimp_i icon)
- {
- icon = icon;
- backup();
- return;
- }
-
- static void program_info(void)
- {
- if (info_dialogue = dbox_new("ProgInfo"),info_dialogue != NULL){
- dbox_raw_eventhandler (info_dialogue, (dbox_raw_handler_proc)
- dialogue_raw_event, 0);
-
- dbox_setfield(info_dialogue, info_field, Version_String);
- dbox_setfield(info_dialogue, author_field,Author);
- dbox_show(info_dialogue);
- dbox_fillin(info_dialogue);
- dbox_dispose(&info_dialogue);
- }
- }
-
- static void program_status(void)
- {
- int i;
-
- if (main_dialogue = dbox_new("MainWindow"), main_dialogue != NULL){
- status_window = TRUE;
- /*wimp_set_icon_state(main_dialogue,file_field,0,0);*/
- dbox_raw_eventhandler (main_dialogue, (dbox_raw_handler_proc) dialogue_raw_event, 0);
- dbox_setfield(main_dialogue, file_field, short_file_name);
- i = atoi(backup_number),i++;
- dbox_setnumeric(main_dialogue, backup_number_field, i);
- if(strcmp("On",Overwrite) == 0){
- dbox_setnumeric(main_dialogue, overwrite_field, 1);
- }
- if(strcmp("On",Time) == 0){
- dbox_setnumeric(main_dialogue,time_field, 1);
- }
- dbox_setfield(main_dialogue, overwrite_field, Overwrite);
- dbox_setfield(main_dialogue, time_field, Time);
- dbox_show(main_dialogue);
- dbox_fillin(main_dialogue);
- dbox_dispose(&main_dialogue);
- status_window = FALSE;
- }
- }
-
- static void program_time(void)
- {
-
- if (time_dialogue = dbox_new("Time"), time_dialogue != NULL){
-
- dbox_setnumeric(time_dialogue, 0, timer);
- dbox_show(time_dialogue);
- dbox_fillin(time_dialogue);
- timer = dbox_getnumeric(time_dialogue,0);
- dbox_dispose(&time_dialogue);
- }
- }
-
- static void program_start_at(void)
- {
- int i,b;
- FILE *fp;
-
- if (start_dialogue = dbox_new("Every"), start_dialogue != NULL){
-
- b = atoi(backup_number);
- dbox_setnumeric(start_dialogue, 0,b+1);
- dbox_show(start_dialogue);
- dbox_fillin(start_dialogue);
- i = dbox_getnumeric(start_dialogue,0);
- dbox_dispose(&start_dialogue);
- if((i-1) != b){
- i--;
- strcpy(backup_number,itoa(i));
-
- if((fp = fopen(current,"w")) != NULL){
- fprintf(fp,"%s",backup_number);
- fclose(fp);
- }
- else{
- werr(0,"couldn't open data file \"%s\"",current);
- }
- }
- }
- return;
- }
-
-
- void redraw_window (handle)
-
- wimp_w handle;
-
- {
- BOOL redraw;
- wimp_redrawstr redraw_box;
-
- redraw_box.w = handle;
- wimpt_noerr (wimp_redraw_wind (&redraw_box, &redraw));
-
- while (redraw)
- {
- wimpt_complain (wimp_borderwindow (redraw_box));
- wimp_get_rectangle (&redraw_box, &redraw);
- }
- }
-
-
-
- void alarm_proc(int called_at,void *handler){
- int time_now,alarm_at,i;
- called_at=called_at;
- if(autobackup){
- time_now = alarm_timenow();
- alarm_at = ((timer*100*60)+time_now);
- alarm_set(alarm_at,alarm_proc,(void *)0);
- }
- backup();
- if(status_window){
- i = atoi(backup_number),i++;
- dbox_setnumeric(main_dialogue, backup_number_field, i);
- }
- return;
- }
-
- void status_handler (wimp_mousestr mouse){
- int time_now;
- int alarm_at,i;
- FILE *fp;
-
- switch (mouse.i)
- {
- case 1:
- if(mouse.bbits == 4 || mouse.bbits == 1){
- if(overwrite){
- strcpy(Overwrite,"Off");
- overwrite = FALSE;
- menu_setflags(top_menu,menu_over,0,0);
- }
- else{
- strcpy(Overwrite,"On");
- overwrite = TRUE;
- menu_setflags(top_menu,menu_over,1,0);
- dbox_setfield(main_dialogue, overwrite_field, " ");
- dbox_setfield(main_dialogue, overwrite_field, Overwrite);
- }
- dbox_setfield(main_dialogue, overwrite_field, Overwrite);
- mouse.bbits = 0;
- workarea_button (mouse);
- }
- break;
-
- case 2:
- if(mouse.bbits == 4 || mouse.bbits == 1){
- if(autobackup){
- autobackup = FALSE;
- alarm_init();
- strcpy(Time,"Off");
- menu_setflags(top_menu,menu_auto,0,0);
- }
- else{
- autobackup = TRUE;
- time_now = alarm_timenow();
- alarm_at = ((timer*100*60)+time_now);
- alarm_set(alarm_at,alarm_proc,0);
- strcpy(Time,"On");
- menu_setflags(top_menu,menu_auto,1,0);
- }
- dbox_setfield(main_dialogue, time_field, " ");
- dbox_setfield(main_dialogue, time_field, Time);
- mouse.bbits = 0;
- workarea_button (mouse);
- }
- break;
-
- case 3:
- if(mouse.bbits == 4){
- i = atoi(backup_number);
- i++;
- strcpy(backup_number,itoa(i));
- dbox_setnumeric(main_dialogue,3,i+1);
- mouse.bbits = 0;
- workarea_button (mouse);
- }
- else if(mouse.bbits == 1){
- i = atoi(backup_number);
- i--;
- strcpy(backup_number,itoa(i));
- dbox_setnumeric(main_dialogue,3,i+1);
- mouse.bbits = 0;
- workarea_button (mouse);
- }
- else if(mouse.bbits == 2){
- break;
- }
- if((fp = fopen(current,"w")) != NULL){
- fprintf(fp,"%s",backup_number);
- fclose(fp);
- }
- else{
- werr(0,"couldn't open data file");
- }
- break;
-
- case 4:
- if(mouse.bbits == 4 || mouse.bbits == 1){
- backup();
- i = atoi(backup_number);
- dbox_setnumeric(main_dialogue,3,i+1);
- mouse.bbits = 0;
- workarea_button (mouse);
- }
- break;
-
- default:
- break;
- }
-
- }
-
- void workarea_button (wimp_mousestr mouse){
- if (mouse.bbits < 5)
- wimpt_complain (wimp_bordericon (mouse));
- }
-