2 /*------------------------------------
3 /* SOURCE FILE NAME: RTDO.C
4 /*------------------------------------
10 #include "restpars.h" /*;AN000;4*/
14 #include "dos.h" /*;AN000;2*/
15 #include "comsub.h" /* common subroutine def'n */
20 unsigned control_file_pointer;
21 unsigned src_file_handle;
22 struct FileFindBuf filefindbuf;
23 struct FileFindBuf dfilefindbuf;
24 BYTE far *control_buf_pointer;
25 unsigned int control_bufsize; /* !wrw */
27 extern unsigned char srcddir[MAXPATH+3];
28 extern unsigned char rtswitch;
29 extern unsigned char control_flag;
30 extern unsigned char control_flag2;
31 extern unsigned control_file_handle; /* !wrw */
32 extern struct subst_list sublist; /*;AN000;6 Message substitution list */
34 /***************** START OF SPECIFICATION ********************************
36 /* SUBROUTINE NAME : Dorestore
38 /* DESCRIPTIVE NAME : Searching all disks and restore the matching files.
40 /* FUNCTION: This routine does the following:
41 /* 1. Initialize the buffer
42 /* 2. Change directory to the one which will hold the first
43 /* files to be restored.
44 /* 3. If the source drive is removable
45 /* Ouput the message to the screen for user to insert a
46 /* diskette and hit a key when ready.
47 /* 4. If the target drive is removable
48 /* Ouput the message to the screen for user to insert a
49 /* diskette and hit a key when ready.
50 /* 5. Check whether the diskette contains old or new data
52 /* 6. ouput "file were backup xx-xx-xx"
54 /* For each diskette, do the following:
55 /* 5. Call check_bkdisk_old or check_bkdisk_new to check whethe
56 /* it is a backup diskette and whether it is in correct
58 /* 6. Call search_src_disk_old or search_src_disk_new to search
59 /* the entire diskette to find matching files and
63 /********************** END OF SPECIFICATIONS *******************************/
64 void dorestore(srcd,destd,inpath,infname,infext,infspec,dt) /* wrw! */
73 BYTE string[MAXPATH+2];
74 struct disk_header_old dheadold;
75 struct disk_header_new dheadnew;
76 struct file_header_new fheadnew;
77 struct disk_info dinfo;
78 struct file_info finfo;
79 unsigned int control_bufsize;
80 unsigned dirlen = MAXPATH;
86 BYTE done; /*;AN000;p????*/
87 BYTE path_to_be_chdir[MAXPATH];
89 BYTE temp_srcddir[MAXPATH];
90 unsigned int dnumwant = 1;
92 BYTE temp_array1[4]; /*temparary array to build parameters for substitution list */
95 /*declaration for dosfindfirst */
96 unsigned dirhandle = 1;
97 unsigned attribute = NOTV;
98 unsigned search_cnt = 1; /* # of entries to find */
99 unsigned buf_len = sizeof(struct FileFindBuf);
100 BYTE search_string[MAXPATHF+2];
102 /*end decleration for ffirst and fnext*/
104 union REGS qregs; /*;AN000;8*/
105 DWORD date; /*;AN000;6*/
107 /****************************************************************/
108 /* change dest drive directory to the one which will hold the */
109 /* first file to be restored */
110 /****************************************************************/
114 strcat(string,inpath);
115 /*if chdir sucessful, save the directory in finfo->curdir*/
116 /*if fail, the path is not exist, and needs to be rebuild*/
118 strcpy(finfo.curdir,inpath);
120 /*****************************************************************/
121 /*if the source disk is hard disk get the current dir of the srcd*/
122 /* chdir the source disk to be in \backup directory */
123 /*****************************************************************/
124 /**************************************/
125 /* if the source disk is a hard disk */
126 /**************************************/
127 /* save current directory of source disk to be reset back later */
128 /* convert character srcd into integer form */
129 /**************************************/
131 srcd_num = (WORD)(srcd - 'A' +1);
133 /**************************************/
134 /* get current directory of srcd (DosQCurDir) */
135 /**************************************/
136 if ((retcode = DOSQCURDIR(srcd_num,(char far *) srcddir,(unsigned far *)&dirlen)) != 0)
138 display_it(INVALID_DRIVE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
139 usererror(INVALIDDRIVE);
142 temp_srcddir[0] = srcd;
143 temp_srcddir[1] = ':';
144 temp_srcddir[2] = NULLC;
145 if (strlen(srcddir) != 1)
146 strcat(temp_srcddir,"\\");
147 strcat(temp_srcddir,srcddir);
148 strcpy(srcddir,temp_srcddir);
150 path_to_be_chdir[0] = srcd;
151 path_to_be_chdir[1] = ':';
152 path_to_be_chdir[2] = NULLC;
153 if (set_reset_test_flag(&control_flag2,SRC_HDISK,TEST) == TRUE)
154 strcat(path_to_be_chdir,"\\BACKUP");
156 strcat(path_to_be_chdir,"\\");
158 if(chdir(path_to_be_chdir)!=0)
159 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
160 usererror(NOBACKUPFILE);
163 /*****************************************************************/
164 /* Identify whether the inserted diskette is a old format backup */
165 /* diskette or a new format backup diskette */
166 /* BACKUP.@@@ or BACKUP.xxx with xxx numeric characters has */
167 /* to be on the diskette */
168 /*****************************************************************/
169 search_string[0] = srcd;
170 search_string[1] = ':';
171 search_string[2] = NULLC;
172 strcat(search_string, "BACKUP*.???");
174 /***********************/
175 /* Find the first file */
176 /***********************/
177 done = FFALSE; /*;AN000;p????*/
179 retcode = /*;AN000;p????*/
180 DOSFINDFIRST /*;AN000;p????*/
182 (char far *)search_string, /*;AN000;p????*/
183 (unsigned far *)&dirhandle, /*;AN000;p????*/
184 attribute, /*;AN000;p????*/
185 (struct FileFindBuf far *)&filefindbuf, /*;AN000;p????*/
186 buf_len, /*;AN000;p????*/
187 (unsigned far *)&search_cnt, /*;AN000;p????*/
188 (DWORD) 0 /*;AN000;p????*/
191 if (retcode != NOERROR) /*;AN000;p????*/
192 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;p????*/
193 usererror(NOBACKUPFILE); /*;AN000;p????*/
196 /*****************************/
197 /* Skip over subdirectories */
198 while((retcode = filefindbuf.attributes & SUBDIR) == SUBDIR) /*;AN000;p????*/
200 search_cnt = 1; /*;AN000;p????*/
202 retcode = /*;AN000;p????*/
203 DOSFINDNEXT /*;AN000;p????*/
204 ( dirhandle, /*;AN000;p????*/
205 (struct FileFindBuf far *)&filefindbuf, /*;AN000;p????*/
206 buf_len, /*;AN000;p????*/
207 (unsigned far *)&search_cnt /*;AN000;p????*/
210 if (retcode != NOERROR) /*;AN000;p????*/
211 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;p????*/
212 usererror(NOBACKUPFILE); /*;AN000;p????*/
216 /****************************************/
217 /* Loop through looking at file names */
218 /****************************************/
220 { /* Is it old BACKUP ??? */ /*;AN000;p????*/
221 if (strcmp(filefindbuf.file_name,BACKUPID)==0) /*;AN000;p????*/
223 set_reset_test_flag(&control_flag,OLDNEW,SET); /*;AN000;p????*/
224 done = TTRUE; /*;AN000;p????*/
226 else /*;AN000;p????*/
227 { /* Is it new BACKUP ??? */ /*;AN000;p????*/
228 if ((filefindbuf.file_name[6] == '.') && /*;AN000;p????*/
229 (filefindbuf.file_name[7] >= '0') && /*;AN000;p????*/
230 (filefindbuf.file_name[7] <= '9') && /*;AN000;p????*/
231 (filefindbuf.file_name[8] >= '0') && /*;AN000;p????*/
232 (filefindbuf.file_name[8] <= '9') && /*;AN000;p????*/
233 (filefindbuf.file_name[9] >= '0') && /*;AN000;p????*/
234 (filefindbuf.file_name[9] <= '9') && /*;AN000;p????*/
235 (filefindbuf.file_name[10] == NULLC) ) /*;AN000;p????*/
237 set_reset_test_flag(&control_flag,OLDNEW,RESET); /*;AN000;p????*/
238 init_control_buf((unsigned long)0,&control_bufsize);/*;AN000;p????*/
239 done = TTRUE; /*;AN000;p????*/
246 search_cnt = 1; /*;AN000;p????*/
247 retcode = /*;AN000;p????*/
248 DOSFINDNEXT /*;AN000;p????*/
249 ( dirhandle, /*;AN000;p????*/
250 (struct FileFindBuf far *)&filefindbuf, /*;AN000;p????*/
251 buf_len, /*;AN000;p????*/
252 (unsigned far *)&search_cnt /*;AN000;p????*/
255 if (retcode != NOERROR) /*;AN000;p????*/
256 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;p????*/
257 usererror(NOBACKUPFILE); /*;AN000;p????*/
260 } /* end while */ /*;AN000;p????*/
261 while(filefindbuf.attributes & SUBDIR == SUBDIR);
263 } /* end DO loop */ /*;AN000;p????*/
264 while (!done); /*;AN000;p????*/
267 retcode = DOSFINDCLOSE(dirhandle);
269 /***************************************/
270 /* Display the date of the backup disk */
271 /***************************************/
272 dyear = (filefindbuf.write_date >> YRSHIFT & YRMASK) + LOYR;
273 dmonth = filefindbuf.write_date >> MOSHIFT & MOMASK;
274 dday = filefindbuf.write_date & DYMASK;
275 date = dyear + (dday*16777216) + (dmonth*65536); /*;AN000;6*/
277 sublist.value1 = (char far *)date; /*;AN000;6*/
278 sublist.flags1 = LEFT_ALIGN + DATE_MDY_4; /*;AN000;6*/
279 sublist.max_width1 = (BYTE)10; /*;AN000;6*/
280 sublist.min_width1 = sublist.max_width1; /*;AN000;6*/
281 display_it(FILES_WERE_BACKUP_ON,STND_OUT_DEV,1,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
283 /*****************************************************************/
284 /*start a loop to check and restore each diskette */
285 /*****************************************************************/
286 initbuf(&bufsize); /* !wrw */
291 /*****************************************************************/
292 /* check whether the inserted diskette is a backup diskette */
293 /*****************************************************************/
294 /*if old, check_bkdisk_old else check_bkdisk_new*/
296 if (set_reset_test_flag(&control_flag,OLDNEW,TEST) == TRUE)
297 check_bkdisk_old(&dheadold, &dinfo, srcd, &dnumwant);
299 check_bkdisk_new((struct disk_header_new far *)&dheadnew, &dinfo, srcd, &dnumwant,&control_bufsize);
301 /*****************************************************************/
302 /* At this point a real backup diskette which is in correct sequence number */
303 /* has been found. In the case of new format, the file CONTROL.xxx is open.*/
304 /*****************************************************************/
305 /* restored the diskette */
306 /*****************************************************************/
309 if (set_reset_test_flag(&control_flag,OLDNEW,TEST) == TRUE)
310 search_src_disk_old(&dinfo,&finfo,&dheadold,(struct disk_header_new far *)&dheadnew,
311 (struct file_header_new far *)&fheadnew,srcd,destd,bufsize,&dnumwant,
312 inpath,infname,infext,infspec,dt);
314 search_src_disk_new(&dinfo,&finfo,&dheadold,(struct disk_header_new far *)&dheadnew,
315 (struct file_header_new far *)&fheadnew,srcd,destd,&dnumwant,bufsize,
316 inpath,infname,infspec,&control_bufsize,dt);
319 set_reset_test_flag(&control_flag2,OUTOF_SEQ,RESET);
320 /************************************************************************/
321 /*if ( bk disk is not the last one && (the file spec is WILDCARD or file*/
322 /*not found yet or SUB flag in rtswitches is on)), then prompt for user */
323 /*to insert another diskette and loop again. */
324 /************************************************************************/
325 if ((dinfo.dflag!=0xff) &&
326 ((set_reset_test_flag(&control_flag,WILDCARD,TEST) == TRUE) ||
327 (set_reset_test_flag(&control_flag,FOUND,TEST) == FALSE) ||
328 (set_reset_test_flag(&rtswitch,SUB,TEST) == TRUE)))
330 /**********************************************************/
331 /* output message for user to insert another diskette and */
332 /* "strike any key when ready" */
333 /* with response type 4 (wait for a key to be hit) */
334 /**********************************************************/
336 if (control_file_handle != 0xffff) /* !wrw */
338 DOSCLOSE(control_file_handle); /* !wrw */
339 control_file_handle = 0xffff; /* !wrw */
342 temp_array1[0] = (char)((dnumwant / 10) + '0');
343 temp_array1[1] = (char)((dnumwant % 10) + '0');
344 temp_array1[2] = NULLC;
345 temp_array2[0] = srcd;
346 temp_array2[1] = NULLC;
348 sublist.value1 = (char far *)temp_array1; /*;AN000;6 */
349 sublist.flags1 = LEFT_ALIGN + CHAR_FIELD_ASCIIZ; /*;AN000;6 */
350 sublist.max_width1 = (BYTE)strlen(temp_array1); /*;AN000;6 */
351 sublist.min_width1 = sublist.max_width1; /*;AN000;6 */
353 sublist.value2 = (char far *)temp_array2; /*;AN000;6 */
354 sublist.flags2 = LEFT_ALIGN + CHAR_FIELD_ASCIIZ; /*;AN000;6 */
355 sublist.max_width2 = (BYTE)strlen(temp_array2); /*;AN000;6 */
356 sublist.min_width2 = sublist.max_width2; /*;AN000;6 */
358 display_it(INSERT_SOURCE_DISK,STND_ERR_DEV,2,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
359 display_it(PRESS_ANY_KEY,STND_ERR_DEV,0,ANY_KEY_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
361 /* If single drive system, eliminates double prompting */
362 /* for user to "Insert diskette for drive %1" */
363 qregs.x.ax = SETLOGICALDRIVE; /*;AN000;8*/
364 qregs.h.bl = srcddir[0] - 'A' + 1; /*;AN000;8*/
365 intdos(&qregs,&qregs); /*;AN000;8*/
372 } /*end of for loop*/