home *** CD-ROM | disk | FTP | other *** search
- ***********************
-
- FUNCTION Backup
-
- PARAMETER _files, _fromdrive, _atrow, _atcol, _todrive
-
- * Take the array of _files and back them up _fromdrive
- * _todrive and display the messages and procedures in a
- * window area beginning at _atrow, at_col
-
- IF PCOUNT() < 4
- RETURN(.F.)
- ELSEIF TYPE("_fromdrive")+TYPE("_atrow")+TYPE("_atcol") != "CNN"
- RETURN(.F.)
- ELSEIF !(TYPE("_files")$"AC")
- RETURN(.F.)
- ELSEIF PCOUNT() = 4
- _todrive = "A:"
- ELSEIF PCOUNT() = 5
- IF TYPE("_todrive") != "C"
- RETURN(.F.)
- ELSEIF LEN(_todrive) != 2
- RETURN(.F.)
- ENDIF
- ELSEIF LEN(_files) > 112
- RETURN(.F.)
- ENDIF
-
- _fromdrive = STRTRAN(_fromdrive + "\", "\\", "\")
-
- IF TYPE("_files") = "C"
- _tfiles = _files
-
- IF ("*"$_tfiles) .OR. ("?"$_tfiles)
- DECLARE _files[ADIR(_fromdrive + _tfiles)]
- ADIR(_fromdrive + _tfiles, _files)
- ELSE
- DECLARE _files[Occurence("/", _tfiles) + 1]
- IF LEN(_files) = 0
- RETURN(.F.)
- ELSE
- FOR _retx = 1 TO LEN(_files)
- _files[_retx] = Parsing(@_tfiles)
- NEXT
- ENDIF
- ENDIF
- ENDIF
-
- FOR _retx = 1 TO LEN(_files)
- _files[_retx] = _fromdrive + _files[_retx]
- NEXT
-
- _atrow = IF( _atrow > 15, 15, _atrow)
- _atcol = IF( _atcol > 25, 25, _atcol)
-
- PRIVATE _totbytes, _qaz, _totdisks, _bytesond
-
- _disknum = 0 && These are implied memory variables, don't
- && make these PRIVATE in nature.
- _retval = .T.
- _totbytes = 0
- _todrive = IF( (TYPE("_todrive")="U"), "A:", _todrive)
-
- Windowpush(_atrow, _atcol, _atrow + 6, _atcol + 40)
-
- FOR _qaz = 1 TO LEN(_files)
- Wsayget(3,7,"Working with " + SUBSTR(_files[_qaz], RAT("\", _files[_qaz]) + 1))
- Wsayget(4,7,Percent(LEN(_files), _qaz))
- IF FILE(_files[_qaz])
- _totbytes = _totbytes + Filesize(_files[_qaz])
- ENDIF
- Clear_area()
- NEXT
-
- EXTERNAL Valid_dr
-
- Wsayget(.T.,2,2,"Drive to BACKUP to => ", "_todrive", "!:", "Valid_dr(SUBSTR(_todrive, 1, 1))")
- IF LASTKEY() = 27 .OR. _todrive = " :"
- _retval = .F.
- ELSE
- Clear_area()
- _bytesond = INT(DISKSPACE(ASC(SUBSTR(_todrive, 1,1))-64) * .95) && Only use 95% of a disk
- _totdisks = INT( _totbytes / _bytesond) + 1
-
- Wsayget(1, 2, "You will need a grand total of " + LTRIM(STR(_totdisks)))
- Wsayget(3, 2, " to complete the Backup Process. ")
- Wsayget(5, 2, "Do you have these disks ready? ")
- IF !Prompt()
- Clear_area()
- Wsayget(2,4,"Unable to complete the Backup at ")
- Wsayget(3,4," this time. Press any key")
- Wsayget(4,4," to continue..")
- INKEY(0)
- _retval = .F.
- ELSE
- _retval = Backup1()
- Clear_area()
- Wsayget(3,1,"Operation Completed. Any Key Please..")
- INKEY(0)
- ENDIF
- ENDIF
- Windowpop()
- RETURN(_retval)
-
- *******************
-
- FUNCTION Backup1
-
- _bhandleto = 0 && Is the file handle for the backup file to copy to
- _bhandlefr = 0 && Is the file handle for the backup file to copy
- && from
- _withfile = 1 && Not PRIVATE, the subscript number with the name of
- && file to be backed up to the file.
- _isover = .F. && This variable is implied and when set to TRUE
- && then the BACKUP routine is finished.
- _byteswrit = 0 && Anther implied variable, this one keeps track of
- && the bytes written to the disk and will be tested
- && against the _bytestos variable. If they equal,
- && the disk will be full, a new one will be prompt
- && for and the operation will continue.
- _inprocess = .F. && Another variable used to say that when you go from
- && one disk to the disk, check this variable to see
- && if is _inprocess. If so, keep working on the file
- && that is open; other, open a new file and begin to
- && to copy
- _goneby = .F. && have we already gone by one pass?
- DO WHILE .T.
- _disknum = _disknum + 1 && Increment the variable
- _writefile = "" && This is the name of string that will contain the
- && names of the files written out to the disk.
- Clear_area()
-
- * Put PROMPTing message in right here telling which disk of how
- * many is being worked on.
-
- IF Dr_status(SUBSTR(_todrive, 1, 1))
- * drive is ready
- * Check to see if it is a GOOD and blank disk, if not..
- * display a message and loop or Q to quit.
- _withfiles = ""
- IF !EMPTY(ADIR(_todrive + "\*.*")) .AND. !_goneby
- Wsayget(2,2,"There's information on this diskette.")
- Wsayget(3,2,"Please insert a new disk & strike any")
- Wsayget(4,2," key to continue or 'Q' to abort!")
- IF Qwait("Q")
- RETURN(.F.)
- ELSE
- _goneby = .F.
- _disknum = _disknum - 1
- LOOP
- ENDIF
- ELSE
- DO WHILE _disknum >= 2
- Wsayget(2,2,"Change Disks and press any key to")
- Wsayget(3,2,"continue backing up, or press 'Q'")
- Wsayget(4,2," to Quit completely.")
- IF Qwait("Q")
- RETURN(.F.)
- ENDIF
- IF _bytesond != INT(DISKSPACE(ASC(SUBSTR(_todrive, 1,1))-64) * .95)
- _disknum = _disknum - 1
- LOOP
- ELSE
- EXIT
- ENDIF
- ENDDO
- Clear_area()
- Wsayget(1,2,"Working on Disk " + LTRIM(STR(_disknum)) + " of " + LTRIM(STR(_totdisks)))
- ENDIF
- ELSE
- Wsayget(2,2,"Experiencing difficulty with the ")
- Wsayget(3,2,"disk drive. Please re-insert or ")
- Wsayget(4,2," press 'Q' to Quit completely.")
- IF Qwait("Q")
- RETURN(.F.)
- ENDIF
- ENDIF
- IF LASTBACK() && Backup the files, if the last file to be copied
- * write out the MEM file with the number of the disk that
- * was just written out, the number of disks that are in the
- * batch, and the string with the files in it.
-
- _backw1 = LTRIM(STR(_disknum)) + "/" + LTRIM(STR(_totdisks)) + "/" + SUBSTR(_writefile, 1, LEN(_writefile)-1)
- MEMOWRIT(_todrive + "BACKUPID", _backw1)
- _backw1 = ""
- _byteswrit = 0 && Reset the variable
- ELSE
- * an error has been experienced, return a .F. to the calling
- * routine to abort...
- RETURN(.F.)
- ENDIF
- IF _isover
- EXIT
- ENDIF
- _goneby = .T.
- ENDDO
- RETURN(.T.)
-
- ********************
-
- FUNCTION Lastback
-
- DO WHILE .T.
- * figure out backup routines, build the script file to be
- * in control, write out the files, and increment the file
- * counter
-
- _tempfile = RAT("\", _files[_withfile])
- IF EMPTY(_tempfile)
- _tempfile = RAT("|", _files[_withfile])
- IF EMPTY(_tempfile)
- _writefile = _writefile + _files[_withfile] + "/"
- ELSE
- _writefile = _writefile + SUBSTR(_files[_withfile], _tempfile+1) + "/"
- ENDIF
- ELSE
- _writefile = _writefile + SUBSTR(_files[_withfile], _tempfile+1) + "/"
- ENDIF
-
- Clear_area(Wrow(2), _atcol, _atrow + 6, _atcol + 40)
-
- Wsayget(3,2, "Copying over File " + SUBSTR(_files[_withfile], RAT("\", _files[_withfile]) + 1))
-
- IF !_inprocess
- _bhandleto = FOPEN(_files[_withfile])
- ENDIF
-
- _bhandlefr = FCREATE(_todrive + SUBSTR(_files[_withfile], RAT("\", _files[_withfile]) + 1))
-
- * open the file on the main disk, create the file on the
- * backup to drive, copy the bytes out from the file to the
- * other file, close the files, move onto the next file.
-
-
- _positto = FSEEK(_bhandleto, 0, 1) && Get the current file position
- Wsayget(4,2,"Working on File #" + LTRIM(STR(_withfile)) + " out of " + LTRIM(STR(LEN(_files))))
-
- * Take into account that every file needs to check with _bytesond
- * to see if the number to write out exceeds that on the disk.
- * if so, return .F. to let the disk writing routines above do
- * their things
- *
- * Take the number of bytestos - the number of bytes written and
- * see if that is bigger than the file being worked on. If so,
- * write the whole file to the disk, increment the counter, add
- * the name of the file to the proper variable and move onto the
- * next file. If not, if the file is bigger than the remaining
- * bytes to write out, then write out only those bytes, do the rest
- * and return .F.
-
- _showbase = 1
- _loopagain = .F.
-
- IF FSEEK(_bhandleto, 0, 2) > (_bytesond - _byteswrit)
- _inprocess = .T.
- FSEEK(_bhandleto, _positto, 0)
- _isgood = .T.
- DO WHILE _isgood
- _tbytes = SPACE(IF( 1024 > (_bytesond - _byteswrit), (_bytesond - _byteswrit), 1024))
- _read = FREAD(_bhandleto, @_tbytes, LEN(_tbytes))
- IF FERROR() != 0
- Clear_area()
- Wsayget(2,2,"An error has been experienced. BACKUP")
- Wsayget(3,2," procedures have been aborted. Press")
- Wsayget(4,2," any key to continue.")
- INKEY(0)
- _withfile = LEN(_files) + 1
- RETURN(.F.)
- ENDIF
- IF _read != LEN(_tbytes) && The file is now completely written and we move onto the next file
- _inprocess = .F.
- FCLOSE(_bhandleto) && Close out the file
- _withfile = _withfile + 1 && Increment the counter
- IF !(_withfile > LEN(_files))
- _loopagain = .T.
- ENDIF
- EXIT
- ELSE
- Wsayget(5,2,FILL_OUT("Writing Out " + LTRIM(STR(INT(_read * _showbase))) + " Bytes ", 20))
- _isgood = (_read = 1024 ) && This is the last pass for this disk
- FWRITE(_bhandlefr, _tbytes, _read)
- _byteswrit = _byteswrit + _read
- IF _isgood
- _showbase = _showbase + 1
- ENDIF
- ENDIF
- ENDDO
- FCLOSE(_bhandlefr)
- IF _loopagain
- LOOP
- _loopagain = .F.
- ELSE
- EXIT
- ENDIF
- ELSE
- _inprocess = .F.
- * the file can be written to disk, so do it
- FSEEK(_bhandleto, _positto, 0) && Rewind to the original file position
- _isgood = .T. && Set the looping variable
- DO WHILE _isgood && Do WHILE it is o.k. to loop
- _tbytes = SPACE(1024) && set 1K of blank space
- _read = FREAD(_bhandleto, @_tbytes, LEN(_tbytes)) && Read in either 1K of info or rest of file
- IF FERROR() != 0
- Clear_area()
- Wsayget(2,2,"An error has been experienced. BACKUP")
- Wsayget(3,2," procedures have been aborted. Press")
- Wsayget(4,2," any key to continue.")
- INKEY(0)
- _withfile = LEN(_files) + 1
- RETURN(.F.)
- ENDIF
- Wsayget(5,2,Fill_out("Writing Out " + LTRIM(STR(INT(_read * _showbase))) + " Bytes ", 20))
- _isgood = (_read = 1024) && Reached the end of file
- FWRITE(_bhandlefr, _tbytes, _read) && Write out the total number of bytes
- _byteswrit = _byteswrit + _read && Increment the bytes written to the disk
- IF _isgood
- _showbase = _showbase + 1
- ENDIF
- ENDDO
- FCLOSE(_bhandlefr) && Close out the file
- FCLOSE(_bhandleto) && Close out the file
- _withfile = _withfile + 1 && Increment the counter
- ENDIF
-
- IF _withfile > LEN(_files)
- EXIT
- ENDIF
- ENDDO
- _isover = (_withfile > LEN(_files))
- RETURN(.T.)
-
- * End of File
-
-