<commit_before>#include "FileProcess.h"
#include <memory>

FileProcess::FileProcess()
{
	strLogicClassFile = "../Struct/LogicClass.xml";
	mysqlWriter = fopen(strMySQLFile.c_str(), "w");
	mysqlClassWriter = fopen(strMySQLClassFile.c_str(), "w");
	protoWriter = fopen(strProtoFile.c_str(), "w");
	hppWriter = fopen(strHPPFile.c_str(), "w");
	javaWriter = fopen(strJavaFile.c_str(), "w");
	csWriter = fopen(strCSFile.c_str(), "w");
}

FileProcess::~FileProcess()
{
	fclose(mysqlWriter);
	fclose(mysqlClassWriter);
	fclose(protoWriter);
	fclose(hppWriter);
	fclose(javaWriter);
	fclose(csWriter);
}

void FileProcess::CreateProtoFile()
{
	std::string toWrite = "package NFrame;\n";
	if ((protoWriter) == NULL)
		return;
	fwrite(toWrite.c_str(), toWrite.length(), 1, protoWriter);
}

void FileProcess::CreateNameFile()
{
	time_t timeval;
	timeval = time(NULL);
	auto strNow = ctime(&timeval);
	std::string strHPPHead
		= "// -------------------------------------------------------------------------\n";
	strHPPHead = strHPPHead
		+ "//    @FileName         :    NFProtocolDefine.hpp\n"
		+ "//    @Author           :    NFrame Studio\n"
		+ "//    @Date             :    " + strNow
		+ "//    @Module           :    NFProtocolDefine\n"
		+ "// -------------------------------------------------------------------------\n\n"
		+ "#ifndef NF_PR_NAME_HPP\n"
		+ "#define NF_PR_NAME_HPP\n\n"
		+ "#include <string>\n"
		+ "namespace NFrame\n{\n";

	/////////////////////////////////////////////////////
	fwrite(strHPPHead.c_str(), strHPPHead.length(), 1, hppWriter);
	/////////////////////////////////////////////////////

	std::string strJavaHead
		= "// -------------------------------------------------------------------------\n";
	strJavaHead = strJavaHead
		+ "//    @FileName         :    NFProtocolDefine.java\n"
		+ "//    @Author           :    NFrame Studio\n"
		+ "//    @Date             :    " + strNow
		+ "//    @Module           :    NFProtocolDefine\n"
		+ "// -------------------------------------------------------------------------\n\n"
		+ "package nframe;\n";

	fwrite(strJavaHead.c_str(), strJavaHead.length(), 1, javaWriter);
	/////////////////////////////////////////////////////

	std::string strCSHead = "// -------------------------------------------------------------------------\n";
	strCSHead = strCSHead
		+ "//    @FileName         :    NFProtocolDefine.cs\n"
		+ "//    @Author           :    NFrame Studio\n"
		+ "//    @Date             :    " + strNow
		+ "//    @Module           :    NFProtocolDefine\n"
		+ "// -------------------------------------------------------------------------\n\n"
		+ "using System;\n"
		//+ "using System.Collections.Concurrent;\n"
		+ "using System.Collections.Generic;\n"
		+ "using System.Linq;\n"
		+ "using System.Text;\n"
		+ "using System.Threading;\n"
		//+ "using System.Threading.Tasks;\n\n"
		+ "namespace NFrame\n{\n";

	fwrite(strCSHead.c_str(), strCSHead.length(), 1, csWriter);
	/////////////////////////////////////////////////////
}

void FileProcess::OnCreateXMLFile()
{
	//////////////////////////////////////////////////////////////////////
	CreateStructThreadFunc();
	CreateIniThreadFunc();
}

void FileProcess::CreateStructThreadFunc()
{
	// protoļ
	CreateProtoFile();

	// PropertyRecordhppͷļ
	CreateNameFile();


	//xmlĵ
	tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
	if (NULL == xmlDoc)
	{
		return;
	}

	//xml
	tinyxml2::XMLDeclaration *pDel = xmlDoc->NewDeclaration("xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"");
	if (NULL == pDel)
	{
		return;
	}

	xmlDoc->LinkEndChild(pDel);

	tinyxml2::XMLElement* root = xmlDoc->NewElement("XML");
	xmlDoc->LinkEndChild(root);

	tinyxml2::XMLElement* classElement = xmlDoc->NewElement("Class");
	root->LinkEndChild(classElement);
	////////////////////////////////////////////////////////////////////////
	classElement->SetAttribute("Id", "IObject");
	classElement->SetAttribute("Type", "TYPE_IOBJECT");

	classElement->SetAttribute("Path", (strExecutePath + "Struct/Class/IObject.xml").c_str());
	classElement->SetAttribute("InstancePath", (strExecutePath + "Ini/NPC/IObject.xml").c_str());

	classElement->SetAttribute("Public", "0");
	classElement->SetAttribute("Desc", "IObject");
	////////////////////////////////////////////////////////////////////////
	//// ǰIObjectһ
	CreateStructXML("../Excel_Struct/IObject.xlsx", "IObject");

	// Structļµexcelļ
	auto fileList = GetFileListInFolder(strToolBasePath + strExcelStructPath, 0);

	for (auto fileName : fileList)
	{
		StringReplace(fileName, "\\", "/");
		StringReplace(fileName, "//", "/");
		// excel֮ɵʱļԹ
		if ((int)(fileName.find("$")) != -1)
		{
			continue;
		}

		// excelļĬ
		auto strExt = fileName.substr(fileName.find_last_of('.') + 1, fileName.length() - fileName.find_last_of('.') - 1);
		if (strExt != "xlsx")
		{
			continue;
		}

		// IObject.xlsx
		auto strFileName = fileName.substr(fileName.find_last_of('/') + 1, fileName.find_last_of('.') - fileName.find_last_of('/') - 1);
		if (strFileName == "IObject")
		{
			continue;
		}

		// excelļתΪxml
		if (!CreateStructXML(fileName.c_str(), strFileName.c_str()))
		{
			std::cout << "Create " + fileName + " failed!" << std::endl;
			return;
		}

		tinyxml2::XMLElement* subClassElement = xmlDoc->NewElement("Class");
		classElement->LinkEndChild(subClassElement);

		subClassElement->SetAttribute("Id", strFileName.c_str());
		std::string strUpFileName = strFileName;
		transform(strUpFileName.begin(), strUpFileName.end(), strUpFileName.begin(), ::toupper);
		subClassElement->SetAttribute("Type", ("TYPE_" + strUpFileName).c_str());

		subClassElement->SetAttribute("Path", (strExecutePath + strXMLStructPath + strFileName + ".xml").c_str());
		subClassElement->SetAttribute("InstancePath", (strExecutePath + strXMLIniPath + strFileName + ".xml").c_str());

		subClassElement->SetAttribute("Public", "0");
		subClassElement->SetAttribute("Desc", strFileName.c_str());
	}

	//// nameļ

	fwrite("} // !@NFrame\n\n#endif // !NF_PR_NAME_HPP",
		sizeof("} // !@NFrame\n\n#endif // !NF_PR_NAME_HPP"), 1, hppWriter);
	fwrite("}",
		sizeof("}"), 1, csWriter);
	xmlDoc->SetBOM(false);
	auto a = xmlDoc->SaveFile(strLogicClassFile.c_str());//ļ ·

	//xmlDoc->Print();//ӡ
	delete xmlDoc;
}

void FileProcess::CreateIniThreadFunc()
{
	// Iniļµexcelļ
	auto fileList = GetFileListInFolder(strToolBasePath + strExcelIniPath, 0);
	for (auto fileName : fileList)
	{
		StringReplace(fileName, "\\", "/");
		StringReplace(fileName, "//", "/");

		int nLastPoint = fileName.find_last_of(".") + 1;
		int nLastSlash = fileName.find_last_of("/") + 1;
		std::string strFileName = fileName.substr(nLastSlash, nLastPoint - nLastSlash - 1);
		std::string strFileExt = fileName.substr(nLastPoint, fileName.length() - nLastPoint);

		// excel֮ɵʱļԹ
		if ((int)(fileName.find("$")) != -1)
		{
			continue;
		}

		// excelļĬ
		auto strExt = fileName.substr(fileName.find_last_of('.') + 1, fileName.length() - fileName.find_last_of('.') - 1);
		if (strExt != "xlsx")
		{
			continue;
		}

		// IObject.xlsx
		if (strFileName == "IObject")
		{
			continue;
		}

		if (!CreateIniXML(fileName))
		{
			std::cout << "Create " + fileName + " failed!" << std::endl;
		}
	}
}

bool FileProcess::CreateStructXML(std::string strFile, std::string strFileName)
{
	std::cout << strFile << std::endl;<commit_msg>Update NFFileProcess<commit_after>#include "FileProcess.h"
#include <memory>

FileProcess::FileProcess()
{
	strLogicClassFile = "../Struct/LogicClass.xml";
	mysqlWriter = fopen(strMySQLFile.c_str(), "w");
	mysqlClassWriter = fopen(strMySQLClassFile.c_str(), "w");
	protoWriter = fopen(strProtoFile.c_str(), "w");
	hppWriter = fopen(strHPPFile.c_str(), "w");
	javaWriter = fopen(strJavaFile.c_str(), "w");
	csWriter = fopen(strCSFile.c_str(), "w");
}

FileProcess::~FileProcess()
{
	fclose(mysqlWriter);
	fclose(mysqlClassWriter);
	fclose(protoWriter);
	fclose(hppWriter);
	fclose(javaWriter);
	fclose(csWriter);
}

void FileProcess::CreateProtoFile()
{
	std::string toWrite = "package NFrame;\n";
	if ((protoWriter) == NULL)
		return;
	fwrite(toWrite.c_str(), toWrite.length(), 1, protoWriter);
}

void FileProcess::CreateNameFile()
{
	time_t timeval;
	timeval = time(NULL);
	auto strNow = ctime(&timeval);
	std::string strHPPHead
		= "// -------------------------------------------------------------------------\n";
	strHPPHead = strHPPHead
		+ "//    @FileName         :    NFProtocolDefine.hpp\n"
		+ "//    @Author           :    NFrame Studio\n"
		+ "//    @Date             :    " + strNow
		+ "//    @Module           :    NFProtocolDefine\n"
		+ "// -------------------------------------------------------------------------\n\n"
		+ "#ifndef NF_PR_NAME_HPP\n"
		+ "#define NF_PR_NAME_HPP\n\n"
		+ "#include <string>\n"
		+ "namespace NFrame\n{\n";

	/////////////////////////////////////////////////////
	fwrite(strHPPHead.c_str(), strHPPHead.length(), 1, hppWriter);
	/////////////////////////////////////////////////////

	std::string strJavaHead
		= "// -------------------------------------------------------------------------\n";
	strJavaHead = strJavaHead
		+ "//    @FileName         :    NFProtocolDefine.java\n"
		+ "//    @Author           :    NFrame Studio\n"
		+ "//    @Date             :    " + strNow
		+ "//    @Module           :    NFProtocolDefine\n"
		+ "// -------------------------------------------------------------------------\n\n"
		+ "package nframe;\n";

	fwrite(strJavaHead.c_str(), strJavaHead.length(), 1, javaWriter);
	/////////////////////////////////////////////////////

	std::string strCSHead = "// -------------------------------------------------------------------------\n";
	strCSHead = strCSHead
		+ "//    @FileName         :    NFProtocolDefine.cs\n"
		+ "//    @Author           :    NFrame Studio\n"
		+ "//    @Date             :    " + strNow
		+ "//    @Module           :    NFProtocolDefine\n"
		+ "// -------------------------------------------------------------------------\n\n"
		+ "using System;\n"
		//+ "using System.Collections.Concurrent;\n"
		+ "using System.Collections.Generic;\n"
		+ "using System.Linq;\n"
		+ "using System.Text;\n"
		+ "using System.Threading;\n"
		//+ "using System.Threading.Tasks;\n\n"
		+ "namespace NFrame\n{\n";

	fwrite(strCSHead.c_str(), strCSHead.length(), 1, csWriter);
	/////////////////////////////////////////////////////
}

void FileProcess::OnCreateXMLFile()
{
	//////////////////////////////////////////////////////////////////////
	CreateStructThreadFunc();
	CreateIniThreadFunc();
}

void FileProcess::CreateStructThreadFunc()
{
	// protoļ
	CreateProtoFile();

	// PropertyRecordhppͷļ
	CreateNameFile();


	//xmlĵ
	tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
	if (NULL == xmlDoc)
	{
		return;
	}

	//xml
	tinyxml2::XMLDeclaration *pDel = xmlDoc->NewDeclaration("xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"");
	if (NULL == pDel)
	{
		return;
	}

	xmlDoc->LinkEndChild(pDel);

	tinyxml2::XMLElement* root = xmlDoc->NewElement("XML");
	xmlDoc->LinkEndChild(root);

	tinyxml2::XMLElement* classElement = xmlDoc->NewElement("Class");
	root->LinkEndChild(classElement);
	////////////////////////////////////////////////////////////////////////
	classElement->SetAttribute("Id", "IObject");
	classElement->SetAttribute("Type", "TYPE_IOBJECT");

	classElement->SetAttribute("Path", (strExecutePath + "Struct/Class/IObject.xml").c_str());
	classElement->SetAttribute("InstancePath", (strExecutePath + "Ini/NPC/IObject.xml").c_str());

	classElement->SetAttribute("Public", "0");
	classElement->SetAttribute("Desc", "IObject");
	////////////////////////////////////////////////////////////////////////
	//// ǰIObjectһ
	CreateStructXML("../Excel_Struct/IObject.xlsx", "IObject");

	// Structļµexcelļ
	auto fileList = GetFileListInFolder(strToolBasePath + strExcelStructPath, 0);

	for (auto fileName : fileList)
	{
		StringReplace(fileName, "\\", "/");
		StringReplace(fileName, "//", "/");
		// excel֮ɵʱļԹ
		if ((int)(fileName.find("$")) != -1)
		{
			continue;
		}

		// excelļĬ
		auto strExt = fileName.substr(fileName.find_last_of('.') + 1, fileName.length() - fileName.find_last_of('.') - 1);
		if (strExt != "xlsx")
		{
			continue;
		}

		// IObject.xlsx
		auto strFileName = fileName.substr(fileName.find_last_of('/') + 1, fileName.find_last_of('.') - fileName.find_last_of('/') - 1);
		if (strFileName == "IObject")
		{
			continue;
		}

		// excelļתΪxml
		if (!CreateStructXML(fileName.c_str(), strFileName.c_str()))
		{
			std::cout << "Create " + fileName + " failed!" << std::endl;
			return;
		}

		tinyxml2::XMLElement* subClassElement = xmlDoc->NewElement("Class");
		classElement->LinkEndChild(subClassElement);

		subClassElement->SetAttribute("Id", strFileName.c_str());
		std::string strUpFileName = strFileName;
		transform(strUpFileName.begin(), strUpFileName.end(), strUpFileName.begin(), ::toupper);
		subClassElement->SetAttribute("Type", ("TYPE_" + strUpFileName).c_str());

		subClassElement->SetAttribute("Path", (strExecutePath + strXMLStructPath + strFileName + ".xml").c_str());
		subClassElement->SetAttribute("InstancePath", (strExecutePath + strXMLIniPath + strFileName + ".xml").c_str());

		subClassElement->SetAttribute("Public", "0");
		subClassElement->SetAttribute("Desc", strFileName.c_str());
	}

	//// nameļ

	fwrite("} // !@NFrame\n\n#endif // !NF_PR_NAME_HPP",
		sizeof("} // !@NFrame\n\n#endif // !NF_PR_NAME_HPP"), 1, hppWriter);
	fwrite("}",
		sizeof("}"), 1, csWriter);
	xmlDoc->SetBOM(false);
	auto a = xmlDoc->SaveFile(strLogicClassFile.c_str());//ļ ·

	//xmlDoc->Print();//ӡ
	delete xmlDoc;
}

void FileProcess::CreateIniThreadFunc()
{
	// Iniļµexcelļ
	auto fileList = GetFileListInFolder(strToolBasePath + strExcelIniPath, 0);
	for (auto fileName : fileList)
	{
		StringReplace(fileName, "\\", "/");
		StringReplace(fileName, "//", "/");

		int nLastPoint = fileName.find_last_of(".") + 1;
		int nLastSlash = fileName.find_last_of("/") + 1;
		std::string strFileName = fileName.substr(nLastSlash, nLastPoint - nLastSlash - 1);
		std::string strFileExt = fileName.substr(nLastPoint, fileName.length() - nLastPoint);

		// excel֮ɵʱļԹ
		if ((int)(fileName.find("$")) != -1)
		{
			continue;
		}

		// excelļĬ
		auto strExt = fileName.substr(fileName.find_last_of('.') + 1, fileName.length() - fileName.find_last_of('.') - 1);
		if (strExt != "xlsx")
		{
			continue;
		}

		if (!CreateIniXML(fileName))
		{
			std::cout << "Create " + fileName + " failed!" << std::endl;
		}
	}
}

bool FileProcess::CreateStructXML(std::string strFile, std::string strFileName)
{
	std::cout << strFile << std::endl;
{'fraction_non_alphanumeric': 0.28258638385220664, 'fraction_numerical': 0.004105371193978789, 'mean_word_length': 2.2933753943217665, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 2, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 54}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3088539', 'n_tokens_mistral': 5046, 'n_tokens_neox': 4783, 'n_words': 727}