//
//
//             SYSTEM DATA MAKER!!!!
//
//


#include <proto/all.h>
#include <exec/types.h>
#include <stdio.h>
#include <Tempest/BBS/headers.h>

struct SystemData SystemData;

struct OldSystemData SD;
struct SystemExtra SE;
struct SystemInternal SI;


main()
{
 char s[255];
 printf("This program will create your new master SystemData.data\n");
 printf("to be used in the new master setup directory.\n");

 printf("Where's your Setup directory kept?: ");
 gets(s);
 if(Doit(s))
  {
   printf("\n\n\n");
   printf("Here's what to do next : \n");
   printf(" 1) Make a back up of your entire setup directory\n",s);
   printf(" 2) Copy the file [Ram:SytemData.data] over to your new master setup dir\n");
  }
 else printf("An Error occured....\n");
}


int Doit(char PATH [])
{
 int in1,in2,in3,out;
 char in1file[255],in2file[255],in3file[255],outfile[255];
 int stat,x=0;

 sprintf(in1file,"%sSETUP/Config.data",PATH);
 in1=Open(in1file,MODE_OLDFILE);
 if(in1==0)
  {
   printf("** ERROR, loading config.data\n");
   return(0);
  }

 sprintf(in2file,"%sSETUP/Custom.data",PATH);
 in2=Open(in2file,MODE_OLDFILE);
 if(in2==0)
  {
   printf("** ERROR, loading custom.data\n");
   return(0);
  }

 sprintf(in3file,"%sSETUP/Internal.data",PATH);
 in3=Open(in3file,MODE_OLDFILE);
 if(in3==0)
  {
   printf("** ERROR, loading internal.data\n");
   return(0);
  }

 sprintf(outfile,"RAM:SystemData.data",PATH);
 out=Open(outfile,MODE_NEWFILE);
 if(out==0)
  {
   printf("** ERROR, creating RAM:SystemData.Data\n");
   return(0);
  }

 stat=Read(in1,(char *)&SD,sizeof(struct OldSystemData));  // Old System Data  / Config.data
 if(stat!=sizeof(struct OldSystemData)) { Close(in1); return(0); }

 stat=Read(in2,(char *)&SE,sizeof(struct SystemExtra));  // Old System Extra / custom.data
 if(stat!=sizeof(struct SystemExtra)) { Close(in2); return(0); }

 stat=Read(in3,(char *)&SI,sizeof(struct SystemInternal));  // Old System Internal / Internal.data
 if(stat!=sizeof(struct SystemInternal)) { Close(in3); return(0); }

 setmem(&SystemData,sizeof(struct SystemData),NULL);

  strcpy(SystemData.Name           ,SD.Name);
  strcpy(SystemData.Location       ,SE.Location);
  strcpy(SystemData.SysopName      ,SD.SysopName);

  strcpy(SystemData.ApplicationsPath,SI.Accounts);
  strcpy(SystemData.AccountDataPath,SI.AccountFile);
  strcpy(SystemData.CatalogsPath   ,SI.CatalogFile);
  strcpy(SystemData.ExtendedDescPath,SD.MSG);
  strcpy(SystemData.LogsPath       ,SD.TransPath);
  strcpy(SystemData.OptionalDirPath,SI.OptionalDir);
  strcpy(SystemData.SysopHoldPath  ,SD.SysopHold);
  strcpy(SystemData.ResumeDirPath  ,SD.ResumeDir);
  strcpy(SystemData.DoorsPath      ,SD.DoorPath);
  strcpy(SystemData.ModulesPath    ,SI.ModulesDir);
  strcpy(SystemData.VoteBoothPath  ,NULL);

  strcpy(SystemData.SysopEntryPassword ,NULL);
  strcpy(SystemData.SysopCmdsPassword  ,SD.PASSWORD);
  strcpy(SystemData.NewUserPassword    ,SD.NewPW);
  strcpy(SystemData.SystemEntryPassword,SD.SystemPW);

  strcpy(SystemData.LocalShell         ,SE.LocalShell);
  strcpy(SystemData.DropToShell        ,SE.DropToShell);
  strcpy(SystemData.FontName           ,SI.Font_Name);
  strcpy(SystemData.CHAR_Extra         ,NULL);

  SystemData.LockViewMode     = SI.ViewMode;
  SystemData.Chat_H           = SD.Chat_H;
  SystemData.Chat_M           = SD.Chat_M;
  SystemData.ULRewardPercent  = 50;
  SystemData.MaxPages         = 3;
  SystemData.NumberOfLines    = SI.Number_of_lines;
  SystemData.FontSize         = SI.Font_Size;
  SystemData.MaxUsers         = SD.Max_Users;
  SystemData.LowFreeSpace     = 6000000L;
  SystemData.NoFreeSpace      = SD.FreeSpace;
  SystemData.MaxSizeViewText  = 50000L;

  SystemData.WindowToFront    = SD.Extra6;


 Write(out,(char *)&SystemData,sizeof(struct SystemData));
 Close(in1);
 Close(in2);
 Close(in3);
 Close(out);
 return(1);
}
