/*************************************************************************
*	インストールファイル複写作業
*************************************************************************/

int		FcopyMode = 0;

int		_set_fcopymode(int update)
{
	if ( update )
		FcopyMode = FCOPY_TIME_CHECK | FCOPY_OVERWRITE_CHECK | FCOPY_LAST_MSG_IGN;
	else
		FcopyMode = FCOPY_LAST_MSG_IGN;
}

/*************************************************************************
*	HEWIN インストール
*************************************************************************/

int		_autoinst_HEWIN(char *pathInst)
{
	int		ret;
	char	*fileInst, *fileCci;
	char	dirSrc[128], instPathCci[256];
	char	tmp[256];

	fileInst = "hewin.exp hewin.ini hewin.icn hewin.tif *.dll *.rex rz.exp sz.exp tdptmp.tbl *.doc *.hlp";
	fileCci  = "makecci.bat cpp.exe *.h *.cci";

	dirSrc[0] = StartPath[0];
	dirSrc[1] = ':';
	strcpy( dirSrc + 2, "/TAROPYON/HEWIN/");

	if ( MakeDir(pathInst) )
		return (ERR);
	sprintf( instPathCci, "%s/CCISRC", pathInst );
	if ( MakeDir(instPathCci) )
		return (ERR);

	/* 複写元に現在ディレクトリを移動	--------------------------------*/
	sprintf( tmp, "%s.", dirSrc );
	FS_chdrv( toupper(dirSrc[0]) - 'A' );
	FS_chdir( tmp );

	/* HEWIN インストール	--------------------------------------------*/
	ret = 0;
	SYL_puts( C_INFO, "HEwin");
	ret = FM_fcopy( fileInst, 0x00, FcopyMode, pathInst, "" );
	if ( ret != NORMAL )
		return (ERR);

	/* RS-232C MIDI 演奏用	--------------------------------------------*/
	if ( HewinRsmidi )
	{
		tmp[0] = StartPath[0];
		tmp[1] = ':';
		strcpy( tmp + 2, "/TAROPYON/RSBGMDLL");
		FS_chdrv( toupper(tmp[0]) - 'A' );
		FS_chdir( tmp );
		ret = FM_fcopy( "rsbgm.dll"   , 0x00, FCOPY_SINGLE_COPY|FCOPY_LAST_MSG_IGN, pathInst, "bgm.dll" );
		if ( ret != NORMAL )
			return (ERR);

		sprintf( tmp, "%s.", dirSrc );
		FS_chdrv( toupper(dirSrc[0]) - 'A' );
		FS_chdir( tmp );
		ret = FM_fcopy( "hewin_rs.cci", 0x00, FCOPY_SINGLE_COPY|FCOPY_LAST_MSG_IGN, pathInst, "hewin.cci" );
		if ( ret != NORMAL )
			return (ERR);
	} else
	{
		ret = FM_fcopy( "bgm.dll"     , 0x00, FCOPY_SINGLE_COPY|FCOPY_LAST_MSG_IGN, pathInst, "bgm.dll" );
		if ( ret != NORMAL )
			return (ERR);

		ret = FM_fcopy( "hewin.cci"   , 0x00, FCOPY_SINGLE_COPY|FCOPY_LAST_MSG_IGN, pathInst, "hewin.cci" );
		if ( ret != NORMAL )
			return (ERR);
	}

	/* CCI インストール	------------------------------------------------*/
	sprintf( tmp, "%sCCISRC", dirSrc );
	FS_chdrv( toupper(dirSrc[0]) - 'A' );
	FS_chdir( tmp );

	ret = 0;
	SYL_puts( C_INFO, "HEwin CCI program" );
	ret = FM_fcopy( fileCci, 0x00, FcopyMode, instPathCci, "" );
	if ( ret != NORMAL )
		return (ERR);

	return (NORMAL);
}

/*************************************************************************
*	EDIA インストール
*************************************************************************/

int		_autoinst_EDIA(char *pathInst)
{
	int		ret;
	char	*fileInst, *fileTool, *fileCci;
	char	dirSrc[128], instPathCci[256];
	char	tmp[256];

	fileInst = "edia.exp edia.ini *.dll *.rex editmp.tbl *.doc";
	fileCci  = "makecci.bat cpp.exe *.h *.cci";

	dirSrc[0] = StartPath[0];
	dirSrc[1] = ':';
	strcpy( dirSrc + 2, "/TAROPYON/EDIA/");

	if ( MakeDir(pathInst) )
		return (ERR);
	sprintf( instPathCci, "%s/CCISRC", pathInst );
	if ( MakeDir(instPathCci) )
		return (ERR);

	/* 複写元に現在ディレクトリを移動	--------------------------------*/
	sprintf( tmp, "%s.", dirSrc );
	FS_chdrv( toupper(dirSrc[0]) - 'A' );
	FS_chdir( tmp );

	/* EDIA インストール	--------------------------------------------*/
	ret = 0;
	SYL_puts( C_INFO, "EDIA");
	ret = FM_fcopy( fileInst, 0x00, FcopyMode, pathInst, "" );
	if ( ret != NORMAL )
		return (ERR);

	/* RS-232C MIDI 演奏用	--------------------------------------------*/
	if ( EdiaRsmidi )
	{
		tmp[0] = StartPath[0];
		tmp[1] = ':';
		strcpy( tmp + 2, "/TAROPYON/RSBGMDLL");
		FS_chdrv( toupper(tmp[0]) - 'A' );
		FS_chdir( tmp );
		ret = FM_fcopy( "rsbgm.dll", 0x00, FCOPY_SINGLE_COPY|FCOPY_LAST_MSG_IGN, pathInst, "bgm.dll" );
		if ( ret != NORMAL )
			return (ERR);

		sprintf( tmp, "%s.", dirSrc );
		FS_chdrv( toupper(dirSrc[0]) - 'A' );
		FS_chdir( tmp );
		ret = FM_fcopy( "edia__rs.cci", 0x00, FCOPY_SINGLE_COPY|FCOPY_LAST_MSG_IGN, pathInst, "edia.cci" );
		if ( ret != NORMAL )
			return (ERR);
	} else
	{
		ret = FM_fcopy( "bgm.dll"     , 0x00, FCOPY_SINGLE_COPY|FCOPY_LAST_MSG_IGN, pathInst, "bgm.dll" );
		if ( ret != NORMAL )
			return (ERR);

		ret = FM_fcopy( "edia.cci"    , 0x00, FCOPY_SINGLE_COPY|FCOPY_LAST_MSG_IGN, pathInst, "edia.cci" );
		if ( ret != NORMAL )
			return (ERR);
	}

	/* CCI インストール	------------------------------------------------*/
	sprintf( tmp, "%sCCISRC", dirSrc );
	FS_chdrv( toupper(dirSrc[0]) - 'A' );
	FS_chdir( tmp );

	ret = 0;
	SYL_puts( C_INFO, "EDIA CCI program");
	ret = FM_fcopy( fileCci, 0x00, FcopyMode, instPathCci, "" );
	if ( ret != NORMAL )
		return (ERR);

	return (NORMAL);
}

/*************************************************************************
*	GSPLAY インストール
*************************************************************************/

int		_autoinst_GSPLAY(char *pathInst)
{
	int		ret;
	char	*fileInst, *fileSample;
	char	dirSrc[128], instPathSample[256];
	char	tmp[256];

	fileInst = "gsplay.exp gsplay.doc gspkok.doc gstone.dat gsrym.dat *.mex";
	fileSample = "sample.mid sample.kok sample.tif";

	dirSrc[0] = StartPath[0];
	dirSrc[1] = ':';
	strcpy( dirSrc + 2, "/TAROPYON/GSPLAY/");

	if ( MakeDir(pathInst) )
		return (ERR);
	if ( GsplaySample )
	{
		sprintf( instPathSample, "%s/SAMPLE", pathInst );
		if ( MakeDir(instPathSample) )
			return (ERR);
	}

	/* 複写元に現在ディレクトリを移動	--------------------------------*/
	sprintf( tmp, "%s.", dirSrc );
	FS_chdrv( toupper(dirSrc[0]) - 'A' );
	FS_chdir( tmp );

	/* GSPLAY インストール	--------------------------------------------*/
	ret = 0;
	SYL_puts( C_INFO, "GSPLAY");
	ret = FM_fcopy( fileInst, 0x00, FcopyMode, pathInst, "" );
	if ( ret != NORMAL )
		return (ERR);

	/* サンプルインストール	--------------------------------------------*/
	if ( GsplaySample )
	{
		sprintf( tmp, "%sSAMPLE", dirSrc );
		FS_chdrv( toupper(dirSrc[0]) - 'A' );
		FS_chdir( tmp );

		ret = 0;
		SYL_puts( C_INFO, "GSPLAY sample data");
		ret = FM_fcopy( fileSample, 0x00, FcopyMode, instPathSample, "" );
		if ( ret != NORMAL )
			return (ERR);
	}

	return (NORMAL);
}

/*************************************************************************
*	HE386 インストール
*************************************************************************/

int		_autoinst_HE386(char *pathInst)
{
	int		ret;
	char	*fileInst, *fileCci, *fileSample;
	char	dirSrc[128], instPathCci[256], instPathSample[256];
	char	tmp[256];

	fileInst   = "he386.exp he386.cci *.dll *.rex *.doc";
	fileCci    = "makecci.bat cpp.exe *.h *.cci";
	fileSample = "*.h *.def *.ini *.mml";

	dirSrc[0] = StartPath[0];
	dirSrc[1] = ':';
	strcpy( dirSrc + 2, "/TAROPYON/HE386/");

	if ( MakeDir(pathInst) )
		return (ERR);
	sprintf( instPathCci, "%s/CCISRC", pathInst );
	if ( MakeDir(instPathCci) )
		return (ERR);
	if ( He386sample )
	{
		sprintf( instPathSample, "%s/SAMPLE", pathInst );
		if ( MakeDir(instPathSample) )
			return (ERR);
	}

	/* 複写元に現在ディレクトリを移動	--------------------------------*/
	sprintf( tmp, "%s.", dirSrc );
	FS_chdrv( toupper(dirSrc[0]) - 'A' );
	FS_chdir( tmp );

	/* HE386 インストール	--------------------------------------------*/
	ret = 0;
	SYL_puts( C_INFO, "HE386");
	ret = FM_fcopy( fileInst, 0x00, FcopyMode, pathInst, "" );
	if ( ret != NORMAL )
		return (ERR);

	/* CCI インストール	------------------------------------------------*/
	sprintf( tmp, "%sCCISRC", dirSrc );
	FS_chdrv( toupper(dirSrc[0]) - 'A' );
	FS_chdir( tmp );

	ret = 0;
	SYL_puts( C_INFO, "HE386 CCI program" );
	ret = FM_fcopy( fileCci, 0x00, FcopyMode, instPathCci, "" );
	if ( ret != NORMAL )
		return (ERR);

	/* サンプルデータインストール	------------------------------------*/
	if ( He386sample )
	{
		sprintf( tmp, "%sSAMPLE", dirSrc );
		FS_chdrv( toupper(dirSrc[0]) - 'A' );
		FS_chdir( tmp );

		ret = 0;
		SYL_puts( C_INFO, "HE386 sample mml" );
		ret = FM_fcopy( fileSample, 0x00, FcopyMode, instPathSample, "" );
		if ( ret != NORMAL )
			return (ERR);
	}

	return (NORMAL);
}

/*************************************************************************
*	CCI インストール
*************************************************************************/

int		_autoinst_CCI(char *pathInst)
{
	int		ret;
	char	*fileInst;
	char	dirSrc[128], instPathCci[256];
	char	tmp[256];

	fileInst = "cci.exp *.dll *.doc *.lst runcci.bat *.h *.cci";

	dirSrc[0] = StartPath[0];
	dirSrc[1] = ':';
	strcpy( dirSrc + 2, "/TAROPYON/CCI/");

	if ( MakeDir(pathInst) )
		return (ERR);

	/* 複写元に現在ディレクトリを移動	--------------------------------*/
	sprintf( tmp, "%s.", dirSrc );
	FS_chdrv( toupper(dirSrc[0]) - 'A' );
	FS_chdir( tmp );

	/* CCI インストール		--------------------------------------------*/
	ret = 0;
	SYL_puts( C_INFO, "CCI");
	ret = FM_fcopy( fileInst, 0x00, FcopyMode, pathInst, "" );
	if ( ret != NORMAL )
		return (ERR);

	return (NORMAL);
}

/*************************************************************************
*	サイドワークツールインストール
*************************************************************************/

int		_autoinst_SDK(char *pathInst)
{
	int		ret, i;
	char	*fileInst;
	char	*msg, dirSrc[128];
	char	tmp[256];

	if ( MakeDir(pathInst) )
		return (ERR);

	for( i = 0; i < 5; ++i )
	{
		dirSrc[0] = StartPath[0];
		dirSrc[1] = ':';
		switch ( i )
		{
			case 0:
				msg = "SDKCALC";
				fileInst = "*.exp *.doc";
				strcpy( dirSrc + 2, "/TAROPYON/SDK/SDKCALC/");
				break;
			case 1:
				msg = "SDKDIC";
				fileInst = "*.exp *.doc";
				strcpy( dirSrc + 2, "/TAROPYON/SDK/SDKDIC/");
				break;
			case 2:
				msg = "SDKFS";
				fileInst = "*.exp *.doc";
				strcpy( dirSrc + 2, "/TAROPYON/SDK/SDKFS/");
				break;
			case 3:
				msg = "SDKMENU";
				fileInst = "*.exp *.doc";
				strcpy( dirSrc + 2, "/TAROPYON/SDK/SDKMENU/");
				break;
			case 4:
				msg = "SMFPLAY";
				fileInst = "*.exp *.doc";
				strcpy( dirSrc + 2, "/TAROPYON/SDK/SMFPLAY/");
				break;
		}

		/* 複写元に現在ディレクトリを移動	--------------------------------*/
		sprintf( tmp, "%s.", dirSrc );
		FS_chdrv( toupper(dirSrc[0]) - 'A' );
		FS_chdir( tmp );

		ret = 0;
		SYL_puts( C_INFO, msg);
		ret = FM_fcopy( fileInst, 0x00, FcopyMode, pathInst, "" );
		if ( ret != NORMAL )
			return (ERR);
	}
	return (NORMAL);
}
