Marginally improve OneSix offline mode launch

While reconstructing assets, skip files that don't exist.
Report missing OneSix native libraries.
This commit is contained in:
Petr Mrázek 2014-01-18 22:11:33 +01:00
parent 8650aa81f0
commit 3fabb11f4c
9 changed files with 95 additions and 47 deletions

View File

@ -93,39 +93,38 @@ QDir OneSixInstance::reconstructAssets(std::shared_ptr<OneSixVersion> version)
AssetsIndex index; AssetsIndex index;
bool loadAssetsIndex = AssetsUtils::loadAssetsIndexJson(indexPath, &index); bool loadAssetsIndex = AssetsUtils::loadAssetsIndexJson(indexPath, &index);
if (loadAssetsIndex) if (loadAssetsIndex && index.isVirtual)
{ {
if (index.isVirtual) QLOG_INFO() << "Reconstructing virtual assets folder at" << virtualRoot.path();
for (QString map : index.objects.keys())
{ {
QLOG_INFO() << "Reconstructing virtual assets folder at" << virtualRoot.path(); AssetObject asset_object = index.objects.value(map);
QString target_path = PathCombine(virtualRoot.path(), map);
QFile target(target_path);
for (QString map : index.objects.keys()) QString tlk = asset_object.hash.left(2);
QString original_path =
PathCombine(PathCombine(objectDir.path(), tlk), asset_object.hash);
QFile original(original_path);
if(!original.exists())
continue;
if (!target.exists())
{ {
AssetObject asset_object = index.objects.value(map); QFileInfo info(target_path);
QString target_path = PathCombine(virtualRoot.path(), map); QDir target_dir = info.dir();
QFile target(target_path); // QLOG_DEBUG() << target_dir;
if (!target_dir.exists())
QDir("").mkpath(target_dir.path());
QString tlk = asset_object.hash.left(2); bool couldCopy = original.copy(target_path);
QLOG_DEBUG() << " Copying" << original_path << "to" << target_path
QString original_path = << QString::number(couldCopy); // << original.errorString();
PathCombine(PathCombine(objectDir.path(), tlk), asset_object.hash);
QFile original(original_path);
if (!target.exists())
{
QFileInfo info(target_path);
QDir target_dir = info.dir();
// QLOG_DEBUG() << target_dir;
if (!target_dir.exists())
QDir("").mkpath(target_dir.path());
bool couldCopy = original.copy(target_path);
QLOG_DEBUG() << " Copying" << original_path << "to" << target_path
<< QString::number(couldCopy); // << original.errorString();
}
} }
// TODO: Write last used time to virtualRoot/.lastused
} }
// TODO: Write last used time to virtualRoot/.lastused
} }
return virtualRoot; return virtualRoot;

View File

@ -136,6 +136,34 @@ QString OneSixLibrary::hint()
return m_hint; return m_hint;
} }
bool OneSixLibrary::filesExist()
{
QString storage = storagePath();
if (storage.contains("${arch}"))
{
QString cooked_storage = storage;
cooked_storage.replace("${arch}", "32");
if (!QFileInfo::exists(PathCombine("libraries", cooked_storage)))
{
return false;
}
cooked_storage = storage;
cooked_storage.replace("${arch}", "64");
if (!QFileInfo::exists(PathCombine("libraries", cooked_storage)))
{
return false;
}
}
else
{
if (!QFileInfo::exists(PathCombine("libraries", storage)))
{
return false;
}
}
return true;
}
bool OneSixLibrary::extractTo(QString target_dir) bool OneSixLibrary::extractTo(QString target_dir)
{ {
QString storage = storagePath(); QString storage = storagePath();

View File

@ -128,4 +128,5 @@ public:
QString hint(); QString hint();
bool extractTo(QString target_dir); bool extractTo(QString target_dir);
bool filesExist();
}; };

View File

@ -348,18 +348,26 @@ void OneSixUpdate::prepareForLaunch()
"it or changing the version."); "it or changing the version.");
return; return;
} }
/* /*
* emitFailed("Could not create the native library folder:\n" + natives_dir_raw + * emitFailed("Could not create the native library folder:\n" + natives_dir_raw +
"\nMake sure MultiMC has appropriate permissions and there is enough space " "\nMake sure MultiMC has appropriate permissions and there is enough
"on the storage device."); space "
*/ "on the storage device.");
*/
for (auto lib : version->getActiveNativeLibs()) for (auto lib : version->getActiveNativeLibs())
{ {
if (!lib->filesExist())
{
emitFailed("Native library is missing some files:\n" + lib->storagePath() +
"\n\nRun the instance at least once in online mode to get all the "
"required files.");
return;
}
if (!lib->extractTo(natives_dir_raw)) if (!lib->extractTo(natives_dir_raw))
{ {
emitFailed("Could not extract the native library:\n" + lib->storagePath() + " to " + emitFailed("Could not extract the native library:\n" + lib->storagePath() + " to " +
natives_dir_raw + natives_dir_raw +
"\nMake sure MultiMC has appropriate permissions and there is enough " "\n\nMake sure MultiMC has appropriate permissions and there is enough "
"space on the storage device."); "space on the storage device.");
return; return;
} }

View File

@ -198,7 +198,11 @@ void MojangAccount::authFailed(QString reason)
{ {
// This is emitted when the yggdrasil tasks time out or are cancelled. // This is emitted when the yggdrasil tasks time out or are cancelled.
// -> we treat the error as no-op // -> we treat the error as no-op
if (reason != "Yggdrasil task cancelled.") if (reason == "Yggdrasil task cancelled.")
{
// do nothing
}
else
{ {
m_online = false; m_online = false;
m_accessToken = QString(); m_accessToken = QString();

View File

@ -187,7 +187,7 @@ bool ForgeListLoadTask::parseForgeList(QList<BaseVersionPtr> &out)
QByteArray data; QByteArray data;
{ {
auto dlJob = listDownload; auto dlJob = listDownload;
auto filename = std::dynamic_pointer_cast<CacheDownload>(dlJob)->m_target_path; auto filename = std::dynamic_pointer_cast<CacheDownload>(dlJob)->getTargetFilepath();
QFile listFile(filename); QFile listFile(filename);
if (!listFile.open(QIODevice::ReadOnly)) if (!listFile.open(QIODevice::ReadOnly))
{ {
@ -303,7 +303,7 @@ bool ForgeListLoadTask::parseForgeGradleList(QList<BaseVersionPtr> &out)
QByteArray data; QByteArray data;
{ {
auto dlJob = gradleListDownload; auto dlJob = gradleListDownload;
auto filename = std::dynamic_pointer_cast<CacheDownload>(dlJob)->m_target_path; auto filename = std::dynamic_pointer_cast<CacheDownload>(dlJob)->getTargetFilepath();
QFile listFile(filename); QFile listFile(filename);
if (!listFile.open(QIODevice::ReadOnly)) if (!listFile.open(QIODevice::ReadOnly))
{ {

View File

@ -40,7 +40,9 @@ void CacheDownload::start()
emit succeeded(m_index_within_job); emit succeeded(m_index_within_job);
return; return;
} }
m_output_file.setFileName(m_target_path); // create a new save file
m_output_file.reset(new QSaveFile(m_target_path));
// if there already is a file and md5 checking is in effect and it can be opened // if there already is a file and md5 checking is in effect and it can be opened
if (!ensureFilePathExists(m_target_path)) if (!ensureFilePathExists(m_target_path))
{ {
@ -49,7 +51,7 @@ void CacheDownload::start()
emit failed(m_index_within_job); emit failed(m_index_within_job);
return; return;
} }
if (!m_output_file.open(QIODevice::WriteOnly)) if (!m_output_file->open(QIODevice::WriteOnly))
{ {
QLOG_ERROR() << "Could not open " + m_target_path + " for writing"; QLOG_ERROR() << "Could not open " + m_target_path + " for writing";
m_status = Job_Failed; m_status = Job_Failed;
@ -94,7 +96,7 @@ void CacheDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
void CacheDownload::downloadError(QNetworkReply::NetworkError error) void CacheDownload::downloadError(QNetworkReply::NetworkError error)
{ {
// error happened during download. // error happened during download.
QLOG_ERROR() << "Failed" << m_url.toString() << "with reason" << error; QLOG_ERROR() << "Failed " << m_url.toString() << " with reason " << error;
m_status = Job_Failed; m_status = Job_Failed;
} }
void CacheDownload::downloadFinished() void CacheDownload::downloadFinished()
@ -102,17 +104,17 @@ void CacheDownload::downloadFinished()
// if the download succeeded // if the download succeeded
if (m_status == Job_Failed) if (m_status == Job_Failed)
{ {
m_output_file.cancelWriting(); m_output_file->cancelWriting();
m_reply.reset(); m_reply.reset();
m_status = Job_Failed;
emit failed(m_index_within_job); emit failed(m_index_within_job);
return; return;
} }
// if we wrote any data to the save file, we try to commit the data to the real file.
if (wroteAnyData) if (wroteAnyData)
{ {
// nothing went wrong... // nothing went wrong...
if (m_output_file.commit()) if (m_output_file->commit())
{ {
m_status = Job_Finished; m_status = Job_Finished;
m_entry->md5sum = md5sum.result().toHex().constData(); m_entry->md5sum = md5sum.result().toHex().constData();
@ -120,7 +122,7 @@ void CacheDownload::downloadFinished()
else else
{ {
QLOG_ERROR() << "Failed to commit changes to " << m_target_path; QLOG_ERROR() << "Failed to commit changes to " << m_target_path;
m_output_file.cancelWriting(); m_output_file->cancelWriting();
m_reply.reset(); m_reply.reset();
m_status = Job_Failed; m_status = Job_Failed;
emit failed(m_index_within_job); emit failed(m_index_within_job);
@ -132,6 +134,9 @@ void CacheDownload::downloadFinished()
m_status = Job_Finished; m_status = Job_Finished;
} }
// then get rid of the save file
m_output_file.reset();
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();
@ -153,7 +158,7 @@ void CacheDownload::downloadReadyRead()
{ {
QByteArray ba = m_reply->readAll(); QByteArray ba = m_reply->readAll();
md5sum.addData(ba); md5sum.addData(ba);
if (m_output_file.write(ba) != ba.size()) if (m_output_file->write(ba) != ba.size())
{ {
QLOG_ERROR() << "Failed writing into " + m_target_path; QLOG_ERROR() << "Failed writing into " + m_target_path;
m_status = Job_Failed; m_status = Job_Failed;

View File

@ -24,12 +24,12 @@ typedef std::shared_ptr<class CacheDownload> CacheDownloadPtr;
class CacheDownload : public NetAction class CacheDownload : public NetAction
{ {
Q_OBJECT Q_OBJECT
public: private:
MetaEntryPtr m_entry; MetaEntryPtr m_entry;
/// if saving to file, use the one specified in this string /// if saving to file, use the one specified in this string
QString m_target_path; QString m_target_path;
/// this is the output file, if any /// this is the output file, if any
QSaveFile m_output_file; std::shared_ptr<QSaveFile> m_output_file;
/// the hash-as-you-download /// the hash-as-you-download
QCryptographicHash md5sum; QCryptographicHash md5sum;
@ -41,7 +41,10 @@ public:
{ {
return CacheDownloadPtr(new CacheDownload(url, entry)); return CacheDownloadPtr(new CacheDownload(url, entry));
} }
QString getTargetFilepath()
{
return m_target_path;
}
protected protected
slots: slots:
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);

View File

@ -55,7 +55,7 @@ void NotificationChecker::downloadSucceeded(int)
{ {
m_entries.clear(); m_entries.clear();
QFile file(m_download->m_output_file.fileName()); QFile file(m_download->getTargetFilepath());
if (file.open(QFile::ReadOnly)) if (file.open(QFile::ReadOnly))
{ {
QJsonArray root = QJsonDocument::fromJson(file.readAll()).array(); QJsonArray root = QJsonDocument::fromJson(file.readAll()).array();