/************************************************************************/
/* PluginBoss plugin manager                                            */
/*																		*/
/* By Steve Pedler, March 2012		     						*/
/************************************************************************/

// main.cpp

/*
Copyright (C) 2012  Steve Pedler

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 3 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, see <http://www.gnu.org/licenses/>.
*/


#include "c4d.h"

// forward declarations
Bool RegisterPluginBoss(void);
C4D_CrashHandler old_handler;

void SDKCrashHandler(CHAR* crashinfo)
{
	// don't forget to call the original handler!!!
	if (old_handler) (*old_handler)(crashinfo);
}

Bool PluginStart(void)
{
	Bool success;

	// example of installing a crashhandler
	old_handler = C4DOS.CrashHandler;		// get the original handler (must be called!)
	C4DOS.CrashHandler = SDKCrashHandler;	// insert own handler

	// attempt to register our plugin with C4D; display a message in the console depending on the result
	if(!RegisterPluginBoss())
	{
		GePrint("Failed to register Plugin Boss");
		success = FALSE;
	} else {
		GePrint("Plugin Boss successfully loaded.");
		success = TRUE;
	}
	GePrint(" ");							// just prints a blank line
	return success;
}

void PluginEnd(void)
{
	// nothing to do here as we haven't allocated any resources which must be freed
	return;
}

Bool PluginMessage(LONG id, void *data)
{
	// handle incoming messages
	switch (id)
	{
	case C4DPL_INIT_SYS:
		if(!resource.Init())
		{
			GePrint("Plugin Boss: failed to load resource file.");
			return FALSE;
		}
		return TRUE;
		break;

	case C4DMSG_PRIORITY:
		return TRUE;
		break;

	default:
		return FALSE;
	}

	return TRUE;
}
