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

struct New
{
 TEXT     Name[31],       // Name of Area
          What[41],       // Description of Area
          Path[51],       // Path
          Password[21],   // Password
          EChar[50];

 BYTE     DelMonths,      // Deletion Months, 0 = Disabled.
          ON,
          Sex,
          EBYTE[20];

 UBYTE    AccessLevel,
          Area,
          MinAge,
          MaxAge,
          ULTimeReward,   // Upload Time Reward Percentage.
          DLTimeReward,   // Download Time Reward Percentage.
          DLBonusReward,  // Reward given to upload for every download of his UL's
          EUBYTE[20];

 WORD     RollOver,
          WExtras[4];
 int      Eint[4];
 long     ELong[5];

 LONGBITS Flags,
          Flags2;
}New;
#define FA_FREEDL    0x00000001  // All files are free donwload?


struct Old {

 TEXT Name[30],
      What[50],
      DONE[50],

      PART[48],
      FREE[1],      /* Y:free N:no */
      TEMP[50];

 int  Area,
      ON;
}Old;


main()
{
 char s[255];
 printf("This program will upgrade files.data in the setup directory\n");

 printf("Enter full Path to your setup directory?: ");
 gets(s);
 if( Doit(s) )
  {
   printf("\n\n\n");
  }
 else printf("Something happened, that wasn't suppose to....\n");
}


int Doit(char PATH [])
{
 int in,out;
 char FILEOUT[255];
 int stat,x=0,y;
 char FILEIN[255],date[255],string[255];

 sprintf(FILEIN,"%sFiles.Data",PATH);
 if(access(FILEIN,0)==0)
  {
   in=Open(FILEIN,MODE_OLDFILE);
   if(in==0)
    {
     printf("*** Error, loading the files.data file\n");
     return 0;
    }
   sprintf(FILEOUT,"%sFiles.Data-new",PATH);
   out=Open(FILEOUT,MODE_NEWFILE);
   if(out==0)
    {
     printf("*** Error, creating files.data file.\n");
     Close(in);
     return 0;
    }
   for(y=0;y<40;y++)
    {
     stat=Read(in,(char *)&Old,sizeof(struct Old));
     if(stat!=sizeof(struct Old)) break;
     setmem(&New,(LONG)sizeof(struct New),NULL);

     strcpy(New.Name,Old.Name);
     strcpy(New.What,Old.What);
     strcpy(New.Path,Old.DONE);

     New.Area=Old.Area;

     if(Old.FREE[0]=='Y') New.Flags |=  FA_FREEDL;
     else                 New.Flags &=~ FA_FREEDL;

     New.ON = Old.ON;

     New.Sex='B';
     New.ULTimeReward=50;

     stat=Write(out,(char *)&New,sizeof(struct New));
    }
   Close(in);
   Close(out);
  }
 exit(0);
}
