/* A friend of mine who works in a computer store will soon move
 * all AmigaLibDisks to a Winchester harddrive with
 * exchangeable disks. For each disk there will be a directory,
 * for AmigaLibDisks there is a Fish, that's why I have written
 * this program.
 *               Olsen
 */

#include <workbench/workbench.h>
#include <exec/execbase.h>

#define Drop(s) Write(Output(),s,strlen(s))

extern struct Library	*OpenLibrary();
struct Library		*IconBase;

USHORT FishData[176] =
{
	/* Plane 0 */

	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0E00,
	0x1000,0x0000,0x3C00,0x3180,0x0C00,0x0000,0x3C00,0x0E00,
	0x0700,0x0000,0xC030,0x0000,0x00C0,0x0000,0x00FC,0x0180,
	0x0000,0x0000,0x03C3,0x0660,0x00F0,0x0000,0x0F0F,0xC180,
	0x007F,0x000C,0x03FF,0x0000,0x0007,0xC03F,0x00FC,0x0000,
	0x0000,0x00FF,0xC030,0x0000,0x0007,0xC3FF,0xF000,0x0000,
	0x007F,0x03FF,0xFC00,0x0000,0x00F0,0x00FF,0xFF00,0x0000,
	0x0000,0x003F,0xFFC0,0x0000,0x00C0,0x000F,0xFF00,0x0000,
	0x0700,0x0003,0xFC00,0x0000,0x0C00,0x0000,0xF000,0x0000,
	0x1000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

	/* Plane 1 */

	0xC000,0x0000,0x0C00,0x0000,0xF000,0x0000,0x3B00,0x0000,
	0x7C00,0x0000,0xFDC0,0x0000,0x3F00,0x0003,0xBEB0,0x0000,
	0x1FC0,0x000D,0xD5CC,0x0000,0x0CF0,0x003A,0xAB03,0x0000,
	0x060C,0x00D5,0x5C3C,0xC000,0x03F3,0x03AA,0xB0F0,0x3000,
	0x01FF,0xCD51,0x5C00,0xDC00,0x00C7,0xFA80,0xAB03,0xAB00,
	0x0060,0xD500,0x15CD,0xFF00,0x00C7,0xF800,0x0ABA,0xAB00,
	0x01FF,0xCC00,0x0155,0x5C00,0x03F3,0x0300,0x00AA,0xB000,
	0x060C,0x00C0,0x0015,0xC000,0x0CF0,0x0030,0x00AB,0x0000,
	0x1FC0,0x000C,0x015C,0x0000,0x3F00,0x0003,0x0AB0,0x0000,
	0x7C00,0x0000,0xD5C0,0x0000,0xF000,0x0000,0x3B00,0x0000,
	0xC000,0x0000,0x0C00,0x0000,0x0000,0x0000,0x0000,0x0000
};

struct Image FishImage =
{
	0,0,
	59,22,2,
	(USHORT *)&FishData[0],
	0x03,0x00,
	(struct Image *)NULL
};

struct DrawerData FishDrawer =
{
	50,50,
	400,100,
	-1,-1,
	NULL,
	0x0240027F,
	(struct Gadget *)NULL,
	(struct Image *)NULL,
	(UBYTE *)NULL,
	(struct Screen *)NULL,
	(struct BitMap *)NULL,
	90,40,
	-1,-1,
	WBENCHSCREEN,

	0,
	0
};

struct DiskObject FishIcon =
{
	WB_DISKMAGIC,
	WB_DISKVERSION,

	(struct Gadget *)NULL,
	0,0,
	59,22,
	GADGIMAGE | GADGBACKFILL,
	RELVERIFY | GADGIMMEDIATE,
	BOOLGADGET,
	(APTR)&FishImage,
	(APTR)NULL,
	(struct IntuiText *)NULL,
	NULL,
	(APTR)NULL,
	NULL,
	(APTR)NULL,

	WBDRAWER,
	(char *)NULL,
	(char **)NULL,
	NO_ICON_POSITION,
	NO_ICON_POSITION,
	(struct DrawerData *)&FishDrawer,
	(char *)NULL,
	0
};

void _wb_parse(){}

void
main(argc,argv)
long argc;
char *argv[];
{
	long FileLock;

	if(!argc)
		exit(20);

	if(!(IconBase = (struct Library *)OpenLibrary("icon.library",LIBRARY_VERSION)))
	{
		Drop("Couldn't open icon.library!\n");

		exit(20);
	}

	if(!(FileLock = CreateDir(argv[1])))
	{
		Drop("Couldn't create directory!\n");
		CloseLibrary(IconBase);

		exit(20);
	}

	UnLock(FileLock);

	if(!PutDiskObject(argv[1],&FishIcon))
	{
		Drop("Couldn't create icon!\n");
		CloseLibrary(IconBase);

		exit(20);
	}

	CloseLibrary(IconBase);

	exit(0);
}
