/*
    NewsCoaster
    Copyright (C) 1999-2002 Mark Harman

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    NewsCoaster Homepage :
        http://newscoaster.tripod.com/

    Mailing List to hear about announcements of new releases etc at:
        http://groups.yahoo.com/group/newscoaster-announce/
*/

#include <proto/dos.h>

#include <stdio.h>
#include <string.h>

#include "Vector.h"
#include "regist.h"

static struct Regist regist;

static BOOL reg;

/* Delete the keyfile!
 */
void p() {
	STRPTR filename = "PROGDIR:.key";
	DeleteFile(filename);
}

/* Check the registration.
 */
void CheckRegist() {
	BOOL ok = TRUE;
	char *filename = "PROGDIR:.key";
	BPTR file;
	struct FileLock *lock;
	lock=(struct FileLock *)Lock(filename,ACCESS_READ);
	if(!lock)
		ok=FALSE;
	else {
		file=Open(filename,MODE_OLDFILE);
		if(!file)
			ok=FALSE;
		else {
			Read(file,&regist,sizeof(struct Regist));
			Close(file);
		}
		UnLock((BPTR)lock);
	}
	
	int k;
	for(k=0;k<25;k++)
		regist.Owner[k] = (regist.Owner[k] - 4*k);

	for(k=0;k<11;k++)
		regist.Date[k] = (regist.Date[k] - 6*k);
	if(strstr(regist.Owner,"of RESISTANCE!")!=0) {
		p();
		ok = FALSE;
	}

	reg=ok;
}

/* Is this a registered copy of NewsCoaster?
 */
BOOL IsRegistered() {
	return(reg);
}

/* Return registration details.
 */
struct Regist * ReturnRegistration() {
	return &regist;
}
