Log version, work paths

This commit is contained in:
Petr Mrázek 2014-01-03 02:29:05 +01:00
parent 1455f051e4
commit f399207ae0
3 changed files with 86 additions and 40 deletions

View File

@ -47,7 +47,7 @@
using namespace Util::Commandline; 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, : QApplication(argc, argv), m_version{VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD,
VERSION_CHANNEL, VERSION_BUILD_TYPE} 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 // Don't quit on hiding the last window
this->setQuitOnLastWindowClosed(false); this->setQuitOnLastWindowClosed(false);
// Print app header
std::cout << "MultiMC 5" << std::endl;
std::cout << "(c) 2013 MultiMC Contributors" << std::endl << std::endl;
// Commandline parsing // Commandline parsing
QHash<QString, QVariant> args; QHash<QString, QVariant> args;
{ {
@ -82,16 +78,6 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &root)
parser.addShortOpt("dir", 'd'); parser.addShortOpt("dir", 'd');
parser.addDocumentation("dir", "use the supplied directory as MultiMC root instead of " parser.addDocumentation("dir", "use the supplied directory as MultiMC root instead of "
"the binary location (use '.' for current)"); "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",
"<path>");
// --quietupdate
parser.addSwitch("quietupdate");
parser.addShortOpt("quietupdate", 'U');
parser.addDocumentation("quietupdate",
"doesn't restart MultiMC after installing updates");
// WARNING: disabled until further notice // WARNING: disabled until further notice
/* /*
// --launch // --launch
@ -129,35 +115,67 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &root)
m_status = MultiMC::Succeeded; m_status = MultiMC::Succeeded;
return; return;
} }
}
// update origcwdPath = QDir::currentPath();
// Note: cwd is always the current executable path! binPath = applicationDirPath();
if (!args["update"].isNull()) QString adjustedBy;
{ // change directory
std::cout << "Performing MultiMC update: " << qPrintable(args["update"].toString()) QString dirParam = args["dir"].toString();
<< std::endl; if (!data_dir_override.isEmpty())
QString cwd = QDir::currentPath(); {
QDir::setCurrent(applicationDirPath()); // the override is used for tests (although dirparam would be enough...)
QFile file(applicationFilePath()); // TODO: remove the need for this extra logic
file.copy(args["update"].toString()); adjustedBy += "Test override " + data_dir_override;
if (args["quietupdate"].toBool()) dataPath = data_dir_override;
{ }
m_status = MultiMC::Succeeded; else if (!dirParam.isEmpty())
return; {
} // the dir param. it makes multimc data path point to whatever the user specified
QDir::setCurrent(cwd); // 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( #ifdef Q_OS_LINUX
args["dir"].toString().isEmpty() QDir foo(PathCombine(binPath, ".."));
? (root.isEmpty() ? QDir::currentPath() : QDir::current().absoluteFilePath(root)) rootPath = foo.absolutePath();
: args["dir"].toString()); #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 // init the logger
initLogger(); 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 // load settings
initGlobalSettings(); initGlobalSettings();
@ -319,7 +337,7 @@ void MultiMC::initLogger()
QsLogging::Logger &logger = QsLogging::Logger::instance(); QsLogging::Logger &logger = QsLogging::Logger::instance();
logger.setLoggingLevel(QsLogging::TraceLevel); logger.setLoggingLevel(QsLogging::TraceLevel);
m_fileDestination = QsLogging::DestinationFactory::MakeFileDestination(logBase.arg(0)); 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_fileDestination.get());
logger.addDestination(m_debugDestination.get()); logger.addDestination(m_debugDestination.get());
// log all the things // log all the things

View File

@ -125,6 +125,29 @@ public:
*/ */
bool openJsonEditor(const QString &filename); 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: private:
void initLogger(); void initLogger();
@ -157,6 +180,11 @@ private:
QString m_updateOnExitPath; QString m_updateOnExitPath;
QString rootPath;
QString binPath;
QString dataPath;
QString origcwdPath;
Status m_status = MultiMC::Failed; Status m_status = MultiMC::Failed;
MultiMCVersion m_version; MultiMCVersion m_version;
}; };

View File

@ -39,7 +39,7 @@ int main(int argc, char *argv[]) \
{ \ { \
char *argv_[] = { argv[0] _MMC_EXTRA_ARGV }; \ char *argv_[] = { argv[0] _MMC_EXTRA_ARGV }; \
int argc_ = 1 + _MMC_EXTRA_ARGC; \ 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); \ app.setAttribute(Qt::AA_Use96Dpi, true); \
TestObject tc; \ TestObject tc; \
return QTest::qExec(&tc, argc, argv); \ return QTest::qExec(&tc, argc, argv); \