home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / F_SYSVER.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  2.4 KB  |  86 lines

  1. *****************************************************************
  2. FUNCTION SYSVERSION (app_exe, app_dat)
  3. *****************************************************************
  4.  
  5. * Compare date and time on a file to that stored in another file
  6.  
  7. * Copyright(c) 1991 -- James Occhiogrosso
  8.  
  9. * Caution: Since SYSVERSION is critical to application
  10. * integrity, it returns to DOS with an error message
  11. * on any error that prevents proper version updating.
  12.  
  13. * App_exe is typically the application EXE file
  14. * App_dat is typically the version control file
  15.  
  16. LOCAL dat_size := 0, new_vers := old_vers := ''
  17.  
  18. IF PCOUNT() != 2
  19.     * Critical error - return to DOS
  20.     ?? CHR(7)
  21.     ? 'SYSVERSION error. - Both parameters are required.'
  22.     QUIT
  23. ENDIF
  24.  
  25. * Check file extensions. If not passed, use defaults.
  26.  
  27. IF AT(".", app_exe) = 0
  28.     * Assume first file is application EXE file
  29.     app_exe = TRIM(app_exe) + '.EXE'
  30. ENDIF
  31.  
  32. IF AT(".", app_dat) = 0
  33.     * Assume second file is a DAT file
  34.     app_dat = TRIM(app_dat) + '.DAT'
  35. ENDIF
  36.  
  37. * Verify existence of application file
  38.  
  39. IF .NOT. FILE(app_exe)
  40.     * Critical error - return to DOS
  41.     ?? CHR(7)
  42.     ? 'SYSVERSION error. -- Incorrect DOS file name passed. - ' ;
  43.                             + UPPER(app_exe)
  44.  
  45.     QUIT
  46. ENDIF
  47.  
  48. * Check control file size. Allow 15 bytes (the correct length)
  49. * or -1 (file does not exist). This prevents accidentally 
  50. * overwriting an important file if the version control file
  51. * name is passed incorrectly.
  52.  
  53. dat_size = FILESIZE(app_dat)
  54. IF dat_size = 15 .OR. dat_size = -1
  55.  
  56.     * Size of control file is correct or file does not exist
  57.  
  58.     * Read and format DOS date and time from first file
  59.     new_vers = DTOS(FILEDATE(app_exe)) + ;
  60.                STRTRAN(FILETIME(app_exe),':')
  61.  
  62.     * Read version control file's date/time string
  63.     old_vers = MEMOREAD(app_dat)
  64.  
  65.     * If new version, update version control file
  66.     * Compare new version string to old version string
  67.     IF EMPTY(old_vers) .OR. new_vers > old_vers
  68.         * New version. Update version control file
  69.         MEMOWRIT(app_dat, new_vers)
  70.         RETURN(.F.)
  71.     ELSE
  72.         * Otherwise, version strings match
  73.         RETURN(.T.)
  74.     ENDIF
  75.  
  76. ELSE
  77.     * Size of control file is incorrect. Do not rewrite it.
  78.     * Programmer probably specified wrong name.
  79.     ?? CHR(7)
  80.     ? 'SYSVERSION error. - Control file ' + UPPER(app_dat) + ;
  81.       ' - incorrect size'
  82.     QUIT
  83. ENDIF
  84.  
  85.  
  86.