1*b51fbe43SDavid McPaul #include "NoWindows.h"
2*b51fbe43SDavid McPaul
3*b51fbe43SDavid McPaul #include "All.h"
4*b51fbe43SDavid McPaul #include "APELink.h"
5*b51fbe43SDavid McPaul #include "CharacterHelper.h"
6*b51fbe43SDavid McPaul #include IO_HEADER_FILE
7*b51fbe43SDavid McPaul
8*b51fbe43SDavid McPaul #define APE_LINK_HEADER "[Monkey's Audio Image Link File]"
9*b51fbe43SDavid McPaul #define APE_LINK_IMAGE_FILE_TAG "Image File="
10*b51fbe43SDavid McPaul #define APE_LINK_START_BLOCK_TAG "Start Block="
11*b51fbe43SDavid McPaul #define APE_LINK_FINISH_BLOCK_TAG "Finish Block="
12*b51fbe43SDavid McPaul
CAPELink(const str_utf16 * pFilename)13*b51fbe43SDavid McPaul CAPELink::CAPELink(const str_utf16 * pFilename)
14*b51fbe43SDavid McPaul {
15*b51fbe43SDavid McPaul // empty
16*b51fbe43SDavid McPaul m_bIsLinkFile = FALSE;
17*b51fbe43SDavid McPaul m_nStartBlock = 0;
18*b51fbe43SDavid McPaul m_nFinishBlock = 0;
19*b51fbe43SDavid McPaul m_cImageFilename[0] = 0;
20*b51fbe43SDavid McPaul
21*b51fbe43SDavid McPaul // open the file
22*b51fbe43SDavid McPaul IO_CLASS_NAME ioLinkFile;
23*b51fbe43SDavid McPaul if (ioLinkFile.Open(pFilename) == ERROR_SUCCESS)
24*b51fbe43SDavid McPaul {
25*b51fbe43SDavid McPaul // create a buffer
26*b51fbe43SDavid McPaul CSmartPtr<char> spBuffer(new char [1024], TRUE);
27*b51fbe43SDavid McPaul
28*b51fbe43SDavid McPaul // fill the buffer from the file and null terminate it
29*b51fbe43SDavid McPaul unsigned int nBytesRead = 0;
30*b51fbe43SDavid McPaul ioLinkFile.Read(spBuffer.GetPtr(), 1023, &nBytesRead);
31*b51fbe43SDavid McPaul spBuffer[nBytesRead] = 0;
32*b51fbe43SDavid McPaul
33*b51fbe43SDavid McPaul // call the other constructor (uses a buffer instead of opening the file)
34*b51fbe43SDavid McPaul ParseData(spBuffer, pFilename);
35*b51fbe43SDavid McPaul }
36*b51fbe43SDavid McPaul }
37*b51fbe43SDavid McPaul
CAPELink(const char * pData,const str_utf16 * pFilename)38*b51fbe43SDavid McPaul CAPELink::CAPELink(const char * pData, const str_utf16 * pFilename)
39*b51fbe43SDavid McPaul {
40*b51fbe43SDavid McPaul ParseData(pData, pFilename);
41*b51fbe43SDavid McPaul }
42*b51fbe43SDavid McPaul
~CAPELink()43*b51fbe43SDavid McPaul CAPELink::~CAPELink()
44*b51fbe43SDavid McPaul {
45*b51fbe43SDavid McPaul }
46*b51fbe43SDavid McPaul
ParseData(const char * pData,const str_utf16 * pFilename)47*b51fbe43SDavid McPaul void CAPELink::ParseData(const char * pData, const str_utf16 * pFilename)
48*b51fbe43SDavid McPaul {
49*b51fbe43SDavid McPaul // empty
50*b51fbe43SDavid McPaul m_bIsLinkFile = FALSE;
51*b51fbe43SDavid McPaul m_nStartBlock = 0;
52*b51fbe43SDavid McPaul m_nFinishBlock = 0;
53*b51fbe43SDavid McPaul m_cImageFilename[0] = 0;
54*b51fbe43SDavid McPaul
55*b51fbe43SDavid McPaul if (pData != NULL)
56*b51fbe43SDavid McPaul {
57*b51fbe43SDavid McPaul // parse out the information
58*b51fbe43SDavid McPaul char * pHeader = strstr(pData, APE_LINK_HEADER);
59*b51fbe43SDavid McPaul char * pImageFile = strstr(pData, APE_LINK_IMAGE_FILE_TAG);
60*b51fbe43SDavid McPaul char * pStartBlock = strstr(pData, APE_LINK_START_BLOCK_TAG);
61*b51fbe43SDavid McPaul char * pFinishBlock = strstr(pData, APE_LINK_FINISH_BLOCK_TAG);
62*b51fbe43SDavid McPaul
63*b51fbe43SDavid McPaul if (pHeader && pImageFile && pStartBlock && pFinishBlock)
64*b51fbe43SDavid McPaul {
65*b51fbe43SDavid McPaul if ((_strnicmp(pHeader, APE_LINK_HEADER, strlen(APE_LINK_HEADER)) == 0) &&
66*b51fbe43SDavid McPaul (_strnicmp(pImageFile, APE_LINK_IMAGE_FILE_TAG, strlen(APE_LINK_IMAGE_FILE_TAG)) == 0) &&
67*b51fbe43SDavid McPaul (_strnicmp(pStartBlock, APE_LINK_START_BLOCK_TAG, strlen(APE_LINK_START_BLOCK_TAG)) == 0) &&
68*b51fbe43SDavid McPaul (_strnicmp(pFinishBlock, APE_LINK_FINISH_BLOCK_TAG, strlen(APE_LINK_FINISH_BLOCK_TAG)) == 0))
69*b51fbe43SDavid McPaul {
70*b51fbe43SDavid McPaul // get the start and finish blocks
71*b51fbe43SDavid McPaul m_nStartBlock = atoi(&pStartBlock[strlen(APE_LINK_START_BLOCK_TAG)]);
72*b51fbe43SDavid McPaul m_nFinishBlock = atoi(&pFinishBlock[strlen(APE_LINK_FINISH_BLOCK_TAG)]);
73*b51fbe43SDavid McPaul
74*b51fbe43SDavid McPaul // get the path
75*b51fbe43SDavid McPaul char cImageFile[MAX_PATH + 1]; int nIndex = 0;
76*b51fbe43SDavid McPaul char * pImageCharacter = &pImageFile[strlen(APE_LINK_IMAGE_FILE_TAG)];
77*b51fbe43SDavid McPaul while ((*pImageCharacter != 0) && (*pImageCharacter != '\r') && (*pImageCharacter != '\n'))
78*b51fbe43SDavid McPaul cImageFile[nIndex++] = *pImageCharacter++;
79*b51fbe43SDavid McPaul cImageFile[nIndex] = 0;
80*b51fbe43SDavid McPaul
81*b51fbe43SDavid McPaul CSmartPtr<str_utf16> spImageFileUTF16(GetUTF16FromUTF8((UCHAR *) cImageFile), TRUE);
82*b51fbe43SDavid McPaul
83*b51fbe43SDavid McPaul // process the path
84*b51fbe43SDavid McPaul // SHINTA: w_char -> char -->
85*b51fbe43SDavid McPaul if (strrchr(spImageFileUTF16, '\\') == NULL)
86*b51fbe43SDavid McPaul {
87*b51fbe43SDavid McPaul str_utf16 cImagePath[MAX_PATH + 1];
88*b51fbe43SDavid McPaul strcpy(cImagePath, pFilename);
89*b51fbe43SDavid McPaul strcpy(strrchr(cImagePath, '\\') + 1, spImageFileUTF16);
90*b51fbe43SDavid McPaul strcpy(m_cImageFilename, cImagePath);
91*b51fbe43SDavid McPaul }
92*b51fbe43SDavid McPaul else
93*b51fbe43SDavid McPaul {
94*b51fbe43SDavid McPaul strcpy(m_cImageFilename, spImageFileUTF16);
95*b51fbe43SDavid McPaul }
96*b51fbe43SDavid McPaul // <-- SHINTA
97*b51fbe43SDavid McPaul
98*b51fbe43SDavid McPaul // this is a valid link file
99*b51fbe43SDavid McPaul m_bIsLinkFile = TRUE;
100*b51fbe43SDavid McPaul }
101*b51fbe43SDavid McPaul }
102*b51fbe43SDavid McPaul }
103*b51fbe43SDavid McPaul }
104*b51fbe43SDavid McPaul
GetStartBlock()105*b51fbe43SDavid McPaul int CAPELink::GetStartBlock()
106*b51fbe43SDavid McPaul {
107*b51fbe43SDavid McPaul return m_nStartBlock;
108*b51fbe43SDavid McPaul }
109*b51fbe43SDavid McPaul
GetFinishBlock()110*b51fbe43SDavid McPaul int CAPELink::GetFinishBlock()
111*b51fbe43SDavid McPaul {
112*b51fbe43SDavid McPaul return m_nFinishBlock;
113*b51fbe43SDavid McPaul }
114*b51fbe43SDavid McPaul
GetImageFilename()115*b51fbe43SDavid McPaul const str_utf16 * CAPELink::GetImageFilename()
116*b51fbe43SDavid McPaul {
117*b51fbe43SDavid McPaul return m_cImageFilename;
118*b51fbe43SDavid McPaul }
119*b51fbe43SDavid McPaul
GetIsLinkFile()120*b51fbe43SDavid McPaul BOOL CAPELink::GetIsLinkFile()
121*b51fbe43SDavid McPaul {
122*b51fbe43SDavid McPaul return m_bIsLinkFile;
123*b51fbe43SDavid McPaul }
124*b51fbe43SDavid McPaul
125