Support version format 9, fix version-related segfault, (maybe) fix forge lists.

This commit is contained in:
Petr Mrázek 2013-10-18 01:00:46 +02:00
parent a600286e33
commit 205570be32
6 changed files with 27 additions and 10 deletions

View File

@ -136,7 +136,7 @@ std::shared_ptr<OneSixVersion> OneSixVersion::fromJson(QJsonObject root)
root.value("minimumLauncherVersion").toDouble(); root.value("minimumLauncherVersion").toDouble();
// ADD MORE HERE :D // ADD MORE HERE :D
if (launcher_ver > 0 && launcher_ver <= 7) if (launcher_ver > 0 && launcher_ver <= 9)
return fromJsonV4(root, readVersion); return fromJsonV4(root, readVersion);
else else
{ {
@ -167,7 +167,8 @@ std::shared_ptr<OneSixVersion> OneSixVersion::fromFile(QString filepath)
} }
QJsonObject root = jsonDoc.object(); QJsonObject root = jsonDoc.object();
auto version = fromJson(root); auto version = fromJson(root);
version->original_file = filepath; if(version)
version->original_file = filepath;
return version; return version;
} }

View File

@ -162,6 +162,10 @@ void ForgeListLoadTask::executeTask()
auto job = new DownloadJob("Version index"); auto job = new DownloadJob("Version index");
// we do not care if the version is stale or not. // we do not care if the version is stale or not.
auto forgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "list.json"); auto forgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "list.json");
// verify by poking the server.
forgeListEntry->stale = true;
job->addCacheDownload(QUrl(JSON_URL), forgeListEntry); job->addCacheDownload(QUrl(JSON_URL), forgeListEntry);
listJob.reset(job); listJob.reset(job);
connect(listJob.get(), SIGNAL(succeeded()), SLOT(list_downloaded())); connect(listJob.get(), SIGNAL(succeeded()), SLOT(list_downloaded()));

View File

@ -33,7 +33,11 @@ void CacheDownload::start()
} }
QLOG_INFO() << "Downloading " << m_url.toString(); QLOG_INFO() << "Downloading " << m_url.toString();
QNetworkRequest request(m_url); QNetworkRequest request(m_url);
request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1()); if(m_entry->remote_changed_timestamp.size())
request.setRawHeader(QString("If-Modified-Since").toLatin1(), m_entry->remote_changed_timestamp.toLatin1());
if(m_entry->etag.size())
request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1());
request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Cached)"); request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Cached)");
auto worker = MMC->qnam(); auto worker = MMC->qnam();
@ -87,7 +91,11 @@ void CacheDownload::downloadFinished()
QFileInfo output_file_info(m_target_path); QFileInfo output_file_info(m_target_path);
m_entry->etag = m_reply->rawHeader("ETag").constData(); m_entry->etag = m_reply->rawHeader("ETag").constData();
m_entry->last_changed_timestamp = if(m_reply->hasRawHeader("Last-Modified"))
{
m_entry->remote_changed_timestamp = m_reply->rawHeader("Last-Modified").constData();
}
m_entry->local_changed_timestamp =
output_file_info.lastModified().toUTC().toMSecsSinceEpoch(); output_file_info.lastModified().toUTC().toMSecsSinceEpoch();
m_entry->stale = false; m_entry->stale = false;
MMC->metacache()->updateEntry(m_entry); MMC->metacache()->updateEntry(m_entry);

View File

@ -269,7 +269,7 @@ void ForgeXzDownload::decompressAndInstall()
QFileInfo output_file_info(m_target_path); QFileInfo output_file_info(m_target_path);
m_entry->etag = m_reply->rawHeader("ETag").constData(); m_entry->etag = m_reply->rawHeader("ETag").constData();
m_entry->last_changed_timestamp = m_entry->local_changed_timestamp =
output_file_info.lastModified().toUTC().toMSecsSinceEpoch(); output_file_info.lastModified().toUTC().toMSecsSinceEpoch();
m_entry->stale = false; m_entry->stale = false;
MMC->metacache()->updateEntry(m_entry); MMC->metacache()->updateEntry(m_entry);

View File

@ -82,7 +82,7 @@ MetaEntryPtr HttpMetaCache::resolveEntry ( QString base, QString resource_path,
// if the file changed, check md5sum // if the file changed, check md5sum
qint64 file_last_changed = finfo.lastModified().toUTC().toMSecsSinceEpoch(); qint64 file_last_changed = finfo.lastModified().toUTC().toMSecsSinceEpoch();
if(file_last_changed != entry->last_changed_timestamp) if(file_last_changed != entry->local_changed_timestamp)
{ {
QFile input(real_path); QFile input(real_path);
input.open(QIODevice::ReadOnly); input.open(QIODevice::ReadOnly);
@ -93,7 +93,7 @@ MetaEntryPtr HttpMetaCache::resolveEntry ( QString base, QString resource_path,
return staleEntry(base, resource_path); return staleEntry(base, resource_path);
} }
// md5sums matched... keep entry and save the new state to file // md5sums matched... keep entry and save the new state to file
entry->last_changed_timestamp = file_last_changed; entry->local_changed_timestamp = file_last_changed;
SaveEventually(); SaveEventually();
} }
@ -184,7 +184,8 @@ void HttpMetaCache::Load()
QString path = foo->path = element_obj.value("path").toString(); QString path = foo->path = element_obj.value("path").toString();
foo->md5sum = element_obj.value("md5sum").toString(); foo->md5sum = element_obj.value("md5sum").toString();
foo->etag = element_obj.value("etag").toString(); foo->etag = element_obj.value("etag").toString();
foo->last_changed_timestamp = element_obj.value("last_changed_timestamp").toDouble(); foo->local_changed_timestamp = element_obj.value("last_changed_timestamp").toDouble();
foo->remote_changed_timestamp = element_obj.value("remote_changed_timestamp").toString();
// presumed innocent until closer examination // presumed innocent until closer examination
foo->stale = false; foo->stale = false;
entrymap.entry_list[path] = MetaEntryPtr( foo ); entrymap.entry_list[path] = MetaEntryPtr( foo );
@ -215,7 +216,9 @@ void HttpMetaCache::SaveNow()
entryObj.insert("path", QJsonValue(entry->path)); entryObj.insert("path", QJsonValue(entry->path));
entryObj.insert("md5sum", QJsonValue(entry->md5sum)); entryObj.insert("md5sum", QJsonValue(entry->md5sum));
entryObj.insert("etag", QJsonValue(entry->etag)); entryObj.insert("etag", QJsonValue(entry->etag));
entryObj.insert("last_changed_timestamp", QJsonValue(double(entry->last_changed_timestamp))); entryObj.insert("last_changed_timestamp", QJsonValue(double(entry->local_changed_timestamp)));
if(!entry->remote_changed_timestamp.isEmpty())
entryObj.insert("remote_changed_timestamp", QJsonValue(entry->remote_changed_timestamp));
entriesArr.append(entryObj); entriesArr.append(entryObj);
} }
} }

View File

@ -10,7 +10,8 @@ struct MetaEntry
QString path; QString path;
QString md5sum; QString md5sum;
QString etag; QString etag;
qint64 last_changed_timestamp = 0; qint64 local_changed_timestamp = 0;
QString remote_changed_timestamp; // QString for now, RFC 2822 encoded time
bool stale = true; bool stale = true;
QString getFullPath(); QString getFullPath();
}; };