📄 anifile.cpp
字号:
unsigned long uAniAmount;
fread(&uAniAmount, sizeof(DWORD), 1, fp);
// read Ani Info...
for(i = 0; i < uAniAmount; i ++)
{
// frame amount ...
unsigned char ucFrameAmount;
fread(&ucFrameAmount, sizeof(unsigned char), 1, fp);
int nIndexLength = strlen(m_infoIndex.szFile);
strupr(m_infoIndex.szFile);
ucFrameAmount = ucFrameAmount^m_infoIndex.szFile[i%nIndexLength];
// new buffer ...
DaiInfo* pAniInfo = new DaiInfo;
if(!pAniInfo)
{
fclose(fp);
this->Clear();
return IDai::CODE_INTERIOR_ERROR;
}
pAniInfo->pFrameInfo = NULL;
pAniInfo->pFrameInfo = new DaiFrameInfo[ucFrameAmount];
if(!pAniInfo->pFrameInfo)
{
fclose(fp);
this->Clear();
return IDai::CODE_INTERIOR_ERROR;
}
unsigned short usIndexNameIndex;
char cIndexNameAdjust1;
char cIndexNameAdjust2;
fread(&usIndexNameIndex, sizeof(unsigned short), 1, fp);
fread(&cIndexNameAdjust1, sizeof(char), 1, fp);
fread(&cIndexNameAdjust2, sizeof(char), 1, fp);
// assign DAI member info ...
pAniInfo->usIndexNameIndex = usIndexNameIndex;
pAniInfo->cIndexNameAdjust1 = cIndexNameAdjust1;
pAniInfo->cIndexNameAdjust2 = cIndexNameAdjust2;
pAniInfo->ucFrameAmount = ucFrameAmount;
// generate id
char szStr[256];
unsigned long uCode = this->UnZipStr(m_pDaiFile->setStr, szStr, 256, pAniInfo->usIndexNameIndex,
pAniInfo->cIndexNameAdjust1, pAniInfo->cIndexNameAdjust2);
if(uCode != IDai::SUCCESS)
{
fclose(fp);
this->Clear();
return uCode;
}
unsigned long uId = this->Str2Id(szStr);
m_pDaiFile->setDaiInfo[uId]=pAniInfo;
fread(pAniInfo->pFrameInfo, sizeof(DaiFrameInfo), ucFrameAmount, fp);
}
fclose(fp);
return IDai::SUCCESS;
}
//--------------------------------------------------------------------------------------
unsigned long CAniFile::UnLoad()
{
this->Clear();
return IDai::SUCCESS;
}
//--------------------------------------------------------------------------------------
unsigned long CAniFile::LoadAniByOrder(const char* pszFile)
{
this->Clear();
if(!pszFile)
return IDai::CODE_EXTERIOR_ERROR;
FILE* fp = fopen(pszFile, "r");
if(!fp)
return IDai::CODE_OPENFILE_FALSE;
// create buffer to hold ani info
m_pAniFileByOrder = new AniFileInfoByOrder;
if(!m_pAniFileByOrder)
return IDai::CODE_INTERIOR_ERROR;
int nLineCounter = 0;
while(true)
{
// scan title
static char szLine[1024] = "";
if(EOF == fscanf(fp, "%s\n", szLine))
{
fclose(fp);
return IDai::SUCCESS;
}
// inc the line counter ...
nLineCounter ++;
// check whether current line is title, if title assay else skip ...
static char szTitle[MAX_PATH] = "";
if (1 != sscanf(szLine, "[%s", szTitle))
continue;
char* p =strchr(szTitle, ']');
if (p)
{
*p = '\0';
}
else
{
fclose(fp);
this->Clear();
m_uLastErrorLine = nLineCounter;
return IDai::CODE_TITLEFORMAT_ERROE;
}
// get frame amount now
int nFrameAmount = 0;
if (1 != fscanf(fp, "FrameAmount=%d\n", &nFrameAmount))
{
fclose(fp);
this->Clear();
m_uLastErrorLine = nLineCounter;
return IDai::CODE_FRAMEAMOUNT_ERROR;
}
if(nFrameAmount > MAX_ANIFRAMEAMOUNT && nFrameAmount < 0)
{
fclose(fp);
this->Clear();
m_uLastErrorLine = nLineCounter;
return IDai::CODE_FRAMEAMOUNT_OVERFLOW;
}
// create new ani buffer to hold the frames ...
AniInfoByOrder* pFrameInfo = new AniInfoByOrder;
if(!pFrameInfo)
{
fclose(fp);
this->Clear();
m_uLastErrorLine = nLineCounter;
return IDai::CODE_INTERIOR_ERROR;
}
pFrameInfo->pszIndex = new char[strlen(szTitle)+1];
strcpy(pFrameInfo->pszIndex, szTitle);
m_pAniFileByOrder->setAniInfo.push_back(pFrameInfo);
// get frame now
for(int i = 0; i < nFrameAmount; i ++)
{
static char szFormat[MAX_PATH] = "";
sprintf(szFormat, "Frame%d=%s\n", i, "%s");
char szFile[MAX_PATH] = "";
if (1 != fscanf(fp, szFormat, szFile))
{
fclose(fp);
this->Clear();
m_uLastErrorLine = nLineCounter;
return IDai::CODE_FRAMEINFO_ERROR;
}
char* pszFile = new char[strlen(szFile)+1];
if(!pszFile)
{
fclose(fp);
this->Clear();
m_uLastErrorLine = nLineCounter;
return IDai::CODE_INTERIOR_ERROR;
}
strcpy(pszFile, szFile);
pFrameInfo->setFrame.push_back(pszFile);
}
}
fclose(fp);
return IDai::SUCCESS;
}
//--------------------------------------------------------------------------------------
unsigned long CAniFile::LoadDaiByOrder(const char* pszFile)
{
this->Clear();
if(!pszFile)
return IDai::CODE_EXTERIOR_ERROR;
FILE* fp = fopen(pszFile, "rb");
if(!fp)
return IDai::CODE_OPENFILE_FALSE;
m_pDaiFileByOrder = new DaiFileInfoByOrder;
if(!m_pDaiFileByOrder)
return IDai::CODE_INTERIOR_ERROR;
char szTitle[8];
DWORD dwVersion;
fread(szTitle, sizeof(char), 8, fp);
if(strcmp(szTitle, "ND_DAI") != 0)
return IDai::CODE_UNKNOW_FILEHEAD;
fread(&dwVersion, sizeof(DWORD), 1, fp);
if(dwVersion != 1000)
return IDai::CODE_UNKNOW_VERSION;
// read path ...
int i;
unsigned short usPathAmount;
fread(&usPathAmount, sizeof(unsigned short), 1, fp);
for(i = 0; i < usPathAmount; i ++)
{
unsigned short usLength;
fread(&usLength, sizeof(unsigned short), 1, fp);
char* pszStr = new char[usLength];
if(!pszStr)
{
fclose(fp);
this->Clear();
return IDai::CODE_INTERIOR_ERROR;
}
fread(pszStr, sizeof(char), usLength, fp);
m_pDaiFileByOrder->setDir.push_back(pszStr);
}
// read Ext ...
unsigned char ucExtAmount;
fread(&ucExtAmount, sizeof(unsigned char), 1, fp);
for(i = 0; i < ucExtAmount; i ++)
{
unsigned short usLength;
fread(&usLength, sizeof(unsigned short), 1, fp);
char* pszStr = new char[usLength];
if(!pszStr)
{
fclose(fp);
this->Clear();
return IDai::CODE_INTERIOR_ERROR;
}
fread(pszStr, sizeof(char), usLength, fp);
m_pDaiFileByOrder->setExt.push_back(pszStr);
}
// read Str ...
unsigned short usStrAmount;
fread(&usStrAmount, sizeof(unsigned short), 1, fp);
for(i = 0; i < usStrAmount; i ++)
{
unsigned short usLength;
fread(&usLength, sizeof(unsigned short), 1, fp);
char* pszStr = new char[usLength];
if(!pszStr)
{
fclose(fp);
this->Clear();
return IDai::CODE_INTERIOR_ERROR;
}
fread(pszStr, sizeof(char), usLength, fp);
m_pDaiFileByOrder->setStr.push_back(pszStr);
}
// read Ani Amount ...
unsigned long uAniAmount;
fread(&uAniAmount, sizeof(DWORD), 1, fp);
// read Ani Info...
// assay file name ...
static char szDir[_MAX_DIR] = "";
static char szDrive[_MAX_PATH] = "";
static char szFileName[_MAX_FNAME] = "";
static char szExt[_MAX_EXT] = "";
_splitpath(pszFile, szDrive, szDir, szFileName, szExt);
strcpy(m_infoIndex.szFile, szFileName);
strupr(m_infoIndex.szFile);
strcpy(m_infoIndex.szPath, szDir);
strupr(m_infoIndex.szPath);
for(i = 0; i < uAniAmount; i ++)
{
// frame amount ...
unsigned char ucFrameAmount;
fread(&ucFrameAmount, sizeof(unsigned char), 1, fp);
int nIndexLength = strlen(m_infoIndex.szFile);
ucFrameAmount = ucFrameAmount^m_infoIndex.szFile[i%nIndexLength];
// new buffer ...
DaiInfo* pAniInfo = new DaiInfo;
if(!pAniInfo)
{
fclose(fp);
this->Clear();
return IDai::CODE_INTERIOR_ERROR;
}
pAniInfo->pFrameInfo = NULL;
pAniInfo->pFrameInfo = new DaiFrameInfo[ucFrameAmount];
if(!pAniInfo->pFrameInfo)
{
fclose(fp);
this->Clear();
return IDai::CODE_INTERIOR_ERROR;
}
unsigned short usIndexNameIndex;
char cIndexNameAdjust1;
char cIndexNameAdjust2;
fread(&usIndexNameIndex, sizeof(unsigned short), 1, fp);
fread(&cIndexNameAdjust1, sizeof(char), 1, fp);
fread(&cIndexNameAdjust2, sizeof(char), 1, fp);
// assign DAI member info ...
pAniInfo->usIndexNameIndex = usIndexNameIndex;
pAniInfo->cIndexNameAdjust1 = cIndexNameAdjust1;
pAniInfo->cIndexNameAdjust2 = cIndexNameAdjust2;
pAniInfo->ucFrameAmount = ucFrameAmount;
// generate id
m_pDaiFileByOrder->setDaiInfo.push_back(pAniInfo);
fread(pAniInfo->pFrameInfo, sizeof(DaiFrameInfo), ucFrameAmount, fp);
}
fclose(fp);
return IDai::SUCCESS;
}
//--------------------------------------------------------------------------------------
unsigned long CAniFile::SaveDai2Ani(const char* pszFile)
{
if(!pszFile)
return IDai::CODE_EXTERIOR_ERROR;
if(!m_pDaiFileByOrder)
return IDai::CODE_INTERIOR_ERROR;
FILE* fp = fopen(pszFile, "wb");
if(!fp)
return IDai::CODE_OPENFILE_FALSE;
int nRecordAmount = m_pDaiFileByOrder->setDaiInfo.size();
for(int i = 0; i < nRecordAmount; i ++)
{
DaiInfo* pInfo = m_pDaiFileByOrder->setDaiInfo[i];
if(pInfo)
{
// generate index
int nStrAmount = m_pDaiFileByOrder->setStr.size();
if(pInfo->usIndexNameIndex >= nStrAmount && pInfo->usIndexNameIndex != 65535
&& pInfo->usIndexNameIndex != 65534)
{
fclose(fp);
this->Clear();
return IDai::CODE_ANIINDEX_OVERFLOW;
}
char szStr[_MAX_PATH];
this->UnZipStr(m_pDaiFileByOrder->setStr, szStr, _MAX_PATH, pInfo->usIndexNameIndex,
pInfo->cIndexNameAdjust1, pInfo->cIndexNameAdjust2);
fprintf(fp, "[%s]\n", szStr);
// frame amount ...
fprintf(fp, "FrameAmount=%d\n", pInfo->ucFrameAmount);
// frame info ...
// generate frame string ...
if(!pInfo->pFrameInfo)
{
fclose(fp);
this->Clear();
return IDai::CODE_INTERIOR_ERROR;
}
for(int j = 0; j < pInfo->ucFrameAmount; j ++)
{
DaiFrameInfo* pFrameInfo = pInfo->pFrameInfo+j;
//static char szFrame[512];
int nDirAmount = m_pDaiFileByOrder->setDir.size();
if(pFrameInfo->usPath >= nDirAmount)
{
fclose(fp);
this->Clear();
return IDai::CODE_DIRINDEX_OVERFLOW;
}
int nExtAmount = m_pDaiFileByOrder->setExt.size();
if(pFrameInfo->ucExtendName >= nExtAmount)
{
fclose(fp);
this->Clear();
return IDai::CODE_EXTINDEX_OVERFLOW;
}
int nStrAmount = m_pDaiFileByOrder->setStr.size();
if(pFrameInfo->usFileNameIndex >= nStrAmount && pFrameInfo->usFileNameIndex != 65535 && pFrameInfo->usFileNameIndex != 65534)
{
fclose(fp);
this->Clear();
return IDai::CODE_STRINDEX_OVERFLOW;
}
static char szFrameInfo[512];
unsigned long uCode = this->UnZipFrame(m_pDaiFileByOrder->setStr, m_pDaiFileByOrder->setExt,
m_pDaiFileByOrder->setDir, szFrameInfo, 512, pFrameInfo->usPath, pFrameInfo->ucExtendName,
pFrameInfo->usFileNameIndex, pFrameInfo->cFileNameAdjust1, pFrameInfo->cFileNameAdjust2);
if(uCode != IDai::SUCCESS)
{
this->Clear();
fclose(fp);
return uCode;
}
fprintf(fp, "Frame%d=%s\n", j, szFrameInfo);
}
fprintf(fp, "\n");
}
else
{
fclose(fp);
this->Clear();
return IDai::CODE_INTERIOR_ERROR;
}
}
fclose(fp);
return IDai::SUCCESS;
}
//--------------------------------------------------------------------------------------
unsigned long CAniFile::SaveAni2Dai(const char* pszFile)
{
// clear first ...
if(!pszFile)
return IDai::CODE_EXTERIOR_ERROR;
if(!m_pAniFileByOrder)
return IDai::CODE_INTERIOR_ERROR;
if(m_pDaiFileByOrder)
{
int nAmount = m_pDaiFileByOrder->setDaiInfo.size();
for(int j = 0; j < nAmount; j ++)
{
DaiInfo* pDaiInfo = m_pDaiFileByOrder->setDaiInfo[j];
if(pDaiInfo)
{
if(pDaiInfo->pFrameInfo)
delete[] pDaiInfo->pFrameInfo;
delete pDaiInfo;
pDaiInfo = NULL;
}
}
m_pDaiFileByOrder->setDaiInfo.clear();
int nDirAmount = m_pDaiFileByOrder->setDir.size();
int i;
for(i= 0; i < nDirAmount; i ++)
{
char* pszStr = m_pDaiFileByOrder->setDir[i];
if(pszStr)
delete[] pszStr;
}
m_pDaiFileByOrder->setDir.clear();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -