From f93f867c3da084c6d6c5e3ed23896609cff0e692 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 5 Oct 2015 01:47:27 +0200 Subject: NOISSUE dissolve util library --- CMakeLists.txt | 1 - application/CMakeLists.txt | 2 +- application/InstancePageProvider.h | 6 +- application/MainWindow.cpp | 39 +- application/MultiMC.cpp | 45 +-- application/VersionProxyModel.cpp | 4 +- application/dialogs/CopyInstanceDialog.cpp | 18 + application/dialogs/CopyInstanceDialog.h | 3 + application/dialogs/CopyInstanceDialog.ui | 11 +- application/dialogs/ExportInstanceDialog.cpp | 11 +- application/dialogs/VersionSelectDialog.cpp | 1 - application/pages/InstanceSettingsPage.cpp | 4 +- application/pages/LegacyJarModPage.cpp | 5 +- application/pages/ModFolderPage.cpp | 5 +- application/pages/OtherLogsPage.cpp | 10 +- application/pages/ScreenshotsPage.cpp | 8 +- application/pages/VersionPage.cpp | 1 - application/pages/WorldListPage.cpp | 3 +- application/pages/WorldListPage.h | 1 - application/pages/global/ExternalToolsPage.cpp | 11 +- application/pages/global/JavaPage.cpp | 5 +- application/pages/global/MinecraftPage.cpp | 2 - application/pages/global/MultiMCPage.cpp | 20 +- application/pages/global/PasteEEPage.cpp | 2 - depends/util/CMakeLists.txt | 28 -- depends/util/include/cmdutils.h | 255 ------------- depends/util/include/modutils.h | 113 ------ depends/util/include/osutils.h | 26 -- depends/util/include/pathutils.h | 83 ----- depends/util/include/userutils.h | 17 - depends/util/src/cmdutils.cpp | 486 ------------------------- depends/util/src/modutils.cpp | 141 ------- depends/util/src/pathutils.cpp | 268 -------------- depends/util/src/userutils.cpp | 126 ------- logic/BaseInstance.cpp | 8 +- logic/CMakeLists.txt | 10 +- logic/Commandline.cpp | 483 ++++++++++++++++++++++++ logic/Commandline.h | 252 +++++++++++++ logic/FileSystem.cpp | 372 +++++++++++++++++++ logic/FileSystem.h | 82 ++++- logic/InstanceList.cpp | 16 +- logic/InstanceList.h | 2 +- logic/MMCZip.cpp | 6 +- logic/Version.cpp | 140 +++++++ logic/Version.h | 110 ++++++ logic/auth/MojangAccountList.cpp | 4 +- logic/forge/ForgeInstaller.cpp | 8 +- logic/forge/ForgeXzDownload.cpp | 4 +- logic/ftb/FTBPlugin.cpp | 10 +- logic/ftb/FTBProfileStrategy.cpp | 8 +- logic/ftb/OneSixFTBInstance.cpp | 6 +- logic/icons/IconList.cpp | 8 +- logic/java/JavaChecker.cpp | 8 +- logic/java/JavaCheckerJob.cpp | 1 - logic/java/JavaUtils.cpp | 1 - logic/java/JavaUtils.h | 5 +- logic/launch/LaunchTask.cpp | 1 - logic/launch/steps/CheckJava.cpp | 4 +- logic/launch/steps/LaunchMinecraft.cpp | 4 +- logic/minecraft/AssetsUtils.cpp | 17 +- logic/minecraft/LegacyInstance.cpp | 29 +- logic/minecraft/LegacyUpdate.cpp | 24 +- logic/minecraft/MinecraftInstance.cpp | 8 +- logic/minecraft/MinecraftProfile.cpp | 1 - logic/minecraft/MinecraftVersionList.cpp | 7 +- logic/minecraft/Mod.cpp | 6 +- logic/minecraft/ModList.cpp | 10 +- logic/minecraft/OneSixInstance.cpp | 24 +- logic/minecraft/OneSixProfileStrategy.cpp | 36 +- logic/minecraft/OneSixUpdate.cpp | 10 +- logic/minecraft/RawLibrary.cpp | 4 +- logic/minecraft/VersionFile.cpp | 6 +- logic/minecraft/World.cpp | 12 +- logic/minecraft/WorldList.cpp | 4 +- logic/net/CacheDownload.cpp | 4 +- logic/net/HttpMetaCache.cpp | 5 +- logic/net/MD5EtagDownload.cpp | 4 +- logic/net/NetJob.cpp | 1 - logic/updater/DownloadTask.cpp | 1 - logic/updater/GoUpdate.cpp | 8 +- tests/tst_DownloadTask.cpp | 4 +- tests/tst_modutils.cpp | 8 +- tests/tst_pathutils.cpp | 7 +- tests/tst_userutils.cpp | 7 +- 84 files changed, 1731 insertions(+), 1830 deletions(-) delete mode 100644 depends/util/CMakeLists.txt delete mode 100644 depends/util/include/cmdutils.h delete mode 100644 depends/util/include/modutils.h delete mode 100644 depends/util/include/osutils.h delete mode 100644 depends/util/include/pathutils.h delete mode 100644 depends/util/include/userutils.h delete mode 100644 depends/util/src/cmdutils.cpp delete mode 100644 depends/util/src/modutils.cpp delete mode 100644 depends/util/src/pathutils.cpp delete mode 100644 depends/util/src/userutils.cpp create mode 100644 logic/Commandline.cpp create mode 100644 logic/Commandline.h create mode 100644 logic/Version.cpp create mode 100644 logic/Version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c896de08..f432f851 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,6 @@ add_subdirectory(depends/libnbtplusplus) ######## MultiMC Libs ######## -add_subdirectory(depends/util) # various utility functions add_subdirectory(depends/LogicalGui) # GUI -> Logic connection add_subdirectory(depends/iconfix) # fork of Qt's QIcon loader diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index fdb27607..d9c37a45 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -348,7 +348,7 @@ qt5_add_resources(MULTIMC_RESOURCES ${MULTIMC_QRCS}) # Add executable add_executable(MultiMC MACOSX_BUNDLE WIN32 ${MULTIMC_SOURCES} ${MULTIMC_UI} ${MULTIMC_RESOURCES} ${MULTIMC_RCS}) -target_link_libraries(MultiMC MultiMC_logic xz-embedded unpack200 iconfix MultiMC_util ${QUAZIP_LIBRARIES} hoedown rainbow) +target_link_libraries(MultiMC MultiMC_logic xz-embedded unpack200 iconfix ${QUAZIP_LIBRARIES} hoedown rainbow) if(APPLE) find_library(OSX_CORE_FOUNDATION CoreFoundation) diff --git a/application/InstancePageProvider.h b/application/InstancePageProvider.h index c3ae17c1..1b283896 100644 --- a/application/InstancePageProvider.h +++ b/application/InstancePageProvider.h @@ -1,6 +1,7 @@ #pragma once #include "minecraft/OneSixInstance.h" #include "minecraft/LegacyInstance.h" +#include #include "pages/BasePage.h" #include "pages/VersionPage.h" #include "pages/ModFolderPage.h" @@ -13,7 +14,6 @@ #include "pages/BasePageProvider.h" #include "pages/LegacyJarModPage.h" #include "pages/WorldListPage.h" -#include class InstancePageProvider : public QObject, public BasePageProvider @@ -41,7 +41,7 @@ public: values.append(new TexturePackPage(onesix.get())); values.append(new NotesPage(onesix.get())); values.append(new WorldListPage(onesix.get(), onesix->worldList(), "worlds", "worlds", tr("Worlds"), "Worlds")); - values.append(new ScreenshotsPage(PathCombine(onesix->minecraftRoot(), "screenshots"))); + values.append(new ScreenshotsPage(FS::PathCombine(onesix->minecraftRoot(), "screenshots"))); values.append(new InstanceSettingsPage(onesix.get())); } std::shared_ptr legacy = std::dynamic_pointer_cast(inst); @@ -57,7 +57,7 @@ public: values.append(new TexturePackPage(legacy.get())); values.append(new NotesPage(legacy.get())); values.append(new WorldListPage(legacy.get(), legacy->worldList(), "worlds", "worlds", tr("Worlds"), "Worlds")); - values.append(new ScreenshotsPage(PathCombine(legacy->minecraftRoot(), "screenshots"))); + values.append(new ScreenshotsPage(FS::PathCombine(legacy->minecraftRoot(), "screenshots"))); values.append(new InstanceSettingsPage(legacy.get())); } auto logMatcher = inst->getLogFileMatcher(); diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 1562efc5..71888870 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -331,10 +331,6 @@ namespace Ui { #include -#include "osutils.h" -#include "userutils.h" -#include "pathutils.h" - #include "groupview/GroupView.h" #include "groupview/InstanceDelegate.h" #include "InstanceProxyModel.h" @@ -972,8 +968,8 @@ void MainWindow::downloadUpdates(GoUpdate::Status status) ProgressDialog updateDlg(this); status.rootPath = MMC->rootPath; - auto dlPath = PathCombine(MMC->root(), "update", "XXXXXX"); - if(!ensureFilePathExists(dlPath)) + auto dlPath = FS::PathCombine(MMC->root(), "update", "XXXXXX"); + if(!FS::ensureFilePathExists(dlPath)) { CustomMessageBox::selectable(this, tr("Error"), tr("Couldn't create folder for update downloads:\n%1").arg(dlPath), QMessageBox::Warning)->show(); } @@ -1053,8 +1049,8 @@ InstancePtr MainWindow::instanceFromZipPack(QString instName, QString instGroup, InstancePtr newInstance; QString instancesDir = MMC->settings()->get("InstanceDir").toString(); - QString instDirName = DirNameFromString(instName, instancesDir); - QString instDir = PathCombine(instancesDir, instDirName); + QString instDirName = FS::DirNameFromString(instName, instancesDir); + QString instDir = FS::PathCombine(instancesDir, instDirName); QString archivePath; if (url.isLocalFile()) @@ -1094,7 +1090,7 @@ InstancePtr MainWindow::instanceFromZipPack(QString instName, QString instGroup, CustomMessageBox::selectable(this, tr("Error"), tr("Archive does not contain instance.cfg"))->show(); return nullptr; } - if (!copyPath(instanceCfgFile.absoluteDir().absolutePath(), instDir)) + if (!FS::copyPath(instanceCfgFile.absoluteDir().absolutePath(), instDir)) { CustomMessageBox::selectable(this, tr("Error"), tr("Unable to copy instance"))->show(); return nullptr; @@ -1124,7 +1120,7 @@ InstancePtr MainWindow::instanceFromZipPack(QString instName, QString instGroup, else { instIcon = newInstance->iconKey(); - auto importIconPath = PathCombine(newInstance->instanceRoot(), instIcon + ".png"); + auto importIconPath = FS::PathCombine(newInstance->instanceRoot(), instIcon + ".png"); if (QFile::exists(importIconPath)) { // import icon @@ -1153,8 +1149,8 @@ InstancePtr MainWindow::instanceFromVersion(QString instName, QString instGroup, InstancePtr newInstance; QString instancesDir = MMC->settings()->get("InstanceDir").toString(); - QString instDirName = DirNameFromString(instName, instancesDir); - QString instDir = PathCombine(instancesDir, instDirName); + QString instDirName = FS::DirNameFromString(instName, instancesDir); + QString instDir = FS::PathCombine(instancesDir, instDirName); auto error = MMC->instances()->createInstance(newInstance, version, instDir); QString errorMsg = tr("Failed to create instance %1: ").arg(instDirName); switch (error) @@ -1257,11 +1253,12 @@ void MainWindow::on_actionCopyInstance_triggered() return; QString instancesDir = MMC->settings()->get("InstanceDir").toString(); - QString instDirName = DirNameFromString(copyInstDlg.instName(), instancesDir); - QString instDir = PathCombine(instancesDir, instDirName); + QString instDirName = FS::DirNameFromString(copyInstDlg.instName(), instancesDir); + QString instDir = FS::PathCombine(instancesDir, instDirName); + bool copySaves = copyInstDlg.shouldCopySaves(); InstancePtr newInstance; - auto error = MMC->instances()->copyInstance(newInstance, m_selectedInstance, instDir); + auto error = MMC->instances()->copyInstance(newInstance, m_selectedInstance, instDir, copySaves); QString errorMsg = tr("Failed to create instance %1: ").arg(instDirName); switch (error) @@ -1359,7 +1356,7 @@ void MainWindow::on_actionChangeInstGroup_triggered() void MainWindow::on_actionViewInstanceFolder_triggered() { QString str = MMC->settings()->get("InstanceDir").toString(); - openDirInDefaultProgram(str); + FS::openDirInDefaultProgram(str); } void MainWindow::on_actionRefresh_triggered() @@ -1369,7 +1366,7 @@ void MainWindow::on_actionRefresh_triggered() void MainWindow::on_actionViewCentralModsFolder_triggered() { - openDirInDefaultProgram(MMC->settings()->get("CentralModsDir").toString(), true); + FS::openDirInDefaultProgram(MMC->settings()->get("CentralModsDir").toString(), true); } void MainWindow::on_actionConfig_Folder_triggered() @@ -1377,7 +1374,7 @@ void MainWindow::on_actionConfig_Folder_triggered() if (m_selectedInstance) { QString str = m_selectedInstance->instanceConfigFolder(); - openDirInDefaultProgram(QDir(str).absolutePath()); + FS::openDirInDefaultProgram(QDir(str).absolutePath()); } } @@ -1509,7 +1506,7 @@ void MainWindow::on_actionViewSelectedInstFolder_triggered() if (m_selectedInstance) { QString str = m_selectedInstance->instanceRoot(); - openDirInDefaultProgram(QDir(str).absolutePath()); + FS::openDirInDefaultProgram(QDir(str).absolutePath()); } } @@ -1677,7 +1674,7 @@ void MainWindow::checkSetDefaultJava() break; } QString currentJavaPath = MMC->settings()->get("JavaPath").toString(); - QString actualPath = ResolveExecutable(currentJavaPath); + QString actualPath = FS::ResolveExecutable(currentJavaPath); if (currentJavaPath.isNull()) { askForJava = true; @@ -1738,7 +1735,7 @@ void MainWindow::checkSetDefaultJava() void MainWindow::checkInstancePathForProblems() { QString instanceFolder = MMC->settings()->get("InstanceDir").toString(); - if (checkProblemticPathJava(QDir(instanceFolder))) + if (FS::checkProblemticPathJava(QDir(instanceFolder))) { QMessageBox warning(this); warning.setText(tr( diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 612ba342..5584de1f 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -41,8 +41,6 @@ #include "tools/JVisualVM.h" #include "tools/MCEditTool.h" -#include "pathutils.h" -#include "cmdutils.h" #include #include "settings/INISettingsObject.h" #include "settings/Setting.h" @@ -54,7 +52,10 @@ #include "ftb/FTBPlugin.h" -using namespace Util::Commandline; +#include +#include + +using namespace Commandline; MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, argv) { @@ -142,7 +143,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar launchId = args["launch"].toString(); - if (!ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath)) + if (!FS::ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath)) { // BAD STUFF. WHAT DO? initLogger(); @@ -159,7 +160,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar else { #ifdef Q_OS_LINUX - QDir foo(PathCombine(binPath, "..")); + QDir foo(FS::PathCombine(binPath, "..")); rootPath = foo.absolutePath(); #elif defined(Q_OS_WIN32) rootPath = binPath; @@ -171,12 +172,12 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar // static data paths... mostly just for translations #ifdef Q_OS_LINUX - QDir foo(PathCombine(binPath, "..")); + QDir foo(FS::PathCombine(binPath, "..")); staticDataPath = foo.absolutePath(); #elif defined(Q_OS_WIN32) staticDataPath = binPath; #elif defined(Q_OS_MAC) - QDir foo(PathCombine(rootPath, "Contents/Resources")); + QDir foo(FS::PathCombine(rootPath, "Contents/Resources")); staticDataPath = foo.absolutePath(); #endif @@ -220,7 +221,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar // and rememer that we have to show him a dialog when the gui starts (if it does so) QString instDir = m_settings->get("InstanceDir").toString(); qDebug() << "Instance path : " << instDir; - if (checkProblemticPathJava(QDir(instDir))) + if (FS::checkProblemticPathJava(QDir(instDir))) { qWarning() << "Your instance path contains \'!\' and this is known to cause java problems"; @@ -671,26 +672,26 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi bool started = false; qDebug() << "Installing updates."; -#ifdef WINDOWS +#ifdef Q_OS_WIN QString finishCmd = applicationFilePath(); -#elif LINUX - QString finishCmd = PathCombine(root(), "MultiMC"); -#elif OSX +#elif defined Q_OS_LINUX + QString finishCmd = FS::PathCombine(root(), "MultiMC"); +#elif defined Q_OS_MAC QString finishCmd = applicationFilePath(); #else #error Unsupported operating system. #endif - QString backupPath = PathCombine(root(), "update", "backup"); + QString backupPath = FS::PathCombine(root(), "update", "backup"); QDir origin(root()); // clean up the backup folder. it should be empty before we start - if(!deletePath(backupPath)) + if(!FS::deletePath(backupPath)) { qWarning() << "couldn't remove previous backup folder" << backupPath; } // and it should exist. - if(!ensureFolderPathExists(backupPath)) + if(!FS::ensureFolderPathExists(backupPath)) { qWarning() << "couldn't create folder" << backupPath; return; @@ -726,7 +727,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi // replace = move original out to backup, if it exists, move the new file in its place case GoUpdate::Operation::OP_REPLACE: { - QFileInfo replaced (PathCombine(root(), op.dest)); + QFileInfo replaced (FS::PathCombine(root(), op.dest)); #ifdef Q_OS_WIN32 if(QSysInfo::windowsVersion() < QSysInfo::WV_VISTA) { @@ -735,7 +736,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi QDir rootDir(root()); exeOrigin = rootDir.relativeFilePath(op.file); exePath = rootDir.relativeFilePath(op.dest); - exeBackup = rootDir.relativeFilePath(PathCombine(backupPath, replaced.fileName())); + exeBackup = rootDir.relativeFilePath(FS::PathCombine(backupPath, replaced.fileName())); useXPHack = true; continue; } @@ -745,7 +746,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi { QString backupName = op.dest; backupName.replace('/', '_'); - QString backupFilePath = PathCombine(backupPath, backupName); + QString backupFilePath = FS::PathCombine(backupPath, backupName); if(!QFile::rename(replaced.absoluteFilePath(), backupFilePath)) { qWarning() << "Couldn't move:" << replaced.absoluteFilePath() << "to" << backupFilePath; @@ -759,7 +760,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi backups.append(be); } // make sure the folder we are putting this into exists - if(!ensureFilePathExists(replaced.absoluteFilePath())) + if(!FS::ensureFilePathExists(replaced.absoluteFilePath())) { qWarning() << "REPLACE: Couldn't create folder:" << replaced.absoluteFilePath(); failedOperationType = Replace; @@ -780,12 +781,12 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi // delete = move original to backup case GoUpdate::Operation::OP_DELETE: { - QString origFilePath = PathCombine(root(), op.file); + QString origFilePath = FS::PathCombine(root(), op.file); if(QFile::exists(origFilePath)) { QString backupName = op.file; backupName.replace('/', '_'); - QString trashFilePath = PathCombine(backupPath, backupName); + QString trashFilePath = FS::PathCombine(backupPath, backupName); if(!QFile::rename(origFilePath, trashFilePath)) { @@ -825,7 +826,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi out << "fso.MoveFile \"" << nativeOriginPath << "\", \"" << nativePath << "\"\n"; out << "shell.Run \"" << nativePath << "\"\n"; - QString scriptPath = PathCombine(root(), "update", "update.vbs"); + QString scriptPath = FS::PathCombine(root(), "update", "update.vbs"); // we save it QFile scriptFile(scriptPath); diff --git a/application/VersionProxyModel.cpp b/application/VersionProxyModel.cpp index 4db5cbd0..70894592 100644 --- a/application/VersionProxyModel.cpp +++ b/application/VersionProxyModel.cpp @@ -2,7 +2,7 @@ #include "MultiMC.h" #include #include -#include +#include class VersionFilterModel : public QSortFilterProxyModel { @@ -35,7 +35,7 @@ public: return false; } } - else if (!Util::versionIsInInterval(versionString, it.value().string)) + else if (!versionIsInInterval(versionString, it.value().string)) { return false; } diff --git a/application/dialogs/CopyInstanceDialog.cpp b/application/dialogs/CopyInstanceDialog.cpp index 54c42f29..67e2e8e1 100644 --- a/application/dialogs/CopyInstanceDialog.cpp +++ b/application/dialogs/CopyInstanceDialog.cpp @@ -52,6 +52,7 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent) } ui->groupBox->setCurrentIndex(index); ui->groupBox->lineEdit()->setPlaceholderText(tr("No group")); + ui->copySavesCheckbox->setChecked(m_copySaves); } CopyInstanceDialog::~CopyInstanceDialog() @@ -95,3 +96,20 @@ void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) { updateDialogState(); } + +bool CopyInstanceDialog::shouldCopySaves() const +{ + return m_copySaves; +} + +void CopyInstanceDialog::on_copySavesCheckbox_stateChanged(int state) +{ + if(state == Qt::Unchecked) + { + m_copySaves = false; + } + else if(state == Qt::Checked) + { + m_copySaves = true; + } +} diff --git a/application/dialogs/CopyInstanceDialog.h b/application/dialogs/CopyInstanceDialog.h index faa20615..a519443f 100644 --- a/application/dialogs/CopyInstanceDialog.h +++ b/application/dialogs/CopyInstanceDialog.h @@ -39,14 +39,17 @@ public: QString instName() const; QString instGroup() const; QString iconKey() const; + bool shouldCopySaves() const; private slots: void on_iconButton_clicked(); void on_instNameTextBox_textChanged(const QString &arg1); + void on_copySavesCheckbox_stateChanged(int state); private: Ui::CopyInstanceDialog *ui; QString InstIconKey; InstancePtr m_original; + bool m_copySaves = true; }; diff --git a/application/dialogs/CopyInstanceDialog.ui b/application/dialogs/CopyInstanceDialog.ui index 2615168c..bbb1bbb3 100644 --- a/application/dialogs/CopyInstanceDialog.ui +++ b/application/dialogs/CopyInstanceDialog.ui @@ -10,7 +10,7 @@ 0 0 345 - 205 + 240 @@ -87,7 +87,7 @@ - Group + &Group groupBox @@ -109,6 +109,13 @@ + + + + Copy saves + + + diff --git a/application/dialogs/ExportInstanceDialog.cpp b/application/dialogs/ExportInstanceDialog.cpp index ec46b6ba..8d320a3c 100644 --- a/application/dialogs/ExportInstanceDialog.cpp +++ b/application/dialogs/ExportInstanceDialog.cpp @@ -17,7 +17,6 @@ #include "ui_ExportInstanceDialog.h" #include #include -#include #include #include #include @@ -185,7 +184,7 @@ public: blocked.remove(cover); // block all contents, except for any cover QModelIndex rootIndex = - fsm->index(PathCombine(m_instance->instanceRoot(), cover)); + fsm->index(FS::PathCombine(m_instance->instanceRoot(), cover)); QModelIndex doing = rootIndex; int row = 0; QStack todo; @@ -376,18 +375,18 @@ void SaveIcon(InstancePtr m_instance) } } auto pixmap = icon.pixmap(largest); - pixmap.save(PathCombine(m_instance->instanceRoot(), iconKey + ".png")); + pixmap.save(FS::PathCombine(m_instance->instanceRoot(), iconKey + ".png")); } } } bool ExportInstanceDialog::doExport() { - auto name = RemoveInvalidFilenameChars(m_instance->name()); + auto name = FS::RemoveInvalidFilenameChars(m_instance->name()); const QString output = QFileDialog::getSaveFileName( this, tr("Export %1").arg(m_instance->name()), - PathCombine(QDir::homePath(), name + ".zip"), "Zip (*.zip)"); + FS::PathCombine(QDir::homePath(), name + ".zip"), "Zip (*.zip)"); if (output.isNull()) { return false; @@ -452,7 +451,7 @@ void ExportInstanceDialog::rowsInserted(QModelIndex parent, int top, int bottom) QString ExportInstanceDialog::ignoreFileName() { - return PathCombine(m_instance->instanceRoot(), ".packignore"); + return FS::PathCombine(m_instance->instanceRoot(), ".packignore"); } void ExportInstanceDialog::loadPackIgnore() diff --git a/application/dialogs/VersionSelectDialog.cpp b/application/dialogs/VersionSelectDialog.cpp index df72189b..50b543db 100644 --- a/application/dialogs/VersionSelectDialog.cpp +++ b/application/dialogs/VersionSelectDialog.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "MultiMC.h" #include diff --git a/application/pages/InstanceSettingsPage.cpp b/application/pages/InstanceSettingsPage.cpp index 35cbefe5..a23d7c22 100644 --- a/application/pages/InstanceSettingsPage.cpp +++ b/application/pages/InstanceSettingsPage.cpp @@ -10,7 +10,7 @@ #include "MultiMC.h" #include -#include +#include InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent) : QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst) @@ -186,7 +186,7 @@ void InstanceSettingsPage::on_javaDetectBtn_clicked() void InstanceSettingsPage::on_javaBrowseBtn_clicked() { QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable")); - QString cooked_path = NormalizePath(raw_path); + QString cooked_path = FS::NormalizePath(raw_path); // do not allow current dir - it's dirty. Do not allow dirs that don't exist if(cooked_path.isEmpty()) diff --git a/application/pages/LegacyJarModPage.cpp b/application/pages/LegacyJarModPage.cpp index 87a9f3b5..5d397978 100644 --- a/application/pages/LegacyJarModPage.cpp +++ b/application/pages/LegacyJarModPage.cpp @@ -19,14 +19,13 @@ #include #include -#include - #include "dialogs/VersionSelectDialog.h" #include "dialogs/ProgressDialog.h" #include "dialogs/ModEditDialogCommon.h" #include "minecraft/ModList.h" #include "minecraft/LegacyInstance.h" #include "Env.h" +#include #include "MultiMC.h" #include @@ -147,7 +146,7 @@ void LegacyJarModPage::on_rmJarBtn_clicked() void LegacyJarModPage::on_viewJarBtn_clicked() { - openDirInDefaultProgram(m_inst->jarModsDir(), true); + FS::openDirInDefaultProgram(m_inst->jarModsDir(), true); } void LegacyJarModPage::jarCurrent(QModelIndex current, QModelIndex previous) diff --git a/application/pages/ModFolderPage.cpp b/application/pages/ModFolderPage.cpp index 9a2a43a4..e3ece5a6 100644 --- a/application/pages/ModFolderPage.cpp +++ b/application/pages/ModFolderPage.cpp @@ -22,8 +22,6 @@ #include #include -#include - #include "MultiMC.h" #include "dialogs/CustomMessageBox.h" #include "dialogs/ModEditDialogCommon.h" @@ -31,6 +29,7 @@ #include "minecraft/ModList.h" #include "minecraft/Mod.h" #include "minecraft/VersionFilterData.h" +#include ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr mods, QString id, QString iconName, QString displayName, QString helpPage, @@ -163,7 +162,7 @@ void ModFolderPage::on_rmModBtn_clicked() void ModFolderPage::on_viewModBtn_clicked() { - openDirInDefaultProgram(m_mods->dir().absolutePath(), true); + FS::openDirInDefaultProgram(m_mods->dir().absolutePath(), true); } void ModFolderPage::modCurrent(const QModelIndex ¤t, const QModelIndex &previous) diff --git a/application/pages/OtherLogsPage.cpp b/application/pages/OtherLogsPage.cpp index f1b59f1e..799f4f39 100644 --- a/application/pages/OtherLogsPage.cpp +++ b/application/pages/OtherLogsPage.cpp @@ -21,7 +21,7 @@ #include "GuiUtil.h" #include "RecursiveFileSystemWatcher.h" #include -#include +#include OtherLogsPage::OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent) : QWidget(parent), ui(new Ui::OtherLogsPage), m_path(path), m_fileFilter(fileFilter), @@ -83,7 +83,7 @@ void OtherLogsPage::on_selectLogBox_currentIndexChanged(const int index) file = ui->selectLogBox->itemText(index); } - if (file.isEmpty() || !QFile::exists(PathCombine(m_path, file))) + if (file.isEmpty() || !QFile::exists(FS::PathCombine(m_path, file))) { m_currentFile = QString(); ui->text->clear(); @@ -104,7 +104,7 @@ void OtherLogsPage::on_btnReload_clicked() setControlsEnabled(false); return; } - QFile file(PathCombine(m_path, m_currentFile)); + QFile file(FS::PathCombine(m_path, m_currentFile)); if (!file.open(QFile::ReadOnly)) { setControlsEnabled(false); @@ -174,7 +174,7 @@ void OtherLogsPage::on_btnDelete_clicked() { return; } - QFile file(PathCombine(m_path, m_currentFile)); + QFile file(FS::PathCombine(m_path, m_currentFile)); if (!file.remove()) { QMessageBox::critical(this, tr("Error"), tr("Unable to delete %1: %2") @@ -215,7 +215,7 @@ void OtherLogsPage::on_btnClean_clicked() QStringList failed; for(auto item: toDelete) { - QFile file(PathCombine(m_path, item)); + QFile file(FS::PathCombine(m_path, item)); if (!file.remove()) { failed.push_back(item); diff --git a/application/pages/ScreenshotsPage.cpp b/application/pages/ScreenshotsPage.cpp index 2a8d7a43..5f5d11f7 100644 --- a/application/pages/ScreenshotsPage.cpp +++ b/application/pages/ScreenshotsPage.cpp @@ -15,7 +15,6 @@ #include #include -#include #include #include "dialogs/ProgressDialog.h" @@ -26,6 +25,7 @@ #include "tasks/SequentialTask.h" #include "RWStorage.h" +#include typedef RWStorage SharedIconCache; typedef std::shared_ptr SharedIconCachePtr; @@ -219,7 +219,7 @@ ScreenshotsPage::ScreenshotsPage(QString path, QWidget *parent) m_model->setNameFilters({"*.png"}); m_model->setNameFilterDisables(false); m_folder = path; - m_valid = ensureFolderPathExists(m_folder); + m_valid = FS::ensureFolderPathExists(m_folder); ui->setupUi(this); ui->tabWidget->tabBar()->hide(); @@ -271,12 +271,12 @@ void ScreenshotsPage::onItemActivated(QModelIndex index) return; auto info = m_model->fileInfo(index); QString fileName = info.absoluteFilePath(); - openFileInDefaultProgram(info.absoluteFilePath()); + FS::openFileInDefaultProgram(info.absoluteFilePath()); } void ScreenshotsPage::on_viewFolderBtn_clicked() { - openDirInDefaultProgram(m_folder, true); + FS::openDirInDefaultProgram(m_folder, true); } void ScreenshotsPage::on_uploadBtn_clicked() diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp index e6933da7..e1abcf0c 100644 --- a/application/pages/VersionPage.cpp +++ b/application/pages/VersionPage.cpp @@ -15,7 +15,6 @@ #include "MultiMC.h" -#include #include #include #include diff --git a/application/pages/WorldListPage.cpp b/application/pages/WorldListPage.cpp index 6bea9dbd..4e7eeedc 100644 --- a/application/pages/WorldListPage.cpp +++ b/application/pages/WorldListPage.cpp @@ -16,6 +16,7 @@ #include "WorldListPage.h" #include "ui_WorldListPage.h" #include "minecraft/WorldList.h" +#include #include "dialogs/ModEditDialogCommon.h" #include #include @@ -122,7 +123,7 @@ void WorldListPage::on_rmWorldBtn_clicked() void WorldListPage::on_viewFolderBtn_clicked() { - openDirInDefaultProgram(m_worlds->dir().absolutePath(), true); + FS::openDirInDefaultProgram(m_worlds->dir().absolutePath(), true); } QModelIndex WorldListPage::getSelectedWorld() diff --git a/application/pages/WorldListPage.h b/application/pages/WorldListPage.h index 1ef441a6..7a7cf591 100644 --- a/application/pages/WorldListPage.h +++ b/application/pages/WorldListPage.h @@ -20,7 +20,6 @@ #include "minecraft/OneSixInstance.h" #include "BasePage.h" #include -#include class WorldList; namespace Ui diff --git a/application/pages/global/ExternalToolsPage.cpp b/application/pages/global/ExternalToolsPage.cpp index 26b2f31e..e8091dee 100644 --- a/application/pages/global/ExternalToolsPage.cpp +++ b/application/pages/global/ExternalToolsPage.cpp @@ -20,10 +20,9 @@ #include #include -#include - #include "settings/SettingsObject.h" #include "tools/BaseProfiler.h" +#include #include "MultiMC.h" ExternalToolsPage::ExternalToolsPage(QWidget *parent) : @@ -91,7 +90,7 @@ void ExternalToolsPage::on_jprofilerPathBtn_clicked() { break; } - QString cooked_dir = NormalizePath(raw_dir); + QString cooked_dir = FS::NormalizePath(raw_dir); if (!MMC->profilers()["jprofiler"]->check(cooked_dir, &error)) { QMessageBox::critical(this, tr("Error"), @@ -130,7 +129,7 @@ void ExternalToolsPage::on_jvisualvmPathBtn_clicked() { break; } - QString cooked_dir = NormalizePath(raw_dir); + QString cooked_dir = FS::NormalizePath(raw_dir); if (!MMC->profilers()["jvisualvm"]->check(cooked_dir, &error)) { QMessageBox::critical(this, tr("Error"), @@ -174,7 +173,7 @@ void ExternalToolsPage::on_mceditPathBtn_clicked() { break; } - QString cooked_dir = NormalizePath(raw_dir); + QString cooked_dir = FS::NormalizePath(raw_dir); if (!MMC->tools()["mcedit"]->check(cooked_dir, &error)) { QMessageBox::critical(this, tr("Error"), @@ -213,7 +212,7 @@ void ExternalToolsPage::on_jsonEditorBrowseBtn_clicked() ? QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).first() #endif : ui->jsonEditorTextBox->text()); - QString cooked_file = NormalizePath(raw_file); + QString cooked_file = FS::NormalizePath(raw_file); if (cooked_file.isEmpty()) { diff --git a/application/pages/global/JavaPage.cpp b/application/pages/global/JavaPage.cpp index 18882ad9..1c33a9ff 100644 --- a/application/pages/global/JavaPage.cpp +++ b/application/pages/global/JavaPage.cpp @@ -21,8 +21,6 @@ #include #include -#include - #include "dialogs/VersionSelectDialog.h" #include @@ -30,6 +28,7 @@ #include "java/JavaVersionList.h" #include "settings/SettingsObject.h" +#include #include "MultiMC.h" JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage) @@ -109,7 +108,7 @@ void JavaPage::on_javaDetectBtn_clicked() void JavaPage::on_javaBrowseBtn_clicked() { QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable")); - QString cooked_path = NormalizePath(raw_path); + QString cooked_path = FS::NormalizePath(raw_path); // do not allow current dir - it's dirty. Do not allow dirs that don't exist if(cooked_path.isEmpty()) diff --git a/application/pages/global/MinecraftPage.cpp b/application/pages/global/MinecraftPage.cpp index 3e05924e..3f1e4388 100644 --- a/application/pages/global/MinecraftPage.cpp +++ b/application/pages/global/MinecraftPage.cpp @@ -19,8 +19,6 @@ #include #include -#include - #include "settings/SettingsObject.h" #include "MultiMC.h" diff --git a/application/pages/global/MultiMCPage.cpp b/application/pages/global/MultiMCPage.cpp index 6a8730c7..5b7a1204 100644 --- a/application/pages/global/MultiMCPage.cpp +++ b/application/pages/global/MultiMCPage.cpp @@ -21,11 +21,11 @@ #include #include -#include #include #include "updater/UpdateChecker.h" #include "settings/SettingsObject.h" +#include #include "MultiMC.h" // FIXME: possibly move elsewhere @@ -85,7 +85,7 @@ void MultiMCPage::on_ftbLauncherBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("FTB Launcher Directory"), ui->ftbLauncherBox->text()); - QString cooked_dir = NormalizePath(raw_dir); + QString cooked_dir = FS::NormalizePath(raw_dir); // do not allow current dir - it's dirty. Do not allow dirs that don't exist if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) @@ -97,7 +97,7 @@ void MultiMCPage::on_ftbBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("FTB Directory"), ui->ftbBox->text()); - QString cooked_dir = NormalizePath(raw_dir); + QString cooked_dir = FS::NormalizePath(raw_dir); // do not allow current dir - it's dirty. Do not allow dirs that don't exist if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) @@ -110,12 +110,12 @@ void MultiMCPage::on_instDirBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Instance Directory"), ui->instDirTextBox->text()); - QString cooked_dir = NormalizePath(raw_dir); + QString cooked_dir = FS::NormalizePath(raw_dir); // do not allow current dir - it's dirty. Do not allow dirs that don't exist if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) { - if (checkProblemticPathJava(QDir(cooked_dir))) + if (FS::checkProblemticPathJava(QDir(cooked_dir))) { QMessageBox warning; warning.setText(tr("You're trying to specify an instance folder which\'s path " @@ -143,7 +143,7 @@ void MultiMCPage::on_iconsDirBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Icons Directory"), ui->iconsDirTextBox->text()); - QString cooked_dir = NormalizePath(raw_dir); + QString cooked_dir = FS::NormalizePath(raw_dir); // do not allow current dir - it's dirty. Do not allow dirs that don't exist if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) @@ -155,7 +155,7 @@ void MultiMCPage::on_modsDirBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Mods Directory"), ui->modsDirTextBox->text()); - QString cooked_dir = NormalizePath(raw_dir); + QString cooked_dir = FS::NormalizePath(raw_dir); // do not allow current dir - it's dirty. Do not allow dirs that don't exist if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) @@ -167,7 +167,7 @@ void MultiMCPage::on_lwjglDirBrowseBtn_clicked() { QString raw_dir = QFileDialog::getExistingDirectory(this, tr("LWJGL Directory"), ui->lwjglDirTextBox->text()); - QString cooked_dir = NormalizePath(raw_dir); + QString cooked_dir = FS::NormalizePath(raw_dir); // do not allow current dir - it's dirty. Do not allow dirs that don't exist if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) @@ -308,8 +308,8 @@ void MultiMCPage::applySettings() // FTB s->set("TrackFTBInstances", ui->trackFtbBox->isChecked()); - s->set("FTBLauncherLocal", NormalizePath(ui->ftbLauncherBox->text())); - s->set("FTBRoot", NormalizePath(ui->ftbBox->text())); + s->set("FTBLauncherLocal", FS::NormalizePath(ui->ftbLauncherBox->text())); + s->set("FTBRoot", FS::NormalizePath(ui->ftbBox->text())); // Folders // TODO: Offer to move instances to new instance folder. diff --git a/application/pages/global/PasteEEPage.cpp b/application/pages/global/PasteEEPage.cpp index e6827601..15ceafe0 100644 --- a/application/pages/global/PasteEEPage.cpp +++ b/application/pages/global/PasteEEPage.cpp @@ -20,8 +20,6 @@ #include #include -#include - #include "settings/SettingsObject.h" #include "tools/BaseProfiler.h" #include "MultiMC.h" diff --git a/depends/util/CMakeLists.txt b/depends/util/CMakeLists.txt deleted file mode 100644 index e8646e1c..00000000 --- a/depends/util/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -project(MultiMC_util) - -include(Coverage) - -# Find Qt -find_package(Qt5Core REQUIRED) -find_package(Qt5Gui REQUIRED) - -set(LIBUTIL_SOURCES - src/pathutils.cpp - src/userutils.cpp - src/cmdutils.cpp - src/modutils.cpp - include/cmdutils.h - include/modutils.h - include/osutils.h - include/pathutils.h - include/userutils.h -) - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -add_library(MultiMC_util STATIC ${LIBUTIL_SOURCES}) - -qt5_use_modules(MultiMC_util Core Gui) -generate_export_header(MultiMC_util) -target_include_directories(MultiMC_util PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include) -set_property(TARGET MultiMC_util PROPERTY CXX_STANDARD 14) diff --git a/depends/util/include/cmdutils.h b/depends/util/include/cmdutils.h deleted file mode 100644 index 8bf39eaa..00000000 --- a/depends/util/include/cmdutils.h +++ /dev/null @@ -1,255 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Authors: Orochimarufan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include -#include -#include -#include - -#include "multimc_util_export.h" - -/** - * @file libutil/include/cmdutils.h - * @brief commandline parsing and processing utilities - */ - -namespace Util -{ -namespace Commandline -{ - -/** - * @brief split a string into argv items like a shell would do - * @param args the argument string - * @return a QStringList containing all arguments - */ -MULTIMC_UTIL_EXPORT QStringList splitArgs(QString args); - -/** - * @brief The FlagStyle enum - * Specifies how flags are decorated - */ - -namespace FlagStyle -{ -enum Enum -{ - GNU, /**< --option and -o (GNU Style) */ - Unix, /**< -option and -o (Unix Style) */ - Windows, /**< /option and /o (Windows Style) */ -#ifdef Q_OS_WIN32 - Default = Windows -#else - Default = GNU -#endif -}; -} - -/** - * @brief The ArgumentStyle enum - */ -namespace ArgumentStyle -{ -enum Enum -{ - Space, /**< --option=value */ - Equals, /**< --option value */ - SpaceAndEquals, /**< --option[= ]value */ -#ifdef Q_OS_WIN32 - Default = Equals -#else - Default = SpaceAndEquals -#endif -}; -} - -/** - * @brief The ParsingError class - */ -class MULTIMC_UTIL_EXPORT ParsingError : public std::runtime_error -{ -public: - ParsingError(const QString &what); -}; - -/** - * @brief The Parser class - */ -class MULTIMC_UTIL_EXPORT Parser -{ -public: - /** - * @brief Parser constructor - * @param flagStyle the FlagStyle to use in this Parser - * @param argStyle the ArgumentStyle to use in this Parser - */ - Parser(FlagStyle::Enum flagStyle = FlagStyle::Default, - ArgumentStyle::Enum argStyle = ArgumentStyle::Default); - - /** - * @brief set the flag style - * @param style - */ - void setFlagStyle(FlagStyle::Enum style); - - /** - * @brief get the flag style - * @return - */ - FlagStyle::Enum flagStyle(); - - /** - * @brief set the argument style - * @param style - */ - void setArgumentStyle(ArgumentStyle::Enum style); - - /** - * @brief get the argument style - * @return - */ - ArgumentStyle::Enum argumentStyle(); - - /** - * @brief define a boolean switch - * @param name the parameter name - * @param def the default value - */ - void addSwitch(QString name, bool def = false); - - /** - * @brief define an option that takes an additional argument - * @param name the parameter name - * @param def the default value - */ - void addOption(QString name, QVariant def = QVariant()); - - /** - * @brief define a positional argument - * @param name the parameter name - * @param required wether this argument is required - * @param def the default value - */ - void addArgument(QString name, bool required = true, QVariant def = QVariant()); - - /** - * @brief adds a flag to an existing parameter - * @param name the (existing) parameter name - * @param flag the flag character - * @see addSwitch addArgument addOption - * Note: any one parameter can only have one flag - */ - void addShortOpt(QString name, QChar flag); - - /** - * @brief adds documentation to a Parameter - * @param name the parameter name - * @param metavar a string to be displayed as placeholder for the value - * @param doc a QString containing the documentation - * Note: on positional arguments, metavar replaces the name as displayed. - * on options , metavar replaces the value placeholder - */ - void addDocumentation(QString name, QString doc, QString metavar = QString()); - - /** - * @brief generate a help message - * @param progName the program name to use in the help message - * @param helpIndent how much the parameter documentation should be indented - * @param flagsInUsage whether we should use flags instead of options in the usage - * @return a help message - */ - QString compileHelp(QString progName, int helpIndent = 22, bool flagsInUsage = true); - - /** - * @brief generate a short usage message - * @param progName the program name to use in the usage message - * @param useFlags whether we should use flags instead of options - * @return a usage message - */ - QString compileUsage(QString progName, bool useFlags = true); - - /** - * @brief parse - * @param argv a QStringList containing the program ARGV - * @return a QHash mapping argument names to their values - */ - QHash parse(QStringList argv); - - /** - * @brief clear all definitions - */ - void clear(); - - ~Parser(); - -private: - FlagStyle::Enum m_flagStyle; - ArgumentStyle::Enum m_argStyle; - - enum OptionType - { - otSwitch, - otOption - }; - - // Important: the common part MUST BE COMMON ON ALL THREE structs - struct CommonDef - { - QString name; - QString doc; - QString metavar; - QVariant def; - }; - - struct OptionDef - { - // common - QString name; - QString doc; - QString metavar; - QVariant def; - // option - OptionType type; - QChar flag; - }; - - struct PositionalDef - { - // common - QString name; - QString doc; - QString metavar; - QVariant def; - // positional - bool required; - }; - - QHash m_options; - QHash m_flags; - QHash m_params; - QList m_positionals; - QList m_optionList; - - void getPrefix(QString &opt, QString &flag); -}; -} -} diff --git a/depends/util/include/modutils.h b/depends/util/include/modutils.h deleted file mode 100644 index fde51881..00000000 --- a/depends/util/include/modutils.h +++ /dev/null @@ -1,113 +0,0 @@ -#pragma once - -#include -#include - -#include "multimc_util_export.h" - -class QUrl; - -namespace Util -{ -struct Version -{ - Version(const QString &str); - Version() {} - - bool operator<(const Version &other) const; - bool operator<=(const Version &other) const; - bool operator>(const Version &other) const; - bool operator>=(const Version &other) const; - bool operator==(const Version &other) const; - bool operator!=(const Version &other) const; - - QString toString() const - { - return m_string; - } - -private: - QString m_string; - struct Section - { - explicit Section(const QString &fullString) - { - m_fullString = fullString; - int cutoff = m_fullString.size(); - for(int i = 0; i < m_fullString.size(); i++) - { - if(!m_fullString[i].isDigit()) - { - cutoff = i; - break; - } - } - auto numPart = m_fullString.leftRef(cutoff); - if(numPart.size()) - { - numValid = true; - m_numPart = numPart.toInt(); - } - auto stringPart = m_fullString.midRef(cutoff); - if(stringPart.size()) - { - m_stringPart = stringPart.toString(); - } - } - explicit Section() {} - bool numValid = false; - int m_numPart = 0; - QString m_stringPart; - QString m_fullString; - - inline bool operator!=(const Section &other) const - { - if(numValid && other.numValid) - { - return m_numPart != other.m_numPart || m_stringPart != other.m_stringPart; - } - else - { - return m_fullString != other.m_fullString; - } - } - inline bool operator<(const Section &other) const - { - if(numValid && other.numValid) - { - if(m_numPart < other.m_numPart) - return true; - if(m_numPart == other.m_numPart && m_stringPart < other.m_stringPart) - return true; - return false; - } - else - { - return m_fullString < other.m_fullString; - } - } - inline bool operator>(const Section &other) const - { - if(numValid && other.numValid) - { - if(m_numPart > other.m_numPart) - return true; - if(m_numPart == other.m_numPart && m_stringPart > other.m_stringPart) - return true; - return false; - } - else - { - return m_fullString > other.m_fullString; - } - } - }; - QList
m_sections; - - void parse(); -}; - -MULTIMC_UTIL_EXPORT bool versionIsInInterval(const QString &version, const QString &interval); -MULTIMC_UTIL_EXPORT bool versionIsInInterval(const Version &version, const QString &interval); -} - diff --git a/depends/util/include/osutils.h b/depends/util/include/osutils.h deleted file mode 100644 index d6875e45..00000000 --- a/depends/util/include/osutils.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#if defined _WIN32 | defined _WIN64 -#define WINDOWS 1 -#elif __APPLE__ &__MACH__ -#define OSX 1 -#elif __linux__ -#define LINUX 1 -#endif diff --git a/depends/util/include/pathutils.h b/depends/util/include/pathutils.h deleted file mode 100644 index ff23fa5d..00000000 --- a/depends/util/include/pathutils.h +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include "multimc_util_export.h" - -MULTIMC_UTIL_EXPORT QString PathCombine(QString path1, QString path2); -MULTIMC_UTIL_EXPORT QString PathCombine(QString path1, QString path2, QString path3); - -MULTIMC_UTIL_EXPORT QString AbsolutePath(QString path); - -/** - * Resolve an executable - * - * Will resolve: - * single executable (by name) - * relative path - * absolute path - * - * @return absolute path to executable or null string - */ -MULTIMC_UTIL_EXPORT QString ResolveExecutable(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) - */ -MULTIMC_UTIL_EXPORT QString NormalizePath(QString path); - -MULTIMC_UTIL_EXPORT QString RemoveInvalidFilenameChars(QString string, QChar replaceWith = '-'); - -MULTIMC_UTIL_EXPORT QString DirNameFromString(QString string, QString inDir = "."); - -/** - * Creates all the folders in a path for the specified path - * last segment of the path is treated as a file name and is ignored! - */ -MULTIMC_UTIL_EXPORT bool ensureFilePathExists(QString filenamepath); - -/** - * Creates all the folders in a path for the specified path - * last segment of the path is treated as a folder name and is created! - */ -MULTIMC_UTIL_EXPORT bool ensureFolderPathExists(QString filenamepath); - -/** - * Copy a folder recursively - */ -MULTIMC_UTIL_EXPORT bool copyPath(const QString &src, const QString &dst, bool follow_symlinks = true); - -/** - * Delete a folder recursively - */ -MULTIMC_UTIL_EXPORT bool deletePath(QString path); - -/// Opens the given file in the default application. -MULTIMC_UTIL_EXPORT void openFileInDefaultProgram(QString filename); - -/// Opens the given directory in the default application. -MULTIMC_UTIL_EXPORT void openDirInDefaultProgram(QString dirpath, bool ensureExists = false); - -/// Checks if the a given Path contains "!" -MULTIMC_UTIL_EXPORT bool checkProblemticPathJava(QDir folder); diff --git a/depends/util/include/userutils.h b/depends/util/include/userutils.h deleted file mode 100644 index aadc112e..00000000 --- a/depends/util/include/userutils.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include - -#include "multimc_util_export.h" - -namespace Util -{ -// Get the Directory representing the User's Desktop -MULTIMC_UTIL_EXPORT QString getDesktopDir(); - -// Create a shortcut at *location*, pointing to *dest* called with the arguments *args* -// call it *name* and assign it the icon *icon* -// return true if operation succeeded -MULTIMC_UTIL_EXPORT bool createShortCut(QString location, QString dest, QStringList args, - QString name, QString iconLocation); -} diff --git a/depends/util/src/cmdutils.cpp b/depends/util/src/cmdutils.cpp deleted file mode 100644 index ab4e6229..00000000 --- a/depends/util/src/cmdutils.cpp +++ /dev/null @@ -1,486 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Authors: Orochimarufan - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "include/cmdutils.h" - -/** - * @file libutil/src/cmdutils.cpp - */ - -namespace Util -{ -namespace Commandline -{ - -// commandline splitter -QStringList splitArgs(QString args) -{ - QStringList argv; - QString current; - bool escape = false; - QChar inquotes; - for (int i = 0; i < args.length(); i++) - { - QChar cchar = args.at(i); - - // \ escaped - if (escape) - { - current += cchar; - escape = false; - // in "quotes" - } - else if (!inquotes.isNull()) - { - if (cchar == 0x5C) - escape = true; - else if (cchar == inquotes) - inquotes = 0; - else - current += cchar; - // otherwise - } - else - { - if (cchar == 0x20) - { - if (!current.isEmpty()) - { - argv << current; - current.clear(); - } - } - else if (cchar == 0x22 || cchar == 0x27) - inquotes = cchar; - else - current += cchar; - } - } - if (!current.isEmpty()) - argv << current; - return argv; -} - -Parser::Parser(FlagStyle::Enum flagStyle, ArgumentStyle::Enum argStyle) -{ - m_flagStyle = flagStyle; - m_argStyle = argStyle; -} - -// styles setter/getter -void Parser::setArgumentStyle(ArgumentStyle::Enum style) -{ - m_argStyle = style; -} -ArgumentStyle::Enum Parser::argumentStyle() -{ - return m_argStyle; -} - -void Parser::setFlagStyle(FlagStyle::Enum style) -{ - m_flagStyle = style; -} -FlagStyle::Enum Parser::flagStyle() -{ - return m_flagStyle; -} - -// setup methods -void Parser::addSwitch(QString name, bool def) -{ - if (m_params.contains(name)) - throw "Name not unique"; - - OptionDef *param = new OptionDef; - param->type = otSwitch; - param->name = name; - param->metavar = QString("<%1>").arg(name); - param->def = def; - - m_options[name] = param; - m_params[name] = (CommonDef *)param; - m_optionList.append(param); -} - -void Parser::addOption(QString name, QVariant def) -{ - if (m_params.contains(name)) - throw "Name not unique"; - - OptionDef *param = new OptionDef; - param->type = otOption; - param->name = name; - param->metavar = QString("<%1>").arg(name); - param->def = def; - - m_options[name] = param; - m_params[name] = (CommonDef *)param; - m_optionList.append(param); -} - -void Parser::addArgument(QString name, bool required, QVariant def) -{ - if (m_params.contains(name)) - throw "Name not unique"; - - PositionalDef *param = new PositionalDef; - param->name = name; - param->def = def; - param->required = required; - param->metavar = name; - - m_positionals.append(param); - m_params[name] = (CommonDef *)param; -} - -void Parser::addDocumentation(QString name, QString doc, QString metavar) -{ - if (!m_params.contains(name)) - throw "Name does not exist"; - - CommonDef *param = m_params[name]; - param->doc = doc; - if (!metavar.isNull()) - param->metavar = metavar; -} - -void Parser::addShortOpt(QString name, QChar flag) -{ - if (!m_params.contains(name)) - throw "Name does not exist"; - if (!m_options.contains(name)) - throw "Name is not an Option or Swtich"; - - OptionDef *param = m_options[name]; - m_flags[flag] = param; - param->flag = flag; -} - -// help methods -QString Parser::compileHelp(QString progName, int helpIndent, bool useFlags) -{ - QStringList help; - help << compileUsage(progName, useFlags) << "\r\n"; - - // positionals - if (!m_positionals.isEmpty()) - { - help << "\r\n"; - help << "Positional arguments:\r\n"; - QListIterator it2(m_positionals); - while (it2.hasNext()) - { - PositionalDef *param = it2.next(); - help << " " << param->metavar; - help << " " << QString(helpIndent - param->metavar.length() - 1, ' '); - help << param->doc << "\r\n"; - } - } - - // Options - if (!m_optionList.isEmpty()) - { - help << "\r\n"; - QString optPrefix, flagPrefix; - getPrefix(optPrefix, flagPrefix); - - help << "Options & Switches:\r\n"; - QListIterator it(m_optionList); - while (it.hasNext()) - { - OptionDef *option = it.next(); - help << " "; - int nameLength = optPrefix.length() + option->name.length(); - if (!option->flag.isNull()) - { - nameLength += 3 + flagPrefix.length(); - help << flagPrefix << option->flag << ", "; - } - help << optPrefix << option->name; - if (option->type == otOption) - { - QString arg = QString("%1%2").arg( - ((m_argStyle == ArgumentStyle::Equals) ? "=" : " "), option->metavar); - nameLength += arg.length(); - help << arg; - } - help << " " << QString(helpIndent - nameLength - 1, ' '); - help << option->doc << "\r\n"; - } - } - - return help.join(""); -} - -QString Parser::compileUsage(QString progName, bool useFlags) -{ - QStringList usage; - usage << "Usage: " << progName; - - QString optPrefix, flagPrefix; - getPrefix(optPrefix, flagPrefix); - - // options - QListIterator it(m_optionList); - while (it.hasNext()) - { - OptionDef *option = it.next(); - usage << " ["; - if (!option->flag.isNull() && useFlags) - usage << flagPrefix << option->flag; - else - usage << optPrefix << option->name; - if (option->type == otOption) - usage << ((m_argStyle == ArgumentStyle::Equals) ? "=" : " ") << option->metavar; - usage << "]"; - } - - // arguments - QListIterator it2(m_positionals); - while (it2.hasNext()) - { - PositionalDef *param = it2.next(); - usage << " " << (param->required ? "<" : "["); - usage << param->metavar; - usage << (param->required ? ">" : "]"); - } - - return usage.join(""); -} - -// parsing -QHash Parser::parse(QStringList argv) -{ - QHash map; - - QStringListIterator it(argv); - QString programName = it.next(); - - QString optionPrefix; - QString flagPrefix; - QListIterator positionals(m_positionals); - QStringList expecting; - - getPrefix(optionPrefix, flagPrefix); - - while (it.hasNext()) - { - QString arg = it.next(); - - if (!expecting.isEmpty()) - // we were expecting an argument - { - QString name = expecting.first(); -/* - if (map.contains(name)) - throw ParsingError( - QString("Option %2%1 was given multiple times").arg(name, optionPrefix)); -*/ - map[name] = QVariant(arg); - - expecting.removeFirst(); - continue; - } - - if (arg.startsWith(optionPrefix)) - // we have an option - { - // qDebug("Found option %s", qPrintable(arg)); - - QString name = arg.mid(optionPrefix.length()); - QString equals; - - if ((m_argStyle == ArgumentStyle::Equals || - m_argStyle == ArgumentStyle::SpaceAndEquals) && - name.contains("=")) - { - int i = name.indexOf("="); - equals = name.mid(i + 1); - name = name.left(i); - } - - if (m_options.contains(name)) - { - /* - if (map.contains(name)) - throw ParsingError(QString("Option %2%1 was given multiple times") - .arg(name, optionPrefix)); -*/ - OptionDef *option = m_options[name]; - if (option->type == otSwitch) - map[name] = true; - else // if (option->type == otOption) - { - if (m_argStyle == ArgumentStyle::Space) - expecting.append(name); - else if (!equals.isNull()) - map[name] = equals; - else if (m_argStyle == ArgumentStyle::SpaceAndEquals) - expecting.append(name); - else - throw ParsingError(QString("Option %2%1 reqires an argument.") - .arg(name, optionPrefix)); - } - - continue; - } - - throw ParsingError(QString("Unknown Option %2%1").arg(name, optionPrefix)); - } - - if (arg.startsWith(flagPrefix)) - // we have (a) flag(s) - { - // qDebug("Found flags %s", qPrintable(arg)); - - QString flags = arg.mid(flagPrefix.length()); - QString equals; - - if ((m_argStyle == ArgumentStyle::Equals || - m_argStyle == ArgumentStyle::SpaceAndEquals) && - flags.contains("=")) - { - int i = flags.indexOf("="); - equals = flags.mid(i + 1); - flags = flags.left(i); - } - - for (int i = 0; i < flags.length(); i++) - { - QChar flag = flags.at(i); - - if (!m_flags.contains(flag)) - throw ParsingError(QString("Unknown flag %2%1").arg(flag, flagPrefix)); - - OptionDef *option = m_flags[flag]; -/* - if (map.contains(option->name)) - throw ParsingError(QString("Option %2%1 was given multiple times") - .arg(option->name, optionPrefix)); -*/ - if (option->type == otSwitch) - map[option->name] = true; - else // if (option->type == otOption) - { - if (m_argStyle == ArgumentStyle::Space) - expecting.append(option->name); - else if (!equals.isNull()) - if (i == flags.length() - 1) - map[option->name] = equals; - else - throw ParsingError(QString("Flag %4%2 of Argument-requiring Option " - "%1 not last flag in %4%3") - .arg(option->name, flag, flags, flagPrefix)); - else if (m_argStyle == ArgumentStyle: