/*
	Copyright (c) 2024 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved.
*/


#include <ProToolkit.h>
#include <ProMfg.h>
#include <ProTool.h>
#include <ProUtil.h>
#include <ProMfgOptions.h>

#include <TestError.h>
#include <UgMfg.h>

/*====================================================================*\
Function : UserToolFileRead
Purpose  : Creates or redefines a tool from file
\*====================================================================*/
ProError UserToolFileRead (
/*--------------------------------------------------------------------*/
ProMfg		mfg_model,
wchar_t		*tool_id,
ProPath		file_name,
ProBool		allow_redefine,
ProTool		*p_tool

)
/*--------------------------------------------------------------------*/
{
 ProError	status = PRO_TK_NO_ERROR;

 status = ProToolInit( tool_id, mfg_model, p_tool );
	
 if ( status == PRO_TK_NO_ERROR )
   status = ProToolVerify( p_tool );

 if ( status == PRO_TK_E_NOT_FOUND )
   status = PRO_TK_NO_ERROR;
 else if ( status == PRO_TK_NO_ERROR && !allow_redefine )
   status = PRO_TK_E_FOUND;  /* tool exists and should not be changed */

 if ( status == PRO_TK_NO_ERROR )
   status = ProToolFileRead( p_tool, file_name );

 if ( status == PRO_TK_NO_ERROR )
   status = ProToolVerify( p_tool );

 return ( status );
}

/*====================================================================*\
Function : UserToolFileWrite
Purpose  : Writes information about a tool into a file
\*====================================================================*/
ProError UserToolFileWrite (
/*--------------------------------------------------------------------*/
ProMfg		mfg_model,
wchar_t		*tool_id,
ProPath		file_name

)
/*--------------------------------------------------------------------*/
{
 ProError	status = PRO_TK_NO_ERROR;
 ProTool	tool;

 status = ProToolInit( tool_id, mfg_model, &tool );
	
 if ( status == PRO_TK_NO_ERROR )
   status = ProToolFileWrite( &tool, file_name );

 return ( status );
}