NOISSUE dissolve util library

This commit is contained in:
Petr Mrázek 2015-10-05 01:47:27 +02:00
parent 7459eb627c
commit f93f867c3d
80 changed files with 770 additions and 869 deletions

View File

@ -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

View File

@ -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)

View File

@ -1,6 +1,7 @@
#pragma once
#include "minecraft/OneSixInstance.h"
#include "minecraft/LegacyInstance.h"
#include <FileSystem.h>
#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 <pathutils.h>
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<LegacyInstance> legacy = std::dynamic_pointer_cast<LegacyInstance>(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();

View File

@ -331,10 +331,6 @@ namespace Ui {
#include <MMCZip.h>
#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(

View File

@ -41,8 +41,6 @@
#include "tools/JVisualVM.h"
#include "tools/MCEditTool.h"
#include "pathutils.h"
#include "cmdutils.h"
#include <xdgicon.h>
#include "settings/INISettingsObject.h"
#include "settings/Setting.h"
@ -54,7 +52,10 @@
#include "ftb/FTBPlugin.h"
using namespace Util::Commandline;
#include <Commandline.h>
#include <FileSystem.h>
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);

View File

@ -2,7 +2,7 @@
#include "MultiMC.h"
#include <QSortFilterProxyModel>
#include <QPixmapCache>
#include <modutils.h>
#include <Version.h>
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;
}

View File

@ -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;
}
}

View File

@ -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;
};

View File

@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>345</width>
<height>205</height>
<height>240</height>
</rect>
</property>
<property name="windowTitle">
@ -87,7 +87,7 @@
<item row="0" column="0">
<widget class="QLabel" name="labelVersion_3">
<property name="text">
<string>Group</string>
<string>&amp;Group</string>
</property>
<property name="buddy">
<cstring>groupBox</cstring>
@ -109,6 +109,13 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="copySavesCheckbox">
<property name="text">
<string>Copy saves</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">

View File

@ -17,7 +17,6 @@
#include "ui_ExportInstanceDialog.h"
#include <BaseInstance.h>
#include <MMCZip.h>
#include <pathutils.h>
#include <QFileDialog>
#include <QMessageBox>
#include <qfilesystemmodel.h>
@ -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<QModelIndex> 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()

View File

@ -24,7 +24,6 @@
#include <BaseVersion.h>
#include <BaseVersionList.h>
#include <tasks/Task.h>
#include <modutils.h>
#include <QDebug>
#include "MultiMC.h"
#include <VersionProxyModel.h>

View File

@ -10,7 +10,7 @@
#include "MultiMC.h"
#include <java/JavaVersionList.h>
#include <pathutils.h>
#include <FileSystem.h>
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())

View File

@ -19,14 +19,13 @@
#include <QKeyEvent>
#include <QKeyEvent>
#include <pathutils.h>
#include "dialogs/VersionSelectDialog.h"
#include "dialogs/ProgressDialog.h"
#include "dialogs/ModEditDialogCommon.h"
#include "minecraft/ModList.h"
#include "minecraft/LegacyInstance.h"
#include "Env.h"
#include <FileSystem.h>
#include "MultiMC.h"
#include <GuiUtil.h>
@ -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)

View File

@ -22,8 +22,6 @@
#include <QDesktopServices>
#include <QAbstractItemModel>
#include <pathutils.h>
#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 <FileSystem.h>
ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> 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 &current, const QModelIndex &previous)

View File

@ -21,7 +21,7 @@
#include "GuiUtil.h"
#include "RecursiveFileSystemWatcher.h"
#include <GZip.h>
#include <pathutils.h>
#include <FileSystem.h>
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);

View File

@ -15,7 +15,6 @@
#include <QDesktopServices>
#include <QKeyEvent>
#include <pathutils.h>
#include <MultiMC.h>
#include "dialogs/ProgressDialog.h"
@ -26,6 +25,7 @@
#include "tasks/SequentialTask.h"
#include "RWStorage.h"
#include <FileSystem.h>
typedef RWStorage<QString, QIcon> SharedIconCache;
typedef std::shared_ptr<SharedIconCache> 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()

View File

@ -15,7 +15,6 @@
#include "MultiMC.h"
#include <pathutils.h>
#include <QMessageBox>
#include <QEvent>
#include <QKeyEvent>

View File

@ -16,6 +16,7 @@
#include "WorldListPage.h"
#include "ui_WorldListPage.h"
#include "minecraft/WorldList.h"
#include <FileSystem.h>
#include "dialogs/ModEditDialogCommon.h"
#include <QEvent>
#include <QKeyEvent>
@ -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()

View File

@ -20,7 +20,6 @@
#include "minecraft/OneSixInstance.h"
#include "BasePage.h"
#include <MultiMC.h>
#include <pathutils.h>
class WorldList;
namespace Ui

View File

@ -20,10 +20,9 @@
#include <QFileDialog>
#include <QStandardPaths>
#include <pathutils.h>
#include "settings/SettingsObject.h"
#include "tools/BaseProfiler.h"
#include <FileSystem.h>
#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())
{

View File

@ -21,8 +21,6 @@
#include <QMessageBox>
#include <QDir>
#include <pathutils.h>
#include "dialogs/VersionSelectDialog.h"
#include <ColumnResizer.h>
@ -30,6 +28,7 @@
#include "java/JavaVersionList.h"
#include "settings/SettingsObject.h"
#include <FileSystem.h>
#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())

View File

@ -19,8 +19,6 @@
#include <QMessageBox>
#include <QDir>
#include <pathutils.h>
#include "settings/SettingsObject.h"
#include "MultiMC.h"

View File

@ -21,11 +21,11 @@
#include <QDir>
#include <QTextCharFormat>
#include <pathutils.h>
#include <ColumnResizer.h>
#include "updater/UpdateChecker.h"
#include "settings/SettingsObject.h"
#include <FileSystem.h>
#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.

View File

@ -20,8 +20,6 @@
#include <QFileDialog>
#include <QStandardPaths>
#include <pathutils.h>
#include "settings/SettingsObject.h"
#include "tools/BaseProfiler.h"
#include "MultiMC.h"

View File

@ -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)

View File

@ -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 <QString>
#if defined _WIN32 | defined _WIN64
#define WINDOWS 1
#elif __APPLE__ &__MACH__
#define OSX 1
#elif __linux__
#define LINUX 1
#endif

View File

@ -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 <QString>
#include <QDir>
#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);

View File

@ -1,17 +0,0 @@
#pragma once
#include <QString>
#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);
}

View File

@ -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 <QFileInfo>
#include <QDir>
#include <QDesktopServices>
#include <QUrl>
#include <QDebug>
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 <windows.h>
#include <string>
#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);
}

View File

@ -1,126 +0,0 @@
#include "include/userutils.h"
#include <QStandardPaths>
#include <QFile>
#include <QTextStream>
#include "include/osutils.h"
#include "include/pathutils.h"
// Win32 crap
#if WINDOWS
#include <windows.h>
#include <winnls.h>
#include <shobjidl.h>
#include <objbase.h>
#include <objidl.h>
#include <shlguid.h>
#include <shlobj.h>
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
}

View File

@ -22,10 +22,10 @@
#include "settings/Setting.h"
#include "settings/OverrideSetting.h"
#include "pathutils.h"
#include <cmdutils.h>
#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());
}

View File

@ -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)

View File

@ -15,14 +15,12 @@
* limitations under the License.
*/
#include "include/cmdutils.h"
#include "Commandline.h"
/**
* @file libutil/src/cmdutils.cpp
*/
namespace Util
{
namespace Commandline
{
@ -482,5 +480,4 @@ void Parser::getPrefix(QString &opt, QString &flag)
ParsingError::ParsingError(const QString &what) : std::runtime_error(what.toStdString())
{
}
}
}
}

View File

@ -25,15 +25,13 @@
#include <QHash>
#include <QStringList>
#include "multimc_util_export.h"
#include "multimc_logic_export.h"
/**
* @file libutil/include/cmdutils.h
* @brief commandline parsing and processing utilities
*/
namespace Util
{
namespace Commandline
{
@ -42,7 +40,7 @@ namespace Commandline
* @param args the argument string
* @return a QStringList containing all arguments
*/
MULTIMC_UTIL_EXPORT QStringList splitArgs(QString args);
MULTIMC_LOGIC_EXPORT QStringList splitArgs(QString args);
/**
* @brief The FlagStyle enum
@ -85,7 +83,7 @@ enum Enum
/**
* @brief The ParsingError class
*/
class MULTIMC_UTIL_EXPORT ParsingError : public std::runtime_error
class MULTIMC_LOGIC_EXPORT ParsingError : public std::runtime_error
{
public:
ParsingError(const QString &what);
@ -94,7 +92,7 @@ public:
/**
* @brief The Parser class
*/
class MULTIMC_UTIL_EXPORT Parser
class MULTIMC_LOGIC_EXPORT Parser
{
public:
/**
@ -252,4 +250,3 @@ private:
void getPrefix(QString &opt, QString &flag);
};
}
}

View File

@ -5,6 +5,9 @@
#include <QDir>
#include <QSaveFile>
#include <QFileInfo>
#include <QDebug>
#include <QDesktopServices>
#include <QUrl>
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 <windows.h>
#include <string>
#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 <QStandardPaths>
#include <QFile>
#include <QTextStream>
// Win32 crap
#if defined Q_OS_WIN
#include <windows.h>
#include <winnls.h>
#include <shobjidl.h>
#include <objbase.h>
#include <objidl.h>
#include <shlguid.h>
#include <shlobj.h>
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
}

View File

@ -5,6 +5,7 @@
#include "Exception.h"
#include "multimc_logic_export.h"
#include <QDir>
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);
}

View File

@ -24,7 +24,6 @@
#include <QJsonArray>
#include <QXmlStreamReader>
#include <QRegularExpression>
#include <pathutils.h>
#include <QDebug>
#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<INISettingsObject>(PathCombine(instDir, "instance.cfg"));
auto instanceSettings = std::make_shared<INISettingsObject>(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<INISettingsObject>(PathCombine(instDir, "instance.cfg"));
auto instanceSettings = std::make_shared<INISettingsObject>(FS::PathCombine(instDir, "instance.cfg"));
instanceSettings->registerSetting("InstanceType", "Legacy");
auto minecraftVersion = std::dynamic_pointer_cast<MinecraftVersion>(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();

View File

@ -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.

View File

@ -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 <pathutils.h>
#include <quazip.h>
#include <JlCompress.h>
#include <quazipdir.h>
#include "MMCZip.h"
#include "FileSystem.h"
#include <QDebug>
@ -111,7 +111,7 @@ bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QStr
if(!blacklist || !blacklist->covers(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<QStr
}
if(prefix.size())
{
filename = PathCombine(prefix, filename);
filename = FS::PathCombine(prefix, filename);
}
added.insert(filename);
if (!compressFile(zip,file.absoluteFilePath(),filename))

View File

@ -1,16 +1,16 @@
#include "include/modutils.h"
#include "Version.h"
#include <QStringList>
#include <QUrl>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
Util::Version::Version(const QString &str) : m_string(str)
Version::Version(const QString &str) : m_string(str)
{
parse();
}
bool Util::Version::operator<(const Version &other) const
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)
@ -26,11 +26,11 @@ bool Util::Version::operator<(const Version &other) const
return false;
}
bool Util::Version::operator<=(const Util::Version &other) const
bool Version::operator<=(const Version &other) const
{
return *this < other || *this == other;
}
bool Util::Version::operator>(const Version &other) const
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)
@ -46,11 +46,11 @@ bool Util::Version::operator>(const Version &other) const
return false;
}
bool Util::Version::operator>=(const Version &other) const
bool Version::operator>=(const Version &other) const
{
return *this > other || *this == other;
}
bool Util::Version::operator==(const Version &other) const
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)
@ -66,12 +66,12 @@ bool Util::Version::operator==(const Version &other) const
return true;
}
bool Util::Version::operator!=(const Version &other) const
bool Version::operator!=(const Version &other) const
{
return !operator==(other);
}
void Util::Version::parse()
void Version::parse()
{
m_sections.clear();
@ -83,11 +83,11 @@ void Util::Version::parse()
}
}
bool Util::versionIsInInterval(const QString &version, const QString &interval)
bool versionIsInInterval(const QString &version, const QString &interval)
{
return versionIsInInterval(Util::Version(version), interval);
return versionIsInInterval(Version(version), interval);
}
bool Util::versionIsInInterval(const Version &version, const QString &interval)
bool versionIsInInterval(const Version &version, const QString &interval)
{
if (interval.isEmpty() || version.toString() == interval)
{
@ -108,7 +108,7 @@ bool Util::versionIsInInterval(const Version &version, const QString &interval)
// check if in range (bottom)
if (!bottom.isEmpty())
{
const auto bottomVersion = Util::Version(bottom);
const auto bottomVersion = Version(bottom);
if ((start == '[') && !(version >= bottomVersion))
{
return false;
@ -122,7 +122,7 @@ bool Util::versionIsInInterval(const Version &version, const QString &interval)
// check if in range (top)
if (!top.isEmpty())
{
const auto topVersion = Util::Version(top);
const auto topVersion = Version(top);
if ((end == ']') && !(version <= topVersion))
{
return false;
@ -138,4 +138,3 @@ bool Util::versionIsInInterval(const Version &version, const QString &interval)
return false;
}

View File

@ -3,13 +3,11 @@
#include <QString>
#include <QList>
#include "multimc_util_export.h"
#include "multimc_logic_export.h"
class QUrl;
namespace Util
{
struct Version
struct MULTIMC_LOGIC_EXPORT Version
{
Version(const QString &str);
Version() {}
@ -107,7 +105,6 @@ private:
void parse();
};
MULTIMC_UTIL_EXPORT bool versionIsInInterval(const QString &version, const QString &interval);
MULTIMC_UTIL_EXPORT bool versionIsInInterval(const Version &version, const QString &interval);
}
MULTIMC_LOGIC_EXPORT bool versionIsInInterval(const QString &version, const QString &interval);
MULTIMC_LOGIC_EXPORT bool versionIsInInterval(const Version &version, const QString &interval);

View File

@ -27,7 +27,7 @@
#include <QDebug>
#include "auth/MojangAccount.h"
#include <pathutils.h>
#include <FileSystem.h>
#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)

View File

@ -23,10 +23,10 @@
#include "minecraft/VersionFilterData.h"
#include "Env.h"
#include "Exception.h"
#include <FileSystem.h>
#include <quazip.h>
#include <quazipfile.h>
#include <pathutils.h>
#include <QStringList>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
@ -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;
}

View File

@ -15,7 +15,7 @@
#include "Env.h"
#include "ForgeXzDownload.h"
#include <pathutils.h>
#include <FileSystem.h>
#include <QCryptographicHash>
#include <QFileInfo>
@ -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);

View File

@ -7,7 +7,7 @@
#include <InstanceList.h>
#include <minecraft/MinecraftVersionList.h>
#include <settings/INISettingsObject.h>
#include <pathutils.h>
#include <FileSystem.h>
#include "QDebug"
#include <QXmlStreamReader>
#include <QRegularExpression>
@ -137,7 +137,7 @@ InstancePtr loadInstance(SettingsObjectPtr globalSettings, QMap<QString, QString
{
InstancePtr inst;
auto m_settings = std::make_shared<INISettingsObject>(PathCombine(record.instanceDir, "instance.cfg"));
auto m_settings = std::make_shared<INISettingsObject>(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<QString, QStri
return nullptr;
}
auto m_settings = std::make_shared<INISettingsObject>(PathCombine(record.instanceDir, "instance.cfg"));
auto m_settings = std::make_shared<INISettingsObject>(FS::PathCombine(record.instanceDir, "instance.cfg"));
m_settings->registerSetting("InstanceType", "Legacy");
if (mcVersion->usesLegacyLauncher())
@ -257,8 +257,8 @@ void FTBPlugin::loadInstances(SettingsObjectPtr globalSettings, QMap<QString, QS
{
qDebug() << "Loading FTB instance from " << record.instanceDir;
QString iconKey = record.iconKey;
ENV.icons()->addIcon(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())

View File

@ -2,8 +2,8 @@
#include "minecraft/VersionBuildError.h"
#include "ftb/OneSixFTBInstance.h"
#include "minecraft/MinecraftVersionList.h"
#include <FileSystem.h>
#include <pathutils.h>
#include <QDir>
#include <QUuid>
#include <QJsonDocument>
@ -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)

View File

@ -7,7 +7,7 @@
#include "forge/ForgeInstaller.h"
#include "forge/ForgeVersionList.h"
#include <settings/INISettingsObject.h>
#include "pathutils.h"
#include <FileSystem.h>
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;
}

View File

@ -14,7 +14,7 @@
*/
#include "IconList.h"
#include <pathutils.h>
#include <FileSystem.h>
#include <QMap>
#include <QEventLoop>
#include <QMimeData>
@ -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")

View File

@ -1,6 +1,6 @@
#include "JavaChecker.h"
#include <pathutils.h>
#include <cmdutils.h>
#include <FileSystem.h>
#include <Commandline.h>
#include <QFile>
#include <QProcess>
#include <QMap>
@ -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)

View File

@ -14,7 +14,6 @@
*/
#include "JavaCheckerJob.h"
#include "pathutils.h"
#include <QDebug>

View File

@ -19,7 +19,6 @@
#include <QStringList>
#include <settings/Setting.h>
#include <pathutils.h>
#include <QDebug>
#include "java/JavaUtils.h"

View File

@ -18,12 +18,11 @@
#include <QStringList>
#include <QWidget>
#include <osutils.h>
#include "JavaCheckerJob.h"
#include "JavaChecker.h"
#include "JavaVersionList.h"
#if WINDOWS
#ifdef Q_OS_WIN
#include <windows.h>
#endif
@ -39,7 +38,7 @@ public:
QList<QString> FindJavaPaths();
JavaVersionPtr GetDefaultJava();
#if WINDOWS
#ifdef Q_OS_WIN
QList<JavaVersionPtr> FindJavaFromRegistryKey(DWORD keyType, QString keyName);
#endif
};

View File

@ -20,7 +20,6 @@
#include "MMCStrings.h"
#include "java/JavaChecker.h"
#include "tasks/Task.h"
#include <pathutils.h>
#include <QDebug>
#include <QDir>
#include <QEventLoop>

View File

@ -15,7 +15,7 @@
#include "CheckJava.h"
#include <launch/LaunchTask.h>
#include <pathutils.h>
#include <FileSystem.h>
#include <QStandardPaths>
#include <QFileInfo>
@ -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);

View File

@ -16,7 +16,7 @@
#include "LaunchMinecraft.h"
#include <launch/LaunchTask.h>
#include <minecraft/OneSixInstance.h>
#include <pathutils.h>
#include <FileSystem.h>
#include <QStandardPaths>
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());

View File

@ -23,7 +23,7 @@
#include <QDebug>
#include "AssetsUtils.h"
#include <pathutils.h>
#include <FileSystem.h>
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;

View File

@ -17,8 +17,6 @@
#include <QDir>
#include <QImage>
#include <settings/Setting.h>
#include <pathutils.h>
#include <cmdutils.h>
#include "LegacyInstance.h"
@ -35,6 +33,7 @@
#include "minecraft/ModList.h"
#include "minecraft/WorldList.h"
#include <MMCZip.h>
#include <FileSystem.h>
LegacyInstance::LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
: MinecraftInstance(globalSettings, settings, rootDir)
@ -109,7 +108,7 @@ std::shared_ptr<LaunchTask> 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<WorldList> 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

View File

@ -14,7 +14,6 @@
*/
#include <QStringList>
#include <pathutils.h>
#include <quazip.h>
#include <quazipfile.h>
#include <QDebug>
@ -30,6 +29,7 @@
#include "minecraft/MinecraftVersionList.h"
#include "minecraft/ModList.h"
#include "minecraft/LegacyInstance.h"
#include <FileSystem.h>
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();

View File

@ -1,12 +1,12 @@
#include "MinecraftInstance.h"
#include <settings/Setting.h>
#include "settings/SettingsObject.h"
#include <pathutils.h>
#include "Env.h"
#include "minecraft/MinecraftVersionList.h"
#include <MMCStrings.h>
#include <pathmatcher/RegexpMatcher.h>
#include <pathmatcher/MultiMatcher.h>
#include <FileSystem.h>
#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;
}

View File

@ -18,7 +18,6 @@
#include <QJsonDocument>
#include <QJsonArray>
#include <QDebug>
#include <pathutils.h>
#include "minecraft/MinecraftProfile.h"
#include "ProfileUtils.h"

View File

@ -27,8 +27,7 @@
#include "ParseUtils.h"
#include "ProfileUtils.h"
#include "VersionFilterData.h"
#include <pathutils.h>
#include <FileSystem.h>
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<Task> 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))

View File

@ -23,8 +23,8 @@
#include <quazipfile.h>
#include "Mod.h"
#include <pathutils.h>
#include "settings/INIFile.h"
#include <FileSystem.h>
#include <QDebug>
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)
{

View File

@ -14,7 +14,7 @@
*/
#include "ModList.h"
#include <pathutils.h>
#include <FileSystem.h>
#include <QMimeData>
#include <QUrl>
#include <QUuid>
@ -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);

View File

@ -14,7 +14,6 @@
*/
#include <QIcon>
#include <pathutils.h>
#include <QDebug>
#include "minecraft/OneSixInstance.h"
@ -36,6 +35,7 @@
#include "minecraft/AssetsUtils.h"
#include "icons/IconList.h"
#include "minecraft/WorldList.h"
#include <FileSystem.h>
OneSixInstance::OneSixInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
: MinecraftInstance(globalSettings, settings, rootDir)
@ -136,7 +136,7 @@ std::shared_ptr<LaunchTask> 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<LaunchTask> 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<Task> 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

View File

@ -3,8 +3,8 @@
#include "minecraft/OneSixInstance.h"
#include "minecraft/MinecraftVersionList.h"
#include "Env.h"
#include <FileSystem.h>
#include <pathutils.h>
#include <QDir>
#include <QUuid>
#include <QJsonDocument>
@ -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);

View File

@ -22,7 +22,6 @@
#include <QFileInfo>
#include <QTextStream>
#include <QDataStream>
#include <pathutils.h>
#include <JlCompress.h>
#include "BaseInstance.h"
@ -35,6 +34,7 @@
#include "minecraft/AssetsUtils.h"
#include "Exception.h"
#include "MMCZip.h"
#include <FileSystem.h>
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;

View File

@ -2,7 +2,7 @@
using namespace Json;
#include "RawLibrary.h"
#include <pathutils.h>
#include <FileSystem.h>
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

View File

@ -1,6 +1,5 @@
#include <QJsonArray>
#include <QJsonDocument>
#include <modutils.h>
#include <QDebug>
@ -14,6 +13,7 @@
using namespace Json;
#include "VersionBuildError.h"
#include <Version.h>
#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)

View File

@ -18,10 +18,10 @@
#include <QDebug>
#include <QSaveFile>
#include "World.h"
#include <pathutils.h>
#include "GZip.h"
#include <MMCZip.h>
#include <FileSystem.h>
#include <sstream>
#include <io/stream_reader.h>
#include <tag_string.h>
@ -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;

View File

@ -14,7 +14,7 @@
*/
#include "WorldList.h"
#include <pathutils.h>
#include <FileSystem.h>
#include <QMimeData>
#include <QUrl>
#include <QUuid>
@ -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);

View File

@ -14,13 +14,13 @@
*/
#include "CacheDownload.h"
#include <pathutils.h>
#include <QCryptographicHash>
#include <QFileInfo>
#include <QDateTime>
#include <QDebug>
#include "Env.h"
#include <FileSystem.h>
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;

View File

@ -16,7 +16,6 @@
#include "Env.h"
#include "HttpMetaCache.h"
#include "FileSystem.h"
#include <pathutils.h>
#include <QFileInfo>
#include <QFile>
@ -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

View File

@ -15,7 +15,7 @@
#include "Env.h"
#include "MD5EtagDownload.h"
#include <pathutils.h>
#include <FileSystem.h>
#include <QCryptographicHash>
#include <QDebug>
@ -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;

View File

@ -14,7 +14,6 @@
*/
#include "NetJob.h"
#include "pathutils.h"
#include "MD5EtagDownload.h"
#include "ByteArrayDownload.h"
#include "CacheDownload.h"

View File

@ -18,7 +18,6 @@
#include "updater/UpdateChecker.h"
#include "GoUpdate.h"
#include "net/NetJob.h"
#include "pathutils.h"
#include <QFile>
#include <QTemporaryDir>

View File

@ -1,9 +1,9 @@
#include "GoUpdate.h"
#include <pathutils.h>
#include <QDebug>
#include <QDomDocument>
#include <QFile>
#include <Env.h>
#include <FileSystem.h>
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/<filepath>-<md5> 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.

View File

@ -6,7 +6,7 @@
#include "updater/GoUpdate.h"
#include "updater/DownloadTask.h"
#include "updater/UpdateChecker.h"
#include "pathutils.h"
#include <FileSystem.h>
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));
}

View File

@ -15,8 +15,8 @@
#include <QTest>
#include "modutils.h"
#include "TestUtil.h"
#include <Version.h>
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);

View File

@ -1,7 +1,6 @@
#include <QTest>
#include "TestUtil.h"
#include "pathutils.h"
#include <FileSystem.h>
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);
}
};

View File

@ -1,8 +1,7 @@
#include <QTest>
#include <QStandardPaths>
#include "TestUtil.h"
#include "userutils.h"
#include <FileSystem.h>
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);