From 6ecb833dbf4c4930c8354dcce7967ad44c16c217 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 28 Oct 2013 20:55:12 +0100 Subject: Fix problem with instance list not using the instance folder path --- depends/util/include/pathutils.h | 10 ++++++++++ depends/util/src/pathutils.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'depends/util') diff --git a/depends/util/include/pathutils.h b/depends/util/include/pathutils.h index cea3a39a..c892c115 100644 --- a/depends/util/include/pathutils.h +++ b/depends/util/include/pathutils.h @@ -25,6 +25,16 @@ LIBUTIL_EXPORT QString PathCombine(QString path1, QString path2, QString path3); LIBUTIL_EXPORT QString AbsolutePath(QString path); +/** + * Normalize path + * + * Any paths inside the current directory will be normalized to relative paths (to current) + * Other paths will be made absolute + * + * Returns false if the path logic somehow filed (and normalizedPath in invalid) + */ +QString NormalizePath(QString path); + LIBUTIL_EXPORT QString RemoveInvalidFilenameChars(QString string, QChar replaceWith = '-'); LIBUTIL_EXPORT QString DirNameFromString(QString string, QString inDir = "."); diff --git a/depends/util/src/pathutils.cpp b/depends/util/src/pathutils.cpp index 4c24fa5d..590ac89d 100644 --- a/depends/util/src/pathutils.cpp +++ b/depends/util/src/pathutils.cpp @@ -39,6 +39,30 @@ QString AbsolutePath(QString path) return QFileInfo(path).absolutePath(); } +/** + * Normalize path + * + * Any paths inside the current directory will be normalized to relative paths (to current) + * Other paths will be made absolute + */ +QString NormalizePath(QString path) +{ + QDir a = QDir::currentPath(); + QString currentAbsolute = a.absolutePath(); + + QDir b(path); + QString newAbsolute = b.absolutePath(); + + if (newAbsolute.startsWith(currentAbsolute)) + { + return a.relativeFilePath(newAbsolute); + } + else + { + return newAbsolute; + } +} + QString badFilenameChars = "\"\\/?<>:*|!"; QString RemoveInvalidFilenameChars(QString string, QChar replaceWith) -- cgit From 7df667f823fc4a679148dfea215b25642babb48f Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 28 Oct 2013 21:50:58 +0100 Subject: Valgrind-checked early application start --- MultiMC.cpp | 14 +++++++++----- depends/util/include/cmdutils.h | 8 +------- depends/util/src/cmdutils.cpp | 15 +-------------- gui/settingsdialog.cpp | 2 +- 4 files changed, 12 insertions(+), 27 deletions(-) (limited to 'depends/util') diff --git a/MultiMC.cpp b/MultiMC.cpp index 56109ba6..4e2a5b0b 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -351,20 +351,24 @@ std::shared_ptr MultiMC::javalist() return m_javalist; } -int main(int argc, char *argv[]) +int main_gui(MultiMC & app) { - // initialize Qt - MultiMC app(argc, argv); - // show main window MainWindow mainWin; mainWin.show(); mainWin.checkSetDefaultJava(); + return app.exec(); +} + +int main(int argc, char *argv[]) +{ + // initialize Qt + MultiMC app(argc, argv); switch (app.status()) { case MultiMC::Initialized: - return app.exec(); + return main_gui(app); case MultiMC::Failed: return 1; case MultiMC::Succeeded: diff --git a/depends/util/include/cmdutils.h b/depends/util/include/cmdutils.h index 93fef9ff..b8582195 100644 --- a/depends/util/include/cmdutils.h +++ b/depends/util/include/cmdutils.h @@ -83,16 +83,10 @@ enum Enum /** * @brief The ParsingError class */ -class LIBUTIL_EXPORT ParsingError : public std::exception +class LIBUTIL_EXPORT ParsingError : public std::runtime_error { public: ParsingError(const QString &what); - ParsingError(const ParsingError &e); - ~ParsingError() throw() {} - const char *what() const throw(); - QString qwhat() const; -private: - QString m_what; }; /** diff --git a/depends/util/src/cmdutils.cpp b/depends/util/src/cmdutils.cpp index 80ba719d..b9cab717 100644 --- a/depends/util/src/cmdutils.cpp +++ b/depends/util/src/cmdutils.cpp @@ -463,21 +463,8 @@ void Parser::getPrefix(QString &opt, QString &flag) // ParsingError ParsingError::ParsingError(const QString &what) +:std::runtime_error(what.toStdString()) { - m_what = what; -} -ParsingError::ParsingError(const ParsingError &e) -{ - m_what = e.m_what; -} - -const char *ParsingError::what() const throw() -{ - return m_what.toLocal8Bit().constData(); -} -QString ParsingError::qwhat() const -{ - return m_what; } } diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index b2fbd898..fb204d10 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -55,7 +55,7 @@ void SettingsDialog::updateCheckboxStuff() void SettingsDialog::on_instDirBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Instance Directory"), - ui->instDirTextBox->text()); + ui->instDirTextBox->text()); QString cooked_dir = NormalizePath(raw_dir); // do not allow current dir - it's dirty. Do not allow dirs that don't exist -- cgit From e7e03c2b542b1cceda63628dd7ca6fa9c875cfd2 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 28 Oct 2013 22:01:37 +0100 Subject: BLIND CODE, BLIND CODE HERE! WHERE IS THE COMPILER!?!?! It choked on missing headers, maybe? --- depends/util/include/cmdutils.h | 1 + 1 file changed, 1 insertion(+) (limited to 'depends/util') diff --git a/depends/util/include/cmdutils.h b/depends/util/include/cmdutils.h index b8582195..bab5a9fa 100644 --- a/depends/util/include/cmdutils.h +++ b/depends/util/include/cmdutils.h @@ -19,6 +19,7 @@ #define CMDUTILS_H #include +#include #include #include -- cgit