From f93f867c3da084c6d6c5e3ed23896609cff0e692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= 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::SpaceAndEquals) - expecting.append(option->name); - else - throw ParsingError(QString("Option %1 reqires an argument. (flag %3%2)") - .arg(option->name, flag, flagPrefix)); - } - } - - continue; - } - - // must be a positional argument - if (!positionals.hasNext()) - throw ParsingError(QString("Don't know what to do with '%1'").arg(arg)); - - PositionalDef *param = positionals.next(); - - map[param->name] = arg; - } - - // check if we're missing something - if (!expecting.isEmpty()) - throw ParsingError(QString("Was still expecting arguments for %2%1").arg( - expecting.join(QString(", ") + optionPrefix), optionPrefix)); - - while (positionals.hasNext()) - { - PositionalDef *param = positionals.next(); - if (param->required) - throw ParsingError( - QString("Missing required positional argument '%1'").arg(param->name)); - else - map[param->name] = param->def; - } - - // fill out gaps - QListIterator iter(m_optionList); - while (iter.hasNext()) - { - OptionDef *option = iter.next(); - if (!map.contains(option->name)) - map[option->name] = option->def; - } - - return map; -} - -// clear defs -void Parser::clear() -{ - m_flags.clear(); - m_params.clear(); - m_options.clear(); - - QMutableListIterator it(m_optionList); - while (it.hasNext()) - { - OptionDef *option = it.next(); - it.remove(); - delete option; - } - - QMutableListIterator it2(m_positionals); - while (it2.hasNext()) - { - PositionalDef *arg = it2.next(); - it2.remove(); - delete arg; - } -} - -// Destructor -Parser::~Parser() -{ - clear(); -} - -// getPrefix -void Parser::getPrefix(QString &opt, QString &flag) -{ - if (m_flagStyle == FlagStyle::Windows) - opt = flag = "/"; - else if (m_flagStyle == FlagStyle::Unix) - opt = flag = "-"; - // else if (m_flagStyle == FlagStyle::GNU) - else - { - opt = "--"; - flag = "-"; - } -} - -// ParsingError -ParsingError::ParsingError(const QString &what) : std::runtime_error(what.toStdString()) -{ -} -} -} diff --git a/depends/util/src/modutils.cpp b/depends/util/src/modutils.cpp deleted file mode 100644 index 5f89eacd..00000000 --- a/depends/util/src/modutils.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include "include/modutils.h" - -#include -#include -#include -#include - -Util::Version::Version(const QString &str) : m_string(str) -{ - parse(); -} - -bool Util::Version::operator<(const Version &other) const -{ - const int size = qMax(m_sections.size(), other.m_sections.size()); - for (int i = 0; i < size; ++i) - { - const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i); - const Section sec2 = - (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i); - if (sec1 != sec2) - { - return sec1 < sec2; - } - } - - return false; -} -bool Util::Version::operator<=(const Util::Version &other) const -{ - return *this < other || *this == other; -} -bool Util::Version::operator>(const Version &other) const -{ - const int size = qMax(m_sections.size(), other.m_sections.size()); - for (int i = 0; i < size; ++i) - { - const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i); - const Section sec2 = - (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i); - if (sec1 != sec2) - { - return sec1 > sec2; - } - } - - return false; -} -bool Util::Version::operator>=(const Version &other) const -{ - return *this > other || *this == other; -} -bool Util::Version::operator==(const Version &other) const -{ - const int size = qMax(m_sections.size(), other.m_sections.size()); - for (int i = 0; i < size; ++i) - { - const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i); - const Section sec2 = - (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i); - if (sec1 != sec2) - { - return false; - } - } - - return true; -} -bool Util::Version::operator!=(const Version &other) const -{ - return !operator==(other); -} - -void Util::Version::parse() -{ - m_sections.clear(); - - QStringList parts = m_string.split('.'); - - for (const auto part : parts) - { - m_sections.append(Section(part)); - } -} - -bool Util::versionIsInInterval(const QString &version, const QString &interval) -{ - return versionIsInInterval(Util::Version(version), interval); -} -bool Util::versionIsInInterval(const Version &version, const QString &interval) -{ - if (interval.isEmpty() || version.toString() == interval) - { - return true; - } - - // Interval notation is used - QRegularExpression exp( - "(?[\\[\\]\\(\\)])(?.*?)(,(?.*?))?(?[\\[\\]\\(\\)]),?"); - QRegularExpressionMatch match = exp.match(interval); - if (match.hasMatch()) - { - const QChar start = match.captured("start").at(0); - const QChar end = match.captured("end").at(0); - const QString bottom = match.captured("bottom"); - const QString top = match.captured("top"); - - // check if in range (bottom) - if (!bottom.isEmpty()) - { - const auto bottomVersion = Util::Version(bottom); - if ((start == '[') && !(version >= bottomVersion)) - { - return false; - } - else if ((start == '(') && !(version > bottomVersion)) - { - return false; - } - } - - // check if in range (top) - if (!top.isEmpty()) - { - const auto topVersion = Util::Version(top); - if ((end == ']') && !(version <= topVersion)) - { - return false; - } - else if ((end == ')') && !(version < topVersion)) - { - return false; - } - } - - return true; - } - - return false; -} - diff --git a/depends/util/src/pathutils.cpp b/depends/util/src/pathutils.cpp deleted file mode 100644 index af1843ba..00000000 --- a/depends/util/src/pathutils.cpp +++ /dev/null @@ -1,268 +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. - */ - -#include "include/pathutils.h" - -#include -#include -#include -#include -#include - -QString PathCombine(QString path1, QString path2) -{ - if(!path1.size()) - return path2; - if(!path2.size()) - return path1; - return QDir::cleanPath(path1 + QDir::separator() + path2); -} - -QString PathCombine(QString path1, QString path2, QString path3) -{ - return PathCombine(PathCombine(path1, path2), path3); -} - -QString AbsolutePath(QString path) -{ - return QFileInfo(path).absolutePath(); -} - -QString ResolveExecutable(QString path) -{ - if (path.isEmpty()) - { - return QString(); - } - if(!path.contains('/')) - { - path = QStandardPaths::findExecutable(path); - } - QFileInfo pathInfo(path); - if(!pathInfo.exists() || !pathInfo.isExecutable()) - { - return QString(); - } - return pathInfo.absoluteFilePath(); -} - -/** - * 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) -{ - for (int i = 0; i < string.length(); i++) - { - if (badFilenameChars.contains(string[i])) - { - string[i] = replaceWith; - } - } - return string; -} - -QString DirNameFromString(QString string, QString inDir) -{ - int num = 0; - QString baseName = RemoveInvalidFilenameChars(string, '-'); - QString dirName; - do - { - if(num == 0) - { - dirName = baseName; - } - else - { - dirName = baseName + QString::number(num);; - } - - // If it's over 9000 - if (num > 9000) - return ""; - num++; - } while (QFileInfo(PathCombine(inDir, dirName)).exists()); - return dirName; -} - -bool ensureFilePathExists(QString filenamepath) -{ - QFileInfo a(filenamepath); - QDir dir; - QString ensuredPath = a.path(); - bool success = dir.mkpath(ensuredPath); - return success; -} - -bool ensureFolderPathExists(QString foldernamepath) -{ - QFileInfo a(foldernamepath); - QDir dir; - QString ensuredPath = a.filePath(); - bool success = dir.mkpath(ensuredPath); - return success; -} - -bool copyPath(const QString &src, const QString &dst, bool follow_symlinks) -{ - //NOTE always deep copy on windows. the alternatives are too messy. - #if defined Q_OS_WIN32 - follow_symlinks = true; - #endif - - QDir dir(src); - if (!dir.exists()) - return false; - if (!ensureFolderPathExists(dst)) - return false; - - bool OK = true; - - qDebug() << "Looking at " << dir.absolutePath(); - foreach(QString f, dir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System)) - { - QString inner_src = src + QDir::separator() + f; - QString inner_dst = dst + QDir::separator() + f; - qDebug() << f << "translates to"<< inner_src << "to" << inner_dst; - QFileInfo fileInfo(inner_src); - if(!follow_symlinks && fileInfo.isSymLink()) - { - qDebug() << "creating symlink" << inner_src << " - " << inner_dst; - OK &= QFile::link(fileInfo.symLinkTarget(),inner_dst); - } - else if (fileInfo.isDir()) - { - qDebug() << "recursing" << inner_src << " - " << inner_dst; - OK &= copyPath(inner_src, inner_dst, follow_symlinks); - } - else if (fileInfo.isFile()) - { - qDebug() << "copying file" << inner_src << " - " << inner_dst; - OK &= QFile::copy(inner_src, inner_dst); - } - else - { - OK = false; - qCritical() << "Copy ERROR: Unknown filesystem object:" << inner_src; - } - } - return OK; -} -#if defined Q_OS_WIN32 -#include -#include -#endif -bool deletePath(QString path) -{ - bool OK = true; - QDir dir(path); - - if (!dir.exists()) - { - return OK; - } - auto allEntries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | - QDir::AllDirs | QDir::Files, - QDir::DirsFirst); - - for(QFileInfo info: allEntries) - { -#if defined Q_OS_WIN32 - QString nativePath = QDir::toNativeSeparators(info.absoluteFilePath()); - auto wString = nativePath.toStdWString(); - DWORD dwAttrs = GetFileAttributesW(wString.c_str()); - // Windows: check for junctions, reparse points and other nasty things of that sort - if(dwAttrs & FILE_ATTRIBUTE_REPARSE_POINT) - { - if (info.isFile()) - { - OK &= QFile::remove(info.absoluteFilePath()); - } - else if (info.isDir()) - { - OK &= dir.rmdir(info.absoluteFilePath()); - } - } -#else - // We do not trust Qt with reparse points, but do trust it with unix symlinks. - if(info.isSymLink()) - { - OK &= QFile::remove(info.absoluteFilePath()); - } -#endif - else if (info.isDir()) - { - OK &= deletePath(info.absoluteFilePath()); - } - else if (info.isFile()) - { - OK &= QFile::remove(info.absoluteFilePath()); - } - else - { - OK = false; - qCritical() << "Delete ERROR: Unknown filesystem object:" << info.absoluteFilePath(); - } - } - OK &= dir.rmdir(dir.absolutePath()); - return OK; -} - -void openDirInDefaultProgram(QString path, bool ensureExists) -{ - QDir parentPath; - QDir dir(path); - if (!dir.exists()) - { - parentPath.mkpath(dir.absolutePath()); - } - QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath())); -} - -void openFileInDefaultProgram(QString filename) -{ - QDesktopServices::openUrl(QUrl::fromLocalFile(filename)); -} - -// Does the directory path contain any '!'? If yes, return true, otherwise false. -// (This is a problem for Java) -bool checkProblemticPathJava(QDir folder) -{ - QString pathfoldername = folder.absolutePath(); - return pathfoldername.contains("!", Qt::CaseInsensitive); -} diff --git a/depends/util/src/userutils.cpp b/depends/util/src/userutils.cpp deleted file mode 100644 index a26af5af..00000000 --- a/depends/util/src/userutils.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include "include/userutils.h" - -#include -#include -#include - -#include "include/osutils.h" -#include "include/pathutils.h" - -// Win32 crap -#if WINDOWS - -#include -#include -#include -#include -#include -#include -#include - -bool called_coinit = false; - -HRESULT CreateLink(LPCSTR linkPath, LPCSTR targetPath, LPCSTR args) -{ - HRESULT hres; - - if (!called_coinit) - { - hres = CoInitialize(NULL); - called_coinit = true; - - if (!SUCCEEDED(hres)) - { - qWarning("Failed to initialize COM. Error 0x%08X", hres); - return hres; - } - } - - IShellLink *link; - hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, - (LPVOID *)&link); - - if (SUCCEEDED(hres)) - { - IPersistFile *persistFile; - - link->SetPath(targetPath); - link->SetArguments(args); - - hres = link->QueryInterface(IID_IPersistFile, (LPVOID *)&persistFile); - if (SUCCEEDED(hres)) - { - WCHAR wstr[MAX_PATH]; - - MultiByteToWideChar(CP_ACP, 0, linkPath, -1, wstr, MAX_PATH); - - hres = persistFile->Save(wstr, TRUE); - persistFile->Release(); - } - link->Release(); - } - return hres; -} - -#endif - -QString Util::getDesktopDir() -{ - return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); -} - -// Cross-platform Shortcut creation -bool Util::createShortCut(QString location, QString dest, QStringList args, QString name, - QString icon) -{ -#if LINUX - location = PathCombine(location, name + ".desktop"); - - QFile f(location); - f.open(QIODevice::WriteOnly | QIODevice::Text); - QTextStream stream(&f); - - QString argstring; - if (!args.empty()) - argstring = " '" + args.join("' '") + "'"; - - stream << "[Desktop Entry]" - << "\n"; - stream << "Type=Application" - << "\n"; - stream << "TryExec=" << dest.toLocal8Bit() << "\n"; - stream << "Exec=" << dest.toLocal8Bit() << argstring.toLocal8Bit() << "\n"; - stream << "Name=" << name.toLocal8Bit() << "\n"; - stream << "Icon=" << icon.toLocal8Bit() << "\n"; - - stream.flush(); - f.close(); - - f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | - QFileDevice::ExeOther); - - return true; -#elif WINDOWS - // TODO: Fix - // QFile file(PathCombine(location, name + ".lnk")); - // WCHAR *file_w; - // WCHAR *dest_w; - // WCHAR *args_w; - // file.fileName().toWCharArray(file_w); - // dest.toWCharArray(dest_w); - - // QString argStr; - // for (int i = 0; i < args.count(); i++) - // { - // argStr.append(args[i]); - // argStr.append(" "); - // } - // argStr.toWCharArray(args_w); - - // return SUCCEEDED(CreateLink(file_w, dest_w, args_w)); - return false; -#else - qWarning("Desktop Shortcuts not supported on your platform!"); - return false; -#endif -} diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp index 02284d37..53e4ca6b 100644 --- a/logic/BaseInstance.cpp +++ b/logic/BaseInstance.cpp @@ -22,10 +22,10 @@ #include "settings/Setting.h" #include "settings/OverrideSetting.h" -#include "pathutils.h" -#include #include "minecraft/MinecraftVersionList.h" #include "icons/IconList.h" +#include "FileSystem.h" +#include "Commandline.h" BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) : QObject() @@ -78,7 +78,7 @@ void BaseInstance::iconUpdated(QString key) void BaseInstance::nuke() { - deletePath(instanceRoot()); + FS::deletePath(instanceRoot()); emit nuked(this); } @@ -268,5 +268,5 @@ QString BaseInstance::windowTitle() const QStringList BaseInstance::extraArguments() const { - return Util::Commandline::splitArgs(settings()->get("JvmArgs").toString()); + return Commandline::splitArgs(settings()->get("JvmArgs").toString()); } diff --git a/logic/CMakeLists.txt b/logic/CMakeLists.txt index 7e9ee1d1..6d03e3bd 100644 --- a/logic/CMakeLists.txt +++ b/logic/CMakeLists.txt @@ -65,6 +65,14 @@ set(LOGIC_SOURCES GZip.h GZip.cpp + # Command line parameter parsing + Commandline.h + Commandline.cpp + + # Version number string support + Version.h + Version.cpp + # network stuffs net/NetAction.h net/MD5EtagDownload.h @@ -312,7 +320,7 @@ set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISI generate_export_header(MultiMC_logic) # Link -target_link_libraries(MultiMC_logic xz-embedded unpack200 iconfix MultiMC_util LogicalGui ${QUAZIP_LIBRARIES} nbt++ ${ZLIB_LIBRARIES}) +target_link_libraries(MultiMC_logic xz-embedded unpack200 iconfix LogicalGui ${QUAZIP_LIBRARIES} nbt++ ${ZLIB_LIBRARIES}) qt5_use_modules(MultiMC_logic Core Xml Widgets Network Concurrent) add_dependencies(MultiMC_logic QuaZIP) diff --git a/logic/Commandline.cpp b/logic/Commandline.cpp new file mode 100644 index 00000000..9a8ddbf1 --- /dev/null +++ b/logic/Commandline.cpp @@ -0,0 +1,483 @@ +/* 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 "Commandline.h" + +/** + * @file libutil/src/cmdutils.cpp + */ + +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::SpaceAndEquals) + expecting.append(option->name); + else + throw ParsingError(QString("Option %1 reqires an argument. (flag %3%2)") + .arg(option->name, flag, flagPrefix)); + } + } + + continue; + } + + // must be a positional argument + if (!positionals.hasNext()) + throw ParsingError(QString("Don't know what to do with '%1'").arg(arg)); + + PositionalDef *param = positionals.next(); + + map[param->name] = arg; + } + + // check if we're missing something + if (!expecting.isEmpty()) + throw ParsingError(QString("Was still expecting arguments for %2%1").arg( + expecting.join(QString(", ") + optionPrefix), optionPrefix)); + + while (positionals.hasNext()) + { + PositionalDef *param = positionals.next(); + if (param->required) + throw ParsingError( + QString("Missing required positional argument '%1'").arg(param->name)); + else + map[param->name] = param->def; + } + + // fill out gaps + QListIterator iter(m_optionList); + while (iter.hasNext()) + { + OptionDef *option = iter.next(); + if (!map.contains(option->name)) + map[option->name] = option->def; + } + + return map; +} + +// clear defs +void Parser::clear() +{ + m_flags.clear(); + m_params.clear(); + m_options.clear(); + + QMutableListIterator it(m_optionList); + while (it.hasNext()) + { + OptionDef *option = it.next(); + it.remove(); + delete option; + } + + QMutableListIterator it2(m_positionals); + while (it2.hasNext()) + { + PositionalDef *arg = it2.next(); + it2.remove(); + delete arg; + } +} + +// Destructor +Parser::~Parser() +{ + clear(); +} + +// getPrefix +void Parser::getPrefix(QString &opt, QString &flag) +{ + if (m_flagStyle == FlagStyle::Windows) + opt = flag = "/"; + else if (m_flagStyle == FlagStyle::Unix) + opt = flag = "-"; + // else if (m_flagStyle == FlagStyle::GNU) + else + { + opt = "--"; + flag = "-"; + } +} + +// ParsingError +ParsingError::ParsingError(const QString &what) : std::runtime_error(what.toStdString()) +{ +} +} \ No newline at end of file diff --git a/logic/Commandline.h b/logic/Commandline.h new file mode 100644 index 00000000..bee02bad --- /dev/null +++ b/logic/Commandline.h @@ -0,0 +1,252 @@ +/* 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_logic_export.h" + +/** + * @file libutil/include/cmdutils.h + * @brief commandline parsing and processing utilities + */ + +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_LOGIC_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_LOGIC_EXPORT ParsingError : public std::runtime_error +{ +public: + ParsingError(const QString &what); +}; + +/** + * @brief The Parser class + */ +class MULTIMC_LOGIC_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/logic/FileSystem.cpp b/logic/FileSystem.cpp index b8d82c51..ca4a3ba0 100644 --- a/logic/FileSystem.cpp +++ b/logic/FileSystem.cpp @@ -5,6 +5,9 @@ #include #include #include +#include +#include +#include void ensureExists(const QDir &dir) { @@ -54,3 +57,372 @@ QByteArray FS::read(const QString &filename) } return data; } + +bool FS::ensureFilePathExists(QString filenamepath) +{ + QFileInfo a(filenamepath); + QDir dir; + QString ensuredPath = a.path(); + bool success = dir.mkpath(ensuredPath); + return success; +} + +bool FS::ensureFolderPathExists(QString foldernamepath) +{ + QFileInfo a(foldernamepath); + QDir dir; + QString ensuredPath = a.filePath(); + bool success = dir.mkpath(ensuredPath); + return success; +} + +bool FS::copyPath(const QString &src, const QString &dst, bool follow_symlinks) +{ + //NOTE always deep copy on windows. the alternatives are too messy. + #if defined Q_OS_WIN32 + follow_symlinks = true; + #endif + + QDir dir(src); + if (!dir.exists()) + return false; + if (!ensureFolderPathExists(dst)) + return false; + + bool OK = true; + + qDebug() << "Looking at " << dir.absolutePath(); + foreach(QString f, dir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System)) + { + QString inner_src = src + QDir::separator() + f; + QString inner_dst = dst + QDir::separator() + f; + qDebug() << f << "translates to"<< inner_src << "to" << inner_dst; + QFileInfo fileInfo(inner_src); + if(!follow_symlinks && fileInfo.isSymLink()) + { + qDebug() << "creating symlink" << inner_src << " - " << inner_dst; + OK &= QFile::link(fileInfo.symLinkTarget(),inner_dst); + } + else if (fileInfo.isDir()) + { + qDebug() << "recursing" << inner_src << " - " << inner_dst; + OK &= copyPath(inner_src, inner_dst, follow_symlinks); + } + else if (fileInfo.isFile()) + { + qDebug() << "copying file" << inner_src << " - " << inner_dst; + OK &= QFile::copy(inner_src, inner_dst); + } + else + { + OK = false; + qCritical() << "Copy ERROR: Unknown filesystem object:" << inner_src; + } + } + return OK; +} +#if defined Q_OS_WIN32 +#include +#include +#endif +bool FS::deletePath(QString path) +{ + bool OK = true; + QDir dir(path); + + if (!dir.exists()) + { + return OK; + } + auto allEntries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | + QDir::AllDirs | QDir::Files, + QDir::DirsFirst); + + for(QFileInfo info: allEntries) + { +#if defined Q_OS_WIN32 + QString nativePath = QDir::toNativeSeparators(info.absoluteFilePath()); + auto wString = nativePath.toStdWString(); + DWORD dwAttrs = GetFileAttributesW(wString.c_str()); + // Windows: check for junctions, reparse points and other nasty things of that sort + if(dwAttrs & FILE_ATTRIBUTE_REPARSE_POINT) + { + if (info.isFile()) + { + OK &= QFile::remove(info.absoluteFilePath()); + } + else if (info.isDir()) + { + OK &= dir.rmdir(info.absoluteFilePath()); + } + } +#else + // We do not trust Qt with reparse points, but do trust it with unix symlinks. + if(info.isSymLink()) + { + OK &= QFile::remove(info.absoluteFilePath()); + } +#endif + else if (info.isDir()) + { + OK &= deletePath(info.absoluteFilePath()); + } + else if (info.isFile()) + { + OK &= QFile::remove(info.absoluteFilePath()); + } + else + { + OK = false; + qCritical() << "Delete ERROR: Unknown filesystem object:" << info.absoluteFilePath(); + } + } + OK &= dir.rmdir(dir.absolutePath()); + return OK; +} + + +QString FS::PathCombine(QString path1, QString path2) +{ + if(!path1.size()) + return path2; + if(!path2.size()) + return path1; + return QDir::cleanPath(path1 + QDir::separator() + path2); +} + +QString FS::PathCombine(QString path1, QString path2, QString path3) +{ + return PathCombine(PathCombine(path1, path2), path3); +} + +QString FS::AbsolutePath(QString path) +{ + return QFileInfo(path).absolutePath(); +} + +QString FS::ResolveExecutable(QString path) +{ + if (path.isEmpty()) + { + return QString(); + } + if(!path.contains('/')) + { + path = QStandardPaths::findExecutable(path); + } + QFileInfo pathInfo(path); + if(!pathInfo.exists() || !pathInfo.isExecutable()) + { + return QString(); + } + return pathInfo.absoluteFilePath(); +} + +/** + * Normalize path + * + * Any paths inside the current directory will be normalized to relative paths (to current) + * Other paths will be made absolute + */ +QString FS::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 FS::RemoveInvalidFilenameChars(QString string, QChar replaceWith) +{ + for (int i = 0; i < string.length(); i++) + { + if (badFilenameChars.contains(string[i])) + { + string[i] = replaceWith; + } + } + return string; +} + +QString FS::DirNameFromString(QString string, QString inDir) +{ + int num = 0; + QString baseName = RemoveInvalidFilenameChars(string, '-'); + QString dirName; + do + { + if(num == 0) + { + dirName = baseName; + } + else + { + dirName = baseName + QString::number(num);; + } + + // If it's over 9000 + if (num > 9000) + return ""; + num++; + } while (QFileInfo(PathCombine(inDir, dirName)).exists()); + return dirName; +} + +void FS::openDirInDefaultProgram(QString path, bool ensureExists) +{ + QDir parentPath; + QDir dir(path); + if (!dir.exists()) + { + parentPath.mkpath(dir.absolutePath()); + } + QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath())); +} + +void FS::openFileInDefaultProgram(QString filename) +{ + QDesktopServices::openUrl(QUrl::fromLocalFile(filename)); +} + +// Does the directory path contain any '!'? If yes, return true, otherwise false. +// (This is a problem for Java) +bool FS::checkProblemticPathJava(QDir folder) +{ + QString pathfoldername = folder.absolutePath(); + return pathfoldername.contains("!", Qt::CaseInsensitive); +} + +#include +#include +#include + +// Win32 crap +#if defined Q_OS_WIN + +#include +#include +#include +#include +#include +#include +#include + +bool called_coinit = false; + +HRESULT CreateLink(LPCSTR linkPath, LPCSTR targetPath, LPCSTR args) +{ + HRESULT hres; + + if (!called_coinit) + { + hres = CoInitialize(NULL); + called_coinit = true; + + if (!SUCCEEDED(hres)) + { + qWarning("Failed to initialize COM. Error 0x%08X", hres); + return hres; + } + } + + IShellLink *link; + hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, + (LPVOID *)&link); + + if (SUCCEEDED(hres)) + { + IPersistFile *persistFile; + + link->SetPath(targetPath); + link->SetArguments(args); + + hres = link->QueryInterface(IID_IPersistFile, (LPVOID *)&persistFile); + if (SUCCEEDED(hres)) + { + WCHAR wstr[MAX_PATH]; + + MultiByteToWideChar(CP_ACP, 0, linkPath, -1, wstr, MAX_PATH); + + hres = persistFile->Save(wstr, TRUE); + persistFile->Release(); + } + link->Release(); + } + return hres; +} + +#endif + +QString FS::getDesktopDir() +{ + return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); +} + +// Cross-platform Shortcut creation +bool FS::createShortCut(QString location, QString dest, QStringList args, QString name, + QString icon) +{ +#if defined Q_OS_LINUX + location = PathCombine(location, name + ".desktop"); + + QFile f(location); + f.open(QIODevice::WriteOnly | QIODevice::Text); + QTextStream stream(&f); + + QString argstring; + if (!args.empty()) + argstring = " '" + args.join("' '") + "'"; + + stream << "[Desktop Entry]" + << "\n"; + stream << "Type=Application" + << "\n"; + stream << "TryExec=" << dest.toLocal8Bit() << "\n"; + stream << "Exec=" << dest.toLocal8Bit() << argstring.toLocal8Bit() << "\n"; + stream << "Name=" << name.toLocal8Bit() << "\n"; + stream << "Icon=" << icon.toLocal8Bit() << "\n"; + + stream.flush(); + f.close(); + + f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | + QFileDevice::ExeOther); + + return true; +#elif defined Q_OS_WIN + // TODO: Fix + // QFile file(PathCombine(location, name + ".lnk")); + // WCHAR *file_w; + // WCHAR *dest_w; + // WCHAR *args_w; + // file.fileName().toWCharArray(file_w); + // dest.toWCharArray(dest_w); + + // QString argStr; + // for (int i = 0; i < args.count(); i++) + // { + // argStr.append(args[i]); + // argStr.append(" "); + // } + // argStr.toWCharArray(args_w); + + // return SUCCEEDED(CreateLink(file_w, dest_w, args_w)); + return false; +#else + qWarning("Desktop Shortcuts not supported on your platform!"); + return false; +#endif +} diff --git a/logic/FileSystem.h b/logic/FileSystem.h index a66e7ead..5055eb6c 100644 --- a/logic/FileSystem.h +++ b/logic/FileSystem.h @@ -5,6 +5,7 @@ #include "Exception.h" #include "multimc_logic_export.h" +#include namespace FS { @@ -15,6 +16,83 @@ public: FileSystemException(const QString &message) : Exception(message) {} }; -void MULTIMC_LOGIC_EXPORT write(const QString &filename, const QByteArray &data); -QByteArray MULTIMC_LOGIC_EXPORT read(const QString &filename); +/** + * write data to a file safely + */ +MULTIMC_LOGIC_EXPORT void write(const QString &filename, const QByteArray &data); + +/** + * read data from a file safely\ + */ +MULTIMC_LOGIC_EXPORT QByteArray read(const QString &filename); + +/** + * 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_LOGIC_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_LOGIC_EXPORT bool ensureFolderPathExists(QString filenamepath); + +/** + * Copy a folder recursively + */ +MULTIMC_LOGIC_EXPORT bool copyPath(const QString &src, const QString &dst, bool follow_symlinks = true); + +/** + * Delete a folder recursively + */ +MULTIMC_LOGIC_EXPORT bool deletePath(QString path); + +MULTIMC_LOGIC_EXPORT QString PathCombine(QString path1, QString path2); +MULTIMC_LOGIC_EXPORT QString PathCombine(QString path1, QString path2, QString path3); + +MULTIMC_LOGIC_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_LOGIC_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_LOGIC_EXPORT QString NormalizePath(QString path); + +MULTIMC_LOGIC_EXPORT QString RemoveInvalidFilenameChars(QString string, QChar replaceWith = '-'); + +MULTIMC_LOGIC_EXPORT QString DirNameFromString(QString string, QString inDir = "."); + +/// Opens the given file in the default application. +MULTIMC_LOGIC_EXPORT void openFileInDefaultProgram(QString filename); + +/// Opens the given directory in the default application. +MULTIMC_LOGIC_EXPORT void openDirInDefaultProgram(QString dirpath, bool ensureExists = false); + +/// Checks if the a given Path contains "!" +MULTIMC_LOGIC_EXPORT bool checkProblemticPathJava(QDir folder); + +// Get the Directory representing the User's Desktop +MULTIMC_LOGIC_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_LOGIC_EXPORT bool createShortCut(QString location, QString dest, QStringList args, QString name, QString iconLocation); } diff --git a/logic/InstanceList.cpp b/logic/InstanceList.cpp index 22b36748..c3a6a9c4 100644 --- a/logic/InstanceList.cpp +++ b/logic/InstanceList.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "InstanceList.h" @@ -38,6 +37,7 @@ #include "settings/INISettingsObject.h" #include "ftb/FTBPlugin.h" #include "NullInstance.h" +#include "FileSystem.h" const static int GROUP_FILE_FORMAT_VERSION = 1; @@ -299,7 +299,7 @@ InstanceList::InstListError InstanceList::loadList() while (iter.hasNext()) { QString subDir = iter.next(); - if (!QFileInfo(PathCombine(subDir, "instance.cfg")).exists()) + if (!QFileInfo(FS::PathCombine(subDir, "instance.cfg")).exists()) continue; qDebug() << "Loading MultiMC instance from " << subDir; InstancePtr instPtr; @@ -432,7 +432,7 @@ bool InstanceList::continueProcessInstance(InstancePtr instPtr, const int error, InstanceList::InstLoadError InstanceList::loadInstance(InstancePtr &inst, const QString &instDir) { - auto instanceSettings = std::make_shared(PathCombine(instDir, "instance.cfg")); + auto instanceSettings = std::make_shared(FS::PathCombine(instDir, "instance.cfg")); instanceSettings->registerSetting("InstanceType", "Legacy"); @@ -473,7 +473,7 @@ InstanceList::createInstance(InstancePtr &inst, BaseVersionPtr version, const QS return InstanceList::NoSuchVersion; } - auto instanceSettings = std::make_shared(PathCombine(instDir, "instance.cfg")); + auto instanceSettings = std::make_shared(FS::PathCombine(instDir, "instance.cfg")); instanceSettings->registerSetting("InstanceType", "Legacy"); auto minecraftVersion = std::dynamic_pointer_cast(version); @@ -490,18 +490,18 @@ InstanceList::createInstance(InstancePtr &inst, BaseVersionPtr version, const QS } InstanceList::InstCreateError -InstanceList::copyInstance(InstancePtr &newInstance, InstancePtr &oldInstance, const QString &instDir) +InstanceList::copyInstance(InstancePtr &newInstance, InstancePtr &oldInstance, const QString &instDir, bool copySaves) { QDir rootDir(instDir); qDebug() << instDir.toUtf8(); - if (!copyPath(oldInstance->instanceRoot(), instDir, false)) + if (!FS::copyPath(oldInstance->instanceRoot(), instDir, false)) { - deletePath(instDir); + FS::deletePath(instDir); return InstanceList::CantCreateDir; } - INISettingsObject settings_obj(PathCombine(instDir, "instance.cfg")); + INISettingsObject settings_obj(FS::PathCombine(instDir, "instance.cfg")); settings_obj.registerSetting("InstanceType", "Legacy"); QString inst_type = settings_obj.get("InstanceType").toString(); diff --git a/logic/InstanceList.h b/logic/InstanceList.h index 1799080a..3dbfaf70 100644 --- a/logic/InstanceList.h +++ b/logic/InstanceList.h @@ -140,7 +140,7 @@ public: * - CantCreateDir if the given instance directory cannot be created. */ InstCreateError copyInstance(InstancePtr &newInstance, InstancePtr &oldInstance, - const QString &instDir); + const QString &instDir, bool copySaves); /*! * \brief Loads an instance from the given directory. diff --git a/logic/MMCZip.cpp b/logic/MMCZip.cpp index 62904fa5..0f35bc70 100644 --- a/logic/MMCZip.cpp +++ b/logic/MMCZip.cpp @@ -23,11 +23,11 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors, see quazip/(un)MMCZip.h files for details. Basically it's the zlib license. */ -#include #include #include #include #include "MMCZip.h" +#include "FileSystem.h" #include @@ -111,7 +111,7 @@ bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSetcovers(internalDirName)) { QuaZipFile dirZipFile(zip); - auto dirPrefix = PathCombine(prefix, origDirectory.relativeFilePath(dir)) + "/"; + auto dirPrefix = FS::PathCombine(prefix, origDirectory.relativeFilePath(dir)) + "/"; if (!dirZipFile.open(QIODevice::WriteOnly, QuaZipNewInfo(dirPrefix, dir), 0, 0, 0)) { return false; @@ -153,7 +153,7 @@ bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet +#include +#include +#include + +Version::Version(const QString &str) : m_string(str) +{ + parse(); +} + +bool Version::operator<(const Version &other) const +{ + const int size = qMax(m_sections.size(), other.m_sections.size()); + for (int i = 0; i < size; ++i) + { + const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i); + const Section sec2 = + (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i); + if (sec1 != sec2) + { + return sec1 < sec2; + } + } + + return false; +} +bool Version::operator<=(const Version &other) const +{ + return *this < other || *this == other; +} +bool Version::operator>(const Version &other) const +{ + const int size = qMax(m_sections.size(), other.m_sections.size()); + for (int i = 0; i < size; ++i) + { + const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i); + const Section sec2 = + (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i); + if (sec1 != sec2) + { + return sec1 > sec2; + } + } + + return false; +} +bool Version::operator>=(const Version &other) const +{ + return *this > other || *this == other; +} +bool Version::operator==(const Version &other) const +{ + const int size = qMax(m_sections.size(), other.m_sections.size()); + for (int i = 0; i < size; ++i) + { + const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i); + const Section sec2 = + (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i); + if (sec1 != sec2) + { + return false; + } + } + + return true; +} +bool Version::operator!=(const Version &other) const +{ + return !operator==(other); +} + +void Version::parse() +{ + m_sections.clear(); + + QStringList parts = m_string.split('.'); + + for (const auto part : parts) + { + m_sections.append(Section(part)); + } +} + +bool versionIsInInterval(const QString &version, const QString &interval) +{ + return versionIsInInterval(Version(version), interval); +} +bool versionIsInInterval(const Version &version, const QString &interval) +{ + if (interval.isEmpty() || version.toString() == interval) + { + return true; + } + + // Interval notation is used + QRegularExpression exp( + "(?[\\[\\]\\(\\)])(?.*?)(,(?.*?))?(?[\\[\\]\\(\\)]),?"); + QRegularExpressionMatch match = exp.match(interval); + if (match.hasMatch()) + { + const QChar start = match.captured("start").at(0); + const QChar end = match.captured("end").at(0); + const QString bottom = match.captured("bottom"); + const QString top = match.captured("top"); + + // check if in range (bottom) + if (!bottom.isEmpty()) + { + const auto bottomVersion = Version(bottom); + if ((start == '[') && !(version >= bottomVersion)) + { + return false; + } + else if ((start == '(') && !(version > bottomVersion)) + { + return false; + } + } + + // check if in range (top) + if (!top.isEmpty()) + { + const auto topVersion = Version(top); + if ((end == ']') && !(version <= topVersion)) + { + return false; + } + else if ((end == ')') && !(version < topVersion)) + { + return false; + } + } + + return true; + } + + return false; +} diff --git a/logic/Version.h b/logic/Version.h new file mode 100644 index 00000000..b5946ced --- /dev/null +++ b/logic/Version.h @@ -0,0 +1,110 @@ +#pragma once + +#include +#include + +#include "multimc_logic_export.h" + +class QUrl; + +struct MULTIMC_LOGIC_EXPORT 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_LOGIC_EXPORT bool versionIsInInterval(const QString &version, const QString &interval); +MULTIMC_LOGIC_EXPORT bool versionIsInInterval(const Version &version, const QString &interval); + diff --git a/logic/auth/MojangAccountList.cpp b/logic/auth/MojangAccountList.cpp index b69b9b81..dac3d67f 100644 --- a/logic/auth/MojangAccountList.cpp +++ b/logic/auth/MojangAccountList.cpp @@ -27,7 +27,7 @@ #include #include "auth/MojangAccount.h" -#include +#include #define ACCOUNT_LIST_FORMAT_VERSION 2 @@ -348,7 +348,7 @@ bool MojangAccountList::saveList(const QString &filePath) } // make sure the parent folder exists - if(!ensureFilePathExists(path)) + if(!FS::ensureFilePathExists(path)) return false; // make sure the file wasn't overwritten with a folder before (fixes a bug) diff --git a/logic/forge/ForgeInstaller.cpp b/logic/forge/ForgeInstaller.cpp index 60dce822..cdbb5f18 100644 --- a/logic/forge/ForgeInstaller.cpp +++ b/logic/forge/ForgeInstaller.cpp @@ -23,10 +23,10 @@ #include "minecraft/VersionFilterData.h" #include "Env.h" #include "Exception.h" +#include #include #include -#include #include #include #include @@ -90,7 +90,7 @@ void ForgeInstaller::prepare(const QString &filename, const QString &universalUr auto cacheentry = ENV.metacache()->resolveEntry("libraries", lib.storageSuffix()); finalPath = "libraries/" + lib.storageSuffix(); - if (!ensureFilePathExists(finalPath)) + if (!FS::ensureFilePathExists(finalPath)) return; if (!zip.setCurrentFile(internalPath)) @@ -278,8 +278,8 @@ bool ForgeInstaller::addLegacy(OneSixInstance *to) return false; } auto entry = ENV.metacache()->resolveEntry("minecraftforge", m_forge_version->filename()); - finalPath = PathCombine(to->jarModsDir(), m_forge_version->filename()); - if (!ensureFilePathExists(finalPath)) + finalPath = FS::PathCombine(to->jarModsDir(), m_forge_version->filename()); + if (!FS::ensureFilePathExists(finalPath)) { return false; } diff --git a/logic/forge/ForgeXzDownload.cpp b/logic/forge/ForgeXzDownload.cpp index 56320ced..6009e31e 100644 --- a/logic/forge/ForgeXzDownload.cpp +++ b/logic/forge/ForgeXzDownload.cpp @@ -15,7 +15,7 @@ #include "Env.h" #include "ForgeXzDownload.h" -#include +#include #include #include @@ -49,7 +49,7 @@ void ForgeXzDownload::start() return; } // can we actually create the real, final file? - if (!ensureFilePathExists(m_target_path)) + if (!FS::ensureFilePathExists(m_target_path)) { m_status = Job_Failed; emit failed(m_index_within_job); diff --git a/logic/ftb/FTBPlugin.cpp b/logic/ftb/FTBPlugin.cpp index aa2c3ca9..201b5d3b 100644 --- a/logic/ftb/FTBPlugin.cpp +++ b/logic/ftb/FTBPlugin.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include "QDebug" #include #include @@ -137,7 +137,7 @@ InstancePtr loadInstance(SettingsObjectPtr globalSettings, QMap(PathCombine(record.instanceDir, "instance.cfg")); + auto m_settings = std::make_shared(FS::PathCombine(record.instanceDir, "instance.cfg")); m_settings->registerSetting("InstanceType", "Legacy"); qDebug() << "Loading existing " << record.name; @@ -206,7 +206,7 @@ InstancePtr createInstance(SettingsObjectPtr globalSettings, QMap(PathCombine(record.instanceDir, "instance.cfg")); + auto m_settings = std::make_shared(FS::PathCombine(record.instanceDir, "instance.cfg")); m_settings->registerSetting("InstanceType", "Legacy"); if (mcVersion->usesLegacyLauncher()) @@ -257,8 +257,8 @@ void FTBPlugin::loadInstances(SettingsObjectPtr globalSettings, QMapaddIcon(iconKey, iconKey, PathCombine(record.templateDir, record.logo), MMCIcon::Transient); - auto settingsFilePath = PathCombine(record.instanceDir, "instance.cfg"); + ENV.icons()->addIcon(iconKey, iconKey, FS::PathCombine(record.templateDir, record.logo), MMCIcon::Transient); + auto settingsFilePath = FS::PathCombine(record.instanceDir, "instance.cfg"); qDebug() << "ICON get!"; if (QFileInfo(settingsFilePath).exists()) diff --git a/logic/ftb/FTBProfileStrategy.cpp b/logic/ftb/FTBProfileStrategy.cpp index 293d0fdc..ac55bbe7 100644 --- a/logic/ftb/FTBProfileStrategy.cpp +++ b/logic/ftb/FTBProfileStrategy.cpp @@ -2,8 +2,8 @@ #include "minecraft/VersionBuildError.h" #include "ftb/OneSixFTBInstance.h" #include "minecraft/MinecraftVersionList.h" +#include -#include #include #include #include @@ -67,7 +67,7 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches() if(file->version.isEmpty()) { file->version = QObject::tr("Unknown"); - QFile versionFile (PathCombine(m_instance->instanceRoot(), "version")); + QFile versionFile (FS::PathCombine(m_instance->instanceRoot(), "version")); if(versionFile.exists()) { if(versionFile.open(QIODevice::ReadOnly)) @@ -94,8 +94,8 @@ void FTBProfileStrategy::loadUserPatches() { // load all patches, put into map for ordering, apply in the right order ProfileUtils::PatchOrder userOrder; - ProfileUtils::readOverrideOrders(PathCombine(m_instance->instanceRoot(), "order.json"), userOrder); - QDir patches(PathCombine(m_instance->instanceRoot(),"patches")); + ProfileUtils::readOverrideOrders(FS::PathCombine(m_instance->instanceRoot(), "order.json"), userOrder); + QDir patches(FS::PathCombine(m_instance->instanceRoot(),"patches")); // first, load things by sort order. for (auto id : userOrder) diff --git a/logic/ftb/OneSixFTBInstance.cpp b/logic/ftb/OneSixFTBInstance.cpp index 1fc5b49b..7a0fdf4d 100644 --- a/logic/ftb/OneSixFTBInstance.cpp +++ b/logic/ftb/OneSixFTBInstance.cpp @@ -7,7 +7,7 @@ #include "forge/ForgeInstaller.h" #include "forge/ForgeVersionList.h" #include -#include "pathutils.h" +#include OneSixFTBInstance::OneSixFTBInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) : OneSixInstance(globalSettings, settings, rootDir) @@ -63,7 +63,7 @@ void OneSixFTBInstance::copy(const QDir &newDir) root.insert("name", name()); root.insert("mcVersion", intendedVersionId()); root.insert("version", intendedVersionId()); - ensureFilePathExists(newDir.absoluteFilePath("patches/ftb.json")); + FS::ensureFilePathExists(newDir.absoluteFilePath("patches/ftb.json")); QFile out(newDir.absoluteFilePath("patches/ftb.json")); if (!out.open(QFile::WriteOnly | QFile::Truncate)) { @@ -83,7 +83,7 @@ void OneSixFTBInstance::copy(const QDir &newDir) { continue; } - if (!ensureFilePathExists(out)) + if (!FS::ensureFilePathExists(out)) { qCritical() << "Couldn't create folder structure for" << out; } diff --git a/logic/icons/IconList.cpp b/logic/icons/IconList.cpp index 45d39575..99def3b7 100644 --- a/logic/icons/IconList.cpp +++ b/logic/icons/IconList.cpp @@ -14,7 +14,7 @@ */ #include "IconList.h" -#include +#include #include #include #include @@ -57,7 +57,7 @@ void IconList::directoryChanged(const QString &path) startWatching(); } if(!m_dir.exists()) - if(!ensureFolderPathExists(m_dir.absolutePath())) + if(!FS::ensureFolderPathExists(m_dir.absolutePath())) return; m_dir.refresh(); auto new_list = m_dir.entryList(QDir::Files, QDir::Name); @@ -149,7 +149,7 @@ void IconList::SettingChanged(const Setting &setting, QVariant value) void IconList::startWatching() { auto abs_path = m_dir.absolutePath(); - ensureFolderPathExists(abs_path); + FS::ensureFolderPathExists(abs_path); is_watching = m_watcher->addPath(abs_path); if (is_watching) { @@ -250,7 +250,7 @@ void IconList::installIcons(QStringList iconFiles) QFileInfo fileinfo(file); if (!fileinfo.isReadable() || !fileinfo.isFile()) continue; - QString target = PathCombine(m_dir.dirName(), fileinfo.fileName()); + QString target = FS::PathCombine(m_dir.dirName(), fileinfo.fileName()); QString suffix = fileinfo.suffix(); if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico") diff --git a/logic/java/JavaChecker.cpp b/logic/java/JavaChecker.cpp index 9c8d5f68..dfda464f 100644 --- a/logic/java/JavaChecker.cpp +++ b/logic/java/JavaChecker.cpp @@ -1,6 +1,6 @@ #include "JavaChecker.h" -#include -#include +#include +#include #include #include #include @@ -14,14 +14,14 @@ JavaChecker::JavaChecker(QObject *parent) : QObject(parent) void JavaChecker::performCheck() { - QString checkerJar = PathCombine(QCoreApplication::applicationDirPath(), "jars", "JavaCheck.jar"); + QString checkerJar = FS::PathCombine(QCoreApplication::applicationDirPath(), "jars", "JavaCheck.jar"); QStringList args; process.reset(new QProcess()); if(m_args.size()) { - auto extraArgs = Util::Commandline::splitArgs(m_args); + auto extraArgs = Commandline::splitArgs(m_args); args.append(extraArgs); } if(m_minMem != 0) diff --git a/logic/java/JavaCheckerJob.cpp b/logic/java/JavaCheckerJob.cpp index bf4271c2..0b040e43 100644 --- a/logic/java/JavaCheckerJob.cpp +++ b/logic/java/JavaCheckerJob.cpp @@ -14,7 +14,6 @@ */ #include "JavaCheckerJob.h" -#include "pathutils.h" #include diff --git a/logic/java/JavaUtils.cpp b/logic/java/JavaUtils.cpp index ac1d60e4..80ded3ee 100644 --- a/logic/java/JavaUtils.cpp +++ b/logic/java/JavaUtils.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include "java/JavaUtils.h" diff --git a/logic/java/JavaUtils.h b/logic/java/JavaUtils.h index d4dd2409..78693b37 100644 --- a/logic/java/JavaUtils.h +++ b/logic/java/JavaUtils.h @@ -18,12 +18,11 @@ #include #include -#include #include "JavaCheckerJob.h" #include "JavaChecker.h" #include "JavaVersionList.h" -#if WINDOWS +#ifdef Q_OS_WIN #include #endif @@ -39,7 +38,7 @@ public: QList FindJavaPaths(); JavaVersionPtr GetDefaultJava(); -#if WINDOWS +#ifdef Q_OS_WIN QList FindJavaFromRegistryKey(DWORD keyType, QString keyName); #endif }; diff --git a/logic/launch/LaunchTask.cpp b/logic/launch/LaunchTask.cpp index 1defeba3..5b7ff182 100644 --- a/logic/launch/LaunchTask.cpp +++ b/logic/launch/LaunchTask.cpp @@ -20,7 +20,6 @@ #include "MMCStrings.h" #include "java/JavaChecker.h" #include "tasks/Task.h" -#include #include #include #include diff --git a/logic/launch/steps/CheckJava.cpp b/logic/launch/steps/CheckJava.cpp index 7482624f..66f7cc2b 100644 --- a/logic/launch/steps/CheckJava.cpp +++ b/logic/launch/steps/CheckJava.cpp @@ -15,7 +15,7 @@ #include "CheckJava.h" #include -#include +#include #include #include @@ -23,7 +23,7 @@ void CheckJava::executeTask() { auto instance = m_parent->instance(); auto settings = instance->settings(); - m_javaPath = ResolveExecutable(settings->get("JavaPath").toString()); + m_javaPath = FS::ResolveExecutable(settings->get("JavaPath").toString()); bool perInstance = settings->get("OverrideJava").toBool() || settings->get("OverrideJavaLocation").toBool(); auto realJavaPath = QStandardPaths::findExecutable(m_javaPath); diff --git a/logic/launch/steps/LaunchMinecraft.cpp b/logic/launch/steps/LaunchMinecraft.cpp index 84abb375..3d75f5f2 100644 --- a/logic/launch/steps/LaunchMinecraft.cpp +++ b/logic/launch/steps/LaunchMinecraft.cpp @@ -16,7 +16,7 @@ #include "LaunchMinecraft.h" #include #include -#include +#include #include LaunchMinecraft::LaunchMinecraft(LaunchTask *parent) : LaunchStep(parent) @@ -34,7 +34,7 @@ void LaunchMinecraft::executeTask() QString allArgs = args.join(", "); emit logLine("Java Arguments:\n[" + m_parent->censorPrivateInfo(allArgs) + "]\n\n", MessageLevel::MultiMC); - auto javaPath = ResolveExecutable(instance->settings()->get("JavaPath").toString()); + auto javaPath = FS::ResolveExecutable(instance->settings()->get("JavaPath").toString()); m_process.setProcessEnvironment(instance->createEnvironment()); diff --git a/logic/minecraft/AssetsUtils.cpp b/logic/minecraft/AssetsUtils.cpp index 63179228..b3589cb8 100644 --- a/logic/minecraft/AssetsUtils.cpp +++ b/logic/minecraft/AssetsUtils.cpp @@ -23,7 +23,7 @@ #include #include "AssetsUtils.h" -#include +#include namespace AssetsUtils { @@ -125,13 +125,13 @@ bool loadAssetsIndexJson(QString path, AssetsIndex *index) QDir reconstructAssets(QString assetsId) { QDir assetsDir = QDir("assets/"); - QDir indexDir = QDir(PathCombine(assetsDir.path(), "indexes")); - QDir objectDir = QDir(PathCombine(assetsDir.path(), "objects")); - QDir virtualDir = QDir(PathCombine(assetsDir.path(), "virtual")); + QDir indexDir = QDir(FS::PathCombine(assetsDir.path(), "indexes")); + QDir objectDir = QDir(FS::PathCombine(assetsDir.path(), "objects")); + QDir virtualDir = QDir(FS::PathCombine(assetsDir.path(), "virtual")); - QString indexPath = PathCombine(indexDir.path(), assetsId + ".json"); + QString indexPath = FS::PathCombine(indexDir.path(), assetsId + ".json"); QFile indexFile(indexPath); - QDir virtualRoot(PathCombine(virtualDir.path(), assetsId)); + QDir virtualRoot(FS::PathCombine(virtualDir.path(), assetsId)); if (!indexFile.exists()) { @@ -152,13 +152,12 @@ QDir reconstructAssets(QString assetsId) for (QString map : index.objects.keys()) { AssetObject asset_object = index.objects.value(map); - QString target_path = PathCombine(virtualRoot.path(), map); + QString target_path = FS::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); + QString original_path = FS::PathCombine(objectDir.path(), tlk, asset_object.hash); QFile original(original_path); if (!original.exists()) continue; diff --git a/logic/minecraft/LegacyInstance.cpp b/logic/minecraft/LegacyInstance.cpp index 342a6f2d..227fd601 100644 --- a/logic/minecraft/LegacyInstance.cpp +++ b/logic/minecraft/LegacyInstance.cpp @@ -17,8 +17,6 @@ #include #include #include -#include -#include #include "LegacyInstance.h" @@ -35,6 +33,7 @@ #include "minecraft/ModList.h" #include "minecraft/WorldList.h" #include +#include LegacyInstance::LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) : MinecraftInstance(globalSettings, settings, rootDir) @@ -109,7 +108,7 @@ std::shared_ptr LegacyInstance::createLaunchTask(AuthSessionPtr sess QString launchScript; QIcon icon = ENV.icons()->getIcon(iconKey()); auto pixmap = icon.pixmap(128, 128); - pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG"); + pixmap.save(FS::PathCombine(minecraftRoot(), "icon.png"), "PNG"); // create the launch script { @@ -331,56 +330,56 @@ std::shared_ptr LegacyInstance::worldList() const QString LegacyInstance::jarModsDir() const { - return PathCombine(instanceRoot(), "instMods"); + return FS::PathCombine(instanceRoot(), "instMods"); } QString LegacyInstance::binDir() const { - return PathCombine(minecraftRoot(), "bin"); + return FS::PathCombine(minecraftRoot(), "bin"); } QString LegacyInstance::libDir() const { - return PathCombine(minecraftRoot(), "lib"); + return FS::PathCombine(minecraftRoot(), "lib"); } QString LegacyInstance::savesDir() const { - return PathCombine(minecraftRoot(), "saves"); + return FS::PathCombine(minecraftRoot(), "saves"); } QString LegacyInstance::loaderModsDir() const { - return PathCombine(minecraftRoot(), "mods"); + return FS::PathCombine(minecraftRoot(), "mods"); } QString LegacyInstance::coreModsDir() const { - return PathCombine(minecraftRoot(), "coremods"); + return FS::PathCombine(minecraftRoot(), "coremods"); } QString LegacyInstance::resourceDir() const { - return PathCombine(minecraftRoot(), "resources"); + return FS::PathCombine(minecraftRoot(), "resources"); } QString LegacyInstance::texturePacksDir() const { - return PathCombine(minecraftRoot(), "texturepacks"); + return FS::PathCombine(minecraftRoot(), "texturepacks"); } QString LegacyInstance::runnableJar() const { - return PathCombine(binDir(), "minecraft.jar"); + return FS::PathCombine(binDir(), "minecraft.jar"); } QString LegacyInstance::modListFile() const { - return PathCombine(instanceRoot(), "modlist"); + return FS::PathCombine(instanceRoot(), "modlist"); } QString LegacyInstance::instanceConfigFolder() const { - return PathCombine(minecraftRoot(), "config"); + return FS::PathCombine(minecraftRoot(), "config"); } bool LegacyInstance::shouldRebuild() const @@ -442,7 +441,7 @@ QString LegacyInstance::defaultBaseJar() const QString LegacyInstance::defaultCustomBaseJar() const { - return PathCombine(binDir(), "mcbackup.jar"); + return FS::PathCombine(binDir(), "mcbackup.jar"); } QString LegacyInstance::lwjglFolder() const diff --git a/logic/minecraft/LegacyUpdate.cpp b/logic/minecraft/LegacyUpdate.cpp index c48984c4..2fd8e3cb 100644 --- a/logic/minecraft/LegacyUpdate.cpp +++ b/logic/minecraft/LegacyUpdate.cpp @@ -14,7 +14,6 @@ */ #include -#include #include #include #include @@ -30,6 +29,7 @@ #include "minecraft/MinecraftVersionList.h" #include "minecraft/ModList.h" #include "minecraft/LegacyInstance.h" +#include LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : Task(parent), m_inst(inst) { @@ -92,7 +92,7 @@ void LegacyUpdate::fmllibsStart() // now check the lib folder inside the instance for files. for (auto &lib : libList) { - QFileInfo libInfo(PathCombine(inst->libDir(), lib.filename)); + QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename)); if (libInfo.exists()) continue; fmlLibsToProcess.append(lib); @@ -137,13 +137,13 @@ void LegacyUpdate::fmllibsFinished() { progress(index, fmlLibsToProcess.size()); auto entry = metacache->resolveEntry("fmllibs", lib.filename); - auto path = PathCombine(inst->libDir(), lib.filename); - if(!ensureFilePathExists(path)) + auto path = FS::PathCombine(inst->libDir(), lib.filename); + if(!FS::ensureFilePathExists(path)) { emitFailed(tr("Failed creating FML library folder inside the instance.")); return; } - if (!QFile::copy(entry->getFullPath(), PathCombine(inst->libDir(), lib.filename))) + if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->libDir(), lib.filename))) { emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename)); return; @@ -166,11 +166,11 @@ void LegacyUpdate::lwjglStart() LegacyInstance *inst = (LegacyInstance *)m_inst; lwjglVersion = inst->lwjglVersion(); - lwjglTargetPath = PathCombine(inst->lwjglFolder(), lwjglVersion); - lwjglNativesPath = PathCombine(lwjglTargetPath, "natives"); + lwjglTargetPath = FS::PathCombine(inst->lwjglFolder(), lwjglVersion); + lwjglNativesPath = FS::PathCombine(lwjglTargetPath, "natives"); // if the 'done' file exists, we don't have to download this again - QFileInfo doneFile(PathCombine(lwjglTargetPath, "done")); + QFileInfo doneFile(FS::PathCombine(lwjglTargetPath, "done")); if (doneFile.exists()) { jarStart(); @@ -256,7 +256,7 @@ void LegacyUpdate::extractLwjgl() { // make sure the directories are there - bool success = ensureFolderPathExists(lwjglNativesPath); + bool success = FS::ensureFolderPathExists(lwjglNativesPath); if (!success) { @@ -295,7 +295,7 @@ void LegacyUpdate::extractLwjgl() { if (name.endsWith(jarNames[i])) { - destFileName = PathCombine(lwjglTargetPath, jarNames[i]); + destFileName = FS::PathCombine(lwjglTargetPath, jarNames[i]); } } // Not found? look for the natives @@ -318,7 +318,7 @@ void LegacyUpdate::extractLwjgl() name = name.mid(lastSlash + 1); else if (lastBackSlash != -1) name = name.mid(lastBackSlash + 1); - destFileName = PathCombine(lwjglNativesPath, name); + destFileName = FS::PathCombine(lwjglNativesPath, name); } } // Now if destFileName is still empty, go to the next file. @@ -334,7 +334,7 @@ void LegacyUpdate::extractLwjgl() } zip.close(); m_reply.reset(); - QFile doneFile(PathCombine(lwjglTargetPath, "done")); + QFile doneFile(FS::PathCombine(lwjglTargetPath, "done")); doneFile.open(QIODevice::WriteOnly); doneFile.write("done."); doneFile.close(); diff --git a/logic/minecraft/MinecraftInstance.cpp b/logic/minecraft/MinecraftInstance.cpp index 8fd65d50..0dab4dfe 100644 --- a/logic/minecraft/MinecraftInstance.cpp +++ b/logic/minecraft/MinecraftInstance.cpp @@ -1,12 +1,12 @@ #include "MinecraftInstance.h" #include #include "settings/SettingsObject.h" -#include #include "Env.h" #include "minecraft/MinecraftVersionList.h" #include #include #include +#include #define IBUS "@im=ibus" @@ -67,8 +67,8 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO QString MinecraftInstance::minecraftRoot() const { - QFileInfo mcDir(PathCombine(instanceRoot(), "minecraft")); - QFileInfo dotMCDir(PathCombine(instanceRoot(), ".minecraft")); + QFileInfo mcDir(FS::PathCombine(instanceRoot(), "minecraft")); + QFileInfo dotMCDir(FS::PathCombine(instanceRoot(), ".minecraft")); if (dotMCDir.exists() && !mcDir.exists()) return dotMCDir.filePath(); @@ -115,7 +115,7 @@ QStringList MinecraftInstance::javaArguments() const } args << "-Duser.language=en"; - args << "-jar" << PathCombine(QCoreApplication::applicationDirPath(), "jars", "NewLaunch.jar"); + args << "-jar" << FS::PathCombine(QCoreApplication::applicationDirPath(), "jars", "NewLaunch.jar"); return args; } diff --git a/logic/minecraft/MinecraftProfile.cpp b/logic/minecraft/MinecraftProfile.cpp index efeb254b..4f33920b 100644 --- a/logic/minecraft/MinecraftProfile.cpp +++ b/logic/minecraft/MinecraftProfile.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include "minecraft/MinecraftProfile.h" #include "ProfileUtils.h" diff --git a/logic/minecraft/MinecraftVersionList.cpp b/logic/minecraft/MinecraftVersionList.cpp index afa7c4c5..8d52c23b 100644 --- a/logic/minecraft/MinecraftVersionList.cpp +++ b/logic/minecraft/MinecraftVersionList.cpp @@ -27,8 +27,7 @@ #include "ParseUtils.h" #include "ProfileUtils.h" #include "VersionFilterData.h" - -#include +#include static const char * localVersionCache = "versions/versions.dat"; @@ -548,7 +547,7 @@ void MCVListVersionUpdateTask::json_downloaded() auto doc = file->toJson(false); auto newdata = doc.toBinaryData(); QString targetPath = "versions/" + versionToUpdate + "/" + versionToUpdate + ".dat"; - ensureFilePathExists(targetPath); + FS::ensureFilePathExists(targetPath); QSaveFile vfile1(targetPath); if (!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly)) { @@ -582,7 +581,7 @@ std::shared_ptr MinecraftVersionList::createUpdateTask(QString version) void MinecraftVersionList::saveCachedList() { // FIXME: throw. - if (!ensureFilePathExists(localVersionCache)) + if (!FS::ensureFilePathExists(localVersionCache)) return; QSaveFile tfile(localVersionCache); if (!tfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) diff --git a/logic/minecraft/Mod.cpp b/logic/minecraft/Mod.cpp index f8eb4faf..879ca195 100644 --- a/logic/minecraft/Mod.cpp +++ b/logic/minecraft/Mod.cpp @@ -23,8 +23,8 @@ #include #include "Mod.h" -#include #include "settings/INIFile.h" +#include #include Mod::Mod(const QFileInfo &file) @@ -113,7 +113,7 @@ void Mod::repath(const QFileInfo &file) } else if (m_type == MOD_FOLDER) { - QFileInfo mcmod_info(PathCombine(m_file.filePath(), "mcmod.info")); + QFileInfo mcmod_info(FS::PathCombine(m_file.filePath(), "mcmod.info")); if (mcmod_info.isFile()) { QFile mcmod(mcmod_info.filePath()); @@ -278,7 +278,7 @@ bool Mod::replace(Mod &with) } if (t == MOD_FOLDER) { - success = copyPath(with.m_file.filePath(), m_file.path()); + success = FS::copyPath(with.m_file.filePath(), m_file.path()); } if (success) { diff --git a/logic/minecraft/ModList.cpp b/logic/minecraft/ModList.cpp index 8f1bc041..60f8b012 100644 --- a/logic/minecraft/ModList.cpp +++ b/logic/minecraft/ModList.cpp @@ -14,7 +14,7 @@ */ #include "ModList.h" -#include +#include #include #include #include @@ -25,7 +25,7 @@ ModList::ModList(const QString &dir, const QString &list_file) : QAbstractListModel(), m_dir(dir), m_list_file(list_file) { - ensureFolderPathExists(m_dir.absolutePath()); + FS::ensureFolderPathExists(m_dir.absolutePath()); m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs | QDir::NoSymLinks); m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); @@ -270,7 +270,7 @@ bool ModList::installMod(const QFileInfo &filename, int index) return false; if (type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE || type == Mod::MOD_LITEMOD) { - QString newpath = PathCombine(m_dir.path(), filename.fileName()); + QString newpath = FS::PathCombine(m_dir.path(), filename.fileName()); if (!QFile::copy(filename.filePath(), newpath)) return false; m.repath(newpath); @@ -285,8 +285,8 @@ bool ModList::installMod(const QFileInfo &filename, int index) { QString from = filename.filePath(); - QString to = PathCombine(m_dir.path(), filename.fileName()); - if (!copyPath(from, to)) + QString to = FS::PathCombine(m_dir.path(), filename.fileName()); + if (!FS::copyPath(from, to)) return false; m.repath(to); beginInsertRows(QModelIndex(), index, index); diff --git a/logic/minecraft/OneSixInstance.cpp b/logic/minecraft/OneSixInstance.cpp index a5be8354..da1b21cb 100644 --- a/logic/minecraft/OneSixInstance.cpp +++ b/logic/minecraft/OneSixInstance.cpp @@ -14,7 +14,6 @@ */ #include -#include #include #include "minecraft/OneSixInstance.h" @@ -36,6 +35,7 @@ #include "minecraft/AssetsUtils.h" #include "icons/IconList.h" #include "minecraft/WorldList.h" +#include OneSixInstance::OneSixInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) : MinecraftInstance(globalSettings, settings, rootDir) @@ -136,7 +136,7 @@ std::shared_ptr OneSixInstance::createLaunchTask(AuthSessionPtr sess QString launchScript; QIcon icon = ENV.icons()->getIcon(iconKey()); auto pixmap = icon.pixmap(128, 128); - pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG"); + pixmap.save(FS::PathCombine(minecraftRoot(), "icon.png"), "PNG"); if (!m_version) return nullptr; @@ -222,7 +222,7 @@ std::shared_ptr OneSixInstance::createLaunchTask(AuthSessionPtr sess // native libraries (mostly LWJGL) { - QDir natives_dir(PathCombine(instanceRoot(), "natives/")); + QDir natives_dir(FS::PathCombine(instanceRoot(), "natives/")); for (auto native : m_version->getActiveNativeLibs()) { QFileInfo finfo(native->storagePath()); @@ -348,7 +348,7 @@ std::shared_ptr OneSixInstance::createJarModdingTask() void OneSixInstance::cleanupAfterRun() { - QString target_dir = PathCombine(instanceRoot(), "natives/"); + QString target_dir = FS::PathCombine(instanceRoot(), "natives/"); QDir dir(target_dir); dir.removeRecursively(); } @@ -515,42 +515,42 @@ bool OneSixInstance::reload() QString OneSixInstance::loaderModsDir() const { - return PathCombine(minecraftRoot(), "mods"); + return FS::PathCombine(minecraftRoot(), "mods"); } QString OneSixInstance::coreModsDir() const { - return PathCombine(minecraftRoot(), "coremods"); + return FS::PathCombine(minecraftRoot(), "coremods"); } QString OneSixInstance::resourcePacksDir() const { - return PathCombine(minecraftRoot(), "resourcepacks"); + return FS::PathCombine(minecraftRoot(), "resourcepacks"); } QString OneSixInstance::texturePacksDir() const { - return PathCombine(minecraftRoot(), "texturepacks"); + return FS::PathCombine(minecraftRoot(), "texturepacks"); } QString OneSixInstance::instanceConfigFolder() const { - return PathCombine(minecraftRoot(), "config"); + return FS::PathCombine(minecraftRoot(), "config"); } QString OneSixInstance::jarModsDir() const { - return PathCombine(instanceRoot(), "jarmods"); + return FS::PathCombine(instanceRoot(), "jarmods"); } QString OneSixInstance::libDir() const { - return PathCombine(minecraftRoot(), "lib"); + return FS::PathCombine(minecraftRoot(), "lib"); } QString OneSixInstance::worldDir() const { - return PathCombine(minecraftRoot(), "saves"); + return FS::PathCombine(minecraftRoot(), "saves"); } QStringList OneSixInstance::extraArguments() const diff --git a/logic/minecraft/OneSixProfileStrategy.cpp b/logic/minecraft/OneSixProfileStrategy.cpp index f5de690b..85e9491c 100644 --- a/logic/minecraft/OneSixProfileStrategy.cpp +++ b/logic/minecraft/OneSixProfileStrategy.cpp @@ -3,8 +3,8 @@ #include "minecraft/OneSixInstance.h" #include "minecraft/MinecraftVersionList.h" #include "Env.h" +#include -#include #include #include #include @@ -17,9 +17,9 @@ OneSixProfileStrategy::OneSixProfileStrategy(OneSixInstance* instance) void OneSixProfileStrategy::upgradeDeprecatedFiles() { - auto versionJsonPath = PathCombine(m_instance->instanceRoot(), "version.json"); - auto customJsonPath = PathCombine(m_instance->instanceRoot(), "custom.json"); - auto mcJson = PathCombine(m_instance->instanceRoot(), "patches" , "net.minecraft.json"); + auto versionJsonPath = FS::PathCombine(m_instance->instanceRoot(), "version.json"); + auto customJsonPath = FS::PathCombine(m_instance->instanceRoot(), "custom.json"); + auto mcJson = FS::PathCombine(m_instance->instanceRoot(), "patches" , "net.minecraft.json"); QString sourceFile; QString renameFile; @@ -36,7 +36,7 @@ void OneSixProfileStrategy::upgradeDeprecatedFiles() } if(!sourceFile.isEmpty() && !QFile::exists(mcJson)) { - if(!ensureFilePathExists(mcJson)) + if(!FS::ensureFilePathExists(mcJson)) { qWarning() << "Couldn't create patches folder for" << m_instance->name(); return; @@ -79,7 +79,7 @@ void OneSixProfileStrategy::upgradeDeprecatedFiles() void OneSixProfileStrategy::loadDefaultBuiltinPatches() { { - auto mcJson = PathCombine(m_instance->instanceRoot(), "patches" , "net.minecraft.json"); + auto mcJson = FS::PathCombine(m_instance->instanceRoot(), "patches" , "net.minecraft.json"); // load up the base minecraft patch ProfilePatchPtr minecraftPatch; if(QFile::exists(mcJson)) @@ -107,7 +107,7 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches() } { - auto lwjglJson = PathCombine(m_instance->instanceRoot(), "patches" , "org.lwjgl.json"); + auto lwjglJson = FS::PathCombine(m_instance->instanceRoot(), "patches" , "org.lwjgl.json"); ProfilePatchPtr lwjglPatch; if(QFile::exists(lwjglJson)) { @@ -138,8 +138,8 @@ void OneSixProfileStrategy::loadUserPatches() { // load all patches, put into map for ordering, apply in the right order ProfileUtils::PatchOrder userOrder; - ProfileUtils::readOverrideOrders(PathCombine(m_instance->instanceRoot(), "order.json"), userOrder); - QDir patches(PathCombine(m_instance->instanceRoot(),"patches")); + ProfileUtils::readOverrideOrders(FS::PathCombine(m_instance->instanceRoot(), "order.json"), userOrder); + QDir patches(FS::PathCombine(m_instance->instanceRoot(),"patches")); // first, load things by sort order. for (auto id : userOrder) @@ -215,7 +215,7 @@ void OneSixProfileStrategy::load() bool OneSixProfileStrategy::saveOrder(ProfileUtils::PatchOrder order) { - return ProfileUtils::writeOverrideOrders(PathCombine(m_instance->instanceRoot(), "order.json"), order); + return ProfileUtils::writeOverrideOrders(FS::PathCombine(m_instance->instanceRoot(), "order.json"), order); } bool OneSixProfileStrategy::resetOrder() @@ -241,7 +241,7 @@ bool OneSixProfileStrategy::removePatch(ProfilePatchPtr patch) auto preRemoveJarMod = [&](JarmodPtr jarMod) -> bool { - QString fullpath = PathCombine(m_instance->jarModsDir(), jarMod->name); + QString fullpath = FS::PathCombine(m_instance->jarModsDir(), jarMod->name); QFileInfo finfo (fullpath); if(finfo.exists()) { @@ -270,8 +270,8 @@ bool OneSixProfileStrategy::customizePatch(ProfilePatchPtr patch) return false; } - auto filename = PathCombine(m_instance->instanceRoot(), "patches" , patch->getPatchID() + ".json"); - if(!ensureFilePathExists(filename)) + auto filename = FS::PathCombine(m_instance->instanceRoot(), "patches" , patch->getPatchID() + ".json"); + if(!FS::ensureFilePathExists(filename)) { return false; } @@ -333,13 +333,13 @@ bool OneSixProfileStrategy::revertPatch(ProfilePatchPtr patch) bool OneSixProfileStrategy::installJarMods(QStringList filepaths) { - QString patchDir = PathCombine(m_instance->instanceRoot(), "patches"); - if(!ensureFolderPathExists(patchDir)) + QString patchDir = FS::PathCombine(m_instance->instanceRoot(), "patches"); + if(!FS::ensureFolderPathExists(patchDir)) { return false; } - if (!ensureFolderPathExists(m_instance->jarModsDir())) + if (!FS::ensureFolderPathExists(m_instance->jarModsDir())) { return false; } @@ -352,7 +352,7 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths) QString target_filename = id + ".jar"; QString target_id = "org.multimc.jarmod." + id; QString target_name = sourceInfo.completeBaseName() + " (jar mod)"; - QString finalPath = PathCombine(m_instance->jarModsDir(), target_filename); + QString finalPath = FS::PathCombine(m_instance->jarModsDir(), target_filename); QFileInfo targetInfo(finalPath); if(targetInfo.exists()) @@ -373,7 +373,7 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths) f->name = target_name; f->fileId = target_id; f->order = profile->getFreeOrderNumber(); - QString patchFileName = PathCombine(patchDir, target_id + ".json"); + QString patchFileName = FS::PathCombine(patchDir, target_id + ".json"); f->filename = patchFileName; f->setMovable(true); f->setRemovable(true); diff --git a/logic/minecraft/OneSixUpdate.cpp b/logic/minecraft/OneSixUpdate.cpp index 34bd7de9..73d48461 100644 --- a/logic/minecraft/OneSixUpdate.cpp +++ b/logic/minecraft/OneSixUpdate.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include "BaseInstance.h" @@ -35,6 +34,7 @@ #include "minecraft/AssetsUtils.h" #include "Exception.h" #include "MMCZip.h" +#include OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent), m_inst(inst) { @@ -344,7 +344,7 @@ void OneSixUpdate::fmllibsStart() // now check the lib folder inside the instance for files. for (auto &lib : libList) { - QFileInfo libInfo(PathCombine(inst->libDir(), lib.filename)); + QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename)); if (libInfo.exists()) continue; fmlLibsToProcess.append(lib); @@ -389,13 +389,13 @@ void OneSixUpdate::fmllibsFinished() { progress(index, fmlLibsToProcess.size()); auto entry = metacache->resolveEntry("fmllibs", lib.filename); - auto path = PathCombine(inst->libDir(), lib.filename); - if (!ensureFilePathExists(path)) + auto path = FS::PathCombine(inst->libDir(), lib.filename); + if (!FS::ensureFilePathExists(path)) { emitFailed(tr("Failed creating FML library folder inside the instance.")); return; } - if (!QFile::copy(entry->getFullPath(), PathCombine(inst->libDir(), lib.filename))) + if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->libDir(), lib.filename))) { emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename)); return; diff --git a/logic/minecraft/RawLibrary.cpp b/logic/minecraft/RawLibrary.cpp index ceaa9dd0..7da743e4 100644 --- a/logic/minecraft/RawLibrary.cpp +++ b/logic/minecraft/RawLibrary.cpp @@ -2,7 +2,7 @@ using namespace Json; #include "RawLibrary.h" -#include +#include RawLibraryPtr RawLibrary::fromJson(const QJsonObject &libObj, const QString &filename) { @@ -314,7 +314,7 @@ QString RawLibrary::storageSuffix() const QString RawLibrary::storagePath() const { - return PathCombine(storagePrefix(), storageSuffix()); + return FS::PathCombine(storagePrefix(), storageSuffix()); } bool RawLibrary::storagePathIsDefault() const diff --git a/logic/minecraft/VersionFile.cpp b/logic/minecraft/VersionFile.cpp index 24f2eb9c..922ba470 100644 --- a/logic/minecraft/VersionFile.cpp +++ b/logic/minecraft/VersionFile.cpp @@ -1,6 +1,5 @@ #include #include -#include #include @@ -14,6 +13,7 @@ using namespace Json; #include "VersionBuildError.h" +#include #define CURRENT_MINIMUM_LAUNCHER_VERSION 14 @@ -427,8 +427,8 @@ void VersionFile::applyTo(MinecraftProfile *version) // otherwise apply differences, if allowed auto existingLibrary = version->libraries.at(index); - const Util::Version addedVersion = addedLibrary->version(); - const Util::Version existingVersion = existingLibrary->version(); + const Version addedVersion(addedLibrary->version()); + const Version existingVersion(existingLibrary->version()); // if the existing version is a hard dependency we can either use it or // fail, but we can't change it if (existingLibrary->dependType == OneSixLibrary::Hard) diff --git a/logic/minecraft/World.cpp b/logic/minecraft/World.cpp index 41d62b1b..e4734556 100644 --- a/logic/minecraft/World.cpp +++ b/logic/minecraft/World.cpp @@ -18,10 +18,10 @@ #include #include #include "World.h" -#include #include "GZip.h" #include +#include #include #include #include @@ -179,8 +179,8 @@ void World::readFromZip(const QFileInfo &file) bool World::install(const QString &to, const QString &name) { - auto finalPath = PathCombine(to, DirNameFromString(m_actualName, to)); - if(!ensureFolderPathExists(finalPath)) + auto finalPath = FS::PathCombine(to, FS::DirNameFromString(m_actualName, to)); + if(!FS::ensureFolderPathExists(finalPath)) { return false; } @@ -197,7 +197,7 @@ bool World::install(const QString &to, const QString &name) else if(m_containerFile.isDir()) { QString from = m_containerFile.filePath(); - ok = copyPath(from, finalPath); + ok = FS::copyPath(from, finalPath); } if(ok && !name.isEmpty() && m_actualName != name) @@ -245,7 +245,7 @@ bool World::rename(const QString &newName) QDir parentDir(m_containerFile.absoluteFilePath()); parentDir.cdUp(); QFile container(m_containerFile.absoluteFilePath()); - auto dirName = DirNameFromString(m_actualName, parentDir.absolutePath()); + auto dirName = FS::DirNameFromString(m_actualName, parentDir.absolutePath()); container.rename(parentDir.absoluteFilePath(dirName)); return true; @@ -350,7 +350,7 @@ bool World::replace(World &with) { if (!destroy()) return false; - bool success = copyPath(with.m_containerFile.filePath(), m_containerFile.path()); + bool success = FS::copyPath(with.m_containerFile.filePath(), m_containerFile.path()); if (success) { m_folderName = with.m_folderName; diff --git a/logic/minecraft/WorldList.cpp b/logic/minecraft/WorldList.cpp index fff4f74a..42c8a3e6 100644 --- a/logic/minecraft/WorldList.cpp +++ b/logic/minecraft/WorldList.cpp @@ -14,7 +14,7 @@ */ #include "WorldList.h" -#include +#include #include #include #include @@ -25,7 +25,7 @@ WorldList::WorldList(const QString &dir) : QAbstractListModel(), m_dir(dir) { - ensureFolderPathExists(m_dir.absolutePath()); + FS::ensureFolderPathExists(m_dir.absolutePath()); m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs | QDir::NoSymLinks); m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); diff --git a/logic/net/CacheDownload.cpp b/logic/net/CacheDownload.cpp index b125a3d9..1d48170a 100644 --- a/logic/net/CacheDownload.cpp +++ b/logic/net/CacheDownload.cpp @@ -14,13 +14,13 @@ */ #include "CacheDownload.h" -#include #include #include #include #include #include "Env.h" +#include CacheDownload::CacheDownload(QUrl url, MetaEntryPtr entry) : NetAction(), md5sum(QCryptographicHash::Md5) @@ -44,7 +44,7 @@ void CacheDownload::start() 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)) + if (!FS::ensureFilePathExists(m_target_path)) { qCritical() << "Could not create folder for " + m_target_path; m_status = Job_Failed; diff --git a/logic/net/HttpMetaCache.cpp b/logic/net/HttpMetaCache.cpp index 977e3a90..3d6aef0d 100644 --- a/logic/net/HttpMetaCache.cpp +++ b/logic/net/HttpMetaCache.cpp @@ -16,7 +16,6 @@ #include "Env.h" #include "HttpMetaCache.h" #include "FileSystem.h" -#include #include #include @@ -33,7 +32,7 @@ QString MetaEntry::getFullPath() { // FIXME: make local? - return PathCombine(ENV.metacache()->getBasePath(base), path); + return FS::PathCombine(ENV.metacache()->getBasePath(base), path); } HttpMetaCache::HttpMetaCache(QString path) : QObject() @@ -77,7 +76,7 @@ MetaEntryPtr HttpMetaCache::resolveEntry(QString base, QString resource_path, } auto &selected_base = m_entries[base]; - QString real_path = PathCombine(selected_base.base_path, resource_path); + QString real_path = FS::PathCombine(selected_base.base_path, resource_path); QFileInfo finfo(real_path); // is the file really there? if not -> stale diff --git a/logic/net/MD5EtagDownload.cpp b/logic/net/MD5EtagDownload.cpp index 7593c87e..3b4d5dcd 100644 --- a/logic/net/MD5EtagDownload.cpp +++ b/logic/net/MD5EtagDownload.cpp @@ -15,7 +15,7 @@ #include "Env.h" #include "MD5EtagDownload.h" -#include +#include #include #include @@ -55,7 +55,7 @@ void MD5EtagDownload::start() // no expected md5. we use the local md5sum as an ETag } } - if (!ensureFilePathExists(filename)) + if (!FS::ensureFilePathExists(filename)) { emit failed(m_index_within_job); return; diff --git a/logic/net/NetJob.cpp b/logic/net/NetJob.cpp index 52307e2a..76c61c35 100644 --- a/logic/net/NetJob.cpp +++ b/logic/net/NetJob.cpp @@ -14,7 +14,6 @@ */ #include "NetJob.h" -#include "pathutils.h" #include "MD5EtagDownload.h" #include "ByteArrayDownload.h" #include "CacheDownload.h" diff --git a/logic/updater/DownloadTask.cpp b/logic/updater/DownloadTask.cpp index 1bbb0edf..6947e8bf 100644 --- a/logic/updater/DownloadTask.cpp +++ b/logic/updater/DownloadTask.cpp @@ -18,7 +18,6 @@ #include "updater/UpdateChecker.h" #include "GoUpdate.h" #include "net/NetJob.h" -#include "pathutils.h" #include #include diff --git a/logic/updater/GoUpdate.cpp b/logic/updater/GoUpdate.cpp index a43c5e7c..60d50e04 100644 --- a/logic/updater/GoUpdate.cpp +++ b/logic/updater/GoUpdate.cpp @@ -1,9 +1,9 @@ #include "GoUpdate.h" -#include #include #include #include #include +#include namespace GoUpdate { @@ -80,7 +80,7 @@ bool processFileLists // delete anything in the current one version's list that isn't in the new version's list. for (VersionFileEntry entry : currentVersion) { - QFileInfo toDelete(PathCombine(rootPath, entry.path)); + QFileInfo toDelete(FS::PathCombine(rootPath, entry.path)); if (!toDelete.exists()) { qCritical() << "Expected file " << toDelete.absoluteFilePath() @@ -114,7 +114,7 @@ bool processFileLists // TODO: Let's not MD5sum a ton of files on the GUI thread. We should probably find a // way to do this in the background. QString fileMD5; - QString realEntryPath = PathCombine(rootPath, entry.path); + QString realEntryPath = FS::PathCombine(rootPath, entry.path); QFile entryFile(realEntryPath); QFileInfo entryInfo(realEntryPath); @@ -186,7 +186,7 @@ bool processFileLists // Download it to updatedir/- where filepath is the file's // path with slashes replaced by underscores. - QString dlPath = PathCombine(tempPath, QString(entry.path).replace("/", "_")); + QString dlPath = FS::PathCombine(tempPath, QString(entry.path).replace("/", "_")); // We need to download the file to the updatefiles folder and add a task // to copy it to its install path. diff --git a/tests/tst_DownloadTask.cpp b/tests/tst_DownloadTask.cpp index 3ff98228..978449f1 100644 --- a/tests/tst_DownloadTask.cpp +++ b/tests/tst_DownloadTask.cpp @@ -6,7 +6,7 @@ #include "updater/GoUpdate.h" #include "updater/DownloadTask.h" #include "updater/UpdateChecker.h" -#include "pathutils.h" +#include using namespace GoUpdate; @@ -166,7 +166,7 @@ slots: << (OperationList() << Operation::DeleteOp("tests/data/fileThree") << Operation::CopyOp( - PathCombine(tempFolder, + FS::PathCombine(tempFolder, QString("tests/data/fileOne").replace("/", "_")), "tests/data/fileOne", 493)); } diff --git a/tests/tst_modutils.cpp b/tests/tst_modutils.cpp index 4d9fe35f..1894711e 100644 --- a/tests/tst_modutils.cpp +++ b/tests/tst_modutils.cpp @@ -15,8 +15,8 @@ #include -#include "modutils.h" #include "TestUtil.h" +#include class ModUtilsTest : public QObject { @@ -95,7 +95,7 @@ private slots: QFETCH(QString, interval); QFETCH(bool, result); - QCOMPARE(Util::versionIsInInterval(version, interval), result); + QCOMPARE(versionIsInInterval(version, interval), result); } void test_versionCompare_data() @@ -109,8 +109,8 @@ private slots: QFETCH(bool, lessThan); QFETCH(bool, equal); - const auto v1 = Util::Version(first); - const auto v2 = Util::Version(second); + const auto v1 = Version(first); + const auto v2 = Version(second); QCOMPARE(v1 < v2, lessThan); QCOMPARE(v1 > v2, !lessThan && !equal); diff --git a/tests/tst_pathutils.cpp b/tests/tst_pathutils.cpp index bccc6dca..de5234b8 100644 --- a/tests/tst_pathutils.cpp +++ b/tests/tst_pathutils.cpp @@ -1,7 +1,6 @@ #include #include "TestUtil.h" - -#include "pathutils.h" +#include class PathUtilsTest : public QObject { @@ -37,7 +36,7 @@ slots: QFETCH(QString, path1); QFETCH(QString, path2); - QCOMPARE(PathCombine(path1, path2), result); + QCOMPARE(FS::PathCombine(path1, path2), result); } void test_PathCombine2_data() @@ -65,7 +64,7 @@ slots: QFETCH(QString, path2); QFETCH(QString, path3); - QCOMPARE(PathCombine(path1, path2, path3), result); + QCOMPARE(FS::PathCombine(path1, path2, path3), result); } }; diff --git a/tests/tst_userutils.cpp b/tests/tst_userutils.cpp index bc7644f3..01f1b2a6 100644 --- a/tests/tst_userutils.cpp +++ b/tests/tst_userutils.cpp @@ -1,8 +1,7 @@ #include #include #include "TestUtil.h" - -#include "userutils.h" +#include class UserUtilsTest : public QObject { @@ -20,7 +19,7 @@ slots: void test_getDesktop() { - QCOMPARE(Util::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); + QCOMPARE(FS::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); } // this is only valid on linux @@ -57,7 +56,7 @@ slots: QFETCH(QString, iconLocation); QFETCH(QByteArray, result); - QVERIFY(Util::createShortCut(location, dest, args, name, iconLocation)); + QVERIFY(FS::createShortCut(location, dest, args, name, iconLocation)); QCOMPARE(QString::fromLocal8Bit(TestsInternal::readFile(location + QDir::separator() + name + ".desktop")), QString::fromLocal8Bit(result)); //QDir().remove(location); -- cgit v1.2.3