void V64Converter::runConverter(QString v64File, QString saveFile, QWidget *parent) { QFile v64(v64File); v64.open(QIODevice::ReadOnly); QString v64Check(v64.read(4).toHex()), message; if (v64Check != "37804012") { if (v64Check == "80371240") message = "\"" + QFileInfo(v64).fileName() + "\" " + tr("already in z64 format!"); else message = "\"" + QFileInfo(v64).fileName() + "\" " + tr("is not a valid .v64 file!"); QMessageBox::warning(parent, tr("CEN64-Qt Converter"), message); } else { v64.seek(0); QFile z64(saveFile); z64.open(QIODevice::WriteOnly); QByteArray data; QByteArray flipped; while (!v64.atEnd()) { data = v64.read(1024); for (int i = 0; i < data.size(); i+=2) { //Check to see if only one byte remaining (though byte count should always be even) if (i + 1 == data.size()) flipped.append(data[i]); else { flipped.append(data[i + 1]); flipped.append(data[i]); } } z64.write(flipped); flipped.truncate(0); } z64.close(); QMessageBox::information(parent, tr("CEN64-Qt Converter"), tr("Conversion complete!")); } v64.close(); }
int main(int argc, char *argv[]) { ExtractZakC64 z64(argv[0]); return z64.run(argc, argv); }