NOISSUE eliminate timestamp strings
This commit is contained in:
parent
80b81c2c1e
commit
b54839b897
@ -60,9 +60,7 @@ void MinecraftProfile::reload()
|
||||
void MinecraftProfile::clear()
|
||||
{
|
||||
id.clear();
|
||||
m_updateTimeString.clear();
|
||||
m_updateTime = QDateTime();
|
||||
m_releaseTimeString.clear();
|
||||
m_releaseTime = QDateTime();
|
||||
type.clear();
|
||||
assets.clear();
|
||||
|
@ -121,12 +121,10 @@ public: /* data */
|
||||
/// the ID - determines which jar to use! ACTUALLY IMPORTANT!
|
||||
QString id;
|
||||
|
||||
/// the time this version was actually released by Mojang, as string and as QDateTime
|
||||
QString m_releaseTimeString;
|
||||
/// the time this version was actually released by Mojang
|
||||
QDateTime m_releaseTime;
|
||||
|
||||
/// the time this version was last updated by Mojang, as string and as QDateTime
|
||||
QString m_updateTimeString;
|
||||
/// the time this version was last updated by Mojang
|
||||
QDateTime m_updateTime;
|
||||
|
||||
/// Release type - "release" or "snapshot"
|
||||
|
@ -192,14 +192,12 @@ void MinecraftVersion::applyTo(MinecraftProfile *version)
|
||||
{
|
||||
version->type = m_type;
|
||||
}
|
||||
if (!m_releaseTimeString.isNull())
|
||||
if (!m_releaseTime.isNull())
|
||||
{
|
||||
version->m_releaseTimeString = m_releaseTimeString;
|
||||
version->m_releaseTime = m_releaseTime;
|
||||
}
|
||||
if (!m_updateTimeString.isNull())
|
||||
if (!m_updateTime.isNull())
|
||||
{
|
||||
version->m_updateTimeString = m_updateTimeString;
|
||||
version->m_updateTime = m_updateTime;
|
||||
}
|
||||
version->traits.unite(m_traits);
|
||||
|
@ -111,12 +111,10 @@ public: /* data */
|
||||
/// The type of this release
|
||||
QString m_type;
|
||||
|
||||
/// the time this version was actually released by Mojang, as string and as QDateTime
|
||||
QString m_releaseTimeString;
|
||||
/// the time this version was actually released by Mojang
|
||||
QDateTime m_releaseTime;
|
||||
|
||||
/// the time this version was last updated by Mojang, as string and as QDateTime
|
||||
QString m_updateTimeString;
|
||||
/// the time this version was last updated by Mojang
|
||||
QDateTime m_updateTime;
|
||||
|
||||
/// MD5 hash of the minecraft jar
|
||||
|
@ -184,14 +184,7 @@ void MinecraftVersionList::loadBuiltinList()
|
||||
mcVersion->m_name = mcVersion->m_descriptor = versionID;
|
||||
|
||||
// Parse the timestamp.
|
||||
if (!parse_timestamp(versionObj.value("releaseTime").toString(""),
|
||||
mcVersion->m_releaseTimeString, mcVersion->m_releaseTime))
|
||||
{
|
||||
qCritical() << "Error while parsing version" << versionID
|
||||
<< ": invalid version timestamp";
|
||||
continue;
|
||||
}
|
||||
|
||||
mcVersion->m_releaseTime = timeFromS3Time(versionObj.value("releaseTime").toString(""));
|
||||
mcVersion->m_versionFileURL = QString();
|
||||
mcVersion->m_versionSource = Builtin;
|
||||
mcVersion->m_type = versionTypeStr;
|
||||
@ -270,20 +263,8 @@ void MinecraftVersionList::loadMojangList(QJsonDocument jsonDoc, VersionSource s
|
||||
std::shared_ptr<MinecraftVersion> mcVersion(new MinecraftVersion());
|
||||
mcVersion->m_name = mcVersion->m_descriptor = versionID;
|
||||
|
||||
if (!parse_timestamp(versionObj.value("releaseTime").toString(""),
|
||||
mcVersion->m_releaseTimeString, mcVersion->m_releaseTime))
|
||||
{
|
||||
qCritical() << "Error while parsing version" << versionID
|
||||
<< ": invalid release timestamp";
|
||||
continue;
|
||||
}
|
||||
if (!parse_timestamp(versionObj.value("time").toString(""),
|
||||
mcVersion->m_updateTimeString, mcVersion->m_updateTime))
|
||||
{
|
||||
qCritical() << "Error while parsing version" << versionID
|
||||
<< ": invalid update timestamp";
|
||||
continue;
|
||||
}
|
||||
mcVersion->m_releaseTime = timeFromS3Time(versionObj.value("releaseTime").toString(""));
|
||||
mcVersion->m_updateTime = timeFromS3Time(versionObj.value("time").toString(""));
|
||||
|
||||
if (mcVersion->m_releaseTime < g_VersionFilterData.legacyCutoffDate)
|
||||
{
|
||||
@ -593,8 +574,8 @@ void MinecraftVersionList::saveCachedList()
|
||||
|
||||
entryObj.insert("id", mcversion->descriptor());
|
||||
entryObj.insert("version", mcversion->descriptor());
|
||||
entryObj.insert("time", mcversion->m_updateTimeString);
|
||||
entryObj.insert("releaseTime", mcversion->m_releaseTimeString);
|
||||
entryObj.insert("time", timeToS3Time(mcversion->m_updateTime));
|
||||
entryObj.insert("releaseTime", timeToS3Time(mcversion->m_releaseTime));
|
||||
entryObj.insert("url", mcversion->m_versionFileURL);
|
||||
entryObj.insert("type", mcversion->m_type);
|
||||
entriesArr.append(entryObj);
|
||||
|
@ -45,14 +45,8 @@ VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
||||
|
||||
readString(root, "assets", out->assets);
|
||||
|
||||
if (!parse_timestamp(root.value("releaseTime").toString(""), out->m_releaseTimeString, out->m_releaseTime))
|
||||
{
|
||||
out->addProblem(PROBLEM_WARNING, QObject::tr("Invalid 'releaseTime' timestamp"));
|
||||
}
|
||||
if (!parse_timestamp(root.value("time").toString(""), out->m_updateTimeString, out->m_updateTime))
|
||||
{
|
||||
out->addProblem(PROBLEM_WARNING, QObject::tr("Invalid 'time' timestamp"));
|
||||
}
|
||||
out->m_releaseTime = timeFromS3Time(root.value("releaseTime").toString(""));
|
||||
out->m_updateTime = timeFromS3Time(root.value("time").toString(""));
|
||||
|
||||
if (root.contains("minimumLauncherVersion"))
|
||||
{
|
||||
@ -90,8 +84,8 @@ static QJsonDocument versionFileToJson(VersionFilePtr patch)
|
||||
writeString(root, "minecraftArguments", patch->overwriteMinecraftArguments);
|
||||
writeString(root, "type", patch->type);
|
||||
writeString(root, "assets", patch->assets);
|
||||
writeString(root, "releaseTime", patch->m_releaseTimeString);
|
||||
writeString(root, "time", patch->m_updateTimeString);
|
||||
writeString(root, "releaseTime", timeToS3Time(patch->m_releaseTime));
|
||||
writeString(root, "time", timeToS3Time(patch->m_updateTime));
|
||||
|
||||
if (!patch->addLibs.isEmpty())
|
||||
{
|
||||
|
@ -1,23 +1,33 @@
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include "ParseUtils.h"
|
||||
#include <QDebug>
|
||||
|
||||
QDateTime timeFromS3Time(QString str)
|
||||
{
|
||||
return QDateTime::fromString(str, Qt::ISODate);
|
||||
}
|
||||
|
||||
bool parse_timestamp (const QString & raw, QString & save_here, QDateTime & parse_here)
|
||||
QString timeToS3Time(QDateTime time)
|
||||
{
|
||||
save_here = raw;
|
||||
if (save_here.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
parse_here = timeFromS3Time(save_here);
|
||||
if (!parse_here.isValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
// this all because Qt can't format timestamps right.
|
||||
int offsetRaw = time.offsetFromUtc();
|
||||
bool negative = offsetRaw < 0;
|
||||
int offsetAbs = std::abs(offsetRaw);
|
||||
|
||||
int offsetSeconds = offsetAbs % 60;
|
||||
offsetAbs -= offsetSeconds;
|
||||
|
||||
int offsetMinutes = offsetAbs % 3600;
|
||||
offsetAbs -= offsetMinutes;
|
||||
offsetMinutes /= 60;
|
||||
|
||||
int offsetHours = offsetAbs / 3600;
|
||||
|
||||
QString raw = time.toString("yyyy-MM-ddTHH:mm:ss");
|
||||
raw += (negative ? QChar('-') : QChar('+'));
|
||||
raw += QString("%1").arg(offsetHours, 2, 10, QChar('0'));
|
||||
raw += ":";
|
||||
raw += QString("%1").arg(offsetMinutes, 2, 10, QChar('0'));
|
||||
return raw;
|
||||
}
|
||||
|
@ -2,13 +2,10 @@
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
|
||||
/**
|
||||
* parse the S3 timestamp in 'raw' and fill the forwarded variables.
|
||||
* return true/false for success/failure
|
||||
*/
|
||||
bool parse_timestamp (const QString &raw, QString &save_here, QDateTime &parse_here);
|
||||
#include "multimc_logic_export.h"
|
||||
|
||||
/**
|
||||
* take the timestamp used by S3 and turn it into QDateTime
|
||||
*/
|
||||
QDateTime timeFromS3Time(QString str);
|
||||
/// take the timestamp used by S3 and turn it into QDateTime
|
||||
MULTIMC_LOGIC_EXPORT QDateTime timeFromS3Time(QString str);
|
||||
|
||||
/// take a timestamp and convert it into an S3 timestamp
|
||||
MULTIMC_LOGIC_EXPORT QString timeToS3Time(QDateTime);
|
||||
|
@ -75,14 +75,12 @@ void VersionFile::applyTo(MinecraftProfile *version)
|
||||
{
|
||||
version->type = type;
|
||||
}
|
||||
if (!m_releaseTimeString.isNull())
|
||||
if (!m_releaseTime.isNull())
|
||||
{
|
||||
version->m_releaseTimeString = m_releaseTimeString;
|
||||
version->m_releaseTime = m_releaseTime;
|
||||
}
|
||||
if (!m_updateTimeString.isNull())
|
||||
if (!m_updateTime.isNull())
|
||||
{
|
||||
version->m_updateTimeString = m_updateTimeString;
|
||||
version->m_updateTime = m_updateTime;
|
||||
}
|
||||
}
|
||||
|
@ -151,12 +151,10 @@ public: /* data */
|
||||
/// Mojang: type of the Minecraft version
|
||||
QString type;
|
||||
|
||||
/// Mojang: the time this version was actually released by Mojang, as string and as QDateTime
|
||||
QString m_releaseTimeString;
|
||||
/// Mojang: the time this version was actually released by Mojang
|
||||
QDateTime m_releaseTime;
|
||||
|
||||
/// Mojang: the time this version was last updated by Mojang, as string and as QDateTime
|
||||
QString m_updateTimeString;
|
||||
/// Mojang: the time this version was last updated by Mojang
|
||||
QDateTime m_updateTime;
|
||||
|
||||
/// Mojang: DEPRECATED asset group to be used with Minecraft
|
||||
|
@ -162,8 +162,8 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
||||
readString(root, "+minecraftArguments", out->addMinecraftArguments);
|
||||
readString(root, "type", out->type);
|
||||
|
||||
parse_timestamp(readStringRet(root, "releaseTime"), out->m_releaseTimeString, out->m_releaseTime);
|
||||
parse_timestamp(readStringRet(root, "time"), out->m_updateTimeString, out->m_updateTime);
|
||||
out->m_releaseTime = timeFromS3Time(readStringRet(root, "releaseTime"));
|
||||
out->m_updateTime = timeFromS3Time(readStringRet(root, "time"));
|
||||
|
||||
readString(root, "assets", out->assets);
|
||||
|
||||
@ -280,8 +280,8 @@ static QJsonDocument versionFileToJson(VersionFilePtr patch, bool saveOrder)
|
||||
writeString(root, "assets", patch->assets);
|
||||
if (patch->isMinecraftVersion())
|
||||
{
|
||||
writeString(root, "releaseTime", patch->m_releaseTimeString);
|
||||
writeString(root, "time", patch->m_updateTimeString);
|
||||
writeString(root, "releaseTime", timeToS3Time(patch->m_releaseTime));
|
||||
writeString(root, "time", timeToS3Time(patch->m_updateTime));
|
||||
}
|
||||
writeStringList(root, "tweakers", patch->overwriteTweakers);
|
||||
writeStringList(root, "+tweakers", patch->addTweakers);
|
||||
|
@ -31,6 +31,7 @@ add_unit_test(ModList tst_ModList.cpp)
|
||||
add_unit_test(Resource tst_Resource.cpp)
|
||||
add_unit_test(GZip tst_GZip.cpp)
|
||||
add_unit_test(JavaVersion tst_JavaVersion.cpp)
|
||||
add_unit_test(ParseUtils tst_ParseUtils.cpp)
|
||||
|
||||
# Tests END #
|
||||
|
||||
|
45
tests/tst_ParseUtils.cpp
Normal file
45
tests/tst_ParseUtils.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include <QTest>
|
||||
#include "TestUtil.h"
|
||||
|
||||
#include "minecraft/ParseUtils.h"
|
||||
|
||||
class ParseUtilsTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private
|
||||
slots:
|
||||
void test_Through_data()
|
||||
{
|
||||
QTest::addColumn<QString>("timestamp");
|
||||
const char * timestamps[] =
|
||||
{
|
||||
"2016-02-29T13:49:54+01:00",
|
||||
"2016-02-26T15:21:11+00:01",
|
||||
"2016-02-24T15:52:36+01:13",
|
||||
"2016-02-18T17:41:00+00:00",
|
||||
"2016-02-17T15:23:19+00:00",
|
||||
"2016-02-16T15:22:39+09:22",
|
||||
"2016-02-10T15:06:41+00:00",
|
||||
"2016-02-04T15:28:02-05:33"
|
||||
};
|
||||
for(int i = 0; i < (sizeof(timestamps) / sizeof(const char *)); i++)
|
||||
{
|
||||
QTest::newRow(timestamps[i]) << QString(timestamps[i]);
|
||||
}
|
||||
}
|
||||
void test_Through()
|
||||
{
|
||||
QFETCH(QString, timestamp);
|
||||
|
||||
auto time_parsed = timeFromS3Time(timestamp);
|
||||
auto time_serialized = timeToS3Time(time_parsed);
|
||||
|
||||
QCOMPARE(time_serialized, timestamp);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(ParseUtilsTest)
|
||||
|
||||
#include "tst_ParseUtils.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user