/
Iss.cpp
143 lines (113 loc) · 2.94 KB
/
Iss.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <Main.h>
Iss::Iss ()
{
opened=false;
}
Iss::~Iss ()
{
if ( opened == true )
{
free(m_record);
free(m_script);
free(raw);
}
}
bool Iss::Open(wxString file)
{
if ( wxFileName::FileExists(file) == false )
return false;
FILE *fp;
char signature[6+1];
int i;
m_fileName = file;
char path[1024];
strcpy( path, (const char*)file.mb_str(wxConvUTF8) );
fp = fopen(path, "rb");
if (fp == NULL)
return false;
fseek(fp, 0, SEEK_END);
m_fileSize = ftell(fp);
raw = (char *)malloc(m_fileSize);
if (raw == NULL)
{
fclose(fp);
return false;
}
fseek(fp, 0, SEEK_SET);
fread((char *)(raw), m_fileSize, sizeof(char), fp);
rawPtr = raw;
fclose(fp);
// header
memcpy(&m_header, rawPtr, sizeof(ISS_HEADER));
rawPtr += sizeof(ISS_HEADER);
// record
m_record = (ISS_RECORD *)malloc(
sizeof(ISS_RECORD) * m_header.rec_count);
if (m_record == NULL) return NULL;
//printf("-----raw_ptr: %d\n", rawPtr-raw);
for (unsigned int x = 0; x < m_header.rec_count; x++)
{
memcpy(&m_record[x].kasa_tick, rawPtr, sizeof(unsigned short));
rawPtr += sizeof(unsigned short);
memcpy(&m_record[x].line, rawPtr, sizeof(char));
rawPtr += sizeof(char);
memcpy(&m_record[x].start_x, rawPtr, sizeof(char));
rawPtr += sizeof(char);
memcpy(&m_record[x].width_x, rawPtr, sizeof(char));
rawPtr += sizeof(char);
}
// script
m_script = (ISS_SCRIPT *)malloc(
sizeof(ISS_SCRIPT) * m_header.line_count);
if (m_script == NULL) return NULL;
for (unsigned int x = 0; x < m_header.line_count; x++)
{
memcpy(&m_script[x], rawPtr, sizeof(ISS_SCRIPT));
rawPtr += sizeof(ISS_SCRIPT);
}
/*
// ----
for (unsigned int x = 0; x < m_header.rec_count; x++)
printf("--%d-- kasa_tick: %d --- kasa_line: %d --\n",
x, m_record[x].kasa_tick, m_record[x].line);
for (unsigned int x = 0; x < m_header.line_count; x++)
{
char title[70];
han_conv(0, m_script[x].script, title);
//printf("--%d-- %s --\n", x, m_script[x].script);
printf("--%d-- %s --\n", x, title);
}
//printf("\n-%d-line_count-- %d", sizeof(ISS_HEADER), m_header.line_count);
//printf("\n-%d-rec_count-- %d", sizeof(ISS_RECORD), m_header.rec_count);
//printf("----ISS_SCRIPT: %d--\n", sizeof(ISS_SCRIPT));
//fflush(stdout);
*/
opened=true;
return true;
}
// Àۻ簡
char *Iss::GetWriter()
{
return (char *)m_header.writer;
}
// ÀÛ°î°¡
char *Iss::GetComposer()
{
return (char *)m_header.composer;
}
// °¡¼ö
wxString Iss::GetSinger()
{
char singer[30];
han_conv(0, m_header.singer, singer);
wchar_t wszBuffer[30];
// cp949 -> unicode
MultiByteToWideChar(CP_ACP, 0, singer, -1, wszBuffer, 30);
// unicode -> utf-8
WideCharToMultiByte(CP_UTF8, 0, wszBuffer, -1, singer, 30, NULL, NULL);
return wxString(wszBuffer, wxConvUTF8);
}
bool Iss::IsOpened()
{
return opened;
}