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


/*---------------------- Pro/Toolkit Includes ------------------------*/
#include <ProToolkit.h>
#include <ProMdl.h>
#include <ProObjects.h>
#include <ProSizeConst.h>
#include <ProUtil.h>
#include <PTApplsUnicodeUtils.h>
#include <ProUtil.h>
/*---------------------- Application Includes ------------------------*/
#include <TestError.h>


/*---------------------- Function Prototypes -------------------------*/
ProError UsrModelFilenameGet(); 

ProError UsrModelFilenameGet(
    ProMdl      model,
    ProCharName filename)
{
    ProError    status;
    ProMdldata  data;
	ProMdlName modelName;
	ProMdlExtension modelExtension;
	ProPath modelFullPath = { 0 }, objDirPath = { 0 };
	int modelVersion;
    char name[PRO_MDLNAME_SIZE];
	char type[PRO_MDLEXTENSION_SIZE];

	status = ProMdlMdlnameGet(model, modelName);
	if (status != PRO_TK_NO_ERROR)
		return (status);

	status = ProMdlExtensionGet(model, modelExtension);
	if (status != PRO_TK_NO_ERROR)
		return (status);

    status = ProMdlOriginGet(model, modelFullPath);
	if (status != PRO_TK_NO_ERROR)
		return (status);

	status = ProFileMdlnameParse (modelFullPath, objDirPath, NULL, NULL, &modelVersion);
	if (status != PRO_TK_NO_ERROR)
		return (status);
	
    ProWstringToString(name, modelName);
    
    ProUtilStringLower(name, name);

    ProWstringToString(type, modelExtension);
    ProUtilStringLower(type, type);

    ProTKSprintf(filename, "%s.%s;%d", name,
             type, modelVersion);

    return(PRO_TK_NO_ERROR);
}