163 lines
5.0 KiB
C++
163 lines
5.0 KiB
C++
#include "XNModelGenServer.h"
|
|
#include "XNModelGen.h"
|
|
#include "XNCodeZip.h"
|
|
#include "XNModelCompile.h"
|
|
#include <cstring>
|
|
|
|
int XNModelCodeGen(const char *className, int classNameLen, const char *version, int versionLen,
|
|
const char *planeName, int planeNameLen, char *errorMsg, int errorMsgLen)
|
|
{
|
|
std::string classNameStr(className, classNameLen);
|
|
std::string versionStr(version, versionLen);
|
|
std::string planeNameStr(planeName, planeNameLen);
|
|
if (classNameStr.empty() || versionStr.empty() || planeNameStr.empty()) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, "className, version or planeName is empty", errorMsgLen);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
std::string errorMsgStr;
|
|
XNModelGen modelGen;
|
|
int ret = modelGen.Initialize(classNameStr, versionStr, planeNameStr, errorMsgStr);
|
|
if (ret != 0) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return ret;
|
|
}
|
|
ret = modelGen.GenerateCode(errorMsgStr);
|
|
if (ret != 0) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return ret;
|
|
}
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int XNModelCodeZip(const char *className, int classNameLen, const char *version, int versionLen,
|
|
const char *planeName, int planeNameLen, char *dstPath, int dstPathLen,
|
|
char *errorMsg, int errorMsgLen)
|
|
{
|
|
std::string classNameStr(className, classNameLen);
|
|
std::string versionStr(version, versionLen);
|
|
std::string planeNameStr(planeName, planeNameLen);
|
|
if (classNameStr.empty() || versionStr.empty() || planeNameStr.empty()) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, "className, version or planeName is empty", errorMsgLen);
|
|
}
|
|
return -1;
|
|
}
|
|
XNModelGen modelGen;
|
|
std::string errorMsgStr;
|
|
int ret = modelGen.Initialize(classNameStr, versionStr, planeNameStr, errorMsgStr);
|
|
if (ret != 0) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return ret;
|
|
}
|
|
std::string srcPath = modelGen.GetCodePath();
|
|
std::string dstPathStr = srcPath;
|
|
size_t lastSlash = dstPathStr.find_last_of("/\\");
|
|
if (lastSlash != std::string::npos) {
|
|
dstPathStr = dstPathStr.substr(0, lastSlash);
|
|
std::string dirName = srcPath.substr(lastSlash + 1);
|
|
dstPathStr += "/" + dirName + ".zip";
|
|
} else {
|
|
dstPathStr += ".zip";
|
|
}
|
|
ret = XNCodeZip::Zip(srcPath, dstPathStr, errorMsgStr);
|
|
if (ret != 0) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
// 将生成的zip文件路径复制到输出参数
|
|
if (dstPath != nullptr) {
|
|
strncpy(dstPath, dstPathStr.c_str(), dstPathLen);
|
|
}
|
|
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int XNModelCodeUnzip(const char *className, int classNameLen, const char *version, int versionLen,
|
|
const char *planeName, int planeNameLen, const char *srcPath, int srcPathLen,
|
|
char *errorMsg, int errorMsgLen)
|
|
{
|
|
std::string classNameStr(className, classNameLen);
|
|
std::string versionStr(version, versionLen);
|
|
std::string planeNameStr(planeName, planeNameLen);
|
|
if (classNameStr.empty() || versionStr.empty() || planeNameStr.empty()) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, "className, version or planeName is empty", errorMsgLen);
|
|
}
|
|
return -1;
|
|
}
|
|
XNModelGen modelGen;
|
|
std::string errorMsgStr;
|
|
int ret = modelGen.Initialize(classNameStr, versionStr, planeNameStr, errorMsgStr);
|
|
if (ret != 0) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return ret;
|
|
}
|
|
std::string srcPathStr(srcPath, srcPathLen);
|
|
std::string dstPathStr = modelGen.GetCodePath();
|
|
ret = XNCodeZip::Unzip(srcPathStr, dstPathStr, errorMsgStr);
|
|
if (ret != 0) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return ret;
|
|
}
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int XNModelCodeCompile(const char *className, int classNameLen, const char *version, int versionLen,
|
|
const char *planeName, int planeNameLen, char *errorMsg, int errorMsgLen)
|
|
{
|
|
std::string classNameStr(className, classNameLen);
|
|
std::string versionStr(version, versionLen);
|
|
std::string planeNameStr(planeName, planeNameLen);
|
|
if (classNameStr.empty() || versionStr.empty() || planeNameStr.empty()) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, "className, version or planeName is empty", errorMsgLen);
|
|
}
|
|
return -1;
|
|
}
|
|
XNModelGen modelGen;
|
|
std::string errorMsgStr;
|
|
int ret = modelGen.Initialize(classNameStr, versionStr, planeNameStr, errorMsgStr);
|
|
if (ret != 0) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return ret;
|
|
}
|
|
std::string srcPath = modelGen.GetCodePath();
|
|
ret = XNModelCompile::Compile(srcPath, errorMsgStr);
|
|
if (ret != 0) {
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return ret;
|
|
}
|
|
if (errorMsg != nullptr) {
|
|
strncpy(errorMsg, errorMsgStr.c_str(), errorMsgLen);
|
|
}
|
|
return 0;
|
|
} |