/*************************************************************************
*	TownsOS tool
*************************************************************************/

int		_tostool_if2tmp( char *instdir );

int		_tostool_install(char *instdir,int item_setup)
{
	int			ret, att, drv;
	char	   *srcdir, *instfile;
	char	   *item_prog, *item_ttl, item_para[128];
	int			item_att;
	char		tmp[256];

	syl_putf("TOS TOOL INSTALL");

	srcdir    = "/TAROPYON/TOOL";
	instfile  = "*.exp *.dll *.doc";

	srcdir = _tc_getFcopySrcDir( srcdir, tmp);
	att    = _FCOPY_MODE_INIT;
	ret    =  FCOPY_exec(att, srcdir, instfile, instdir);

#if	0
	if ( ret == NORMAL && item_setup != 0 )
	{	/* アイテム登録	*/
		syl_putf("TownsOS tools ITEM SETUP");

		drv = toupper(instdir[0]) - 'A';

		/* J-TYPE	*/
		item_prog    = "JTYPE.EXP";
		item_ttl     = "J-TYPE";
		item_para[0] = '\0';
		item_att     = 2;
		strcpy(tmp,instdir);	add_path_fn(tmp,item_prog);
		item_setApl( drv, 1024, item_ttl, tmp, item_para, item_att );

		/* J-MEC	*/
		item_prog    = "JMEC.EXP";
		item_ttl     = "J-MEC";
		item_para[0] = '\0';
		item_att     = 2;
		strcpy(tmp,instdir);	add_path_fn(tmp,item_prog);
		item_setApl( drv, 1024, item_ttl, tmp, item_para, item_att );

		/* J-SOUND	*/
		item_prog    = "JSOUND.EXP";
		item_ttl     = "J-SOUND";
		item_para[0] = '\0';
		item_att     = 2;
		strcpy(tmp,instdir);	add_path_fn(tmp,item_prog);
		item_setApl( drv, 1024, item_ttl, tmp, item_para, item_att );
	}
#endif

	if ( ret == NORMAL )
		ret = _tostool_if2tmp( instdir );

	return (ret);
}

/* "tmenu.if2" のテンプレートファイルの作成	*/

char	*_tostool_file[16] = 
{
	"CCI 00 20 cci.exp"      ,
	"LZH 00 20 lhx2.exp"     ,
	"MID 00 20 gsplay.exp"   ,
	"MOV 00 20 ugkplay.exp"  ,
	"MVE 00 20 mveplay.exp"  ,
	"WRD 00 20 jcomp.exp"    ,
	"V02 00 20 ugkplay.exp"  ,
	NULL                      
};

int		_tostool_if2tmp( char *instdir )
{
	int			i, argc;
	char		fn[256], tmp[256], **argv;
	char	   *fp;

	strcpy( tmp, instdir);	add_path_fn(tmp,"tmenuif2.tmp");
	if ( (fp = FS_fopen(tmp,"wb")) == NULL )
		return (ERR);

	for ( i = 0; _tostool_file[i] != NULL; ++i )
	{
		if ( (argc = DTA_makeArg(_tostool_file[i],&argv)) > 0 )
		{
			if ( argc > 3 )
			{
				strcpy( tmp, instdir);	add_path_fn(tmp,argv[3]);
				FS_dosFn(fn,tmp);
				fprintf(fp,"%-3s,%s,%s,%s\r\n",
				    argv[0], argv[1], argv[2], fn );
			}
			DTA_clearArg(argc,argv);
		}
	}
	FS_fclose(fp);
	return (NORMAL);
}
