Support for Japanese character in savegame

This commit is contained in:
Rafael 2016-03-31 21:33:16 +02:00
parent cb1ae08394
commit 6e3f7118a9
3 changed files with 48 additions and 7 deletions

View file

@ -17,6 +17,8 @@
*****************************************************************************/ *****************************************************************************/
#include "SavegameData.h" #include "SavegameData.h"
#include <QTextCodec>
#include <QDebug>
#include <QFile> #include <QFile>
SavegameData::SavegameData(QString fileName, QObject *parent) : QObject(parent), savegameFileName(fileName) SavegameData::SavegameData(QString fileName, QObject *parent) : QObject(parent), savegameFileName(fileName)
@ -62,7 +64,6 @@ bool SavegameData::readingSavegame()
savegameOk = true; savegameOk = true;
} }
} }
saveFile->close(); saveFile->close();
saveFile->deleteLater(); saveFile->deleteLater();
delete saveFile; delete saveFile;
@ -71,10 +72,43 @@ bool SavegameData::readingSavegame()
QString SavegameData::getSavegameDataString(QByteArray savegameHeader) QString SavegameData::getSavegameDataString(QByteArray savegameHeader)
{ {
QByteArray savegameUsefulBytes = savegameHeader.left(savegameHeaderLength); QString savegameTitle;
savegameUsefulBytes.replace(QByteArray::fromHex("00"),""); QByteArray savegameBytes = savegameHeader.left(savegameHeaderLength);
savegameUsefulBytes.replace(QByteArray::fromHex("01"),""); QList<QByteArray> savegameBytesList = savegameBytes.split(char(0x01));
return QString::fromLatin1(savegameUsefulBytes); savegameBytes = savegameBytesList.at(1);
int savegameLength = savegameBytes.length();
int parsedBytes = 0;
while (parsedBytes <= savegameLength)
{
QList<QByteArray> parseByteList;
parseByteList.append(savegameBytes.mid(parsedBytes-1, 1));
parseByteList.append(savegameBytes.mid(parsedBytes-2, 1));
if (parseByteList.at(0).toHex() == "00")
{
// Latin character
savegameTitle.append(QString::fromLatin1(parseByteList.at(1)));
}
else if (parseByteList.at(0).toHex() == "30")
{
// Japanese character
QByteArray japaneseHex;
japaneseHex.append(QByteArray::fromHex("A5"));
japaneseHex.append(parseByteList.at(1));
savegameTitle.append(QTextCodec::codecForName("EUC-JP")->toUnicode(japaneseHex));
}
else
{
// Unsupported
}
parsedBytes = parsedBytes + 2;
parseByteList.clear();
}
savegameBytesList.clear();
savegameBytes.clear();
return savegameTitle;
} }
bool SavegameData::readingSavegameFromFile(QString fileName) bool SavegameData::readingSavegameFromFile(QString fileName)

View file

@ -190,7 +190,7 @@ QString SnapmaticPicture::getSnapmaticJSONString(QByteArray jsonBytes)
QByteArray jsonUsefulBytes = jsonBytes; QByteArray jsonUsefulBytes = jsonBytes;
jsonUsefulBytes.replace((char)0x00, ""); jsonUsefulBytes.replace((char)0x00, "");
jsonUsefulBytes.replace((char)0x0c, ""); jsonUsefulBytes.replace((char)0x0c, "");
return QString::fromLatin1(jsonUsefulBytes); return QString::fromUtf8(jsonUsefulBytes);
} }
QString SnapmaticPicture::getSnapmaticTIDEString(QByteArray tideBytes) QString SnapmaticPicture::getSnapmaticTIDEString(QByteArray tideBytes)
@ -198,7 +198,7 @@ QString SnapmaticPicture::getSnapmaticTIDEString(QByteArray tideBytes)
QByteArray tideUsefulBytes = tideBytes; QByteArray tideUsefulBytes = tideBytes;
tideUsefulBytes.remove(0, 4); tideUsefulBytes.remove(0, 4);
QList<QByteArray> tideUsefulBytesList = tideUsefulBytes.split(char(0x00)); QList<QByteArray> tideUsefulBytesList = tideUsefulBytes.split(char(0x00));
return QString::fromLatin1(tideUsefulBytesList.at(0)); return QString::fromUtf8(tideUsefulBytesList.at(0));
} }
bool SnapmaticPicture::readingPictureFromFile(QString fileName) bool SnapmaticPicture::readingPictureFromFile(QString fileName)

View file

@ -65,6 +65,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="cmdCopy">
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="cmdDelete"> <widget class="QPushButton" name="cmdDelete">
<property name="text"> <property name="text">