-
Notifications
You must be signed in to change notification settings - Fork 0
/
xcifile.cpp
executable file
·177 lines (150 loc) · 4.04 KB
/
xcifile.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "xcifile.h"
#include <QDebug>
#include <QtEndian>
XCIFile::XCIFile(QObject *parent) : QObject(parent)
{
pFileOK = true;
pInPath = "";//in.replace("file://","");
// pOutPath = "";//out.replace("file://","");
pDataSize = 0;
pCartSize = 0;
pRealfileSize = 0;
InfileStream = new QFile();
// OutfileStream = new QFile();
}
/*!
* \brief XCIFile::setOutPath
* \param val
*/
//void XCIFile::setOutPath(QString val)
//{
// pOutPath = val.replace("file://","");
// OutfileStream = new QFile(pOutPath);
// if (OutfileStream->open(QIODevice::WriteOnly))
// bw = new QDataStream(OutfileStream);
//}
/*!
* \brief XCIFile::setInPath
* \param val
*/
void XCIFile::setInPath(QString val)
{
pInPath = val.replace("file://","");
InfileStream = new QFile(pInPath);
// if (InfileStream->open(QIODevice::ReadOnly))
// br = new QDataStream(InfileStream);
ReadSizes();
}
/*!
* \brief XCIFile::ReadSizes
*/
void XCIFile::ReadSizes()
{
if (OpenReader())
{
InfileStream->seek(269);
char cartType;
InfileStream->read(&cartType,1);
qDebug()<<cartType;
switch ((quint8)cartType) {
case 248:
pCartSize = 1904;
break;
case 240:
pCartSize = 3808;
break;
case 224:
pCartSize = 7616;
break;
case 225:
pCartSize = 15232;
break;
case 226:
pCartSize = 30464;
break;
default:
qDebug()<<"The source file doesn't look like an XCI file" << "Can't determine cartridge size!";
break;
}
qDebug()<<pCartSize;
InfileStream->seek(280);
char dataSizeArray[4];
InfileStream->read(&dataSizeArray[0],4);
QByteArray test(dataSizeArray);
quint32 ds = qFromLittleEndian<quint32>(test.data());
//qDebug()<<ds;
pDataSize = 512 + ((quint64)ds * 512);
pChunkCount = (pDataSize / ChunkSize) + 1;
qDebug()<<pDataSize<<ChunkSize<<pChunkCount;
pRealfileSize = QFile(pInPath).size();
qDebug()<<pRealfileSize;
if (pInPath.endsWith("xc0"))
{
for (quint32 i=0; i < ChunkSize; i++)
{
QString fname = QString("%1%2").arg(pInPath.left(pInPath.length() - 1)).arg(i);
if ( QFile(fname).exists() )
{
pRealfileSize += QFile(fname).size();
}
else
{
qDebug()<<"Make sure that all parts of the dump are accessible. Dump incomplete!";
pDataSize = 0;
pCartSize = 0;
pRealfileSize = 0;
pFileOK = false;
}
}
}
if (pRealfileSize < 32*1024)
{
qDebug()<<"The source file doesn't look like an XCI file, File to small!";
pDataSize = 0;
pCartSize = 0;
pRealfileSize = 0;
pFileOK = false;
}
CloseReaders();
}
else
{
qDebug()<<"Cannot open file readers!";
pDataSize = 0;
pCartSize = 0;
pRealfileSize = 0;
pFileOK = false;
}
emit dataAvailable();
}
/*!
* \brief XCIFile::OpenReader
*/
bool XCIFile::OpenReader()
{
bool ret1 = true;
// bool ret2 = true;
if (InfileStream->isOpen() == false && QFile(pInPath).exists())
{
InfileStream = new QFile(pInPath);
ret1 = InfileStream->open(QIODevice::ReadOnly);
// if (ret1)
// br = new QDataStream(InfileStream);
}
// if (OutfileStream->isOpen() == false && pOutPath != "")
// {
// OutfileStream = new QFile(pOutPath);
// ret2 = OutfileStream->open(QIODevice::WriteOnly);
// if (ret2)
// bw = new QDataStream(OutfileStream);
// }
return ret1 /*&& ret2*/;
}
/*!
* \brief XCIFile::CloseReader
*/
void XCIFile::CloseReaders()
{
InfileStream->close();
//OutfileStream->close();
}