5 #include "CharacterHelper.h"
6 #include IO_HEADER_FILE
8 #define APE_LINK_HEADER "[Monkey's Audio Image Link File]"
9 #define APE_LINK_IMAGE_FILE_TAG "Image File="
10 #define APE_LINK_START_BLOCK_TAG "Start Block="
11 #define APE_LINK_FINISH_BLOCK_TAG "Finish Block="
13 CAPELink::CAPELink(const str_utf16
* pFilename
)
16 m_bIsLinkFile
= FALSE
;
19 m_cImageFilename
[0] = 0;
22 IO_CLASS_NAME ioLinkFile
;
23 if (ioLinkFile
.Open(pFilename
) == ERROR_SUCCESS
)
26 CSmartPtr
<char> spBuffer(new char [1024], TRUE
);
28 // fill the buffer from the file and null terminate it
29 unsigned int nBytesRead
= 0;
30 ioLinkFile
.Read(spBuffer
.GetPtr(), 1023, &nBytesRead
);
31 spBuffer
[nBytesRead
] = 0;
33 // call the other constructor (uses a buffer instead of opening the file)
34 ParseData(spBuffer
, pFilename
);
38 CAPELink::CAPELink(const char * pData
, const str_utf16
* pFilename
)
40 ParseData(pData
, pFilename
);
47 void CAPELink::ParseData(const char * pData
, const str_utf16
* pFilename
)
50 m_bIsLinkFile
= FALSE
;
53 m_cImageFilename
[0] = 0;
57 // parse out the information
58 char * pHeader
= strstr(pData
, APE_LINK_HEADER
);
59 char * pImageFile
= strstr(pData
, APE_LINK_IMAGE_FILE_TAG
);
60 char * pStartBlock
= strstr(pData
, APE_LINK_START_BLOCK_TAG
);
61 char * pFinishBlock
= strstr(pData
, APE_LINK_FINISH_BLOCK_TAG
);
63 if (pHeader
&& pImageFile
&& pStartBlock
&& pFinishBlock
)
65 if ((_strnicmp(pHeader
, APE_LINK_HEADER
, strlen(APE_LINK_HEADER
)) == 0) &&
66 (_strnicmp(pImageFile
, APE_LINK_IMAGE_FILE_TAG
, strlen(APE_LINK_IMAGE_FILE_TAG
)) == 0) &&
67 (_strnicmp(pStartBlock
, APE_LINK_START_BLOCK_TAG
, strlen(APE_LINK_START_BLOCK_TAG
)) == 0) &&
68 (_strnicmp(pFinishBlock
, APE_LINK_FINISH_BLOCK_TAG
, strlen(APE_LINK_FINISH_BLOCK_TAG
)) == 0))
70 // get the start and finish blocks
71 m_nStartBlock
= atoi(&pStartBlock
[strlen(APE_LINK_START_BLOCK_TAG
)]);
72 m_nFinishBlock
= atoi(&pFinishBlock
[strlen(APE_LINK_FINISH_BLOCK_TAG
)]);
75 char cImageFile
[MAX_PATH
+ 1]; int nIndex
= 0;
76 char * pImageCharacter
= &pImageFile
[strlen(APE_LINK_IMAGE_FILE_TAG
)];
77 while ((*pImageCharacter
!= 0) && (*pImageCharacter
!= '\r') && (*pImageCharacter
!= '\n'))
78 cImageFile
[nIndex
++] = *pImageCharacter
++;
79 cImageFile
[nIndex
] = 0;
81 CSmartPtr
<str_utf16
> spImageFileUTF16(GetUTF16FromUTF8((UCHAR
*) cImageFile
), TRUE
);
84 // SHINTA: w_char -> char -->
85 if (strrchr(spImageFileUTF16
, '\\') == NULL
)
87 str_utf16 cImagePath
[MAX_PATH
+ 1];
88 strcpy(cImagePath
, pFilename
);
89 strcpy(strrchr(cImagePath
, '\\') + 1, spImageFileUTF16
);
90 strcpy(m_cImageFilename
, cImagePath
);
94 strcpy(m_cImageFilename
, spImageFileUTF16
);
98 // this is a valid link file
105 int CAPELink::GetStartBlock()
107 return m_nStartBlock
;
110 int CAPELink::GetFinishBlock()
112 return m_nFinishBlock
;
115 const str_utf16
* CAPELink::GetImageFilename()
117 return m_cImageFilename
;
120 BOOL
CAPELink::GetIsLinkFile()
122 return m_bIsLinkFile
;