add UTF-16 Support for titles

This commit is contained in:
Rafael 2016-03-31 23:41:53 +02:00
parent 6e3f7118a9
commit aca1916fd8
5 changed files with 107 additions and 37 deletions

View file

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "StringParser.h"
#include "SavegameData.h"
#include <QTextCodec>
#include <QDebug>
@ -72,43 +73,11 @@ bool SavegameData::readingSavegame()
QString SavegameData::getSavegameDataString(QByteArray savegameHeader)
{
QString savegameTitle;
QByteArray savegameBytes = savegameHeader.left(savegameHeaderLength);
QList<QByteArray> savegameBytesList = savegameBytes.split(char(0x01));
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;
return StringParser::parseTitleString(savegameBytes, savegameBytes.length());
}
bool SavegameData::readingSavegameFromFile(QString fileName)

View file

@ -17,6 +17,7 @@
*****************************************************************************/
#include "SnapmaticPicture.h"
#include "StringParser.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QVariantMap>
@ -179,10 +180,11 @@ bool SnapmaticPicture::readingPicture()
QString SnapmaticPicture::getSnapmaticPictureString(QByteArray snapmaticHeader)
{
QByteArray snapmaticUsefulBytes = snapmaticHeader.left(snapmaticUsefulLength);
snapmaticUsefulBytes.replace((char)0x00, "");
snapmaticUsefulBytes.replace((char)0x01, "");
return QString::fromLatin1(snapmaticUsefulBytes);
QByteArray snapmaticBytes = snapmaticHeader.left(snapmaticUsefulLength);
QList<QByteArray> snapmaticBytesList = snapmaticBytes.split(char(0x01));
snapmaticBytes = snapmaticBytesList.at(1);
snapmaticBytesList.clear();
return StringParser::parseTitleString(snapmaticBytes, snapmaticBytes.length());
}
QString SnapmaticPicture::getSnapmaticJSONString(QByteArray jsonBytes)

65
StringParser.cpp Executable file
View file

@ -0,0 +1,65 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include <QTextCodec>
#include <QByteArray>
#include <QString>
#include <QList>
#include "StringParser.h"
StringParser::StringParser()
{
}
QString StringParser::parseTitleString(QByteArray commitBytes, int maxLength)
{
QString finalString;
int parsedBytes = 0;
while (parsedBytes <= maxLength)
{
QList<QByteArray> parseByteList;
parseByteList.append(commitBytes.mid(parsedBytes-1, 1));
parseByteList.append(commitBytes.mid(parsedBytes-2, 1));
if (parseByteList.at(0).toHex() == "00")
{
// Latin character
finalString.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));
// finalString.append(QTextCodec::codecForName("EUC-JP")->toUnicode(japaneseHex));
// }
else
{
QByteArray unsupportedHex;
unsupportedHex.append(parseByteList.at(0));
unsupportedHex.append(parseByteList.at(1));
finalString.append(QTextCodec::codecForName("UTF-16BE")->toUnicode(unsupportedHex));
}
parsedBytes = parsedBytes + 2;
parseByteList.clear();
}
return finalString;
}

32
StringParser.h Executable file
View file

@ -0,0 +1,32 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef STRINGPARSER_H
#define STRINGPARSER_H
#include <QByteArray>
#include <QString>
class StringParser
{
public:
StringParser();
static QString parseTitleString(QByteArray commitBytes, int maxLength);
};
#endif // STRINGPARSER_H

View file

@ -39,6 +39,7 @@ SOURCES += main.cpp \
SnapmaticPicture.cpp \
SnapmaticWidget.cpp \
StandardPaths.cpp \
StringParser.cpp \
UserInterface.cpp
HEADERS += \
@ -57,6 +58,7 @@ HEADERS += \
SnapmaticPicture.h \
SnapmaticWidget.h \
StandardPaths.h \
StringParser.h \
UserInterface.h
FORMS += \