add UTF-16 Support for titles
This commit is contained in:
parent
6e3f7118a9
commit
aca1916fd8
5 changed files with 107 additions and 37 deletions
|
@ -16,6 +16,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "StringParser.h"
|
||||||
#include "SavegameData.h"
|
#include "SavegameData.h"
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -72,43 +73,11 @@ bool SavegameData::readingSavegame()
|
||||||
|
|
||||||
QString SavegameData::getSavegameDataString(QByteArray savegameHeader)
|
QString SavegameData::getSavegameDataString(QByteArray savegameHeader)
|
||||||
{
|
{
|
||||||
QString savegameTitle;
|
|
||||||
QByteArray savegameBytes = savegameHeader.left(savegameHeaderLength);
|
QByteArray savegameBytes = savegameHeader.left(savegameHeaderLength);
|
||||||
QList<QByteArray> savegameBytesList = savegameBytes.split(char(0x01));
|
QList<QByteArray> savegameBytesList = savegameBytes.split(char(0x01));
|
||||||
savegameBytes = savegameBytesList.at(1);
|
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();
|
savegameBytesList.clear();
|
||||||
savegameBytes.clear();
|
return StringParser::parseTitleString(savegameBytes, savegameBytes.length());
|
||||||
return savegameTitle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SavegameData::readingSavegameFromFile(QString fileName)
|
bool SavegameData::readingSavegameFromFile(QString fileName)
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "SnapmaticPicture.h"
|
#include "SnapmaticPicture.h"
|
||||||
|
#include "StringParser.h"
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
|
@ -179,10 +180,11 @@ bool SnapmaticPicture::readingPicture()
|
||||||
|
|
||||||
QString SnapmaticPicture::getSnapmaticPictureString(QByteArray snapmaticHeader)
|
QString SnapmaticPicture::getSnapmaticPictureString(QByteArray snapmaticHeader)
|
||||||
{
|
{
|
||||||
QByteArray snapmaticUsefulBytes = snapmaticHeader.left(snapmaticUsefulLength);
|
QByteArray snapmaticBytes = snapmaticHeader.left(snapmaticUsefulLength);
|
||||||
snapmaticUsefulBytes.replace((char)0x00, "");
|
QList<QByteArray> snapmaticBytesList = snapmaticBytes.split(char(0x01));
|
||||||
snapmaticUsefulBytes.replace((char)0x01, "");
|
snapmaticBytes = snapmaticBytesList.at(1);
|
||||||
return QString::fromLatin1(snapmaticUsefulBytes);
|
snapmaticBytesList.clear();
|
||||||
|
return StringParser::parseTitleString(snapmaticBytes, snapmaticBytes.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SnapmaticPicture::getSnapmaticJSONString(QByteArray jsonBytes)
|
QString SnapmaticPicture::getSnapmaticJSONString(QByteArray jsonBytes)
|
||||||
|
|
65
StringParser.cpp
Executable file
65
StringParser.cpp
Executable 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
32
StringParser.h
Executable 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
|
|
@ -39,6 +39,7 @@ SOURCES += main.cpp \
|
||||||
SnapmaticPicture.cpp \
|
SnapmaticPicture.cpp \
|
||||||
SnapmaticWidget.cpp \
|
SnapmaticWidget.cpp \
|
||||||
StandardPaths.cpp \
|
StandardPaths.cpp \
|
||||||
|
StringParser.cpp \
|
||||||
UserInterface.cpp
|
UserInterface.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
@ -57,6 +58,7 @@ HEADERS += \
|
||||||
SnapmaticPicture.h \
|
SnapmaticPicture.h \
|
||||||
SnapmaticWidget.h \
|
SnapmaticWidget.h \
|
||||||
StandardPaths.h \
|
StandardPaths.h \
|
||||||
|
StringParser.h \
|
||||||
UserInterface.h
|
UserInterface.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
|
|
Loading…
Reference in a new issue