1 #include "NoWindows.h"
2
3 #include "All.h"
4 #include "APELink.h"
5 #include "CharacterHelper.h"
6 #include IO_HEADER_FILE
7
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="
12
CAPELink(const str_utf16 * pFilename)13 CAPELink::CAPELink(const str_utf16 * pFilename)
14 {
15 // empty
16 m_bIsLinkFile = FALSE;
17 m_nStartBlock = 0;
18 m_nFinishBlock = 0;
19 m_cImageFilename[0] = 0;
20
21 // open the file
22 IO_CLASS_NAME ioLinkFile;
23 if (ioLinkFile.Open(pFilename) == ERROR_SUCCESS)
24 {
25 // create a buffer
26 CSmartPtr<char> spBuffer(new char [1024], TRUE);
27
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;
32
33 // call the other constructor (uses a buffer instead of opening the file)
34 ParseData(spBuffer, pFilename);
35 }
36 }
37
CAPELink(const char * pData,const str_utf16 * pFilename)38 CAPELink::CAPELink(const char * pData, const str_utf16 * pFilename)
39 {
40 ParseData(pData, pFilename);
41 }
42
~CAPELink()43 CAPELink::~CAPELink()
44 {
45 }
46
ParseData(const char * pData,const str_utf16 * pFilename)47 void CAPELink::ParseData(const char * pData, const str_utf16 * pFilename)
48 {
49 // empty
50 m_bIsLinkFile = FALSE;
51 m_nStartBlock = 0;
52 m_nFinishBlock = 0;
53 m_cImageFilename[0] = 0;
54
55 if (pData != NULL)
56 {
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);
62
63 if (pHeader && pImageFile && pStartBlock && pFinishBlock)
64 {
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))
69 {
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)]);
73
74 // get the path
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;
80
81 CSmartPtr<str_utf16> spImageFileUTF16(GetUTF16FromUTF8((UCHAR *) cImageFile), TRUE);
82
83 // process the path
84 // SHINTA: w_char -> char -->
85 if (strrchr(spImageFileUTF16, '\\') == NULL)
86 {
87 str_utf16 cImagePath[MAX_PATH + 1];
88 strcpy(cImagePath, pFilename);
89 strcpy(strrchr(cImagePath, '\\') + 1, spImageFileUTF16);
90 strcpy(m_cImageFilename, cImagePath);
91 }
92 else
93 {
94 strcpy(m_cImageFilename, spImageFileUTF16);
95 }
96 // <-- SHINTA
97
98 // this is a valid link file
99 m_bIsLinkFile = TRUE;
100 }
101 }
102 }
103 }
104
GetStartBlock()105 int CAPELink::GetStartBlock()
106 {
107 return m_nStartBlock;
108 }
109
GetFinishBlock()110 int CAPELink::GetFinishBlock()
111 {
112 return m_nFinishBlock;
113 }
114
GetImageFilename()115 const str_utf16 * CAPELink::GetImageFilename()
116 {
117 return m_cImageFilename;
118 }
119
GetIsLinkFile()120 BOOL CAPELink::GetIsLinkFile()
121 {
122 return m_bIsLinkFile;
123 }
124
125