home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a075 / 1.img / TOOLKIT1.EXE / SST111.PRG < prev    next >
Encoding:
Text File  |  1989-08-13  |  12.7 KB  |  335 lines

  1. ***********************
  2.  
  3. FUNCTION Backup
  4.  
  5.    PARAMETER _files, _fromdrive, _atrow, _atcol, _todrive
  6.  
  7.    * Take the array of _files and back them up _fromdrive
  8.    * _todrive and display the messages and procedures in a
  9.    * window area beginning at _atrow, at_col
  10.  
  11.    IF PCOUNT() < 4
  12.       RETURN(.F.)
  13.    ELSEIF TYPE("_fromdrive")+TYPE("_atrow")+TYPE("_atcol") != "CNN"
  14.       RETURN(.F.)
  15.    ELSEIF !(TYPE("_files")$"AC")
  16.       RETURN(.F.)
  17.    ELSEIF PCOUNT() = 4
  18.       _todrive = "A:"
  19.    ELSEIF PCOUNT() = 5
  20.       IF TYPE("_todrive") != "C"
  21.          RETURN(.F.)
  22.       ELSEIF LEN(_todrive) != 2
  23.          RETURN(.F.)
  24.       ENDIF
  25.    ELSEIF LEN(_files) > 112
  26.       RETURN(.F.)
  27.    ENDIF
  28.  
  29.    _fromdrive = STRTRAN(_fromdrive + "\", "\\", "\")
  30.  
  31.    IF TYPE("_files") = "C"
  32.       _tfiles = _files
  33.  
  34.       IF ("*"$_tfiles) .OR. ("?"$_tfiles)
  35.          DECLARE _files[ADIR(_fromdrive + _tfiles)]
  36.          ADIR(_fromdrive + _tfiles, _files)
  37.       ELSE
  38.          DECLARE _files[Occurence("/", _tfiles) + 1]
  39.          IF LEN(_files) = 0
  40.             RETURN(.F.)
  41.          ELSE
  42.             FOR _retx = 1 TO LEN(_files)
  43.                _files[_retx] = Parsing(@_tfiles)
  44.             NEXT
  45.          ENDIF
  46.       ENDIF
  47.    ENDIF
  48.  
  49.    FOR _retx = 1 TO LEN(_files)
  50.       _files[_retx] = _fromdrive + _files[_retx]
  51.    NEXT
  52.  
  53.    _atrow = IF( _atrow > 15, 15, _atrow)
  54.    _atcol = IF( _atcol > 25, 25, _atcol)
  55.  
  56.    PRIVATE _totbytes, _qaz, _totdisks, _bytesond
  57.  
  58.    _disknum = 0    && These are implied memory variables, don't
  59.                    && make these PRIVATE in nature.
  60.    _retval = .T.
  61.    _totbytes = 0
  62.    _todrive  = IF( (TYPE("_todrive")="U"), "A:", _todrive)
  63.  
  64.    Windowpush(_atrow, _atcol, _atrow + 6, _atcol + 40)
  65.  
  66.    FOR _qaz = 1 TO LEN(_files)
  67.       Wsayget(3,7,"Working with " + SUBSTR(_files[_qaz], RAT("\", _files[_qaz]) + 1))
  68.       Wsayget(4,7,Percent(LEN(_files), _qaz))
  69.       IF FILE(_files[_qaz])
  70.          _totbytes = _totbytes + Filesize(_files[_qaz])
  71.       ENDIF
  72.       Clear_area()
  73.    NEXT
  74.  
  75.    EXTERNAL Valid_dr
  76.  
  77.    Wsayget(.T.,2,2,"Drive to BACKUP to => ", "_todrive", "!:", "Valid_dr(SUBSTR(_todrive, 1, 1))")
  78.    IF LASTKEY() = 27 .OR. _todrive = " :"
  79.       _retval = .F.
  80.    ELSE
  81.       Clear_area()
  82.       _bytesond = INT(DISKSPACE(ASC(SUBSTR(_todrive, 1,1))-64) * .95)  && Only use 95% of a disk
  83.       _totdisks = INT( _totbytes / _bytesond) + 1   
  84.  
  85.       Wsayget(1, 2, "You will need a grand total of " + LTRIM(STR(_totdisks)))
  86.       Wsayget(3, 2, "  to complete the Backup Process. ")
  87.       Wsayget(5, 2, "Do you have these disks ready? ")
  88.       IF !Prompt()
  89.          Clear_area()
  90.          Wsayget(2,4,"Unable to complete the Backup at ")
  91.          Wsayget(3,4,"   this time.  Press any key")
  92.          Wsayget(4,4,"        to continue..")
  93.          INKEY(0)
  94.          _retval = .F.
  95.       ELSE
  96.          _retval = Backup1()
  97.          Clear_area()
  98.          Wsayget(3,1,"Operation Completed.  Any Key Please..")
  99.          INKEY(0)
  100.       ENDIF
  101.    ENDIF
  102.    Windowpop()
  103.    RETURN(_retval)
  104.  
  105. *******************
  106.  
  107. FUNCTION Backup1
  108.  
  109.    _bhandleto = 0   && Is the file handle for the backup file to copy to
  110.    _bhandlefr = 0   && Is the file handle for the backup file to copy
  111.                     && from
  112.    _withfile = 1    && Not PRIVATE, the subscript number with the name of
  113.                     && file to be backed up to the file.
  114.    _isover = .F.    && This variable is implied and when set to TRUE
  115.                     && then the BACKUP routine is finished.
  116.    _byteswrit = 0   && Anther implied variable, this one keeps track of
  117.                     && the bytes written to the disk and will be tested
  118.                     && against the _bytestos variable.  If they equal,
  119.                     && the disk will be full, a new one will be prompt
  120.                     && for and the operation will continue.
  121.    _inprocess = .F. && Another variable used to say that when you go from
  122.                     && one disk to the disk, check this variable to see
  123.                     && if is _inprocess.  If so, keep working on the file
  124.                     && that is open; other, open a new file and begin to
  125.                     && to copy
  126.    _goneby = .F.    && have we already gone by one pass?
  127.    DO WHILE .T.
  128.       _disknum = _disknum + 1    && Increment the variable
  129.       _writefile = ""  && This is the name of string that will contain the
  130.                        && names of the files written out to the disk.
  131.       Clear_area()
  132.  
  133.       * Put PROMPTing message in right here telling which disk of how
  134.       * many is being worked on.
  135.  
  136.       IF Dr_status(SUBSTR(_todrive, 1, 1))
  137.          * drive is ready
  138.          * Check to see if it is a GOOD and blank disk, if not..
  139.          * display a message and loop or Q to quit.
  140.          _withfiles = ""
  141.          IF !EMPTY(ADIR(_todrive + "\*.*")) .AND. !_goneby
  142.             Wsayget(2,2,"There's information on this diskette.")
  143.             Wsayget(3,2,"Please insert a new disk & strike any")
  144.             Wsayget(4,2,"  key to continue or 'Q' to abort!")
  145.             IF Qwait("Q")
  146.                RETURN(.F.)
  147.             ELSE
  148.                _goneby = .F.
  149.                _disknum = _disknum - 1
  150.                LOOP
  151.             ENDIF
  152.          ELSE
  153.             DO WHILE _disknum >= 2
  154.                Wsayget(2,2,"Change Disks and press any key to")
  155.                Wsayget(3,2,"continue backing up, or press 'Q'")
  156.                Wsayget(4,2,"      to Quit completely.")
  157.                IF Qwait("Q")
  158.                   RETURN(.F.)
  159.                ENDIF
  160.                IF _bytesond != INT(DISKSPACE(ASC(SUBSTR(_todrive, 1,1))-64) * .95)
  161.                   _disknum = _disknum - 1
  162.                   LOOP
  163.                ELSE
  164.                   EXIT
  165.                ENDIF
  166.             ENDDO
  167.             Clear_area()
  168.             Wsayget(1,2,"Working on Disk " + LTRIM(STR(_disknum)) + " of " + LTRIM(STR(_totdisks)))
  169.          ENDIF
  170.       ELSE
  171.          Wsayget(2,2,"Experiencing difficulty with the ")
  172.          Wsayget(3,2,"disk drive.  Please re-insert or ")
  173.          Wsayget(4,2," press 'Q' to Quit completely.")
  174.          IF Qwait("Q")
  175.             RETURN(.F.)
  176.          ENDIF
  177.       ENDIF
  178.       IF LASTBACK()   && Backup the files, if the last file to be copied
  179.          * write out the MEM file with the number of the disk that
  180.          * was just written out, the number of disks that are in the
  181.          * batch, and the string with the files in it.
  182.  
  183.          _backw1 = LTRIM(STR(_disknum)) + "/" + LTRIM(STR(_totdisks)) + "/" + SUBSTR(_writefile, 1, LEN(_writefile)-1)
  184.          MEMOWRIT(_todrive + "BACKUPID", _backw1)
  185.          _backw1 = ""
  186.          _byteswrit = 0            && Reset the variable
  187.       ELSE
  188.          * an error has been experienced, return a .F. to the calling
  189.          * routine to abort...
  190.          RETURN(.F.)
  191.       ENDIF
  192.       IF _isover
  193.          EXIT
  194.       ENDIF
  195.       _goneby = .T.
  196.    ENDDO
  197.    RETURN(.T.)
  198.  
  199. ********************
  200.  
  201. FUNCTION Lastback
  202.  
  203.    DO WHILE .T.
  204.       * figure out backup routines, build the script file to be
  205.       * in control, write out the files, and increment the file
  206.       * counter
  207.  
  208.       _tempfile = RAT("\", _files[_withfile])
  209.       IF EMPTY(_tempfile)
  210.          _tempfile = RAT("|", _files[_withfile])
  211.          IF EMPTY(_tempfile)
  212.             _writefile = _writefile + _files[_withfile] + "/"
  213.          ELSE
  214.             _writefile = _writefile + SUBSTR(_files[_withfile], _tempfile+1) + "/"
  215.          ENDIF
  216.       ELSE
  217.          _writefile = _writefile + SUBSTR(_files[_withfile], _tempfile+1) + "/"
  218.       ENDIF
  219.  
  220.       Clear_area(Wrow(2), _atcol, _atrow + 6, _atcol + 40)
  221.  
  222.       Wsayget(3,2, "Copying over File " + SUBSTR(_files[_withfile], RAT("\", _files[_withfile]) + 1))
  223.  
  224.       IF !_inprocess
  225.          _bhandleto = FOPEN(_files[_withfile])
  226.       ENDIF
  227.  
  228.       _bhandlefr = FCREATE(_todrive + SUBSTR(_files[_withfile], RAT("\", _files[_withfile]) + 1))
  229.  
  230.                      * open the file on the main disk, create the file on the
  231.                      * backup to drive, copy the bytes out from the file to the
  232.                      * other file, close the files, move onto the next file.
  233.  
  234.  
  235.       _positto = FSEEK(_bhandleto, 0, 1)   && Get the current file position
  236.       Wsayget(4,2,"Working on File #" + LTRIM(STR(_withfile)) + " out of " + LTRIM(STR(LEN(_files))))
  237.  
  238.       * Take into account that every file needs to check with _bytesond
  239.       * to see if the number to write out exceeds that on the disk.
  240.       * if so, return .F. to let the disk writing routines above do
  241.       * their things
  242.       * 
  243.       * Take the number of bytestos - the number of bytes written and
  244.       * see if that is bigger than the file being worked on.  If so,
  245.       * write the whole file to the disk, increment the counter, add
  246.       * the name of the file to the proper variable and move onto the
  247.       * next file.  If not, if the file is bigger than the remaining
  248.       * bytes to write out, then write out only those bytes, do the rest
  249.       * and return .F.
  250.  
  251.       _showbase = 1
  252.       _loopagain = .F.
  253.  
  254.       IF FSEEK(_bhandleto, 0, 2) > (_bytesond - _byteswrit)
  255.          _inprocess = .T.                                      
  256.          FSEEK(_bhandleto, _positto, 0)                        
  257.          _isgood = .T.                                         
  258.          DO WHILE _isgood                                      
  259.             _tbytes = SPACE(IF( 1024 > (_bytesond - _byteswrit), (_bytesond - _byteswrit), 1024))
  260.             _read = FREAD(_bhandleto, @_tbytes, LEN(_tbytes))  
  261.             IF FERROR() != 0
  262.                Clear_area()
  263.                Wsayget(2,2,"An error has been experienced.  BACKUP")
  264.                Wsayget(3,2," procedures have been aborted.  Press")
  265.                Wsayget(4,2,"       any key to continue.")
  266.                INKEY(0)
  267.                _withfile = LEN(_files) + 1
  268.                RETURN(.F.)
  269.             ENDIF
  270.             IF _read != LEN(_tbytes)  && The file is now completely written and we move onto the next file
  271.                _inprocess = .F.
  272.                FCLOSE(_bhandleto)                                    && Close out the file
  273.                _withfile = _withfile + 1                             && Increment the counter
  274.                IF !(_withfile > LEN(_files))
  275.                   _loopagain = .T.
  276.                ENDIF
  277.                EXIT
  278.             ELSE
  279.                Wsayget(5,2,FILL_OUT("Writing Out " + LTRIM(STR(INT(_read * _showbase))) + " Bytes ", 20))
  280.                _isgood = (_read = 1024 )  && This is the last pass for this disk
  281.                FWRITE(_bhandlefr, _tbytes, _read)
  282.                _byteswrit = _byteswrit + _read            
  283.                IF _isgood
  284.                   _showbase = _showbase + 1
  285.                ENDIF
  286.             ENDIF
  287.          ENDDO
  288.          FCLOSE(_bhandlefr)         
  289.          IF _loopagain
  290.             LOOP
  291.             _loopagain = .F.
  292.          ELSE
  293.             EXIT
  294.          ENDIF
  295.       ELSE
  296.          _inprocess = .F.
  297.          * the file can be written to disk, so do it
  298.          FSEEK(_bhandleto, _positto, 0)                        && Rewind to the original file position
  299.          _isgood = .T.                                         && Set the looping variable
  300.          DO WHILE _isgood                                      && Do WHILE it is o.k. to loop
  301.             _tbytes = SPACE(1024)                              && set 1K of blank space
  302.             _read = FREAD(_bhandleto, @_tbytes, LEN(_tbytes))  && Read in either 1K of info or rest of file
  303.             IF FERROR() != 0
  304.                Clear_area()
  305.                Wsayget(2,2,"An error has been experienced.  BACKUP")
  306.                Wsayget(3,2," procedures have been aborted.  Press")
  307.                Wsayget(4,2,"       any key to continue.")
  308.                INKEY(0)
  309.                _withfile = LEN(_files) + 1
  310.                RETURN(.F.)
  311.             ENDIF
  312.             Wsayget(5,2,Fill_out("Writing Out " + LTRIM(STR(INT(_read * _showbase))) + " Bytes ", 20))
  313.             _isgood = (_read = 1024)                           && Reached the end of file
  314.             FWRITE(_bhandlefr, _tbytes, _read)                 && Write out the total number of bytes
  315.             _byteswrit = _byteswrit + _read                    && Increment the bytes written to the disk
  316.             IF _isgood
  317.                _showbase = _showbase + 1
  318.             ENDIF
  319.          ENDDO
  320.          FCLOSE(_bhandlefr)                                    && Close out the file
  321.          FCLOSE(_bhandleto)                                    && Close out the file
  322.          _withfile = _withfile + 1                             && Increment the counter
  323.       ENDIF
  324.  
  325.       IF _withfile > LEN(_files)
  326.          EXIT
  327.       ENDIF
  328.    ENDDO
  329.    _isover = (_withfile > LEN(_files))
  330.    RETURN(.T.)
  331.  
  332. * End of File
  333.  
  334.  
  335.