From fca4441229808891f460d5fbc4affd51e8896aa5 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Thu, 9 Jan 2014 01:22:34 +0100 Subject: Replace old launcher part with a shiny new one. No more garbage on the command line. --- logic/OneSixInstance.cpp | 88 ++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 48 deletions(-) (limited to 'logic/OneSixInstance.cpp') diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 2392c683..a12cf047 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -13,12 +13,14 @@ * limitations under the License. */ +#include "MultiMC.h" #include "OneSixInstance.h" #include "OneSixInstance_p.h" #include "OneSixUpdate.h" #include "MinecraftProcess.h" #include "OneSixVersion.h" #include "JavaChecker.h" +#include "logic/icons/IconList.h" #include #include @@ -27,6 +29,7 @@ #include "gui/dialogs/OneSixModEditDialog.h" #include "logger/QsLog.h" #include "logic/assets/AssetsUtils.h" +#include OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *setting_obj, QObject *parent) @@ -40,7 +43,7 @@ OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *setting_o std::shared_ptr OneSixInstance::doUpdate(bool only_prepare) { - return std::shared_ptr (new OneSixUpdate(this, only_prepare)); + return std::shared_ptr(new OneSixUpdate(this, only_prepare)); } QString replaceTokensIn(QString text, QMap with) @@ -78,24 +81,25 @@ QDir OneSixInstance::reconstructAssets(std::shared_ptr version) QFile indexFile(indexPath); QDir virtualRoot(PathCombine(virtualDir.path(), version->assets)); - if(!indexFile.exists()) + if (!indexFile.exists()) { QLOG_ERROR() << "No assets index file" << indexPath << "; can't reconstruct assets"; return virtualRoot; } - QLOG_DEBUG() << "reconstructAssets" << assetsDir.path() << indexDir.path() << objectDir.path() << virtualDir.path() << virtualRoot.path(); + QLOG_DEBUG() << "reconstructAssets" << assetsDir.path() << indexDir.path() + << objectDir.path() << virtualDir.path() << virtualRoot.path(); AssetsIndex index; bool loadAssetsIndex = AssetsUtils::loadAssetsIndexJson(indexPath, &index); - if(loadAssetsIndex) + if (loadAssetsIndex) { - if(index.isVirtual) + if (index.isVirtual) { QLOG_INFO() << "Reconstructing virtual assets folder at" << virtualRoot.path(); - for(QString map : index.objects.keys()) + for (QString map : index.objects.keys()) { AssetObject asset_object = index.objects.value(map); QString target_path = PathCombine(virtualRoot.path(), map); @@ -103,17 +107,20 @@ QDir OneSixInstance::reconstructAssets(std::shared_ptr version) QString tlk = asset_object.hash.left(2); - QString original_path = PathCombine(PathCombine(objectDir.path(), tlk), asset_object.hash); + QString original_path = + PathCombine(PathCombine(objectDir.path(), tlk), asset_object.hash); QFile original(original_path); - if(!target.exists()) + 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()); + // 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(); + QLOG_DEBUG() << " Copying" << original_path << "to" << target_path + << QString::number(couldCopy); // << original.errorString(); } } @@ -155,7 +162,7 @@ QStringList OneSixInstance::processMinecraftArgs(MojangAccountPtr account) auto user = account->user(); QJsonObject userAttrs; - for(auto key: user.properties.keys()) + for (auto key : user.properties.keys()) { auto array = QJsonArray::fromStringList(user.properties.values(key)); userAttrs.insert(key, array); @@ -180,71 +187,56 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(MojangAccountPtr account) { I_D(OneSixInstance); - QString natives_dir_raw = PathCombine(instanceRoot(), "natives/"); + QIcon icon = MMC->icons()->getIcon(iconKey()); + auto pixmap = icon.pixmap(128, 128); + pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG"); auto version = d->version; if (!version) return nullptr; - - QStringList args; - args.append(Util::Commandline::splitArgs(settings().get("JvmArgs").toString())); - args << QString("-Xms%1m").arg(settings().get("MinMemAlloc").toInt()); - args << QString("-Xmx%1m").arg(settings().get("MaxMemAlloc").toInt()); - args << QString("-XX:PermSize=%1m").arg(settings().get("PermGen").toInt()); - -/** - * HACK: Stupid hack for Intel drivers. - * See: https://mojang.atlassian.net/browse/MCL-767 - */ -#ifdef Q_OS_WIN32 - args << QString("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_" - "minecraft.exe.heapdump"); -#endif - - QDir natives_dir(natives_dir_raw); - args << QString("-Djava.library.path=%1").arg(natives_dir.absolutePath()); - QString classPath; + QString launchScript; { auto libs = version->getActiveNormalLibs(); for (auto lib : libs) { QFileInfo fi(QString("libraries/") + lib->storagePath()); - classPath.append(fi.absoluteFilePath()); -#ifdef Q_OS_WIN32 - classPath.append(';'); -#else - classPath.append(':'); -#endif + launchScript += "cp " + fi.absoluteFilePath() + "\n"; } QString targetstr = "versions/" + version->id + "/" + version->id + ".jar"; QFileInfo fi(targetstr); - classPath.append(fi.absoluteFilePath()); + launchScript += "cp " + fi.absoluteFilePath() + "\n"; } - if (classPath.size()) + launchScript += "mainClass " + version->mainClass + "\n"; + + for (auto param : processMinecraftArgs(account)) { - args << "-cp"; - args << classPath; + launchScript += "param " + param + "\n"; } - args << version->mainClass; - args.append(processMinecraftArgs(account)); // Set the width and height for 1.6 instances bool maximize = settings().get("LaunchMaximized").toBool(); if (maximize) { // this is probably a BAD idea - // args << QString("--fullscreen"); + // launchScript += "param --fullscreen\n"; } else { - args << QString("--width") << settings().get("MinecraftWinWidth").toString(); - args << QString("--height") << settings().get("MinecraftWinHeight").toString(); + launchScript += + "param --width\nparam " + settings().get("MinecraftWinWidth").toString() + "\n"; + launchScript += + "param --height\nparam " + settings().get("MinecraftWinHeight").toString() + "\n"; } + QDir natives_dir(PathCombine(instanceRoot(), "natives/")); + launchScript += "windowTitle MultiMC: " + name() + "\n"; + launchScript += "natives " + natives_dir.absolutePath() + "\n"; + launchScript += "launch onesix\n"; // create the process and set its parameters MinecraftProcess *proc = new MinecraftProcess(this); - proc->setArguments(args); proc->setWorkdir(minecraftRoot()); + proc->setLaunchScript(launchScript); + // proc->setNativeFolder(natives_dir.absolutePath()); return proc; } -- cgit From afd1778fd766011a968074d68241b42b1438fb18 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 12 Jan 2014 23:38:12 +0100 Subject: Fix window title problem on OSX. --- logic/BaseInstance.cpp | 5 +++++ logic/BaseInstance.h | 3 +++ logic/LegacyInstance.cpp | 2 +- logic/MinecraftProcess.cpp | 2 +- logic/OneSixInstance.cpp | 2 +- 5 files changed, 11 insertions(+), 3 deletions(-) (limited to 'logic/OneSixInstance.cpp') diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp index 4fc6b9dc..afe3dd03 100644 --- a/logic/BaseInstance.cpp +++ b/logic/BaseInstance.cpp @@ -256,6 +256,11 @@ QString BaseInstance::name() const return d->m_settings->get("name").toString(); } +QString BaseInstance::windowTitle() const +{ + return "MultiMC: " + name(); +} + QStringList BaseInstance::extraArguments() const { return Util::Commandline::splitArgs(settings().get("JvmArgs").toString()); diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h index c059d058..353ea58a 100644 --- a/logic/BaseInstance.h +++ b/logic/BaseInstance.h @@ -71,6 +71,9 @@ public: QString name() const; void setName(QString val); + /// Value used for instance window titles + QString windowTitle() const; + QString iconKey() const; void setIconKey(QString val); diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp index 4b650e37..2828bcbf 100644 --- a/logic/LegacyInstance.cpp +++ b/logic/LegacyInstance.cpp @@ -73,7 +73,7 @@ MinecraftProcess *LegacyInstance::prepareForLaunch(MojangAccountPtr account) .absolutePath(); launchScript += "userName " + account->currentProfile()->name + "\n"; launchScript += "sessionId " + account->sessionId() + "\n"; - launchScript += "windowTitle MultiMC: " + name() + "\n"; + launchScript += "windowTitle " + windowTitle() + "\n"; launchScript += "windowParams " + windowParams + "\n"; launchScript += "lwjgl " + lwjgl + "\n"; launchScript += "launch legacy\n"; diff --git a/logic/MinecraftProcess.cpp b/logic/MinecraftProcess.cpp index 153b462c..09d60771 100644 --- a/logic/MinecraftProcess.cpp +++ b/logic/MinecraftProcess.cpp @@ -195,7 +195,7 @@ void MinecraftProcess::launch() // OSX dock icon and name #ifdef OSX args << "-Xdock:icon=icon.png"; - args << QString("-Xdock:name=\"%1\"").arg(windowTitle); + args << QString("-Xdock:name=\"%1\"").arg(m_instance->windowTitle()); #endif // HACK: Stupid hack for Intel drivers. See: https://mojang.atlassian.net/browse/MCL-767 diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index a12cf047..16699a1d 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -228,7 +228,7 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(MojangAccountPtr account) "param --height\nparam " + settings().get("MinecraftWinHeight").toString() + "\n"; } QDir natives_dir(PathCombine(instanceRoot(), "natives/")); - launchScript += "windowTitle MultiMC: " + name() + "\n"; + launchScript += "windowTitle " + windowTitle() + "\n"; launchScript += "natives " + natives_dir.absolutePath() + "\n"; launchScript += "launch onesix\n"; -- cgit From 3fabb11f4c59baffb14db00d338d9efe342e277e Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sat, 18 Jan 2014 22:11:33 +0100 Subject: Marginally improve OneSix offline mode launch While reconstructing assets, skip files that don't exist. Report missing OneSix native libraries. --- logic/OneSixInstance.cpp | 55 +++++++++++++++++------------------ logic/OneSixLibrary.cpp | 28 ++++++++++++++++++ logic/OneSixLibrary.h | 1 + logic/OneSixUpdate.cpp | 20 +++++++++---- logic/auth/MojangAccount.cpp | 6 +++- logic/lists/ForgeVersionList.cpp | 4 +-- logic/net/CacheDownload.cpp | 21 ++++++++----- logic/net/CacheDownload.h | 9 ++++-- logic/updater/NotificationChecker.cpp | 2 +- 9 files changed, 97 insertions(+), 49 deletions(-) (limited to 'logic/OneSixInstance.cpp') diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 16699a1d..3cfc1c76 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -93,39 +93,38 @@ QDir OneSixInstance::reconstructAssets(std::shared_ptr version) AssetsIndex 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(); + QLOG_INFO() << "Reconstructing virtual assets folder at" << virtualRoot.path(); - for (QString map : index.objects.keys()) + for (QString map : index.objects.keys()) + { + AssetObject asset_object = index.objects.value(map); + QString target_path = PathCombine(virtualRoot.path(), map); + QFile target(target_path); + + 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); - QString target_path = PathCombine(virtualRoot.path(), map); - QFile target(target_path); - - QString tlk = asset_object.hash.left(2); - - QString original_path = - 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(); - } + 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; diff --git a/logic/OneSixLibrary.cpp b/logic/OneSixLibrary.cpp index 1d69b660..cf29a832 100644 --- a/logic/OneSixLibrary.cpp +++ b/logic/OneSixLibrary.cpp @@ -136,6 +136,34 @@ QString OneSixLibrary::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) { QString storage = storagePath(); diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h index bc097348..227cdbef 100644 --- a/logic/OneSixLibrary.h +++ b/logic/OneSixLibrary.h @@ -128,4 +128,5 @@ public: QString hint(); bool extractTo(QString target_dir); + bool filesExist(); }; diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index ee355308..0119ab07 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -348,18 +348,26 @@ void OneSixUpdate::prepareForLaunch() "it or changing the version."); return; } -/* - * emitFailed("Could not create the native library folder:\n" + natives_dir_raw + - "\nMake sure MultiMC has appropriate permissions and there is enough space " - "on the storage device."); -*/ + /* + * emitFailed("Could not create the native library folder:\n" + natives_dir_raw + + "\nMake sure MultiMC has appropriate permissions and there is enough + space " + "on the storage device."); + */ 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)) { emitFailed("Could not extract the native library:\n" + lib->storagePath() + " to " + 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."); return; } diff --git a/logic/auth/MojangAccount.cpp b/logic/auth/MojangAccount.cpp index a462eda5..f41985ec 100644 --- a/logic/auth/MojangAccount.cpp +++ b/logic/auth/MojangAccount.cpp @@ -198,7 +198,11 @@ void MojangAccount::authFailed(QString reason) { // This is emitted when the yggdrasil tasks time out or are cancelled. // -> we treat the error as no-op - if (reason != "Yggdrasil task cancelled.") + if (reason == "Yggdrasil task cancelled.") + { + // do nothing + } + else { m_online = false; m_accessToken = QString(); diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp index 38e033fa..4902dc64 100644 --- a/logic/lists/ForgeVersionList.cpp +++ b/logic/lists/ForgeVersionList.cpp @@ -187,7 +187,7 @@ bool ForgeListLoadTask::parseForgeList(QList &out) QByteArray data; { auto dlJob = listDownload; - auto filename = std::dynamic_pointer_cast(dlJob)->m_target_path; + auto filename = std::dynamic_pointer_cast(dlJob)->getTargetFilepath(); QFile listFile(filename); if (!listFile.open(QIODevice::ReadOnly)) { @@ -303,7 +303,7 @@ bool ForgeListLoadTask::parseForgeGradleList(QList &out) QByteArray data; { auto dlJob = gradleListDownload; - auto filename = std::dynamic_pointer_cast(dlJob)->m_target_path; + auto filename = std::dynamic_pointer_cast(dlJob)->getTargetFilepath(); QFile listFile(filename); if (!listFile.open(QIODevice::ReadOnly)) { diff --git a/logic/net/CacheDownload.cpp b/logic/net/CacheDownload.cpp index 0022c361..d2a9bdee 100644 --- a/logic/net/CacheDownload.cpp +++ b/logic/net/CacheDownload.cpp @@ -40,7 +40,9 @@ void CacheDownload::start() emit succeeded(m_index_within_job); 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 (!ensureFilePathExists(m_target_path)) { @@ -49,7 +51,7 @@ void CacheDownload::start() emit failed(m_index_within_job); 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"; m_status = Job_Failed; @@ -94,7 +96,7 @@ void CacheDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) void CacheDownload::downloadError(QNetworkReply::NetworkError error) { // 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; } void CacheDownload::downloadFinished() @@ -102,17 +104,17 @@ void CacheDownload::downloadFinished() // if the download succeeded if (m_status == Job_Failed) { - m_output_file.cancelWriting(); + m_output_file->cancelWriting(); m_reply.reset(); - m_status = Job_Failed; emit failed(m_index_within_job); return; } + // if we wrote any data to the save file, we try to commit the data to the real file. if (wroteAnyData) { // nothing went wrong... - if (m_output_file.commit()) + if (m_output_file->commit()) { m_status = Job_Finished; m_entry->md5sum = md5sum.result().toHex().constData(); @@ -120,7 +122,7 @@ void CacheDownload::downloadFinished() else { QLOG_ERROR() << "Failed to commit changes to " << m_target_path; - m_output_file.cancelWriting(); + m_output_file->cancelWriting(); m_reply.reset(); m_status = Job_Failed; emit failed(m_index_within_job); @@ -132,6 +134,9 @@ void CacheDownload::downloadFinished() m_status = Job_Finished; } + // then get rid of the save file + m_output_file.reset(); + QFileInfo output_file_info(m_target_path); m_entry->etag = m_reply->rawHeader("ETag").constData(); @@ -153,7 +158,7 @@ void CacheDownload::downloadReadyRead() { QByteArray ba = m_reply->readAll(); 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; m_status = Job_Failed; diff --git a/logic/net/CacheDownload.h b/logic/net/CacheDownload.h index 48be1dae..154f5988 100644 --- a/logic/net/CacheDownload.h +++ b/logic/net/CacheDownload.h @@ -24,12 +24,12 @@ typedef std::shared_ptr CacheDownloadPtr; class CacheDownload : public NetAction { Q_OBJECT -public: +private: MetaEntryPtr m_entry; /// if saving to file, use the one specified in this string QString m_target_path; /// this is the output file, if any - QSaveFile m_output_file; + std::shared_ptr m_output_file; /// the hash-as-you-download QCryptographicHash md5sum; @@ -41,7 +41,10 @@ public: { return CacheDownloadPtr(new CacheDownload(url, entry)); } - + QString getTargetFilepath() + { + return m_target_path; + } protected slots: virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); diff --git a/logic/updater/NotificationChecker.cpp b/logic/updater/NotificationChecker.cpp index b2d67632..191e90a3 100644 --- a/logic/updater/NotificationChecker.cpp +++ b/logic/updater/NotificationChecker.cpp @@ -55,7 +55,7 @@ void NotificationChecker::downloadSucceeded(int) { m_entries.clear(); - QFile file(m_download->m_output_file.fileName()); + QFile file(m_download->getTargetFilepath()); if (file.open(QFile::ReadOnly)) { QJsonArray root = QJsonDocument::fromJson(file.readAll()).array(); -- cgit