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 ######## ######## MultiMC Libs ########
add_subdirectory(depends/util) # various utility functions
add_subdirectory(depends/LogicalGui) # GUI -> Logic connection add_subdirectory(depends/LogicalGui) # GUI -> Logic connection
add_subdirectory(depends/iconfix) # fork of Qt's QIcon loader 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
add_executable(MultiMC MACOSX_BUNDLE WIN32 ${MULTIMC_SOURCES} ${MULTIMC_UI} ${MULTIMC_RESOURCES} ${MULTIMC_RCS}) 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) if(APPLE)
find_library(OSX_CORE_FOUNDATION CoreFoundation) find_library(OSX_CORE_FOUNDATION CoreFoundation)

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "minecraft/OneSixInstance.h" #include "minecraft/OneSixInstance.h"
#include "minecraft/LegacyInstance.h" #include "minecraft/LegacyInstance.h"
#include <FileSystem.h>
#include "pages/BasePage.h" #include "pages/BasePage.h"
#include "pages/VersionPage.h" #include "pages/VersionPage.h"
#include "pages/ModFolderPage.h" #include "pages/ModFolderPage.h"
@ -13,7 +14,6 @@
#include "pages/BasePageProvider.h" #include "pages/BasePageProvider.h"
#include "pages/LegacyJarModPage.h" #include "pages/LegacyJarModPage.h"
#include "pages/WorldListPage.h" #include "pages/WorldListPage.h"
#include <pathutils.h>
class InstancePageProvider : public QObject, public BasePageProvider class InstancePageProvider : public QObject, public BasePageProvider
@ -41,7 +41,7 @@ public:
values.append(new TexturePackPage(onesix.get())); values.append(new TexturePackPage(onesix.get()));
values.append(new NotesPage(onesix.get())); values.append(new NotesPage(onesix.get()));
values.append(new WorldListPage(onesix.get(), onesix->worldList(), "worlds", "worlds", tr("Worlds"), "Worlds")); 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())); values.append(new InstanceSettingsPage(onesix.get()));
} }
std::shared_ptr<LegacyInstance> legacy = std::dynamic_pointer_cast<LegacyInstance>(inst); 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 TexturePackPage(legacy.get()));
values.append(new NotesPage(legacy.get())); values.append(new NotesPage(legacy.get()));
values.append(new WorldListPage(legacy.get(), legacy->worldList(), "worlds", "worlds", tr("Worlds"), "Worlds")); 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())); values.append(new InstanceSettingsPage(legacy.get()));
} }
auto logMatcher = inst->getLogFileMatcher(); auto logMatcher = inst->getLogFileMatcher();

View File

@ -331,10 +331,6 @@ namespace Ui {
#include <MMCZip.h> #include <MMCZip.h>
#include "osutils.h"
#include "userutils.h"
#include "pathutils.h"
#include "groupview/GroupView.h" #include "groupview/GroupView.h"
#include "groupview/InstanceDelegate.h" #include "groupview/InstanceDelegate.h"
#include "InstanceProxyModel.h" #include "InstanceProxyModel.h"
@ -972,8 +968,8 @@ void MainWindow::downloadUpdates(GoUpdate::Status status)
ProgressDialog updateDlg(this); ProgressDialog updateDlg(this);
status.rootPath = MMC->rootPath; status.rootPath = MMC->rootPath;
auto dlPath = PathCombine(MMC->root(), "update", "XXXXXX"); auto dlPath = FS::PathCombine(MMC->root(), "update", "XXXXXX");
if(!ensureFilePathExists(dlPath)) if(!FS::ensureFilePathExists(dlPath))
{ {
CustomMessageBox::selectable(this, tr("Error"), tr("Couldn't create folder for update downloads:\n%1").arg(dlPath), QMessageBox::Warning)->show(); 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; InstancePtr newInstance;
QString instancesDir = MMC->settings()->get("InstanceDir").toString(); QString instancesDir = MMC->settings()->get("InstanceDir").toString();
QString instDirName = DirNameFromString(instName, instancesDir); QString instDirName = FS::DirNameFromString(instName, instancesDir);
QString instDir = PathCombine(instancesDir, instDirName); QString instDir = FS::PathCombine(instancesDir, instDirName);
QString archivePath; QString archivePath;
if (url.isLocalFile()) 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(); CustomMessageBox::selectable(this, tr("Error"), tr("Archive does not contain instance.cfg"))->show();
return nullptr; 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(); CustomMessageBox::selectable(this, tr("Error"), tr("Unable to copy instance"))->show();
return nullptr; return nullptr;
@ -1124,7 +1120,7 @@ InstancePtr MainWindow::instanceFromZipPack(QString instName, QString instGroup,
else else
{ {
instIcon = newInstance->iconKey(); instIcon = newInstance->iconKey();
auto importIconPath = PathCombine(newInstance->instanceRoot(), instIcon + ".png"); auto importIconPath = FS::PathCombine(newInstance->instanceRoot(), instIcon + ".png");
if (QFile::exists(importIconPath)) if (QFile::exists(importIconPath))
{ {
// import icon // import icon
@ -1153,8 +1149,8 @@ InstancePtr MainWindow::instanceFromVersion(QString instName, QString instGroup,
InstancePtr newInstance; InstancePtr newInstance;
QString instancesDir = MMC->settings()->get("InstanceDir").toString(); QString instancesDir = MMC->settings()->get("InstanceDir").toString();
QString instDirName = DirNameFromString(instName, instancesDir); QString instDirName = FS::DirNameFromString(instName, instancesDir);
QString instDir = PathCombine(instancesDir, instDirName); QString instDir = FS::PathCombine(instancesDir, instDirName);
auto error = MMC->instances()->createInstance(newInstance, version, instDir); auto error = MMC->instances()->createInstance(newInstance, version, instDir);
QString errorMsg = tr("Failed to create instance %1: ").arg(instDirName); QString errorMsg = tr("Failed to create instance %1: ").arg(instDirName);
switch (error) switch (error)
@ -1257,11 +1253,12 @@ void MainWindow::on_actionCopyInstance_triggered()
return; return;
QString instancesDir = MMC->settings()->get("InstanceDir").toString(); QString instancesDir = MMC->settings()->get("InstanceDir").toString();
QString instDirName = DirNameFromString(copyInstDlg.instName(), instancesDir); QString instDirName = FS::DirNameFromString(copyInstDlg.instName(), instancesDir);
QString instDir = PathCombine(instancesDir, instDirName); QString instDir = FS::PathCombine(instancesDir, instDirName);
bool copySaves = copyInstDlg.shouldCopySaves();
InstancePtr newInstance; 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); QString errorMsg = tr("Failed to create instance %1: ").arg(instDirName);
switch (error) switch (error)
@ -1359,7 +1356,7 @@ void MainWindow::on_actionChangeInstGroup_triggered()
void MainWindow::on_actionViewInstanceFolder_triggered() void MainWindow::on_actionViewInstanceFolder_triggered()
{ {
QString str = MMC->settings()->get("InstanceDir").toString(); QString str = MMC->settings()->get("InstanceDir").toString();
openDirInDefaultProgram(str); FS::openDirInDefaultProgram(str);
} }
void MainWindow::on_actionRefresh_triggered() void MainWindow::on_actionRefresh_triggered()
@ -1369,7 +1366,7 @@ void MainWindow::on_actionRefresh_triggered()
void MainWindow::on_actionViewCentralModsFolder_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() void MainWindow::on_actionConfig_Folder_triggered()
@ -1377,7 +1374,7 @@ void MainWindow::on_actionConfig_Folder_triggered()
if (m_selectedInstance) if (m_selectedInstance)
{ {
QString str = m_selectedInstance->instanceConfigFolder(); 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) if (m_selectedInstance)
{ {
QString str = m_selectedInstance->instanceRoot(); QString str = m_selectedInstance->instanceRoot();
openDirInDefaultProgram(QDir(str).absolutePath()); FS::openDirInDefaultProgram(QDir(str).absolutePath());
} }
} }
@ -1677,7 +1674,7 @@ void MainWindow::checkSetDefaultJava()
break; break;
} }
QString currentJavaPath = MMC->settings()->get("JavaPath").toString(); QString currentJavaPath = MMC->settings()->get("JavaPath").toString();
QString actualPath = ResolveExecutable(currentJavaPath); QString actualPath = FS::ResolveExecutable(currentJavaPath);
if (currentJavaPath.isNull()) if (currentJavaPath.isNull())
{ {
askForJava = true; askForJava = true;
@ -1738,7 +1735,7 @@ void MainWindow::checkSetDefaultJava()
void MainWindow::checkInstancePathForProblems() void MainWindow::checkInstancePathForProblems()
{ {
QString instanceFolder = MMC->settings()->get("InstanceDir").toString(); QString instanceFolder = MMC->settings()->get("InstanceDir").toString();
if (checkProblemticPathJava(QDir(instanceFolder))) if (FS::checkProblemticPathJava(QDir(instanceFolder)))
{ {
QMessageBox warning(this); QMessageBox warning(this);
warning.setText(tr( warning.setText(tr(

View File

@ -41,8 +41,6 @@
#include "tools/JVisualVM.h" #include "tools/JVisualVM.h"
#include "tools/MCEditTool.h" #include "tools/MCEditTool.h"
#include "pathutils.h"
#include "cmdutils.h"
#include <xdgicon.h> #include <xdgicon.h>
#include "settings/INISettingsObject.h" #include "settings/INISettingsObject.h"
#include "settings/Setting.h" #include "settings/Setting.h"
@ -54,7 +52,10 @@
#include "ftb/FTBPlugin.h" #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) 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(); launchId = args["launch"].toString();
if (!ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath)) if (!FS::ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath))
{ {
// BAD STUFF. WHAT DO? // BAD STUFF. WHAT DO?
initLogger(); initLogger();
@ -159,7 +160,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar
else else
{ {
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QDir foo(PathCombine(binPath, "..")); QDir foo(FS::PathCombine(binPath, ".."));
rootPath = foo.absolutePath(); rootPath = foo.absolutePath();
#elif defined(Q_OS_WIN32) #elif defined(Q_OS_WIN32)
rootPath = binPath; 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 // static data paths... mostly just for translations
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QDir foo(PathCombine(binPath, "..")); QDir foo(FS::PathCombine(binPath, ".."));
staticDataPath = foo.absolutePath(); staticDataPath = foo.absolutePath();
#elif defined(Q_OS_WIN32) #elif defined(Q_OS_WIN32)
staticDataPath = binPath; staticDataPath = binPath;
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
QDir foo(PathCombine(rootPath, "Contents/Resources")); QDir foo(FS::PathCombine(rootPath, "Contents/Resources"));
staticDataPath = foo.absolutePath(); staticDataPath = foo.absolutePath();
#endif #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) // 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(); QString instDir = m_settings->get("InstanceDir").toString();
qDebug() << "Instance path : " << instDir; qDebug() << "Instance path : " << instDir;
if (checkProblemticPathJava(QDir(instDir))) if (FS::checkProblemticPathJava(QDir(instDir)))
{ {
qWarning() qWarning()
<< "Your instance path contains \'!\' and this is known to cause java problems"; << "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; bool started = false;
qDebug() << "Installing updates."; qDebug() << "Installing updates.";
#ifdef WINDOWS #ifdef Q_OS_WIN
QString finishCmd = applicationFilePath(); QString finishCmd = applicationFilePath();
#elif LINUX #elif defined Q_OS_LINUX
QString finishCmd = PathCombine(root(), "MultiMC"); QString finishCmd = FS::PathCombine(root(), "MultiMC");
#elif OSX #elif defined Q_OS_MAC
QString finishCmd = applicationFilePath(); QString finishCmd = applicationFilePath();
#else #else
#error Unsupported operating system. #error Unsupported operating system.
#endif #endif
QString backupPath = PathCombine(root(), "update", "backup"); QString backupPath = FS::PathCombine(root(), "update", "backup");
QDir origin(root()); QDir origin(root());
// clean up the backup folder. it should be empty before we start // 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; qWarning() << "couldn't remove previous backup folder" << backupPath;
} }
// and it should exist. // and it should exist.
if(!ensureFolderPathExists(backupPath)) if(!FS::ensureFolderPathExists(backupPath))
{ {
qWarning() << "couldn't create folder" << backupPath; qWarning() << "couldn't create folder" << backupPath;
return; 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 // replace = move original out to backup, if it exists, move the new file in its place
case GoUpdate::Operation::OP_REPLACE: case GoUpdate::Operation::OP_REPLACE:
{ {
QFileInfo replaced (PathCombine(root(), op.dest)); QFileInfo replaced (FS::PathCombine(root(), op.dest));
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
if(QSysInfo::windowsVersion() < QSysInfo::WV_VISTA) if(QSysInfo::windowsVersion() < QSysInfo::WV_VISTA)
{ {
@ -735,7 +736,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
QDir rootDir(root()); QDir rootDir(root());
exeOrigin = rootDir.relativeFilePath(op.file); exeOrigin = rootDir.relativeFilePath(op.file);
exePath = rootDir.relativeFilePath(op.dest); exePath = rootDir.relativeFilePath(op.dest);
exeBackup = rootDir.relativeFilePath(PathCombine(backupPath, replaced.fileName())); exeBackup = rootDir.relativeFilePath(FS::PathCombine(backupPath, replaced.fileName()));
useXPHack = true; useXPHack = true;
continue; continue;
} }
@ -745,7 +746,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
{ {
QString backupName = op.dest; QString backupName = op.dest;
backupName.replace('/', '_'); backupName.replace('/', '_');
QString backupFilePath = PathCombine(backupPath, backupName); QString backupFilePath = FS::PathCombine(backupPath, backupName);
if(!QFile::rename(replaced.absoluteFilePath(), backupFilePath)) if(!QFile::rename(replaced.absoluteFilePath(), backupFilePath))
{ {
qWarning() << "Couldn't move:" << replaced.absoluteFilePath() << "to" << backupFilePath; qWarning() << "Couldn't move:" << replaced.absoluteFilePath() << "to" << backupFilePath;
@ -759,7 +760,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
backups.append(be); backups.append(be);
} }
// make sure the folder we are putting this into exists // 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(); qWarning() << "REPLACE: Couldn't create folder:" << replaced.absoluteFilePath();
failedOperationType = Replace; failedOperationType = Replace;
@ -780,12 +781,12 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
// delete = move original to backup // delete = move original to backup
case GoUpdate::Operation::OP_DELETE: case GoUpdate::Operation::OP_DELETE:
{ {
QString origFilePath = PathCombine(root(), op.file); QString origFilePath = FS::PathCombine(root(), op.file);
if(QFile::exists(origFilePath)) if(QFile::exists(origFilePath))
{ {
QString backupName = op.file; QString backupName = op.file;
backupName.replace('/', '_'); backupName.replace('/', '_');
QString trashFilePath = PathCombine(backupPath, backupName); QString trashFilePath = FS::PathCombine(backupPath, backupName);
if(!QFile::rename(origFilePath, trashFilePath)) if(!QFile::rename(origFilePath, trashFilePath))
{ {
@ -825,7 +826,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
out << "fso.MoveFile \"" << nativeOriginPath << "\", \"" << nativePath << "\"\n"; out << "fso.MoveFile \"" << nativeOriginPath << "\", \"" << nativePath << "\"\n";
out << "shell.Run \"" << 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 // we save it
QFile scriptFile(scriptPath); QFile scriptFile(scriptPath);

View File

@ -2,7 +2,7 @@
#include "MultiMC.h" #include "MultiMC.h"
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QPixmapCache> #include <QPixmapCache>
#include <modutils.h> #include <Version.h>
class VersionFilterModel : public QSortFilterProxyModel class VersionFilterModel : public QSortFilterProxyModel
{ {
@ -35,7 +35,7 @@ public:
return false; return false;
} }
} }
else if (!Util::versionIsInInterval(versionString, it.value().string)) else if (!versionIsInInterval(versionString, it.value().string))
{ {
return false; return false;
} }

View File

@ -52,6 +52,7 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent)
} }
ui->groupBox->setCurrentIndex(index); ui->groupBox->setCurrentIndex(index);
ui->groupBox->lineEdit()->setPlaceholderText(tr("No group")); ui->groupBox->lineEdit()->setPlaceholderText(tr("No group"));
ui->copySavesCheckbox->setChecked(m_copySaves);
} }
CopyInstanceDialog::~CopyInstanceDialog() CopyInstanceDialog::~CopyInstanceDialog()
@ -95,3 +96,20 @@ void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1)
{ {
updateDialogState(); 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 instName() const;
QString instGroup() const; QString instGroup() const;
QString iconKey() const; QString iconKey() const;
bool shouldCopySaves() const;
private private
slots: slots:
void on_iconButton_clicked(); void on_iconButton_clicked();
void on_instNameTextBox_textChanged(const QString &arg1); void on_instNameTextBox_textChanged(const QString &arg1);
void on_copySavesCheckbox_stateChanged(int state);
private: private:
Ui::CopyInstanceDialog *ui; Ui::CopyInstanceDialog *ui;
QString InstIconKey; QString InstIconKey;
InstancePtr m_original; InstancePtr m_original;
bool m_copySaves = true;
}; };

View File

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

View File

@ -17,7 +17,6 @@
#include "ui_ExportInstanceDialog.h" #include "ui_ExportInstanceDialog.h"
#include <BaseInstance.h> #include <BaseInstance.h>
#include <MMCZip.h> #include <MMCZip.h>
#include <pathutils.h>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <qfilesystemmodel.h> #include <qfilesystemmodel.h>
@ -185,7 +184,7 @@ public:
blocked.remove(cover); blocked.remove(cover);
// block all contents, except for any cover // block all contents, except for any cover
QModelIndex rootIndex = QModelIndex rootIndex =
fsm->index(PathCombine(m_instance->instanceRoot(), cover)); fsm->index(FS::PathCombine(m_instance->instanceRoot(), cover));
QModelIndex doing = rootIndex; QModelIndex doing = rootIndex;
int row = 0; int row = 0;
QStack<QModelIndex> todo; QStack<QModelIndex> todo;
@ -376,18 +375,18 @@ void SaveIcon(InstancePtr m_instance)
} }
} }
auto pixmap = icon.pixmap(largest); 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() bool ExportInstanceDialog::doExport()
{ {
auto name = RemoveInvalidFilenameChars(m_instance->name()); auto name = FS::RemoveInvalidFilenameChars(m_instance->name());
const QString output = QFileDialog::getSaveFileName( const QString output = QFileDialog::getSaveFileName(
this, tr("Export %1").arg(m_instance->name()), 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()) if (output.isNull())
{ {
return false; return false;
@ -452,7 +451,7 @@ void ExportInstanceDialog::rowsInserted(QModelIndex parent, int top, int bottom)
QString ExportInstanceDialog::ignoreFileName() QString ExportInstanceDialog::ignoreFileName()
{ {
return PathCombine(m_instance->instanceRoot(), ".packignore"); return FS::PathCombine(m_instance->instanceRoot(), ".packignore");
} }
void ExportInstanceDialog::loadPackIgnore() void ExportInstanceDialog::loadPackIgnore()

View File

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

View File

@ -10,7 +10,7 @@
#include "MultiMC.h" #include "MultiMC.h"
#include <java/JavaVersionList.h> #include <java/JavaVersionList.h>
#include <pathutils.h> #include <FileSystem.h>
InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent) InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
: QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst) : QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)
@ -186,7 +186,7 @@ void InstanceSettingsPage::on_javaDetectBtn_clicked()
void InstanceSettingsPage::on_javaBrowseBtn_clicked() void InstanceSettingsPage::on_javaBrowseBtn_clicked()
{ {
QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable")); 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 // do not allow current dir - it's dirty. Do not allow dirs that don't exist
if(cooked_path.isEmpty()) if(cooked_path.isEmpty())

View File

@ -19,14 +19,13 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QKeyEvent> #include <QKeyEvent>
#include <pathutils.h>
#include "dialogs/VersionSelectDialog.h" #include "dialogs/VersionSelectDialog.h"
#include "dialogs/ProgressDialog.h" #include "dialogs/ProgressDialog.h"
#include "dialogs/ModEditDialogCommon.h" #include "dialogs/ModEditDialogCommon.h"
#include "minecraft/ModList.h" #include "minecraft/ModList.h"
#include "minecraft/LegacyInstance.h" #include "minecraft/LegacyInstance.h"
#include "Env.h" #include "Env.h"
#include <FileSystem.h>
#include "MultiMC.h" #include "MultiMC.h"
#include <GuiUtil.h> #include <GuiUtil.h>
@ -147,7 +146,7 @@ void LegacyJarModPage::on_rmJarBtn_clicked()
void LegacyJarModPage::on_viewJarBtn_clicked() void LegacyJarModPage::on_viewJarBtn_clicked()
{ {
openDirInDefaultProgram(m_inst->jarModsDir(), true); FS::openDirInDefaultProgram(m_inst->jarModsDir(), true);
} }
void LegacyJarModPage::jarCurrent(QModelIndex current, QModelIndex previous) void LegacyJarModPage::jarCurrent(QModelIndex current, QModelIndex previous)

View File

@ -22,8 +22,6 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <pathutils.h>
#include "MultiMC.h" #include "MultiMC.h"
#include "dialogs/CustomMessageBox.h" #include "dialogs/CustomMessageBox.h"
#include "dialogs/ModEditDialogCommon.h" #include "dialogs/ModEditDialogCommon.h"
@ -31,6 +29,7 @@
#include "minecraft/ModList.h" #include "minecraft/ModList.h"
#include "minecraft/Mod.h" #include "minecraft/Mod.h"
#include "minecraft/VersionFilterData.h" #include "minecraft/VersionFilterData.h"
#include <FileSystem.h>
ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods, QString id, ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods, QString id,
QString iconName, QString displayName, QString helpPage, QString iconName, QString displayName, QString helpPage,
@ -163,7 +162,7 @@ void ModFolderPage::on_rmModBtn_clicked()
void ModFolderPage::on_viewModBtn_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) void ModFolderPage::modCurrent(const QModelIndex &current, const QModelIndex &previous)

View File

@ -21,7 +21,7 @@
#include "GuiUtil.h" #include "GuiUtil.h"
#include "RecursiveFileSystemWatcher.h" #include "RecursiveFileSystemWatcher.h"
#include <GZip.h> #include <GZip.h>
#include <pathutils.h> #include <FileSystem.h>
OtherLogsPage::OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent) OtherLogsPage::OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent)
: QWidget(parent), ui(new Ui::OtherLogsPage), m_path(path), m_fileFilter(fileFilter), : 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); 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(); m_currentFile = QString();
ui->text->clear(); ui->text->clear();
@ -104,7 +104,7 @@ void OtherLogsPage::on_btnReload_clicked()
setControlsEnabled(false); setControlsEnabled(false);
return; return;
} }
QFile file(PathCombine(m_path, m_currentFile)); QFile file(FS::PathCombine(m_path, m_currentFile));
if (!file.open(QFile::ReadOnly)) if (!file.open(QFile::ReadOnly))
{ {
setControlsEnabled(false); setControlsEnabled(false);
@ -174,7 +174,7 @@ void OtherLogsPage::on_btnDelete_clicked()
{ {
return; return;
} }
QFile file(PathCombine(m_path, m_currentFile)); QFile file(FS::PathCombine(m_path, m_currentFile));
if (!file.remove()) if (!file.remove())
{ {
QMessageBox::critical(this, tr("Error"), tr("Unable to delete %1: %2") QMessageBox::critical(this, tr("Error"), tr("Unable to delete %1: %2")
@ -215,7 +215,7 @@ void OtherLogsPage::on_btnClean_clicked()
QStringList failed; QStringList failed;
for(auto item: toDelete) for(auto item: toDelete)
{ {
QFile file(PathCombine(m_path, item)); QFile file(FS::PathCombine(m_path, item));
if (!file.remove()) if (!file.remove())
{ {
failed.push_back(item); failed.push_back(item);

View File

@ -15,7 +15,6 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QKeyEvent> #include <QKeyEvent>
#include <pathutils.h>
#include <MultiMC.h> #include <MultiMC.h>
#include "dialogs/ProgressDialog.h" #include "dialogs/ProgressDialog.h"
@ -26,6 +25,7 @@
#include "tasks/SequentialTask.h" #include "tasks/SequentialTask.h"
#include "RWStorage.h" #include "RWStorage.h"
#include <FileSystem.h>
typedef RWStorage<QString, QIcon> SharedIconCache; typedef RWStorage<QString, QIcon> SharedIconCache;
typedef std::shared_ptr<SharedIconCache> SharedIconCachePtr; typedef std::shared_ptr<SharedIconCache> SharedIconCachePtr;
@ -219,7 +219,7 @@ ScreenshotsPage::ScreenshotsPage(QString path, QWidget *parent)
m_model->setNameFilters({"*.png"}); m_model->setNameFilters({"*.png"});
m_model->setNameFilterDisables(false); m_model->setNameFilterDisables(false);
m_folder = path; m_folder = path;
m_valid = ensureFolderPathExists(m_folder); m_valid = FS::ensureFolderPathExists(m_folder);
ui->setupUi(this); ui->setupUi(this);
ui->tabWidget->tabBar()->hide(); ui->tabWidget->tabBar()->hide();
@ -271,12 +271,12 @@ void ScreenshotsPage::onItemActivated(QModelIndex index)
return; return;
auto info = m_model->fileInfo(index); auto info = m_model->fileInfo(index);
QString fileName = info.absoluteFilePath(); QString fileName = info.absoluteFilePath();
openFileInDefaultProgram(info.absoluteFilePath()); FS::openFileInDefaultProgram(info.absoluteFilePath());
} }
void ScreenshotsPage::on_viewFolderBtn_clicked() void ScreenshotsPage::on_viewFolderBtn_clicked()
{ {
openDirInDefaultProgram(m_folder, true); FS::openDirInDefaultProgram(m_folder, true);
} }
void ScreenshotsPage::on_uploadBtn_clicked() void ScreenshotsPage::on_uploadBtn_clicked()

View File

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

View File

@ -16,6 +16,7 @@
#include "WorldListPage.h" #include "WorldListPage.h"
#include "ui_WorldListPage.h" #include "ui_WorldListPage.h"
#include "minecraft/WorldList.h" #include "minecraft/WorldList.h"
#include <FileSystem.h>
#include "dialogs/ModEditDialogCommon.h" #include "dialogs/ModEditDialogCommon.h"
#include <QEvent> #include <QEvent>
#include <QKeyEvent> #include <QKeyEvent>
@ -122,7 +123,7 @@ void WorldListPage::on_rmWorldBtn_clicked()
void WorldListPage::on_viewFolderBtn_clicked() void WorldListPage::on_viewFolderBtn_clicked()
{ {
openDirInDefaultProgram(m_worlds->dir().absolutePath(), true); FS::openDirInDefaultProgram(m_worlds->dir().absolutePath(), true);
} }
QModelIndex WorldListPage::getSelectedWorld() QModelIndex WorldListPage::getSelectedWorld()

View File

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

View File

@ -20,10 +20,9 @@
#include <QFileDialog> #include <QFileDialog>
#include <QStandardPaths> #include <QStandardPaths>
#include <pathutils.h>
#include "settings/SettingsObject.h" #include "settings/SettingsObject.h"
#include "tools/BaseProfiler.h" #include "tools/BaseProfiler.h"
#include <FileSystem.h>
#include "MultiMC.h" #include "MultiMC.h"
ExternalToolsPage::ExternalToolsPage(QWidget *parent) : ExternalToolsPage::ExternalToolsPage(QWidget *parent) :
@ -91,7 +90,7 @@ void ExternalToolsPage::on_jprofilerPathBtn_clicked()
{ {
break; break;
} }
QString cooked_dir = NormalizePath(raw_dir); QString cooked_dir = FS::NormalizePath(raw_dir);
if (!MMC->profilers()["jprofiler"]->check(cooked_dir, &error)) if (!MMC->profilers()["jprofiler"]->check(cooked_dir, &error))
{ {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"),
@ -130,7 +129,7 @@ void ExternalToolsPage::on_jvisualvmPathBtn_clicked()
{ {
break; break;
} }
QString cooked_dir = NormalizePath(raw_dir); QString cooked_dir = FS::NormalizePath(raw_dir);
if (!MMC->profilers()["jvisualvm"]->check(cooked_dir, &error)) if (!MMC->profilers()["jvisualvm"]->check(cooked_dir, &error))
{ {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"),
@ -174,7 +173,7 @@ void ExternalToolsPage::on_mceditPathBtn_clicked()
{ {
break; break;
} }
QString cooked_dir = NormalizePath(raw_dir); QString cooked_dir = FS::NormalizePath(raw_dir);
if (!MMC->tools()["mcedit"]->check(cooked_dir, &error)) if (!MMC->tools()["mcedit"]->check(cooked_dir, &error))
{ {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"),
@ -213,7 +212,7 @@ void ExternalToolsPage::on_jsonEditorBrowseBtn_clicked()
? QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).first() ? QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).first()
#endif #endif
: ui->jsonEditorTextBox->text()); : ui->jsonEditorTextBox->text());
QString cooked_file = NormalizePath(raw_file); QString cooked_file = FS::NormalizePath(raw_file);
if (cooked_file.isEmpty()) if (cooked_file.isEmpty())
{ {

View File

@ -21,8 +21,6 @@
#include <QMessageBox> #include <QMessageBox>
#include <QDir> #include <QDir>
#include <pathutils.h>
#include "dialogs/VersionSelectDialog.h" #include "dialogs/VersionSelectDialog.h"
#include <ColumnResizer.h> #include <ColumnResizer.h>
@ -30,6 +28,7 @@
#include "java/JavaVersionList.h" #include "java/JavaVersionList.h"
#include "settings/SettingsObject.h" #include "settings/SettingsObject.h"
#include <FileSystem.h>
#include "MultiMC.h" #include "MultiMC.h"
JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage) JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage)
@ -109,7 +108,7 @@ void JavaPage::on_javaDetectBtn_clicked()
void JavaPage::on_javaBrowseBtn_clicked() void JavaPage::on_javaBrowseBtn_clicked()
{ {
QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable")); 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 // do not allow current dir - it's dirty. Do not allow dirs that don't exist
if(cooked_path.isEmpty()) if(cooked_path.isEmpty())

View File

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

View File

@ -21,11 +21,11 @@
#include <QDir> #include <QDir>
#include <QTextCharFormat> #include <QTextCharFormat>
#include <pathutils.h>
#include <ColumnResizer.h> #include <ColumnResizer.h>
#include "updater/UpdateChecker.h" #include "updater/UpdateChecker.h"
#include "settings/SettingsObject.h" #include "settings/SettingsObject.h"
#include <FileSystem.h>
#include "MultiMC.h" #include "MultiMC.h"
// FIXME: possibly move elsewhere // FIXME: possibly move elsewhere
@ -85,7 +85,7 @@ void MultiMCPage::on_ftbLauncherBrowseBtn_clicked()
{ {
QString raw_dir = QFileDialog::getExistingDirectory(this, tr("FTB Launcher Directory"), QString raw_dir = QFileDialog::getExistingDirectory(this, tr("FTB Launcher Directory"),
ui->ftbLauncherBox->text()); 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 // 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 (!cooked_dir.isEmpty() && QDir(cooked_dir).exists())
@ -97,7 +97,7 @@ void MultiMCPage::on_ftbBrowseBtn_clicked()
{ {
QString raw_dir = QString raw_dir =
QFileDialog::getExistingDirectory(this, tr("FTB Directory"), ui->ftbBox->text()); 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 // 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 (!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"), QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Instance Directory"),
ui->instDirTextBox->text()); 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 // 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 (!cooked_dir.isEmpty() && QDir(cooked_dir).exists())
{ {
if (checkProblemticPathJava(QDir(cooked_dir))) if (FS::checkProblemticPathJava(QDir(cooked_dir)))
{ {
QMessageBox warning; QMessageBox warning;
warning.setText(tr("You're trying to specify an instance folder which\'s path " 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"), QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Icons Directory"),
ui->iconsDirTextBox->text()); 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 // 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 (!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"), QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Mods Directory"),
ui->modsDirTextBox->text()); 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 // 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 (!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"), QString raw_dir = QFileDialog::getExistingDirectory(this, tr("LWJGL Directory"),
ui->lwjglDirTextBox->text()); 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 // 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 (!cooked_dir.isEmpty() && QDir(cooked_dir).exists())
@ -308,8 +308,8 @@ void MultiMCPage::applySettings()
// FTB // FTB
s->set("TrackFTBInstances", ui->trackFtbBox->isChecked()); s->set("TrackFTBInstances", ui->trackFtbBox->isChecked());
s->set("FTBLauncherLocal", NormalizePath(ui->ftbLauncherBox->text())); s->set("FTBLauncherLocal", FS::NormalizePath(ui->ftbLauncherBox->text()));
s->set("FTBRoot", NormalizePath(ui->ftbBox->text())); s->set("FTBRoot", FS::NormalizePath(ui->ftbBox->text()));
// Folders // Folders
// TODO: Offer to move instances to new instance folder. // TODO: Offer to move instances to new instance folder.

View File

@ -20,8 +20,6 @@
#include <QFileDialog> #include <QFileDialog>
#include <QStandardPaths> #include <QStandardPaths>
#include <pathutils.h>
#include "settings/SettingsObject.h" #include "settings/SettingsObject.h"
#include "tools/BaseProfiler.h" #include "tools/BaseProfiler.h"
#include "MultiMC.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/Setting.h"
#include "settings/OverrideSetting.h" #include "settings/OverrideSetting.h"
#include "pathutils.h"
#include <cmdutils.h>
#include "minecraft/MinecraftVersionList.h" #include "minecraft/MinecraftVersionList.h"
#include "icons/IconList.h" #include "icons/IconList.h"
#include "FileSystem.h"
#include "Commandline.h"
BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
: QObject() : QObject()
@ -78,7 +78,7 @@ void BaseInstance::iconUpdated(QString key)
void BaseInstance::nuke() void BaseInstance::nuke()
{ {
deletePath(instanceRoot()); FS::deletePath(instanceRoot());
emit nuked(this); emit nuked(this);
} }
@ -268,5 +268,5 @@ QString BaseInstance::windowTitle() const
QStringList BaseInstance::extraArguments() 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.h
GZip.cpp GZip.cpp
# Command line parameter parsing
Commandline.h
Commandline.cpp
# Version number string support
Version.h
Version.cpp
# network stuffs # network stuffs
net/NetAction.h net/NetAction.h
net/MD5EtagDownload.h net/MD5EtagDownload.h
@ -312,7 +320,7 @@ set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISI
generate_export_header(MultiMC_logic) generate_export_header(MultiMC_logic)
# Link # 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) qt5_use_modules(MultiMC_logic Core Xml Widgets Network Concurrent)
add_dependencies(MultiMC_logic QuaZIP) add_dependencies(MultiMC_logic QuaZIP)

View File

@ -15,14 +15,12 @@
* limitations under the License. * limitations under the License.
*/ */
#include "include/cmdutils.h" #include "Commandline.h"
/** /**
* @file libutil/src/cmdutils.cpp * @file libutil/src/cmdutils.cpp
*/ */
namespace Util
{
namespace Commandline namespace Commandline
{ {
@ -483,4 +481,3 @@ ParsingError::ParsingError(const QString &what) : std::runtime_error(what.toStdS
{ {
} }
} }
}

View File

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

View File

@ -5,6 +5,9 @@
#include <QDir> #include <QDir>
#include <QSaveFile> #include <QSaveFile>
#include <QFileInfo> #include <QFileInfo>
#include <QDebug>
#include <QDesktopServices>
#include <QUrl>
void ensureExists(const QDir &dir) void ensureExists(const QDir &dir)
{ {
@ -54,3 +57,372 @@ QByteArray FS::read(const QString &filename)
} }
return data; 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 "Exception.h"
#include "multimc_logic_export.h" #include "multimc_logic_export.h"
#include <QDir>
namespace FS namespace FS
{ {
@ -15,6 +16,83 @@ public:
FileSystemException(const QString &message) : Exception(message) {} 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 <QJsonArray>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QRegularExpression> #include <QRegularExpression>
#include <pathutils.h>
#include <QDebug> #include <QDebug>
#include "InstanceList.h" #include "InstanceList.h"
@ -38,6 +37,7 @@
#include "settings/INISettingsObject.h" #include "settings/INISettingsObject.h"
#include "ftb/FTBPlugin.h" #include "ftb/FTBPlugin.h"
#include "NullInstance.h" #include "NullInstance.h"
#include "FileSystem.h"
const static int GROUP_FILE_FORMAT_VERSION = 1; const static int GROUP_FILE_FORMAT_VERSION = 1;
@ -299,7 +299,7 @@ InstanceList::InstListError InstanceList::loadList()
while (iter.hasNext()) while (iter.hasNext())
{ {
QString subDir = iter.next(); QString subDir = iter.next();
if (!QFileInfo(PathCombine(subDir, "instance.cfg")).exists()) if (!QFileInfo(FS::PathCombine(subDir, "instance.cfg")).exists())
continue; continue;
qDebug() << "Loading MultiMC instance from " << subDir; qDebug() << "Loading MultiMC instance from " << subDir;
InstancePtr instPtr; InstancePtr instPtr;
@ -432,7 +432,7 @@ bool InstanceList::continueProcessInstance(InstancePtr instPtr, const int error,
InstanceList::InstLoadError InstanceList::InstLoadError
InstanceList::loadInstance(InstancePtr &inst, const QString &instDir) 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"); instanceSettings->registerSetting("InstanceType", "Legacy");
@ -473,7 +473,7 @@ InstanceList::createInstance(InstancePtr &inst, BaseVersionPtr version, const QS
return InstanceList::NoSuchVersion; 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"); instanceSettings->registerSetting("InstanceType", "Legacy");
auto minecraftVersion = std::dynamic_pointer_cast<MinecraftVersion>(version); auto minecraftVersion = std::dynamic_pointer_cast<MinecraftVersion>(version);
@ -490,18 +490,18 @@ InstanceList::createInstance(InstancePtr &inst, BaseVersionPtr version, const QS
} }
InstanceList::InstCreateError 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); QDir rootDir(instDir);
qDebug() << instDir.toUtf8(); qDebug() << instDir.toUtf8();
if (!copyPath(oldInstance->instanceRoot(), instDir, false)) if (!FS::copyPath(oldInstance->instanceRoot(), instDir, false))
{ {
deletePath(instDir); FS::deletePath(instDir);
return InstanceList::CantCreateDir; return InstanceList::CantCreateDir;
} }
INISettingsObject settings_obj(PathCombine(instDir, "instance.cfg")); INISettingsObject settings_obj(FS::PathCombine(instDir, "instance.cfg"));
settings_obj.registerSetting("InstanceType", "Legacy"); settings_obj.registerSetting("InstanceType", "Legacy");
QString inst_type = settings_obj.get("InstanceType").toString(); QString inst_type = settings_obj.get("InstanceType").toString();

View File

@ -140,7 +140,7 @@ public:
* - CantCreateDir if the given instance directory cannot be created. * - CantCreateDir if the given instance directory cannot be created.
*/ */
InstCreateError copyInstance(InstancePtr &newInstance, InstancePtr &oldInstance, InstCreateError copyInstance(InstancePtr &newInstance, InstancePtr &oldInstance,
const QString &instDir); const QString &instDir, bool copySaves);
/*! /*!
* \brief Loads an instance from the given directory. * \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. see quazip/(un)MMCZip.h files for details. Basically it's the zlib license.
*/ */
#include <pathutils.h>
#include <quazip.h> #include <quazip.h>
#include <JlCompress.h> #include <JlCompress.h>
#include <quazipdir.h> #include <quazipdir.h>
#include "MMCZip.h" #include "MMCZip.h"
#include "FileSystem.h"
#include <QDebug> #include <QDebug>
@ -111,7 +111,7 @@ bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QStr
if(!blacklist || !blacklist->covers(internalDirName)) if(!blacklist || !blacklist->covers(internalDirName))
{ {
QuaZipFile dirZipFile(zip); 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)) if (!dirZipFile.open(QIODevice::WriteOnly, QuaZipNewInfo(dirPrefix, dir), 0, 0, 0))
{ {
return false; return false;
@ -153,7 +153,7 @@ bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QStr
} }
if(prefix.size()) if(prefix.size())
{ {
filename = PathCombine(prefix, filename); filename = FS::PathCombine(prefix, filename);
} }
added.insert(filename); added.insert(filename);
if (!compressFile(zip,file.absoluteFilePath(),filename)) if (!compressFile(zip,file.absoluteFilePath(),filename))

View File

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

View File

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

View File

@ -27,7 +27,7 @@
#include <QDebug> #include <QDebug>
#include "auth/MojangAccount.h" #include "auth/MojangAccount.h"
#include <pathutils.h> #include <FileSystem.h>
#define ACCOUNT_LIST_FORMAT_VERSION 2 #define ACCOUNT_LIST_FORMAT_VERSION 2
@ -348,7 +348,7 @@ bool MojangAccountList::saveList(const QString &filePath)
} }
// make sure the parent folder exists // make sure the parent folder exists
if(!ensureFilePathExists(path)) if(!FS::ensureFilePathExists(path))
return false; return false;
// make sure the file wasn't overwritten with a folder before (fixes a bug) // 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 "minecraft/VersionFilterData.h"
#include "Env.h" #include "Env.h"
#include "Exception.h" #include "Exception.h"
#include <FileSystem.h>
#include <quazip.h> #include <quazip.h>
#include <quazipfile.h> #include <quazipfile.h>
#include <pathutils.h>
#include <QStringList> #include <QStringList>
#include <QRegularExpression> #include <QRegularExpression>
#include <QRegularExpressionMatch> #include <QRegularExpressionMatch>
@ -90,7 +90,7 @@ void ForgeInstaller::prepare(const QString &filename, const QString &universalUr
auto cacheentry = ENV.metacache()->resolveEntry("libraries", lib.storageSuffix()); auto cacheentry = ENV.metacache()->resolveEntry("libraries", lib.storageSuffix());
finalPath = "libraries/" + lib.storageSuffix(); finalPath = "libraries/" + lib.storageSuffix();
if (!ensureFilePathExists(finalPath)) if (!FS::ensureFilePathExists(finalPath))
return; return;
if (!zip.setCurrentFile(internalPath)) if (!zip.setCurrentFile(internalPath))
@ -278,8 +278,8 @@ bool ForgeInstaller::addLegacy(OneSixInstance *to)
return false; return false;
} }
auto entry = ENV.metacache()->resolveEntry("minecraftforge", m_forge_version->filename()); auto entry = ENV.metacache()->resolveEntry("minecraftforge", m_forge_version->filename());
finalPath = PathCombine(to->jarModsDir(), m_forge_version->filename()); finalPath = FS::PathCombine(to->jarModsDir(), m_forge_version->filename());
if (!ensureFilePathExists(finalPath)) if (!FS::ensureFilePathExists(finalPath))
{ {
return false; return false;
} }

View File

@ -15,7 +15,7 @@
#include "Env.h" #include "Env.h"
#include "ForgeXzDownload.h" #include "ForgeXzDownload.h"
#include <pathutils.h> #include <FileSystem.h>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QFileInfo> #include <QFileInfo>
@ -49,7 +49,7 @@ void ForgeXzDownload::start()
return; return;
} }
// can we actually create the real, final file? // can we actually create the real, final file?
if (!ensureFilePathExists(m_target_path)) if (!FS::ensureFilePathExists(m_target_path))
{ {
m_status = Job_Failed; m_status = Job_Failed;
emit failed(m_index_within_job); emit failed(m_index_within_job);

View File

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

View File

@ -2,8 +2,8 @@
#include "minecraft/VersionBuildError.h" #include "minecraft/VersionBuildError.h"
#include "ftb/OneSixFTBInstance.h" #include "ftb/OneSixFTBInstance.h"
#include "minecraft/MinecraftVersionList.h" #include "minecraft/MinecraftVersionList.h"
#include <FileSystem.h>
#include <pathutils.h>
#include <QDir> #include <QDir>
#include <QUuid> #include <QUuid>
#include <QJsonDocument> #include <QJsonDocument>
@ -67,7 +67,7 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches()
if(file->version.isEmpty()) if(file->version.isEmpty())
{ {
file->version = QObject::tr("Unknown"); 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.exists())
{ {
if(versionFile.open(QIODevice::ReadOnly)) 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 // load all patches, put into map for ordering, apply in the right order
ProfileUtils::PatchOrder userOrder; ProfileUtils::PatchOrder userOrder;
ProfileUtils::readOverrideOrders(PathCombine(m_instance->instanceRoot(), "order.json"), userOrder); ProfileUtils::readOverrideOrders(FS::PathCombine(m_instance->instanceRoot(), "order.json"), userOrder);
QDir patches(PathCombine(m_instance->instanceRoot(),"patches")); QDir patches(FS::PathCombine(m_instance->instanceRoot(),"patches"));
// first, load things by sort order. // first, load things by sort order.
for (auto id : userOrder) for (auto id : userOrder)

View File

@ -7,7 +7,7 @@
#include "forge/ForgeInstaller.h" #include "forge/ForgeInstaller.h"
#include "forge/ForgeVersionList.h" #include "forge/ForgeVersionList.h"
#include <settings/INISettingsObject.h> #include <settings/INISettingsObject.h>
#include "pathutils.h" #include <FileSystem.h>
OneSixFTBInstance::OneSixFTBInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) : OneSixFTBInstance::OneSixFTBInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) :
OneSixInstance(globalSettings, settings, rootDir) OneSixInstance(globalSettings, settings, rootDir)
@ -63,7 +63,7 @@ void OneSixFTBInstance::copy(const QDir &newDir)
root.insert("name", name()); root.insert("name", name());
root.insert("mcVersion", intendedVersionId()); root.insert("mcVersion", intendedVersionId());
root.insert("version", 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")); QFile out(newDir.absoluteFilePath("patches/ftb.json"));
if (!out.open(QFile::WriteOnly | QFile::Truncate)) if (!out.open(QFile::WriteOnly | QFile::Truncate))
{ {
@ -83,7 +83,7 @@ void OneSixFTBInstance::copy(const QDir &newDir)
{ {
continue; continue;
} }
if (!ensureFilePathExists(out)) if (!FS::ensureFilePathExists(out))
{ {
qCritical() << "Couldn't create folder structure for" << out; qCritical() << "Couldn't create folder structure for" << out;
} }

View File

@ -14,7 +14,7 @@
*/ */
#include "IconList.h" #include "IconList.h"
#include <pathutils.h> #include <FileSystem.h>
#include <QMap> #include <QMap>
#include <QEventLoop> #include <QEventLoop>
#include <QMimeData> #include <QMimeData>
@ -57,7 +57,7 @@ void IconList::directoryChanged(const QString &path)
startWatching(); startWatching();
} }
if(!m_dir.exists()) if(!m_dir.exists())
if(!ensureFolderPathExists(m_dir.absolutePath())) if(!FS::ensureFolderPathExists(m_dir.absolutePath()))
return; return;
m_dir.refresh(); m_dir.refresh();
auto new_list = m_dir.entryList(QDir::Files, QDir::Name); 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() void IconList::startWatching()
{ {
auto abs_path = m_dir.absolutePath(); auto abs_path = m_dir.absolutePath();
ensureFolderPathExists(abs_path); FS::ensureFolderPathExists(abs_path);
is_watching = m_watcher->addPath(abs_path); is_watching = m_watcher->addPath(abs_path);
if (is_watching) if (is_watching)
{ {
@ -250,7 +250,7 @@ void IconList::installIcons(QStringList iconFiles)
QFileInfo fileinfo(file); QFileInfo fileinfo(file);
if (!fileinfo.isReadable() || !fileinfo.isFile()) if (!fileinfo.isReadable() || !fileinfo.isFile())
continue; continue;
QString target = PathCombine(m_dir.dirName(), fileinfo.fileName()); QString target = FS::PathCombine(m_dir.dirName(), fileinfo.fileName());
QString suffix = fileinfo.suffix(); QString suffix = fileinfo.suffix();
if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico") if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico")

View File

@ -1,6 +1,6 @@
#include "JavaChecker.h" #include "JavaChecker.h"
#include <pathutils.h> #include <FileSystem.h>
#include <cmdutils.h> #include <Commandline.h>
#include <QFile> #include <QFile>
#include <QProcess> #include <QProcess>
#include <QMap> #include <QMap>
@ -14,14 +14,14 @@ JavaChecker::JavaChecker(QObject *parent) : QObject(parent)
void JavaChecker::performCheck() void JavaChecker::performCheck()
{ {
QString checkerJar = PathCombine(QCoreApplication::applicationDirPath(), "jars", "JavaCheck.jar"); QString checkerJar = FS::PathCombine(QCoreApplication::applicationDirPath(), "jars", "JavaCheck.jar");
QStringList args; QStringList args;
process.reset(new QProcess()); process.reset(new QProcess());
if(m_args.size()) if(m_args.size())
{ {
auto extraArgs = Util::Commandline::splitArgs(m_args); auto extraArgs = Commandline::splitArgs(m_args);
args.append(extraArgs); args.append(extraArgs);
} }
if(m_minMem != 0) if(m_minMem != 0)

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,7 @@
#include "CheckJava.h" #include "CheckJava.h"
#include <launch/LaunchTask.h> #include <launch/LaunchTask.h>
#include <pathutils.h> #include <FileSystem.h>
#include <QStandardPaths> #include <QStandardPaths>
#include <QFileInfo> #include <QFileInfo>
@ -23,7 +23,7 @@ void CheckJava::executeTask()
{ {
auto instance = m_parent->instance(); auto instance = m_parent->instance();
auto settings = instance->settings(); 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(); bool perInstance = settings->get("OverrideJava").toBool() || settings->get("OverrideJavaLocation").toBool();
auto realJavaPath = QStandardPaths::findExecutable(m_javaPath); auto realJavaPath = QStandardPaths::findExecutable(m_javaPath);

View File

@ -16,7 +16,7 @@
#include "LaunchMinecraft.h" #include "LaunchMinecraft.h"
#include <launch/LaunchTask.h> #include <launch/LaunchTask.h>
#include <minecraft/OneSixInstance.h> #include <minecraft/OneSixInstance.h>
#include <pathutils.h> #include <FileSystem.h>
#include <QStandardPaths> #include <QStandardPaths>
LaunchMinecraft::LaunchMinecraft(LaunchTask *parent) : LaunchStep(parent) LaunchMinecraft::LaunchMinecraft(LaunchTask *parent) : LaunchStep(parent)
@ -34,7 +34,7 @@ void LaunchMinecraft::executeTask()
QString allArgs = args.join(", "); QString allArgs = args.join(", ");
emit logLine("Java Arguments:\n[" + m_parent->censorPrivateInfo(allArgs) + "]\n\n", MessageLevel::MultiMC); 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()); m_process.setProcessEnvironment(instance->createEnvironment());

View File

@ -23,7 +23,7 @@
#include <QDebug> #include <QDebug>
#include "AssetsUtils.h" #include "AssetsUtils.h"
#include <pathutils.h> #include <FileSystem.h>
namespace AssetsUtils namespace AssetsUtils
{ {
@ -125,13 +125,13 @@ bool loadAssetsIndexJson(QString path, AssetsIndex *index)
QDir reconstructAssets(QString assetsId) QDir reconstructAssets(QString assetsId)
{ {
QDir assetsDir = QDir("assets/"); QDir assetsDir = QDir("assets/");
QDir indexDir = QDir(PathCombine(assetsDir.path(), "indexes")); QDir indexDir = QDir(FS::PathCombine(assetsDir.path(), "indexes"));
QDir objectDir = QDir(PathCombine(assetsDir.path(), "objects")); QDir objectDir = QDir(FS::PathCombine(assetsDir.path(), "objects"));
QDir virtualDir = QDir(PathCombine(assetsDir.path(), "virtual")); 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); QFile indexFile(indexPath);
QDir virtualRoot(PathCombine(virtualDir.path(), assetsId)); QDir virtualRoot(FS::PathCombine(virtualDir.path(), assetsId));
if (!indexFile.exists()) if (!indexFile.exists())
{ {
@ -152,13 +152,12 @@ QDir reconstructAssets(QString assetsId)
for (QString map : index.objects.keys()) for (QString map : index.objects.keys())
{ {
AssetObject asset_object = index.objects.value(map); 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); QFile target(target_path);
QString tlk = asset_object.hash.left(2); QString tlk = asset_object.hash.left(2);
QString original_path = QString original_path = FS::PathCombine(objectDir.path(), tlk, asset_object.hash);
PathCombine(PathCombine(objectDir.path(), tlk), asset_object.hash);
QFile original(original_path); QFile original(original_path);
if (!original.exists()) if (!original.exists())
continue; continue;

View File

@ -17,8 +17,6 @@
#include <QDir> #include <QDir>
#include <QImage> #include <QImage>
#include <settings/Setting.h> #include <settings/Setting.h>
#include <pathutils.h>
#include <cmdutils.h>
#include "LegacyInstance.h" #include "LegacyInstance.h"
@ -35,6 +33,7 @@
#include "minecraft/ModList.h" #include "minecraft/ModList.h"
#include "minecraft/WorldList.h" #include "minecraft/WorldList.h"
#include <MMCZip.h> #include <MMCZip.h>
#include <FileSystem.h>
LegacyInstance::LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) LegacyInstance::LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
: MinecraftInstance(globalSettings, settings, rootDir) : MinecraftInstance(globalSettings, settings, rootDir)
@ -109,7 +108,7 @@ std::shared_ptr<LaunchTask> LegacyInstance::createLaunchTask(AuthSessionPtr sess
QString launchScript; QString launchScript;
QIcon icon = ENV.icons()->getIcon(iconKey()); QIcon icon = ENV.icons()->getIcon(iconKey());
auto pixmap = icon.pixmap(128, 128); 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 // create the launch script
{ {
@ -331,56 +330,56 @@ std::shared_ptr<WorldList> LegacyInstance::worldList() const
QString LegacyInstance::jarModsDir() const QString LegacyInstance::jarModsDir() const
{ {
return PathCombine(instanceRoot(), "instMods"); return FS::PathCombine(instanceRoot(), "instMods");
} }
QString LegacyInstance::binDir() const QString LegacyInstance::binDir() const
{ {
return PathCombine(minecraftRoot(), "bin"); return FS::PathCombine(minecraftRoot(), "bin");
} }
QString LegacyInstance::libDir() const QString LegacyInstance::libDir() const
{ {
return PathCombine(minecraftRoot(), "lib"); return FS::PathCombine(minecraftRoot(), "lib");
} }
QString LegacyInstance::savesDir() const QString LegacyInstance::savesDir() const
{ {
return PathCombine(minecraftRoot(), "saves"); return FS::PathCombine(minecraftRoot(), "saves");
} }
QString LegacyInstance::loaderModsDir() const QString LegacyInstance::loaderModsDir() const
{ {
return PathCombine(minecraftRoot(), "mods"); return FS::PathCombine(minecraftRoot(), "mods");
} }
QString LegacyInstance::coreModsDir() const QString LegacyInstance::coreModsDir() const
{ {
return PathCombine(minecraftRoot(), "coremods"); return FS::PathCombine(minecraftRoot(), "coremods");
} }
QString LegacyInstance::resourceDir() const QString LegacyInstance::resourceDir() const
{ {
return PathCombine(minecraftRoot(), "resources"); return FS::PathCombine(minecraftRoot(), "resources");
} }
QString LegacyInstance::texturePacksDir() const QString LegacyInstance::texturePacksDir() const
{ {
return PathCombine(minecraftRoot(), "texturepacks"); return FS::PathCombine(minecraftRoot(), "texturepacks");
} }
QString LegacyInstance::runnableJar() const QString LegacyInstance::runnableJar() const
{ {
return PathCombine(binDir(), "minecraft.jar"); return FS::PathCombine(binDir(), "minecraft.jar");
} }
QString LegacyInstance::modListFile() const QString LegacyInstance::modListFile() const
{ {
return PathCombine(instanceRoot(), "modlist"); return FS::PathCombine(instanceRoot(), "modlist");
} }
QString LegacyInstance::instanceConfigFolder() const QString LegacyInstance::instanceConfigFolder() const
{ {
return PathCombine(minecraftRoot(), "config"); return FS::PathCombine(minecraftRoot(), "config");
} }
bool LegacyInstance::shouldRebuild() const bool LegacyInstance::shouldRebuild() const
@ -442,7 +441,7 @@ QString LegacyInstance::defaultBaseJar() const
QString LegacyInstance::defaultCustomBaseJar() const QString LegacyInstance::defaultCustomBaseJar() const
{ {
return PathCombine(binDir(), "mcbackup.jar"); return FS::PathCombine(binDir(), "mcbackup.jar");
} }
QString LegacyInstance::lwjglFolder() const QString LegacyInstance::lwjglFolder() const

View File

@ -14,7 +14,6 @@
*/ */
#include <QStringList> #include <QStringList>
#include <pathutils.h>
#include <quazip.h> #include <quazip.h>
#include <quazipfile.h> #include <quazipfile.h>
#include <QDebug> #include <QDebug>
@ -30,6 +29,7 @@
#include "minecraft/MinecraftVersionList.h" #include "minecraft/MinecraftVersionList.h"
#include "minecraft/ModList.h" #include "minecraft/ModList.h"
#include "minecraft/LegacyInstance.h" #include "minecraft/LegacyInstance.h"
#include <FileSystem.h>
LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : Task(parent), m_inst(inst) 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. // now check the lib folder inside the instance for files.
for (auto &lib : libList) for (auto &lib : libList)
{ {
QFileInfo libInfo(PathCombine(inst->libDir(), lib.filename)); QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename));
if (libInfo.exists()) if (libInfo.exists())
continue; continue;
fmlLibsToProcess.append(lib); fmlLibsToProcess.append(lib);
@ -137,13 +137,13 @@ void LegacyUpdate::fmllibsFinished()
{ {
progress(index, fmlLibsToProcess.size()); progress(index, fmlLibsToProcess.size());
auto entry = metacache->resolveEntry("fmllibs", lib.filename); auto entry = metacache->resolveEntry("fmllibs", lib.filename);
auto path = PathCombine(inst->libDir(), lib.filename); auto path = FS::PathCombine(inst->libDir(), lib.filename);
if(!ensureFilePathExists(path)) if(!FS::ensureFilePathExists(path))
{ {
emitFailed(tr("Failed creating FML library folder inside the instance.")); emitFailed(tr("Failed creating FML library folder inside the instance."));
return; 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)); emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename));
return; return;
@ -166,11 +166,11 @@ void LegacyUpdate::lwjglStart()
LegacyInstance *inst = (LegacyInstance *)m_inst; LegacyInstance *inst = (LegacyInstance *)m_inst;
lwjglVersion = inst->lwjglVersion(); lwjglVersion = inst->lwjglVersion();
lwjglTargetPath = PathCombine(inst->lwjglFolder(), lwjglVersion); lwjglTargetPath = FS::PathCombine(inst->lwjglFolder(), lwjglVersion);
lwjglNativesPath = PathCombine(lwjglTargetPath, "natives"); lwjglNativesPath = FS::PathCombine(lwjglTargetPath, "natives");
// if the 'done' file exists, we don't have to download this again // 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()) if (doneFile.exists())
{ {
jarStart(); jarStart();
@ -256,7 +256,7 @@ void LegacyUpdate::extractLwjgl()
{ {
// make sure the directories are there // make sure the directories are there
bool success = ensureFolderPathExists(lwjglNativesPath); bool success = FS::ensureFolderPathExists(lwjglNativesPath);
if (!success) if (!success)
{ {
@ -295,7 +295,7 @@ void LegacyUpdate::extractLwjgl()
{ {
if (name.endsWith(jarNames[i])) if (name.endsWith(jarNames[i]))
{ {
destFileName = PathCombine(lwjglTargetPath, jarNames[i]); destFileName = FS::PathCombine(lwjglTargetPath, jarNames[i]);
} }
} }
// Not found? look for the natives // Not found? look for the natives
@ -318,7 +318,7 @@ void LegacyUpdate::extractLwjgl()
name = name.mid(lastSlash + 1); name = name.mid(lastSlash + 1);
else if (lastBackSlash != -1) else if (lastBackSlash != -1)
name = name.mid(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. // Now if destFileName is still empty, go to the next file.
@ -334,7 +334,7 @@ void LegacyUpdate::extractLwjgl()
} }
zip.close(); zip.close();
m_reply.reset(); m_reply.reset();
QFile doneFile(PathCombine(lwjglTargetPath, "done")); QFile doneFile(FS::PathCombine(lwjglTargetPath, "done"));
doneFile.open(QIODevice::WriteOnly); doneFile.open(QIODevice::WriteOnly);
doneFile.write("done."); doneFile.write("done.");
doneFile.close(); doneFile.close();

View File

@ -1,12 +1,12 @@
#include "MinecraftInstance.h" #include "MinecraftInstance.h"
#include <settings/Setting.h> #include <settings/Setting.h>
#include "settings/SettingsObject.h" #include "settings/SettingsObject.h"
#include <pathutils.h>
#include "Env.h" #include "Env.h"
#include "minecraft/MinecraftVersionList.h" #include "minecraft/MinecraftVersionList.h"
#include <MMCStrings.h> #include <MMCStrings.h>
#include <pathmatcher/RegexpMatcher.h> #include <pathmatcher/RegexpMatcher.h>
#include <pathmatcher/MultiMatcher.h> #include <pathmatcher/MultiMatcher.h>
#include <FileSystem.h>
#define IBUS "@im=ibus" #define IBUS "@im=ibus"
@ -67,8 +67,8 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO
QString MinecraftInstance::minecraftRoot() const QString MinecraftInstance::minecraftRoot() const
{ {
QFileInfo mcDir(PathCombine(instanceRoot(), "minecraft")); QFileInfo mcDir(FS::PathCombine(instanceRoot(), "minecraft"));
QFileInfo dotMCDir(PathCombine(instanceRoot(), ".minecraft")); QFileInfo dotMCDir(FS::PathCombine(instanceRoot(), ".minecraft"));
if (dotMCDir.exists() && !mcDir.exists()) if (dotMCDir.exists() && !mcDir.exists())
return dotMCDir.filePath(); return dotMCDir.filePath();
@ -115,7 +115,7 @@ QStringList MinecraftInstance::javaArguments() const
} }
args << "-Duser.language=en"; args << "-Duser.language=en";
args << "-jar" << PathCombine(QCoreApplication::applicationDirPath(), "jars", "NewLaunch.jar"); args << "-jar" << FS::PathCombine(QCoreApplication::applicationDirPath(), "jars", "NewLaunch.jar");
return args; return args;
} }

View File

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

View File

@ -27,8 +27,7 @@
#include "ParseUtils.h" #include "ParseUtils.h"
#include "ProfileUtils.h" #include "ProfileUtils.h"
#include "VersionFilterData.h" #include "VersionFilterData.h"
#include <FileSystem.h>
#include <pathutils.h>
static const char * localVersionCache = "versions/versions.dat"; static const char * localVersionCache = "versions/versions.dat";
@ -548,7 +547,7 @@ void MCVListVersionUpdateTask::json_downloaded()
auto doc = file->toJson(false); auto doc = file->toJson(false);
auto newdata = doc.toBinaryData(); auto newdata = doc.toBinaryData();
QString targetPath = "versions/" + versionToUpdate + "/" + versionToUpdate + ".dat"; QString targetPath = "versions/" + versionToUpdate + "/" + versionToUpdate + ".dat";
ensureFilePathExists(targetPath); FS::ensureFilePathExists(targetPath);
QSaveFile vfile1(targetPath); QSaveFile vfile1(targetPath);
if (!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly)) if (!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly))
{ {
@ -582,7 +581,7 @@ std::shared_ptr<Task> MinecraftVersionList::createUpdateTask(QString version)
void MinecraftVersionList::saveCachedList() void MinecraftVersionList::saveCachedList()
{ {
// FIXME: throw. // FIXME: throw.
if (!ensureFilePathExists(localVersionCache)) if (!FS::ensureFilePathExists(localVersionCache))
return; return;
QSaveFile tfile(localVersionCache); QSaveFile tfile(localVersionCache);
if (!tfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) if (!tfile.open(QIODevice::WriteOnly | QIODevice::Truncate))

View File

@ -23,8 +23,8 @@
#include <quazipfile.h> #include <quazipfile.h>
#include "Mod.h" #include "Mod.h"
#include <pathutils.h>
#include "settings/INIFile.h" #include "settings/INIFile.h"
#include <FileSystem.h>
#include <QDebug> #include <QDebug>
Mod::Mod(const QFileInfo &file) Mod::Mod(const QFileInfo &file)
@ -113,7 +113,7 @@ void Mod::repath(const QFileInfo &file)
} }
else if (m_type == MOD_FOLDER) 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()) if (mcmod_info.isFile())
{ {
QFile mcmod(mcmod_info.filePath()); QFile mcmod(mcmod_info.filePath());
@ -278,7 +278,7 @@ bool Mod::replace(Mod &with)
} }
if (t == MOD_FOLDER) 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) if (success)
{ {

View File

@ -14,7 +14,7 @@
*/ */
#include "ModList.h" #include "ModList.h"
#include <pathutils.h> #include <FileSystem.h>
#include <QMimeData> #include <QMimeData>
#include <QUrl> #include <QUrl>
#include <QUuid> #include <QUuid>
@ -25,7 +25,7 @@
ModList::ModList(const QString &dir, const QString &list_file) ModList::ModList(const QString &dir, const QString &list_file)
: QAbstractListModel(), m_dir(dir), m_list_file(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 | m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs |
QDir::NoSymLinks); QDir::NoSymLinks);
m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware);
@ -270,7 +270,7 @@ bool ModList::installMod(const QFileInfo &filename, int index)
return false; return false;
if (type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE || type == Mod::MOD_LITEMOD) 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)) if (!QFile::copy(filename.filePath(), newpath))
return false; return false;
m.repath(newpath); m.repath(newpath);
@ -285,8 +285,8 @@ bool ModList::installMod(const QFileInfo &filename, int index)
{ {
QString from = filename.filePath(); QString from = filename.filePath();
QString to = PathCombine(m_dir.path(), filename.fileName()); QString to = FS::PathCombine(m_dir.path(), filename.fileName());
if (!copyPath(from, to)) if (!FS::copyPath(from, to))
return false; return false;
m.repath(to); m.repath(to);
beginInsertRows(QModelIndex(), index, index); beginInsertRows(QModelIndex(), index, index);

View File

@ -14,7 +14,6 @@
*/ */
#include <QIcon> #include <QIcon>
#include <pathutils.h>
#include <QDebug> #include <QDebug>
#include "minecraft/OneSixInstance.h" #include "minecraft/OneSixInstance.h"
@ -36,6 +35,7 @@
#include "minecraft/AssetsUtils.h" #include "minecraft/AssetsUtils.h"
#include "icons/IconList.h" #include "icons/IconList.h"
#include "minecraft/WorldList.h" #include "minecraft/WorldList.h"
#include <FileSystem.h>
OneSixInstance::OneSixInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) OneSixInstance::OneSixInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
: MinecraftInstance(globalSettings, settings, rootDir) : MinecraftInstance(globalSettings, settings, rootDir)
@ -136,7 +136,7 @@ std::shared_ptr<LaunchTask> OneSixInstance::createLaunchTask(AuthSessionPtr sess
QString launchScript; QString launchScript;
QIcon icon = ENV.icons()->getIcon(iconKey()); QIcon icon = ENV.icons()->getIcon(iconKey());
auto pixmap = icon.pixmap(128, 128); auto pixmap = icon.pixmap(128, 128);
pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG"); pixmap.save(FS::PathCombine(minecraftRoot(), "icon.png"), "PNG");
if (!m_version) if (!m_version)
return nullptr; return nullptr;
@ -222,7 +222,7 @@ std::shared_ptr<LaunchTask> OneSixInstance::createLaunchTask(AuthSessionPtr sess
// native libraries (mostly LWJGL) // native libraries (mostly LWJGL)
{ {
QDir natives_dir(PathCombine(instanceRoot(), "natives/")); QDir natives_dir(FS::PathCombine(instanceRoot(), "natives/"));
for (auto native : m_version->getActiveNativeLibs()) for (auto native : m_version->getActiveNativeLibs())
{ {
QFileInfo finfo(native->storagePath()); QFileInfo finfo(native->storagePath());
@ -348,7 +348,7 @@ std::shared_ptr<Task> OneSixInstance::createJarModdingTask()
void OneSixInstance::cleanupAfterRun() void OneSixInstance::cleanupAfterRun()
{ {
QString target_dir = PathCombine(instanceRoot(), "natives/"); QString target_dir = FS::PathCombine(instanceRoot(), "natives/");
QDir dir(target_dir); QDir dir(target_dir);
dir.removeRecursively(); dir.removeRecursively();
} }
@ -515,42 +515,42 @@ bool OneSixInstance::reload()
QString OneSixInstance::loaderModsDir() const QString OneSixInstance::loaderModsDir() const
{ {
return PathCombine(minecraftRoot(), "mods"); return FS::PathCombine(minecraftRoot(), "mods");
} }
QString OneSixInstance::coreModsDir() const QString OneSixInstance::coreModsDir() const
{ {
return PathCombine(minecraftRoot(), "coremods"); return FS::PathCombine(minecraftRoot(), "coremods");
} }
QString OneSixInstance::resourcePacksDir() const QString OneSixInstance::resourcePacksDir() const
{ {
return PathCombine(minecraftRoot(), "resourcepacks"); return FS::PathCombine(minecraftRoot(), "resourcepacks");
} }
QString OneSixInstance::texturePacksDir() const QString OneSixInstance::texturePacksDir() const
{ {
return PathCombine(minecraftRoot(), "texturepacks"); return FS::PathCombine(minecraftRoot(), "texturepacks");
} }
QString OneSixInstance::instanceConfigFolder() const QString OneSixInstance::instanceConfigFolder() const
{ {
return PathCombine(minecraftRoot(), "config"); return FS::PathCombine(minecraftRoot(), "config");
} }
QString OneSixInstance::jarModsDir() const QString OneSixInstance::jarModsDir() const
{ {
return PathCombine(instanceRoot(), "jarmods"); return FS::PathCombine(instanceRoot(), "jarmods");
} }
QString OneSixInstance::libDir() const QString OneSixInstance::libDir() const
{ {
return PathCombine(minecraftRoot(), "lib"); return FS::PathCombine(minecraftRoot(), "lib");
} }
QString OneSixInstance::worldDir() const QString OneSixInstance::worldDir() const
{ {
return PathCombine(minecraftRoot(), "saves"); return FS::PathCombine(minecraftRoot(), "saves");
} }
QStringList OneSixInstance::extraArguments() const QStringList OneSixInstance::extraArguments() const

View File

@ -3,8 +3,8 @@
#include "minecraft/OneSixInstance.h" #include "minecraft/OneSixInstance.h"
#include "minecraft/MinecraftVersionList.h" #include "minecraft/MinecraftVersionList.h"
#include "Env.h" #include "Env.h"
#include <FileSystem.h>
#include <pathutils.h>
#include <QDir> #include <QDir>
#include <QUuid> #include <QUuid>
#include <QJsonDocument> #include <QJsonDocument>
@ -17,9 +17,9 @@ OneSixProfileStrategy::OneSixProfileStrategy(OneSixInstance* instance)
void OneSixProfileStrategy::upgradeDeprecatedFiles() void OneSixProfileStrategy::upgradeDeprecatedFiles()
{ {
auto versionJsonPath = PathCombine(m_instance->instanceRoot(), "version.json"); auto versionJsonPath = FS::PathCombine(m_instance->instanceRoot(), "version.json");
auto customJsonPath = PathCombine(m_instance->instanceRoot(), "custom.json"); auto customJsonPath = FS::PathCombine(m_instance->instanceRoot(), "custom.json");
auto mcJson = PathCombine(m_instance->instanceRoot(), "patches" , "net.minecraft.json"); auto mcJson = FS::PathCombine(m_instance->instanceRoot(), "patches" , "net.minecraft.json");
QString sourceFile; QString sourceFile;
QString renameFile; QString renameFile;
@ -36,7 +36,7 @@ void OneSixProfileStrategy::upgradeDeprecatedFiles()
} }
if(!sourceFile.isEmpty() && !QFile::exists(mcJson)) if(!sourceFile.isEmpty() && !QFile::exists(mcJson))
{ {
if(!ensureFilePathExists(mcJson)) if(!FS::ensureFilePathExists(mcJson))
{ {
qWarning() << "Couldn't create patches folder for" << m_instance->name(); qWarning() << "Couldn't create patches folder for" << m_instance->name();
return; return;
@ -79,7 +79,7 @@ void OneSixProfileStrategy::upgradeDeprecatedFiles()
void OneSixProfileStrategy::loadDefaultBuiltinPatches() 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 // load up the base minecraft patch
ProfilePatchPtr minecraftPatch; ProfilePatchPtr minecraftPatch;
if(QFile::exists(mcJson)) 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; ProfilePatchPtr lwjglPatch;
if(QFile::exists(lwjglJson)) if(QFile::exists(lwjglJson))
{ {
@ -138,8 +138,8 @@ void OneSixProfileStrategy::loadUserPatches()
{ {
// load all patches, put into map for ordering, apply in the right order // load all patches, put into map for ordering, apply in the right order
ProfileUtils::PatchOrder userOrder; ProfileUtils::PatchOrder userOrder;
ProfileUtils::readOverrideOrders(PathCombine(m_instance->instanceRoot(), "order.json"), userOrder); ProfileUtils::readOverrideOrders(FS::PathCombine(m_instance->instanceRoot(), "order.json"), userOrder);
QDir patches(PathCombine(m_instance->instanceRoot(),"patches")); QDir patches(FS::PathCombine(m_instance->instanceRoot(),"patches"));
// first, load things by sort order. // first, load things by sort order.
for (auto id : userOrder) for (auto id : userOrder)
@ -215,7 +215,7 @@ void OneSixProfileStrategy::load()
bool OneSixProfileStrategy::saveOrder(ProfileUtils::PatchOrder order) 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() bool OneSixProfileStrategy::resetOrder()
@ -241,7 +241,7 @@ bool OneSixProfileStrategy::removePatch(ProfilePatchPtr patch)
auto preRemoveJarMod = [&](JarmodPtr jarMod) -> bool 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); QFileInfo finfo (fullpath);
if(finfo.exists()) if(finfo.exists())
{ {
@ -270,8 +270,8 @@ bool OneSixProfileStrategy::customizePatch(ProfilePatchPtr patch)
return false; return false;
} }
auto filename = PathCombine(m_instance->instanceRoot(), "patches" , patch->getPatchID() + ".json"); auto filename = FS::PathCombine(m_instance->instanceRoot(), "patches" , patch->getPatchID() + ".json");
if(!ensureFilePathExists(filename)) if(!FS::ensureFilePathExists(filename))
{ {
return false; return false;
} }
@ -333,13 +333,13 @@ bool OneSixProfileStrategy::revertPatch(ProfilePatchPtr patch)
bool OneSixProfileStrategy::installJarMods(QStringList filepaths) bool OneSixProfileStrategy::installJarMods(QStringList filepaths)
{ {
QString patchDir = PathCombine(m_instance->instanceRoot(), "patches"); QString patchDir = FS::PathCombine(m_instance->instanceRoot(), "patches");
if(!ensureFolderPathExists(patchDir)) if(!FS::ensureFolderPathExists(patchDir))
{ {
return false; return false;
} }
if (!ensureFolderPathExists(m_instance->jarModsDir())) if (!FS::ensureFolderPathExists(m_instance->jarModsDir()))
{ {
return false; return false;
} }
@ -352,7 +352,7 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths)
QString target_filename = id + ".jar"; QString target_filename = id + ".jar";
QString target_id = "org.multimc.jarmod." + id; QString target_id = "org.multimc.jarmod." + id;
QString target_name = sourceInfo.completeBaseName() + " (jar mod)"; 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); QFileInfo targetInfo(finalPath);
if(targetInfo.exists()) if(targetInfo.exists())
@ -373,7 +373,7 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths)
f->name = target_name; f->name = target_name;
f->fileId = target_id; f->fileId = target_id;
f->order = profile->getFreeOrderNumber(); f->order = profile->getFreeOrderNumber();
QString patchFileName = PathCombine(patchDir, target_id + ".json"); QString patchFileName = FS::PathCombine(patchDir, target_id + ".json");
f->filename = patchFileName; f->filename = patchFileName;
f->setMovable(true); f->setMovable(true);
f->setRemovable(true); f->setRemovable(true);

View File

@ -22,7 +22,6 @@
#include <QFileInfo> #include <QFileInfo>
#include <QTextStream> #include <QTextStream>
#include <QDataStream> #include <QDataStream>
#include <pathutils.h>
#include <JlCompress.h> #include <JlCompress.h>
#include "BaseInstance.h" #include "BaseInstance.h"
@ -35,6 +34,7 @@
#include "minecraft/AssetsUtils.h" #include "minecraft/AssetsUtils.h"
#include "Exception.h" #include "Exception.h"
#include "MMCZip.h" #include "MMCZip.h"
#include <FileSystem.h>
OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent), m_inst(inst) 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. // now check the lib folder inside the instance for files.
for (auto &lib : libList) for (auto &lib : libList)
{ {
QFileInfo libInfo(PathCombine(inst->libDir(), lib.filename)); QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename));
if (libInfo.exists()) if (libInfo.exists())
continue; continue;
fmlLibsToProcess.append(lib); fmlLibsToProcess.append(lib);
@ -389,13 +389,13 @@ void OneSixUpdate::fmllibsFinished()
{ {
progress(index, fmlLibsToProcess.size()); progress(index, fmlLibsToProcess.size());
auto entry = metacache->resolveEntry("fmllibs", lib.filename); auto entry = metacache->resolveEntry("fmllibs", lib.filename);
auto path = PathCombine(inst->libDir(), lib.filename); auto path = FS::PathCombine(inst->libDir(), lib.filename);
if (!ensureFilePathExists(path)) if (!FS::ensureFilePathExists(path))
{ {
emitFailed(tr("Failed creating FML library folder inside the instance.")); emitFailed(tr("Failed creating FML library folder inside the instance."));
return; 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)); emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename));
return; return;

View File

@ -2,7 +2,7 @@
using namespace Json; using namespace Json;
#include "RawLibrary.h" #include "RawLibrary.h"
#include <pathutils.h> #include <FileSystem.h>
RawLibraryPtr RawLibrary::fromJson(const QJsonObject &libObj, const QString &filename) RawLibraryPtr RawLibrary::fromJson(const QJsonObject &libObj, const QString &filename)
{ {
@ -314,7 +314,7 @@ QString RawLibrary::storageSuffix() const
QString RawLibrary::storagePath() const QString RawLibrary::storagePath() const
{ {
return PathCombine(storagePrefix(), storageSuffix()); return FS::PathCombine(storagePrefix(), storageSuffix());
} }
bool RawLibrary::storagePathIsDefault() const bool RawLibrary::storagePathIsDefault() const

View File

@ -1,6 +1,5 @@
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <modutils.h>
#include <QDebug> #include <QDebug>
@ -14,6 +13,7 @@
using namespace Json; using namespace Json;
#include "VersionBuildError.h" #include "VersionBuildError.h"
#include <Version.h>
#define CURRENT_MINIMUM_LAUNCHER_VERSION 14 #define CURRENT_MINIMUM_LAUNCHER_VERSION 14
@ -427,8 +427,8 @@ void VersionFile::applyTo(MinecraftProfile *version)
// otherwise apply differences, if allowed // otherwise apply differences, if allowed
auto existingLibrary = version->libraries.at(index); auto existingLibrary = version->libraries.at(index);
const Util::Version addedVersion = addedLibrary->version(); const Version addedVersion(addedLibrary->version());
const Util::Version existingVersion = existingLibrary->version(); const Version existingVersion(existingLibrary->version());
// if the existing version is a hard dependency we can either use it or // if the existing version is a hard dependency we can either use it or
// fail, but we can't change it // fail, but we can't change it
if (existingLibrary->dependType == OneSixLibrary::Hard) if (existingLibrary->dependType == OneSixLibrary::Hard)

View File

@ -18,10 +18,10 @@
#include <QDebug> #include <QDebug>
#include <QSaveFile> #include <QSaveFile>
#include "World.h" #include "World.h"
#include <pathutils.h>
#include "GZip.h" #include "GZip.h"
#include <MMCZip.h> #include <MMCZip.h>
#include <FileSystem.h>
#include <sstream> #include <sstream>
#include <io/stream_reader.h> #include <io/stream_reader.h>
#include <tag_string.h> #include <tag_string.h>
@ -179,8 +179,8 @@ void World::readFromZip(const QFileInfo &file)
bool World::install(const QString &to, const QString &name) bool World::install(const QString &to, const QString &name)
{ {
auto finalPath = PathCombine(to, DirNameFromString(m_actualName, to)); auto finalPath = FS::PathCombine(to, FS::DirNameFromString(m_actualName, to));
if(!ensureFolderPathExists(finalPath)) if(!FS::ensureFolderPathExists(finalPath))
{ {
return false; return false;
} }
@ -197,7 +197,7 @@ bool World::install(const QString &to, const QString &name)
else if(m_containerFile.isDir()) else if(m_containerFile.isDir())
{ {
QString from = m_containerFile.filePath(); QString from = m_containerFile.filePath();
ok = copyPath(from, finalPath); ok = FS::copyPath(from, finalPath);
} }
if(ok && !name.isEmpty() && m_actualName != name) if(ok && !name.isEmpty() && m_actualName != name)
@ -245,7 +245,7 @@ bool World::rename(const QString &newName)
QDir parentDir(m_containerFile.absoluteFilePath()); QDir parentDir(m_containerFile.absoluteFilePath());
parentDir.cdUp(); parentDir.cdUp();
QFile container(m_containerFile.absoluteFilePath()); 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)); container.rename(parentDir.absoluteFilePath(dirName));
return true; return true;
@ -350,7 +350,7 @@ bool World::replace(World &with)
{ {
if (!destroy()) if (!destroy())
return false; 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) if (success)
{ {
m_folderName = with.m_folderName; m_folderName = with.m_folderName;

View File

@ -14,7 +14,7 @@
*/ */
#include "WorldList.h" #include "WorldList.h"
#include <pathutils.h> #include <FileSystem.h>
#include <QMimeData> #include <QMimeData>
#include <QUrl> #include <QUrl>
#include <QUuid> #include <QUuid>
@ -25,7 +25,7 @@
WorldList::WorldList(const QString &dir) WorldList::WorldList(const QString &dir)
: QAbstractListModel(), m_dir(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 | m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs |
QDir::NoSymLinks); QDir::NoSymLinks);
m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware);

View File

@ -14,13 +14,13 @@
*/ */
#include "CacheDownload.h" #include "CacheDownload.h"
#include <pathutils.h>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QFileInfo> #include <QFileInfo>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include "Env.h" #include "Env.h"
#include <FileSystem.h>
CacheDownload::CacheDownload(QUrl url, MetaEntryPtr entry) CacheDownload::CacheDownload(QUrl url, MetaEntryPtr entry)
: NetAction(), md5sum(QCryptographicHash::Md5) : NetAction(), md5sum(QCryptographicHash::Md5)
@ -44,7 +44,7 @@ void CacheDownload::start()
m_output_file.reset(new QSaveFile(m_target_path)); 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 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; qCritical() << "Could not create folder for " + m_target_path;
m_status = Job_Failed; m_status = Job_Failed;

View File

@ -16,7 +16,6 @@
#include "Env.h" #include "Env.h"
#include "HttpMetaCache.h" #include "HttpMetaCache.h"
#include "FileSystem.h" #include "FileSystem.h"
#include <pathutils.h>
#include <QFileInfo> #include <QFileInfo>
#include <QFile> #include <QFile>
@ -33,7 +32,7 @@
QString MetaEntry::getFullPath() QString MetaEntry::getFullPath()
{ {
// FIXME: make local? // FIXME: make local?
return PathCombine(ENV.metacache()->getBasePath(base), path); return FS::PathCombine(ENV.metacache()->getBasePath(base), path);
} }
HttpMetaCache::HttpMetaCache(QString path) : QObject() HttpMetaCache::HttpMetaCache(QString path) : QObject()
@ -77,7 +76,7 @@ MetaEntryPtr HttpMetaCache::resolveEntry(QString base, QString resource_path,
} }
auto &selected_base = m_entries[base]; 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); QFileInfo finfo(real_path);
// is the file really there? if not -> stale // is the file really there? if not -> stale

View File

@ -15,7 +15,7 @@
#include "Env.h" #include "Env.h"
#include "MD5EtagDownload.h" #include "MD5EtagDownload.h"
#include <pathutils.h> #include <FileSystem.h>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QDebug> #include <QDebug>
@ -55,7 +55,7 @@ void MD5EtagDownload::start()
// no expected md5. we use the local md5sum as an ETag // no expected md5. we use the local md5sum as an ETag
} }
} }
if (!ensureFilePathExists(filename)) if (!FS::ensureFilePathExists(filename))
{ {
emit failed(m_index_within_job); emit failed(m_index_within_job);
return; return;

View File

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

View File

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

View File

@ -1,9 +1,9 @@
#include "GoUpdate.h" #include "GoUpdate.h"
#include <pathutils.h>
#include <QDebug> #include <QDebug>
#include <QDomDocument> #include <QDomDocument>
#include <QFile> #include <QFile>
#include <Env.h> #include <Env.h>
#include <FileSystem.h>
namespace GoUpdate 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. // delete anything in the current one version's list that isn't in the new version's list.
for (VersionFileEntry entry : currentVersion) for (VersionFileEntry entry : currentVersion)
{ {
QFileInfo toDelete(PathCombine(rootPath, entry.path)); QFileInfo toDelete(FS::PathCombine(rootPath, entry.path));
if (!toDelete.exists()) if (!toDelete.exists())
{ {
qCritical() << "Expected file " << toDelete.absoluteFilePath() 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 // 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. // way to do this in the background.
QString fileMD5; QString fileMD5;
QString realEntryPath = PathCombine(rootPath, entry.path); QString realEntryPath = FS::PathCombine(rootPath, entry.path);
QFile entryFile(realEntryPath); QFile entryFile(realEntryPath);
QFileInfo entryInfo(realEntryPath); QFileInfo entryInfo(realEntryPath);
@ -186,7 +186,7 @@ bool processFileLists
// Download it to updatedir/<filepath>-<md5> where filepath is the file's // Download it to updatedir/<filepath>-<md5> where filepath is the file's
// path with slashes replaced by underscores. // 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 // We need to download the file to the updatefiles folder and add a task
// to copy it to its install path. // to copy it to its install path.

View File

@ -6,7 +6,7 @@
#include "updater/GoUpdate.h" #include "updater/GoUpdate.h"
#include "updater/DownloadTask.h" #include "updater/DownloadTask.h"
#include "updater/UpdateChecker.h" #include "updater/UpdateChecker.h"
#include "pathutils.h" #include <FileSystem.h>
using namespace GoUpdate; using namespace GoUpdate;
@ -166,7 +166,7 @@ slots:
<< (OperationList() << (OperationList()
<< Operation::DeleteOp("tests/data/fileThree") << Operation::DeleteOp("tests/data/fileThree")
<< Operation::CopyOp( << Operation::CopyOp(
PathCombine(tempFolder, FS::PathCombine(tempFolder,
QString("tests/data/fileOne").replace("/", "_")), QString("tests/data/fileOne").replace("/", "_")),
"tests/data/fileOne", 493)); "tests/data/fileOne", 493));
} }

View File

@ -15,8 +15,8 @@
#include <QTest> #include <QTest>
#include "modutils.h"
#include "TestUtil.h" #include "TestUtil.h"
#include <Version.h>
class ModUtilsTest : public QObject class ModUtilsTest : public QObject
{ {
@ -95,7 +95,7 @@ private slots:
QFETCH(QString, interval); QFETCH(QString, interval);
QFETCH(bool, result); QFETCH(bool, result);
QCOMPARE(Util::versionIsInInterval(version, interval), result); QCOMPARE(versionIsInInterval(version, interval), result);
} }
void test_versionCompare_data() void test_versionCompare_data()
@ -109,8 +109,8 @@ private slots:
QFETCH(bool, lessThan); QFETCH(bool, lessThan);
QFETCH(bool, equal); QFETCH(bool, equal);
const auto v1 = Util::Version(first); const auto v1 = Version(first);
const auto v2 = Util::Version(second); const auto v2 = Version(second);
QCOMPARE(v1 < v2, lessThan); QCOMPARE(v1 < v2, lessThan);
QCOMPARE(v1 > v2, !lessThan && !equal); QCOMPARE(v1 > v2, !lessThan && !equal);

View File

@ -1,7 +1,6 @@
#include <QTest> #include <QTest>
#include "TestUtil.h" #include "TestUtil.h"
#include <FileSystem.h>
#include "pathutils.h"
class PathUtilsTest : public QObject class PathUtilsTest : public QObject
{ {
@ -37,7 +36,7 @@ slots:
QFETCH(QString, path1); QFETCH(QString, path1);
QFETCH(QString, path2); QFETCH(QString, path2);
QCOMPARE(PathCombine(path1, path2), result); QCOMPARE(FS::PathCombine(path1, path2), result);
} }
void test_PathCombine2_data() void test_PathCombine2_data()
@ -65,7 +64,7 @@ slots:
QFETCH(QString, path2); QFETCH(QString, path2);
QFETCH(QString, path3); 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 <QTest>
#include <QStandardPaths> #include <QStandardPaths>
#include "TestUtil.h" #include "TestUtil.h"
#include <FileSystem.h>
#include "userutils.h"
class UserUtilsTest : public QObject class UserUtilsTest : public QObject
{ {
@ -20,7 +19,7 @@ slots:
void test_getDesktop() void test_getDesktop()
{ {
QCOMPARE(Util::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); QCOMPARE(FS::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
} }
// this is only valid on linux // this is only valid on linux
@ -57,7 +56,7 @@ slots:
QFETCH(QString, iconLocation); QFETCH(QString, iconLocation);
QFETCH(QByteArray, result); 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)); QCOMPARE(QString::fromLocal8Bit(TestsInternal::readFile(location + QDir::separator() + name + ".desktop")), QString::fromLocal8Bit(result));
//QDir().remove(location); //QDir().remove(location);