/***************************************************************************
 *                                                                         *
 *   ANYCHG.CPP                                                            *
 *                                                                         *
 *   Copyright (c) 1987-1996 Galacticomm, Inc.    All Rights Reserved.     *
 *                                                                         *
 *   This is the integration-checker that BBSINT.EXE and BBSINTRO.EXE use  *
 *   to determine if system files need regeneration.  If there has been    *
 *   any change in time, date, or size on any of the .MDF files in the     *
 *   current directory, or any re-arrangement of them, or any change in    *
 *   the time, date, or size of WGSMENU2.DAT since the last time it ran,   *
 *   anychg() returns 1, otherwise 0.                                      *
 *                                                                         *
 *                                            - T. Stryker 2/17/92         *
 *                                            - R. Stein   2/2/93          *
 *                                                                         *
 ***************************************************************************/

#include "stdafx.h"
#include "gcommlib.h"

GBOOL anychg(GBOOL patreq);
GBOOL mjrup(VOID);

GBOOL                              //   returns TRUE if there has been a change
anychg(                            // check for any .MDF changes
GBOOL patreq)                      //   ignored -- no longer used
{
     FILE *fp;
     Cffblk dirfb;                 // for actual dir searches
     Cffblk oldfb;                 // for file I/O and comparison only

     (void)patreq;
     if ((fp=fopen("wgsint.run",FOPRB)) != NULL) {
          fclose(fp);
          unlink("wgsint.run");
          return(1);
     }
     if (fnd1st(&dirfb,"GALNSSF\\*.*",0)) {
          return(1);
     }
     if ((fp=fopen("wgsint.ref",FOPRB)) == NULL) {
          return(1);
     }
     if (fnd1st(&dirfb,"*.mdf",0)) {
          do {
               if (fread(&oldfb,sizeof(Cffblk),1,fp) != 1
                || !sameas(oldfb.ff_name,dirfb.ff_name)
                || oldfb.ff_ftime != dirfb.ff_ftime
                || oldfb.ff_fdate != dirfb.ff_fdate
                || oldfb.ff_fsize != dirfb.ff_fsize) {
                    fclose(fp);
                    oldfb.ff_handle=INVALID_HANDLE_VALUE;
                    return(1);
               }
          } while (fndnxt(&dirfb));
     }
     if (!fnd1st(&dirfb,"wgsmenu2.dat",0)
      || fread(&oldfb,sizeof(Cffblk),1,fp) != 1
      || oldfb.ff_ftime != dirfb.ff_ftime
      || oldfb.ff_fdate != dirfb.ff_fdate
      || oldfb.ff_fsize != dirfb.ff_fsize) {
          fclose(fp);
          oldfb.ff_handle=INVALID_HANDLE_VALUE;
          return(1);
     }

     oldfb.ff_handle=INVALID_HANDLE_VALUE;

     if (!fnd1st(&dirfb,"wgsuser.doc",0)) {
        fclose(fp);
        return(1);
     }
     fclose(fp);
     return(0);
}
