From f399207ae09e2b9a34166be6dbb2a1d22dbddc99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 3 Jan 2014 02:29:05 +0100 Subject: [PATCH] Log version, work paths --- MultiMC.cpp | 96 ++++++++++++++++++++++++++++-------------------- MultiMC.h | 28 ++++++++++++++ tests/TestUtil.h | 2 +- 3 files changed, 86 insertions(+), 40 deletions(-) diff --git a/MultiMC.cpp b/MultiMC.cpp index 4e06f558..619a7e0a 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -47,7 +47,7 @@ using namespace Util::Commandline; -MultiMC::MultiMC(int &argc, char **argv, const QString &root) +MultiMC::MultiMC(int &argc, char **argv, const QString &data_dir_override) : QApplication(argc, argv), m_version{VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_CHANNEL, VERSION_BUILD_TYPE} { @@ -60,10 +60,6 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &root) // Don't quit on hiding the last window this->setQuitOnLastWindowClosed(false); - // Print app header - std::cout << "MultiMC 5" << std::endl; - std::cout << "(c) 2013 MultiMC Contributors" << std::endl << std::endl; - // Commandline parsing QHash args; { @@ -82,16 +78,6 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &root) parser.addShortOpt("dir", 'd'); parser.addDocumentation("dir", "use the supplied directory as MultiMC root instead of " "the binary location (use '.' for current)"); - // --update - parser.addOption("update"); - parser.addShortOpt("update", 'u'); - parser.addDocumentation("update", "replaces the given file with the running executable", - ""); - // --quietupdate - parser.addSwitch("quietupdate"); - parser.addShortOpt("quietupdate", 'U'); - parser.addDocumentation("quietupdate", - "doesn't restart MultiMC after installing updates"); // WARNING: disabled until further notice /* // --launch @@ -129,35 +115,67 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &root) m_status = MultiMC::Succeeded; return; } - - // update - // Note: cwd is always the current executable path! - if (!args["update"].isNull()) - { - std::cout << "Performing MultiMC update: " << qPrintable(args["update"].toString()) - << std::endl; - QString cwd = QDir::currentPath(); - QDir::setCurrent(applicationDirPath()); - QFile file(applicationFilePath()); - file.copy(args["update"].toString()); - if (args["quietupdate"].toBool()) - { - m_status = MultiMC::Succeeded; - return; - } - QDir::setCurrent(cwd); - } + } + origcwdPath = QDir::currentPath(); + binPath = applicationDirPath(); + QString adjustedBy; + // change directory + QString dirParam = args["dir"].toString(); + if (!data_dir_override.isEmpty()) + { + // the override is used for tests (although dirparam would be enough...) + // TODO: remove the need for this extra logic + adjustedBy += "Test override " + data_dir_override; + dataPath = data_dir_override; + } + else if (!dirParam.isEmpty()) + { + // the dir param. it makes multimc data path point to whatever the user specified + // on command line + adjustedBy += "Command line " + dirParam; + dataPath = dirParam; + } + if(!ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath)) + { + // BAD STUFF. WHAT DO? + initLogger(); + QLOG_ERROR() << "Failed to set work path. Will exit. NOW."; + m_status = MultiMC::Failed; + return; } - // change directory - QDir::setCurrent( - args["dir"].toString().isEmpty() - ? (root.isEmpty() ? QDir::currentPath() : QDir::current().absoluteFilePath(root)) - : args["dir"].toString()); + { + #ifdef Q_OS_LINUX + QDir foo(PathCombine(binPath, "..")); + rootPath = foo.absolutePath(); + #elif defined(Q_OS_WIN32) + QDir foo(PathCombine(binPath, "..")); + rootPath = foo.absolutePath(); + #elif defined(Q_OS_MAC) + QDir foo(PathCombine(binPath, "../..")); + rootPath = foo.absolutePath(); + #endif + } // init the logger initLogger(); + QLOG_INFO() << "MultiMC 5, (c) 2013 MultiMC Contributors"; + QLOG_INFO() << "Version : " << VERSION_STR; + QLOG_INFO() << "Git commit : " << GIT_COMMIT; + if (adjustedBy.size()) + { + QLOG_INFO() << "Work dir before adjustment : " << origcwdPath; + QLOG_INFO() << "Work dir after adjustment : " << QDir::currentPath(); + QLOG_INFO() << "Adjusted by : " << adjustedBy; + } + else + { + QLOG_INFO() << "Work dir : " << QDir::currentPath(); + } + QLOG_INFO() << "Binary path : " << binPath; + QLOG_INFO() << "Application root path : " << rootPath; + // load settings initGlobalSettings(); @@ -319,7 +337,7 @@ void MultiMC::initLogger() QsLogging::Logger &logger = QsLogging::Logger::instance(); logger.setLoggingLevel(QsLogging::TraceLevel); m_fileDestination = QsLogging::DestinationFactory::MakeFileDestination(logBase.arg(0)); - m_debugDestination = QsLogging::DestinationFactory::MakeQDebugDestination(); + m_debugDestination = QsLogging::DestinationFactory::MakeDebugOutputDestination(); logger.addDestination(m_fileDestination.get()); logger.addDestination(m_debugDestination.get()); // log all the things diff --git a/MultiMC.h b/MultiMC.h index 9ad276ff..91731afa 100644 --- a/MultiMC.h +++ b/MultiMC.h @@ -125,6 +125,29 @@ public: */ bool openJsonEditor(const QString &filename); + /// this is the root of the 'installation'. Used for automatic updates + const QString &root() + { + return rootPath; + } + /// this is the where the binary files reside + const QString &bin() + { + return binPath; + } + /// this is the work/data path. All user data is here. + const QString &data() + { + return dataPath; + } + /** + * this is the original work path before it was changed by the adjustment mechanism + */ + const QString &origcwd() + { + return origcwdPath; + } + private: void initLogger(); @@ -157,6 +180,11 @@ private: QString m_updateOnExitPath; + QString rootPath; + QString binPath; + QString dataPath; + QString origcwdPath; + Status m_status = MultiMC::Failed; MultiMCVersion m_version; }; diff --git a/tests/TestUtil.h b/tests/TestUtil.h index fd25d24f..231ce7f6 100644 --- a/tests/TestUtil.h +++ b/tests/TestUtil.h @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) \ { \ char *argv_[] = { argv[0] _MMC_EXTRA_ARGV }; \ int argc_ = 1 + _MMC_EXTRA_ARGC; \ - MultiMC app(argc_, argv_, QDir::temp().absoluteFilePath("MultiMC_Test")); \ + MultiMC app(argc_, argv_/*, QDir::temp().absoluteFilePath("MultiMC_Test")*/); \ app.setAttribute(Qt::AA_Use96Dpi, true); \ TestObject tc; \ return QTest::qExec(&tc, argc, argv); \